Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: ash/launcher/launcher_button.cc

Issue 10453035: Clean up SkBitmapOperations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/app_list/app_list_item_view.cc » ('j') | ui/app_list/app_list_item_view.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
9 #include "ash/launcher/launcher_button_host.h" 10 #include "ash/launcher/launcher_button_host.h"
10 #include "grit/ui_resources.h" 11 #include "grit/ui_resources.h"
12 #include "skia/ext/image_operations.h"
11 #include "ui/base/accessibility/accessible_view_state.h" 13 #include "ui/base/accessibility/accessible_view_state.h"
12 #include "ui/base/animation/animation_delegate.h" 14 #include "ui/base/animation/animation_delegate.h"
13 #include "ui/base/animation/throb_animation.h" 15 #include "ui/base/animation/throb_animation.h"
14 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/compositor/layer.h" 17 #include "ui/compositor/layer.h"
16 #include "ui/compositor/scoped_layer_animation_settings.h" 18 #include "ui/compositor/scoped_layer_animation_settings.h"
17 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
21 #include "ui/gfx/shadow_value.h"
19 #include "ui/gfx/skbitmap_operations.h" 22 #include "ui/gfx/skbitmap_operations.h"
20 #include "ui/views/controls/image_view.h" 23 #include "ui/views/controls/image_view.h"
21 24
22 namespace { 25 namespace {
23 26
24 // Size of the bar. This is along the opposite axis of the shelf. For example, 27 // 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. 28 // if the shelf is aligned horizontally then this is the height of the bar.
26 const int kBarSize = 3; 29 const int kBarSize = 3;
27 const int kBarSpacing = 5; 30 const int kBarSpacing = 5;
28 const int kIconSize = 32; 31 const int kIconSize = 32;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 bar_(new BarView), 119 bar_(new BarView),
117 state_(STATE_NORMAL) { 120 state_(STATE_NORMAL) {
118 set_accessibility_focusable(true); 121 set_accessibility_focusable(true);
119 AddChildView(bar_); 122 AddChildView(bar_);
120 } 123 }
121 124
122 LauncherButton::~LauncherButton() { 125 LauncherButton::~LauncherButton() {
123 } 126 }
124 127
125 void LauncherButton::SetShadowedImage(const SkBitmap& bitmap) { 128 void LauncherButton::SetShadowedImage(const SkBitmap& bitmap) {
126 const SkColor kShadowColor[] = { 129 const gfx::ShadowValue kShadows[] = {
127 SkColorSetARGB(0x1A, 0, 0, 0), 130 gfx::ShadowValue(gfx::Point(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)),
128 SkColorSetARGB(0x1A, 0, 0, 0), 131 gfx::ShadowValue(gfx::Point(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)),
129 SkColorSetARGB(0x54, 0, 0, 0), 132 gfx::ShadowValue(gfx::Point(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)),
130 }; 133 };
131 const gfx::Point kShadowOffset[] = { 134 const std::vector<gfx::ShadowValue> shadows(
132 gfx::Point(0, 2), 135 &kShadows[0],
133 gfx::Point(0, 3), 136 &kShadows[arraysize(kShadows)]);
134 gfx::Point(0, 0),
135 };
136 const SkScalar kShadowRadius[] = {
137 SkIntToScalar(0),
138 SkIntToScalar(1),
139 SkIntToScalar(1),
140 };
141 137
142 SkBitmap shadowed_bitmap = SkBitmapOperations::CreateDropShadow( 138 SkBitmap shadowed_bitmap = SkBitmapOperations::CreateDropShadow(
143 bitmap, 139 bitmap, shadows);
144 arraysize(kShadowColor) - 1,
145 kShadowColor,
146 kShadowOffset,
147 kShadowRadius);
148 icon_view_->SetImage(shadowed_bitmap); 140 icon_view_->SetImage(shadowed_bitmap);
149 } 141 }
150 142
151 void LauncherButton::SetImage(const SkBitmap& image) { 143 void LauncherButton::SetImage(const SkBitmap& image) {
152 if (image.empty()) { 144 if (image.empty()) {
153 // TODO: need an empty image. 145 // TODO: need an empty image.
154 icon_view_->SetImage(image); 146 icon_view_->SetImage(image);
155 return; 147 return;
156 } 148 }
157 149
(...skipping 11 matching lines...) Expand all
169 if (width > pref) { 161 if (width > pref) {
170 width = pref; 162 width = pref;
171 height = static_cast<int>(width / aspect_ratio); 163 height = static_cast<int>(width / aspect_ratio);
172 } 164 }
173 165
174 if (width == image.width() && height == image.height()) { 166 if (width == image.width() && height == image.height()) {
175 SetShadowedImage(image); 167 SetShadowedImage(image);
176 return; 168 return;
177 } 169 }
178 170
179 SkBitmap resized_image = SkBitmapOperations::CreateResizedBitmap( 171 SkBitmap resized_image = skia::ImageOperations::Resize(
180 image, gfx::Size(width, height)); 172 image, skia::ImageOperations::RESIZE_BEST, width, height);
181 SetShadowedImage(resized_image); 173 SetShadowedImage(resized_image);
182 } 174 }
183 175
184 void LauncherButton::AddState(State state) { 176 void LauncherButton::AddState(State state) {
185 if (!(state_ & state)) { 177 if (!(state_ & state)) {
186 if (ShouldHop(state) || !ShouldHop(state_)) { 178 if (ShouldHop(state) || !ShouldHop(state_)) {
187 ui::ScopedLayerAnimationSettings scoped_setter( 179 ui::ScopedLayerAnimationSettings scoped_setter(
188 icon_view_->layer()->GetAnimator()); 180 icon_view_->layer()->GetAnimator());
189 scoped_setter.SetTransitionDuration( 181 scoped_setter.SetTransitionDuration(
190 base::TimeDelta::FromMilliseconds(kHopUpMS)); 182 base::TimeDelta::FromMilliseconds(kHopUpMS));
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 views::ImageView::TRAILING); 345 views::ImageView::TRAILING);
354 bar_->SetVerticalAlignment(views::ImageView::CENTER); 346 bar_->SetVerticalAlignment(views::ImageView::CENTER);
355 break; 347 break;
356 } 348 }
357 349
358 Layout(); 350 Layout();
359 SchedulePaint(); 351 SchedulePaint();
360 } 352 }
361 } // namespace internal 353 } // namespace internal
362 } // namespace ash 354 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/app_list/app_list_item_view.cc » ('j') | ui/app_list/app_list_item_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698