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

Side by Side Diff: ui/views/controls/button/label_button.cc

Issue 23534062: Fix Views blue button's blurry text on Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make LabelButton::ResetColorsFromNativeTheme virtual; override for BlueButton. Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/controls/button/label_button.h ('k') | 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 (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 "ui/views/controls/button/label_button.h" 5 #include "ui/views/controls/button/label_button.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "grit/ui_resources.h" 8 #include "grit/ui_resources.h"
9 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/animation/throb_animation.h" 10 #include "ui/gfx/animation/throb_animation.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { 250 void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
251 params->button.checked = false; 251 params->button.checked = false;
252 params->button.indeterminate = false; 252 params->button.indeterminate = false;
253 params->button.is_default = is_default_; 253 params->button.is_default = is_default_;
254 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); 254 params->button.is_focused = HasFocus() && IsAccessibilityFocusable();
255 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON; 255 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON;
256 params->button.classic_state = 0; 256 params->button.classic_state = 0;
257 params->button.background_color = label()->background_color(); 257 params->button.background_color = label()->background_color();
258 } 258 }
259 259
260 void LabelButton::UpdateImage() {
261 image_->SetImage(GetImage(state()));
262 }
263
264 void LabelButton::ResetColorsFromNativeTheme() { 260 void LabelButton::ResetColorsFromNativeTheme() {
265 const ui::NativeTheme* theme = GetNativeTheme(); 261 const ui::NativeTheme* theme = GetNativeTheme();
266 SkColor colors[STATE_COUNT] = { 262 SkColor colors[STATE_COUNT] = {
267 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor), 263 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor),
268 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), 264 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor),
269 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), 265 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor),
270 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor), 266 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor),
271 }; 267 };
272 268
273 // Certain styles do not change text color when hovered or pressed. 269 // Certain styles do not change text color when hovered or pressed.
274 bool constant_text_color = false; 270 bool constant_text_color = false;
275 #if defined(OS_WIN) 271 #if defined(OS_WIN)
276 constant_text_color |= (style() == STYLE_NATIVE_TEXTBUTTON && 272 constant_text_color |= (style() == STYLE_NATIVE_TEXTBUTTON &&
277 theme == ui::NativeThemeWin::instance()); 273 theme == ui::NativeThemeWin::instance());
278 #endif 274 #endif
279 275
280 label_->SetBackgroundColor(theme->GetSystemColor(
281 ui::NativeTheme::kColorId_ButtonBackgroundColor));
282
283 // Use hardcoded colors for inverted color scheme support and STYLE_BUTTON. 276 // Use hardcoded colors for inverted color scheme support and STYLE_BUTTON.
284 if (gfx::IsInvertedColorScheme()) { 277 if (gfx::IsInvertedColorScheme()) {
285 constant_text_color = true; 278 constant_text_color = true;
286 colors[STATE_NORMAL] = SK_ColorWHITE; 279 colors[STATE_NORMAL] = SK_ColorWHITE;
287 label_->SetBackgroundColor(SK_ColorBLACK); 280 label_->SetBackgroundColor(SK_ColorBLACK);
288 label_->SetAutoColorReadabilityEnabled(true); 281 label_->SetAutoColorReadabilityEnabled(true);
289 label_->ClearEmbellishing(); 282 label_->ClearEmbellishing();
290 } else if (style() == STYLE_BUTTON) { 283 } else if (style() == STYLE_BUTTON) {
291 constant_text_color = true; 284 constant_text_color = true;
292 colors[STATE_NORMAL] = kStyleButtonTextColor; 285 colors[STATE_NORMAL] = kStyleButtonTextColor;
286 label_->SetBackgroundColor(theme->GetSystemColor(
287 ui::NativeTheme::kColorId_ButtonBackgroundColor));
293 label_->SetAutoColorReadabilityEnabled(false); 288 label_->SetAutoColorReadabilityEnabled(false);
294 label_->SetShadowColors(kStyleButtonShadowColor, kStyleButtonShadowColor); 289 label_->SetShadowColors(kStyleButtonShadowColor, kStyleButtonShadowColor);
295 label_->SetShadowOffset(0, 1); 290 label_->SetShadowOffset(0, 1);
296 } 291 }
297 292
298 if (constant_text_color) 293 if (constant_text_color)
299 colors[STATE_HOVERED] = colors[STATE_PRESSED] = colors[STATE_NORMAL]; 294 colors[STATE_HOVERED] = colors[STATE_PRESSED] = colors[STATE_NORMAL];
300 295
301 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) { 296 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) {
302 if (!explicitly_set_colors_[state]) { 297 if (!explicitly_set_colors_[state]) {
303 SetTextColor(static_cast<ButtonState>(state), colors[state]); 298 SetTextColor(static_cast<ButtonState>(state), colors[state]);
304 explicitly_set_colors_[state] = false; 299 explicitly_set_colors_[state] = false;
305 } 300 }
306 } 301 }
307 } 302 }
308 303
304 void LabelButton::UpdateImage() {
305 image_->SetImage(GetImage(state()));
306 }
307
309 void LabelButton::StateChanged() { 308 void LabelButton::StateChanged() {
310 const gfx::Size previous_image_size(image_->GetPreferredSize()); 309 const gfx::Size previous_image_size(image_->GetPreferredSize());
311 UpdateImage(); 310 UpdateImage();
312 const SkColor color = button_state_colors_[state()]; 311 const SkColor color = button_state_colors_[state()];
313 if (state() != STATE_DISABLED && label_->enabled_color() != color) 312 if (state() != STATE_DISABLED && label_->enabled_color() != color)
314 label_->SetEnabledColor(color); 313 label_->SetEnabledColor(color);
315 label_->SetEnabled(state() != STATE_DISABLED); 314 label_->SetEnabled(state() != STATE_DISABLED);
316 if (image_->GetPreferredSize() != previous_image_size) 315 if (image_->GetPreferredSize() != previous_image_size)
317 Layout(); 316 Layout();
318 } 317 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return ui::NativeTheme::kNormal; 362 return ui::NativeTheme::kNormal;
364 } 363 }
365 364
366 ui::NativeTheme::State LabelButton::GetForegroundThemeState( 365 ui::NativeTheme::State LabelButton::GetForegroundThemeState(
367 ui::NativeTheme::ExtraParams* params) const { 366 ui::NativeTheme::ExtraParams* params) const {
368 GetExtraParams(params); 367 GetExtraParams(params);
369 return ui::NativeTheme::kHovered; 368 return ui::NativeTheme::kHovered;
370 } 369 }
371 370
372 } // namespace views 371 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/label_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698