| 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 | 8 |
| 9 #include "ash/launcher/launcher_button_host.h" | 9 #include "ash/launcher/launcher_button_host.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| 11 #include "skia/ext/image_operations.h" |
| 11 #include "ui/base/accessibility/accessible_view_state.h" | 12 #include "ui/base/accessibility/accessible_view_state.h" |
| 12 #include "ui/base/animation/animation_delegate.h" | 13 #include "ui/base/animation/animation_delegate.h" |
| 13 #include "ui/base/animation/throb_animation.h" | 14 #include "ui/base/animation/throb_animation.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/compositor/layer.h" | 16 #include "ui/compositor/layer.h" |
| 16 #include "ui/compositor/scoped_layer_animation_settings.h" | 17 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 17 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 20 #include "ui/gfx/shadow_value.h" |
| 19 #include "ui/gfx/skbitmap_operations.h" | 21 #include "ui/gfx/skbitmap_operations.h" |
| 20 #include "ui/views/controls/image_view.h" | 22 #include "ui/views/controls/image_view.h" |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 // Size of the bar. This is along the opposite axis of the shelf. For example, | 26 // Size of the bar. This is along the opposite axis of the shelf. For example, |
| 25 // if the shelf is aligned horizontally then this is the height of the bar. | 27 // if the shelf is aligned horizontally then this is the height of the bar. |
| 26 const int kBarSize = 3; | 28 const int kBarSize = 3; |
| 27 const int kBarSpacing = 5; | 29 const int kBarSpacing = 5; |
| 28 const int kIconSize = 32; | 30 const int kIconSize = 32; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 bar_(new BarView), | 118 bar_(new BarView), |
| 117 state_(STATE_NORMAL) { | 119 state_(STATE_NORMAL) { |
| 118 set_accessibility_focusable(true); | 120 set_accessibility_focusable(true); |
| 119 AddChildView(bar_); | 121 AddChildView(bar_); |
| 120 } | 122 } |
| 121 | 123 |
| 122 LauncherButton::~LauncherButton() { | 124 LauncherButton::~LauncherButton() { |
| 123 } | 125 } |
| 124 | 126 |
| 125 void LauncherButton::SetShadowedImage(const SkBitmap& bitmap) { | 127 void LauncherButton::SetShadowedImage(const SkBitmap& bitmap) { |
| 126 const SkColor kShadowColor[] = { | 128 const gfx::ShadowValue kShadows[] = { |
| 127 SkColorSetARGB(0x1A, 0, 0, 0), | 129 gfx::ShadowValue(gfx::Point(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), |
| 128 SkColorSetARGB(0x1A, 0, 0, 0), | 130 gfx::ShadowValue(gfx::Point(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), |
| 129 SkColorSetARGB(0x54, 0, 0, 0), | 131 gfx::ShadowValue(gfx::Point(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), |
| 130 }; | |
| 131 const gfx::Point kShadowOffset[] = { | |
| 132 gfx::Point(0, 2), | |
| 133 gfx::Point(0, 3), | |
| 134 gfx::Point(0, 0), | |
| 135 }; | |
| 136 const SkScalar kShadowRadius[] = { | |
| 137 SkIntToScalar(0), | |
| 138 SkIntToScalar(1), | |
| 139 SkIntToScalar(1), | |
| 140 }; | 132 }; |
| 141 | 133 |
| 142 SkBitmap shadowed_bitmap = SkBitmapOperations::CreateDropShadow( | 134 SkBitmap shadowed_bitmap = SkBitmapOperations::CreateDropShadow( |
| 143 bitmap, | 135 bitmap, gfx::ShadowValues(kShadows, kShadows + arraysize(kShadows))); |
| 144 arraysize(kShadowColor) - 1, | |
| 145 kShadowColor, | |
| 146 kShadowOffset, | |
| 147 kShadowRadius); | |
| 148 icon_view_->SetImage(shadowed_bitmap); | 136 icon_view_->SetImage(shadowed_bitmap); |
| 149 } | 137 } |
| 150 | 138 |
| 151 void LauncherButton::SetImage(const SkBitmap& image) { | 139 void LauncherButton::SetImage(const SkBitmap& image) { |
| 152 if (image.empty()) { | 140 if (image.empty()) { |
| 153 // TODO: need an empty image. | 141 // TODO: need an empty image. |
| 154 icon_view_->SetImage(image); | 142 icon_view_->SetImage(image); |
| 155 return; | 143 return; |
| 156 } | 144 } |
| 157 | 145 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 169 if (width > pref) { | 157 if (width > pref) { |
| 170 width = pref; | 158 width = pref; |
| 171 height = static_cast<int>(width / aspect_ratio); | 159 height = static_cast<int>(width / aspect_ratio); |
| 172 } | 160 } |
| 173 | 161 |
| 174 if (width == image.width() && height == image.height()) { | 162 if (width == image.width() && height == image.height()) { |
| 175 SetShadowedImage(image); | 163 SetShadowedImage(image); |
| 176 return; | 164 return; |
| 177 } | 165 } |
| 178 | 166 |
| 179 SkBitmap resized_image = SkBitmapOperations::CreateResizedBitmap( | 167 SkBitmap resized_image = skia::ImageOperations::Resize( |
| 180 image, gfx::Size(width, height)); | 168 image, skia::ImageOperations::RESIZE_BEST, width, height); |
| 181 SetShadowedImage(resized_image); | 169 SetShadowedImage(resized_image); |
| 182 } | 170 } |
| 183 | 171 |
| 184 void LauncherButton::AddState(State state) { | 172 void LauncherButton::AddState(State state) { |
| 185 if (!(state_ & state)) { | 173 if (!(state_ & state)) { |
| 186 if (ShouldHop(state) || !ShouldHop(state_)) { | 174 if (ShouldHop(state) || !ShouldHop(state_)) { |
| 187 ui::ScopedLayerAnimationSettings scoped_setter( | 175 ui::ScopedLayerAnimationSettings scoped_setter( |
| 188 icon_view_->layer()->GetAnimator()); | 176 icon_view_->layer()->GetAnimator()); |
| 189 scoped_setter.SetTransitionDuration( | 177 scoped_setter.SetTransitionDuration( |
| 190 base::TimeDelta::FromMilliseconds(kHopUpMS)); | 178 base::TimeDelta::FromMilliseconds(kHopUpMS)); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 views::ImageView::TRAILING); | 341 views::ImageView::TRAILING); |
| 354 bar_->SetVerticalAlignment(views::ImageView::CENTER); | 342 bar_->SetVerticalAlignment(views::ImageView::CENTER); |
| 355 break; | 343 break; |
| 356 } | 344 } |
| 357 | 345 |
| 358 Layout(); | 346 Layout(); |
| 359 SchedulePaint(); | 347 SchedulePaint(); |
| 360 } | 348 } |
| 361 } // namespace internal | 349 } // namespace internal |
| 362 } // namespace ash | 350 } // namespace ash |
| OLD | NEW |