Chromium Code Reviews| 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" | |
| 17 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 19 #include "third_party/skia/include/core/SkColor.h" | 21 #include "third_party/skia/include/core/SkColor.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/base/theme_provider.h" | 24 #include "ui/base/theme_provider.h" |
| 23 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 24 #include "ui/views/background.h" | 26 #include "ui/views/background.h" |
| 25 | 27 |
| 26 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, | 28 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, |
| 27 BrowserView* browser_view) | 29 BrowserView* browser_view) |
| 28 : frame_(frame), | 30 : frame_(frame), |
| 29 browser_view_(browser_view), | 31 browser_view_(browser_view), |
| 30 avatar_button_(NULL), | 32 avatar_button_(NULL), |
| 31 avatar_label_(NULL) { | 33 avatar_label_(NULL), |
| 34 new_avatar_button_(NULL) { | |
| 32 } | 35 } |
| 33 | 36 |
| 34 BrowserNonClientFrameView::~BrowserNonClientFrameView() { | 37 BrowserNonClientFrameView::~BrowserNonClientFrameView() { |
| 35 } | 38 } |
| 36 | 39 |
| 37 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, | 40 void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, |
| 38 bool is_visible) { | 41 bool is_visible) { |
| 39 if (!is_visible) | 42 if (!is_visible) |
| 40 return; | 43 return; |
| 41 // The first time UpdateAvatarInfo() is called the window is not visible so | 44 // The first time UpdateAvatarInfo() is called the window is not visible so |
| 42 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again | 45 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again |
| 43 // once the window is visible. | 46 // once the window is visible. |
| 44 UpdateAvatarInfo(); | 47 bool is_incognito = browser_view_->IsOffTheRecord() && |
| 48 !browser_view_->IsGuestSession(); | |
| 49 if (!is_incognito && profiles::IsNewProfileManagementEnabled()) | |
| 50 UpdateNewStyleAvatarInfo(); | |
|
sky
2013/09/26 20:21:39
Why do we need this here and not at init time?
noms (inactive)
2013/10/01 17:42:21
I don't fully understand the comment about DrawTas
| |
| 51 else | |
| 52 UpdateAvatarInfo(); | |
| 45 } | 53 } |
| 46 | 54 |
| 47 void BrowserNonClientFrameView::OnThemeChanged() { | 55 void BrowserNonClientFrameView::OnThemeChanged() { |
| 48 if (avatar_label_) | 56 if (avatar_label_) |
| 49 avatar_label_->UpdateLabelStyle(); | 57 avatar_label_->UpdateLabelStyle(); |
| 50 } | 58 } |
| 51 | 59 |
| 52 void BrowserNonClientFrameView::UpdateAvatarInfo() { | 60 void BrowserNonClientFrameView::UpdateAvatarInfo() { |
| 53 if (browser_view_->ShouldShowAvatar()) { | 61 if (browser_view_->ShouldShowAvatar()) { |
| 54 if (!avatar_button_) { | 62 if (!avatar_button_) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 if (!text.empty()) | 112 if (!text.empty()) |
| 105 avatar_button_->SetText(text); | 113 avatar_button_->SetText(text); |
| 106 } | 114 } |
| 107 | 115 |
| 108 // For popups and panels which don't have the avatar button, we still | 116 // For popups and panels which don't have the avatar button, we still |
| 109 // need to draw the taskbar decoration. | 117 // need to draw the taskbar decoration. |
| 110 chrome::DrawTaskbarDecoration( | 118 chrome::DrawTaskbarDecoration( |
| 111 frame_->GetNativeWindow(), | 119 frame_->GetNativeWindow(), |
| 112 AvatarMenu::ShouldShowAvatarMenu() ? &avatar : NULL); | 120 AvatarMenu::ShouldShowAvatarMenu() ? &avatar : NULL); |
| 113 } | 121 } |
| 122 | |
| 123 void BrowserNonClientFrameView::UpdateNewStyleAvatarInfo() { | |
| 124 DCHECK(profiles::IsNewProfileManagementEnabled()); | |
| 125 // This should never be called in incognito mode. | |
| 126 if (browser_view_->IsOffTheRecord()) | |
| 127 DCHECK(browser_view_->IsGuestSession()); | |
| 128 | |
| 129 if (browser_view_->ShouldShowAvatar()) { | |
| 130 if (!new_avatar_button_) { | |
| 131 // The name of the profile that should be displayed in the button. | |
| 132 string16 profile_name; | |
| 133 if (browser_view_->IsGuestSession()) { | |
| 134 profile_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME); | |
| 135 } else { | |
| 136 ProfileInfoCache& cache = | |
| 137 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 138 Profile* profile = browser_view_->browser()->profile(); | |
| 139 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | |
| 140 if (index != std::string::npos) | |
| 141 profile_name = cache.GetNameOfProfileAtIndex(index); | |
| 142 } | |
| 143 new_avatar_button_ = new NewAvatarButton(browser_view_, profile_name); | |
| 144 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); | |
| 145 AddChildView(new_avatar_button_); | |
| 146 frame_->GetRootView()->Layout(); | |
| 147 } | |
| 148 } else if (new_avatar_button_) { | |
| 149 RemoveChildView(new_avatar_button_); | |
| 150 delete new_avatar_button_; | |
| 151 new_avatar_button_ = NULL; | |
| 152 frame_->GetRootView()->Layout(); | |
| 153 } | |
| 154 } | |
| 155 | |
| OLD | NEW |