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" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 views::View* BrowserNonClientFrameView::GetLocationIconView() const { | 67 views::View* BrowserNonClientFrameView::GetLocationIconView() const { |
68 return nullptr; | 68 return nullptr; |
69 } | 69 } |
70 | 70 |
71 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, | 71 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, |
72 bool is_visible) { | 72 bool is_visible) { |
73 if (!is_visible) | 73 if (!is_visible) |
74 return; | 74 return; |
75 | 75 |
76 // The first time UpdateOldAvatarButton() is called the window is not visible | 76 #if defined(OS_CHROMEOS) |
77 // so DrawTaskBarDecoration() has no effect. Therefore we need to call it | 77 // On ChromeOS we always need to give the old avatar button a chance to update |
78 // again once the window is visible. | 78 // in case we're in a teleported window. On desktop, the old avatar button |
79 if (!browser_view_->IsRegularOrGuestSession() || | 79 // only shows up when in incognito mode. |
80 !switches::IsNewAvatarMenu()) { | 80 UpdateOldAvatarButton(); |
| 81 OnProfileAvatarChanged(base::FilePath()); |
| 82 #else |
| 83 if (!browser_view_->IsRegularOrGuestSession()) { |
| 84 // The first time UpdateOldAvatarButton() is called the window is not |
| 85 // visible so DrawTaskBarDecoration() has no effect. Therefore we need to |
| 86 // call it again once the window is visible. |
81 UpdateOldAvatarButton(); | 87 UpdateOldAvatarButton(); |
82 } | 88 } |
83 | 89 |
84 // Make sure the task bar icon is correctly updated call | 90 // Call OnProfileAvatarChanged() in this case to make sure the task bar icon |
85 // |OnProfileAvatarChanged()| in this case, but only for non guest profiles. | 91 // is correctly updated. Guest profiles don't badge the icon so no need to do |
86 if (!browser_view_->IsGuestSession() || !switches::IsNewAvatarMenu()) | 92 // this in guest mode. |
| 93 if (!browser_view_->IsGuestSession()) |
87 OnProfileAvatarChanged(base::FilePath()); | 94 OnProfileAvatarChanged(base::FilePath()); |
| 95 #endif |
88 } | 96 } |
89 | 97 |
90 void BrowserNonClientFrameView::ChildPreferredSizeChanged(View* child) { | 98 void BrowserNonClientFrameView::ChildPreferredSizeChanged(View* child) { |
91 #if defined(FRAME_AVATAR_BUTTON) | 99 #if defined(FRAME_AVATAR_BUTTON) |
92 // Only perform a re-layout if the avatar button has changed, since that | 100 // Only perform a re-layout if the avatar button has changed, since that |
93 // can affect the size of the tabs. | 101 // can affect the size of the tabs. |
94 if (child == new_avatar_button_) { | 102 if (child == new_avatar_button_) { |
95 InvalidateLayout(); | 103 InvalidateLayout(); |
96 frame_->GetRootView()->Layout(); | 104 frame_->GetRootView()->Layout(); |
97 } | 105 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 gfx::ImageSkia* frame_image = GetFrameImage(); | 180 gfx::ImageSkia* frame_image = GetFrameImage(); |
173 int top_area_height = frame_image->height(); | 181 int top_area_height = frame_image->height(); |
174 if (browser_view_->IsTabStripVisible()) { | 182 if (browser_view_->IsTabStripVisible()) { |
175 top_area_height = std::max(top_area_height, | 183 top_area_height = std::max(top_area_height, |
176 GetBoundsForTabStrip(browser_view_->tabstrip()).bottom()); | 184 GetBoundsForTabStrip(browser_view_->tabstrip()).bottom()); |
177 } | 185 } |
178 return top_area_height; | 186 return top_area_height; |
179 } | 187 } |
180 | 188 |
181 void BrowserNonClientFrameView::UpdateAvatar() { | 189 void BrowserNonClientFrameView::UpdateAvatar() { |
182 if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu()) | 190 #if !defined(OS_CHROMEOS) |
| 191 if (browser_view()->IsRegularOrGuestSession()) |
183 UpdateNewAvatarButtonImpl(); | 192 UpdateNewAvatarButtonImpl(); |
184 else | 193 else |
| 194 #endif |
185 UpdateOldAvatarButton(); | 195 UpdateOldAvatarButton(); |
186 } | 196 } |
187 | 197 |
188 void BrowserNonClientFrameView::UpdateOldAvatarButton() { | 198 void BrowserNonClientFrameView::UpdateOldAvatarButton() { |
189 if (browser_view_->ShouldShowAvatar()) { | 199 if (browser_view_->ShouldShowAvatar()) { |
190 if (!avatar_button_) { | 200 if (!avatar_button_) { |
191 #if defined(ENABLE_SUPERVISED_USERS) | 201 #if defined(ENABLE_SUPERVISED_USERS) |
192 Profile* profile = browser_view_->browser()->profile(); | 202 Profile* profile = browser_view_->browser()->profile(); |
193 if (profile->IsSupervised() && !supervised_user_avatar_label_) { | 203 if (profile->IsSupervised() && !supervised_user_avatar_label_) { |
194 supervised_user_avatar_label_ = | 204 supervised_user_avatar_label_ = |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) | 249 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) |
240 avatar_button_->SetEnabled(false); | 250 avatar_button_->SetEnabled(false); |
241 if (avatar_button_) | 251 if (avatar_button_) |
242 avatar_button_->SetAvatarIcon(avatar, is_rectangle); | 252 avatar_button_->SetAvatarIcon(avatar, is_rectangle); |
243 } | 253 } |
244 | 254 |
245 #if defined(FRAME_AVATAR_BUTTON) | 255 #if defined(FRAME_AVATAR_BUTTON) |
246 void BrowserNonClientFrameView::UpdateNewAvatarButton( | 256 void BrowserNonClientFrameView::UpdateNewAvatarButton( |
247 views::ButtonListener* listener, | 257 views::ButtonListener* listener, |
248 const NewAvatarButton::AvatarButtonStyle style) { | 258 const NewAvatarButton::AvatarButtonStyle style) { |
249 DCHECK(switches::IsNewAvatarMenu()); | |
250 // This should never be called in incognito mode. | 259 // This should never be called in incognito mode. |
251 DCHECK(browser_view_->IsRegularOrGuestSession()); | 260 DCHECK(browser_view_->IsRegularOrGuestSession()); |
252 | 261 |
253 if (browser_view_->ShouldShowAvatar()) { | 262 if (browser_view_->ShouldShowAvatar()) { |
254 if (!new_avatar_button_) { | 263 if (!new_avatar_button_) { |
255 new_avatar_button_ = | 264 new_avatar_button_ = |
256 new NewAvatarButton(listener, style, browser_view_->browser()); | 265 new NewAvatarButton(listener, style, browser_view_->browser()); |
257 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); | 266 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); |
258 AddChildView(new_avatar_button_); | 267 AddChildView(new_avatar_button_); |
259 frame_->GetRootView()->Layout(); | 268 frame_->GetRootView()->Layout(); |
(...skipping 15 matching lines...) Expand all Loading... |
275 void BrowserNonClientFrameView::OnProfileWasRemoved( | 284 void BrowserNonClientFrameView::OnProfileWasRemoved( |
276 const base::FilePath& profile_path, | 285 const base::FilePath& profile_path, |
277 const base::string16& profile_name) { | 286 const base::string16& profile_name) { |
278 UpdateTaskbarDecoration(); | 287 UpdateTaskbarDecoration(); |
279 UpdateAvatar(); | 288 UpdateAvatar(); |
280 } | 289 } |
281 | 290 |
282 void BrowserNonClientFrameView::OnProfileAvatarChanged( | 291 void BrowserNonClientFrameView::OnProfileAvatarChanged( |
283 const base::FilePath& profile_path) { | 292 const base::FilePath& profile_path) { |
284 UpdateTaskbarDecoration(); | 293 UpdateTaskbarDecoration(); |
285 // Profile avatars are only displayed in the old UI or incognito. | 294 // Profile avatars are only displayed in incognito or on ChromeOS teleported |
286 if ((!browser_view()->IsGuestSession() && browser_view()->IsOffTheRecord()) || | 295 // windows. |
287 !switches::IsNewAvatarMenu()) { | 296 #if !defined(OS_CHROMEOS) |
| 297 if (!browser_view()->IsGuestSession() && browser_view()->IsOffTheRecord()) |
| 298 #endif |
288 UpdateOldAvatarButton(); | 299 UpdateOldAvatarButton(); |
289 } | |
290 } | 300 } |
291 | 301 |
292 void BrowserNonClientFrameView::UpdateTaskbarDecoration() { | 302 void BrowserNonClientFrameView::UpdateTaskbarDecoration() { |
293 gfx::Image avatar; | 303 gfx::Image avatar; |
294 gfx::Image taskbar_badge_avatar; | 304 gfx::Image taskbar_badge_avatar; |
295 bool is_rectangle; | 305 bool is_rectangle; |
296 // Only need to update the taskbar overlay here. If GetAvatarImages() | 306 // Only need to update the taskbar overlay here. If GetAvatarImages() |
297 // returns false, don't bother trying to update the taskbar decoration since | 307 // returns false, don't bother trying to update the taskbar decoration since |
298 // the returned images are not initialized. This can happen if the user | 308 // the returned images are not initialized. This can happen if the user |
299 // deletes the current profile. | 309 // deletes the current profile. |
(...skipping 17 matching lines...) Expand all Loading... |
317 const ProfileInfoCache& cache = | 327 const ProfileInfoCache& cache = |
318 g_browser_process->profile_manager()->GetProfileInfoCache(); | 328 g_browser_process->profile_manager()->GetProfileInfoCache(); |
319 show_decoration = show_decoration && cache.GetNumberOfProfiles() > 1; | 329 show_decoration = show_decoration && cache.GetNumberOfProfiles() > 1; |
320 } | 330 } |
321 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), | 331 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), |
322 show_decoration | 332 show_decoration |
323 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) | 333 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) |
324 : nullptr); | 334 : nullptr); |
325 } | 335 } |
326 } | 336 } |
OLD | NEW |