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

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 2736613008: Improve appearance of higlighting in profile chooser view. (Closed)
Patch Set: msw review Created 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 (including blurring when the mouse
240 if (title_) 238 // leaves the button). If we don't do this, the focused view and the hovered
241 title_->SetEnabledColor(color); 239 // view might both have the selection highlight.
242 else 240 if (state() == STATE_HOVERED || state() == STATE_PRESSED)
243 SetEnabledTextColors(color); 241 RequestFocus();
244 }; 242 else if (state() == STATE_NORMAL && HasFocus())
243 GetFocusManager()->SetFocusedView(nullptr);
245 244
246 bool was_prelight = 245 UpdateColors();
247 old_state == STATE_HOVERED || old_state == STATE_PRESSED; 246 }
248 bool is_prelight = state() == STATE_HOVERED || state() == STATE_PRESSED; 247
249 if (was_prelight && !is_prelight) { 248 void UpdateColors() {
250 // The pointer is no longer over this button. Set the 249 bool is_selected = HasFocus();
251 // background and text colors back to their normal states. 250
252 set_background(nullptr); 251 set_background(
253 set_title_color(normal_title_color_); 252 is_selected
254 if (subtitle_) 253 ? views::Background::CreateSolidBackground(
255 subtitle_->SetDisabledColor(normal_subtitle_color_); 254 GetNativeTheme()->GetSystemColor(
256 } else if (!was_prelight && is_prelight) { 255 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor))
257 // The pointer moved over this button. Set the background and 256 : nullptr);
258 // text colors back to their hovered states. 257
259 SkColor bg_color = profiles::kHoverColor; 258 SkColor text_color = GetNativeTheme()->GetSystemColor(
260 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 259 is_selected ? ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor
261 if (ThemeServiceFactory::GetForProfile( 260 : ui::NativeTheme::kColorId_LabelEnabledColor);
262 profile_chooser_view_->browser()->profile()) 261 SetEnabledTextColors(text_color);
263 ->UsingSystemTheme()) { 262 if (title_)
264 // When using the system (GTK) theme, use the selected menuitem colors. 263 title_->SetEnabledColor(text_color);
265 bg_color = GetNativeTheme()->GetSystemColor( 264
266 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); 265 if (subtitle_) {
267 SkColor text_color = GetNativeTheme()->GetSystemColor( 266 DCHECK(!subtitle_->enabled());
268 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor); 267 subtitle_->SetDisabledColor(GetNativeTheme()->GetSystemColor(
269 set_title_color(text_color); 268 is_selected
270 if (subtitle_) 269 ? ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor
271 subtitle_->SetDisabledColor(text_color); 270 : ui::NativeTheme::kColorId_LabelDisabledColor));
272 }
273 #endif
274 set_background(views::Background::CreateSolidBackground(bg_color));
275 } 271 }
276 } 272 }
277 273
278 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
279 ProfileChooserView* profile_chooser_view_;
280 #endif
281
282 views::Label* title_; 274 views::Label* title_;
283 SkColor normal_title_color_;
284
285 views::Label* subtitle_; 275 views::Label* subtitle_;
286 SkColor normal_subtitle_color_;
287 276
288 DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton); 277 DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton);
289 }; 278 };
290 279
291 // SizedContainer ------------------------------------------------- 280 // SizedContainer -------------------------------------------------
292 281
293 // A simple container view that takes an explicit preferred size. 282 // A simple container view that takes an explicit preferred size.
294 class SizedContainer : public views::View { 283 class SizedContainer : public views::View {
295 public: 284 public:
296 explicit SizedContainer(const gfx::Size& preferred_size) 285 explicit SizedContainer(const gfx::Size& preferred_size)
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1955 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1967 IncognitoModePrefs::DISABLED; 1956 IncognitoModePrefs::DISABLED;
1968 return incognito_available && !browser_->profile()->IsGuestSession(); 1957 return incognito_available && !browser_->profile()->IsGuestSession();
1969 } 1958 }
1970 1959
1971 void ProfileChooserView::PostActionPerformed( 1960 void ProfileChooserView::PostActionPerformed(
1972 ProfileMetrics::ProfileDesktopMenu action_performed) { 1961 ProfileMetrics::ProfileDesktopMenu action_performed) {
1973 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1962 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1974 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1963 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1975 } 1964 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698