OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/controls/button/text_button.h" | 5 #include "views/controls/button/text_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/throb_animation.h" | 9 #include "app/throb_animation.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // static | 27 // static |
28 const SkColor TextButton::kHighlightColor = SkColorSetARGB(200, 255, 255, 255); | 28 const SkColor TextButton::kHighlightColor = SkColorSetARGB(200, 255, 255, 255); |
29 // static | 29 // static |
30 const SkColor TextButton::kDisabledColor = SkColorSetRGB(161, 161, 146); | 30 const SkColor TextButton::kDisabledColor = SkColorSetRGB(161, 161, 146); |
31 // static | 31 // static |
32 const SkColor TextButton::kHoverColor = TextButton::kEnabledColor; | 32 const SkColor TextButton::kHoverColor = TextButton::kEnabledColor; |
33 | 33 |
34 // How long the hover fade animation should last. | 34 // How long the hover fade animation should last. |
35 static const int kHoverAnimationDurationMs = 170; | 35 static const int kHoverAnimationDurationMs = 170; |
36 | 36 |
| 37 // static |
| 38 const char TextButton::kViewClassName[] = "views/TextButton"; |
| 39 |
37 static int PrefixTypeToCanvasType(TextButton::PrefixType type) { | 40 static int PrefixTypeToCanvasType(TextButton::PrefixType type) { |
38 switch (type) { | 41 switch (type) { |
39 case TextButton::PREFIX_HIDE: | 42 case TextButton::PREFIX_HIDE: |
40 return gfx::Canvas::HIDE_PREFIX; | 43 return gfx::Canvas::HIDE_PREFIX; |
41 case TextButton::PREFIX_SHOW: | 44 case TextButton::PREFIX_SHOW: |
42 return gfx::Canvas::SHOW_PREFIX; | 45 return gfx::Canvas::SHOW_PREFIX; |
43 case TextButton::PREFIX_NONE: | 46 case TextButton::PREFIX_NONE: |
44 return 0; | 47 return 0; |
45 default: | 48 default: |
46 NOTREACHED(); | 49 NOTREACHED(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 SetText(text); | 199 SetText(text); |
197 set_border(new TextButtonBorder); | 200 set_border(new TextButtonBorder); |
198 SetAnimationDuration(kHoverAnimationDurationMs); | 201 SetAnimationDuration(kHoverAnimationDurationMs); |
199 } | 202 } |
200 | 203 |
201 TextButton::~TextButton() { | 204 TextButton::~TextButton() { |
202 } | 205 } |
203 | 206 |
204 void TextButton::SetText(const std::wstring& text) { | 207 void TextButton::SetText(const std::wstring& text) { |
205 text_ = text; | 208 text_ = text; |
| 209 SetAccessibleName(text); |
206 UpdateTextSize(); | 210 UpdateTextSize(); |
207 } | 211 } |
208 | 212 |
209 void TextButton::SetIcon(const SkBitmap& icon) { | 213 void TextButton::SetIcon(const SkBitmap& icon) { |
210 icon_ = icon; | 214 icon_ = icon; |
211 } | 215 } |
212 | 216 |
213 void TextButton::SetHoverIcon(const SkBitmap& icon) { | 217 void TextButton::SetHoverIcon(const SkBitmap& icon) { |
214 icon_hover_ = icon; | 218 icon_hover_ = icon; |
215 has_hover_icon_ = true; | 219 has_hover_icon_ = true; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 void TextButton::SetEnabled(bool enabled) { | 424 void TextButton::SetEnabled(bool enabled) { |
421 if (enabled != IsEnabled()) { | 425 if (enabled != IsEnabled()) { |
422 CustomButton::SetEnabled(enabled); | 426 CustomButton::SetEnabled(enabled); |
423 } | 427 } |
424 // We should always call UpdateColor() since the state of the button might be | 428 // We should always call UpdateColor() since the state of the button might be |
425 // changed by other functions like CustomButton::SetState(). | 429 // changed by other functions like CustomButton::SetState(). |
426 UpdateColor(); | 430 UpdateColor(); |
427 SchedulePaint(); | 431 SchedulePaint(); |
428 } | 432 } |
429 | 433 |
| 434 std::string TextButton::GetClassName() const { |
| 435 return kViewClassName; |
| 436 } |
| 437 |
430 void TextButton::Paint(gfx::Canvas* canvas) { | 438 void TextButton::Paint(gfx::Canvas* canvas) { |
431 Paint(canvas, false); | 439 Paint(canvas, false); |
432 } | 440 } |
433 | 441 |
434 } // namespace views | 442 } // namespace views |
OLD | NEW |