1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/app/chrome_dll_resource.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/signin/signin_header_helper.h"
13 #include "chrome/browser/themes/theme_properties.h"
14 #include "chrome/browser/ui/views/frame/browser_view.h"
15 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
16 #include "chrome/browser/ui/views/profiles/new_avatar_button.h"
17 #include "chrome/browser/ui/views/tabs/tab.h"
18 #include "chrome/browser/ui/views/tabs/tab_strip.h"
19 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
20 #include "components/signin/core/common/profile_management_switches.h"
21 #include "grit/theme_resources.h"
22 #include "skia/ext/image_operations.h"
23 #include "ui/base/resource/resource_bundle_win.h"
24 #include "ui/base/theme_provider.h"
25 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/icon_util.h"
27 #include "ui/gfx/image/image.h"
28 #include "ui/gfx/win/dpi.h"
29 #include "ui/resources/grit/ui_resources.h"
30 #include "ui/views/controls/label.h"
31 #include "ui/views/layout/layout_constants.h"
32 #include "ui/views/win/hwnd_util.h"
33 #include "ui/views/window/client_view.h"
35 HICON
GlassBrowserFrameView::throbber_icons_
[
36 GlassBrowserFrameView::kThrobberIconCount
];
39 // There are 3 px of client edge drawn inside the outer frame borders.
40 const int kNonClientBorderThickness
= 3;
41 // Besides the frame border, there's another 9 px of empty space atop the
42 // window in restored mode, to use to drag the window around.
43 const int kNonClientRestoredExtraThickness
= 9;
44 // In the window corners, the resize areas don't actually expand bigger, but the
45 // 16 px at the end of the top and bottom edges triggers diagonal resizing.
46 const int kResizeAreaCornerSize
= 16;
47 // The avatar ends 2 px above the bottom of the tabstrip (which, given the
48 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
50 const int kAvatarBottomSpacing
= 2;
51 // Space between the frame border and the left edge of the avatar.
52 const int kAvatarLeftSpacing
= 2;
53 // Space between the right edge of the avatar and the tabstrip.
54 const int kAvatarRightSpacing
= -2;
55 // How far the new avatar button is from the left of the minimize button.
56 const int kNewAvatarButtonOffset
= 5;
57 // The content left/right images have a shadow built into them.
58 const int kContentEdgeShadowThickness
= 2;
59 // The top 3 px of the tabstrip is shadow; in maximized mode we push this off
60 // the top of the screen so the tabs appear flush against the screen edge.
61 const int kTabstripTopShadowThickness
= 3;
62 // In restored mode, the New Tab button isn't at the same height as the caption
63 // buttons, but the space will look cluttered if it actually slides under them,
64 // so we stop it when the gap between the two is down to 5 px.
65 const int kNewTabCaptionRestoredSpacing
= 5;
66 // In maximized mode, where the New Tab button and the caption buttons are at
67 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid
68 // looking too cluttered.
69 const int kNewTabCaptionMaximizedSpacing
= 16;
70 // How far to indent the tabstrip from the left side of the screen when there
72 const int kTabStripIndent
= -6;
74 // Converts the |image| to a Windows icon and returns the corresponding HICON
75 // handle. |image| is resized to desired |width| and |height| if needed.
76 HICON
CreateHICONFromSkBitmapSizedTo(const gfx::ImageSkia
& image
,
79 if (width
== image
.width() && height
== image
.height())
80 return IconUtil::CreateHICONFromSkBitmap(*image
.bitmap());
81 return IconUtil::CreateHICONFromSkBitmap(skia::ImageOperations::Resize(
82 *image
.bitmap(), skia::ImageOperations::RESIZE_BEST
, width
, height
));
87 ///////////////////////////////////////////////////////////////////////////////
88 // GlassBrowserFrameView, public:
90 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame
* frame
,
91 BrowserView
* browser_view
)
92 : BrowserNonClientFrameView(frame
, browser_view
),
93 throbber_running_(false),
95 if (browser_view
->ShouldShowWindowIcon())
101 GlassBrowserFrameView::~GlassBrowserFrameView() {
104 ///////////////////////////////////////////////////////////////////////////////
105 // GlassBrowserFrameView, BrowserNonClientFrameView implementation:
107 gfx::Rect
GlassBrowserFrameView::GetBoundsForTabStrip(
108 views::View
* tabstrip
) const {
109 int minimize_button_offset
=
110 std::min(frame()->GetMinimizeButtonOffset(), width());
112 // The new avatar button is optionally displayed to the left of the
114 if (new_avatar_button()) {
115 DCHECK(switches::IsNewAvatarMenu());
116 minimize_button_offset
-=
117 new_avatar_button()->width() + kNewAvatarButtonOffset
;
119 // In non-maximized mode, allow the new tab button to completely slide under
120 // the avatar button.
121 if (!frame()->IsMaximized() && !base::i18n::IsRTL()) {
122 minimize_button_offset
+=
123 TabStrip::kNewTabButtonAssetWidth
+ kNewTabCaptionRestoredSpacing
;
127 int tabstrip_x
= browser_view()->ShouldShowAvatar() ?
128 (avatar_bounds_
.right() + kAvatarRightSpacing
) :
129 NonClientBorderThickness() + kTabStripIndent
;
130 // In RTL languages, we have moved an avatar icon left by the size of window
131 // controls to prevent it from being rendered over them. So, we use its x
132 // position to move this tab strip left when maximized. Also, we can render
133 // a tab strip until the left end of this window without considering the size
134 // of window controls in RTL languages.
135 if (base::i18n::IsRTL()) {
136 if (!browser_view()->ShouldShowAvatar() && frame()->IsMaximized()) {
137 tabstrip_x
+= avatar_bounds_
.x();
138 } else if (browser_view()->IsRegularOrGuestSession() &&
139 switches::IsNewAvatarMenu()) {
140 tabstrip_x
= width() - minimize_button_offset
;
143 minimize_button_offset
= width();
145 int tabstrip_width
= minimize_button_offset
- tabstrip_x
-
146 (frame()->IsMaximized() ?
147 kNewTabCaptionMaximizedSpacing
: kNewTabCaptionRestoredSpacing
);
148 return gfx::Rect(tabstrip_x
, NonClientTopBorderHeight(),
149 std::max(0, tabstrip_width
),
150 tabstrip
->GetPreferredSize().height());
153 int GlassBrowserFrameView::GetTopInset() const {
154 return GetClientAreaInsets().top();
157 int GlassBrowserFrameView::GetThemeBackgroundXInset() const {
161 void GlassBrowserFrameView::UpdateThrobber(bool running
) {
162 if (throbber_running_
) {
164 DisplayNextThrobberFrame();
168 } else if (running
) {
173 gfx::Size
GlassBrowserFrameView::GetMinimumSize() const {
174 gfx::Size
min_size(browser_view()->GetMinimumSize());
176 // Account for the client area insets.
177 gfx::Insets insets
= GetClientAreaInsets();
178 min_size
.Enlarge(insets
.width(), insets
.height());
179 // Client area insets do not include the shadow thickness.
180 min_size
.Enlarge(2 * kContentEdgeShadowThickness
, 0);
182 // Ensure that the minimum width is enough to hold a tab strip with minimum
183 // width at its usual insets.
184 if (browser_view()->IsTabStripVisible()) {
185 TabStrip
* tabstrip
= browser_view()->tabstrip();
186 int min_tabstrip_width
= tabstrip
->GetMinimumSize().width();
187 int min_tabstrip_area_width
=
188 width() - GetBoundsForTabStrip(tabstrip
).width() + min_tabstrip_width
;
189 min_size
.set_width(std::max(min_tabstrip_area_width
, min_size
.width()));
195 ///////////////////////////////////////////////////////////////////////////////
196 // GlassBrowserFrameView, views::NonClientFrameView implementation:
198 gfx::Rect
GlassBrowserFrameView::GetBoundsForClientView() const {
199 return client_view_bounds_
;
202 gfx::Rect
GlassBrowserFrameView::GetWindowBoundsForClientBounds(
203 const gfx::Rect
& client_bounds
) const {
204 HWND hwnd
= views::HWNDForWidget(frame());
205 if (!browser_view()->IsTabStripVisible() && hwnd
) {
206 // If we don't have a tabstrip, we're either a popup or an app window, in
207 // which case we have a standard size non-client area and can just use
208 // AdjustWindowRectEx to obtain it. We check for a non-null window handle in
209 // case this gets called before the window is actually created.
210 RECT rect
= client_bounds
.ToRECT();
211 AdjustWindowRectEx(&rect
, GetWindowLong(hwnd
, GWL_STYLE
), FALSE
,
212 GetWindowLong(hwnd
, GWL_EXSTYLE
));
213 return gfx::Rect(rect
);
216 gfx::Insets insets
= GetClientAreaInsets();
217 return gfx::Rect(std::max(0, client_bounds
.x() - insets
.left()),
218 std::max(0, client_bounds
.y() - insets
.top()),
219 client_bounds
.width() + insets
.width(),
220 client_bounds
.height() + insets
.height());
223 int GlassBrowserFrameView::NonClientHitTest(const gfx::Point
& point
) {
224 // If the browser isn't in normal mode, we haven't customized the frame, so
225 // Windows can figure this out. If the point isn't within our bounds, then
226 // it's in the native portion of the frame, so again Windows can figure it
228 if (!browser_view()->IsBrowserTypeNormal() || !bounds().Contains(point
))
231 // See if the point is within the avatar menu button or within the avatar
233 if (avatar_button() && avatar_button()->GetMirroredBounds().Contains(point
))
236 if (new_avatar_button() &&
237 new_avatar_button()->GetMirroredBounds().Contains(point
))
240 int frame_component
= frame()->client_view()->NonClientHitTest(point
);
242 // See if we're in the sysmenu region. We still have to check the tabstrip
243 // first so that clicks in a tab don't get treated as sysmenu clicks.
244 int nonclient_border_thickness
= NonClientBorderThickness();
245 if (gfx::Rect(nonclient_border_thickness
,
246 gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME
),
247 gfx::win::GetSystemMetricsInDIP(SM_CXSMICON
),
248 gfx::win::GetSystemMetricsInDIP(SM_CYSMICON
)).Contains(point
))
249 return (frame_component
== HTCLIENT
) ? HTCLIENT
: HTSYSMENU
;
251 if (frame_component
!= HTNOWHERE
)
252 return frame_component
;
254 int frame_border_thickness
= FrameBorderThickness();
255 int window_component
= GetHTComponentForFrame(point
, frame_border_thickness
,
256 nonclient_border_thickness
, frame_border_thickness
,
257 kResizeAreaCornerSize
- frame_border_thickness
,
258 frame()->widget_delegate()->CanResize());
259 // Fall back to the caption if no other component matches.
260 return (window_component
== HTNOWHERE
) ? HTCAPTION
: window_component
;
263 ///////////////////////////////////////////////////////////////////////////////
264 // GlassBrowserFrameView, views::View overrides:
266 void GlassBrowserFrameView::OnPaint(gfx::Canvas
* canvas
) {
267 if (browser_view()->IsToolbarVisible() &&
268 browser_view()->toolbar()->ShouldPaintBackground())
269 PaintToolbarBackground(canvas
);
270 if (!frame()->IsMaximized())
271 PaintRestoredClientEdge(canvas
);
274 void GlassBrowserFrameView::Layout() {
275 if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu())
276 LayoutNewStyleAvatar();
283 ///////////////////////////////////////////////////////////////////////////////
284 // GlassBrowserFrameView, protected:
286 // views::ButtonListener:
287 void GlassBrowserFrameView::ButtonPressed(views::Button
* sender
,
288 const ui::Event
& event
) {
289 if (sender
== new_avatar_button()) {
290 BrowserWindow::AvatarBubbleMode mode
=
291 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT
;
292 if (event
.IsMouseEvent() &&
293 static_cast<const ui::MouseEvent
&>(event
).IsRightMouseButton()) {
294 mode
= BrowserWindow::AVATAR_BUBBLE_MODE_FAST_USER_SWITCH
;
296 browser_view()->ShowAvatarBubbleFromAvatarButton(
298 signin::ManageAccountsParams());
302 // BrowserNonClientFrameView:
303 void GlassBrowserFrameView::UpdateNewAvatarButtonImpl() {
304 UpdateNewAvatarButton(this, NewAvatarButton::NATIVE_BUTTON
);
307 ///////////////////////////////////////////////////////////////////////////////
308 // GlassBrowserFrameView, private:
310 // views::NonClientFrameView:
311 bool GlassBrowserFrameView::DoesIntersectRect(const views::View
* target
,
312 const gfx::Rect
& rect
) const {
313 CHECK_EQ(target
, this);
314 bool hit_avatar_button
= avatar_button() &&
315 avatar_button()->GetMirroredBounds().Intersects(rect
);
316 bool hit_new_avatar_button
= new_avatar_button() &&
317 new_avatar_button()->GetMirroredBounds().Intersects(rect
);
318 return hit_avatar_button
|| hit_new_avatar_button
||
319 !frame()->client_view()->bounds().Intersects(rect
);
322 int GlassBrowserFrameView::FrameBorderThickness() const {
323 return (frame()->IsMaximized() || frame()->IsFullscreen()) ?
324 0 : gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME
);
327 int GlassBrowserFrameView::NonClientBorderThickness() const {
328 if (frame()->IsMaximized() || frame()->IsFullscreen())
331 return kNonClientBorderThickness
;
334 int GlassBrowserFrameView::NonClientTopBorderHeight() const {
335 if (frame()->IsFullscreen())
338 // We'd like to use FrameBorderThickness() here, but the maximized Aero glass
339 // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border
340 // at the top (see AeroGlassFrame::OnGetMinMaxInfo()).
341 return gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME
) +
342 (!frame()->ShouldLeaveOffsetNearTopBorder() ?
343 -kTabstripTopShadowThickness
: kNonClientRestoredExtraThickness
);
346 void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas
* canvas
) {
347 ui::ThemeProvider
* tp
= GetThemeProvider();
349 gfx::Rect
toolbar_bounds(browser_view()->GetToolbarBounds());
350 gfx::Point
toolbar_origin(toolbar_bounds
.origin());
351 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin
);
352 toolbar_bounds
.set_origin(toolbar_origin
);
353 int x
= toolbar_bounds
.x();
354 int w
= toolbar_bounds
.width();
355 int left_x
= x
- kContentEdgeShadowThickness
;
357 gfx::ImageSkia
* theme_toolbar
= tp
->GetImageSkiaNamed(IDR_THEME_TOOLBAR
);
358 gfx::ImageSkia
* toolbar_left
= tp
->GetImageSkiaNamed(
359 IDR_CONTENT_TOP_LEFT_CORNER
);
360 gfx::ImageSkia
* toolbar_center
= tp
->GetImageSkiaNamed(
361 IDR_CONTENT_TOP_CENTER
);
363 // Tile the toolbar image starting at the frame edge on the left and where
364 // the tabstrip is on the top.
365 int y
= toolbar_bounds
.y();
366 int dest_y
= browser_view()->IsTabStripVisible()
367 ? y
+ (kFrameShadowThickness
* 2)
369 canvas
->TileImageInt(*theme_toolbar
,
370 x
+ GetThemeBackgroundXInset(),
371 dest_y
- GetTopInset(), x
,
372 dest_y
, w
, theme_toolbar
->height());
374 if (browser_view()->IsTabStripVisible()) {
375 // Draw rounded corners for the tab.
376 gfx::ImageSkia
* toolbar_left_mask
=
377 tp
->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK
);
378 gfx::ImageSkia
* toolbar_right_mask
=
379 tp
->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK
);
381 // We mask out the corners by using the DestinationIn transfer mode,
382 // which keeps the RGB pixels from the destination and the alpha from
385 paint
.setXfermodeMode(SkXfermode::kDstIn_Mode
);
387 // Mask out the top left corner.
388 canvas
->DrawImageInt(*toolbar_left_mask
, left_x
, y
, paint
);
390 // Mask out the top right corner.
392 x
+ w
+ kContentEdgeShadowThickness
- toolbar_right_mask
->width();
393 canvas
->DrawImageInt(*toolbar_right_mask
, right_x
, y
, paint
);
396 canvas
->DrawImageInt(*toolbar_left
, left_x
, y
);
399 canvas
->TileImageInt(*toolbar_center
, left_x
+ toolbar_left
->width(), y
,
400 right_x
- (left_x
+ toolbar_left
->width()), toolbar_center
->height());
403 canvas
->DrawImageInt(*tp
->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER
),
407 // Draw the content/toolbar separator.
409 gfx::Rect(x
+ kClientEdgeThickness
,
410 toolbar_bounds
.bottom() - kClientEdgeThickness
,
411 w
- (2 * kClientEdgeThickness
),
412 kClientEdgeThickness
),
413 ThemeProperties::GetDefaultColor(
414 ThemeProperties::COLOR_TOOLBAR_SEPARATOR
));
417 void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas
* canvas
) {
418 ui::ThemeProvider
* tp
= GetThemeProvider();
419 gfx::Rect client_area_bounds
= CalculateClientAreaBounds(width(), height());
421 // The client edges start below the toolbar upper corner images regardless
422 // of how tall the toolbar itself is.
423 int client_area_top
= frame()->client_view()->y() +
424 browser_view()->GetToolbarBounds().y() +
425 tp
->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER
)->height();
426 int client_area_bottom
=
427 std::max(client_area_top
, height() - NonClientBorderThickness());
428 int client_area_height
= client_area_bottom
- client_area_top
;
430 // Draw the client edge images.
431 gfx::ImageSkia
* right
= tp
->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE
);
432 canvas
->TileImageInt(*right
, client_area_bounds
.right(), client_area_top
,
433 right
->width(), client_area_height
);
434 canvas
->DrawImageInt(
435 *tp
->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER
),
436 client_area_bounds
.right(), client_area_bottom
);
437 gfx::ImageSkia
* bottom
= tp
->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER
);
438 canvas
->TileImageInt(*bottom
, client_area_bounds
.x(),
439 client_area_bottom
, client_area_bounds
.width(),
441 gfx::ImageSkia
* bottom_left
=
442 tp
->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER
);
443 canvas
->DrawImageInt(*bottom_left
,
444 client_area_bounds
.x() - bottom_left
->width(), client_area_bottom
);
445 gfx::ImageSkia
* left
= tp
->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE
);
446 canvas
->TileImageInt(*left
, client_area_bounds
.x() - left
->width(),
447 client_area_top
, left
->width(), client_area_height
);
449 // Draw the toolbar color so that the client edges show the right color even
450 // where not covered by the toolbar image. NOTE: We do this after drawing the
451 // images because the images are meant to alpha-blend atop the frame whereas
452 // these rects are meant to be fully opaque, without anything overlaid.
453 SkColor toolbar_color
= tp
->GetColor(ThemeProperties::COLOR_TOOLBAR
);
454 canvas
->FillRect(gfx::Rect(client_area_bounds
.x() - kClientEdgeThickness
,
455 client_area_top
, kClientEdgeThickness
,
456 client_area_bottom
+ kClientEdgeThickness
- client_area_top
),
458 canvas
->FillRect(gfx::Rect(client_area_bounds
.x(), client_area_bottom
,
459 client_area_bounds
.width(), kClientEdgeThickness
),
461 canvas
->FillRect(gfx::Rect(client_area_bounds
.right(), client_area_top
,
462 kClientEdgeThickness
,
463 client_area_bottom
+ kClientEdgeThickness
- client_area_top
),
467 void GlassBrowserFrameView::LayoutNewStyleAvatar() {
468 DCHECK(switches::IsNewAvatarMenu());
469 if (!new_avatar_button())
472 gfx::Size label_size
= new_avatar_button()->GetPreferredSize();
474 int button_x
= frame()->GetMinimizeButtonOffset() -
475 kNewAvatarButtonOffset
- label_size
.width();
476 if (base::i18n::IsRTL())
477 button_x
= width() - frame()->GetMinimizeButtonOffset() +
478 kNewAvatarButtonOffset
;
480 // We need to offset the button correctly in maximized mode, so that the
481 // custom glass style aligns with the native control glass style. The
482 // glass shadow is off by 1px, which was determined by visual inspection.
483 int button_y
= !frame()->IsMaximized() ? 1 :
484 NonClientTopBorderHeight() + kTabstripTopShadowThickness
- 1;
486 new_avatar_button()->SetBounds(
490 gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE
) + 1);
493 void GlassBrowserFrameView::LayoutAvatar() {
494 // Even though the avatar is used for both incognito and profiles we always
495 // use the incognito icon to layout the avatar button. The profile icon
496 // can be customized so we can't depend on its size to perform layout.
497 gfx::ImageSkia incognito_icon
= browser_view()->GetOTRAvatarIcon();
499 int avatar_x
= NonClientBorderThickness() + kAvatarLeftSpacing
;
500 // Move this avatar icon by the size of window controls to prevent it from
501 // being rendered over them in RTL languages. This code also needs to adjust
502 // the width of a tab strip to avoid decreasing this size twice. (See the
503 // comment in GetBoundsForTabStrip().)
504 if (base::i18n::IsRTL())
505 avatar_x
+= width() - frame()->GetMinimizeButtonOffset();
507 int avatar_bottom
= GetTopInset() +
508 browser_view()->GetTabStripHeight() - kAvatarBottomSpacing
;
509 int avatar_restored_y
= avatar_bottom
- incognito_icon
.height();
510 int avatar_y
= frame()->IsMaximized() ?
511 (NonClientTopBorderHeight() + kTabstripTopShadowThickness
) :
513 avatar_bounds_
.SetRect(avatar_x
, avatar_y
, incognito_icon
.width(),
514 browser_view()->ShouldShowAvatar() ? (avatar_bottom
- avatar_y
) : 0);
516 avatar_button()->SetBoundsRect(avatar_bounds_
);
519 void GlassBrowserFrameView::LayoutClientView() {
520 client_view_bounds_
= CalculateClientAreaBounds(width(), height());
523 gfx::Insets
GlassBrowserFrameView::GetClientAreaInsets() const {
524 if (!browser_view()->IsTabStripVisible())
525 return gfx::Insets();
527 const int top_height
= NonClientTopBorderHeight();
528 const int border_thickness
= NonClientBorderThickness();
529 return gfx::Insets(top_height
,
535 gfx::Rect
GlassBrowserFrameView::CalculateClientAreaBounds(int width
,
537 gfx::Rect
bounds(0, 0, width
, height
);
538 bounds
.Inset(GetClientAreaInsets());
542 void GlassBrowserFrameView::StartThrobber() {
543 if (!throbber_running_
) {
544 throbber_running_
= true;
547 SendMessage(views::HWNDForWidget(frame()), WM_SETICON
,
548 static_cast<WPARAM
>(ICON_SMALL
),
549 reinterpret_cast<LPARAM
>(throbber_icons_
[throbber_frame_
]));
553 void GlassBrowserFrameView::StopThrobber() {
554 if (throbber_running_
) {
555 throbber_running_
= false;
557 HICON small_icon
= nullptr;
558 HICON big_icon
= nullptr;
560 // Check if hosted BrowserView has a window icon to use.
561 if (browser_view()->ShouldShowWindowIcon()) {
562 gfx::ImageSkia icon
= browser_view()->GetWindowIcon();
563 if (!icon
.isNull()) {
564 small_icon
= CreateHICONFromSkBitmapSizedTo(
565 icon
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
566 big_icon
= CreateHICONFromSkBitmapSizedTo(
567 icon
, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
));
571 // Fallback to class icon.
573 small_icon
= reinterpret_cast<HICON
>(
574 GetClassLongPtr(views::HWNDForWidget(frame()), GCLP_HICONSM
));
577 big_icon
= reinterpret_cast<HICON
>(
578 GetClassLongPtr(views::HWNDForWidget(frame()), GCLP_HICON
));
581 // This will reset the icon which we set in the throbber code.
582 // WM_SETICON with null icon restores the icon for title bar but not
583 // for taskbar. See http://crbug.com/29996
584 HICON previous_small_icon
= reinterpret_cast<HICON
>(
585 SendMessage(views::HWNDForWidget(frame()), WM_SETICON
,
586 static_cast<WPARAM
>(ICON_SMALL
),
587 reinterpret_cast<LPARAM
>(small_icon
)));
589 HICON previous_big_icon
= reinterpret_cast<HICON
>(
590 SendMessage(views::HWNDForWidget(frame()), WM_SETICON
,
591 static_cast<WPARAM
>(ICON_BIG
),
592 reinterpret_cast<LPARAM
>(big_icon
)));
594 if (previous_small_icon
)
595 ::DestroyIcon(previous_small_icon
);
597 if (previous_big_icon
)
598 ::DestroyIcon(previous_big_icon
);
602 void GlassBrowserFrameView::DisplayNextThrobberFrame() {
603 throbber_frame_
= (throbber_frame_
+ 1) % kThrobberIconCount
;
604 SendMessage(views::HWNDForWidget(frame()), WM_SETICON
,
605 static_cast<WPARAM
>(ICON_SMALL
),
606 reinterpret_cast<LPARAM
>(throbber_icons_
[throbber_frame_
]));
610 void GlassBrowserFrameView::InitThrobberIcons() {
611 static bool initialized
= false;
613 for (int i
= 0; i
< kThrobberIconCount
; ++i
) {
615 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01
+ i
);
616 DCHECK(throbber_icons_
[i
]);