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::kToggled: return Button::STATE_TOGGLED; | |
38 case ui::NativeTheme::kMaxState: NOTREACHED() << "Unknown state: " << state; | 39 case ui::NativeTheme::kMaxState: NOTREACHED() << "Unknown state: " << state; |
39 } | 40 } |
40 return Button::STATE_NORMAL; | 41 return Button::STATE_NORMAL; |
41 } | 42 } |
42 | 43 |
43 // 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. |
44 void PaintHelper(LabelButtonBorder* border, | 45 void PaintHelper(LabelButtonBorder* border, |
45 gfx::Canvas* canvas, | 46 gfx::Canvas* canvas, |
46 const ui::NativeTheme* theme, | 47 const ui::NativeTheme* theme, |
47 ui::NativeTheme::Part part, | 48 ui::NativeTheme::Part part, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 SetPainter(false, Button::STATE_HOVERED, | 87 SetPainter(false, Button::STATE_HOVERED, |
87 Painter::CreateImageGridPainter(kTextHoveredImages)); | 88 Painter::CreateImageGridPainter(kTextHoveredImages)); |
88 SetPainter(false, Button::STATE_PRESSED, | 89 SetPainter(false, Button::STATE_PRESSED, |
89 Painter::CreateImageGridPainter(kTextPressedImages)); | 90 Painter::CreateImageGridPainter(kTextPressedImages)); |
90 } | 91 } |
91 } | 92 } |
92 | 93 |
93 LabelButtonBorder::~LabelButtonBorder() {} | 94 LabelButtonBorder::~LabelButtonBorder() {} |
94 | 95 |
95 void LabelButtonBorder::Paint(const View& view, gfx::Canvas* canvas) { | 96 void LabelButtonBorder::Paint(const View& view, gfx::Canvas* canvas) { |
96 DCHECK(!strcmp(view.GetClassName(), LabelButton::kViewClassName)); | 97 //DCHECK(!strcmp(view.GetClassName(), LabelButton::kViewClassName)); |
msw
2013/05/16 22:40:05
You can just remove this DCHECK.
tfarina
2013/05/18 00:54:08
Done.
| |
97 const NativeThemeDelegate* native_theme_delegate = | 98 const NativeThemeDelegate* native_theme_delegate = |
98 static_cast<const LabelButton*>(&view); | 99 static_cast<const LabelButton*>(&view); |
99 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart(); | 100 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart(); |
100 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); | 101 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); |
101 ui::NativeTheme::ExtraParams extra; | 102 ui::NativeTheme::ExtraParams extra; |
102 const ui::NativeTheme* theme = view.GetNativeTheme(); | 103 const ui::NativeTheme* theme = view.GetNativeTheme(); |
103 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation(); | 104 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation(); |
104 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); | 105 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); |
105 | 106 |
106 if (animation && animation->is_animating()) { | 107 if (animation && animation->is_animating()) { |
(...skipping 24 matching lines...) Expand all Loading... | |
131 } | 132 } |
132 | 133 |
133 gfx::Insets LabelButtonBorder::GetInsets() const { | 134 gfx::Insets LabelButtonBorder::GetInsets() const { |
134 // Return the style-specific insets between button contents and edges. | 135 // Return the style-specific insets between button contents and edges. |
135 if (style() == Button::STYLE_BUTTON) | 136 if (style() == Button::STYLE_BUTTON) |
136 return gfx::Insets(9, 13, 9, 13); | 137 return gfx::Insets(9, 13, 9, 13); |
137 if (style() == Button::STYLE_TEXTBUTTON) | 138 if (style() == Button::STYLE_TEXTBUTTON) |
138 return gfx::Insets(5, 6, 5, 6); | 139 return gfx::Insets(5, 6, 5, 6); |
139 if (style() == Button::STYLE_NATIVE_TEXTBUTTON) | 140 if (style() == Button::STYLE_NATIVE_TEXTBUTTON) |
140 return gfx::Insets(5, 12, 5, 12); | 141 return gfx::Insets(5, 12, 5, 12); |
142 if (style() == Button::STYLE_CHECKBOX) | |
msw
2013/05/16 22:40:05
Would you mind making this function a switch inste
tfarina
2013/05/18 00:54:08
Done.
| |
143 return gfx::Insets(5, 12, 5, 12); | |
144 if (style() == Button::STYLE_RADIO) | |
145 return gfx::Insets(5, 12, 5, 12); | |
141 NOTREACHED(); | 146 NOTREACHED(); |
142 return gfx::Insets(); | 147 return gfx::Insets(); |
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 |