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. 4 5#include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" 6 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/chrome_notification_types.h" 12#include "chrome/browser/profiles/profile.h" 13#include "chrome/browser/signin/signin_header_helper.h" 14#include "chrome/browser/themes/theme_properties.h" 15#include "chrome/browser/ui/views/frame/browser_view.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 "chrome/common/pref_names.h" 22#include "components/signin/core/common/profile_management_switches.h" 23#include "content/public/browser/notification_service.h" 24#include "grit/generated_resources.h" 25#include "grit/theme_resources.h" 26#include "grit/ui_resources.h" 27#include "ui/base/l10n/l10n_util.h" 28#include "ui/base/resource/resource_bundle_win.h" 29#include "ui/base/theme_provider.h" 30#include "ui/gfx/canvas.h" 31#include "ui/gfx/icon_util.h" 32#include "ui/gfx/image/image.h" 33#include "ui/gfx/win/dpi.h" 34#include "ui/views/controls/label.h" 35#include "ui/views/layout/layout_constants.h" 36#include "ui/views/win/hwnd_util.h" 37#include "ui/views/window/client_view.h" 38 39HICON GlassBrowserFrameView::throbber_icons_[ 40 GlassBrowserFrameView::kThrobberIconCount]; 41 42namespace { 43// There are 3 px of client edge drawn inside the outer frame borders. 44const int kNonClientBorderThickness = 3; 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. 47const 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. 50const 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). 54const int kAvatarBottomSpacing = 2; 55// Space between the frame border and the left edge of the avatar. 56const int kAvatarLeftSpacing = 2; 57// Space between the right edge of the avatar and the tabstrip. 58const int kAvatarRightSpacing = -2; 59// How far the new avatar button is from the left of the minimize button. 60const int kNewAvatarButtonOffset = 5; 61// The content left/right images have a shadow built into them. 62const 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. 65const 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. 69const 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. 73const int kNewTabCaptionMaximizedSpacing = 16; 74// How far to indent the tabstrip from the left side of the screen when there 75// is no avatar icon. 76const int kTabStripIndent = -6; 77 78} // namespace 79 80/////////////////////////////////////////////////////////////////////////////// 81// GlassBrowserFrameView, public: 82 83GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, 84 BrowserView* browser_view) 85 : BrowserNonClientFrameView(frame, browser_view), 86 throbber_running_(false), 87 throbber_frame_(0) { 88 if (browser_view->ShouldShowWindowIcon()) 89 InitThrobberIcons(); 90 91 if (browser_view->IsRegularOrGuestSession() && switches::IsNewAvatarMenu()) 92 UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON); 93 else 94 UpdateAvatarInfo(); 95 96 if (!browser_view->IsOffTheRecord()) { 97 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 98 content::NotificationService::AllSources()); 99 } 100} 101 102GlassBrowserFrameView::~GlassBrowserFrameView() { 103} 104 105/////////////////////////////////////////////////////////////////////////////// 106// GlassBrowserFrameView, BrowserNonClientFrameView implementation: 107 108gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( 109 views::View* tabstrip) const { 110 int minimize_button_offset = 111 std::min(frame()->GetMinimizeButtonOffset(), width()); 112 113 // The new avatar button is optionally displayed to the left of the 114 // minimize button. 115 if (new_avatar_button()) { 116 DCHECK(switches::IsNewAvatarMenu()); 117 minimize_button_offset -= new_avatar_button()->width(); 118 } 119 120 int tabstrip_x = browser_view()->ShouldShowAvatar() ? 121 (avatar_bounds_.right() + kAvatarRightSpacing) : 122 NonClientBorderThickness() + kTabStripIndent; 123 // In RTL languages, we have moved an avatar icon left by the size of window 124 // controls to prevent it from being rendered over them. So, we use its x 125 // position to move this tab strip left when maximized. Also, we can render 126 // a tab strip until the left end of this window without considering the size 127 // of window controls in RTL languages. 128 if (base::i18n::IsRTL()) { 129 if (!browser_view()->ShouldShowAvatar() && frame()->IsMaximized()) { 130 tabstrip_x += avatar_bounds_.x(); 131 } else if (browser_view()->IsRegularOrGuestSession() && 132 switches::IsNewAvatarMenu()) { 133 tabstrip_x = width() - minimize_button_offset; 134 } 135 136 minimize_button_offset = width(); 137 } 138 int tabstrip_width = minimize_button_offset - tabstrip_x - 139 (frame()->IsMaximized() ? 140 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing); 141 return gfx::Rect(tabstrip_x, NonClientTopBorderHeight(), 142 std::max(0, tabstrip_width), 143 tabstrip->GetPreferredSize().height()); 144} 145 146int GlassBrowserFrameView::GetTopInset() const { 147 return GetClientAreaInsets().top(); 148} 149 150int GlassBrowserFrameView::GetThemeBackgroundXInset() const { 151 return 0; 152} 153 154void GlassBrowserFrameView::UpdateThrobber(bool running) { 155 if (throbber_running_) { 156 if (running) { 157 DisplayNextThrobberFrame(); 158 } else { 159 StopThrobber(); 160 } 161 } else if (running) { 162 StartThrobber(); 163 } 164} 165 166gfx::Size GlassBrowserFrameView::GetMinimumSize() const { 167 gfx::Size min_size(browser_view()->GetMinimumSize()); 168 169 // Account for the client area insets. 170 gfx::Insets insets = GetClientAreaInsets(); 171 min_size.Enlarge(insets.width(), insets.height()); 172 // Client area insets do not include the shadow thickness. 173 min_size.Enlarge(2 * kContentEdgeShadowThickness, 0); 174 175 // Ensure that the minimum width is enough to hold a tab strip with minimum 176 // width at its usual insets. 177 if (browser_view()->IsTabStripVisible()) { 178 TabStrip* tabstrip = browser_view()->tabstrip(); 179 int min_tabstrip_width = tabstrip->GetMinimumSize().width(); 180 int min_tabstrip_area_width = 181 width() - GetBoundsForTabStrip(tabstrip).width() + min_tabstrip_width; 182 min_size.set_width(std::max(min_tabstrip_area_width, min_size.width())); 183 } 184 185 return min_size; 186} 187 188/////////////////////////////////////////////////////////////////////////////// 189// GlassBrowserFrameView, views::NonClientFrameView implementation: 190 191gfx::Rect GlassBrowserFrameView::GetBoundsForClientView() const { 192 return client_view_bounds_; 193} 194 195gfx::Rect GlassBrowserFrameView::GetWindowBoundsForClientBounds( 196 const gfx::Rect& client_bounds) const { 197 HWND hwnd = views::HWNDForWidget(frame()); 198 if (!browser_view()->IsTabStripVisible() && hwnd) { 199 // If we don't have a tabstrip, we're either a popup or an app window, in 200 // which case we have a standard size non-client area and can just use 201 // AdjustWindowRectEx to obtain it. We check for a non-NULL window handle in 202 // case this gets called before the window is actually created. 203 RECT rect = client_bounds.ToRECT(); 204 AdjustWindowRectEx(&rect, GetWindowLong(hwnd, GWL_STYLE), FALSE, 205 GetWindowLong(hwnd, GWL_EXSTYLE)); 206 return gfx::Rect(rect); 207 } 208 209 gfx::Insets insets = GetClientAreaInsets(); 210 return gfx::Rect(std::max(0, client_bounds.x() - insets.left()), 211 std::max(0, client_bounds.y() - insets.top()), 212 client_bounds.width() + insets.width(), 213 client_bounds.height() + insets.height()); 214} 215 216int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) { 217 // If the browser isn't in normal mode, we haven't customized the frame, so 218 // Windows can figure this out. If the point isn't within our bounds, then 219 // it's in the native portion of the frame, so again Windows can figure it 220 // out. 221 if (!browser_view()->IsBrowserTypeNormal() || !bounds().Contains(point)) 222 return HTNOWHERE; 223 224 // See if the point is within the avatar menu button or within the avatar 225 // label. 226 if (avatar_button() && avatar_button()->GetMirroredBounds().Contains(point)) 227 return HTCLIENT; 228 229 if (new_avatar_button() && 230 new_avatar_button()->GetMirroredBounds().Contains(point)) 231 return HTCLIENT; 232 233 int frame_component = frame()->client_view()->NonClientHitTest(point); 234 235 // See if we're in the sysmenu region. We still have to check the tabstrip 236 // first so that clicks in a tab don't get treated as sysmenu clicks. 237 int nonclient_border_thickness = NonClientBorderThickness(); 238 if (gfx::Rect(nonclient_border_thickness, 239 gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME), 240 gfx::win::GetSystemMetricsInDIP(SM_CXSMICON), 241 gfx::win::GetSystemMetricsInDIP(SM_CYSMICON)).Contains(point)) 242 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; 243 244 if (frame_component != HTNOWHERE) 245 return frame_component; 246 247 int frame_border_thickness = FrameBorderThickness(); 248 int window_component = GetHTComponentForFrame(point, frame_border_thickness, 249 nonclient_border_thickness, frame_border_thickness, 250 kResizeAreaCornerSize - frame_border_thickness, 251 frame()->widget_delegate()->CanResize()); 252 // Fall back to the caption if no other component matches. 253 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; 254} 255 256/////////////////////////////////////////////////////////////////////////////// 257// GlassBrowserFrameView, views::View overrides: 258 259void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { 260 if (browser_view()->IsToolbarVisible() && 261 browser_view()->toolbar()->ShouldPaintBackground()) 262 PaintToolbarBackground(canvas); 263 if (!frame()->IsMaximized()) 264 PaintRestoredClientEdge(canvas); 265} 266 267void GlassBrowserFrameView::Layout() { 268 if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu()) 269 LayoutNewStyleAvatar(); 270 else 271 LayoutAvatar(); 272 273 LayoutClientView(); 274} 275 276bool GlassBrowserFrameView::HitTestRect(const gfx::Rect& rect) const { 277 bool hit_avatar_button = avatar_button() && 278 avatar_button()->GetMirroredBounds().Intersects(rect); 279 bool hit_new_avatar_button = new_avatar_button() && 280 new_avatar_button()->GetMirroredBounds().Intersects(rect); 281 return hit_avatar_button || hit_new_avatar_button || 282 !frame()->client_view()->bounds().Intersects(rect); 283} 284 285/////////////////////////////////////////////////////////////////////////////// 286// GlassBrowserFrameView, views::ButtonListener overrides: 287void GlassBrowserFrameView::ButtonPressed(views::Button* sender, 288 const ui::Event& event) { 289 if (sender == new_avatar_button()) { 290 browser_view()->ShowAvatarBubbleFromAvatarButton( 291 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT, 292 signin::ManageAccountsParams()); 293 } 294} 295 296/////////////////////////////////////////////////////////////////////////////// 297// GlassBrowserFrameView, private: 298 299int GlassBrowserFrameView::FrameBorderThickness() const { 300 return (frame()->IsMaximized() || frame()->IsFullscreen()) ? 301 0 : gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME); 302} 303 304int GlassBrowserFrameView::NonClientBorderThickness() const { 305 if (frame()->IsMaximized() || frame()->IsFullscreen()) 306 return 0; 307 308 return kNonClientBorderThickness; 309} 310 311int GlassBrowserFrameView::NonClientTopBorderHeight() const { 312 if (frame()->IsFullscreen()) 313 return 0; 314 315 // We'd like to use FrameBorderThickness() here, but the maximized Aero glass 316 // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border 317 // at the top (see AeroGlassFrame::OnGetMinMaxInfo()). 318 return gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME) + 319 (!frame()->ShouldLeaveOffsetNearTopBorder() ? 320 -kTabstripTopShadowThickness : kNonClientRestoredExtraThickness); 321} 322 323void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) { 324 ui::ThemeProvider* tp = GetThemeProvider(); 325 326 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); 327 gfx::Point toolbar_origin(toolbar_bounds.origin()); 328 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); 329 toolbar_bounds.set_origin(toolbar_origin); 330 int x = toolbar_bounds.x(); 331 int w = toolbar_bounds.width(); 332 int left_x = x - kContentEdgeShadowThickness; 333 334 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); 335 gfx::ImageSkia* toolbar_left = tp->GetImageSkiaNamed( 336 IDR_CONTENT_TOP_LEFT_CORNER); 337 gfx::ImageSkia* toolbar_center = tp->GetImageSkiaNamed( 338 IDR_CONTENT_TOP_CENTER); 339 340 // Tile the toolbar image starting at the frame edge on the left and where 341 // the tabstrip is on the top. 342 int y = toolbar_bounds.y(); 343 int dest_y = browser_view()->IsTabStripVisible() 344 ? y + (kFrameShadowThickness * 2) 345 : y; 346 canvas->TileImageInt(*theme_toolbar, 347 x + GetThemeBackgroundXInset(), 348 dest_y - GetTopInset(), x, 349 dest_y, w, theme_toolbar->height()); 350 351 if (browser_view()->IsTabStripVisible()) { 352 // Draw rounded corners for the tab. 353 gfx::ImageSkia* toolbar_left_mask = 354 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK); 355 gfx::ImageSkia* toolbar_right_mask = 356 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK); 357 358 // We mask out the corners by using the DestinationIn transfer mode, 359 // which keeps the RGB pixels from the destination and the alpha from 360 // the source. 361 SkPaint paint; 362 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); 363 364 // Mask out the top left corner. 365 canvas->DrawImageInt(*toolbar_left_mask, left_x, y, paint); 366 367 // Mask out the top right corner. 368 int right_x = 369 x + w + kContentEdgeShadowThickness - toolbar_right_mask->width(); 370 canvas->DrawImageInt(*toolbar_right_mask, right_x, y, paint); 371 372 // Draw left edge. 373 canvas->DrawImageInt(*toolbar_left, left_x, y); 374 375 // Draw center edge. 376 canvas->TileImageInt(*toolbar_center, left_x + toolbar_left->width(), y, 377 right_x - (left_x + toolbar_left->width()), toolbar_center->height()); 378 379 // Right edge. 380 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER), 381 right_x, y); 382 } 383 384 // Draw the content/toolbar separator. 385 canvas->FillRect( 386 gfx::Rect(x + kClientEdgeThickness, 387 toolbar_bounds.bottom() - kClientEdgeThickness, 388 w - (2 * kClientEdgeThickness), 389 kClientEdgeThickness), 390 ThemeProperties::GetDefaultColor( 391 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); 392} 393 394void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { 395 ui::ThemeProvider* tp = GetThemeProvider(); 396 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); 397 398 // The client edges start below the toolbar upper corner images regardless 399 // of how tall the toolbar itself is. 400 int client_area_top = frame()->client_view()->y() + 401 browser_view()->GetToolbarBounds().y() + 402 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER)->height(); 403 int client_area_bottom = 404 std::max(client_area_top, height() - NonClientBorderThickness()); 405 int client_area_height = client_area_bottom - client_area_top; 406 407 // Draw the client edge images. 408 gfx::ImageSkia* right = tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE); 409 canvas->TileImageInt(*right, client_area_bounds.right(), client_area_top, 410 right->width(), client_area_height); 411 canvas->DrawImageInt( 412 *tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER), 413 client_area_bounds.right(), client_area_bottom); 414 gfx::ImageSkia* bottom = tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER); 415 canvas->TileImageInt(*bottom, client_area_bounds.x(), 416 client_area_bottom, client_area_bounds.width(), 417 bottom->height()); 418 gfx::ImageSkia* bottom_left = 419 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER); 420 canvas->DrawImageInt(*bottom_left, 421 client_area_bounds.x() - bottom_left->width(), client_area_bottom); 422 gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE); 423 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(), 424 client_area_top, left->width(), client_area_height); 425 426 // Draw the toolbar color so that the client edges show the right color even 427 // where not covered by the toolbar image. NOTE: We do this after drawing the 428 // images because the images are meant to alpha-blend atop the frame whereas 429 // these rects are meant to be fully opaque, without anything overlaid. 430 SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); 431 canvas->FillRect(gfx::Rect(client_area_bounds.x() - kClientEdgeThickness, 432 client_area_top, kClientEdgeThickness, 433 client_area_bottom + kClientEdgeThickness - client_area_top), 434 toolbar_color); 435 canvas->FillRect(gfx::Rect(client_area_bounds.x(), client_area_bottom, 436 client_area_bounds.width(), kClientEdgeThickness), 437 toolbar_color); 438 canvas->FillRect(gfx::Rect(client_area_bounds.right(), client_area_top, 439 kClientEdgeThickness, 440 client_area_bottom + kClientEdgeThickness - client_area_top), 441 toolbar_color); 442} 443 444void GlassBrowserFrameView::LayoutNewStyleAvatar() { 445 DCHECK(switches::IsNewAvatarMenu()); 446 if (!new_avatar_button()) 447 return; 448 449 gfx::Size label_size = new_avatar_button()->GetPreferredSize(); 450 451 int button_x = frame()->GetMinimizeButtonOffset() - 452 kNewAvatarButtonOffset - label_size.width(); 453 if (base::i18n::IsRTL()) 454 button_x = width() - frame()->GetMinimizeButtonOffset() + 455 kNewAvatarButtonOffset; 456 457 // We need to offset the button correctly in maximized mode, so that the 458 // custom glass style aligns with the native control glass style. The 459 // glass shadow is off by 1px, which was determined by visual inspection. 460 int button_y = !frame()->IsMaximized() ? 1 : 461 NonClientTopBorderHeight() + kTabstripTopShadowThickness - 1; 462 463 new_avatar_button()->SetBounds( 464 button_x, 465 button_y, 466 label_size.width(), 467 gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1); 468} 469 470void GlassBrowserFrameView::LayoutAvatar() { 471 // Even though the avatar is used for both incognito and profiles we always 472 // use the incognito icon to layout the avatar button. The profile icon 473 // can be customized so we can't depend on its size to perform layout. 474 gfx::ImageSkia incognito_icon = browser_view()->GetOTRAvatarIcon(); 475 476 int avatar_x = NonClientBorderThickness() + kAvatarLeftSpacing; 477 // Move this avatar icon by the size of window controls to prevent it from 478 // being rendered over them in RTL languages. This code also needs to adjust 479 // the width of a tab strip to avoid decreasing this size twice. (See the 480 // comment in GetBoundsForTabStrip().) 481 if (base::i18n::IsRTL()) 482 avatar_x += width() - frame()->GetMinimizeButtonOffset(); 483 484 int avatar_bottom = GetTopInset() + 485 browser_view()->GetTabStripHeight() - kAvatarBottomSpacing; 486 int avatar_restored_y = avatar_bottom - incognito_icon.height(); 487 int avatar_y = frame()->IsMaximized() ? 488 (NonClientTopBorderHeight() + kTabstripTopShadowThickness) : 489 avatar_restored_y; 490 avatar_bounds_.SetRect(avatar_x, avatar_y, incognito_icon.width(), 491 browser_view()->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0); 492 if (avatar_button()) 493 avatar_button()->SetBoundsRect(avatar_bounds_); 494} 495 496void GlassBrowserFrameView::LayoutClientView() { 497 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); 498} 499 500gfx::Insets GlassBrowserFrameView::GetClientAreaInsets() const { 501 if (!browser_view()->IsTabStripVisible()) 502 return gfx::Insets(); 503 504 const int top_height = NonClientTopBorderHeight(); 505 const int border_thickness = NonClientBorderThickness(); 506 return gfx::Insets(top_height, 507 border_thickness, 508 border_thickness, 509 border_thickness); 510} 511 512gfx::Rect GlassBrowserFrameView::CalculateClientAreaBounds(int width, 513 int height) const { 514 gfx::Rect bounds(0, 0, width, height); 515 bounds.Inset(GetClientAreaInsets()); 516 return bounds; 517} 518 519void GlassBrowserFrameView::StartThrobber() { 520 if (!throbber_running_) { 521 throbber_running_ = true; 522 throbber_frame_ = 0; 523 InitThrobberIcons(); 524 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, 525 static_cast<WPARAM>(ICON_SMALL), 526 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); 527 } 528} 529 530void GlassBrowserFrameView::StopThrobber() { 531 if (throbber_running_) { 532 throbber_running_ = false; 533 534 HICON frame_icon = NULL; 535 536 // Check if hosted BrowserView has a window icon to use. 537 if (browser_view()->ShouldShowWindowIcon()) { 538 gfx::ImageSkia icon = browser_view()->GetWindowIcon(); 539 if (!icon.isNull()) 540 frame_icon = IconUtil::CreateHICONFromSkBitmap(*icon.bitmap()); 541 } 542 543 // Fallback to class icon. 544 if (!frame_icon) { 545 frame_icon = reinterpret_cast<HICON>(GetClassLongPtr( 546 views::HWNDForWidget(frame()), GCLP_HICONSM)); 547 } 548 549 // This will reset the small icon which we set in the throbber code. 550 // WM_SETICON with NULL icon restores the icon for title bar but not 551 // for taskbar. See http://crbug.com/29996 552 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, 553 static_cast<WPARAM>(ICON_SMALL), 554 reinterpret_cast<LPARAM>(frame_icon)); 555 } 556} 557 558void GlassBrowserFrameView::DisplayNextThrobberFrame() { 559 throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount; 560 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, 561 static_cast<WPARAM>(ICON_SMALL), 562 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); 563} 564 565void GlassBrowserFrameView::Observe( 566 int type, 567 const content::NotificationSource& source, 568 const content::NotificationDetails& details) { 569 switch (type) { 570 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: 571 if (browser_view()->IsRegularOrGuestSession() && 572 switches::IsNewAvatarMenu()) { 573 UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON); 574 } else { 575 UpdateAvatarInfo(); 576 } 577 break; 578 default: 579 NOTREACHED() << "Got a notification we didn't register for!"; 580 break; 581 } 582} 583 584// static 585void GlassBrowserFrameView::InitThrobberIcons() { 586 static bool initialized = false; 587 if (!initialized) { 588 for (int i = 0; i < kThrobberIconCount; ++i) { 589 throbber_icons_[i] = 590 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); 591 DCHECK(throbber_icons_[i]); 592 } 593 initialized = true; 594 } 595} 596