| 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" |
| 24 #include "ui/gfx/shadow_value.h" | 23 #include "ui/gfx/shadow_value.h" |
| 25 #include "ui/gfx/skbitmap_operations.h" | |
| 26 #include "ui/gfx/transform_util.h" | 24 #include "ui/gfx/transform_util.h" |
| 27 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
| 28 | 26 |
| 29 namespace { | 27 namespace { |
| 30 | 28 |
| 31 // Size of the bar. This is along the opposite axis of the shelf. For example, | 29 // 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. | 30 // if the shelf is aligned horizontally then this is the height of the bar. |
| 33 const int kBarSize = 3; | 31 const int kBarSize = 3; |
| 34 const int kBarSpacing = 5; | 32 const int kBarSpacing = 5; |
| 35 const int kIconSize = 32; | 33 const int kIconSize = 32; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 icon_view_(NULL), | 226 icon_view_(NULL), |
| 229 bar_(new BarView), | 227 bar_(new BarView), |
| 230 state_(STATE_NORMAL) { | 228 state_(STATE_NORMAL) { |
| 231 set_accessibility_focusable(true); | 229 set_accessibility_focusable(true); |
| 232 AddChildView(bar_); | 230 AddChildView(bar_); |
| 233 } | 231 } |
| 234 | 232 |
| 235 LauncherButton::~LauncherButton() { | 233 LauncherButton::~LauncherButton() { |
| 236 } | 234 } |
| 237 | 235 |
| 238 void LauncherButton::SetShadowedImage(const SkBitmap& bitmap) { | 236 void LauncherButton::SetShadowedImage(const gfx::ImageSkia& image) { |
| 239 const gfx::ShadowValue kShadows[] = { | 237 const gfx::ShadowValue kShadows[] = { |
| 240 gfx::ShadowValue(gfx::Point(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), | 238 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)), | 239 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)), | 240 gfx::ShadowValue(gfx::Point(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), |
| 243 }; | 241 }; |
| 244 | 242 |
| 245 SkBitmap shadowed_bitmap = SkBitmapOperations::CreateDropShadow( | 243 gfx::ImageSkia shadowed_bitmap = image.CreateDropShadow( |
| 246 bitmap, gfx::ShadowValues(kShadows, kShadows + arraysize(kShadows))); | 244 gfx::ShadowValues(kShadows, kShadows + arraysize(kShadows))); |
| 247 icon_view_->SetImage(shadowed_bitmap); | 245 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 gfx::ImageSkia resized_image = image.Resize(gfx::Size(width, height)); |
| 279 image, skia::ImageOperations::RESIZE_BEST, width, height); | |
| 280 SetShadowedImage(resized_image); | 277 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)); |
| (...skipping 175 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 |