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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "ui/gfx/animation/throb_animation.h" | 15 #include "ui/gfx/animation/throb_animation.h" |
16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/color_utils.h" | 17 #include "ui/gfx/color_utils.h" |
18 #include "ui/gfx/font_list.h" | 18 #include "ui/gfx/font_list.h" |
19 #include "ui/gfx/geometry/vector2d.h" | 19 #include "ui/gfx/geometry/vector2d.h" |
20 #include "ui/native_theme/native_theme.h" | 20 #include "ui/native_theme/native_theme.h" |
21 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 21 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
22 #include "ui/views/animation/ink_drop.h" | 22 #include "ui/views/animation/ink_drop.h" |
23 #include "ui/views/animation/ink_drop_highlight.h" | 23 #include "ui/views/animation/ink_drop_highlight.h" |
24 #include "ui/views/animation/ink_drop_impl.h" | 24 #include "ui/views/animation/ink_drop_impl.h" |
25 #include "ui/views/animation/square_ink_drop_ripple.h" | 25 #include "ui/views/animation/square_ink_drop_ripple.h" |
26 #include "ui/views/background.h" | 26 #include "ui/views/background.h" |
27 #include "ui/views/controls/button/label_button_border.h" | 27 #include "ui/views/controls/button/label_button_border.h" |
| 28 #include "ui/views/controls/button/label_button_label.h" |
28 #include "ui/views/layout/layout_provider.h" | 29 #include "ui/views/layout/layout_provider.h" |
29 #include "ui/views/painter.h" | 30 #include "ui/views/painter.h" |
30 #include "ui/views/style/platform_style.h" | 31 #include "ui/views/style/platform_style.h" |
31 #include "ui/views/window/dialog_delegate.h" | 32 #include "ui/views/window/dialog_delegate.h" |
32 | 33 |
33 namespace views { | 34 namespace views { |
34 | 35 |
35 // static | 36 // static |
36 const int LabelButton::kHoverAnimationDurationMs = 170; | 37 const int LabelButton::kHoverAnimationDurationMs = 170; |
37 const char LabelButton::kViewClassName[] = "LabelButton"; | 38 const char LabelButton::kViewClassName[] = "LabelButton"; |
38 | 39 |
39 LabelButton::LabelButton(ButtonListener* listener, | 40 LabelButton::LabelButton(ButtonListener* listener, |
40 const base::string16& text, | 41 const base::string16& text, |
41 int button_context) | 42 int button_context) |
42 : CustomButton(listener), | 43 : CustomButton(listener), |
43 image_(new ImageView()), | 44 image_(new ImageView()), |
44 label_(new Label(text, button_context, style::STYLE_PRIMARY)), | 45 label_(new LabelButtonLabel(text, button_context)), |
45 ink_drop_container_(new InkDropContainerView()), | 46 ink_drop_container_(new InkDropContainerView()), |
46 cached_normal_font_list_( | 47 cached_normal_font_list_( |
47 style::GetFont(button_context, style::STYLE_PRIMARY)), | 48 style::GetFont(button_context, style::STYLE_PRIMARY)), |
48 cached_default_button_font_list_( | 49 cached_default_button_font_list_( |
49 style::GetFont(button_context, style::STYLE_DIALOG_BUTTON_DEFAULT)), | 50 style::GetFont(button_context, style::STYLE_DIALOG_BUTTON_DEFAULT)), |
50 button_state_images_(), | 51 button_state_images_(), |
51 button_state_colors_(), | 52 button_state_colors_(), |
52 explicitly_set_colors_(), | 53 explicitly_set_colors_(), |
53 is_default_(false), | 54 is_default_(false), |
54 style_(STYLE_TEXTBUTTON), | 55 style_(STYLE_TEXTBUTTON), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 return label_->text(); | 93 return label_->text(); |
93 } | 94 } |
94 | 95 |
95 void LabelButton::SetText(const base::string16& text) { | 96 void LabelButton::SetText(const base::string16& text) { |
96 SetTextInternal(text); | 97 SetTextInternal(text); |
97 } | 98 } |
98 | 99 |
99 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { | 100 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { |
100 button_state_colors_[for_state] = color; | 101 button_state_colors_[for_state] = color; |
101 if (for_state == STATE_DISABLED) | 102 if (for_state == STATE_DISABLED) |
102 label_->SetDisabledColorForLabelButton(color); | 103 label_->SetDisabledColor(color); |
103 else if (for_state == state()) | 104 else if (for_state == state()) |
104 label_->SetEnabledColor(color); | 105 label_->SetEnabledColor(color); |
105 explicitly_set_colors_[for_state] = true; | 106 explicitly_set_colors_[for_state] = true; |
106 } | 107 } |
107 | 108 |
108 void LabelButton::SetEnabledTextColors(SkColor color) { | 109 void LabelButton::SetEnabledTextColors(SkColor color) { |
109 ButtonState states[] = {STATE_NORMAL, STATE_HOVERED, STATE_PRESSED}; | 110 ButtonState states[] = {STATE_NORMAL, STATE_HOVERED, STATE_PRESSED}; |
110 for (auto state : states) | 111 for (auto state : states) |
111 SetTextColor(state, color); | 112 SetTextColor(state, color); |
112 } | 113 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 style_)); | 319 style_)); |
319 return border; | 320 return border; |
320 } | 321 } |
321 | 322 |
322 void LabelButton::SetBorder(std::unique_ptr<Border> border) { | 323 void LabelButton::SetBorder(std::unique_ptr<Border> border) { |
323 border_is_themed_border_ = false; | 324 border_is_themed_border_ = false; |
324 View::SetBorder(std::move(border)); | 325 View::SetBorder(std::move(border)); |
325 ResetCachedPreferredSize(); | 326 ResetCachedPreferredSize(); |
326 } | 327 } |
327 | 328 |
| 329 Label* LabelButton::label() const { |
| 330 return label_; |
| 331 } |
| 332 |
328 gfx::Rect LabelButton::GetChildAreaBounds() { | 333 gfx::Rect LabelButton::GetChildAreaBounds() { |
329 return GetLocalBounds(); | 334 return GetLocalBounds(); |
330 } | 335 } |
331 | 336 |
332 bool LabelButton::ShouldUseFloodFillInkDrop() const { | 337 bool LabelButton::ShouldUseFloodFillInkDrop() const { |
333 return !GetText().empty(); | 338 return !GetText().empty(); |
334 } | 339 } |
335 | 340 |
336 void LabelButton::OnFocus() { | 341 void LabelButton::OnFocus() { |
337 CustomButton::OnFocus(); | 342 CustomButton::OnFocus(); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 void LabelButton::ResetLabelEnabledColor() { | 549 void LabelButton::ResetLabelEnabledColor() { |
545 const SkColor color = | 550 const SkColor color = |
546 explicitly_set_colors_[state()] | 551 explicitly_set_colors_[state()] |
547 ? button_state_colors_[state()] | 552 ? button_state_colors_[state()] |
548 : PlatformStyle::TextColorForButton(button_state_colors_, *this); | 553 : PlatformStyle::TextColorForButton(button_state_colors_, *this); |
549 if (state() != STATE_DISABLED && label_->enabled_color() != color) | 554 if (state() != STATE_DISABLED && label_->enabled_color() != color) |
550 label_->SetEnabledColor(color); | 555 label_->SetEnabledColor(color); |
551 } | 556 } |
552 | 557 |
553 } // namespace views | 558 } // namespace views |
OLD | NEW |