| 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" |
| 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/profiles/profiles_state.h" | |
| 14 #include "chrome/browser/themes/theme_properties.h" | 12 #include "chrome/browser/themes/theme_properties.h" |
| 15 #include "chrome/browser/ui/view_ids.h" | 13 #include "chrome/browser/ui/view_ids.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 15 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 18 #include "chrome/grit/theme_resources.h" | 16 #include "chrome/grit/theme_resources.h" |
| 19 #include "components/signin/core/common/profile_management_switches.h" | 17 #include "components/signin/core/common/profile_management_switches.h" |
| 20 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
| 21 #include "ui/base/material_design/material_design_controller.h" | |
| 22 #include "ui/base/resource/resource_bundle.h" | |
| 23 #include "ui/base/theme_provider.h" | 19 #include "ui/base/theme_provider.h" |
| 24 #include "ui/gfx/color_palette.h" | 20 #include "ui/gfx/color_palette.h" |
| 25 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| 26 #include "ui/gfx/paint_vector_icon.h" | 22 #include "ui/gfx/paint_vector_icon.h" |
| 27 #include "ui/gfx/vector_icons_public.h" | 23 #include "ui/gfx/vector_icons_public.h" |
| 28 #include "ui/resources/grit/ui_resources.h" | |
| 29 #include "ui/views/background.h" | 24 #include "ui/views/background.h" |
| 30 #include "ui/views/resources/grit/views_resources.h" | |
| 31 | 25 |
| 32 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 33 #include "chrome/browser/ui/views/frame/taskbar_decorator_win.h" | 27 #include "chrome/browser/ui/views/frame/taskbar_decorator_win.h" |
| 34 #endif | 28 #endif |
| 35 | 29 |
| 36 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, | 30 BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, |
| 37 BrowserView* browser_view) | 31 BrowserView* browser_view) |
| 38 : frame_(frame), | 32 : frame_(frame), |
| 39 browser_view_(browser_view), | 33 browser_view_(browser_view), |
| 40 profile_indicator_icon_(nullptr) { | 34 profile_indicator_icon_(nullptr) { |
| 41 // The profile manager may by null in tests. | 35 // The profile manager may by null in tests. |
| 42 if (g_browser_process->profile_manager()) { | 36 if (g_browser_process->profile_manager()) { |
| 43 g_browser_process->profile_manager()-> | 37 g_browser_process->profile_manager()-> |
| 44 GetProfileAttributesStorage().AddObserver(this); | 38 GetProfileAttributesStorage().AddObserver(this); |
| 45 } | 39 } |
| 46 } | 40 } |
| 47 | 41 |
| 48 BrowserNonClientFrameView::~BrowserNonClientFrameView() { | 42 BrowserNonClientFrameView::~BrowserNonClientFrameView() { |
| 49 // The profile manager may by null in tests. | 43 // The profile manager may by null in tests. |
| 50 if (g_browser_process->profile_manager()) { | 44 if (g_browser_process->profile_manager()) { |
| 51 g_browser_process->profile_manager()-> | 45 g_browser_process->profile_manager()-> |
| 52 GetProfileAttributesStorage().RemoveObserver(this); | 46 GetProfileAttributesStorage().RemoveObserver(this); |
| 53 } | 47 } |
| 54 } | 48 } |
| 55 | 49 |
| 56 void BrowserNonClientFrameView::OnBrowserViewInitViewsComplete() {} | 50 void BrowserNonClientFrameView::OnBrowserViewInitViewsComplete() {} |
| 57 | 51 |
| 58 gfx::ImageSkia BrowserNonClientFrameView::GetIncognitoAvatarIcon() const { | 52 gfx::ImageSkia BrowserNonClientFrameView::GetIncognitoAvatarIcon() const { |
| 59 if (!ui::MaterialDesignController::IsModeMaterial()) | |
| 60 return *GetThemeProviderForProfile()->GetImageSkiaNamed(IDR_OTR_ICON); | |
| 61 const SkColor icon_color = color_utils::PickContrastingColor( | 53 const SkColor icon_color = color_utils::PickContrastingColor( |
| 62 SK_ColorWHITE, gfx::kChromeIconGrey, GetFrameColor()); | 54 SK_ColorWHITE, gfx::kChromeIconGrey, GetFrameColor()); |
| 63 return gfx::CreateVectorIcon(gfx::VectorIconId::INCOGNITO, icon_color); | 55 return gfx::CreateVectorIcon(gfx::VectorIconId::INCOGNITO, icon_color); |
| 64 } | 56 } |
| 65 | 57 |
| 66 SkColor BrowserNonClientFrameView::GetToolbarTopSeparatorColor() const { | 58 SkColor BrowserNonClientFrameView::GetToolbarTopSeparatorColor() const { |
| 67 const auto color_id = | 59 const auto color_id = |
| 68 ShouldPaintAsActive() | 60 ShouldPaintAsActive() |
| 69 ? ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR | 61 ? ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR |
| 70 : ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR_INACTIVE; | 62 : ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR_INACTIVE; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 : ThemeProperties::COLOR_FRAME_INACTIVE; | 96 : ThemeProperties::COLOR_FRAME_INACTIVE; |
| 105 return ShouldPaintAsThemed() | 97 return ShouldPaintAsThemed() |
| 106 ? GetThemeProviderForProfile()->GetColor(color_id) | 98 ? GetThemeProviderForProfile()->GetColor(color_id) |
| 107 : ThemeProperties::GetDefaultColor(color_id, | 99 : ThemeProperties::GetDefaultColor(color_id, |
| 108 browser_view_->IsIncognito()); | 100 browser_view_->IsIncognito()); |
| 109 } | 101 } |
| 110 | 102 |
| 111 gfx::ImageSkia BrowserNonClientFrameView::GetFrameImage(bool active) const { | 103 gfx::ImageSkia BrowserNonClientFrameView::GetFrameImage(bool active) const { |
| 112 const ui::ThemeProvider* tp = frame_->GetThemeProvider(); | 104 const ui::ThemeProvider* tp = frame_->GetThemeProvider(); |
| 113 int frame_image_id = active ? IDR_THEME_FRAME : IDR_THEME_FRAME_INACTIVE; | 105 int frame_image_id = active ? IDR_THEME_FRAME : IDR_THEME_FRAME_INACTIVE; |
| 114 | 106 return ShouldPaintAsThemed() && (tp->HasCustomImage(frame_image_id) || |
| 115 // |default_uses_color| means the default frame is painted with a solid color. | 107 tp->HasCustomImage(IDR_THEME_FRAME)) |
| 116 // When false, the default frame is painted with assets. | |
| 117 #if defined(OS_CHROMEOS) | |
| 118 bool default_uses_color = true; | |
| 119 #else | |
| 120 bool default_uses_color = ui::MaterialDesignController::IsModeMaterial(); | |
| 121 #endif | |
| 122 if (default_uses_color) { | |
| 123 return ShouldPaintAsThemed() && (tp->HasCustomImage(frame_image_id) || | |
| 124 tp->HasCustomImage(IDR_THEME_FRAME)) | |
| 125 ? *tp->GetImageSkiaNamed(frame_image_id) | |
| 126 : gfx::ImageSkia(); | |
| 127 } | |
| 128 | |
| 129 return ShouldPaintAsThemed() | |
| 130 ? *tp->GetImageSkiaNamed(frame_image_id) | 108 ? *tp->GetImageSkiaNamed(frame_image_id) |
| 131 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 109 : gfx::ImageSkia(); |
| 132 frame_image_id); | |
| 133 } | 110 } |
| 134 | 111 |
| 135 gfx::ImageSkia BrowserNonClientFrameView::GetFrameOverlayImage( | 112 gfx::ImageSkia BrowserNonClientFrameView::GetFrameOverlayImage( |
| 136 bool active) const { | 113 bool active) const { |
| 137 if (browser_view_->IsIncognito() || !browser_view_->IsBrowserTypeNormal()) | 114 if (browser_view_->IsIncognito() || !browser_view_->IsBrowserTypeNormal()) |
| 138 return gfx::ImageSkia(); | 115 return gfx::ImageSkia(); |
| 139 | 116 |
| 140 const ui::ThemeProvider* tp = frame_->GetThemeProvider(); | 117 const ui::ThemeProvider* tp = frame_->GetThemeProvider(); |
| 141 int frame_overlay_image_id = | 118 int frame_overlay_image_id = |
| 142 active ? IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE; | 119 active ? IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 164 AddChildView(profile_indicator_icon_); | 141 AddChildView(profile_indicator_icon_); |
| 165 // Invalidate here because adding a child does not invalidate the layout. | 142 // Invalidate here because adding a child does not invalidate the layout. |
| 166 InvalidateLayout(); | 143 InvalidateLayout(); |
| 167 frame_->GetRootView()->Layout(); | 144 frame_->GetRootView()->Layout(); |
| 168 } | 145 } |
| 169 | 146 |
| 170 gfx::Image icon; | 147 gfx::Image icon; |
| 171 const Profile* profile = browser_view()->browser()->profile(); | 148 const Profile* profile = browser_view()->browser()->profile(); |
| 172 if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { | 149 if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { |
| 173 icon = gfx::Image(GetIncognitoAvatarIcon()); | 150 icon = gfx::Image(GetIncognitoAvatarIcon()); |
| 174 if (!ui::MaterialDesignController::IsModeMaterial()) | |
| 175 profile_indicator_icon_->EnableCanvasFlippingForRTLUI(true); | |
| 176 } else { | 151 } else { |
| 177 #if defined(OS_CHROMEOS) | 152 #if defined(OS_CHROMEOS) |
| 178 AvatarMenu::GetImageForMenuButton(profile->GetPath(), &icon); | 153 AvatarMenu::GetImageForMenuButton(profile->GetPath(), &icon); |
| 179 #else | 154 #else |
| 180 NOTREACHED(); | 155 NOTREACHED(); |
| 181 #endif | 156 #endif |
| 182 } | 157 } |
| 183 | 158 |
| 184 profile_indicator_icon_->SetIcon(icon); | 159 profile_indicator_icon_->SetIcon(icon); |
| 185 } | 160 } |
| 186 | 161 |
| 187 void BrowserNonClientFrameView::ViewHierarchyChanged( | 162 void BrowserNonClientFrameView::ViewHierarchyChanged( |
| 188 const ViewHierarchyChangedDetails& details) { | 163 const ViewHierarchyChangedDetails& details) { |
| 189 if (details.is_add && details.child == this) | 164 if (details.is_add && details.child == this) |
| 190 UpdateProfileIcons(); | 165 UpdateProfileIcons(); |
| 191 } | 166 } |
| 192 | 167 |
| 193 void BrowserNonClientFrameView::ActivationChanged(bool active) { | 168 void BrowserNonClientFrameView::ActivationChanged(bool active) { |
| 194 if (ui::MaterialDesignController::IsModeMaterial()) { | 169 // On Windows, while deactivating the widget, this is called before the |
| 195 // On Windows, while deactivating the widget, this is called before the | 170 // active HWND has actually been changed. Since we want the avatar state to |
| 196 // active HWND has actually been changed. Since we want the avatar state to | 171 // reflect that the window is inactive, we force NonClientFrameView to see the |
| 197 // reflect that the window is inactive, we force NonClientFrameView to see | 172 // "correct" state as an override. |
| 198 // the "correct" state as an override. | 173 set_active_state_override(&active); |
| 199 set_active_state_override(&active); | 174 UpdateProfileIcons(); |
| 200 UpdateProfileIcons(); | 175 set_active_state_override(nullptr); |
| 201 set_active_state_override(nullptr); | |
| 202 | 176 |
| 203 // Changing the activation state may change the toolbar top separator color | 177 // Changing the activation state may change the toolbar top separator color |
| 204 // that's used as the stroke around tabs/the new tab button. | 178 // that's used as the stroke around tabs/the new tab button. |
| 205 browser_view_->tabstrip()->SchedulePaint(); | 179 browser_view_->tabstrip()->SchedulePaint(); |
| 206 } | |
| 207 | 180 |
| 208 // Changing the activation state may change the visible frame color. | 181 // Changing the activation state may change the visible frame color. |
| 209 SchedulePaint(); | 182 SchedulePaint(); |
| 210 } | 183 } |
| 211 | 184 |
| 212 bool BrowserNonClientFrameView::DoesIntersectRect(const views::View* target, | 185 bool BrowserNonClientFrameView::DoesIntersectRect(const views::View* target, |
| 213 const gfx::Rect& rect) const { | 186 const gfx::Rect& rect) const { |
| 214 DCHECK_EQ(target, this); | 187 DCHECK_EQ(target, this); |
| 215 if (!views::ViewTargeterDelegate::DoesIntersectRect(this, rect)) { | 188 if (!views::ViewTargeterDelegate::DoesIntersectRect(this, rect)) { |
| 216 // |rect| is outside the frame's bounds. | 189 // |rect| is outside the frame's bounds. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 // safety. See crbug.com/313800. | 276 // safety. See crbug.com/313800. |
| 304 gfx::Image decoration; | 277 gfx::Image decoration; |
| 305 AvatarMenu::GetImageForMenuButton( | 278 AvatarMenu::GetImageForMenuButton( |
| 306 browser_view()->browser()->profile()->GetPath(), &decoration); | 279 browser_view()->browser()->profile()->GetPath(), &decoration); |
| 307 // This can happen if the user deletes the current profile. | 280 // This can happen if the user deletes the current profile. |
| 308 if (decoration.IsEmpty()) | 281 if (decoration.IsEmpty()) |
| 309 return; | 282 return; |
| 310 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), &decoration); | 283 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), &decoration); |
| 311 #endif | 284 #endif |
| 312 } | 285 } |
| OLD | NEW |