summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/wm_overview_snapshot.cc
blob: 218227363a9f822c6ce12f6ed688b11fc94f4b39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/wm_overview_snapshot.h"

#include <vector>

#include "app/x11_util.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/chromeos/wm_ipc.h"
#include "chrome/browser/ui/browser.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/grid_layout.h"

using std::vector;

#if !defined(OS_CHROMEOS)
#error This file is only meant to be compiled for ChromeOS
#endif

namespace chromeos {

WmOverviewSnapshot::WmOverviewSnapshot()
  : WidgetGtk(TYPE_WINDOW),
    snapshot_view_(NULL),
    index_(-1),
    configured_snapshot_(false) {
}

void WmOverviewSnapshot::Init(const gfx::Size& size,
                              Browser* browser,
                              int index) {
  snapshot_view_ = new views::ImageView();

  WidgetGtk::Init(NULL, gfx::Rect(size));

  SetContentsView(snapshot_view_);

  UpdateIndex(browser, index);
}


void WmOverviewSnapshot::UpdateIndex(Browser* browser, int index) {
  vector<int> params;
  params.push_back(x11_util::GetX11WindowFromGtkWidget(
      GTK_WIDGET(browser->window()->GetNativeHandle())));
  params.push_back(index);
  WmIpc::instance()->SetWindowType(
      GetNativeView(),
      WM_IPC_WINDOW_CHROME_TAB_SNAPSHOT,
      &params);
  index_ = index;
}

void WmOverviewSnapshot::SetImage(const SkBitmap& image) {
  CHECK(snapshot_view_) << "Init not called before setting image.";
  snapshot_view_->SetImage(image);

  // Reset the bounds to the size of the image.
  gfx::Rect bounds;
  GetBounds(&bounds, false);
  bounds.set_width(image.width());
  bounds.set_height(image.height());
  SetBounds(bounds);

  configured_snapshot_ = true;
}

}  // namespace chromeos