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/label_button_border.h" | 5 #include "ui/views/controls/button/label_button_border.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/animation/animation.h" | 9 #include "ui/base/animation/animation.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 const int kDisabledImages[] = IMAGE_GRID(IDR_BUTTON_DISABLED); | 24 const int kDisabledImages[] = IMAGE_GRID(IDR_BUTTON_DISABLED); |
25 const int kFocusedNormalImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_NORMAL); | 25 const int kFocusedNormalImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_NORMAL); |
26 const int kFocusedHoveredImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_HOVER); | 26 const int kFocusedHoveredImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_HOVER); |
27 const int kFocusedPressedImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_PRESSED); | 27 const int kFocusedPressedImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_PRESSED); |
28 | 28 |
29 // The text-button hot and pushed image IDs; normal is unadorned by default. | 29 // The text-button hot and pushed image IDs; normal is unadorned by default. |
30 const int kTextHoveredImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER); | 30 const int kTextHoveredImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER); |
31 const int kTextPressedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED); | 31 const int kTextPressedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED); |
32 | 32 |
33 Button::ButtonState GetButtonState(ui::NativeTheme::State state) { | 33 Button::ButtonState GetButtonState(ui::NativeTheme::State state) { |
34 switch(state) { | 34 switch (state) { |
35 case ui::NativeTheme::kDisabled: return Button::STATE_DISABLED; | 35 case ui::NativeTheme::kDisabled: return Button::STATE_DISABLED; |
36 case ui::NativeTheme::kHovered: return Button::STATE_HOVERED; | 36 case ui::NativeTheme::kHovered: return Button::STATE_HOVERED; |
37 case ui::NativeTheme::kNormal: return Button::STATE_NORMAL; | 37 case ui::NativeTheme::kNormal: return Button::STATE_NORMAL; |
38 case ui::NativeTheme::kPressed: return Button::STATE_PRESSED; | 38 case ui::NativeTheme::kPressed: return Button::STATE_PRESSED; |
39 case ui::NativeTheme::kMaxState: NOTREACHED() << "Unknown state: " << state; | 39 case ui::NativeTheme::kMaxState: NOTREACHED() << "Unknown state: " << state; |
40 } | 40 } |
41 return Button::STATE_NORMAL; | 41 return Button::STATE_NORMAL; |
42 } | 42 } |
43 | 43 |
44 // A helper function to paint the native theme or images as appropriate. | 44 // A helper function to paint the native theme or images as appropriate. |
(...skipping 15 matching lines...) Expand all Loading... |
60 if (painter) | 60 if (painter) |
61 painter->Paint(canvas, rect.size()); | 61 painter->Paint(canvas, rect.size()); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 } // namespace | 65 } // namespace |
66 | 66 |
67 LabelButtonBorder::LabelButtonBorder(Button::ButtonStyle style) | 67 LabelButtonBorder::LabelButtonBorder(Button::ButtonStyle style) |
68 : style_(style) { | 68 : style_(style) { |
69 if (style == Button::STYLE_BUTTON) { | 69 if (style == Button::STYLE_BUTTON) { |
| 70 set_insets(gfx::Insets(9, 13, 9, 13)); |
70 SetPainter(false, Button::STATE_NORMAL, | 71 SetPainter(false, Button::STATE_NORMAL, |
71 Painter::CreateImageGridPainter(kNormalImages)); | 72 Painter::CreateImageGridPainter(kNormalImages)); |
72 SetPainter(false, Button::STATE_HOVERED, | 73 SetPainter(false, Button::STATE_HOVERED, |
73 Painter::CreateImageGridPainter(kHoveredImages)); | 74 Painter::CreateImageGridPainter(kHoveredImages)); |
74 SetPainter(false, Button::STATE_PRESSED, | 75 SetPainter(false, Button::STATE_PRESSED, |
75 Painter::CreateImageGridPainter(kPressedImages)); | 76 Painter::CreateImageGridPainter(kPressedImages)); |
76 SetPainter(false, Button::STATE_DISABLED, | 77 SetPainter(false, Button::STATE_DISABLED, |
77 Painter::CreateImageGridPainter(kDisabledImages)); | 78 Painter::CreateImageGridPainter(kDisabledImages)); |
78 SetPainter(true, Button::STATE_NORMAL, | 79 SetPainter(true, Button::STATE_NORMAL, |
79 Painter::CreateImageGridPainter(kFocusedNormalImages)); | 80 Painter::CreateImageGridPainter(kFocusedNormalImages)); |
80 SetPainter(true, Button::STATE_HOVERED, | 81 SetPainter(true, Button::STATE_HOVERED, |
81 Painter::CreateImageGridPainter(kFocusedHoveredImages)); | 82 Painter::CreateImageGridPainter(kFocusedHoveredImages)); |
82 SetPainter(true, Button::STATE_PRESSED, | 83 SetPainter(true, Button::STATE_PRESSED, |
83 Painter::CreateImageGridPainter(kFocusedPressedImages)); | 84 Painter::CreateImageGridPainter(kFocusedPressedImages)); |
84 SetPainter(true, Button::STATE_DISABLED, | 85 SetPainter(true, Button::STATE_DISABLED, |
85 Painter::CreateImageGridPainter(kDisabledImages)); | 86 Painter::CreateImageGridPainter(kDisabledImages)); |
86 } else if (style == Button::STYLE_TEXTBUTTON) { | 87 } else if (style == Button::STYLE_TEXTBUTTON) { |
| 88 set_insets(gfx::Insets(5, 6, 5, 6)); |
87 SetPainter(false, Button::STATE_HOVERED, | 89 SetPainter(false, Button::STATE_HOVERED, |
88 Painter::CreateImageGridPainter(kTextHoveredImages)); | 90 Painter::CreateImageGridPainter(kTextHoveredImages)); |
89 SetPainter(false, Button::STATE_PRESSED, | 91 SetPainter(false, Button::STATE_PRESSED, |
90 Painter::CreateImageGridPainter(kTextPressedImages)); | 92 Painter::CreateImageGridPainter(kTextPressedImages)); |
| 93 } else if (style == Button::STYLE_NATIVE_TEXTBUTTON) { |
| 94 set_insets(gfx::Insets(5, 12, 5, 12)); |
91 } | 95 } |
92 } | 96 } |
93 | 97 |
94 LabelButtonBorder::~LabelButtonBorder() {} | 98 LabelButtonBorder::~LabelButtonBorder() {} |
95 | 99 |
96 void LabelButtonBorder::Paint(const View& view, gfx::Canvas* canvas) { | 100 void LabelButtonBorder::Paint(const View& view, gfx::Canvas* canvas) { |
97 DCHECK(!strcmp(view.GetClassName(), LabelButton::kViewClassName)); | |
98 const NativeThemeDelegate* native_theme_delegate = | 101 const NativeThemeDelegate* native_theme_delegate = |
99 static_cast<const LabelButton*>(&view); | 102 static_cast<const LabelButton*>(&view); |
100 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart(); | 103 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart(); |
101 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); | 104 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); |
102 ui::NativeTheme::ExtraParams extra; | 105 ui::NativeTheme::ExtraParams extra; |
103 const ui::NativeTheme* theme = view.GetNativeTheme(); | 106 const ui::NativeTheme* theme = view.GetNativeTheme(); |
104 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation(); | 107 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation(); |
105 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); | 108 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); |
106 | 109 |
107 if (animation && animation->is_animating()) { | 110 if (animation && animation->is_animating()) { |
(...skipping 12 matching lines...) Expand all Loading... |
120 PaintHelper(this, canvas, theme, part, state, rect, extra); | 123 PaintHelper(this, canvas, theme, part, state, rect, extra); |
121 } | 124 } |
122 | 125 |
123 // Draw the Views focus border for the native theme style. | 126 // Draw the Views focus border for the native theme style. |
124 if (style() == Button::STYLE_NATIVE_TEXTBUTTON && | 127 if (style() == Button::STYLE_NATIVE_TEXTBUTTON && |
125 view.focus_border() && extra.button.is_focused) | 128 view.focus_border() && extra.button.is_focused) |
126 view.focus_border()->Paint(view, canvas); | 129 view.focus_border()->Paint(view, canvas); |
127 } | 130 } |
128 | 131 |
129 gfx::Insets LabelButtonBorder::GetInsets() const { | 132 gfx::Insets LabelButtonBorder::GetInsets() const { |
130 // Return the style-specific insets between button contents and edges. | 133 return insets_; |
131 if (style() == Button::STYLE_BUTTON) | |
132 return gfx::Insets(9, 13, 9, 13); | |
133 if (style() == Button::STYLE_TEXTBUTTON) | |
134 return gfx::Insets(5, 6, 5, 6); | |
135 if (style() == Button::STYLE_NATIVE_TEXTBUTTON) | |
136 return gfx::Insets(5, 12, 5, 12); | |
137 NOTREACHED(); | |
138 return gfx::Insets(); | |
139 } | 134 } |
140 | 135 |
141 Painter* LabelButtonBorder::GetPainter(bool focused, | 136 Painter* LabelButtonBorder::GetPainter(bool focused, |
142 Button::ButtonState state) { | 137 Button::ButtonState state) { |
143 return painters_[focused ? 1 : 0][state].get(); | 138 return painters_[focused ? 1 : 0][state].get(); |
144 } | 139 } |
145 | 140 |
146 void LabelButtonBorder::SetPainter(bool focused, | 141 void LabelButtonBorder::SetPainter(bool focused, |
147 Button::ButtonState state, | 142 Button::ButtonState state, |
148 Painter* painter) { | 143 Painter* painter) { |
149 painters_[focused ? 1 : 0][state].reset(painter); | 144 painters_[focused ? 1 : 0][state].reset(painter); |
150 } | 145 } |
151 | 146 |
152 } // namespace views | 147 } // namespace views |
OLD | NEW |