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_sources.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 const gfx::ShadowValues shadows(kShadows, kShadows + arraysize(kShadows)); |
246 bitmap, gfx::ShadowValues(kShadows, kShadows + arraysize(kShadows))); | 245 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); |
247 icon_view_->SetImage(shadowed_bitmap); | 246 gfx::Size shadow_image_size = image.size(); |
247 shadow_image_size.Enlarge(shadow_padding.width(), | |
248 shadow_padding.height()); | |
249 | |
250 icon_view_->SetImage(gfx::ImageSkia( | |
251 gfx::image_skia_sources::CreateDropShadowSource(image, shadows), | |
252 shadow_image_size)); | |
oshima
2012/07/10 23:51:06
Can you move this to gfx::ImageSkiaOperations ? (u
xiyuan
2012/07/11 17:39:13
Done. Peter made a similar proposal. :)
| |
248 } | 253 } |
249 | 254 |
250 void LauncherButton::SetImage(const SkBitmap& image) { | 255 void LauncherButton::SetImage(const gfx::ImageSkia& image) { |
251 if (image.empty()) { | 256 if (image.empty()) { |
252 // TODO: need an empty image. | 257 // TODO: need an empty image. |
253 icon_view_->SetImage(image); | 258 icon_view_->SetImage(image); |
254 return; | 259 return; |
255 } | 260 } |
256 | 261 |
257 if (icon_view_->icon_size() == 0) { | 262 if (icon_view_->icon_size() == 0) { |
258 SetShadowedImage(image); | 263 SetShadowedImage(image); |
259 return; | 264 return; |
260 } | 265 } |
261 | 266 |
262 // Resize the image maintaining our aspect ratio. | 267 // Resize the image maintaining our aspect ratio. |
263 int pref = icon_view_->icon_size(); | 268 int pref = icon_view_->icon_size(); |
264 float aspect_ratio = | 269 float aspect_ratio = |
265 static_cast<float>(image.width()) / static_cast<float>(image.height()); | 270 static_cast<float>(image.width()) / static_cast<float>(image.height()); |
266 int height = pref; | 271 int height = pref; |
267 int width = static_cast<int>(aspect_ratio * height); | 272 int width = static_cast<int>(aspect_ratio * height); |
268 if (width > pref) { | 273 if (width > pref) { |
269 width = pref; | 274 width = pref; |
270 height = static_cast<int>(width / aspect_ratio); | 275 height = static_cast<int>(width / aspect_ratio); |
271 } | 276 } |
272 | 277 |
273 if (width == image.width() && height == image.height()) { | 278 if (width == image.width() && height == image.height()) { |
274 SetShadowedImage(image); | 279 SetShadowedImage(image); |
275 return; | 280 return; |
276 } | 281 } |
277 | 282 |
278 SkBitmap resized_image = skia::ImageOperations::Resize( | 283 const gfx::Size size(width, height); |
279 image, skia::ImageOperations::RESIZE_BEST, width, height); | 284 SetShadowedImage(gfx::ImageSkia( |
280 SetShadowedImage(resized_image); | 285 gfx::image_skia_sources::CreateResizeSource(image, size), |
286 size)); | |
281 } | 287 } |
282 | 288 |
283 void LauncherButton::AddState(State state) { | 289 void LauncherButton::AddState(State state) { |
284 if (!(state_ & state)) { | 290 if (!(state_ & state)) { |
285 if (ShouldHop(state) || !ShouldHop(state_)) { | 291 if (ShouldHop(state) || !ShouldHop(state_)) { |
286 ui::ScopedLayerAnimationSettings scoped_setter( | 292 ui::ScopedLayerAnimationSettings scoped_setter( |
287 icon_view_->layer()->GetAnimator()); | 293 icon_view_->layer()->GetAnimator()); |
288 scoped_setter.SetTransitionDuration( | 294 scoped_setter.SetTransitionDuration( |
289 base::TimeDelta::FromMilliseconds(kHopUpMS)); | 295 base::TimeDelta::FromMilliseconds(kHopUpMS)); |
290 state_ |= state; | 296 state_ |= state; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 bar_->SetVerticalAlignment(views::ImageView::CENTER); | 471 bar_->SetVerticalAlignment(views::ImageView::CENTER); |
466 break; | 472 break; |
467 } | 473 } |
468 | 474 |
469 Layout(); | 475 Layout(); |
470 SchedulePaint(); | 476 SchedulePaint(); |
471 } | 477 } |
472 | 478 |
473 } // namespace internal | 479 } // namespace internal |
474 } // namespace ash | 480 } // namespace ash |
OLD | NEW |