1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/chromeos/wm_overview_snapshot.h" 6 7 #include <vector> 8 9 #include "chrome/browser/chromeos/wm_ipc.h" 10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser_window.h" 12 #include "ui/base/x/x11_util.h" 13 #include "views/controls/image_view.h" 14 #include "views/controls/label.h" 15 #include "views/layout/grid_layout.h" 16 17 using std::vector; 18 19 #if !defined(OS_CHROMEOS) 20 #error This file is only meant to be compiled for ChromeOS 21 #endif 22 23 namespace chromeos { 24 25 WmOverviewSnapshot::WmOverviewSnapshot() 26 : WidgetGtk(TYPE_WINDOW), 27 snapshot_view_(NULL), 28 index_(-1), 29 configured_snapshot_(false) { 30 } 31 32 void WmOverviewSnapshot::Init(const gfx::Size& size, 33 Browser* browser, 34 int index) { 35 snapshot_view_ = new views::ImageView(); 36 37 WidgetGtk::Init(NULL, gfx::Rect(size)); 38 39 SetContentsView(snapshot_view_); 40 41 UpdateIndex(browser, index); 42 } 43 44 45 void WmOverviewSnapshot::UpdateIndex(Browser* browser, int index) { 46 vector<int> params; 47 params.push_back(ui::GetX11WindowFromGtkWidget( 48 GTK_WIDGET(browser->window()->GetNativeHandle()))); 49 params.push_back(index); 50 WmIpc::instance()->SetWindowType( 51 GetNativeView(), 52 WM_IPC_WINDOW_CHROME_TAB_SNAPSHOT, 53 ¶ms); 54 index_ = index; 55 } 56 57 void WmOverviewSnapshot::SetImage(const SkBitmap& image) { 58 CHECK(snapshot_view_) << "Init not called before setting image."; 59 snapshot_view_->SetImage(image); 60 61 // Reset the bounds to the size of the image. 62 SetBounds(gfx::Rect(image.width(), image.height())); 63 configured_snapshot_ = true; 64 } 65 66 } // namespace chromeos 67