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/browser_non_client_frame_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/profiles/avatar_menu.h" | 8 #include "chrome/browser/profiles/avatar_menu.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/browser/profiles/profiles_state.h" |
12 #include "chrome/browser/ui/view_ids.h" | 13 #include "chrome/browser/ui/view_ids.h" |
13 #include "chrome/browser/ui/views/avatar_label.h" | 14 #include "chrome/browser/ui/views/avatar_label.h" |
14 #include "chrome/browser/ui/views/avatar_menu_button.h" | 15 #include "chrome/browser/ui/views/avatar_menu_button.h" |
15 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
16 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" | 17 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" |
| 18 #include "chrome/browser/ui/views/new_avatar_button.h" |
| 19 #include "chrome/browser/ui/views/profile_chooser_view.h" |
17 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
19 #include "third_party/skia/include/core/SkColor.h" | 22 #include "third_party/skia/include/core/SkColor.h" |
20 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/base/theme_provider.h" | 25 #include "ui/base/theme_provider.h" |
23 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
24 #include "ui/views/background.h" | 27 #include "ui/views/background.h" |
25 | 28 |
26 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, | 29 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, |
27 BrowserView* browser_view) | 30 BrowserView* browser_view) |
28 : frame_(frame), | 31 : frame_(frame), |
29 browser_view_(browser_view), | 32 browser_view_(browser_view), |
30 avatar_button_(NULL), | 33 avatar_button_(NULL), |
31 avatar_label_(NULL) { | 34 avatar_label_(NULL), |
| 35 new_avatar_button_(NULL) { |
32 } | 36 } |
33 | 37 |
34 BrowserNonClientFrameView::~BrowserNonClientFrameView() { | 38 BrowserNonClientFrameView::~BrowserNonClientFrameView() { |
35 } | 39 } |
36 | 40 |
37 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, | 41 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, |
38 bool is_visible) { | 42 bool is_visible) { |
39 if (!is_visible) | 43 if (!is_visible) |
40 return; | 44 return; |
41 // The first time UpdateAvatarInfo() is called the window is not visible so | 45 // The first time UpdateAvatarInfo() is called the window is not visible so |
42 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again | 46 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again |
43 // once the window is visible. | 47 // once the window is visible. |
44 UpdateAvatarInfo(); | 48 if (!browser_view_->IsRegularOrGuestSession() || |
| 49 !profiles::IsNewProfileManagementEnabled()) |
| 50 UpdateAvatarInfo(); |
45 } | 51 } |
46 | 52 |
47 void BrowserNonClientFrameView::OnThemeChanged() { | 53 void BrowserNonClientFrameView::OnThemeChanged() { |
48 if (avatar_label_) | 54 if (avatar_label_) |
49 avatar_label_->UpdateLabelStyle(); | 55 avatar_label_->UpdateLabelStyle(); |
50 } | 56 } |
51 | 57 |
52 void BrowserNonClientFrameView::UpdateAvatarInfo() { | 58 void BrowserNonClientFrameView::UpdateAvatarInfo() { |
53 if (browser_view_->ShouldShowAvatar()) { | 59 if (browser_view_->ShouldShowAvatar()) { |
54 if (!avatar_button_) { | 60 if (!avatar_button_) { |
55 Profile* profile = browser_view_->browser()->profile(); | 61 Profile* profile = browser_view_->browser()->profile(); |
56 if (profile->IsManaged() && !avatar_label_) { | 62 if (profile->IsManaged() && !avatar_label_) { |
57 avatar_label_ = new AvatarLabel(browser_view_); | 63 avatar_label_ = new AvatarLabel(browser_view_); |
58 avatar_label_->set_id(VIEW_ID_AVATAR_LABEL); | 64 avatar_label_->set_id(VIEW_ID_AVATAR_LABEL); |
59 AddChildView(avatar_label_); | 65 AddChildView(avatar_label_); |
60 } | 66 } |
61 avatar_button_ = new AvatarMenuButton( | 67 avatar_button_ = new AvatarMenuButton( |
62 browser_view_->browser(), | 68 browser_view_->browser(), !browser_view_->IsRegularOrGuestSession()); |
63 browser_view_->IsOffTheRecord() && !browser_view_->IsGuestSession()); | |
64 avatar_button_->set_id(VIEW_ID_AVATAR_BUTTON); | 69 avatar_button_->set_id(VIEW_ID_AVATAR_BUTTON); |
65 AddChildView(avatar_button_); | 70 AddChildView(avatar_button_); |
66 frame_->GetRootView()->Layout(); | 71 frame_->GetRootView()->Layout(); |
67 } | 72 } |
68 } else if (avatar_button_) { | 73 } else if (avatar_button_) { |
69 // The avatar label can just be there if there is also an avatar button. | 74 // The avatar label can just be there if there is also an avatar button. |
70 if (avatar_label_) { | 75 if (avatar_label_) { |
71 RemoveChildView(avatar_label_); | 76 RemoveChildView(avatar_label_); |
72 delete avatar_label_; | 77 delete avatar_label_; |
73 avatar_label_ = NULL; | 78 avatar_label_ = NULL; |
(...skipping 30 matching lines...) Expand all Loading... |
104 if (!text.empty()) | 109 if (!text.empty()) |
105 avatar_button_->SetText(text); | 110 avatar_button_->SetText(text); |
106 } | 111 } |
107 | 112 |
108 // For popups and panels which don't have the avatar button, we still | 113 // For popups and panels which don't have the avatar button, we still |
109 // need to draw the taskbar decoration. | 114 // need to draw the taskbar decoration. |
110 chrome::DrawTaskbarDecoration( | 115 chrome::DrawTaskbarDecoration( |
111 frame_->GetNativeWindow(), | 116 frame_->GetNativeWindow(), |
112 AvatarMenu::ShouldShowAvatarMenu() ? &avatar : NULL); | 117 AvatarMenu::ShouldShowAvatarMenu() ? &avatar : NULL); |
113 } | 118 } |
| 119 |
| 120 void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo( |
| 121 views::ButtonListener* listener, |
| 122 const NewAvatarButton::AvatarButtonStyle style) { |
| 123 DCHECK(profiles::IsNewProfileManagementEnabled()); |
| 124 // This should never be called in incognito mode. |
| 125 DCHECK(browser_view_->IsRegularOrGuestSession()); |
| 126 |
| 127 if (browser_view_->ShouldShowAvatar()) { |
| 128 if (!new_avatar_button_) { |
| 129 string16 profile_name = |
| 130 profiles::GetActiveProfileDisplayName(browser_view_->browser()); |
| 131 new_avatar_button_ = new NewAvatarButton(listener, profile_name, style); |
| 132 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); |
| 133 AddChildView(new_avatar_button_); |
| 134 frame_->GetRootView()->Layout(); |
| 135 } |
| 136 } else if (new_avatar_button_) { |
| 137 delete new_avatar_button_; |
| 138 new_avatar_button_ = NULL; |
| 139 frame_->GetRootView()->Layout(); |
| 140 } |
| 141 } |
| 142 |
| 143 void BrowserNonClientFrameView::ShowProfileChooserViewBubble() { |
| 144 gfx::Point origin; |
| 145 views::View::ConvertPointToScreen(new_avatar_button(), &origin); |
| 146 gfx::Rect bounds(origin, size()); |
| 147 |
| 148 ProfileChooserView::ShowBubble( |
| 149 new_avatar_button(), views::BubbleBorder::TOP_RIGHT, |
| 150 views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE, bounds, |
| 151 browser_view_->browser()); |
| 152 } |
OLD | NEW |