| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" | 5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/signin/signin_header_helper.h" | 12 #include "chrome/browser/signin/signin_header_helper.h" |
| 14 #include "chrome/browser/themes/theme_properties.h" | 13 #include "chrome/browser/themes/theme_properties.h" |
| 15 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 16 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 15 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
| 17 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" | 16 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" |
| 18 #include "chrome/browser/ui/views/tabs/tab.h" | 17 #include "chrome/browser/ui/views/tabs/tab.h" |
| 19 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 18 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 19 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 21 #include "components/signin/core/common/profile_management_switches.h" | 20 #include "components/signin/core/common/profile_management_switches.h" |
| 22 #include "content/public/browser/notification_service.h" | |
| 23 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
| 24 #include "skia/ext/image_operations.h" | 22 #include "skia/ext/image_operations.h" |
| 25 #include "ui/base/resource/resource_bundle_win.h" | 23 #include "ui/base/resource/resource_bundle_win.h" |
| 26 #include "ui/base/theme_provider.h" | 24 #include "ui/base/theme_provider.h" |
| 27 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/icon_util.h" | 26 #include "ui/gfx/icon_util.h" |
| 29 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 30 #include "ui/gfx/win/dpi.h" | 28 #include "ui/gfx/win/dpi.h" |
| 31 #include "ui/resources/grit/ui_resources.h" | 29 #include "ui/resources/grit/ui_resources.h" |
| 32 #include "ui/views/controls/label.h" | 30 #include "ui/views/controls/label.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // GlassBrowserFrameView, public: | 88 // GlassBrowserFrameView, public: |
| 91 | 89 |
| 92 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, | 90 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, |
| 93 BrowserView* browser_view) | 91 BrowserView* browser_view) |
| 94 : BrowserNonClientFrameView(frame, browser_view), | 92 : BrowserNonClientFrameView(frame, browser_view), |
| 95 throbber_running_(false), | 93 throbber_running_(false), |
| 96 throbber_frame_(0) { | 94 throbber_frame_(0) { |
| 97 if (browser_view->ShouldShowWindowIcon()) | 95 if (browser_view->ShouldShowWindowIcon()) |
| 98 InitThrobberIcons(); | 96 InitThrobberIcons(); |
| 99 | 97 |
| 100 if (browser_view->IsRegularOrGuestSession() && switches::IsNewAvatarMenu()) | 98 UpdateAvatar(); |
| 101 UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON); | |
| 102 else | |
| 103 UpdateAvatarInfo(); | |
| 104 | |
| 105 if (!browser_view->IsOffTheRecord()) { | |
| 106 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | |
| 107 content::NotificationService::AllSources()); | |
| 108 } | |
| 109 } | 99 } |
| 110 | 100 |
| 111 GlassBrowserFrameView::~GlassBrowserFrameView() { | 101 GlassBrowserFrameView::~GlassBrowserFrameView() { |
| 112 } | 102 } |
| 113 | 103 |
| 114 /////////////////////////////////////////////////////////////////////////////// | 104 /////////////////////////////////////////////////////////////////////////////// |
| 115 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: | 105 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: |
| 116 | 106 |
| 117 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( | 107 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( |
| 118 views::View* tabstrip) const { | 108 views::View* tabstrip) const { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 void GlassBrowserFrameView::Layout() { | 274 void GlassBrowserFrameView::Layout() { |
| 285 if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu()) | 275 if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu()) |
| 286 LayoutNewStyleAvatar(); | 276 LayoutNewStyleAvatar(); |
| 287 else | 277 else |
| 288 LayoutAvatar(); | 278 LayoutAvatar(); |
| 289 | 279 |
| 290 LayoutClientView(); | 280 LayoutClientView(); |
| 291 } | 281 } |
| 292 | 282 |
| 293 /////////////////////////////////////////////////////////////////////////////// | 283 /////////////////////////////////////////////////////////////////////////////// |
| 294 // GlassBrowserFrameView, views::ButtonListener overrides: | 284 // GlassBrowserFrameView, protected: |
| 285 |
| 286 // views::ButtonListener: |
| 295 void GlassBrowserFrameView::ButtonPressed(views::Button* sender, | 287 void GlassBrowserFrameView::ButtonPressed(views::Button* sender, |
| 296 const ui::Event& event) { | 288 const ui::Event& event) { |
| 297 if (sender == new_avatar_button()) { | 289 if (sender == new_avatar_button()) { |
| 298 browser_view()->ShowAvatarBubbleFromAvatarButton( | 290 browser_view()->ShowAvatarBubbleFromAvatarButton( |
| 299 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT, | 291 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT, |
| 300 signin::ManageAccountsParams()); | 292 signin::ManageAccountsParams()); |
| 301 } | 293 } |
| 302 } | 294 } |
| 303 | 295 |
| 296 // BrowserNonClientFrameView: |
| 297 void GlassBrowserFrameView::UpdateNewStyleAvatar() { |
| 298 UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON); |
| 299 } |
| 300 |
| 304 /////////////////////////////////////////////////////////////////////////////// | 301 /////////////////////////////////////////////////////////////////////////////// |
| 305 // GlassBrowserFrameView, private: | 302 // GlassBrowserFrameView, private: |
| 306 | 303 |
| 307 // views::NonClientFrameView: | 304 // views::NonClientFrameView: |
| 308 bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target, | 305 bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target, |
| 309 const gfx::Rect& rect) const { | 306 const gfx::Rect& rect) const { |
| 310 CHECK_EQ(target, this); | 307 CHECK_EQ(target, this); |
| 311 bool hit_avatar_button = avatar_button() && | 308 bool hit_avatar_button = avatar_button() && |
| 312 avatar_button()->GetMirroredBounds().Intersects(rect); | 309 avatar_button()->GetMirroredBounds().Intersects(rect); |
| 313 bool hit_new_avatar_button = new_avatar_button() && | 310 bool hit_new_avatar_button = new_avatar_button() && |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 } | 584 } |
| 588 } | 585 } |
| 589 | 586 |
| 590 void GlassBrowserFrameView::DisplayNextThrobberFrame() { | 587 void GlassBrowserFrameView::DisplayNextThrobberFrame() { |
| 591 throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount; | 588 throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount; |
| 592 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, | 589 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, |
| 593 static_cast<WPARAM>(ICON_SMALL), | 590 static_cast<WPARAM>(ICON_SMALL), |
| 594 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); | 591 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); |
| 595 } | 592 } |
| 596 | 593 |
| 597 void GlassBrowserFrameView::Observe( | |
| 598 int type, | |
| 599 const content::NotificationSource& source, | |
| 600 const content::NotificationDetails& details) { | |
| 601 switch (type) { | |
| 602 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: | |
| 603 if (browser_view()->IsRegularOrGuestSession() && | |
| 604 switches::IsNewAvatarMenu()) { | |
| 605 UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON); | |
| 606 } else { | |
| 607 UpdateAvatarInfo(); | |
| 608 } | |
| 609 break; | |
| 610 default: | |
| 611 NOTREACHED() << "Got a notification we didn't register for!"; | |
| 612 break; | |
| 613 } | |
| 614 } | |
| 615 | |
| 616 // static | 594 // static |
| 617 void GlassBrowserFrameView::InitThrobberIcons() { | 595 void GlassBrowserFrameView::InitThrobberIcons() { |
| 618 static bool initialized = false; | 596 static bool initialized = false; |
| 619 if (!initialized) { | 597 if (!initialized) { |
| 620 for (int i = 0; i < kThrobberIconCount; ++i) { | 598 for (int i = 0; i < kThrobberIconCount; ++i) { |
| 621 throbber_icons_[i] = | 599 throbber_icons_[i] = |
| 622 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); | 600 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); |
| 623 DCHECK(throbber_icons_[i]); | 601 DCHECK(throbber_icons_[i]); |
| 624 } | 602 } |
| 625 initialized = true; | 603 initialized = true; |
| 626 } | 604 } |
| 627 } | 605 } |
| OLD | NEW |