| 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 16 matching lines...) Expand all Loading... |
| 27 // The min size in DLUs comes from | 27 // The min size in DLUs comes from |
| 28 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwue/html/c
h14e.asp | 28 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwue/html/c
h14e.asp |
| 29 static const int kMinWidthDLUs = 50; | 29 static const int kMinWidthDLUs = 50; |
| 30 static const int kMinHeightDLUs = 14; | 30 static const int kMinHeightDLUs = 14; |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 | 33 |
| 34 // Default space between the icon and text. | 34 // Default space between the icon and text. |
| 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 // By default the focus rect is drawn at the border of the view. |
| 46 // For a button, we inset the focus rect by 3 pixels so that it |
| 47 // doesn't draw on top of the button's border. This roughly matches |
| 48 // how the Windows native focus rect for buttons looks. A subclass |
| 49 // that draws a button with different padding may need to |
| 50 // override OnPaintFocusBorder and do something different. |
| 51 static const int kFocusRectInset = 3; |
| 52 |
| 45 // Default background color for buttons. | 53 // Default background color for buttons. |
| 46 const SkColor kBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde); | 54 const SkColor kBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde); |
| 47 | 55 |
| 48 #if defined(USE_AURA) | 56 #if defined(USE_AURA) |
| 49 // static | 57 // static |
| 50 const SkColor TextButtonBase::kEnabledColor = SkColorSetRGB(0x44, 0x44, 0x44); | 58 const SkColor TextButtonBase::kEnabledColor = SkColorSetRGB(0x44, 0x44, 0x44); |
| 51 // static | 59 // static |
| 52 const SkColor TextButtonBase::kHighlightColor = SkColorSetRGB(0, 0, 0); | 60 const SkColor TextButtonBase::kHighlightColor = SkColorSetRGB(0, 0, 0); |
| 53 // static | 61 // static |
| 54 const SkColor TextButtonBase::kDisabledColor = SkColorSetRGB(0x99, 0x99, 0x99); | 62 const SkColor TextButtonBase::kDisabledColor = SkColorSetRGB(0x99, 0x99, 0x99); |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 } | 745 } |
| 738 | 746 |
| 739 void TextButton::set_ignore_minimum_size(bool ignore_minimum_size) { | 747 void TextButton::set_ignore_minimum_size(bool ignore_minimum_size) { |
| 740 ignore_minimum_size_ = ignore_minimum_size; | 748 ignore_minimum_size_ = ignore_minimum_size; |
| 741 } | 749 } |
| 742 | 750 |
| 743 std::string TextButton::GetClassName() const { | 751 std::string TextButton::GetClassName() const { |
| 744 return kViewClassName; | 752 return kViewClassName; |
| 745 } | 753 } |
| 746 | 754 |
| 755 void TextButton::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| 756 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) { |
| 757 gfx::Rect rect(GetLocalBounds()); |
| 758 rect.Inset(kFocusRectInset, kFocusRectInset); |
| 759 canvas->DrawFocusRect(rect); |
| 760 } |
| 761 } |
| 762 |
| 747 gfx::NativeTheme::Part TextButton::GetThemePart() const { | 763 gfx::NativeTheme::Part TextButton::GetThemePart() const { |
| 748 return gfx::NativeTheme::kPushButton; | 764 return gfx::NativeTheme::kPushButton; |
| 749 } | 765 } |
| 750 | 766 |
| 751 void TextButton::GetExtraParams(gfx::NativeTheme::ExtraParams* params) const { | 767 void TextButton::GetExtraParams(gfx::NativeTheme::ExtraParams* params) const { |
| 752 TextButtonBase::GetExtraParams(params); | 768 TextButtonBase::GetExtraParams(params); |
| 753 params->button.is_default = is_default_; | 769 params->button.is_default = is_default_; |
| 754 } | 770 } |
| 755 | 771 |
| 756 gfx::Rect TextButton::GetTextBounds() const { | 772 gfx::Rect TextButton::GetTextBounds() const { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 gfx::Size NativeTextButton::GetMinimumSize() { | 834 gfx::Size NativeTextButton::GetMinimumSize() { |
| 819 return GetPreferredSize(); | 835 return GetPreferredSize(); |
| 820 } | 836 } |
| 821 | 837 |
| 822 std::string NativeTextButton::GetClassName() const { | 838 std::string NativeTextButton::GetClassName() const { |
| 823 return kViewClassName; | 839 return kViewClassName; |
| 824 } | 840 } |
| 825 | 841 |
| 826 void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) { | 842 void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| 827 #if defined(OS_WIN) | 843 #if defined(OS_WIN) |
| 828 // 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. | |
| 830 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) { | 844 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) { |
| 831 gfx::Rect rect(GetLocalBounds()); | 845 gfx::Rect rect(GetLocalBounds()); |
| 832 rect.Inset(3, 3); | 846 rect.Inset(kFocusRectInset, kFocusRectInset); |
| 833 canvas->DrawFocusRect(rect); | 847 canvas->DrawFocusRect(rect); |
| 834 } | 848 } |
| 835 #else | 849 #else |
| 836 TextButton::OnPaintFocusBorder(canvas); | 850 TextButton::OnPaintFocusBorder(canvas); |
| 837 #endif | 851 #endif |
| 838 } | 852 } |
| 839 | 853 |
| 840 void NativeTextButton::GetExtraParams( | 854 void NativeTextButton::GetExtraParams( |
| 841 gfx::NativeTheme::ExtraParams* params) const { | 855 gfx::NativeTheme::ExtraParams* params) const { |
| 842 TextButton::GetExtraParams(params); | 856 TextButton::GetExtraParams(params); |
| 843 params->button.has_border = true; | 857 params->button.has_border = true; |
| 844 } | 858 } |
| 845 | 859 |
| 846 } // namespace views | 860 } // namespace views |
| OLD | NEW |