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

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

Issue 120823003: [Views] Only paint background of text portion of LabelButton in inverted color theme. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 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 | « no previous file | ui/views/controls/button/label_button_border.cc » ('j') | 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"
11 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/font_list.h" 12 #include "ui/gfx/font_list.h"
12 #include "ui/gfx/sys_color_change_listener.h" 13 #include "ui/gfx/sys_color_change_listener.h"
13 #include "ui/native_theme/native_theme.h" 14 #include "ui/native_theme/native_theme.h"
15 #include "ui/views/background.h"
14 #include "ui/views/controls/button/label_button_border.h" 16 #include "ui/views/controls/button/label_button_border.h"
15 #include "ui/views/painter.h" 17 #include "ui/views/painter.h"
16 #include "ui/views/window/dialog_delegate.h" 18 #include "ui/views/window/dialog_delegate.h"
17 19
18 #if defined(OS_WIN) 20 #if defined(OS_WIN)
19 #include "ui/native_theme/native_theme_win.h" 21 #include "ui/native_theme/native_theme_win.h"
20 #endif 22 #endif
21 23
22 namespace { 24 namespace {
23 25
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 SchedulePaint(); 292 SchedulePaint();
291 } 293 }
292 294
293 void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { 295 void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
294 params->button.checked = false; 296 params->button.checked = false;
295 params->button.indeterminate = false; 297 params->button.indeterminate = false;
296 params->button.is_default = is_default_; 298 params->button.is_default = is_default_;
297 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); 299 params->button.is_focused = HasFocus() && IsAccessibilityFocusable();
298 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON; 300 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON;
299 params->button.classic_state = 0; 301 params->button.classic_state = 0;
300 params->button.background_color = label()->background_color(); 302 params->button.background_color = label_->background_color();
301 } 303 }
302 304
303 void LabelButton::ResetColorsFromNativeTheme() { 305 void LabelButton::ResetColorsFromNativeTheme() {
304 const ui::NativeTheme* theme = GetNativeTheme(); 306 const ui::NativeTheme* theme = GetNativeTheme();
305 SkColor colors[STATE_COUNT] = { 307 SkColor colors[STATE_COUNT] = {
306 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor), 308 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor),
307 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), 309 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor),
308 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), 310 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor),
309 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor), 311 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor),
310 }; 312 };
311 313
312 // Certain styles do not change text color when hovered or pressed. 314 // Certain styles do not change text color when hovered or pressed.
313 bool constant_text_color = false; 315 bool constant_text_color = false;
314 #if defined(OS_WIN) 316 #if defined(OS_WIN)
315 constant_text_color |= (style() == STYLE_NATIVE_TEXTBUTTON && 317 constant_text_color |= (style() == STYLE_NATIVE_TEXTBUTTON &&
316 theme == ui::NativeThemeWin::instance()); 318 theme == ui::NativeThemeWin::instance());
317 #endif 319 #endif
318 320
319 // Use hardcoded colors for inverted color scheme support and STYLE_BUTTON. 321 // Use hardcoded colors for inverted color scheme support and STYLE_BUTTON.
320 if (gfx::IsInvertedColorScheme()) { 322 if (gfx::IsInvertedColorScheme()) {
321 constant_text_color = true; 323 constant_text_color = true;
322 colors[STATE_NORMAL] = SK_ColorWHITE; 324 colors[STATE_NORMAL] = SK_ColorWHITE;
323 label_->SetBackgroundColor(SK_ColorBLACK); 325 label_->SetBackgroundColor(SK_ColorBLACK);
326 label_->set_background(Background::CreateSolidBackground(SK_ColorBLACK));
324 label_->SetAutoColorReadabilityEnabled(true); 327 label_->SetAutoColorReadabilityEnabled(true);
325 label_->ClearEmbellishing(); 328 label_->ClearEmbellishing();
326 } else if (style() == STYLE_BUTTON) { 329 } else if (style() == STYLE_BUTTON) {
327 constant_text_color = true; 330 constant_text_color = true;
328 colors[STATE_NORMAL] = kStyleButtonTextColor; 331 colors[STATE_NORMAL] = kStyleButtonTextColor;
329 label_->SetBackgroundColor(theme->GetSystemColor( 332 label_->SetBackgroundColor(theme->GetSystemColor(
330 ui::NativeTheme::kColorId_ButtonBackgroundColor)); 333 ui::NativeTheme::kColorId_ButtonBackgroundColor));
334 label_->set_background(NULL);
331 label_->SetAutoColorReadabilityEnabled(false); 335 label_->SetAutoColorReadabilityEnabled(false);
332 label_->SetShadowColors(kStyleButtonShadowColor, kStyleButtonShadowColor); 336 label_->SetShadowColors(kStyleButtonShadowColor, kStyleButtonShadowColor);
333 label_->SetShadowOffset(0, 1); 337 label_->SetShadowOffset(0, 1);
338 } else {
339 label_->set_background(NULL);
334 } 340 }
335 341
336 if (constant_text_color) 342 if (constant_text_color)
337 colors[STATE_HOVERED] = colors[STATE_PRESSED] = colors[STATE_NORMAL]; 343 colors[STATE_HOVERED] = colors[STATE_PRESSED] = colors[STATE_NORMAL];
338 344
339 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) { 345 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) {
340 if (!explicitly_set_colors_[state]) { 346 if (!explicitly_set_colors_[state]) {
341 SetTextColor(static_cast<ButtonState>(state), colors[state]); 347 SetTextColor(static_cast<ButtonState>(state), colors[state]);
342 explicitly_set_colors_[state] = false; 348 explicitly_set_colors_[state] = false;
343 } 349 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 return ui::NativeTheme::kNormal; 411 return ui::NativeTheme::kNormal;
406 } 412 }
407 413
408 ui::NativeTheme::State LabelButton::GetForegroundThemeState( 414 ui::NativeTheme::State LabelButton::GetForegroundThemeState(
409 ui::NativeTheme::ExtraParams* params) const { 415 ui::NativeTheme::ExtraParams* params) const {
410 GetExtraParams(params); 416 GetExtraParams(params);
411 return ui::NativeTheme::kHovered; 417 return ui::NativeTheme::kHovered;
412 } 418 }
413 419
414 } // namespace views 420 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/button/label_button_border.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698