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_avatar_icon_util.h" | 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
11 #include "chrome/browser/profiles/profile_info_cache.h" | 11 #include "chrome/browser/profiles/profile_info_cache.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/browser/profiles/profiles_state.h" | 13 #include "chrome/browser/profiles/profiles_state.h" |
14 #include "chrome/browser/ui/view_ids.h" | 14 #include "chrome/browser/ui/view_ids.h" |
15 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
16 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" | 16 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" |
17 #include "chrome/browser/ui/views/profiles/avatar_label.h" | |
18 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 17 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
19 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" | 18 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" |
20 #include "components/signin/core/common/profile_management_switches.h" | 19 #include "components/signin/core/common/profile_management_switches.h" |
21 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
22 #include "third_party/skia/include/core/SkColor.h" | 21 #include "third_party/skia/include/core/SkColor.h" |
23 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/base/theme_provider.h" | 23 #include "ui/base/theme_provider.h" |
25 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
26 #include "ui/views/background.h" | 25 #include "ui/views/background.h" |
27 | 26 |
| 27 #if defined(ENABLE_MANAGED_USERS) |
| 28 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h" |
| 29 #endif |
| 30 |
28 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, | 31 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, |
29 BrowserView* browser_view) | 32 BrowserView* browser_view) |
30 : frame_(frame), | 33 : frame_(frame), |
31 browser_view_(browser_view), | 34 browser_view_(browser_view), |
32 avatar_button_(NULL), | 35 avatar_button_(NULL), |
33 avatar_label_(NULL), | 36 #if defined(ENABLE_MANAGED_USERS) |
| 37 supervised_user_avatar_label_(NULL), |
| 38 #endif |
34 new_avatar_button_(NULL) { | 39 new_avatar_button_(NULL) { |
35 } | 40 } |
36 | 41 |
37 BrowserNonClientFrameView::~BrowserNonClientFrameView() { | 42 BrowserNonClientFrameView::~BrowserNonClientFrameView() { |
38 } | 43 } |
39 | 44 |
40 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, | 45 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, |
41 bool is_visible) { | 46 bool is_visible) { |
42 if (!is_visible) | 47 if (!is_visible) |
43 return; | 48 return; |
44 // The first time UpdateAvatarInfo() is called the window is not visible so | 49 // The first time UpdateAvatarInfo() is called the window is not visible so |
45 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again | 50 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again |
46 // once the window is visible. | 51 // once the window is visible. |
47 if (!browser_view_->IsRegularOrGuestSession() || | 52 if (!browser_view_->IsRegularOrGuestSession() || |
48 !switches::IsNewAvatarMenu()) | 53 !switches::IsNewAvatarMenu()) |
49 UpdateAvatarInfo(); | 54 UpdateAvatarInfo(); |
50 } | 55 } |
51 | 56 |
| 57 #if defined(ENABLE_MANAGED_USERS) |
52 void BrowserNonClientFrameView::OnThemeChanged() { | 58 void BrowserNonClientFrameView::OnThemeChanged() { |
53 if (avatar_label_) | 59 if (supervised_user_avatar_label_) |
54 avatar_label_->UpdateLabelStyle(); | 60 supervised_user_avatar_label_->UpdateLabelStyle(); |
55 } | 61 } |
| 62 #endif |
56 | 63 |
57 void BrowserNonClientFrameView::UpdateAvatarInfo() { | 64 void BrowserNonClientFrameView::UpdateAvatarInfo() { |
58 if (browser_view_->ShouldShowAvatar()) { | 65 if (browser_view_->ShouldShowAvatar()) { |
59 if (!avatar_button_) { | 66 if (!avatar_button_) { |
| 67 #if defined(ENABLE_MANAGED_USERS) |
60 Profile* profile = browser_view_->browser()->profile(); | 68 Profile* profile = browser_view_->browser()->profile(); |
61 if (profile->IsSupervised() && !avatar_label_) { | 69 if (profile->IsSupervised() && !supervised_user_avatar_label_) { |
62 avatar_label_ = new AvatarLabel(browser_view_); | 70 supervised_user_avatar_label_ = |
63 avatar_label_->set_id(VIEW_ID_AVATAR_LABEL); | 71 new SupervisedUserAvatarLabel(browser_view_); |
64 AddChildView(avatar_label_); | 72 supervised_user_avatar_label_->set_id( |
| 73 VIEW_ID_SUPERVISED_USER_AVATAR_LABEL); |
| 74 AddChildView(supervised_user_avatar_label_); |
65 } | 75 } |
| 76 #endif |
66 avatar_button_ = new AvatarMenuButton( | 77 avatar_button_ = new AvatarMenuButton( |
67 browser_view_->browser(), !browser_view_->IsRegularOrGuestSession()); | 78 browser_view_->browser(), !browser_view_->IsRegularOrGuestSession()); |
68 avatar_button_->set_id(VIEW_ID_AVATAR_BUTTON); | 79 avatar_button_->set_id(VIEW_ID_AVATAR_BUTTON); |
69 AddChildView(avatar_button_); | 80 AddChildView(avatar_button_); |
70 // Invalidate here because adding a child does not invalidate the layout. | 81 // Invalidate here because adding a child does not invalidate the layout. |
71 InvalidateLayout(); | 82 InvalidateLayout(); |
72 frame_->GetRootView()->Layout(); | 83 frame_->GetRootView()->Layout(); |
73 } | 84 } |
74 } else if (avatar_button_) { | 85 } else if (avatar_button_) { |
| 86 #if defined(ENABLE_MANAGED_USERS) |
75 // The avatar label can just be there if there is also an avatar button. | 87 // The avatar label can just be there if there is also an avatar button. |
76 if (avatar_label_) { | 88 if (supervised_user_avatar_label_) { |
77 RemoveChildView(avatar_label_); | 89 RemoveChildView(supervised_user_avatar_label_); |
78 delete avatar_label_; | 90 delete supervised_user_avatar_label_; |
79 avatar_label_ = NULL; | 91 supervised_user_avatar_label_ = NULL; |
80 } | 92 } |
| 93 #endif |
81 RemoveChildView(avatar_button_); | 94 RemoveChildView(avatar_button_); |
82 delete avatar_button_; | 95 delete avatar_button_; |
83 avatar_button_ = NULL; | 96 avatar_button_ = NULL; |
84 frame_->GetRootView()->Layout(); | 97 frame_->GetRootView()->Layout(); |
85 } | 98 } |
86 | 99 |
87 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 100 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
88 gfx::Image avatar; | 101 gfx::Image avatar; |
89 gfx::Image taskbar_badge_avatar; | 102 gfx::Image taskbar_badge_avatar; |
90 base::string16 text; | 103 base::string16 text; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); | 164 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); |
152 AddChildView(new_avatar_button_); | 165 AddChildView(new_avatar_button_); |
153 frame_->GetRootView()->Layout(); | 166 frame_->GetRootView()->Layout(); |
154 } | 167 } |
155 } else if (new_avatar_button_) { | 168 } else if (new_avatar_button_) { |
156 delete new_avatar_button_; | 169 delete new_avatar_button_; |
157 new_avatar_button_ = NULL; | 170 new_avatar_button_ = NULL; |
158 frame_->GetRootView()->Layout(); | 171 frame_->GetRootView()->Layout(); |
159 } | 172 } |
160 } | 173 } |
OLD | NEW |