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

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

Issue 15061006: views: Switch Checkbox over to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: override GetImage + SetCheckedImage 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.h" 5 #include "ui/views/controls/button/label_button.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/throb_animation.h" 9 #include "ui/base/animation/throb_animation.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 // Initialize the colors, border, and layout. 55 // Initialize the colors, border, and layout.
56 SetStyle(style_); 56 SetStyle(style_);
57 57
58 SetAccessibleName(text); 58 SetAccessibleName(text);
59 } 59 }
60 60
61 LabelButton::~LabelButton() {} 61 LabelButton::~LabelButton() {}
62 62
63 const gfx::ImageSkia& LabelButton::GetImage(ButtonState for_state) { 63 const gfx::ImageSkia& LabelButton::GetImage(ButtonState for_state) {
64 if (for_state != STATE_NORMAL && button_state_images_[for_state].isNull()) 64 if (for_state != STATE_NORMAL && button_state_images_[0][for_state].isNull())
65 return button_state_images_[STATE_NORMAL]; 65 return button_state_images_[0][STATE_NORMAL];
66 return button_state_images_[for_state]; 66 return button_state_images_[0][for_state];
67 }
68
69 const gfx::ImageSkia& LabelButton::GetFocusedImage(ButtonState for_state) {
msw 2013/05/18 03:46:30 Don't make a separate GetFocusedImage. Check if th
tfarina 2013/05/18 18:43:23 Done.
70 if (for_state != STATE_NORMAL && button_state_images_[1][for_state].isNull())
71 return button_state_images_[1][STATE_NORMAL];
72 return button_state_images_[1][for_state];
67 } 73 }
68 74
69 void LabelButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) { 75 void LabelButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) {
70 button_state_images_[for_state] = image; 76 button_state_images_[0][for_state] = image;
71 image_->SetImage(GetImage(state())); 77 image_->SetImage(GetImage(state()));
72 } 78 }
73 79
80 void LabelButton::SetFocusedImage(ButtonState for_state,
81 const gfx::ImageSkia& image) {
82 button_state_images_[1][for_state] = image;
83 image_->SetImage(GetFocusedImage(state()));
84 }
85
74 const string16& LabelButton::GetText() const { 86 const string16& LabelButton::GetText() const {
75 return label_->text(); 87 return label_->text();
76 } 88 }
77 89
78 void LabelButton::SetText(const string16& text) { 90 void LabelButton::SetText(const string16& text) {
79 SetAccessibleName(text); 91 SetAccessibleName(text);
80 label_->SetText(text); 92 label_->SetText(text);
81 } 93 }
82 94
83 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { 95 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 size.set_width(std::min(max_size_.width(), size.width())); 199 size.set_width(std::min(max_size_.width(), size.width()));
188 if (max_size_.height() > 0) 200 if (max_size_.height() > 0)
189 size.set_height(std::min(max_size_.height(), size.height())); 201 size.set_height(std::min(max_size_.height(), size.height()));
190 return size; 202 return size;
191 } 203 }
192 204
193 const char* LabelButton::GetClassName() const { 205 const char* LabelButton::GetClassName() const {
194 return kViewClassName; 206 return kViewClassName;
195 } 207 }
196 208
209 void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
210 params->button.checked = false;
211 params->button.indeterminate = false;
212 params->button.is_default = is_default_;
213 params->button.is_focused = HasFocus() && IsAccessibilityFocusable();
214 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON;
215 params->button.classic_state = 0;
216 params->button.background_color = GetNativeTheme()->GetSystemColor(
217 ui::NativeTheme::kColorId_ButtonBackgroundColor);
218 }
219
197 void LabelButton::ResetColorsFromNativeTheme() { 220 void LabelButton::ResetColorsFromNativeTheme() {
198 const ui::NativeTheme* theme = GetNativeTheme(); 221 const ui::NativeTheme* theme = GetNativeTheme();
199 SkColor colors[STATE_COUNT] = { 222 SkColor colors[STATE_COUNT] = {
200 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor), 223 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor),
201 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), 224 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor),
202 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), 225 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor),
203 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor), 226 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor),
204 }; 227 };
205 228
206 // Certain styles do not change text color when hovered or pressed. 229 // Certain styles do not change text color when hovered or pressed.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 return ui::NativeTheme::kPushButton; 308 return ui::NativeTheme::kPushButton;
286 } 309 }
287 310
288 gfx::Rect LabelButton::GetThemePaintRect() const { 311 gfx::Rect LabelButton::GetThemePaintRect() const {
289 return GetLocalBounds(); 312 return GetLocalBounds();
290 } 313 }
291 314
292 ui::NativeTheme::State LabelButton::GetThemeState( 315 ui::NativeTheme::State LabelButton::GetThemeState(
293 ui::NativeTheme::ExtraParams* params) const { 316 ui::NativeTheme::ExtraParams* params) const {
294 GetExtraParams(params); 317 GetExtraParams(params);
295 switch(state()) { 318 switch (state()) {
296 case STATE_NORMAL: return ui::NativeTheme::kNormal; 319 case STATE_NORMAL: return ui::NativeTheme::kNormal;
297 case STATE_HOVERED: return ui::NativeTheme::kHovered; 320 case STATE_HOVERED: return ui::NativeTheme::kHovered;
298 case STATE_PRESSED: return ui::NativeTheme::kPressed; 321 case STATE_PRESSED: return ui::NativeTheme::kPressed;
299 case STATE_DISABLED: return ui::NativeTheme::kDisabled; 322 case STATE_DISABLED: return ui::NativeTheme::kDisabled;
300 case STATE_COUNT: NOTREACHED() << "Unknown state: " << state(); 323 case STATE_COUNT: NOTREACHED() << "Unknown state: " << state();
301 } 324 }
302 return ui::NativeTheme::kNormal; 325 return ui::NativeTheme::kNormal;
303 } 326 }
304 327
305 const ui::Animation* LabelButton::GetThemeAnimation() const { 328 const ui::Animation* LabelButton::GetThemeAnimation() const {
(...skipping 12 matching lines...) Expand all
318 GetExtraParams(params); 341 GetExtraParams(params);
319 return ui::NativeTheme::kNormal; 342 return ui::NativeTheme::kNormal;
320 } 343 }
321 344
322 ui::NativeTheme::State LabelButton::GetForegroundThemeState( 345 ui::NativeTheme::State LabelButton::GetForegroundThemeState(
323 ui::NativeTheme::ExtraParams* params) const { 346 ui::NativeTheme::ExtraParams* params) const {
324 GetExtraParams(params); 347 GetExtraParams(params);
325 return ui::NativeTheme::kHovered; 348 return ui::NativeTheme::kHovered;
326 } 349 }
327 350
328 void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
329 params->button.checked = false;
330 params->button.indeterminate = false;
331 params->button.is_default = is_default_;
332 params->button.is_focused = HasFocus() && IsAccessibilityFocusable();
333 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON;
334 params->button.classic_state = 0;
335 params->button.background_color = GetNativeTheme()->GetSystemColor(
336 ui::NativeTheme::kColorId_ButtonBackgroundColor);
337 }
338
339 } // namespace views 351 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698