OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/wm_overview_fav_icon.h" | 5 #include "chrome/browser/chromeos/wm_overview_favicon.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "chrome/browser/chromeos/wm_ipc.h" | 9 #include "chrome/browser/chromeos/wm_ipc.h" |
10 #include "chrome/browser/chromeos/wm_overview_snapshot.h" | 10 #include "chrome/browser/chromeos/wm_overview_snapshot.h" |
11 #include "skia/ext/image_operations.h" | 11 #include "skia/ext/image_operations.h" |
12 #include "third_party/cros/chromeos_wm_ipc_enums.h" | 12 #include "third_party/cros/chromeos_wm_ipc_enums.h" |
13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
14 #include "ui/base/x/x11_util.h" | 14 #include "ui/base/x/x11_util.h" |
15 #include "views/controls/image_view.h" | 15 #include "views/controls/image_view.h" |
16 #include "views/controls/label.h" | 16 #include "views/controls/label.h" |
17 #include "views/layout/grid_layout.h" | 17 #include "views/layout/grid_layout.h" |
18 | 18 |
19 using std::vector; | 19 using std::vector; |
20 | 20 |
21 #if !defined(OS_CHROMEOS) | 21 #if !defined(OS_CHROMEOS) |
22 #error This file is only meant to be compiled for ChromeOS | 22 #error This file is only meant to be compiled for ChromeOS |
23 #endif | 23 #endif |
24 | 24 |
25 namespace chromeos { | 25 namespace chromeos { |
26 | 26 |
27 const int WmOverviewFavIcon::kIconSize = 32; | 27 const int WmOverviewFavicon::kIconSize = 32; |
28 | 28 |
29 WmOverviewFavIcon::WmOverviewFavIcon() | 29 WmOverviewFavicon::WmOverviewFavicon() |
30 : WidgetGtk(TYPE_WINDOW), | 30 : WidgetGtk(TYPE_WINDOW), |
31 fav_icon_view_(NULL) { | 31 favicon_view_(NULL) { |
32 } | 32 } |
33 | 33 |
34 void WmOverviewFavIcon::Init(WmOverviewSnapshot* snapshot) { | 34 void WmOverviewFavicon::Init(WmOverviewSnapshot* snapshot) { |
35 MakeTransparent(); | 35 MakeTransparent(); |
36 | 36 |
37 fav_icon_view_ = new views::ImageView(); | 37 favicon_view_ = new views::ImageView(); |
38 | 38 |
39 WidgetGtk::Init(NULL, gfx::Rect(0, 0, 0, 0)); | 39 WidgetGtk::Init(NULL, gfx::Rect(0, 0, 0, 0)); |
40 | 40 |
41 SetContentsView(fav_icon_view_); | 41 SetContentsView(favicon_view_); |
42 | 42 |
43 // Set the window type | 43 // Set the window type |
44 vector<int> params; | 44 vector<int> params; |
45 params.push_back(ui::GetX11WindowFromGtkWidget( | 45 params.push_back(ui::GetX11WindowFromGtkWidget( |
46 GTK_WIDGET(snapshot->GetNativeView()))); | 46 GTK_WIDGET(snapshot->GetNativeView()))); |
47 WmIpc::instance()->SetWindowType( | 47 WmIpc::instance()->SetWindowType( |
48 GetNativeView(), | 48 GetNativeView(), |
49 WM_IPC_WINDOW_CHROME_TAB_FAV_ICON, | 49 WM_IPC_WINDOW_CHROME_TAB_FAVICON, |
50 ¶ms); | 50 ¶ms); |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 void WmOverviewFavIcon::SetFavicon(const SkBitmap& image) { | 54 void WmOverviewFavicon::SetFavicon(const SkBitmap& image) { |
55 CHECK(fav_icon_view_) << "Init not called before setting favicon."; | 55 CHECK(favicon_view_) << "Init not called before setting favicon."; |
56 SkBitmap icon; | 56 SkBitmap icon; |
57 if (image.width() && image.height()) { | 57 if (image.width() && image.height()) { |
58 float aspect_ratio = static_cast<float>(image.width()) / image.height(); | 58 float aspect_ratio = static_cast<float>(image.width()) / image.height(); |
59 int new_width = kIconSize; | 59 int new_width = kIconSize; |
60 int new_height = kIconSize; | 60 int new_height = kIconSize; |
61 if (aspect_ratio > 1.0f) { | 61 if (aspect_ratio > 1.0f) { |
62 new_height = kIconSize / aspect_ratio; | 62 new_height = kIconSize / aspect_ratio; |
63 } else { | 63 } else { |
64 new_width = kIconSize * aspect_ratio; | 64 new_width = kIconSize * aspect_ratio; |
65 } | 65 } |
66 if (new_width && new_height) { | 66 if (new_width && new_height) { |
67 icon = skia::ImageOperations::Resize( | 67 icon = skia::ImageOperations::Resize( |
68 image, skia::ImageOperations::RESIZE_BOX, | 68 image, skia::ImageOperations::RESIZE_BOX, |
69 new_width, new_height); | 69 new_width, new_height); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 fav_icon_view_->SetImage(icon); | 73 favicon_view_->SetImage(icon); |
74 | 74 |
75 // Reset the bounds to the size of the image. | 75 // Reset the bounds to the size of the image. |
76 SetBounds(gfx::Rect(icon.width(), icon.height())); | 76 SetBounds(gfx::Rect(icon.width(), icon.height())); |
77 } | 77 } |
78 | 78 |
79 } // namespace chromeos | 79 } // namespace chromeos |
OLD | NEW |