Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/profile_chooser_view.h" | 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/metrics/user_metrics.h" | 8 #include "base/metrics/user_metrics.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/app/vector_icons/vector_icons.h" | 10 #include "chrome/app/vector_icons/vector_icons.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 } | 174 } |
| 175 | 175 |
| 176 // BackgroundColorHoverButton ------------------------------------------------- | 176 // BackgroundColorHoverButton ------------------------------------------------- |
| 177 | 177 |
| 178 // A custom button that allows for setting a background color when hovered over. | 178 // A custom button that allows for setting a background color when hovered over. |
| 179 class BackgroundColorHoverButton : public views::LabelButton { | 179 class BackgroundColorHoverButton : public views::LabelButton { |
| 180 public: | 180 public: |
| 181 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view, | 181 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view, |
| 182 const base::string16& text) | 182 const base::string16& text) |
| 183 : views::LabelButton(profile_chooser_view, text), | 183 : views::LabelButton(profile_chooser_view, text), |
| 184 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 185 profile_chooser_view_(profile_chooser_view), | |
| 186 #endif | |
| 187 title_(nullptr), | 184 title_(nullptr), |
| 188 subtitle_(nullptr) { | 185 subtitle_(nullptr) { |
| 189 DCHECK(profile_chooser_view); | 186 DCHECK(profile_chooser_view); |
| 190 SetImageLabelSpacing(kMenuEdgeMargin - 2); | 187 SetImageLabelSpacing(kMenuEdgeMargin - 2); |
| 191 SetBorder(views::CreateEmptyBorder(0, kMenuEdgeMargin, 0, kMenuEdgeMargin)); | 188 SetBorder(views::CreateEmptyBorder(0, kMenuEdgeMargin, 0, kMenuEdgeMargin)); |
| 192 SetFocusForPlatform(); | 189 SetFocusForPlatform(); |
| 190 SetFocusPainter(nullptr); | |
| 193 | 191 |
| 194 label()->SetHandlesTooltips(false); | 192 label()->SetHandlesTooltips(false); |
| 195 } | 193 } |
| 196 | 194 |
| 197 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view, | 195 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view, |
| 198 const base::string16& text, | 196 const base::string16& text, |
| 199 const gfx::ImageSkia& icon) | 197 const gfx::ImageSkia& icon) |
| 200 : BackgroundColorHoverButton(profile_chooser_view, text) { | 198 : BackgroundColorHoverButton(profile_chooser_view, text) { |
| 201 SetMinSize(gfx::Size( | 199 SetMinSize(gfx::Size( |
| 202 icon.width(), kButtonHeight + views::kRelatedControlVerticalSpacing)); | 200 icon.width(), kButtonHeight + views::kRelatedControlVerticalSpacing)); |
| 203 SetImage(STATE_NORMAL, icon); | 201 SetImage(STATE_NORMAL, icon); |
| 204 } | 202 } |
| 205 | 203 |
| 206 // Overrides the main label associated with this button. If unset, | 204 // Overrides the main label associated with this button. If unset, |
| 207 // label() will be used instead. |label| should be drawn over this | 205 // label() will be used instead. |label| should be drawn over this |
| 208 // button, but it is not necessary that it be a child view. | 206 // button, but it is not necessary that it be a child view. |
| 209 void set_title(views::Label* label) { title_ = label; } | 207 void set_title(views::Label* label) { title_ = label; } |
| 210 | 208 |
| 211 // Sets a secondary label associated with this button. |label| | 209 // Sets a secondary label associated with this button. |label| |
| 212 // should be drawn over this button, but it is not necessary that it | 210 // should be drawn over this button, but it is not necessary that it |
| 213 // be a child view. | 211 // be a child view. |
| 214 void set_subtitle(views::Label* label) { subtitle_ = label; } | 212 void set_subtitle(views::Label* label) { subtitle_ = label; } |
| 215 | 213 |
| 216 ~BackgroundColorHoverButton() override {} | 214 ~BackgroundColorHoverButton() override {} |
| 217 | 215 |
| 218 private: | 216 private: |
| 219 // views::View: | 217 // views::View: |
| 218 void OnFocus() override { | |
| 219 LabelButton::OnFocus(); | |
| 220 UpdateColors(); | |
| 221 } | |
| 222 | |
| 223 void OnBlur() override { | |
| 224 LabelButton::OnBlur(); | |
| 225 UpdateColors(); | |
| 226 } | |
| 227 | |
| 220 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { | 228 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { |
| 221 // The first time the theme changes, the state will not be hovered | |
| 222 // or pressed and the colors will be initialized. It's okay to | |
| 223 // reset the colors when the theme changes and the button is NOT | |
| 224 // hovered or pressed because the labels will be in a normal state. | |
| 225 if (state() == STATE_HOVERED || state() == STATE_PRESSED) | |
| 226 return; | |
| 227 | |
| 228 LabelButton::OnNativeThemeChanged(theme); | 229 LabelButton::OnNativeThemeChanged(theme); |
| 229 views::Label* title = title_ ? title_ : label(); | 230 UpdateColors(); |
| 230 normal_title_color_ = title->enabled_color(); | |
| 231 if (subtitle_) | |
| 232 normal_subtitle_color_ = subtitle_->disabled_color(); | |
| 233 } | 231 } |
| 234 | 232 |
| 235 // views::CustomButton: | 233 // views::CustomButton: |
| 236 void StateChanged(ButtonState old_state) override { | 234 void StateChanged(ButtonState old_state) override { |
| 237 LabelButton::StateChanged(old_state); | 235 LabelButton::StateChanged(old_state); |
| 238 | 236 |
| 239 auto set_title_color = [&](SkColor color) { | 237 // As in a menu, focus follows the mouse. If we don't do this, the focused |
| 240 if (title_) | 238 // view and the hovered view might both have the selection highlight. |
| 241 title_->SetEnabledColor(color); | 239 if ((state() == STATE_HOVERED || state() == STATE_PRESSED)) |
|
msw
2017/03/16 01:41:45
nit: extra parens not needed
Evan Stade
2017/03/16 17:28:14
Done.
| |
| 242 else | 240 RequestFocus(); |
| 243 SetEnabledTextColors(color); | 241 else if (state() == STATE_NORMAL && HasFocus()) |
|
msw
2017/03/16 01:41:45
q: odd, when does this happen? add a comment?
Evan Stade
2017/03/16 17:28:14
this is the blur-on-unhover part of "focus follows
msw
2017/03/16 17:40:17
Acknowledged.
| |
| 244 }; | 242 GetFocusManager()->SetFocusedView(nullptr); |
| 245 | 243 |
| 246 bool was_prelight = | 244 UpdateColors(); |
| 247 old_state == STATE_HOVERED || old_state == STATE_PRESSED; | 245 } |
| 248 bool is_prelight = state() == STATE_HOVERED || state() == STATE_PRESSED; | 246 |
| 249 if (was_prelight && !is_prelight) { | 247 void UpdateColors() { |
|
msw
2017/03/16 01:41:45
nit: should this be called from the constructor? (
Evan Stade
2017/03/16 17:28:14
It relies on the native theme, and the correct nat
msw
2017/03/16 17:40:17
Acknowledged.
| |
| 250 // The pointer is no longer over this button. Set the | 248 bool is_selected = HasFocus(); |
| 251 // background and text colors back to their normal states. | 249 |
| 252 set_background(nullptr); | 250 set_background( |
| 253 set_title_color(normal_title_color_); | 251 is_selected |
| 254 if (subtitle_) | 252 ? views::Background::CreateSolidBackground( |
| 255 subtitle_->SetDisabledColor(normal_subtitle_color_); | 253 GetNativeTheme()->GetSystemColor( |
| 256 } else if (!was_prelight && is_prelight) { | 254 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor)) |
| 257 // The pointer moved over this button. Set the background and | 255 : nullptr); |
| 258 // text colors back to their hovered states. | 256 |
| 259 SkColor bg_color = profiles::kHoverColor; | 257 SkColor text_color = GetNativeTheme()->GetSystemColor( |
| 260 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 258 is_selected ? ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor |
| 261 if (ThemeServiceFactory::GetForProfile( | 259 : ui::NativeTheme::kColorId_LabelEnabledColor); |
|
msw
2017/03/16 01:41:45
nit: kColorId_EnabledMenuItemForegroundColor for c
Evan Stade
2017/03/16 17:28:15
Indeed this is sort of weird, but the background o
msw
2017/03/16 17:40:17
Acknowledged.
| |
| 262 profile_chooser_view_->browser()->profile()) | 260 SetEnabledTextColors(text_color); |
| 263 ->UsingSystemTheme()) { | 261 if (title_) |
| 264 // When using the system (GTK) theme, use the selected menuitem colors. | 262 title_->SetEnabledColor(text_color); |
| 265 bg_color = GetNativeTheme()->GetSystemColor( | 263 |
| 266 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | 264 if (subtitle_) { |
| 267 SkColor text_color = GetNativeTheme()->GetSystemColor( | 265 DCHECK(!subtitle_->enabled()); |
| 268 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor); | 266 subtitle_->SetDisabledColor(GetNativeTheme()->GetSystemColor( |
| 269 set_title_color(text_color); | 267 is_selected |
| 270 if (subtitle_) | 268 ? ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor |
| 271 subtitle_->SetDisabledColor(text_color); | 269 : ui::NativeTheme::kColorId_LabelDisabledColor)); |
|
msw
2017/03/16 01:41:45
nit: kColorId_DisabledMenuItemForegroundColor for
| |
| 272 } | |
| 273 #endif | |
| 274 set_background(views::Background::CreateSolidBackground(bg_color)); | |
| 275 } | 270 } |
| 276 } | 271 } |
| 277 | 272 |
| 278 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 279 ProfileChooserView* profile_chooser_view_; | |
| 280 #endif | |
| 281 | |
| 282 views::Label* title_; | 273 views::Label* title_; |
| 283 SkColor normal_title_color_; | |
| 284 | |
| 285 views::Label* subtitle_; | 274 views::Label* subtitle_; |
| 286 SkColor normal_subtitle_color_; | |
| 287 | 275 |
| 288 DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton); | 276 DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton); |
| 289 }; | 277 }; |
| 290 | 278 |
| 291 // SizedContainer ------------------------------------------------- | 279 // SizedContainer ------------------------------------------------- |
| 292 | 280 |
| 293 // A simple container view that takes an explicit preferred size. | 281 // A simple container view that takes an explicit preferred size. |
| 294 class SizedContainer : public views::View { | 282 class SizedContainer : public views::View { |
| 295 public: | 283 public: |
| 296 explicit SizedContainer(const gfx::Size& preferred_size) | 284 explicit SizedContainer(const gfx::Size& preferred_size) |
| (...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1966 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 1954 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 1967 IncognitoModePrefs::DISABLED; | 1955 IncognitoModePrefs::DISABLED; |
| 1968 return incognito_available && !browser_->profile()->IsGuestSession(); | 1956 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 1969 } | 1957 } |
| 1970 | 1958 |
| 1971 void ProfileChooserView::PostActionPerformed( | 1959 void ProfileChooserView::PostActionPerformed( |
| 1972 ProfileMetrics::ProfileDesktopMenu action_performed) { | 1960 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 1973 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 1961 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 1974 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 1962 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 1975 } | 1963 } |
| OLD | NEW |