Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: ui/views/controls/button/label_button_border.cc

Issue 15061006: views: Switch Checkbox over to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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_BUTTON:
msw 2013/05/18 01:04:56 Remove this duplicated case for STYLE_BUTTON.
tfarina 2013/05/18 02:30:49 Done.
139 if (style() == Button::STYLE_NATIVE_TEXTBUTTON) 138 case Button::STYLE_TEXTBUTTON:
140 return gfx::Insets(5, 12, 5, 12); 139 return gfx::Insets(5, 6, 5, 6);
140 case Button::STYLE_NATIVE_TEXTBUTTON:
141 return gfx::Insets(5, 12, 5, 12);
142 case Button::STYLE_CHECKBOX:
143 case Button::STYLE_RADIO:
144 return gfx::Insets(5, 12, 5, 12);
145 default:
msw 2013/05/18 01:04:56 Make this a STYLE_COUNT case, and don't offer a de
tfarina 2013/05/18 02:30:49 Done.
146 NOTREACHED();
147 return gfx::Insets();
148 }
141 NOTREACHED(); 149 NOTREACHED();
msw 2013/05/18 01:04:56 Can you remove this NOTREACHED and the extra retur
tfarina 2013/05/18 02:30:49 Done.
142 return gfx::Insets(); 150 return gfx::Insets();
143 } 151 }
144 152
145 Painter* LabelButtonBorder::GetPainter(bool focused, 153 Painter* LabelButtonBorder::GetPainter(bool focused,
146 Button::ButtonState state) { 154 Button::ButtonState state) {
147 return painters_[focused ? 1 : 0][state].get(); 155 return painters_[focused ? 1 : 0][state].get();
148 } 156 }
149 157
150 void LabelButtonBorder::SetPainter(bool focused, 158 void LabelButtonBorder::SetPainter(bool focused,
151 Button::ButtonState state, 159 Button::ButtonState state,
152 Painter* painter) { 160 Painter* painter) {
153 painters_[focused ? 1 : 0][state].reset(painter); 161 painters_[focused ? 1 : 0][state].reset(painter);
154 } 162 }
155 163
156 } // namespace views 164 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698