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

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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 image_->SetBoundsRect(gfx::Rect(image_origin, image_size)); 270 image_->SetBoundsRect(gfx::Rect(image_origin, image_size));
269 label_->SetBoundsRect(gfx::Rect(label_origin, label_size)); 271 label_->SetBoundsRect(gfx::Rect(label_origin, label_size));
270 } 272 }
271 273
272 const char* LabelButton::GetClassName() const { 274 const char* LabelButton::GetClassName() const {
273 return kViewClassName; 275 return kViewClassName;
274 } 276 }
275 277
276 void LabelButton::OnPaint(gfx::Canvas* canvas) { 278 void LabelButton::OnPaint(gfx::Canvas* canvas) {
277 View::OnPaint(canvas); 279 View::OnPaint(canvas);
280
msw 2014/01/07 00:00:54 nit: remove blank line
Greg Billock 2014/01/07 17:29:58 Done.
278 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); 281 Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
279 } 282 }
280 283
281 void LabelButton::OnFocus() { 284 void LabelButton::OnFocus() {
282 View::OnFocus(); 285 View::OnFocus();
283 // Typically the border renders differently when focused. 286 // Typically the border renders differently when focused.
284 SchedulePaint(); 287 SchedulePaint();
285 } 288 }
286 289
287 void LabelButton::OnBlur() { 290 void LabelButton::OnBlur() {
288 View::OnBlur(); 291 View::OnBlur();
289 // Typically the border renders differently when focused. 292 // Typically the border renders differently when focused.
290 SchedulePaint(); 293 SchedulePaint();
291 } 294 }
292 295
293 void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { 296 void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
294 params->button.checked = false; 297 params->button.checked = false;
295 params->button.indeterminate = false; 298 params->button.indeterminate = false;
296 params->button.is_default = is_default_; 299 params->button.is_default = is_default_;
297 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); 300 params->button.is_focused = HasFocus() && IsAccessibilityFocusable();
298 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON; 301 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON;
299 params->button.classic_state = 0; 302 params->button.classic_state = 0;
300 params->button.background_color = label()->background_color(); 303 params->button.background_color = label_->background_color();
301 } 304 }
302 305
303 void LabelButton::ResetColorsFromNativeTheme() { 306 void LabelButton::ResetColorsFromNativeTheme() {
304 const ui::NativeTheme* theme = GetNativeTheme(); 307 const ui::NativeTheme* theme = GetNativeTheme();
305 SkColor colors[STATE_COUNT] = { 308 SkColor colors[STATE_COUNT] = {
306 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor), 309 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor),
307 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), 310 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor),
308 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), 311 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor),
309 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor), 312 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor),
310 }; 313 };
311 314
312 // Certain styles do not change text color when hovered or pressed. 315 // Certain styles do not change text color when hovered or pressed.
313 bool constant_text_color = false; 316 bool constant_text_color = false;
314 #if defined(OS_WIN) 317 #if defined(OS_WIN)
315 constant_text_color |= (style() == STYLE_NATIVE_TEXTBUTTON && 318 constant_text_color |= (style() == STYLE_NATIVE_TEXTBUTTON &&
316 theme == ui::NativeThemeWin::instance()); 319 theme == ui::NativeThemeWin::instance());
317 #endif 320 #endif
318 321
319 // Use hardcoded colors for inverted color scheme support and STYLE_BUTTON. 322 // Use hardcoded colors for inverted color scheme support and STYLE_BUTTON.
320 if (gfx::IsInvertedColorScheme()) { 323 if (gfx::IsInvertedColorScheme()) {
321 constant_text_color = true; 324 constant_text_color = true;
322 colors[STATE_NORMAL] = SK_ColorWHITE; 325 colors[STATE_NORMAL] = SK_ColorWHITE;
323 label_->SetBackgroundColor(SK_ColorBLACK); 326 label_->SetBackgroundColor(SK_ColorBLACK);
327 label_->set_background(Background::CreateSolidBackground(SK_ColorBLACK));
324 label_->SetAutoColorReadabilityEnabled(true); 328 label_->SetAutoColorReadabilityEnabled(true);
325 label_->ClearEmbellishing(); 329 label_->ClearEmbellishing();
326 } else if (style() == STYLE_BUTTON) { 330 } else if (style() == STYLE_BUTTON) {
327 constant_text_color = true; 331 constant_text_color = true;
328 colors[STATE_NORMAL] = kStyleButtonTextColor; 332 colors[STATE_NORMAL] = kStyleButtonTextColor;
329 label_->SetBackgroundColor(theme->GetSystemColor( 333 label_->SetBackgroundColor(theme->GetSystemColor(
330 ui::NativeTheme::kColorId_ButtonBackgroundColor)); 334 ui::NativeTheme::kColorId_ButtonBackgroundColor));
335 label_->set_background(NULL);
331 label_->SetAutoColorReadabilityEnabled(false); 336 label_->SetAutoColorReadabilityEnabled(false);
332 label_->SetShadowColors(kStyleButtonShadowColor, kStyleButtonShadowColor); 337 label_->SetShadowColors(kStyleButtonShadowColor, kStyleButtonShadowColor);
333 label_->SetShadowOffset(0, 1); 338 label_->SetShadowOffset(0, 1);
339 } else {
340 label_->set_background(NULL);
334 } 341 }
335 342
336 if (constant_text_color) 343 if (constant_text_color)
337 colors[STATE_HOVERED] = colors[STATE_PRESSED] = colors[STATE_NORMAL]; 344 colors[STATE_HOVERED] = colors[STATE_PRESSED] = colors[STATE_NORMAL];
338 345
339 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) { 346 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) {
340 if (!explicitly_set_colors_[state]) { 347 if (!explicitly_set_colors_[state]) {
341 SetTextColor(static_cast<ButtonState>(state), colors[state]); 348 SetTextColor(static_cast<ButtonState>(state), colors[state]);
342 explicitly_set_colors_[state] = false; 349 explicitly_set_colors_[state] = false;
343 } 350 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 return ui::NativeTheme::kNormal; 412 return ui::NativeTheme::kNormal;
406 } 413 }
407 414
408 ui::NativeTheme::State LabelButton::GetForegroundThemeState( 415 ui::NativeTheme::State LabelButton::GetForegroundThemeState(
409 ui::NativeTheme::ExtraParams* params) const { 416 ui::NativeTheme::ExtraParams* params) const {
410 GetExtraParams(params); 417 GetExtraParams(params);
411 return ui::NativeTheme::kHovered; 418 return ui::NativeTheme::kHovered;
412 } 419 }
413 420
414 } // namespace views 421 } // 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