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

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

Issue 1733293002: Toggle avatar color when window activation changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Convert widget observer to direct call Created 4 years, 9 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"
(...skipping 13 matching lines...) Expand all
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/base/theme_provider.h" 25 #include "ui/base/theme_provider.h"
26 #include "ui/gfx/color_palette.h" 26 #include "ui/gfx/color_palette.h"
27 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
28 #include "ui/gfx/paint_vector_icon.h" 28 #include "ui/gfx/paint_vector_icon.h"
29 #include "ui/gfx/vector_icons_public.h" 29 #include "ui/gfx/vector_icons_public.h"
30 #include "ui/resources/grit/ui_resources.h" 30 #include "ui/resources/grit/ui_resources.h"
31 #include "ui/views/background.h" 31 #include "ui/views/background.h"
32 #include "ui/views/resources/grit/views_resources.h" 32 #include "ui/views/resources/grit/views_resources.h"
33 33
34 #if defined(OS_WIN)
35 #include "base/win/windows_version.h"
36 #endif
37
38 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, 34 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame,
39 BrowserView* browser_view) 35 BrowserView* browser_view)
40 : frame_(frame), 36 : frame_(frame),
41 browser_view_(browser_view) { 37 browser_view_(browser_view) {
42 // The profile manager may by null in tests. 38 // The profile manager may by null in tests.
43 if (g_browser_process->profile_manager()) { 39 if (g_browser_process->profile_manager()) {
44 g_browser_process->profile_manager()-> 40 g_browser_process->profile_manager()->
45 GetProfileAttributesStorage().AddObserver(this); 41 GetProfileAttributesStorage().AddObserver(this);
46 } 42 }
47 } 43 }
48 44
49 BrowserNonClientFrameView::~BrowserNonClientFrameView() { 45 BrowserNonClientFrameView::~BrowserNonClientFrameView() {
50 // The profile manager may by null in tests. 46 // The profile manager may by null in tests.
51 if (g_browser_process->profile_manager()) { 47 if (g_browser_process->profile_manager()) {
52 g_browser_process->profile_manager()-> 48 g_browser_process->profile_manager()->
53 GetProfileAttributesStorage().RemoveObserver(this); 49 GetProfileAttributesStorage().RemoveObserver(this);
54 } 50 }
55 } 51 }
56 52
57 void BrowserNonClientFrameView::OnBrowserViewInitViewsComplete() {} 53 void BrowserNonClientFrameView::OnBrowserViewInitViewsComplete() {}
58 54
59 gfx::ImageSkia BrowserNonClientFrameView::GetOTRAvatarIcon() const { 55 gfx::ImageSkia BrowserNonClientFrameView::GetOTRAvatarIcon() const {
60 if (!ui::MaterialDesignController::IsModeMaterial()) 56 if (!ui::MaterialDesignController::IsModeMaterial())
61 return *GetThemeProviderForProfile()->GetImageSkiaNamed(IDR_OTR_ICON); 57 return *GetThemeProviderForProfile()->GetImageSkiaNamed(IDR_OTR_ICON);
62 SkColor icon_color = SK_ColorWHITE; 58 const SkColor icon_color = color_utils::PickContrastingColor(
63 #if defined(OS_WIN) 59 SK_ColorWHITE, gfx::kChromeIconGrey, GetFrameColor());
64 // On Windows 10+, we assume the native frame color is white.
65 // TODO(pkasting): Read the correct frame color from the registry or APIs.
66 if (GetWidget() && GetWidget()->ShouldUseNativeFrame() &&
67 (base::win::GetVersion() >= base::win::VERSION_WIN10))
68 icon_color = gfx::kChromeIconGrey;
69 #endif
70 return gfx::CreateVectorIcon(gfx::VectorIconId::INCOGNITO, 24, icon_color); 60 return gfx::CreateVectorIcon(gfx::VectorIconId::INCOGNITO, 24, icon_color);
71 } 61 }
72 62
73 void BrowserNonClientFrameView::UpdateToolbar() { 63 void BrowserNonClientFrameView::UpdateToolbar() {
74 } 64 }
75 65
76 views::View* BrowserNonClientFrameView::GetLocationIconView() const { 66 views::View* BrowserNonClientFrameView::GetLocationIconView() const {
77 return nullptr; 67 return nullptr;
78 } 68 }
79 69
(...skipping 12 matching lines...) Expand all
92 } 82 }
93 83
94 bool BrowserNonClientFrameView::ShouldPaintAsThemed() const { 84 bool BrowserNonClientFrameView::ShouldPaintAsThemed() const {
95 return browser_view_->IsBrowserTypeNormal(); 85 return browser_view_->IsBrowserTypeNormal();
96 } 86 }
97 87
98 SkColor BrowserNonClientFrameView::GetFrameColor(bool active) const { 88 SkColor BrowserNonClientFrameView::GetFrameColor(bool active) const {
99 ThemeProperties::OverwritableByUserThemeProperty color_id = 89 ThemeProperties::OverwritableByUserThemeProperty color_id =
100 active ? ThemeProperties::COLOR_FRAME 90 active ? ThemeProperties::COLOR_FRAME
101 : ThemeProperties::COLOR_FRAME_INACTIVE; 91 : ThemeProperties::COLOR_FRAME_INACTIVE;
102 return ShouldPaintAsThemed() ? GetThemeProvider()->GetColor(color_id) 92 return ShouldPaintAsThemed() ?
103 : ThemeProperties::GetDefaultColor( 93 GetThemeProviderForProfile()->GetColor(color_id) :
104 color_id, browser_view_->IsOffTheRecord()); 94 ThemeProperties::GetDefaultColor(color_id,
95 browser_view_->IsOffTheRecord());
105 } 96 }
106 97
107 gfx::ImageSkia BrowserNonClientFrameView::GetFrameImage(bool active) const { 98 gfx::ImageSkia BrowserNonClientFrameView::GetFrameImage(bool active) const {
108 const ui::ThemeProvider* tp = frame_->GetThemeProvider(); 99 const ui::ThemeProvider* tp = frame_->GetThemeProvider();
109 int frame_image_id = active ? IDR_THEME_FRAME : IDR_THEME_FRAME_INACTIVE; 100 int frame_image_id = active ? IDR_THEME_FRAME : IDR_THEME_FRAME_INACTIVE;
110 101
111 // |default_uses_color| means the default frame is painted with a solid color. 102 // |default_uses_color| means the default frame is painted with a solid color.
112 // When false, the default frame is painted with assets. 103 // When false, the default frame is painted with assets.
113 #if defined(OS_CHROMEOS) 104 #if defined(OS_CHROMEOS)
114 bool default_uses_color = true; 105 bool default_uses_color = true;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (avatar_button_) 179 if (avatar_button_)
189 avatar_button_->SetAvatarIcon(avatar, is_rectangle); 180 avatar_button_->SetAvatarIcon(avatar, is_rectangle);
190 } 181 }
191 182
192 void BrowserNonClientFrameView::ViewHierarchyChanged( 183 void BrowserNonClientFrameView::ViewHierarchyChanged(
193 const ViewHierarchyChangedDetails& details) { 184 const ViewHierarchyChangedDetails& details) {
194 if (details.is_add && details.child == this) 185 if (details.is_add && details.child == this)
195 UpdateAvatar(); 186 UpdateAvatar();
196 } 187 }
197 188
189 void BrowserNonClientFrameView::ActivationChanged(bool active) {
190 if (ui::MaterialDesignController::IsModeMaterial()) {
191 // On Windows, while deactivating the widget, this is called before the
192 // active HWND has actually been changed. Since we want the avatar state to
193 // reflect that the window is inactive, we force NonClientFrameView to see
194 // the "correct" state as an override.
195 set_active_state_override(&active);
196 UpdateAvatar();
197 set_active_state_override(nullptr);
198 }
199 }
200
198 void BrowserNonClientFrameView::OnProfileAdded( 201 void BrowserNonClientFrameView::OnProfileAdded(
199 const base::FilePath& profile_path) { 202 const base::FilePath& profile_path) {
200 OnProfileAvatarChanged(profile_path); 203 OnProfileAvatarChanged(profile_path);
201 } 204 }
202 205
203 void BrowserNonClientFrameView::OnProfileWasRemoved( 206 void BrowserNonClientFrameView::OnProfileWasRemoved(
204 const base::FilePath& profile_path, 207 const base::FilePath& profile_path,
205 const base::string16& profile_name) { 208 const base::string16& profile_name) {
206 OnProfileAvatarChanged(profile_path); 209 OnProfileAvatarChanged(profile_path);
207 } 210 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 const ProfileAttributesStorage& storage = 249 const ProfileAttributesStorage& storage =
247 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 250 g_browser_process->profile_manager()->GetProfileAttributesStorage();
248 show_decoration = show_decoration && storage.GetNumberOfProfiles() > 1; 251 show_decoration = show_decoration && storage.GetNumberOfProfiles() > 1;
249 } 252 }
250 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), 253 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(),
251 show_decoration 254 show_decoration
252 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) 255 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar)
253 : nullptr); 256 : nullptr);
254 } 257 }
255 } 258 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_non_client_frame_view.h ('k') | ui/views/widget/widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698