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 "ui/base/accessibility/accessible_view_state.h" | 11 #include "ui/base/accessibility/accessible_view_state.h" |
12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/compositor/layer.h" | 13 #include "ui/gfx/compositor/layer.h" |
14 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" | 14 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" |
15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 16 #include "ui/gfx/skbitmap_operations.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/views/controls/image_view.h" | 18 #include "ui/views/controls/image_view.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 const int kBarHeight = 3; | 21 const int kBarHeight = 3; |
21 const int kBarSpacing = 5; | 22 const int kBarSpacing = 5; |
22 const int kIconHeight = 32; | 23 const int kIconHeight = 32; |
23 const int kIconWidth = 48; | 24 const int kIconWidth = 48; |
24 const int kHopSpacing = 2; | 25 const int kHopSpacing = 2; |
25 const int kActiveBarColor = 0xe6ffffff; | 26 const int kActiveBarColor = 0xe6ffffff; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 state_(STATE_NORMAL) { | 73 state_(STATE_NORMAL) { |
73 set_accessibility_focusable(true); | 74 set_accessibility_focusable(true); |
74 bar_->SetHorizontalAlignment(views::ImageView::CENTER); | 75 bar_->SetHorizontalAlignment(views::ImageView::CENTER); |
75 bar_->SetVerticalAlignment(views::ImageView::TRAILING); | 76 bar_->SetVerticalAlignment(views::ImageView::TRAILING); |
76 AddChildView(bar_); | 77 AddChildView(bar_); |
77 } | 78 } |
78 | 79 |
79 LauncherButton::~LauncherButton() { | 80 LauncherButton::~LauncherButton() { |
80 } | 81 } |
81 | 82 |
| 83 void LauncherButton::SetShadowedImage(const SkBitmap& bitmap) { |
| 84 const SkColor kShadowColor[] = { |
| 85 SkColorSetARGB(0x1A, 0, 0, 0), |
| 86 SkColorSetARGB(0x1A, 0, 0, 0), |
| 87 SkColorSetARGB(0x54, 0, 0, 0), |
| 88 }; |
| 89 const gfx::Point kShadowOffset[] = { |
| 90 gfx::Point(0, 2), |
| 91 gfx::Point(0, 3), |
| 92 gfx::Point(0, 0), |
| 93 }; |
| 94 const SkScalar kShadowRadius[] = { |
| 95 SkIntToScalar(0), |
| 96 SkIntToScalar(1), |
| 97 SkIntToScalar(1), |
| 98 }; |
| 99 |
| 100 SkBitmap shadowed_bitmap = SkBitmapOperations::CreateDropShadow( |
| 101 bitmap, |
| 102 arraysize(kShadowColor) - 1, |
| 103 kShadowColor, |
| 104 kShadowOffset, |
| 105 kShadowRadius); |
| 106 icon_view_->SetImage(shadowed_bitmap); |
| 107 } |
| 108 |
82 void LauncherButton::SetImage(const SkBitmap& image) { | 109 void LauncherButton::SetImage(const SkBitmap& image) { |
83 if (image.empty()) { | 110 if (image.empty()) { |
84 // TODO: need an empty image. | 111 // TODO: need an empty image. |
85 icon_view_->SetImage(&image); | 112 icon_view_->SetImage(&image); |
86 return; | 113 return; |
87 } | 114 } |
88 | 115 |
89 if (icon_view_->icon_size() == 0) { | 116 if (icon_view_->icon_size() == 0) { |
90 icon_view_->SetImage(&image); | 117 SetShadowedImage(image); |
91 return; | 118 return; |
92 } | 119 } |
93 | 120 |
94 // Resize the image maintaining our aspect ratio. | 121 // Resize the image maintaining our aspect ratio. |
95 int pref = icon_view_->icon_size(); | 122 int pref = icon_view_->icon_size(); |
96 float aspect_ratio = | 123 float aspect_ratio = |
97 static_cast<float>(image.width()) / static_cast<float>(image.height()); | 124 static_cast<float>(image.width()) / static_cast<float>(image.height()); |
98 int height = pref; | 125 int height = pref; |
99 int width = static_cast<int>(aspect_ratio * height); | 126 int width = static_cast<int>(aspect_ratio * height); |
100 if (width > pref) { | 127 if (width > pref) { |
101 width = pref; | 128 width = pref; |
102 height = static_cast<int>(width / aspect_ratio); | 129 height = static_cast<int>(width / aspect_ratio); |
103 } | 130 } |
| 131 |
104 if (width == image.width() && height == image.height()) { | 132 if (width == image.width() && height == image.height()) { |
105 icon_view_->SetImage(&image); | 133 SetShadowedImage(image); |
106 return; | 134 return; |
107 } | 135 } |
108 gfx::Canvas canvas(gfx::Size(width, height), false); | 136 |
109 canvas.DrawBitmapInt(image, 0, 0, image.width(), image.height(), | 137 SkBitmap resized_image = SkBitmapOperations::CreateResizedBitmap( |
110 0, 0, width, height, false); | 138 image, gfx::Size(width, height)); |
111 SkBitmap resized_image(canvas.ExtractBitmap()); | 139 SetShadowedImage(resized_image); |
112 icon_view_->SetImage(&resized_image); | |
113 } | 140 } |
114 | 141 |
115 void LauncherButton::AddState(State state) { | 142 void LauncherButton::AddState(State state) { |
116 if (!(state_ & state)) { | 143 if (!(state_ & state)) { |
117 if (ShouldHop(state) || !ShouldHop(state_)) { | 144 if (ShouldHop(state) || !ShouldHop(state_)) { |
118 ui::ScopedLayerAnimationSettings scoped_setter( | 145 ui::ScopedLayerAnimationSettings scoped_setter( |
119 icon_view_->layer()->GetAnimator()); | 146 icon_view_->layer()->GetAnimator()); |
120 scoped_setter.SetTransitionDuration( | 147 scoped_setter.SetTransitionDuration( |
121 base::TimeDelta::FromMilliseconds(kHopUpMS)); | 148 base::TimeDelta::FromMilliseconds(kHopUpMS)); |
122 state_ |= state; | 149 state_ |= state; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_RUNNING; | 265 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_RUNNING; |
239 | 266 |
240 bar_->SetImage(rb.GetImageNamed(bar_id).ToSkBitmap()); | 267 bar_->SetImage(rb.GetImageNamed(bar_id).ToSkBitmap()); |
241 } | 268 } |
242 | 269 |
243 Layout(); | 270 Layout(); |
244 SchedulePaint(); | 271 SchedulePaint(); |
245 } | 272 } |
246 } // namespace internal | 273 } // namespace internal |
247 } // namespace ash | 274 } // namespace ash |
OLD | NEW |