Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / glass_browser_frame_view.cc
blob82879708de7d3c6b01fec1585c0218db0f245189
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 "base/win/windows_version.h"
10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/app/chrome_dll_resource.h"
12 #include "chrome/browser/profiles/profile.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/layout_constants.h"
16 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
17 #include "chrome/browser/ui/views/profiles/new_avatar_button.h"
18 #include "chrome/browser/ui/views/tabs/tab.h"
19 #include "chrome/browser/ui/views/tabs/tab_strip.h"
20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
21 #include "components/signin/core/browser/signin_header_helper.h"
22 #include "components/signin/core/common/profile_management_switches.h"
23 #include "grit/theme_resources.h"
24 #include "skia/ext/image_operations.h"
25 #include "ui/base/resource/material_design/material_design_controller.h"
26 #include "ui/base/resource/resource_bundle_win.h"
27 #include "ui/base/theme_provider.h"
28 #include "ui/gfx/canvas.h"
29 #include "ui/gfx/icon_util.h"
30 #include "ui/gfx/image/image.h"
31 #include "ui/gfx/win/dpi.h"
32 #include "ui/resources/grit/ui_resources.h"
33 #include "ui/views/controls/label.h"
34 #include "ui/views/layout/layout_constants.h"
35 #include "ui/views/resources/grit/views_resources.h"
36 #include "ui/views/win/hwnd_util.h"
37 #include "ui/views/window/client_view.h"
39 HICON GlassBrowserFrameView::throbber_icons_[
40 GlassBrowserFrameView::kThrobberIconCount];
42 namespace {
43 // Size of client edge drawn inside the outer frame borders.
44 const int kNonClientBorderThicknessPreWin10 = 3;
45 const int kNonClientBorderThicknessWin10 = 1;
46 // Besides the frame border, there's another 9 px of empty space atop the
47 // window in restored mode, to use to drag the window around.
48 const int kNonClientRestoredExtraThickness = 9;
49 // In the window corners, the resize areas don't actually expand bigger, but the
50 // 16 px at the end of the top and bottom edges triggers diagonal resizing.
51 const int kResizeAreaCornerSize = 16;
52 // The avatar ends 2 px above the bottom of the tabstrip (which, given the
53 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
54 // user).
55 const int kAvatarBottomSpacing = 2;
56 // Space between the frame border and the left edge of the avatar.
57 const int kAvatarLeftSpacing = 2;
58 // Space between the right edge of the avatar and the tabstrip.
59 const int kAvatarRightSpacing = -2;
60 // How far the new avatar button is from the left of the minimize button.
61 const int kNewAvatarButtonOffset = 5;
62 // The content left/right images have a shadow built into them.
63 const int kContentEdgeShadowThickness = 2;
64 // In restored mode, the New Tab button isn't at the same height as the caption
65 // buttons, but the space will look cluttered if it actually slides under them,
66 // so we stop it when the gap between the two is down to 5 px.
67 const int kNewTabCaptionRestoredSpacing = 5;
68 // In maximized mode, where the New Tab button and the caption buttons are at
69 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid
70 // looking too cluttered.
71 const int kNewTabCaptionMaximizedSpacing = 16;
72 // How far to indent the tabstrip from the left side of the screen when there
73 // is no avatar icon.
74 const int kTabStripIndent = -6;
76 // Converts the |image| to a Windows icon and returns the corresponding HICON
77 // handle. |image| is resized to desired |width| and |height| if needed.
78 HICON CreateHICONFromSkBitmapSizedTo(const gfx::ImageSkia& image,
79 int width,
80 int height) {
81 if (width == image.width() && height == image.height())
82 return IconUtil::CreateHICONFromSkBitmap(*image.bitmap());
83 return IconUtil::CreateHICONFromSkBitmap(skia::ImageOperations::Resize(
84 *image.bitmap(), skia::ImageOperations::RESIZE_BEST, width, height));
87 } // namespace
89 ///////////////////////////////////////////////////////////////////////////////
90 // GlassBrowserFrameView, public:
92 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame,
93 BrowserView* browser_view)
94 : BrowserNonClientFrameView(frame, browser_view),
95 throbber_running_(false),
96 throbber_frame_(0) {
97 if (browser_view->ShouldShowWindowIcon())
98 InitThrobberIcons();
100 UpdateAvatar();
103 GlassBrowserFrameView::~GlassBrowserFrameView() {
106 ///////////////////////////////////////////////////////////////////////////////
107 // GlassBrowserFrameView, BrowserNonClientFrameView implementation:
109 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip(
110 views::View* tabstrip) const {
111 int minimize_button_offset =
112 std::min(frame()->GetMinimizeButtonOffset(), width());
114 // The new avatar button is optionally displayed to the left of the
115 // minimize button.
116 if (new_avatar_button()) {
117 DCHECK(switches::IsNewAvatarMenu());
118 minimize_button_offset -=
119 new_avatar_button()->width() + kNewAvatarButtonOffset;
121 // In non-maximized mode, allow the new tab button to completely slide under
122 // the avatar button.
123 if (!frame()->IsMaximized() && !base::i18n::IsRTL()) {
124 minimize_button_offset +=
125 TabStrip::kNewTabButtonAssetWidth + kNewTabCaptionRestoredSpacing;
129 int tabstrip_x = browser_view()->ShouldShowAvatar() ?
130 (avatar_bounds_.right() + kAvatarRightSpacing) :
131 NonClientBorderThickness() + kTabStripIndent;
132 // In RTL languages, we have moved an avatar icon left by the size of window
133 // controls to prevent it from being rendered over them. So, we use its x
134 // position to move this tab strip left when maximized. Also, we can render
135 // a tab strip until the left end of this window without considering the size
136 // of window controls in RTL languages.
137 if (base::i18n::IsRTL()) {
138 if (!browser_view()->ShouldShowAvatar() && frame()->IsMaximized()) {
139 tabstrip_x += avatar_bounds_.x();
140 } else if (browser_view()->IsRegularOrGuestSession() &&
141 switches::IsNewAvatarMenu()) {
142 tabstrip_x = width() - minimize_button_offset;
145 minimize_button_offset = width();
147 int tabstrip_width = minimize_button_offset - tabstrip_x -
148 (frame()->IsMaximized() ?
149 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing);
150 return gfx::Rect(tabstrip_x, NonClientTopBorderHeight(),
151 std::max(0, tabstrip_width),
152 tabstrip->GetPreferredSize().height());
155 int GlassBrowserFrameView::GetTopInset() const {
156 return GetClientAreaInsets().top();
159 int GlassBrowserFrameView::GetThemeBackgroundXInset() const {
160 return 0;
163 void GlassBrowserFrameView::UpdateThrobber(bool running) {
164 if (throbber_running_) {
165 if (running) {
166 DisplayNextThrobberFrame();
167 } else {
168 StopThrobber();
170 } else if (running) {
171 StartThrobber();
175 gfx::Size GlassBrowserFrameView::GetMinimumSize() const {
176 gfx::Size min_size(browser_view()->GetMinimumSize());
178 // Account for the client area insets.
179 gfx::Insets insets = GetClientAreaInsets();
180 min_size.Enlarge(insets.width(), insets.height());
181 // Client area insets do not include the shadow thickness.
182 min_size.Enlarge(2 * kContentEdgeShadowThickness, 0);
184 // Ensure that the minimum width is enough to hold a tab strip with minimum
185 // width at its usual insets.
186 if (browser_view()->IsTabStripVisible()) {
187 TabStrip* tabstrip = browser_view()->tabstrip();
188 int min_tabstrip_width = tabstrip->GetMinimumSize().width();
189 int min_tabstrip_area_width =
190 width() - GetBoundsForTabStrip(tabstrip).width() + min_tabstrip_width;
191 min_size.set_width(std::max(min_tabstrip_area_width, min_size.width()));
194 return min_size;
197 ///////////////////////////////////////////////////////////////////////////////
198 // GlassBrowserFrameView, views::NonClientFrameView implementation:
200 gfx::Rect GlassBrowserFrameView::GetBoundsForClientView() const {
201 return client_view_bounds_;
204 gfx::Rect GlassBrowserFrameView::GetWindowBoundsForClientBounds(
205 const gfx::Rect& client_bounds) const {
206 HWND hwnd = views::HWNDForWidget(frame());
207 if (!browser_view()->IsTabStripVisible() && hwnd) {
208 // If we don't have a tabstrip, we're either a popup or an app window, in
209 // which case we have a standard size non-client area and can just use
210 // AdjustWindowRectEx to obtain it. We check for a non-null window handle in
211 // case this gets called before the window is actually created.
212 RECT rect = client_bounds.ToRECT();
213 AdjustWindowRectEx(&rect, GetWindowLong(hwnd, GWL_STYLE), FALSE,
214 GetWindowLong(hwnd, GWL_EXSTYLE));
215 return gfx::Rect(rect);
218 gfx::Insets insets = GetClientAreaInsets();
219 return gfx::Rect(std::max(0, client_bounds.x() - insets.left()),
220 std::max(0, client_bounds.y() - insets.top()),
221 client_bounds.width() + insets.width(),
222 client_bounds.height() + insets.height());
225 int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
226 // If the browser isn't in normal mode, we haven't customized the frame, so
227 // Windows can figure this out. If the point isn't within our bounds, then
228 // it's in the native portion of the frame, so again Windows can figure it
229 // out.
230 if (!browser_view()->IsBrowserTypeNormal() || !bounds().Contains(point))
231 return HTNOWHERE;
233 // See if the point is within the avatar menu button or within the avatar
234 // label.
235 if (avatar_button() && avatar_button()->GetMirroredBounds().Contains(point))
236 return HTCLIENT;
238 if (new_avatar_button() &&
239 new_avatar_button()->GetMirroredBounds().Contains(point))
240 return HTCLIENT;
242 int frame_component = frame()->client_view()->NonClientHitTest(point);
244 // See if we're in the sysmenu region. We still have to check the tabstrip
245 // first so that clicks in a tab don't get treated as sysmenu clicks.
246 int nonclient_border_thickness = NonClientBorderThickness();
247 if (gfx::Rect(nonclient_border_thickness,
248 gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME),
249 gfx::win::GetSystemMetricsInDIP(SM_CXSMICON),
250 gfx::win::GetSystemMetricsInDIP(SM_CYSMICON)).Contains(point))
251 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
253 if (frame_component != HTNOWHERE)
254 return frame_component;
256 int frame_border_thickness = FrameBorderThickness();
257 int window_component = GetHTComponentForFrame(point, frame_border_thickness,
258 nonclient_border_thickness, frame_border_thickness,
259 kResizeAreaCornerSize - frame_border_thickness,
260 frame()->widget_delegate()->CanResize());
261 // Fall back to the caption if no other component matches.
262 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
265 ///////////////////////////////////////////////////////////////////////////////
266 // GlassBrowserFrameView, views::View overrides:
268 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
269 if (browser_view()->IsToolbarVisible() &&
270 browser_view()->toolbar()->ShouldPaintBackground())
271 PaintToolbarBackground(canvas);
272 if (!frame()->IsMaximized())
273 PaintRestoredClientEdge(canvas);
276 void GlassBrowserFrameView::Layout() {
277 if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu())
278 LayoutNewStyleAvatar();
279 else
280 LayoutAvatar();
282 LayoutClientView();
285 ///////////////////////////////////////////////////////////////////////////////
286 // GlassBrowserFrameView, protected:
288 // views::ButtonListener:
289 void GlassBrowserFrameView::ButtonPressed(views::Button* sender,
290 const ui::Event& event) {
291 if (sender == new_avatar_button()) {
292 BrowserWindow::AvatarBubbleMode mode =
293 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT;
294 if ((event.IsMouseEvent() &&
295 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) ||
296 (event.type() == ui::ET_GESTURE_LONG_PRESS)) {
297 mode = BrowserWindow::AVATAR_BUBBLE_MODE_FAST_USER_SWITCH;
299 browser_view()->ShowAvatarBubbleFromAvatarButton(
300 mode,
301 signin::ManageAccountsParams());
305 // BrowserNonClientFrameView:
306 void GlassBrowserFrameView::UpdateNewAvatarButtonImpl() {
307 UpdateNewAvatarButton(this, NewAvatarButton::NATIVE_BUTTON);
310 ///////////////////////////////////////////////////////////////////////////////
311 // GlassBrowserFrameView, private:
313 // views::NonClientFrameView:
314 bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target,
315 const gfx::Rect& rect) const {
316 CHECK_EQ(target, this);
317 bool hit_avatar_button = avatar_button() &&
318 avatar_button()->GetMirroredBounds().Intersects(rect);
319 bool hit_new_avatar_button = new_avatar_button() &&
320 new_avatar_button()->GetMirroredBounds().Intersects(rect);
321 return hit_avatar_button || hit_new_avatar_button ||
322 !frame()->client_view()->bounds().Intersects(rect);
325 int GlassBrowserFrameView::FrameBorderThickness() const {
326 return (frame()->IsMaximized() || frame()->IsFullscreen()) ?
327 0 : gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
330 int GlassBrowserFrameView::NonClientBorderThickness() const {
331 if (frame()->IsMaximized() || frame()->IsFullscreen())
332 return 0;
334 return (base::win::GetVersion() <= base::win::VERSION_WIN8_1)
335 ? kNonClientBorderThicknessPreWin10
336 : kNonClientBorderThicknessWin10;
339 int GlassBrowserFrameView::NonClientTopBorderHeight() const {
340 if (frame()->IsFullscreen())
341 return 0;
343 // We'd like to use FrameBorderThickness() here, but the maximized Aero glass
344 // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border
345 // at the top (see AeroGlassFrame::OnGetMinMaxInfo()).
346 return gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME) +
347 (!frame()->ShouldLeaveOffsetNearTopBorder() ?
348 -GetLayoutConstant(TABSTRIP_TOP_SHADOW_HEIGHT) :
349 kNonClientRestoredExtraThickness);
352 void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) {
353 ui::ThemeProvider* tp = GetThemeProvider();
355 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
356 gfx::Point toolbar_origin(toolbar_bounds.origin());
357 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin);
358 toolbar_bounds.set_origin(toolbar_origin);
359 int x = toolbar_bounds.x();
360 int w = toolbar_bounds.width();
362 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
363 gfx::ImageSkia* toolbar_center = tp->GetImageSkiaNamed(
364 IDR_CONTENT_TOP_CENTER);
366 // Tile the toolbar image starting at the frame edge on the left and where
367 // the tabstrip is on the top.
368 int y = toolbar_bounds.y();
369 int dest_y = browser_view()->IsTabStripVisible()
370 ? y + (kFrameShadowThickness * 2)
371 : y;
372 canvas->TileImageInt(*theme_toolbar,
373 x + GetThemeBackgroundXInset(),
374 dest_y - GetTopInset(), x,
375 dest_y, w, theme_toolbar->height());
377 if (browser_view()->IsTabStripVisible()) {
378 // On Windows 10, we don't draw our own window border but rather go right to
379 // the system border, so we don't need to draw the toolbar edges.
380 if (base::win::GetVersion() < base::win::VERSION_WIN10) {
381 int left_x = x - kContentEdgeShadowThickness;
382 // Draw rounded corners for the tab.
383 gfx::ImageSkia* toolbar_left_mask =
384 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK);
385 gfx::ImageSkia* toolbar_right_mask =
386 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK);
388 // We mask out the corners by using the DestinationIn transfer mode,
389 // which keeps the RGB pixels from the destination and the alpha from
390 // the source.
391 SkPaint paint;
392 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
394 // Mask out the top left corner.
395 canvas->DrawImageInt(*toolbar_left_mask, left_x, y, paint);
397 // Mask out the top right corner.
398 int right_x =
399 x + w + kContentEdgeShadowThickness - toolbar_right_mask->width();
400 canvas->DrawImageInt(*toolbar_right_mask, right_x, y, paint);
402 // Draw left edge.
403 gfx::ImageSkia* toolbar_left =
404 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER);
405 canvas->DrawImageInt(*toolbar_left, left_x, y);
407 // Draw center edge.
408 canvas->TileImageInt(*toolbar_center, left_x + toolbar_left->width(), y,
409 right_x - (left_x + toolbar_left->width()),
410 toolbar_center->height());
412 // Right edge.
413 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER),
414 right_x, y);
415 } else {
416 canvas->TileImageInt(*toolbar_center, x, y, w, toolbar_center->height());
420 // Draw the content/toolbar separator.
421 if (ui::MaterialDesignController::IsModeMaterial()) {
422 toolbar_bounds.Inset(kClientEdgeThickness, 0);
423 BrowserView::Paint1pxHorizontalLine(
424 canvas,
425 ThemeProperties::GetDefaultColor(
426 ThemeProperties::COLOR_TOOLBAR_SEPARATOR),
427 toolbar_bounds);
428 } else {
429 canvas->FillRect(
430 gfx::Rect(x + kClientEdgeThickness,
431 toolbar_bounds.bottom() - kClientEdgeThickness,
432 w - (2 * kClientEdgeThickness),
433 kClientEdgeThickness),
434 ThemeProperties::GetDefaultColor(
435 ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
439 void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
440 ui::ThemeProvider* tp = GetThemeProvider();
441 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height());
443 // The client edges start below the toolbar upper corner images regardless
444 // of how tall the toolbar itself is.
445 int client_area_top = frame()->client_view()->y() +
446 browser_view()->GetToolbarBounds().y() +
447 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER)->height();
448 int client_area_bottom =
449 std::max(client_area_top, height() - NonClientBorderThickness());
450 int client_area_height = client_area_bottom - client_area_top;
452 // Draw the client edge images.
453 gfx::ImageSkia* right = tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE);
454 canvas->TileImageInt(*right, client_area_bounds.right(), client_area_top,
455 right->width(), client_area_height);
456 canvas->DrawImageInt(
457 *tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER),
458 client_area_bounds.right(), client_area_bottom);
459 gfx::ImageSkia* bottom = tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER);
460 canvas->TileImageInt(*bottom, client_area_bounds.x(),
461 client_area_bottom, client_area_bounds.width(),
462 bottom->height());
463 gfx::ImageSkia* bottom_left =
464 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER);
465 canvas->DrawImageInt(*bottom_left,
466 client_area_bounds.x() - bottom_left->width(), client_area_bottom);
467 gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE);
468 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
469 client_area_top, left->width(), client_area_height);
471 // Draw the toolbar color so that the client edges show the right color even
472 // where not covered by the toolbar image. NOTE: We do this after drawing the
473 // images because the images are meant to alpha-blend atop the frame whereas
474 // these rects are meant to be fully opaque, without anything overlaid.
475 SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
476 canvas->FillRect(gfx::Rect(client_area_bounds.x() - kClientEdgeThickness,
477 client_area_top, kClientEdgeThickness,
478 client_area_bottom + kClientEdgeThickness - client_area_top),
479 toolbar_color);
480 canvas->FillRect(gfx::Rect(client_area_bounds.x(), client_area_bottom,
481 client_area_bounds.width(), kClientEdgeThickness),
482 toolbar_color);
483 canvas->FillRect(gfx::Rect(client_area_bounds.right(), client_area_top,
484 kClientEdgeThickness,
485 client_area_bottom + kClientEdgeThickness - client_area_top),
486 toolbar_color);
489 void GlassBrowserFrameView::LayoutNewStyleAvatar() {
490 DCHECK(switches::IsNewAvatarMenu());
491 if (!new_avatar_button())
492 return;
494 gfx::Size label_size = new_avatar_button()->GetPreferredSize();
496 int button_x = frame()->GetMinimizeButtonOffset() -
497 kNewAvatarButtonOffset - label_size.width();
498 if (base::i18n::IsRTL())
499 button_x = width() - frame()->GetMinimizeButtonOffset() +
500 kNewAvatarButtonOffset;
502 // We need to offset the button correctly in maximized mode, so that the
503 // custom glass style aligns with the native control glass style. The
504 // glass shadow is off by 1px, which was determined by visual inspection.
505 const int shadow_height = GetLayoutConstant(TABSTRIP_TOP_SHADOW_HEIGHT);
506 int button_y = frame()->IsMaximized() ?
507 (NonClientTopBorderHeight() + shadow_height - 1) : 1;
509 new_avatar_button()->SetBounds(
510 button_x,
511 button_y,
512 label_size.width(),
513 gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1);
516 void GlassBrowserFrameView::LayoutAvatar() {
517 // Even though the avatar is used for both incognito and profiles we always
518 // use the incognito icon to layout the avatar button. The profile icon
519 // can be customized so we can't depend on its size to perform layout.
520 gfx::ImageSkia incognito_icon = browser_view()->GetOTRAvatarIcon();
522 int avatar_x = NonClientBorderThickness() + kAvatarLeftSpacing;
523 // Move this avatar icon by the size of window controls to prevent it from
524 // being rendered over them in RTL languages. This code also needs to adjust
525 // the width of a tab strip to avoid decreasing this size twice. (See the
526 // comment in GetBoundsForTabStrip().)
527 if (base::i18n::IsRTL())
528 avatar_x += width() - frame()->GetMinimizeButtonOffset();
530 int avatar_bottom = GetTopInset() +
531 browser_view()->GetTabStripHeight() - kAvatarBottomSpacing;
532 int avatar_restored_y = avatar_bottom - incognito_icon.height();
533 const int shadow_height = GetLayoutConstant(TABSTRIP_TOP_SHADOW_HEIGHT);
534 int avatar_y = frame()->IsMaximized() ?
535 (NonClientTopBorderHeight() + shadow_height) : avatar_restored_y;
536 avatar_bounds_.SetRect(avatar_x, avatar_y, incognito_icon.width(),
537 browser_view()->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0);
538 if (avatar_button())
539 avatar_button()->SetBoundsRect(avatar_bounds_);
542 void GlassBrowserFrameView::LayoutClientView() {
543 client_view_bounds_ = CalculateClientAreaBounds(width(), height());
546 gfx::Insets GlassBrowserFrameView::GetClientAreaInsets() const {
547 if (!browser_view()->IsTabStripVisible())
548 return gfx::Insets();
550 const int top_height = NonClientTopBorderHeight();
551 const int border_thickness = NonClientBorderThickness();
552 return gfx::Insets(top_height,
553 border_thickness,
554 border_thickness,
555 border_thickness);
558 gfx::Rect GlassBrowserFrameView::CalculateClientAreaBounds(int width,
559 int height) const {
560 gfx::Rect bounds(0, 0, width, height);
561 bounds.Inset(GetClientAreaInsets());
562 return bounds;
565 void GlassBrowserFrameView::StartThrobber() {
566 if (!throbber_running_) {
567 throbber_running_ = true;
568 throbber_frame_ = 0;
569 InitThrobberIcons();
570 SendMessage(views::HWNDForWidget(frame()), WM_SETICON,
571 static_cast<WPARAM>(ICON_SMALL),
572 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_]));
576 void GlassBrowserFrameView::StopThrobber() {
577 if (throbber_running_) {
578 throbber_running_ = false;
580 HICON small_icon = nullptr;
581 HICON big_icon = nullptr;
583 // Check if hosted BrowserView has a window icon to use.
584 if (browser_view()->ShouldShowWindowIcon()) {
585 gfx::ImageSkia icon = browser_view()->GetWindowIcon();
586 if (!icon.isNull()) {
587 small_icon = CreateHICONFromSkBitmapSizedTo(
588 icon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
589 big_icon = CreateHICONFromSkBitmapSizedTo(
590 icon, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
594 // Fallback to class icon.
595 if (!small_icon) {
596 small_icon = reinterpret_cast<HICON>(
597 GetClassLongPtr(views::HWNDForWidget(frame()), GCLP_HICONSM));
599 if (!big_icon) {
600 big_icon = reinterpret_cast<HICON>(
601 GetClassLongPtr(views::HWNDForWidget(frame()), GCLP_HICON));
604 // This will reset the icon which we set in the throbber code.
605 // WM_SETICON with null icon restores the icon for title bar but not
606 // for taskbar. See http://crbug.com/29996
607 HICON previous_small_icon = reinterpret_cast<HICON>(
608 SendMessage(views::HWNDForWidget(frame()), WM_SETICON,
609 static_cast<WPARAM>(ICON_SMALL),
610 reinterpret_cast<LPARAM>(small_icon)));
612 HICON previous_big_icon = reinterpret_cast<HICON>(
613 SendMessage(views::HWNDForWidget(frame()), WM_SETICON,
614 static_cast<WPARAM>(ICON_BIG),
615 reinterpret_cast<LPARAM>(big_icon)));
617 if (previous_small_icon)
618 ::DestroyIcon(previous_small_icon);
620 if (previous_big_icon)
621 ::DestroyIcon(previous_big_icon);
625 void GlassBrowserFrameView::DisplayNextThrobberFrame() {
626 throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount;
627 SendMessage(views::HWNDForWidget(frame()), WM_SETICON,
628 static_cast<WPARAM>(ICON_SMALL),
629 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_]));
632 // static
633 void GlassBrowserFrameView::InitThrobberIcons() {
634 static bool initialized = false;
635 if (!initialized) {
636 for (int i = 0; i < kThrobberIconCount; ++i) {
637 throbber_icons_[i] =
638 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i);
639 DCHECK(throbber_icons_[i]);
641 initialized = true;