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 "ui/app_list/app_list_item_view.h" | 5 #include "ui/app_list/app_list_item_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/synchronization/cancellation_flag.h" | 11 #include "base/synchronization/cancellation_flag.h" |
12 #include "base/threading/worker_pool.h" | 12 #include "base/threading/worker_pool.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "skia/ext/image_operations.h" | |
15 #include "ui/app_list/app_list_item_model.h" | 14 #include "ui/app_list/app_list_item_model.h" |
16 #include "ui/app_list/apps_grid_view.h" | 15 #include "ui/app_list/apps_grid_view.h" |
17 #include "ui/app_list/drop_shadow_label.h" | 16 #include "ui/app_list/drop_shadow_label.h" |
18 #include "ui/app_list/icon_cache.h" | 17 #include "ui/app_list/icon_cache.h" |
19 #include "ui/base/accessibility/accessible_view_state.h" | 18 #include "ui/base/accessibility/accessible_view_state.h" |
20 #include "ui/base/animation/throb_animation.h" | 19 #include "ui/base/animation/throb_animation.h" |
21 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
23 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
24 #include "ui/gfx/skbitmap_operations.h" | 23 #include "ui/gfx/image/image_skia_operations.h" |
| 24 #include "ui/gfx/screen.h" |
25 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
26 #include "ui/views/controls/menu/menu_item_view.h" | 26 #include "ui/views/controls/menu/menu_item_view.h" |
27 #include "ui/views/controls/menu/menu_model_adapter.h" | 27 #include "ui/views/controls/menu/menu_model_adapter.h" |
28 #include "ui/views/controls/menu/menu_runner.h" | 28 #include "ui/views/controls/menu/menu_runner.h" |
29 | 29 |
30 namespace app_list { | 30 namespace app_list { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const int kTopBottomPadding = 10; | 34 const int kTopBottomPadding = 10; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 // static | 81 // static |
82 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; | 82 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; |
83 | 83 |
84 // AppListItemView::IconOperation wraps background icon processing. | 84 // AppListItemView::IconOperation wraps background icon processing. |
85 class AppListItemView::IconOperation | 85 class AppListItemView::IconOperation |
86 : public base::RefCountedThreadSafe<AppListItemView::IconOperation> { | 86 : public base::RefCountedThreadSafe<AppListItemView::IconOperation> { |
87 public: | 87 public: |
88 IconOperation(const SkBitmap& bitmap, | 88 IconOperation(const gfx::ImageSkia& image, |
89 const gfx::Size& size, | 89 const gfx::Size& size, |
90 const gfx::ShadowValues& shadows) | 90 const gfx::ShadowValues& shadows) |
91 : bitmap_(bitmap), | 91 : image_(image), |
92 size_(size), | 92 size_(size), |
93 shadows_(shadows) { | 93 shadows_(shadows) { |
94 } | 94 } |
95 | 95 |
96 static void Run(scoped_refptr<IconOperation> op) { | 96 static void Run(scoped_refptr<IconOperation> op) { |
97 op->ResizeAndGenerateShadow(); | 97 op->ResizeAndGenerateShadow(); |
98 } | 98 } |
99 | 99 |
100 void ResizeAndGenerateShadow() { | 100 void ResizeAndGenerateShadow() { |
101 if (cancel_flag_.IsSet()) | 101 if (cancel_flag_.IsSet()) |
102 return; | 102 return; |
103 | 103 |
104 if (size_ != gfx::Size(bitmap_.width(), bitmap_.height())) { | 104 gfx::ImageSkia resized( |
105 bitmap_ = skia::ImageOperations::Resize(bitmap_, | 105 gfx::ImageSkiaOperations::CreateResizedImage(image_, size_)); |
106 skia::ImageOperations::RESIZE_BEST, size_.width(), size_.height()); | 106 gfx::ImageSkia shadow( |
107 } | 107 gfx::ImageSkiaOperations::CreateDropShadowImage(resized, shadows_)); |
108 | 108 |
109 if (cancel_flag_.IsSet()) | 109 // The following statement causes shadowed image being generated. |
110 return; | 110 image_ = shadow.GetRepresentation(gfx::Screen::IsDIPEnabled() ? |
111 | 111 ui::SCALE_FACTOR_200P : ui::SCALE_FACTOR_100P); |
112 bitmap_ = SkBitmapOperations::CreateDropShadow(bitmap_, shadows_); | |
113 } | 112 } |
114 | 113 |
115 void Cancel() { | 114 void Cancel() { |
116 cancel_flag_.Set(); | 115 cancel_flag_.Set(); |
117 } | 116 } |
118 | 117 |
119 const SkBitmap& bitmap() const { | 118 const gfx::ImageSkia& image() const { |
120 return bitmap_; | 119 return image_; |
121 } | 120 } |
122 | 121 |
123 private: | 122 private: |
124 friend class base::RefCountedThreadSafe<AppListItemView::IconOperation>; | 123 friend class base::RefCountedThreadSafe<AppListItemView::IconOperation>; |
125 ~IconOperation() {} | 124 ~IconOperation() {} |
126 | 125 |
127 base::CancellationFlag cancel_flag_; | 126 base::CancellationFlag cancel_flag_; |
128 | 127 |
129 SkBitmap bitmap_; | 128 gfx::ImageSkia image_; |
130 const gfx::Size size_; | 129 const gfx::Size size_; |
131 const gfx::ShadowValues shadows_; | 130 const gfx::ShadowValues shadows_; |
132 | 131 |
133 DISALLOW_COPY_AND_ASSIGN(IconOperation); | 132 DISALLOW_COPY_AND_ASSIGN(IconOperation); |
134 }; | 133 }; |
135 | 134 |
136 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, | 135 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, |
137 AppListItemModel* model, | 136 AppListItemModel* model, |
138 views::ButtonListener* listener) | 137 views::ButtonListener* listener) |
139 : CustomButton(listener), | 138 : CustomButton(listener), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 172 |
174 icon_size_ = size; | 173 icon_size_ = size; |
175 UpdateIcon(); | 174 UpdateIcon(); |
176 } | 175 } |
177 | 176 |
178 void AppListItemView::UpdateIcon() { | 177 void AppListItemView::UpdateIcon() { |
179 // Skip if |icon_size_| has not been determined. | 178 // Skip if |icon_size_| has not been determined. |
180 if (icon_size_.IsEmpty()) | 179 if (icon_size_.IsEmpty()) |
181 return; | 180 return; |
182 | 181 |
183 SkBitmap icon = model_->icon(); | 182 gfx::ImageSkia icon = model_->icon(); |
184 // Clear icon and bail out if model icon is empty. | 183 // Clear icon and bail out if model icon is empty. |
185 if (icon.empty()) { | 184 if (icon.empty()) { |
186 icon_->SetImage(NULL); | 185 icon_->SetImage(NULL); |
187 return; | 186 return; |
188 } | 187 } |
189 | 188 |
190 CancelPendingIconOperation(); | 189 CancelPendingIconOperation(); |
191 | 190 |
192 SkBitmap shadow; | 191 gfx::ImageSkia shadow; |
193 if (IconCache::GetInstance()->Get(icon, icon_size_, &shadow)) { | 192 if (IconCache::GetInstance()->Get(icon, icon_size_, &shadow)) { |
194 icon_->SetImage(shadow); | 193 icon_->SetImage(shadow); |
195 } else { | 194 } else { |
196 // Schedule resize and shadow generation. | 195 // Schedule resize and shadow generation. |
197 icon_op_ = new IconOperation(icon, icon_size_, icon_shadows_); | 196 icon_op_ = new IconOperation(icon, icon_size_, icon_shadows_); |
198 base::WorkerPool::PostTaskAndReply( | 197 base::WorkerPool::PostTaskAndReply( |
199 FROM_HERE, | 198 FROM_HERE, |
200 base::Bind(&IconOperation::Run, icon_op_), | 199 base::Bind(&IconOperation::Run, icon_op_), |
201 base::Bind(&AppListItemView::ApplyShadow, | 200 base::Bind(&AppListItemView::ApplyShadow, |
202 apply_shadow_factory_.GetWeakPtr(), | 201 apply_shadow_factory_.GetWeakPtr(), |
203 icon_op_), | 202 icon_op_), |
204 true /* task_is_slow */); | 203 true /* task_is_slow */); |
205 } | 204 } |
206 } | 205 } |
207 | 206 |
208 void AppListItemView::CancelPendingIconOperation() { | 207 void AppListItemView::CancelPendingIconOperation() { |
209 // Set canceled flag of previous request to skip unneeded processing. | 208 // Set canceled flag of previous request to skip unneeded processing. |
210 if (icon_op_.get()) | 209 if (icon_op_.get()) |
211 icon_op_->Cancel(); | 210 icon_op_->Cancel(); |
212 | 211 |
213 // Cancel reply callback for previous request. | 212 // Cancel reply callback for previous request. |
214 apply_shadow_factory_.InvalidateWeakPtrs(); | 213 apply_shadow_factory_.InvalidateWeakPtrs(); |
215 } | 214 } |
216 | 215 |
217 void AppListItemView::ApplyShadow(scoped_refptr<IconOperation> op) { | 216 void AppListItemView::ApplyShadow(scoped_refptr<IconOperation> op) { |
218 icon_->SetImage(op->bitmap()); | 217 icon_->SetImage(op->image()); |
219 IconCache::GetInstance()->Put(model_->icon(), icon_size_, op->bitmap()); | 218 IconCache::GetInstance()->Put(model_->icon(), icon_size_, op->image()); |
220 | 219 |
221 DCHECK(op.get() == icon_op_.get()); | 220 DCHECK(op.get() == icon_op_.get()); |
222 icon_op_ = NULL; | 221 icon_op_ = NULL; |
223 } | 222 } |
224 | 223 |
225 void AppListItemView::ItemIconChanged() { | 224 void AppListItemView::ItemIconChanged() { |
226 UpdateIcon(); | 225 UpdateIcon(); |
227 } | 226 } |
228 | 227 |
229 void AppListItemView::ItemTitleChanged() { | 228 void AppListItemView::ItemTitleChanged() { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 apps_grid_view_->SetSelectedItem(this); | 303 apps_grid_view_->SetSelectedItem(this); |
305 title_->SetEnabledColor(kTitleHoverColor); | 304 title_->SetEnabledColor(kTitleHoverColor); |
306 } else { | 305 } else { |
307 apps_grid_view_->ClearSelectedItem(this); | 306 apps_grid_view_->ClearSelectedItem(this); |
308 model_->SetHighlighted(false); | 307 model_->SetHighlighted(false); |
309 title_->SetEnabledColor(kTitleColor); | 308 title_->SetEnabledColor(kTitleColor); |
310 } | 309 } |
311 } | 310 } |
312 | 311 |
313 } // namespace app_list | 312 } // namespace app_list |
OLD | NEW |