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 "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/profiles/avatar_menu.h" | 9 #include "chrome/browser/profiles/avatar_menu.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
12 #include "chrome/browser/profiles/profile_info_cache.h" | 12 #include "chrome/browser/profiles/profile_info_cache.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/profiles/profiles_state.h" | 14 #include "chrome/browser/profiles/profiles_state.h" |
15 #include "chrome/browser/themes/theme_properties.h" | 15 #include "chrome/browser/themes/theme_properties.h" |
16 #include "chrome/browser/ui/view_ids.h" | 16 #include "chrome/browser/ui/view_ids.h" |
17 #include "chrome/browser/ui/views/frame/browser_view.h" | 17 #include "chrome/browser/ui/views/frame/browser_view.h" |
18 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" | 18 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" |
19 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 19 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
20 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" | |
21 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 20 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
22 #include "chrome/browser/ui/views/theme_image_mapper.h" | 21 #include "chrome/browser/ui/views/theme_image_mapper.h" |
23 #include "components/signin/core/common/profile_management_switches.h" | 22 #include "components/signin/core/common/profile_management_switches.h" |
24 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
25 #include "third_party/skia/include/core/SkColor.h" | 24 #include "third_party/skia/include/core/SkColor.h" |
26 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
27 #include "ui/base/theme_provider.h" | 26 #include "ui/base/theme_provider.h" |
28 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
29 #include "ui/resources/grit/ui_resources.h" | 28 #include "ui/resources/grit/ui_resources.h" |
30 #include "ui/views/background.h" | 29 #include "ui/views/background.h" |
31 #include "ui/views/resources/grit/views_resources.h" | 30 #include "ui/views/resources/grit/views_resources.h" |
32 | 31 |
33 #if defined(ENABLE_SUPERVISED_USERS) | 32 #if defined(ENABLE_SUPERVISED_USERS) |
34 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h" | 33 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h" |
35 #endif | 34 #endif |
36 | 35 |
37 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, | 36 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, |
38 BrowserView* browser_view) | 37 BrowserView* browser_view) |
39 : frame_(frame), | 38 : frame_(frame), |
40 browser_view_(browser_view), | 39 browser_view_(browser_view), |
41 #if defined(ENABLE_SUPERVISED_USERS) | 40 #if defined(ENABLE_SUPERVISED_USERS) |
42 supervised_user_avatar_label_(nullptr), | 41 supervised_user_avatar_label_(nullptr), |
43 #endif | 42 #endif |
44 #if defined(FRAME_AVATAR_BUTTON) | 43 #if defined(FRAME_AVATAR_BUTTON) |
45 new_avatar_button_(nullptr), | 44 profile_switcher_(this), |
46 #endif | 45 #endif |
47 avatar_button_(nullptr) { | 46 avatar_button_(nullptr) { |
48 // The profile manager may by null in tests. | 47 // The profile manager may by null in tests. |
49 if (g_browser_process->profile_manager()) { | 48 if (g_browser_process->profile_manager()) { |
50 ProfileInfoCache& cache = | 49 ProfileInfoCache& cache = |
51 g_browser_process->profile_manager()->GetProfileInfoCache(); | 50 g_browser_process->profile_manager()->GetProfileInfoCache(); |
52 cache.AddObserver(this); | 51 cache.AddObserver(this); |
53 } | 52 } |
54 } | 53 } |
55 | 54 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // this in guest mode. | 94 // this in guest mode. |
96 if (!browser_view_->IsGuestSession()) | 95 if (!browser_view_->IsGuestSession()) |
97 OnProfileAvatarChanged(base::FilePath()); | 96 OnProfileAvatarChanged(base::FilePath()); |
98 #endif | 97 #endif |
99 } | 98 } |
100 | 99 |
101 void BrowserNonClientFrameView::ChildPreferredSizeChanged(View* child) { | 100 void BrowserNonClientFrameView::ChildPreferredSizeChanged(View* child) { |
102 #if defined(FRAME_AVATAR_BUTTON) | 101 #if defined(FRAME_AVATAR_BUTTON) |
103 // Only perform a re-layout if the avatar button has changed, since that | 102 // Only perform a re-layout if the avatar button has changed, since that |
104 // can affect the size of the tabs. | 103 // can affect the size of the tabs. |
105 if (child == new_avatar_button_) { | 104 if (child == new_avatar_button()) { |
106 InvalidateLayout(); | 105 InvalidateLayout(); |
107 frame_->GetRootView()->Layout(); | 106 frame_->GetRootView()->Layout(); |
108 } | 107 } |
109 #endif | 108 #endif |
110 } | 109 } |
111 | 110 |
112 #if defined(ENABLE_SUPERVISED_USERS) | 111 #if defined(ENABLE_SUPERVISED_USERS) |
113 void BrowserNonClientFrameView::OnThemeChanged() { | 112 void BrowserNonClientFrameView::OnThemeChanged() { |
114 if (supervised_user_avatar_label_) | 113 if (supervised_user_avatar_label_) |
115 supervised_user_avatar_label_->UpdateLabelStyle(); | 114 supervised_user_avatar_label_->UpdateLabelStyle(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 243 |
245 // Disable the menu when we should not show the menu. | 244 // Disable the menu when we should not show the menu. |
246 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) | 245 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) |
247 avatar_button_->SetEnabled(false); | 246 avatar_button_->SetEnabled(false); |
248 if (avatar_button_) | 247 if (avatar_button_) |
249 avatar_button_->SetAvatarIcon(avatar, is_rectangle); | 248 avatar_button_->SetAvatarIcon(avatar, is_rectangle); |
250 } | 249 } |
251 | 250 |
252 #if defined(FRAME_AVATAR_BUTTON) | 251 #if defined(FRAME_AVATAR_BUTTON) |
253 void BrowserNonClientFrameView::UpdateNewAvatarButton( | 252 void BrowserNonClientFrameView::UpdateNewAvatarButton( |
254 views::ButtonListener* listener, | 253 const AvatarButtonStyle style) { |
255 const NewAvatarButton::AvatarButtonStyle style) { | 254 profile_switcher_.Update(style); |
256 // This should never be called in incognito mode. | |
257 DCHECK(browser_view_->IsRegularOrGuestSession()); | |
258 | |
259 if (browser_view_->ShouldShowAvatar()) { | |
260 if (!new_avatar_button_) { | |
261 new_avatar_button_ = | |
262 new NewAvatarButton(listener, style, browser_view_->browser()); | |
263 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); | |
264 AddChildView(new_avatar_button_); | |
265 frame_->GetRootView()->Layout(); | |
266 } | |
267 } else if (new_avatar_button_) { | |
268 delete new_avatar_button_; | |
269 new_avatar_button_ = nullptr; | |
270 frame_->GetRootView()->Layout(); | |
271 } | |
272 } | 255 } |
273 #endif | 256 #endif |
274 | 257 |
275 void BrowserNonClientFrameView::OnProfileAdded( | 258 void BrowserNonClientFrameView::OnProfileAdded( |
276 const base::FilePath& profile_path) { | 259 const base::FilePath& profile_path) { |
277 UpdateTaskbarDecoration(); | 260 UpdateTaskbarDecoration(); |
278 UpdateAvatar(); | 261 UpdateAvatar(); |
279 } | 262 } |
280 | 263 |
281 void BrowserNonClientFrameView::OnProfileWasRemoved( | 264 void BrowserNonClientFrameView::OnProfileWasRemoved( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 const ProfileInfoCache& cache = | 306 const ProfileInfoCache& cache = |
324 g_browser_process->profile_manager()->GetProfileInfoCache(); | 307 g_browser_process->profile_manager()->GetProfileInfoCache(); |
325 show_decoration = show_decoration && cache.GetNumberOfProfiles() > 1; | 308 show_decoration = show_decoration && cache.GetNumberOfProfiles() > 1; |
326 } | 309 } |
327 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), | 310 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), |
328 show_decoration | 311 show_decoration |
329 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) | 312 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) |
330 : nullptr); | 313 : nullptr); |
331 } | 314 } |
332 } | 315 } |
OLD | NEW |