Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/ui/views/frame/browser_non_client_frame_view.cc

Issue 1972033002: Simplify some old avatar menu button code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_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/themes/theme_properties.h" 14 #include "chrome/browser/themes/theme_properties.h"
15 #include "chrome/browser/ui/view_ids.h" 15 #include "chrome/browser/ui/view_ids.h"
16 #include "chrome/browser/ui/views/frame/browser_view.h" 16 #include "chrome/browser/ui/views/frame/browser_view.h"
17 #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/profiles/avatar_menu_button.h"
19 #include "chrome/browser/ui/views/tabs/tab_strip.h" 18 #include "chrome/browser/ui/views/tabs/tab_strip.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/material_design/material_design_controller.h" 22 #include "ui/base/material_design/material_design_controller.h"
24 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/base/theme_provider.h" 24 #include "ui/base/theme_provider.h"
26 #include "ui/gfx/color_palette.h" 25 #include "ui/gfx/color_palette.h"
27 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
28 #include "ui/gfx/paint_vector_icon.h" 27 #include "ui/gfx/paint_vector_icon.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 146 }
148 147
149 gfx::ImageSkia BrowserNonClientFrameView::GetFrameImage() const { 148 gfx::ImageSkia BrowserNonClientFrameView::GetFrameImage() const {
150 return GetFrameImage(ShouldPaintAsActive()); 149 return GetFrameImage(ShouldPaintAsActive());
151 } 150 }
152 151
153 gfx::ImageSkia BrowserNonClientFrameView::GetFrameOverlayImage() const { 152 gfx::ImageSkia BrowserNonClientFrameView::GetFrameOverlayImage() const {
154 return GetFrameOverlayImage(ShouldPaintAsActive()); 153 return GetFrameOverlayImage(ShouldPaintAsActive());
155 } 154 }
156 155
157 void BrowserNonClientFrameView::UpdateOldAvatarButton() { 156 void BrowserNonClientFrameView::UpdateProfileIndicatorIcon() {
158 if (browser_view_->ShouldShowAvatar()) { 157 if (!profile_indicator_) {
159 if (!avatar_button_) { 158 profile_indicator_ = new ProfileIndicatorIcon(browser_view_);
160 avatar_button_ = new AvatarMenuButton(browser_view_); 159 profile_indicator_->set_id(VIEW_ID_PROFILE_INDICATOR_ICON);
161 avatar_button_->set_id(VIEW_ID_AVATAR_BUTTON); 160 AddChildView(profile_indicator_);
162 AddChildView(avatar_button_); 161 // Invalidate here because adding a child does not invalidate the layout.
163 // Invalidate here because adding a child does not invalidate the layout. 162 InvalidateLayout();
164 InvalidateLayout();
165 frame_->GetRootView()->Layout();
166 }
167 } else if (avatar_button_) {
168 RemoveChildView(avatar_button_);
169 delete avatar_button_;
170 avatar_button_ = nullptr;
171 frame_->GetRootView()->Layout(); 163 frame_->GetRootView()->Layout();
172 } 164 }
173 165
174 gfx::Image avatar; 166 gfx::Image icon;
175 gfx::Image taskbar_badge_avatar; 167 const Profile* profile = browser_view()->browser()->profile();
176 bool is_rectangle = false; 168 if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) {
169 icon = gfx::Image(GetOTRAvatarIcon());
170 } else {
171 #if defined(OS_CHROMEOS)
172 bool unused;
173 AvatarMenu::GetImageForMenuButton(profile->GetPath(), &icon, &unused);
Peter Kasting 2016/05/17 03:51:42 Nit: Does this need to be conditionally compiled i
Evan Stade 2016/05/17 18:13:08 I wanted to add the NOTREACHED to document that th
Peter Kasting 2016/05/18 02:44:01 Can we just have a comment that says "only reached
Evan Stade 2016/05/20 22:04:42 I personally don't have a problem with ifdefs. Sur
Peter Kasting 2016/05/20 22:24:22 How you have it is fine.
174 #else
175 NOTREACHED();
176 #endif
177 }
177 178
178 // Update the avatar button in the window frame and the taskbar overlay. 179 profile_indicator_->SetIcon(icon);
179 bool should_show_avatar_menu =
180 avatar_button_ || AvatarMenu::ShouldShowAvatarMenu();
181
182 if (!AvatarMenuButton::GetAvatarImages(this, should_show_avatar_menu, &avatar,
183 &taskbar_badge_avatar, &is_rectangle))
184 return;
185
186 // Disable the menu when we should not show the menu.
187 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu())
188 avatar_button_->SetEnabled(false);
189 if (avatar_button_)
190 avatar_button_->SetAvatarIcon(avatar, is_rectangle);
191 } 180 }
192 181
193 void BrowserNonClientFrameView::ViewHierarchyChanged( 182 void BrowserNonClientFrameView::ViewHierarchyChanged(
194 const ViewHierarchyChangedDetails& details) { 183 const ViewHierarchyChangedDetails& details) {
195 if (details.is_add && details.child == this) 184 if (details.is_add && details.child == this)
196 UpdateAvatar(); 185 UpdateProfileIcons();
197 } 186 }
198 187
199 void BrowserNonClientFrameView::ActivationChanged(bool active) { 188 void BrowserNonClientFrameView::ActivationChanged(bool active) {
200 if (ui::MaterialDesignController::IsModeMaterial()) { 189 if (ui::MaterialDesignController::IsModeMaterial()) {
201 // On Windows, while deactivating the widget, this is called before the 190 // On Windows, while deactivating the widget, this is called before the
202 // active HWND has actually been changed. Since we want the avatar state to 191 // active HWND has actually been changed. Since we want the avatar state to
203 // reflect that the window is inactive, we force NonClientFrameView to see 192 // reflect that the window is inactive, we force NonClientFrameView to see
204 // the "correct" state as an override. 193 // the "correct" state as an override.
205 set_active_state_override(&active); 194 set_active_state_override(&active);
206 UpdateAvatar(); 195 UpdateProfileIcons();
207 set_active_state_override(nullptr); 196 set_active_state_override(nullptr);
208 197
209 // Changing the activation state may change the toolbar top separator color 198 // Changing the activation state may change the toolbar top separator color
210 // that's used as the stroke around tabs/the new tab button. 199 // that's used as the stroke around tabs/the new tab button.
211 browser_view_->tabstrip()->SchedulePaint(); 200 browser_view_->tabstrip()->SchedulePaint();
212 } 201 }
213 202
214 // Changing the activation state may change the visible frame color. 203 // Changing the activation state may change the visible frame color.
215 SchedulePaint(); 204 SchedulePaint();
216 } 205 }
217 206
218 void BrowserNonClientFrameView::OnProfileAdded( 207 void BrowserNonClientFrameView::OnProfileAdded(
219 const base::FilePath& profile_path) { 208 const base::FilePath& profile_path) {
220 OnProfileAvatarChanged(profile_path); 209 OnProfileAvatarChanged(profile_path);
221 } 210 }
222 211
223 void BrowserNonClientFrameView::OnProfileWasRemoved( 212 void BrowserNonClientFrameView::OnProfileWasRemoved(
224 const base::FilePath& profile_path, 213 const base::FilePath& profile_path,
225 const base::string16& profile_name) { 214 const base::string16& profile_name) {
226 OnProfileAvatarChanged(profile_path); 215 OnProfileAvatarChanged(profile_path);
227 } 216 }
228 217
229 void BrowserNonClientFrameView::OnProfileAvatarChanged( 218 void BrowserNonClientFrameView::OnProfileAvatarChanged(
230 const base::FilePath& profile_path) { 219 const base::FilePath& profile_path) {
231 UpdateTaskbarDecoration(); 220 UpdateTaskbarDecoration();
232 UpdateAvatar(); 221 UpdateProfileIcons();
233 } 222 }
234 223
235 const ui::ThemeProvider* 224 const ui::ThemeProvider*
236 BrowserNonClientFrameView::GetThemeProviderForProfile() const { 225 BrowserNonClientFrameView::GetThemeProviderForProfile() const {
237 // Because the frame's accessor reads the ThemeProvider from the profile and 226 // Because the frame's accessor reads the ThemeProvider from the profile and
238 // not the widget, it can be called even before we're in a view hierarchy. 227 // not the widget, it can be called even before we're in a view hierarchy.
239 return frame_->GetThemeProvider(); 228 return frame_->GetThemeProvider();
240 } 229 }
241 230
242 void BrowserNonClientFrameView::UpdateTaskbarDecoration() { 231 void BrowserNonClientFrameView::UpdateTaskbarDecoration() {
243 gfx::Image avatar; 232 #if defined(OS_WIN)
244 gfx::Image taskbar_badge_avatar; 233 if (browser_view()->browser()->profile()->IsGuestSession() ||
245 bool is_rectangle; 234 // In tests, make sure that the browser process and profile manager are
246 // Only need to update the taskbar overlay here. If GetAvatarImages() 235 // valid before using.
Peter Kasting 2016/05/17 03:51:42 Nit: Comment might be clearer as "Tests may not ha
Evan Stade 2016/05/17 18:13:08 Done.
247 // returns false, don't bother trying to update the taskbar decoration since 236 (g_browser_process && g_browser_process->profile_manager() &&
248 // the returned images are not initialized. This can happen if the user 237 g_browser_process->profile_manager()
249 // deletes the current profile. 238 ->GetProfileAttributesStorage()
250 if (AvatarMenuButton::GetAvatarImages( 239 .GetNumberOfProfiles() <= 1)) {
251 this, AvatarMenu::ShouldShowAvatarMenu(), &avatar, 240 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), nullptr);
Peter Kasting 2016/05/17 03:51:42 If you're going to make this whole block ifdefed f
Evan Stade 2016/05/17 18:13:08 Done.
252 &taskbar_badge_avatar, &is_rectangle)) { 241 return;
253 // For popups and panels which don't have the avatar button, we still
254 // need to draw the taskbar decoration. Even though we have an icon on the
255 // window's relaunch details, we draw over it because the user may have
256 // pinned the badge-less Chrome shortcut which will cause windows to ignore
257 // the relaunch details.
258 // TODO(calamity): ideally this should not be necessary but due to issues
259 // with the default shortcut being pinned, we add the runtime badge for
260 // safety. See crbug.com/313800.
261 bool show_decoration = AvatarMenu::ShouldShowAvatarMenu() &&
262 !browser_view_->browser()->profile()->IsGuestSession();
263 // In tests, make sure that the browser process and profile manager are
264 // valid before using.
265 if (g_browser_process && g_browser_process->profile_manager()) {
266 const ProfileAttributesStorage& storage =
267 g_browser_process->profile_manager()->GetProfileAttributesStorage();
268 show_decoration = show_decoration && storage.GetNumberOfProfiles() > 1;
269 }
270 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(),
271 show_decoration
272 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar)
273 : nullptr);
274 } 242 }
243
244 // For popups and panels which don't have the avatar button, we still
245 // need to draw the taskbar decoration. Even though we have an icon on the
246 // window's relaunch details, we draw over it because the user may have
247 // pinned the badge-less Chrome shortcut which will cause windows to ignore
Peter Kasting 2016/05/17 03:51:42 Nit: While here: windows -> Windows ?
Evan Stade 2016/05/17 18:13:08 Done.
248 // the relaunch details.
249 // TODO(calamity): ideally this should not be necessary but due to issues
250 // with the default shortcut being pinned, we add the runtime badge for
251 // safety. See crbug.com/313800.
252 gfx::Image decoration;
253 bool unused;
Peter Kasting 2016/05/17 03:51:42 Nit: This is the second place in this file that do
Evan Stade 2016/05/17 18:13:08 turns out it's not used anywhere any more. Removed
254 AvatarMenu::GetImageForMenuButton(
255 browser_view()->browser()->profile()->GetPath(), &decoration, &unused);
256 // This can happen if the user deletes the current profile.
257 if (decoration.IsEmpty())
258 return;
259 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), &decoration);
260 #endif
275 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698