Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / glass_browser_frame_view.cc
blobae8d6f72541850731250e92616c24432e7ada3a4
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/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/browser/signin_header_helper.h"
21 #include "components/signin/core/common/profile_management_switches.h"
22 #include "grit/theme_resources.h"
23 #include "skia/ext/image_operations.h"
24 #include "ui/base/resource/material_design/material_design_controller.h"
25 #include "ui/base/resource/resource_bundle_win.h"
26 #include "ui/base/theme_provider.h"
27 #include "ui/gfx/canvas.h"
28 #include "ui/gfx/icon_util.h"
29 #include "ui/gfx/image/image.h"
30 #include "ui/gfx/win/dpi.h"
31 #include "ui/resources/grit/ui_resources.h"
32 #include "ui/views/controls/label.h"
33 #include "ui/views/layout/layout_constants.h"
34 #include "ui/views/resources/grit/views_resources.h"
35 #include "ui/views/win/hwnd_util.h"
36 #include "ui/views/window/client_view.h"
38 HICON GlassBrowserFrameView::throbber_icons_[
39 GlassBrowserFrameView::kThrobberIconCount];
41 namespace {
42 // Size of client edge drawn inside the outer frame borders.
43 const int kNonClientBorderThicknessPreWin10 = 3;
44 const int kNonClientBorderThicknessWin10 = 1;
45 // Besides the frame border, there's another 9 px of empty space atop the
46 // window in restored mode, to use to drag the window around.
47 const int kNonClientRestoredExtraThickness = 9;
48 // In the window corners, the resize areas don't actually expand bigger, but the
49 // 16 px at the end of the top and bottom edges triggers diagonal resizing.
50 const int kResizeAreaCornerSize = 16;
51 // The avatar ends 2 px above the bottom of the tabstrip (which, given the
52 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
53 // user).
54 const int kAvatarBottomSpacing = 2;
55 // Space between the frame border and the left edge of the avatar.
56 const int kAvatarLeftSpacing = 2;
57 // Space between the right edge of the avatar and the tabstrip.
58 const int kAvatarRightSpacing = -2;
59 // How far the new avatar button is from the left of the minimize button.
60 const int kNewAvatarButtonOffset = 5;
61 // The content left/right images have a shadow built into them.
62 const int kContentEdgeShadowThickness = 2;
63 // The top 3 px of the tabstrip is shadow; in maximized mode we push this off
64 // the top of the screen so the tabs appear flush against the screen edge.
65 const int kTabstripTopShadowThickness = 3;
66 // In restored mode, the New Tab button isn't at the same height as the caption
67 // buttons, but the space will look cluttered if it actually slides under them,
68 // so we stop it when the gap between the two is down to 5 px.
69 const int kNewTabCaptionRestoredSpacing = 5;
70 // In maximized mode, where the New Tab button and the caption buttons are at
71 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid
72 // looking too cluttered.
73 const int kNewTabCaptionMaximizedSpacing = 16;
74 // How far to indent the tabstrip from the left side of the screen when there
75 // is no avatar icon.
76 const int kTabStripIndent = -6;
78 // Converts the |image| to a Windows icon and returns the corresponding HICON
79 // handle. |image| is resized to desired |width| and |height| if needed.
80 HICON CreateHICONFromSkBitmapSizedTo(const gfx::ImageSkia& image,
81 int width,
82 int height) {
83 if (width == image.width() && height == image.height())
84 return IconUtil::CreateHICONFromSkBitmap(*image.bitmap());
85 return IconUtil::CreateHICONFromSkBitmap(skia::ImageOperations::Resize(
86 *image.bitmap(), skia::ImageOperations::RESIZE_BEST, width, height));
89 } // namespace
91 ///////////////////////////////////////////////////////////////////////////////
92 // GlassBrowserFrameView, public:
94 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame,
95 BrowserView* browser_view)
96 : BrowserNonClientFrameView(frame, browser_view),
97 throbber_running_(false),
98 throbber_frame_(0) {
99 if (browser_view->ShouldShowWindowIcon())
100 InitThrobberIcons();
102 UpdateAvatar();
105 GlassBrowserFrameView::~GlassBrowserFrameView() {
108 ///////////////////////////////////////////////////////////////////////////////
109 // GlassBrowserFrameView, BrowserNonClientFrameView implementation:
111 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip(
112 views::View* tabstrip) const {
113 int minimize_button_offset =
114 std::min(frame()->GetMinimizeButtonOffset(), width());
116 // The new avatar button is optionally displayed to the left of the
117 // minimize button.
118 if (new_avatar_button()) {
119 DCHECK(switches::IsNewAvatarMenu());
120 minimize_button_offset -=
121 new_avatar_button()->width() + kNewAvatarButtonOffset;
123 // In non-maximized mode, allow the new tab button to completely slide under
124 // the avatar button.
125 if (!frame()->IsMaximized() && !base::i18n::IsRTL()) {
126 minimize_button_offset +=
127 TabStrip::kNewTabButtonAssetWidth + kNewTabCaptionRestoredSpacing;
131 int tabstrip_x = browser_view()->ShouldShowAvatar() ?
132 (avatar_bounds_.right() + kAvatarRightSpacing) :
133 NonClientBorderThickness() + kTabStripIndent;
134 // In RTL languages, we have moved an avatar icon left by the size of window
135 // controls to prevent it from being rendered over them. So, we use its x
136 // position to move this tab strip left when maximized. Also, we can render
137 // a tab strip until the left end of this window without considering the size
138 // of window controls in RTL languages.
139 if (base::i18n::IsRTL()) {
140 if (!browser_view()->ShouldShowAvatar() && frame()->IsMaximized()) {
141 tabstrip_x += avatar_bounds_.x();
142 } else if (browser_view()->IsRegularOrGuestSession() &&
143 switches::IsNewAvatarMenu()) {
144 tabstrip_x = width() - minimize_button_offset;
147 minimize_button_offset = width();
149 int tabstrip_width = minimize_button_offset - tabstrip_x -
150 (frame()->IsMaximized() ?
151 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing);
152 return gfx::Rect(tabstrip_x, NonClientTopBorderHeight(),
153 std::max(0, tabstrip_width),
154 tabstrip->GetPreferredSize().height());
157 int GlassBrowserFrameView::GetTopInset() const {
158 return GetClientAreaInsets().top();
161 int GlassBrowserFrameView::GetThemeBackgroundXInset() const {
162 return 0;
165 void GlassBrowserFrameView::UpdateThrobber(bool running) {
166 if (throbber_running_) {
167 if (running) {
168 DisplayNextThrobberFrame();
169 } else {
170 StopThrobber();
172 } else if (running) {
173 StartThrobber();
177 gfx::Size GlassBrowserFrameView::GetMinimumSize() const {
178 gfx::Size min_size(browser_view()->GetMinimumSize());
180 // Account for the client area insets.
181 gfx::Insets insets = GetClientAreaInsets();
182 min_size.Enlarge(insets.width(), insets.height());
183 // Client area insets do not include the shadow thickness.
184 min_size.Enlarge(2 * kContentEdgeShadowThickness, 0);
186 // Ensure that the minimum width is enough to hold a tab strip with minimum
187 // width at its usual insets.
188 if (browser_view()->IsTabStripVisible()) {
189 TabStrip* tabstrip = browser_view()->tabstrip();
190 int min_tabstrip_width = tabstrip->GetMinimumSize().width();
191 int min_tabstrip_area_width =
192 width() - GetBoundsForTabStrip(tabstrip).width() + min_tabstrip_width;
193 min_size.set_width(std::max(min_tabstrip_area_width, min_size.width()));
196 return min_size;
199 ///////////////////////////////////////////////////////////////////////////////
200 // GlassBrowserFrameView, views::NonClientFrameView implementation:
202 gfx::Rect GlassBrowserFrameView::GetBoundsForClientView() const {
203 return client_view_bounds_;
206 gfx::Rect GlassBrowserFrameView::GetWindowBoundsForClientBounds(
207 const gfx::Rect& client_bounds) const {
208 HWND hwnd = views::HWNDForWidget(frame());
209 if (!browser_view()->IsTabStripVisible() && hwnd) {
210 // If we don't have a tabstrip, we're either a popup or an app window, in
211 // which case we have a standard size non-client area and can just use
212 // AdjustWindowRectEx to obtain it. We check for a non-null window handle in
213 // case this gets called before the window is actually created.
214 RECT rect = client_bounds.ToRECT();
215 AdjustWindowRectEx(&rect, GetWindowLong(hwnd, GWL_STYLE), FALSE,
216 GetWindowLong(hwnd, GWL_EXSTYLE));
217 return gfx::Rect(rect);
220 gfx::Insets insets = GetClientAreaInsets();
221 return gfx::Rect(std::max(0, client_bounds.x() - insets.left()),
222 std::max(0, client_bounds.y() - insets.top()),
223 client_bounds.width() + insets.width(),
224 client_bounds.height() + insets.height());
227 int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
228 // If the browser isn't in normal mode, we haven't customized the frame, so
229 // Windows can figure this out. If the point isn't within our bounds, then
230 // it's in the native portion of the frame, so again Windows can figure it
231 // out.
232 if (!browser_view()->IsBrowserTypeNormal() || !bounds().Contains(point))
233 return HTNOWHERE;
235 // See if the point is within the avatar menu button or within the avatar
236 // label.
237 if (avatar_button() && avatar_button()->GetMirroredBounds().Contains(point))
238 return HTCLIENT;
240 if (new_avatar_button() &&
241 new_avatar_button()->GetMirroredBounds().Contains(point))
242 return HTCLIENT;
244 int frame_component = frame()->client_view()->NonClientHitTest(point);
246 // See if we're in the sysmenu region. We still have to check the tabstrip
247 // first so that clicks in a tab don't get treated as sysmenu clicks.
248 int nonclient_border_thickness = NonClientBorderThickness();
249 if (gfx::Rect(nonclient_border_thickness,
250 gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME),
251 gfx::win::GetSystemMetricsInDIP(SM_CXSMICON),
252 gfx::win::GetSystemMetricsInDIP(SM_CYSMICON)).Contains(point))
253 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
255 if (frame_component != HTNOWHERE)
256 return frame_component;
258 int frame_border_thickness = FrameBorderThickness();
259 int window_component = GetHTComponentForFrame(point, frame_border_thickness,
260 nonclient_border_thickness, frame_border_thickness,
261 kResizeAreaCornerSize - frame_border_thickness,
262 frame()->widget_delegate()->CanResize());
263 // Fall back to the caption if no other component matches.
264 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
267 ///////////////////////////////////////////////////////////////////////////////
268 // GlassBrowserFrameView, views::View overrides:
270 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
271 if (browser_view()->IsToolbarVisible() &&
272 browser_view()->toolbar()->ShouldPaintBackground())
273 PaintToolbarBackground(canvas);
274 if (!frame()->IsMaximized())
275 PaintRestoredClientEdge(canvas);
278 void GlassBrowserFrameView::Layout() {
279 if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu())
280 LayoutNewStyleAvatar();
281 else
282 LayoutAvatar();
284 LayoutClientView();
287 ///////////////////////////////////////////////////////////////////////////////
288 // GlassBrowserFrameView, protected:
290 // views::ButtonListener:
291 void GlassBrowserFrameView::ButtonPressed(views::Button* sender,
292 const ui::Event& event) {
293 if (sender == new_avatar_button()) {
294 BrowserWindow::AvatarBubbleMode mode =
295 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT;
296 if ((event.IsMouseEvent() &&
297 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) ||
298 (event.type() == ui::ET_GESTURE_LONG_PRESS)) {
299 mode = BrowserWindow::AVATAR_BUBBLE_MODE_FAST_USER_SWITCH;
301 browser_view()->ShowAvatarBubbleFromAvatarButton(
302 mode,
303 signin::ManageAccountsParams());
307 // BrowserNonClientFrameView:
308 void GlassBrowserFrameView::UpdateNewAvatarButtonImpl() {
309 UpdateNewAvatarButton(this, NewAvatarButton::NATIVE_BUTTON);
312 ///////////////////////////////////////////////////////////////////////////////
313 // GlassBrowserFrameView, private:
315 // views::NonClientFrameView:
316 bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target,
317 const gfx::Rect& rect) const {
318 CHECK_EQ(target, this);
319 bool hit_avatar_button = avatar_button() &&
320 avatar_button()->GetMirroredBounds().Intersects(rect);
321 bool hit_new_avatar_button = new_avatar_button() &&
322 new_avatar_button()->GetMirroredBounds().Intersects(rect);
323 return hit_avatar_button || hit_new_avatar_button ||
324 !frame()->client_view()->bounds().Intersects(rect);
327 int GlassBrowserFrameView::FrameBorderThickness() const {
328 return (frame()->IsMaximized() || frame()->IsFullscreen()) ?
329 0 : gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
332 int GlassBrowserFrameView::NonClientBorderThickness() const {
333 if (frame()->IsMaximized() || frame()->IsFullscreen())
334 return 0;
336 return (base::win::GetVersion() <= base::win::VERSION_WIN8_1)
337 ? kNonClientBorderThicknessPreWin10
338 : kNonClientBorderThicknessWin10;
341 int GlassBrowserFrameView::NonClientTopBorderHeight() const {
342 if (frame()->IsFullscreen())
343 return 0;
345 // We'd like to use FrameBorderThickness() here, but the maximized Aero glass
346 // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border
347 // at the top (see AeroGlassFrame::OnGetMinMaxInfo()).
348 return gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME) +
349 (!frame()->ShouldLeaveOffsetNearTopBorder() ?
350 -kTabstripTopShadowThickness : kNonClientRestoredExtraThickness);
353 void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) {
354 ui::ThemeProvider* tp = GetThemeProvider();
356 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
357 gfx::Point toolbar_origin(toolbar_bounds.origin());
358 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin);
359 toolbar_bounds.set_origin(toolbar_origin);
360 int x = toolbar_bounds.x();
361 int w = toolbar_bounds.width();
363 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
364 gfx::ImageSkia* toolbar_center = tp->GetImageSkiaNamed(
365 IDR_CONTENT_TOP_CENTER);
367 // Tile the toolbar image starting at the frame edge on the left and where
368 // the tabstrip is on the top.
369 int y = toolbar_bounds.y();
370 int dest_y = browser_view()->IsTabStripVisible()
371 ? y + (kFrameShadowThickness * 2)
372 : y;
373 canvas->TileImageInt(*theme_toolbar,
374 x + GetThemeBackgroundXInset(),
375 dest_y - GetTopInset(), x,
376 dest_y, w, theme_toolbar->height());
378 if (browser_view()->IsTabStripVisible()) {
379 // On Windows 10, we don't draw our own window border but rather go right to
380 // the system border, so we don't need to draw the toolbar edges.
381 if (base::win::GetVersion() < base::win::VERSION_WIN10) {
382 int left_x = x - kContentEdgeShadowThickness;
383 // Draw rounded corners for the tab.
384 gfx::ImageSkia* toolbar_left_mask =
385 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK);
386 gfx::ImageSkia* toolbar_right_mask =
387 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK);
389 // We mask out the corners by using the DestinationIn transfer mode,
390 // which keeps the RGB pixels from the destination and the alpha from
391 // the source.
392 SkPaint paint;
393 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
395 // Mask out the top left corner.
396 canvas->DrawImageInt(*toolbar_left_mask, left_x, y, paint);
398 // Mask out the top right corner.
399 int right_x =
400 x + w + kContentEdgeShadowThickness - toolbar_right_mask->width();
401 canvas->DrawImageInt(*toolbar_right_mask, right_x, y, paint);
403 // Draw left edge.
404 gfx::ImageSkia* toolbar_left =
405 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER);
406 canvas->DrawImageInt(*toolbar_left, left_x, y);
408 // Draw center edge.
409 canvas->TileImageInt(*toolbar_center, left_x + toolbar_left->width(), y,
410 right_x - (left_x + toolbar_left->width()),
411 toolbar_center->height());
413 // Right edge.
414 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER),
415 right_x, y);
416 } else {
417 canvas->TileImageInt(*toolbar_center, x, y, w, toolbar_center->height());
421 // Draw the content/toolbar separator.
422 if (ui::MaterialDesignController::IsModeMaterial()) {
423 toolbar_bounds.Inset(kClientEdgeThickness, 0);
424 BrowserView::Paint1pxHorizontalLine(
425 canvas,
426 ThemeProperties::GetDefaultColor(
427 ThemeProperties::COLOR_TOOLBAR_SEPARATOR),
428 toolbar_bounds);
429 } else {
430 canvas->FillRect(
431 gfx::Rect(x + kClientEdgeThickness,
432 toolbar_bounds.bottom() - kClientEdgeThickness,
433 w - (2 * kClientEdgeThickness),
434 kClientEdgeThickness),
435 ThemeProperties::GetDefaultColor(
436 ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
440 void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
441 ui::ThemeProvider* tp = GetThemeProvider();
442 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height());
444 // The client edges start below the toolbar upper corner images regardless
445 // of how tall the toolbar itself is.
446 int client_area_top = frame()->client_view()->y() +
447 browser_view()->GetToolbarBounds().y() +
448 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER)->height();
449 int client_area_bottom =
450 std::max(client_area_top, height() - NonClientBorderThickness());
451 int client_area_height = client_area_bottom - client_area_top;
453 // Draw the client edge images.
454 gfx::ImageSkia* right = tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE);
455 canvas->TileImageInt(*right, client_area_bounds.right(), client_area_top,
456 right->width(), client_area_height);
457 canvas->DrawImageInt(
458 *tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER),
459 client_area_bounds.right(), client_area_bottom);
460 gfx::ImageSkia* bottom = tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER);
461 canvas->TileImageInt(*bottom, client_area_bounds.x(),
462 client_area_bottom, client_area_bounds.width(),
463 bottom->height());
464 gfx::ImageSkia* bottom_left =
465 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER);
466 canvas->DrawImageInt(*bottom_left,
467 client_area_bounds.x() - bottom_left->width(), client_area_bottom);
468 gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE);
469 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
470 client_area_top, left->width(), client_area_height);
472 // Draw the toolbar color so that the client edges show the right color even
473 // where not covered by the toolbar image. NOTE: We do this after drawing the
474 // images because the images are meant to alpha-blend atop the frame whereas
475 // these rects are meant to be fully opaque, without anything overlaid.
476 SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
477 canvas->FillRect(gfx::Rect(client_area_bounds.x() - kClientEdgeThickness,
478 client_area_top, kClientEdgeThickness,
479 client_area_bottom + kClientEdgeThickness - client_area_top),
480 toolbar_color);
481 canvas->FillRect(gfx::Rect(client_area_bounds.x(), client_area_bottom,
482 client_area_bounds.width(), kClientEdgeThickness),
483 toolbar_color);
484 canvas->FillRect(gfx::Rect(client_area_bounds.right(), client_area_top,
485 kClientEdgeThickness,
486 client_area_bottom + kClientEdgeThickness - client_area_top),
487 toolbar_color);
490 void GlassBrowserFrameView::LayoutNewStyleAvatar() {
491 DCHECK(switches::IsNewAvatarMenu());
492 if (!new_avatar_button())
493 return;
495 gfx::Size label_size = new_avatar_button()->GetPreferredSize();
497 int button_x = frame()->GetMinimizeButtonOffset() -
498 kNewAvatarButtonOffset - label_size.width();
499 if (base::i18n::IsRTL())
500 button_x = width() - frame()->GetMinimizeButtonOffset() +
501 kNewAvatarButtonOffset;
503 // We need to offset the button correctly in maximized mode, so that the
504 // custom glass style aligns with the native control glass style. The
505 // glass shadow is off by 1px, which was determined by visual inspection.
506 int button_y = !frame()->IsMaximized() ? 1 :
507 NonClientTopBorderHeight() + kTabstripTopShadowThickness - 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 int avatar_y = frame()->IsMaximized() ?
534 (NonClientTopBorderHeight() + kTabstripTopShadowThickness) :
535 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;