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 "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 Loading... | |
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), |
38 observer_(this) { | |
sky
2016/03/17 21:00:31
Feels wrong to have an observer on Widget when the
Peter Kasting
2016/03/17 23:14:10
Done.
| |
42 // The profile manager may by null in tests. | 39 // The profile manager may by null in tests. |
43 if (g_browser_process->profile_manager()) { | 40 if (g_browser_process->profile_manager()) { |
44 g_browser_process->profile_manager()-> | 41 g_browser_process->profile_manager()-> |
45 GetProfileAttributesStorage().AddObserver(this); | 42 GetProfileAttributesStorage().AddObserver(this); |
46 } | 43 } |
47 } | 44 } |
48 | 45 |
49 BrowserNonClientFrameView::~BrowserNonClientFrameView() { | 46 BrowserNonClientFrameView::~BrowserNonClientFrameView() { |
50 // The profile manager may by null in tests. | 47 // The profile manager may by null in tests. |
51 if (g_browser_process->profile_manager()) { | 48 if (g_browser_process->profile_manager()) { |
52 g_browser_process->profile_manager()-> | 49 g_browser_process->profile_manager()-> |
53 GetProfileAttributesStorage().RemoveObserver(this); | 50 GetProfileAttributesStorage().RemoveObserver(this); |
54 } | 51 } |
55 } | 52 } |
56 | 53 |
57 void BrowserNonClientFrameView::OnBrowserViewInitViewsComplete() {} | 54 void BrowserNonClientFrameView::OnBrowserViewInitViewsComplete() {} |
58 | 55 |
59 gfx::ImageSkia BrowserNonClientFrameView::GetOTRAvatarIcon() const { | 56 gfx::ImageSkia BrowserNonClientFrameView::GetOTRAvatarIcon() const { |
60 if (!ui::MaterialDesignController::IsModeMaterial()) | 57 if (!ui::MaterialDesignController::IsModeMaterial()) |
61 return *GetThemeProviderForProfile()->GetImageSkiaNamed(IDR_OTR_ICON); | 58 return *GetThemeProviderForProfile()->GetImageSkiaNamed(IDR_OTR_ICON); |
62 SkColor icon_color = SK_ColorWHITE; | 59 const SkColor icon_color = color_utils::PickContrastingColor( |
63 #if defined(OS_WIN) | 60 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); | 61 return gfx::CreateVectorIcon(gfx::VectorIconId::INCOGNITO, 24, icon_color); |
71 } | 62 } |
72 | 63 |
73 void BrowserNonClientFrameView::UpdateToolbar() { | 64 void BrowserNonClientFrameView::UpdateToolbar() { |
74 } | 65 } |
75 | 66 |
76 views::View* BrowserNonClientFrameView::GetLocationIconView() const { | 67 views::View* BrowserNonClientFrameView::GetLocationIconView() const { |
77 return nullptr; | 68 return nullptr; |
78 } | 69 } |
79 | 70 |
(...skipping 12 matching lines...) Expand all Loading... | |
92 } | 83 } |
93 | 84 |
94 bool BrowserNonClientFrameView::ShouldPaintAsThemed() const { | 85 bool BrowserNonClientFrameView::ShouldPaintAsThemed() const { |
95 return browser_view_->IsBrowserTypeNormal(); | 86 return browser_view_->IsBrowserTypeNormal(); |
96 } | 87 } |
97 | 88 |
98 SkColor BrowserNonClientFrameView::GetFrameColor(bool active) const { | 89 SkColor BrowserNonClientFrameView::GetFrameColor(bool active) const { |
99 ThemeProperties::OverwritableByUserThemeProperty color_id = | 90 ThemeProperties::OverwritableByUserThemeProperty color_id = |
100 active ? ThemeProperties::COLOR_FRAME | 91 active ? ThemeProperties::COLOR_FRAME |
101 : ThemeProperties::COLOR_FRAME_INACTIVE; | 92 : ThemeProperties::COLOR_FRAME_INACTIVE; |
102 return ShouldPaintAsThemed() ? GetThemeProvider()->GetColor(color_id) | 93 return ShouldPaintAsThemed() ? |
103 : ThemeProperties::GetDefaultColor( | 94 GetThemeProviderForProfile()->GetColor(color_id) : |
104 color_id, browser_view_->IsOffTheRecord()); | 95 ThemeProperties::GetDefaultColor(color_id, |
96 browser_view_->IsOffTheRecord()); | |
105 } | 97 } |
106 | 98 |
107 gfx::ImageSkia BrowserNonClientFrameView::GetFrameImage(bool active) const { | 99 gfx::ImageSkia BrowserNonClientFrameView::GetFrameImage(bool active) const { |
108 const ui::ThemeProvider* tp = frame_->GetThemeProvider(); | 100 const ui::ThemeProvider* tp = frame_->GetThemeProvider(); |
109 int frame_image_id = active ? IDR_THEME_FRAME : IDR_THEME_FRAME_INACTIVE; | 101 int frame_image_id = active ? IDR_THEME_FRAME : IDR_THEME_FRAME_INACTIVE; |
110 | 102 |
111 // |default_uses_color| means the default frame is painted with a solid color. | 103 // |default_uses_color| means the default frame is painted with a solid color. |
112 // When false, the default frame is painted with assets. | 104 // When false, the default frame is painted with assets. |
113 #if defined(OS_CHROMEOS) | 105 #if defined(OS_CHROMEOS) |
114 bool default_uses_color = true; | 106 bool default_uses_color = true; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 | 176 |
185 // Disable the menu when we should not show the menu. | 177 // Disable the menu when we should not show the menu. |
186 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) | 178 if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) |
187 avatar_button_->SetEnabled(false); | 179 avatar_button_->SetEnabled(false); |
188 if (avatar_button_) | 180 if (avatar_button_) |
189 avatar_button_->SetAvatarIcon(avatar, is_rectangle); | 181 avatar_button_->SetAvatarIcon(avatar, is_rectangle); |
190 } | 182 } |
191 | 183 |
192 void BrowserNonClientFrameView::ViewHierarchyChanged( | 184 void BrowserNonClientFrameView::ViewHierarchyChanged( |
193 const ViewHierarchyChangedDetails& details) { | 185 const ViewHierarchyChangedDetails& details) { |
194 if (details.is_add && details.child == this) | 186 if (details.is_add && details.child == this) { |
187 if (ui::MaterialDesignController::IsModeMaterial()) | |
188 observer_.Add(GetWidget()); | |
195 UpdateAvatar(); | 189 UpdateAvatar(); |
190 } | |
191 } | |
192 | |
193 // TODO(pkasting): This probably isn't needed, I bet the widget is guaranteed to | |
194 // outlive us. | |
195 void BrowserNonClientFrameView::OnWidgetDestroyed(views::Widget* widget) { | |
196 observer_.Remove(widget); | |
197 } | |
198 | |
199 void BrowserNonClientFrameView::OnWidgetActivationChanged(views::Widget* widget, | |
200 bool active) { | |
201 // On Windows, while deactivating the widget, this is called before the active | |
202 // HWND has actually been changed. Since we want the avatar state to reflect | |
203 // that the window is inactive, we force NonClientFrameView to see the | |
204 // "correct" state as an override. | |
205 set_active_state_override(&active); | |
206 UpdateAvatar(); | |
207 set_active_state_override(nullptr); | |
196 } | 208 } |
197 | 209 |
198 void BrowserNonClientFrameView::OnProfileAdded( | 210 void BrowserNonClientFrameView::OnProfileAdded( |
199 const base::FilePath& profile_path) { | 211 const base::FilePath& profile_path) { |
200 OnProfileAvatarChanged(profile_path); | 212 OnProfileAvatarChanged(profile_path); |
201 } | 213 } |
202 | 214 |
203 void BrowserNonClientFrameView::OnProfileWasRemoved( | 215 void BrowserNonClientFrameView::OnProfileWasRemoved( |
204 const base::FilePath& profile_path, | 216 const base::FilePath& profile_path, |
205 const base::string16& profile_name) { | 217 const base::string16& profile_name) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 const ProfileAttributesStorage& storage = | 258 const ProfileAttributesStorage& storage = |
247 g_browser_process->profile_manager()->GetProfileAttributesStorage(); | 259 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
248 show_decoration = show_decoration && storage.GetNumberOfProfiles() > 1; | 260 show_decoration = show_decoration && storage.GetNumberOfProfiles() > 1; |
249 } | 261 } |
250 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), | 262 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), |
251 show_decoration | 263 show_decoration |
252 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) | 264 ? (taskbar_badge_avatar.IsEmpty() ? &avatar : &taskbar_badge_avatar) |
253 : nullptr); | 265 : nullptr); |
254 } | 266 } |
255 } | 267 } |
OLD | NEW |