Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/text_button.h" | 5 #include "ui/views/controls/button/text_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 has_text_shadow_(false), | 200 has_text_shadow_(false), |
| 201 active_text_shadow_color_(0), | 201 active_text_shadow_color_(0), |
| 202 inactive_text_shadow_color_(0), | 202 inactive_text_shadow_color_(0), |
| 203 text_shadow_offset_(gfx::Point(1, 1)), | 203 text_shadow_offset_(gfx::Point(1, 1)), |
| 204 min_width_(0), | 204 min_width_(0), |
| 205 min_height_(0), | 205 min_height_(0), |
| 206 max_width_(0), | 206 max_width_(0), |
| 207 show_multiple_icon_states_(true), | 207 show_multiple_icon_states_(true), |
| 208 is_default_(false), | 208 is_default_(false), |
| 209 multi_line_(false), | 209 multi_line_(false), |
| 210 color_(ui::NativeTheme::instance()->GetSystemColor( | 210 color_(0), |
|
msw
2012/12/12 19:38:16
nit: Skip initializing these values to 0.
cpu_(ooo_6.6-7.5)
2012/12/12 22:53:25
Done.
| |
| 211 ui::NativeTheme::kColorId_TextButtonEnabledColor)), | 211 color_enabled_(0), |
| 212 color_enabled_(ui::NativeTheme::instance()->GetSystemColor( | 212 color_disabled_(0), |
| 213 ui::NativeTheme::kColorId_TextButtonEnabledColor)), | 213 color_highlight_(0), |
| 214 color_disabled_(ui::NativeTheme::instance()->GetSystemColor( | 214 color_hover_(0), |
| 215 ui::NativeTheme::kColorId_TextButtonDisabledColor)), | |
| 216 color_highlight_(ui::NativeTheme::instance()->GetSystemColor( | |
| 217 ui::NativeTheme::kColorId_TextButtonHighlightColor)), | |
| 218 color_hover_(ui::NativeTheme::instance()->GetSystemColor( | |
| 219 ui::NativeTheme::kColorId_TextButtonHoverColor)), | |
| 220 use_enabled_color_from_theme_(true), | 215 use_enabled_color_from_theme_(true), |
| 221 use_disabled_color_from_theme_(true), | 216 use_disabled_color_from_theme_(true), |
| 222 use_highlight_color_from_theme_(true), | 217 use_highlight_color_from_theme_(true), |
| 223 use_hover_color_from_theme_(true) { | 218 use_hover_color_from_theme_(true) { |
| 224 SetText(text); | 219 SetText(text); |
| 220 OnNativeThemeChanged(ui::NativeTheme::instance()); | |
| 225 SetAnimationDuration(kHoverAnimationDurationMs); | 221 SetAnimationDuration(kHoverAnimationDurationMs); |
| 226 } | 222 } |
| 227 | 223 |
| 228 TextButtonBase::~TextButtonBase() { | 224 TextButtonBase::~TextButtonBase() { |
| 229 } | 225 } |
| 230 | 226 |
| 231 void TextButtonBase::SetIsDefault(bool is_default) { | 227 void TextButtonBase::SetIsDefault(bool is_default) { |
| 232 if (is_default == is_default_) | 228 if (is_default == is_default_) |
| 233 return; | 229 return; |
| 234 is_default_ = is_default; | 230 is_default_ = is_default; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 CustomButton::OnEnabledChanged(); | 523 CustomButton::OnEnabledChanged(); |
| 528 } | 524 } |
| 529 | 525 |
| 530 std::string TextButtonBase::GetClassName() const { | 526 std::string TextButtonBase::GetClassName() const { |
| 531 return kViewClassName; | 527 return kViewClassName; |
| 532 } | 528 } |
| 533 | 529 |
| 534 void TextButtonBase::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 530 void TextButtonBase::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 535 if (use_enabled_color_from_theme_) { | 531 if (use_enabled_color_from_theme_) { |
| 536 color_enabled_ = theme->GetSystemColor( | 532 color_enabled_ = theme->GetSystemColor( |
| 537 ui::NativeTheme::kColorId_TextButtonEnabledColor); | 533 ui::NativeTheme::kColorId_LabelEnabledColor); |
|
msw
2012/12/12 19:38:16
Repurpose kColorId_TextButtonEnabledColor to get C
cpu_(ooo_6.6-7.5)
2012/12/12 22:53:25
Done.
| |
| 538 } | 534 } |
| 539 if (use_disabled_color_from_theme_) { | 535 if (use_disabled_color_from_theme_) { |
| 540 color_disabled_ = theme->GetSystemColor( | 536 color_disabled_ = theme->GetSystemColor( |
| 541 ui::NativeTheme::kColorId_TextButtonDisabledColor); | 537 ui::NativeTheme::kColorId_LabelDisabledColor); |
|
msw
2012/12/12 19:38:16
Using kColorId_LabelDisabledColor (COLOR_GRAYTEXT)
cpu_(ooo_6.6-7.5)
2012/12/12 22:53:25
Done.
| |
| 542 } | 538 } |
| 543 if (use_highlight_color_from_theme_) { | 539 if (use_highlight_color_from_theme_) { |
| 544 color_highlight_ = theme->GetSystemColor( | 540 color_highlight_ = theme->GetSystemColor( |
|
cpu_(ooo_6.6-7.5)
2012/12/12 03:42:12
highlight_ is only used on windows and only in PB_
| |
| 545 ui::NativeTheme::kColorId_TextButtonHighlightColor); | 541 ui::NativeTheme::kColorId_TextButtonHighlightColor); |
| 546 } | 542 } |
| 547 if (use_hover_color_from_theme_) { | 543 if (use_hover_color_from_theme_) { |
| 548 color_hover_ = theme->GetSystemColor( | 544 color_hover_ = theme->GetSystemColor( |
| 549 ui::NativeTheme::kColorId_TextButtonHoverColor); | 545 ui::NativeTheme::kColorId_TextButtonHoverColor); |
|
cpu_(ooo_6.6-7.5)
2012/12/12 03:42:12
this seems correct, on hover the text becomes blue
| |
| 550 } | 546 } |
| 551 UpdateColor(); | 547 UpdateColor(); |
| 552 } | 548 } |
| 553 | 549 |
| 554 //////////////////////////////////////////////////////////////////////////////// | 550 //////////////////////////////////////////////////////////////////////////////// |
| 555 // TextButtonBase, NativeThemeDelegate overrides: | 551 // TextButtonBase, NativeThemeDelegate overrides: |
| 556 | 552 |
| 557 gfx::Rect TextButtonBase::GetThemePaintRect() const { | 553 gfx::Rect TextButtonBase::GetThemePaintRect() const { |
| 558 return GetLocalBounds(); | 554 return GetLocalBounds(); |
| 559 } | 555 } |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 786 } | 782 } |
| 787 | 783 |
| 788 void NativeTextButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 784 void NativeTextButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 789 SetThemeSpecificState(theme); | 785 SetThemeSpecificState(theme); |
| 790 } | 786 } |
| 791 | 787 |
| 792 void NativeTextButton::SetThemeSpecificState(const ui::NativeTheme* theme) { | 788 void NativeTextButton::SetThemeSpecificState(const ui::NativeTheme* theme) { |
| 793 #if defined(OS_WIN) | 789 #if defined(OS_WIN) |
| 794 if (theme == ui::NativeThemeWin::instance()) { | 790 if (theme == ui::NativeThemeWin::instance()) { |
| 795 if (use_enabled_color_from_theme()) | 791 if (use_enabled_color_from_theme()) |
| 796 set_color_enabled(skia::COLORREFToSkColor(GetSysColor(COLOR_BTNTEXT))); | 792 set_color_enabled(skia::COLORREFToSkColor(GetSysColor(COLOR_BTNTEXT))); |
|
msw
2012/12/12 19:38:16
Use the theme here to get COLOR_BTNTEXT and COLOR_
| |
| 797 if (use_disabled_color_from_theme()) | 793 if (use_disabled_color_from_theme()) |
| 798 set_color_disabled(skia::COLORREFToSkColor(GetSysColor(COLOR_GRAYTEXT))); | 794 set_color_disabled(skia::COLORREFToSkColor(GetSysColor(COLOR_GRAYTEXT))); |
| 799 if (use_hover_color_from_theme()) | 795 if (use_hover_color_from_theme()) |
| 800 set_color_hover(skia::COLORREFToSkColor(GetSysColor(COLOR_BTNTEXT))); | 796 set_color_hover(skia::COLORREFToSkColor(GetSysColor(COLOR_BTNTEXT))); |
| 801 UpdateColor(); | 797 UpdateColor(); |
| 802 set_focus_border(FocusBorder::CreateDashedFocusBorder(kFocusRectInset, | 798 set_focus_border(FocusBorder::CreateDashedFocusBorder(kFocusRectInset, |
| 803 kFocusRectInset, | 799 kFocusRectInset, |
| 804 kFocusRectInset, | 800 kFocusRectInset, |
| 805 kFocusRectInset)); | 801 kFocusRectInset)); |
| 806 } else { | 802 } else { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 821 // when not using NativeThemeWin. | 817 // when not using NativeThemeWin. |
| 822 #if defined(OS_WIN) | 818 #if defined(OS_WIN) |
| 823 if (GetNativeTheme() == ui::NativeThemeWin::instance()) | 819 if (GetNativeTheme() == ui::NativeThemeWin::instance()) |
| 824 return; | 820 return; |
| 825 #endif | 821 #endif |
| 826 params->button.is_focused = HasFocus() && | 822 params->button.is_focused = HasFocus() && |
| 827 (focusable() || IsAccessibilityFocusable()); | 823 (focusable() || IsAccessibilityFocusable()); |
| 828 } | 824 } |
| 829 | 825 |
| 830 } // namespace views | 826 } // namespace views |
| OLD | NEW |