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/image_button.h" | 5 #include "ui/views/controls/button/image_button.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "ui/base/accessibility/accessible_view_state.h" | 8 #include "ui/base/accessibility/accessible_view_state.h" |
9 #include "ui/base/animation/throb_animation.h" | 9 #include "ui/base/animation/throb_animation.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
11 #include "ui/gfx/image/image_skia_operations.h" | 11 #include "ui/gfx/image/image_skia_operations.h" |
12 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
13 | 13 |
14 namespace views { | 14 namespace views { |
15 | 15 |
16 static const int kDefaultWidth = 16; // Default button width if no theme. | 16 static const int kDefaultWidth = 16; // Default button width if no theme. |
17 static const int kDefaultHeight = 14; // Default button height if no theme. | 17 static const int kDefaultHeight = 14; // Default button height if no theme. |
18 | 18 |
| 19 const char ImageButton::kViewClassName[] = "ImageButton"; |
| 20 |
19 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
20 // ImageButton, public: | 22 // ImageButton, public: |
21 | 23 |
22 ImageButton::ImageButton(ButtonListener* listener) | 24 ImageButton::ImageButton(ButtonListener* listener) |
23 : CustomButton(listener), | 25 : CustomButton(listener), |
24 h_alignment_(ALIGN_LEFT), | 26 h_alignment_(ALIGN_LEFT), |
25 v_alignment_(ALIGN_TOP), | 27 v_alignment_(ALIGN_TOP), |
26 preferred_size_(kDefaultWidth, kDefaultHeight) { | 28 preferred_size_(kDefaultWidth, kDefaultHeight) { |
27 // By default, we request that the gfx::Canvas passed to our View::OnPaint() | 29 // By default, we request that the gfx::Canvas passed to our View::OnPaint() |
28 // implementation is flipped horizontally so that the button's images are | 30 // implementation is flipped horizontally so that the button's images are |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 if (!images_[STATE_NORMAL].isNull()) { | 79 if (!images_[STATE_NORMAL].isNull()) { |
78 size = gfx::Size(images_[STATE_NORMAL].width(), | 80 size = gfx::Size(images_[STATE_NORMAL].width(), |
79 images_[STATE_NORMAL].height()); | 81 images_[STATE_NORMAL].height()); |
80 } | 82 } |
81 | 83 |
82 gfx::Insets insets = GetInsets(); | 84 gfx::Insets insets = GetInsets(); |
83 size.Enlarge(insets.width(), insets.height()); | 85 size.Enlarge(insets.width(), insets.height()); |
84 return size; | 86 return size; |
85 } | 87 } |
86 | 88 |
| 89 const char* ImageButton::GetClassName() const { |
| 90 return kViewClassName; |
| 91 } |
| 92 |
87 void ImageButton::OnPaint(gfx::Canvas* canvas) { | 93 void ImageButton::OnPaint(gfx::Canvas* canvas) { |
88 // Call the base class first to paint any background/borders. | 94 // Call the base class first to paint any background/borders. |
89 View::OnPaint(canvas); | 95 View::OnPaint(canvas); |
90 | 96 |
91 gfx::ImageSkia img = GetImageToPaint(); | 97 gfx::ImageSkia img = GetImageToPaint(); |
92 | 98 |
93 if (!img.isNull()) { | 99 if (!img.isNull()) { |
94 gfx::Point position = ComputeImagePaintPosition(img); | 100 gfx::Point position = ComputeImagePaintPosition(img); |
95 if (!background_image_.isNull()) | 101 if (!background_image_.isNull()) |
96 canvas->DrawImageInt(background_image_, position.x(), position.y()); | 102 canvas->DrawImageInt(background_image_, position.x(), position.y()); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 *tooltip = toggled_tooltip_text_; | 221 *tooltip = toggled_tooltip_text_; |
216 return true; | 222 return true; |
217 } | 223 } |
218 | 224 |
219 void ToggleImageButton::GetAccessibleState(ui::AccessibleViewState* state) { | 225 void ToggleImageButton::GetAccessibleState(ui::AccessibleViewState* state) { |
220 ImageButton::GetAccessibleState(state); | 226 ImageButton::GetAccessibleState(state); |
221 GetTooltipText(gfx::Point(), &state->name); | 227 GetTooltipText(gfx::Point(), &state->name); |
222 } | 228 } |
223 | 229 |
224 } // namespace views | 230 } // namespace views |
OLD | NEW |