Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/button/text_button.h" | 5 #include "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 24 matching lines...) Expand all Loading... | |
| 35 static const int kDefaultIconTextSpacing = 5; | 35 static const int kDefaultIconTextSpacing = 5; |
| 36 | 36 |
| 37 // Preferred padding between text and edge | 37 // Preferred padding between text and edge |
| 38 static const int kPreferredPaddingHorizontal = 6; | 38 static const int kPreferredPaddingHorizontal = 6; |
| 39 static const int kPreferredPaddingVertical = 5; | 39 static const int kPreferredPaddingVertical = 5; |
| 40 | 40 |
| 41 // Preferred padding between text and edge for NativeTheme border | 41 // Preferred padding between text and edge for NativeTheme border |
| 42 static const int kPreferredNativeThemePaddingHorizontal = 12; | 42 static const int kPreferredNativeThemePaddingHorizontal = 12; |
| 43 static const int kPreferredNativeThemePaddingVertical = 5; | 43 static const int kPreferredNativeThemePaddingVertical = 5; |
| 44 | 44 |
| 45 // Number of pixels from the edge of the view to inset the focus rect | |
|
Peter Kasting
2011/11/01 21:51:28
Needs to be a complete sentence (I see some existi
| |
| 46 static const int kFocusRectInset = 3; | |
| 47 | |
| 45 // Default background color for buttons. | 48 // Default background color for buttons. |
| 46 const SkColor kBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde); | 49 const SkColor kBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde); |
| 47 | 50 |
| 48 #if defined(USE_AURA) | 51 #if defined(USE_AURA) |
| 49 // static | 52 // static |
| 50 const SkColor TextButtonBase::kEnabledColor = SkColorSetRGB(0x44, 0x44, 0x44); | 53 const SkColor TextButtonBase::kEnabledColor = SkColorSetRGB(0x44, 0x44, 0x44); |
| 51 // static | 54 // static |
| 52 const SkColor TextButtonBase::kHighlightColor = SkColorSetRGB(0, 0, 0); | 55 const SkColor TextButtonBase::kHighlightColor = SkColorSetRGB(0, 0, 0); |
| 53 // static | 56 // static |
| 54 const SkColor TextButtonBase::kDisabledColor = SkColorSetRGB(0x99, 0x99, 0x99); | 57 const SkColor TextButtonBase::kDisabledColor = SkColorSetRGB(0x99, 0x99, 0x99); |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 } | 740 } |
| 738 | 741 |
| 739 void TextButton::set_ignore_minimum_size(bool ignore_minimum_size) { | 742 void TextButton::set_ignore_minimum_size(bool ignore_minimum_size) { |
| 740 ignore_minimum_size_ = ignore_minimum_size; | 743 ignore_minimum_size_ = ignore_minimum_size; |
| 741 } | 744 } |
| 742 | 745 |
| 743 std::string TextButton::GetClassName() const { | 746 std::string TextButton::GetClassName() const { |
| 744 return kViewClassName; | 747 return kViewClassName; |
| 745 } | 748 } |
| 746 | 749 |
| 750 void TextButton::OnPaintFocusBorder(gfx::Canvas* canvas) { | |
| 751 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) { | |
| 752 gfx::Rect rect(GetLocalBounds()); | |
| 753 rect.Inset(kFocusRectInset, kFocusRectInset); | |
| 754 canvas->DrawFocusRect(rect); | |
| 755 } | |
| 756 } | |
| 757 | |
| 747 gfx::NativeTheme::Part TextButton::GetThemePart() const { | 758 gfx::NativeTheme::Part TextButton::GetThemePart() const { |
| 748 return gfx::NativeTheme::kPushButton; | 759 return gfx::NativeTheme::kPushButton; |
| 749 } | 760 } |
| 750 | 761 |
| 751 void TextButton::GetExtraParams(gfx::NativeTheme::ExtraParams* params) const { | 762 void TextButton::GetExtraParams(gfx::NativeTheme::ExtraParams* params) const { |
| 752 TextButtonBase::GetExtraParams(params); | 763 TextButtonBase::GetExtraParams(params); |
| 753 params->button.is_default = is_default_; | 764 params->button.is_default = is_default_; |
| 754 } | 765 } |
| 755 | 766 |
| 756 gfx::Rect TextButton::GetTextBounds() const { | 767 gfx::Rect TextButton::GetTextBounds() const { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 std::string NativeTextButton::GetClassName() const { | 833 std::string NativeTextButton::GetClassName() const { |
| 823 return kViewClassName; | 834 return kViewClassName; |
| 824 } | 835 } |
| 825 | 836 |
| 826 void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) { | 837 void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| 827 #if defined(OS_WIN) | 838 #if defined(OS_WIN) |
| 828 // On windows, make sure the focus border is inset wrt the entire button so | 839 // On windows, make sure the focus border is inset wrt the entire button so |
| 829 // that the native text button appears more like a windows button. | 840 // that the native text button appears more like a windows button. |
| 830 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) { | 841 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) { |
| 831 gfx::Rect rect(GetLocalBounds()); | 842 gfx::Rect rect(GetLocalBounds()); |
| 832 rect.Inset(3, 3); | 843 rect.Inset(kFocusRectInset, kFocusRectInset); |
| 833 canvas->DrawFocusRect(rect); | 844 canvas->DrawFocusRect(rect); |
| 834 } | 845 } |
| 835 #else | 846 #else |
| 836 TextButton::OnPaintFocusBorder(canvas); | 847 TextButton::OnPaintFocusBorder(canvas); |
| 837 #endif | 848 #endif |
| 838 } | 849 } |
| 839 | 850 |
| 840 void NativeTextButton::GetExtraParams( | 851 void NativeTextButton::GetExtraParams( |
| 841 gfx::NativeTheme::ExtraParams* params) const { | 852 gfx::NativeTheme::ExtraParams* params) const { |
| 842 TextButton::GetExtraParams(params); | 853 TextButton::GetExtraParams(params); |
| 843 params->button.has_border = true; | 854 params->button.has_border = true; |
| 844 } | 855 } |
| 845 | 856 |
| 846 } // namespace views | 857 } // namespace views |
| OLD | NEW |