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 #if defined(OS_CHROMEOS) | |
77 // On ChromeOS we always need to give the old avatar button a chance to update | |
78 // in case we're in a teleported window. | |
79 UpdateOldAvatarButton(); | |
Peter Kasting
2015/09/25 23:42:52
Nit: Hopefully one of your subsequent cleanup chan
anthonyvd
2015/09/29 20:23:16
I absolutely agree with that. Along with functiona
Peter Kasting
2015/09/29 20:34:16
Seems OK. It would be nice if it were possible to
anthonyvd
2015/09/30 18:34:03
There should be a few places at least where specif
| |
80 OnProfileAvatarChanged(base::FilePath()); | |
81 #else | |
82 // On desktop, the old avatar button only shows up when in incognito mode. | |
Peter Kasting
2015/09/25 23:42:52
Nit: I'd combine this comment with the one above a
anthonyvd
2015/09/29 20:23:15
Done.
| |
83 | |
76 // The first time UpdateOldAvatarButton() is called the window is not visible | 84 // The first time UpdateOldAvatarButton() is called the window is not visible |
77 // so DrawTaskBarDecoration() has no effect. Therefore we need to call it | 85 // so DrawTaskBarDecoration() has no effect. Therefore we need to call it |
78 // again once the window is visible. | 86 // again once the window is visible. |
Peter Kasting
2015/09/25 23:42:52
It's not obvious to me how this comment is related
anthonyvd
2015/09/29 20:23:15
I take it as an explanation of why we're calling t
Peter Kasting
2015/09/29 20:34:16
If it's a comment about how this containing functi
anthonyvd
2015/09/30 18:34:03
Good point. Since it's pertinent only to this spec
| |
79 if (!browser_view_->IsRegularOrGuestSession() || | 87 if (!browser_view_->IsRegularOrGuestSession()) { |
80 !switches::IsNewAvatarMenu()) { | |
81 UpdateOldAvatarButton(); | 88 UpdateOldAvatarButton(); |
82 } | 89 } |
83 | 90 |
84 // Make sure the task bar icon is correctly updated call | 91 // Make sure the task bar icon is correctly updated call |
85 // |OnProfileAvatarChanged()| in this case, but only for non guest profiles. | 92 // |OnProfileAvatarChanged()| in this case, but only for non guest profiles. |
Peter Kasting
2015/09/25 23:42:52
Nit: Fix this comment's grammar while here?
anthonyvd
2015/09/29 20:23:16
Done.
| |
86 if (!browser_view_->IsGuestSession() || !switches::IsNewAvatarMenu()) | 93 if (!browser_view_->IsGuestSession()) { |
Peter Kasting
2015/09/25 23:42:52
Nit: No {}
anthonyvd
2015/09/29 20:23:16
Done.
| |
87 OnProfileAvatarChanged(base::FilePath()); | 94 OnProfileAvatarChanged(base::FilePath()); |
95 } | |
96 #endif | |
88 } | 97 } |
89 | 98 |
90 void BrowserNonClientFrameView::ChildPreferredSizeChanged(View* child) { | 99 void BrowserNonClientFrameView::ChildPreferredSizeChanged(View* child) { |
91 #if defined(FRAME_AVATAR_BUTTON) | 100 #if defined(FRAME_AVATAR_BUTTON) |
92 // Only perform a re-layout if the avatar button has changed, since that | 101 // Only perform a re-layout if the avatar button has changed, since that |
93 // can affect the size of the tabs. | 102 // can affect the size of the tabs. |
94 if (child == new_avatar_button_) { | 103 if (child == new_avatar_button_) { |
95 InvalidateLayout(); | 104 InvalidateLayout(); |
96 frame_->GetRootView()->Layout(); | 105 frame_->GetRootView()->Layout(); |
97 } | 106 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 gfx::ImageSkia* frame_image = GetFrameImage(); | 181 gfx::ImageSkia* frame_image = GetFrameImage(); |
173 int top_area_height = frame_image->height(); | 182 int top_area_height = frame_image->height(); |
174 if (browser_view_->IsTabStripVisible()) { | 183 if (browser_view_->IsTabStripVisible()) { |
175 top_area_height = std::max(top_area_height, | 184 top_area_height = std::max(top_area_height, |
176 GetBoundsForTabStrip(browser_view_->tabstrip()).bottom()); | 185 GetBoundsForTabStrip(browser_view_->tabstrip()).bottom()); |
177 } | 186 } |
178 return top_area_height; | 187 return top_area_height; |
179 } | 188 } |
180 | 189 |
181 void BrowserNonClientFrameView::UpdateAvatar() { | 190 void BrowserNonClientFrameView::UpdateAvatar() { |
182 if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu()) | 191 #if !defined(OS_CHROMEOS) |
192 if (browser_view()->IsRegularOrGuestSession()) | |
183 UpdateNewAvatarButtonImpl(); | 193 UpdateNewAvatarButtonImpl(); |
184 else | 194 else |
195 #endif | |
185 UpdateOldAvatarButton(); | 196 UpdateOldAvatarButton(); |
186 } | 197 } |
187 | 198 |
188 void BrowserNonClientFrameView::UpdateOldAvatarButton() { | 199 void BrowserNonClientFrameView::UpdateOldAvatarButton() { |
189 if (browser_view_->ShouldShowAvatar()) { | 200 if (browser_view_->ShouldShowAvatar()) { |
190 if (!avatar_button_) { | 201 if (!avatar_button_) { |
191 #if defined(ENABLE_SUPERVISED_USERS) | 202 #if defined(ENABLE_SUPERVISED_USERS) |
192 Profile* profile = browser_view_->browser()->profile(); | 203 Profile* profile = browser_view_->browser()->profile(); |
193 if (profile->IsSupervised() && !supervised_user_avatar_label_) { | 204 if (profile->IsSupervised() && !supervised_user_avatar_label_) { |
194 supervised_user_avatar_label_ = | 205 supervised_user_avatar_label_ = |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) | 250 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) |
240 avatar_button_->SetEnabled(false); | 251 avatar_button_->SetEnabled(false); |
241 if (avatar_button_) | 252 if (avatar_button_) |
242 avatar_button_->SetAvatarIcon(avatar, is_rectangle); | 253 avatar_button_->SetAvatarIcon(avatar, is_rectangle); |
243 } | 254 } |
244 | 255 |
245 #if defined(FRAME_AVATAR_BUTTON) | 256 #if defined(FRAME_AVATAR_BUTTON) |
246 void BrowserNonClientFrameView::UpdateNewAvatarButton( | 257 void BrowserNonClientFrameView::UpdateNewAvatarButton( |
247 views::ButtonListener* listener, | 258 views::ButtonListener* listener, |
248 const NewAvatarButton::AvatarButtonStyle style) { | 259 const NewAvatarButton::AvatarButtonStyle style) { |
249 DCHECK(switches::IsNewAvatarMenu()); | |
250 // This should never be called in incognito mode. | 260 // This should never be called in incognito mode. |
251 DCHECK(browser_view_->IsRegularOrGuestSession()); | 261 DCHECK(browser_view_->IsRegularOrGuestSession()); |
252 | 262 |
253 if (browser_view_->ShouldShowAvatar()) { | 263 if (browser_view_->ShouldShowAvatar()) { |
254 if (!new_avatar_button_) { | 264 if (!new_avatar_button_) { |
255 new_avatar_button_ = | 265 new_avatar_button_ = |
256 new NewAvatarButton(listener, style, browser_view_->browser()); | 266 new NewAvatarButton(listener, style, browser_view_->browser()); |
257 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); | 267 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); |
258 AddChildView(new_avatar_button_); | 268 AddChildView(new_avatar_button_); |
259 frame_->GetRootView()->Layout(); | 269 frame_->GetRootView()->Layout(); |
(...skipping 15 matching lines...) Expand all Loading... | |
275 void BrowserNonClientFrameView::OnProfileWasRemoved( | 285 void BrowserNonClientFrameView::OnProfileWasRemoved( |
276 const base::FilePath& profile_path, | 286 const base::FilePath& profile_path, |
277 const base::string16& profile_name) { | 287 const base::string16& profile_name) { |
278 UpdateTaskbarDecoration(); | 288 UpdateTaskbarDecoration(); |
279 UpdateAvatar(); | 289 UpdateAvatar(); |
280 } | 290 } |
281 | 291 |
282 void BrowserNonClientFrameView::OnProfileAvatarChanged( | 292 void BrowserNonClientFrameView::OnProfileAvatarChanged( |
283 const base::FilePath& profile_path) { | 293 const base::FilePath& profile_path) { |
284 UpdateTaskbarDecoration(); | 294 UpdateTaskbarDecoration(); |
285 // Profile avatars are only displayed in the old UI or incognito. | 295 // Profile avatars are only displayed in incognito or on ChromeOS teleported |
286 if ((!browser_view()->IsGuestSession() && browser_view()->IsOffTheRecord()) || | 296 // windows. |
287 !switches::IsNewAvatarMenu()) { | 297 #if !defined(OS_CHROMEOS) |
298 if (!browser_view()->IsGuestSession() && browser_view()->IsOffTheRecord()) | |
299 #endif | |
288 UpdateOldAvatarButton(); | 300 UpdateOldAvatarButton(); |
289 } | |
290 } | 301 } |
291 | 302 |
292 void BrowserNonClientFrameView::UpdateTaskbarDecoration() { | 303 void BrowserNonClientFrameView::UpdateTaskbarDecoration() { |
293 gfx::Image avatar; | 304 gfx::Image avatar; |
294 gfx::Image taskbar_badge_avatar; | 305 gfx::Image taskbar_badge_avatar; |
295 bool is_rectangle; | 306 bool is_rectangle; |
296 // Only need to update the taskbar overlay here. If GetAvatarImages() | 307 // Only need to update the taskbar overlay here. If GetAvatarImages() |
297 // returns false, don't bother trying to update the taskbar decoration since | 308 // 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 | 309 // the returned images are not initialized. This can happen if the user |
299 // deletes the current profile. | 310 // deletes the current profile. |
(...skipping 17 matching lines...) Expand all Loading... | |
317 const ProfileInfoCache& cache = | 328 const ProfileInfoCache& cache = |
318 g_browser_process->profile_manager()->GetProfileInfoCache(); | 329 g_browser_process->profile_manager()->GetProfileInfoCache(); |
319 show_decoration = show_decoration && cache.GetNumberOfProfiles() > 1; | 330 show_decoration = show_decoration && cache.GetNumberOfProfiles() > 1; |
320 } | 331 } |
321 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), | 332 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), |
322 show_decoration | 333 show_decoration |
323 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) | 334 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) |
324 : nullptr); | 335 : nullptr); |
325 } | 336 } |
326 } | 337 } |
OLD | NEW |