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 BrowserWindow::AvatarBubbleMode mode = | 290 BrowserWindow::AvatarBubbleMode mode = |
299 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT; | 291 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT; |
300 if (event.IsMouseEvent() && | 292 if (event.IsMouseEvent() && |
301 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) { | 293 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) { |
302 mode = BrowserWindow::AVATAR_BUBBLE_MODE_FAST_USER_SWITCH; | 294 mode = BrowserWindow::AVATAR_BUBBLE_MODE_FAST_USER_SWITCH; |
303 } | 295 } |
304 browser_view()->ShowAvatarBubbleFromAvatarButton( | 296 browser_view()->ShowAvatarBubbleFromAvatarButton( |
305 mode, | 297 mode, |
306 signin::ManageAccountsParams()); | 298 signin::ManageAccountsParams()); |
307 } | 299 } |
308 } | 300 } |
309 | 301 |
| 302 // BrowserNonClientFrameView: |
| 303 void GlassBrowserFrameView::UpdateNewStyleAvatar() { |
| 304 UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON); |
| 305 } |
| 306 |
310 /////////////////////////////////////////////////////////////////////////////// | 307 /////////////////////////////////////////////////////////////////////////////// |
311 // GlassBrowserFrameView, private: | 308 // GlassBrowserFrameView, private: |
312 | 309 |
313 // views::NonClientFrameView: | 310 // views::NonClientFrameView: |
314 bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target, | 311 bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target, |
315 const gfx::Rect& rect) const { | 312 const gfx::Rect& rect) const { |
316 CHECK_EQ(target, this); | 313 CHECK_EQ(target, this); |
317 bool hit_avatar_button = avatar_button() && | 314 bool hit_avatar_button = avatar_button() && |
318 avatar_button()->GetMirroredBounds().Intersects(rect); | 315 avatar_button()->GetMirroredBounds().Intersects(rect); |
319 bool hit_new_avatar_button = new_avatar_button() && | 316 bool hit_new_avatar_button = new_avatar_button() && |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 } | 590 } |
594 } | 591 } |
595 | 592 |
596 void GlassBrowserFrameView::DisplayNextThrobberFrame() { | 593 void GlassBrowserFrameView::DisplayNextThrobberFrame() { |
597 throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount; | 594 throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount; |
598 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, | 595 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, |
599 static_cast<WPARAM>(ICON_SMALL), | 596 static_cast<WPARAM>(ICON_SMALL), |
600 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); | 597 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); |
601 } | 598 } |
602 | 599 |
603 void GlassBrowserFrameView::Observe( | |
604 int type, | |
605 const content::NotificationSource& source, | |
606 const content::NotificationDetails& details) { | |
607 switch (type) { | |
608 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: | |
609 if (browser_view()->IsRegularOrGuestSession() && | |
610 switches::IsNewAvatarMenu()) { | |
611 UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON); | |
612 } else { | |
613 UpdateAvatarInfo(); | |
614 } | |
615 break; | |
616 default: | |
617 NOTREACHED() << "Got a notification we didn't register for!"; | |
618 break; | |
619 } | |
620 } | |
621 | |
622 // static | 600 // static |
623 void GlassBrowserFrameView::InitThrobberIcons() { | 601 void GlassBrowserFrameView::InitThrobberIcons() { |
624 static bool initialized = false; | 602 static bool initialized = false; |
625 if (!initialized) { | 603 if (!initialized) { |
626 for (int i = 0; i < kThrobberIconCount; ++i) { | 604 for (int i = 0; i < kThrobberIconCount; ++i) { |
627 throbber_icons_[i] = | 605 throbber_icons_[i] = |
628 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); | 606 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); |
629 DCHECK(throbber_icons_[i]); | 607 DCHECK(throbber_icons_[i]); |
630 } | 608 } |
631 initialized = true; | 609 initialized = true; |
632 } | 610 } |
633 } | 611 } |
OLD | NEW |