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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "ui/base/animation/throb_animation.h" | 8 #include "ui/base/animation/throb_animation.h" |
9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
10 #include "ui/gfx/skbitmap_operations.h" | 10 #include "ui/gfx/skbitmap_operations.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 preferred_size_(kDefaultWidth, kDefaultHeight) { | 24 preferred_size_(kDefaultWidth, kDefaultHeight) { |
25 // By default, we request that the gfx::Canvas passed to our View::OnPaint() | 25 // By default, we request that the gfx::Canvas passed to our View::OnPaint() |
26 // implementation is flipped horizontally so that the button's bitmaps are | 26 // implementation is flipped horizontally so that the button's bitmaps are |
27 // mirrored when the UI directionality is right-to-left. | 27 // mirrored when the UI directionality is right-to-left. |
28 EnableCanvasFlippingForRTLUI(true); | 28 EnableCanvasFlippingForRTLUI(true); |
29 } | 29 } |
30 | 30 |
31 ImageButton::~ImageButton() { | 31 ImageButton::~ImageButton() { |
32 } | 32 } |
33 | 33 |
34 void ImageButton::SetImage(ButtonState state, const SkBitmap* image) { | 34 void ImageButton::SetImage(ButtonState state, const gfx::ImageSkia* image) { |
35 images_[state] = image ? *image : SkBitmap(); | 35 images_[state] = image ? *image : gfx::ImageSkia(); |
36 PreferredSizeChanged(); | 36 PreferredSizeChanged(); |
37 } | 37 } |
38 | 38 |
39 void ImageButton::SetBackground(SkColor color, | 39 void ImageButton::SetBackground(SkColor color, |
40 const SkBitmap* image, | 40 const gfx::ImageSkia* image, |
41 const SkBitmap* mask) { | 41 const gfx::ImageSkia* mask) { |
42 if (!image || !mask) { | 42 if (!image || !mask) { |
43 background_image_.reset(); | 43 background_image_.reset(); |
44 return; | 44 return; |
45 } | 45 } |
46 | 46 |
47 background_image_ = | 47 background_image_ = |
48 SkBitmapOperations::CreateButtonBackground(color, *image, *mask); | 48 SkBitmapOperations::CreateButtonBackground(color, *image, *mask); |
49 } | 49 } |
50 | 50 |
51 void ImageButton::SetOverlayImage(const SkBitmap* image) { | 51 void ImageButton::SetOverlayImage(const SkBitmap* image) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 for (int i = 0; i < BS_COUNT; ++i) { | 136 for (int i = 0; i < BS_COUNT; ++i) { |
137 SkBitmap temp = images_[i]; | 137 SkBitmap temp = images_[i]; |
138 images_[i] = alternate_images_[i]; | 138 images_[i] = alternate_images_[i]; |
139 alternate_images_[i] = temp; | 139 alternate_images_[i] = temp; |
140 } | 140 } |
141 toggled_ = toggled; | 141 toggled_ = toggled; |
142 SchedulePaint(); | 142 SchedulePaint(); |
143 } | 143 } |
144 | 144 |
145 void ToggleImageButton::SetToggledImage(ButtonState state, | 145 void ToggleImageButton::SetToggledImage(ButtonState state, |
146 const SkBitmap* image) { | 146 const gfx::ImageSkia* image) { |
147 if (toggled_) { | 147 if (toggled_) { |
148 images_[state] = image ? *image : SkBitmap(); | 148 images_[state] = image ? *image : gfx::ImageSkia(); |
149 if (state_ == state) | 149 if (state_ == state) |
150 SchedulePaint(); | 150 SchedulePaint(); |
151 } else { | 151 } else { |
152 alternate_images_[state] = image ? *image : SkBitmap(); | 152 alternate_images_[state] = image ? *image : gfx::ImageSkia(); |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 void ToggleImageButton::SetToggledTooltipText(const string16& tooltip) { | 156 void ToggleImageButton::SetToggledTooltipText(const string16& tooltip) { |
157 toggled_tooltip_text_ = tooltip; | 157 toggled_tooltip_text_ = tooltip; |
158 } | 158 } |
159 | 159 |
160 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
161 // ToggleImageButton, ImageButton overrides: | 161 // ToggleImageButton, ImageButton overrides: |
162 | 162 |
163 void ToggleImageButton::SetImage(ButtonState state, const SkBitmap* image) { | 163 void ToggleImageButton::SetImage(ButtonState state, |
| 164 const gfx::ImageSkia* image) { |
164 if (toggled_) { | 165 if (toggled_) { |
165 alternate_images_[state] = image ? *image : SkBitmap(); | 166 alternate_images_[state] = image ? *image : gfx::ImageSkia(); |
166 } else { | 167 } else { |
167 images_[state] = image ? *image : SkBitmap(); | 168 images_[state] = image ? *image : gfx::ImageSkia(); |
168 if (state_ == state) | 169 if (state_ == state) |
169 SchedulePaint(); | 170 SchedulePaint(); |
170 } | 171 } |
171 PreferredSizeChanged(); | 172 PreferredSizeChanged(); |
172 } | 173 } |
173 | 174 |
174 //////////////////////////////////////////////////////////////////////////////// | 175 //////////////////////////////////////////////////////////////////////////////// |
175 // ToggleImageButton, View overrides: | 176 // ToggleImageButton, View overrides: |
176 | 177 |
177 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, | 178 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, |
178 string16* tooltip) const { | 179 string16* tooltip) const { |
179 if (!toggled_ || toggled_tooltip_text_.empty()) | 180 if (!toggled_ || toggled_tooltip_text_.empty()) |
180 return Button::GetTooltipText(p, tooltip); | 181 return Button::GetTooltipText(p, tooltip); |
181 | 182 |
182 *tooltip = toggled_tooltip_text_; | 183 *tooltip = toggled_tooltip_text_; |
183 return true; | 184 return true; |
184 } | 185 } |
185 | 186 |
186 } // namespace views | 187 } // namespace views |
OLD | NEW |