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.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 Loading... |
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 const size_t focused_index = HasFocus() ? 1 : 0; |
65 return button_state_images_[STATE_NORMAL]; | 65 if (for_state != STATE_NORMAL && |
66 return button_state_images_[for_state]; | 66 button_state_images_[focused_index][for_state].isNull()) |
| 67 return button_state_images_[focused_index][STATE_NORMAL]; |
| 68 return button_state_images_[focused_index][for_state]; |
67 } | 69 } |
68 | 70 |
69 void LabelButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) { | 71 void LabelButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) { |
70 button_state_images_[for_state] = image; | 72 button_state_images_[0][for_state] = image; |
71 image_->SetImage(GetImage(state())); | 73 image_->SetImage(GetImage(state())); |
72 } | 74 } |
73 | 75 |
| 76 void LabelButton::SetFocusedImage(ButtonState for_state, |
| 77 const gfx::ImageSkia& image) { |
| 78 button_state_images_[1][for_state] = image; |
| 79 image_->SetImage(GetImage(state())); |
| 80 } |
| 81 |
74 const string16& LabelButton::GetText() const { | 82 const string16& LabelButton::GetText() const { |
75 return label_->text(); | 83 return label_->text(); |
76 } | 84 } |
77 | 85 |
78 void LabelButton::SetText(const string16& text) { | 86 void LabelButton::SetText(const string16& text) { |
79 SetAccessibleName(text); | 87 SetAccessibleName(text); |
80 label_->SetText(text); | 88 label_->SetText(text); |
81 } | 89 } |
82 | 90 |
83 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { | 91 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 size.set_width(std::min(max_size_.width(), size.width())); | 195 size.set_width(std::min(max_size_.width(), size.width())); |
188 if (max_size_.height() > 0) | 196 if (max_size_.height() > 0) |
189 size.set_height(std::min(max_size_.height(), size.height())); | 197 size.set_height(std::min(max_size_.height(), size.height())); |
190 return size; | 198 return size; |
191 } | 199 } |
192 | 200 |
193 const char* LabelButton::GetClassName() const { | 201 const char* LabelButton::GetClassName() const { |
194 return kViewClassName; | 202 return kViewClassName; |
195 } | 203 } |
196 | 204 |
| 205 void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { |
| 206 params->button.checked = false; |
| 207 params->button.indeterminate = false; |
| 208 params->button.is_default = is_default_; |
| 209 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); |
| 210 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON; |
| 211 params->button.classic_state = 0; |
| 212 params->button.background_color = GetNativeTheme()->GetSystemColor( |
| 213 ui::NativeTheme::kColorId_ButtonBackgroundColor); |
| 214 } |
| 215 |
197 void LabelButton::ResetColorsFromNativeTheme() { | 216 void LabelButton::ResetColorsFromNativeTheme() { |
198 const ui::NativeTheme* theme = GetNativeTheme(); | 217 const ui::NativeTheme* theme = GetNativeTheme(); |
199 SkColor colors[STATE_COUNT] = { | 218 SkColor colors[STATE_COUNT] = { |
200 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor), | 219 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor), |
201 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), | 220 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), |
202 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), | 221 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor), |
203 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor), | 222 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor), |
204 }; | 223 }; |
205 | 224 |
206 // Certain styles do not change text color when hovered or pressed. | 225 // Certain styles do not change text color when hovered or pressed. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 return ui::NativeTheme::kPushButton; | 304 return ui::NativeTheme::kPushButton; |
286 } | 305 } |
287 | 306 |
288 gfx::Rect LabelButton::GetThemePaintRect() const { | 307 gfx::Rect LabelButton::GetThemePaintRect() const { |
289 return GetLocalBounds(); | 308 return GetLocalBounds(); |
290 } | 309 } |
291 | 310 |
292 ui::NativeTheme::State LabelButton::GetThemeState( | 311 ui::NativeTheme::State LabelButton::GetThemeState( |
293 ui::NativeTheme::ExtraParams* params) const { | 312 ui::NativeTheme::ExtraParams* params) const { |
294 GetExtraParams(params); | 313 GetExtraParams(params); |
295 switch(state()) { | 314 switch (state()) { |
296 case STATE_NORMAL: return ui::NativeTheme::kNormal; | 315 case STATE_NORMAL: return ui::NativeTheme::kNormal; |
297 case STATE_HOVERED: return ui::NativeTheme::kHovered; | 316 case STATE_HOVERED: return ui::NativeTheme::kHovered; |
298 case STATE_PRESSED: return ui::NativeTheme::kPressed; | 317 case STATE_PRESSED: return ui::NativeTheme::kPressed; |
299 case STATE_DISABLED: return ui::NativeTheme::kDisabled; | 318 case STATE_DISABLED: return ui::NativeTheme::kDisabled; |
300 case STATE_COUNT: NOTREACHED() << "Unknown state: " << state(); | 319 case STATE_COUNT: NOTREACHED() << "Unknown state: " << state(); |
301 } | 320 } |
302 return ui::NativeTheme::kNormal; | 321 return ui::NativeTheme::kNormal; |
303 } | 322 } |
304 | 323 |
305 const ui::Animation* LabelButton::GetThemeAnimation() const { | 324 const ui::Animation* LabelButton::GetThemeAnimation() const { |
(...skipping 12 matching lines...) Expand all Loading... |
318 GetExtraParams(params); | 337 GetExtraParams(params); |
319 return ui::NativeTheme::kNormal; | 338 return ui::NativeTheme::kNormal; |
320 } | 339 } |
321 | 340 |
322 ui::NativeTheme::State LabelButton::GetForegroundThemeState( | 341 ui::NativeTheme::State LabelButton::GetForegroundThemeState( |
323 ui::NativeTheme::ExtraParams* params) const { | 342 ui::NativeTheme::ExtraParams* params) const { |
324 GetExtraParams(params); | 343 GetExtraParams(params); |
325 return ui::NativeTheme::kHovered; | 344 return ui::NativeTheme::kHovered; |
326 } | 345 } |
327 | 346 |
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 | 347 } // namespace views |
OLD | NEW |