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 "ash/launcher/launcher_button.h" | 5 #include "ash/launcher/launcher_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/launcher/launcher_button_host.h" | 10 #include "ash/launcher/launcher_button_host.h" |
11 #include "grit/ui_resources.h" | 11 #include "grit/ui_resources.h" |
12 #include "skia/ext/image_operations.h" | |
13 #include "ui/base/accessibility/accessible_view_state.h" | 12 #include "ui/base/accessibility/accessible_view_state.h" |
14 #include "ui/base/animation/animation_delegate.h" | 13 #include "ui/base/animation/animation_delegate.h" |
15 #include "ui/base/animation/throb_animation.h" | 14 #include "ui/base/animation/throb_animation.h" |
16 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/compositor/layer.h" | 16 #include "ui/compositor/layer.h" |
18 #include "ui/compositor/layer_animation_element.h" | 17 #include "ui/compositor/layer_animation_element.h" |
19 #include "ui/compositor/layer_animation_observer.h" | 18 #include "ui/compositor/layer_animation_observer.h" |
20 #include "ui/compositor/layer_animation_sequence.h" | 19 #include "ui/compositor/layer_animation_sequence.h" |
21 #include "ui/compositor/scoped_layer_animation_settings.h" | 20 #include "ui/compositor/scoped_layer_animation_settings.h" |
22 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
23 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
23 #include "ui/gfx/image/image_skia_operations.h" | |
24 #include "ui/gfx/shadow_value.h" | 24 #include "ui/gfx/shadow_value.h" |
25 #include "ui/gfx/skbitmap_operations.h" | |
26 #include "ui/gfx/transform_util.h" | 25 #include "ui/gfx/transform_util.h" |
27 #include "ui/views/controls/image_view.h" | 26 #include "ui/views/controls/image_view.h" |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 // Size of the bar. This is along the opposite axis of the shelf. For example, | 30 // Size of the bar. This is along the opposite axis of the shelf. For example, |
32 // if the shelf is aligned horizontally then this is the height of the bar. | 31 // if the shelf is aligned horizontally then this is the height of the bar. |
33 const int kBarSize = 3; | 32 const int kBarSize = 3; |
34 const int kBarSpacing = 5; | 33 const int kBarSpacing = 5; |
35 const int kIconSize = 32; | 34 const int kIconSize = 32; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 icon_view_(NULL), | 227 icon_view_(NULL), |
229 bar_(new BarView), | 228 bar_(new BarView), |
230 state_(STATE_NORMAL) { | 229 state_(STATE_NORMAL) { |
231 set_accessibility_focusable(true); | 230 set_accessibility_focusable(true); |
232 AddChildView(bar_); | 231 AddChildView(bar_); |
233 } | 232 } |
234 | 233 |
235 LauncherButton::~LauncherButton() { | 234 LauncherButton::~LauncherButton() { |
236 } | 235 } |
237 | 236 |
238 void LauncherButton::SetShadowedImage(const SkBitmap& bitmap) { | 237 void LauncherButton::SetShadowedImage(const gfx::ImageSkia& image) { |
239 const gfx::ShadowValue kShadows[] = { | 238 const gfx::ShadowValue kShadows[] = { |
240 gfx::ShadowValue(gfx::Point(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), | 239 gfx::ShadowValue(gfx::Point(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), |
241 gfx::ShadowValue(gfx::Point(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), | 240 gfx::ShadowValue(gfx::Point(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), |
242 gfx::ShadowValue(gfx::Point(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), | 241 gfx::ShadowValue(gfx::Point(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), |
243 }; | 242 }; |
244 | 243 |
245 SkBitmap shadowed_bitmap = SkBitmapOperations::CreateDropShadow( | 244 icon_view_->SetImage(gfx::ImageSkiaOperations::CreateDropShadowImage( |
pkotwicz
2012/07/12 00:18:24
Nit: if you want, can you rename this method to Im
xiyuan
2012/07/12 16:52:23
Done.
| |
246 bitmap, gfx::ShadowValues(kShadows, kShadows + arraysize(kShadows))); | 245 image, gfx::ShadowValues(kShadows, kShadows + arraysize(kShadows)))); |
247 icon_view_->SetImage(shadowed_bitmap); | |
248 } | 246 } |
249 | 247 |
250 void LauncherButton::SetImage(const SkBitmap& image) { | 248 void LauncherButton::SetImage(const gfx::ImageSkia& image) { |
251 if (image.empty()) { | 249 if (image.empty()) { |
252 // TODO: need an empty image. | 250 // TODO: need an empty image. |
253 icon_view_->SetImage(image); | 251 icon_view_->SetImage(image); |
254 return; | 252 return; |
255 } | 253 } |
256 | 254 |
257 if (icon_view_->icon_size() == 0) { | 255 if (icon_view_->icon_size() == 0) { |
258 SetShadowedImage(image); | 256 SetShadowedImage(image); |
259 return; | 257 return; |
260 } | 258 } |
261 | 259 |
262 // Resize the image maintaining our aspect ratio. | 260 // Resize the image maintaining our aspect ratio. |
263 int pref = icon_view_->icon_size(); | 261 int pref = icon_view_->icon_size(); |
264 float aspect_ratio = | 262 float aspect_ratio = |
265 static_cast<float>(image.width()) / static_cast<float>(image.height()); | 263 static_cast<float>(image.width()) / static_cast<float>(image.height()); |
266 int height = pref; | 264 int height = pref; |
267 int width = static_cast<int>(aspect_ratio * height); | 265 int width = static_cast<int>(aspect_ratio * height); |
268 if (width > pref) { | 266 if (width > pref) { |
269 width = pref; | 267 width = pref; |
270 height = static_cast<int>(width / aspect_ratio); | 268 height = static_cast<int>(width / aspect_ratio); |
271 } | 269 } |
272 | 270 |
273 if (width == image.width() && height == image.height()) { | 271 if (width == image.width() && height == image.height()) { |
274 SetShadowedImage(image); | 272 SetShadowedImage(image); |
275 return; | 273 return; |
276 } | 274 } |
277 | 275 |
278 SkBitmap resized_image = skia::ImageOperations::Resize( | 276 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage( |
279 image, skia::ImageOperations::RESIZE_BEST, width, height); | 277 image, gfx::Size(width, height))); |
280 SetShadowedImage(resized_image); | |
281 } | 278 } |
282 | 279 |
283 void LauncherButton::AddState(State state) { | 280 void LauncherButton::AddState(State state) { |
284 if (!(state_ & state)) { | 281 if (!(state_ & state)) { |
285 if (ShouldHop(state) || !ShouldHop(state_)) { | 282 if (ShouldHop(state) || !ShouldHop(state_)) { |
286 ui::ScopedLayerAnimationSettings scoped_setter( | 283 ui::ScopedLayerAnimationSettings scoped_setter( |
287 icon_view_->layer()->GetAnimator()); | 284 icon_view_->layer()->GetAnimator()); |
288 scoped_setter.SetTransitionDuration( | 285 scoped_setter.SetTransitionDuration( |
289 base::TimeDelta::FromMilliseconds(kHopUpMS)); | 286 base::TimeDelta::FromMilliseconds(kHopUpMS)); |
290 state_ |= state; | 287 state_ |= state; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 bar_->SetVerticalAlignment(views::ImageView::CENTER); | 462 bar_->SetVerticalAlignment(views::ImageView::CENTER); |
466 break; | 463 break; |
467 } | 464 } |
468 | 465 |
469 Layout(); | 466 Layout(); |
470 SchedulePaint(); | 467 SchedulePaint(); |
471 } | 468 } |
472 | 469 |
473 } // namespace internal | 470 } // namespace internal |
474 } // namespace ash | 471 } // namespace ash |
OLD | NEW |