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 12 matching lines...) Expand all Loading... |
23 const int kPressedImages[] = IMAGE_GRID(IDR_BUTTON_PRESSED); | 23 const int kPressedImages[] = IMAGE_GRID(IDR_BUTTON_PRESSED); |
24 const int kFocusedNormalImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_NORMAL); | 24 const int kFocusedNormalImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_NORMAL); |
25 const int kFocusedHoveredImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_HOVER); | 25 const int kFocusedHoveredImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_HOVER); |
26 const int kFocusedPressedImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_PRESSED); | 26 const int kFocusedPressedImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_PRESSED); |
27 | 27 |
28 // The text-button hot and pushed image IDs; normal is unadorned by default. | 28 // The text-button hot and pushed image IDs; normal is unadorned by default. |
29 const int kTextHoveredImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER); | 29 const int kTextHoveredImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER); |
30 const int kTextPressedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED); | 30 const int kTextPressedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED); |
31 | 31 |
32 Button::ButtonState GetButtonState(ui::NativeTheme::State state) { | 32 Button::ButtonState GetButtonState(ui::NativeTheme::State state) { |
33 switch(state) { | 33 switch (state) { |
34 case ui::NativeTheme::kDisabled: return Button::STATE_DISABLED; | 34 case ui::NativeTheme::kDisabled: return Button::STATE_DISABLED; |
35 case ui::NativeTheme::kHovered: return Button::STATE_HOVERED; | 35 case ui::NativeTheme::kHovered: return Button::STATE_HOVERED; |
36 case ui::NativeTheme::kNormal: return Button::STATE_NORMAL; | 36 case ui::NativeTheme::kNormal: return Button::STATE_NORMAL; |
37 case ui::NativeTheme::kPressed: return Button::STATE_PRESSED; | 37 case ui::NativeTheme::kPressed: return Button::STATE_PRESSED; |
38 case ui::NativeTheme::kMaxState: NOTREACHED() << "Unknown state: " << state; | 38 case ui::NativeTheme::kMaxState: NOTREACHED() << "Unknown state: " << state; |
39 } | 39 } |
40 return Button::STATE_NORMAL; | 40 return Button::STATE_NORMAL; |
41 } | 41 } |
42 | 42 |
43 // A helper function to paint the native theme or images as appropriate. | 43 // A helper function to paint the native theme or images as appropriate. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 SetPainter(false, Button::STATE_HOVERED, | 86 SetPainter(false, Button::STATE_HOVERED, |
87 Painter::CreateImageGridPainter(kTextHoveredImages)); | 87 Painter::CreateImageGridPainter(kTextHoveredImages)); |
88 SetPainter(false, Button::STATE_PRESSED, | 88 SetPainter(false, Button::STATE_PRESSED, |
89 Painter::CreateImageGridPainter(kTextPressedImages)); | 89 Painter::CreateImageGridPainter(kTextPressedImages)); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 LabelButtonBorder::~LabelButtonBorder() {} | 93 LabelButtonBorder::~LabelButtonBorder() {} |
94 | 94 |
95 void LabelButtonBorder::Paint(const View& view, gfx::Canvas* canvas) { | 95 void LabelButtonBorder::Paint(const View& view, gfx::Canvas* canvas) { |
96 DCHECK(!strcmp(view.GetClassName(), LabelButton::kViewClassName)); | |
97 const NativeThemeDelegate* native_theme_delegate = | 96 const NativeThemeDelegate* native_theme_delegate = |
98 static_cast<const LabelButton*>(&view); | 97 static_cast<const LabelButton*>(&view); |
99 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart(); | 98 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart(); |
100 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); | 99 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); |
101 ui::NativeTheme::ExtraParams extra; | 100 ui::NativeTheme::ExtraParams extra; |
102 const ui::NativeTheme* theme = view.GetNativeTheme(); | 101 const ui::NativeTheme* theme = view.GetNativeTheme(); |
103 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation(); | 102 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation(); |
104 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); | 103 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); |
105 | 104 |
106 if (animation && animation->is_animating()) { | 105 if (animation && animation->is_animating()) { |
(...skipping 18 matching lines...) Expand all Loading... |
125 } | 124 } |
126 | 125 |
127 // Draw the Views focus border for the native theme style. | 126 // Draw the Views focus border for the native theme style. |
128 if (style() == Button::STYLE_NATIVE_TEXTBUTTON && | 127 if (style() == Button::STYLE_NATIVE_TEXTBUTTON && |
129 view.focus_border() && extra.button.is_focused) | 128 view.focus_border() && extra.button.is_focused) |
130 view.focus_border()->Paint(view, canvas); | 129 view.focus_border()->Paint(view, canvas); |
131 } | 130 } |
132 | 131 |
133 gfx::Insets LabelButtonBorder::GetInsets() const { | 132 gfx::Insets LabelButtonBorder::GetInsets() const { |
134 // Return the style-specific insets between button contents and edges. | 133 // Return the style-specific insets between button contents and edges. |
135 if (style() == Button::STYLE_BUTTON) | 134 switch (style()) { |
136 return gfx::Insets(9, 13, 9, 13); | 135 case Button::STYLE_BUTTON: |
137 if (style() == Button::STYLE_TEXTBUTTON) | 136 return gfx::Insets(9, 13, 9, 13); |
138 return gfx::Insets(5, 6, 5, 6); | 137 case Button::STYLE_TEXTBUTTON: |
139 if (style() == Button::STYLE_NATIVE_TEXTBUTTON) | 138 return gfx::Insets(5, 6, 5, 6); |
140 return gfx::Insets(5, 12, 5, 12); | 139 case Button::STYLE_NATIVE_TEXTBUTTON: |
141 NOTREACHED(); | 140 return gfx::Insets(5, 12, 5, 12); |
142 return gfx::Insets(); | 141 case Button::STYLE_CHECKBOX: |
| 142 case Button::STYLE_RADIO: |
| 143 return gfx::Insets(7, 6, 5, 7); |
| 144 case Button::STYLE_COUNT: |
| 145 NOTREACHED(); |
| 146 return gfx::Insets(); |
| 147 } |
143 } | 148 } |
144 | 149 |
145 Painter* LabelButtonBorder::GetPainter(bool focused, | 150 Painter* LabelButtonBorder::GetPainter(bool focused, |
146 Button::ButtonState state) { | 151 Button::ButtonState state) { |
147 return painters_[focused ? 1 : 0][state].get(); | 152 return painters_[focused ? 1 : 0][state].get(); |
148 } | 153 } |
149 | 154 |
150 void LabelButtonBorder::SetPainter(bool focused, | 155 void LabelButtonBorder::SetPainter(bool focused, |
151 Button::ButtonState state, | 156 Button::ButtonState state, |
152 Painter* painter) { | 157 Painter* painter) { |
153 painters_[focused ? 1 : 0][state].reset(painter); | 158 painters_[focused ? 1 : 0][state].reset(painter); |
154 } | 159 } |
155 | 160 |
156 } // namespace views | 161 } // namespace views |
OLD | NEW |