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/views/app_list_item_view.h" | 5 #include "ui/app_list/views/app_list_item_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "grit/generated_resources.h" | |
11 #include "grit/theme_resources.h" | |
benwells
2013/02/12 07:55:17
Again, do we need generated resources here? I thou
koz (OOO until 15th September)
2013/02/12 08:20:11
Right you are. Done.
| |
10 #include "ui/app_list/app_list_item_model.h" | 12 #include "ui/app_list/app_list_item_model.h" |
11 #include "ui/app_list/views/apps_grid_view.h" | 13 #include "ui/app_list/views/apps_grid_view.h" |
12 #include "ui/base/accessibility/accessible_view_state.h" | 14 #include "ui/base/accessibility/accessible_view_state.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/font.h" | 20 #include "ui/gfx/font.h" |
19 #include "ui/gfx/image/image_skia_operations.h" | 21 #include "ui/gfx/image/image_skia_operations.h" |
20 #include "ui/gfx/transform_util.h" | 22 #include "ui/gfx/transform_util.h" |
21 #include "ui/views/controls/image_view.h" | 23 #include "ui/views/controls/image_view.h" |
22 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
23 #include "ui/views/controls/menu/menu_item_view.h" | 25 #include "ui/views/controls/menu/menu_item_view.h" |
24 #include "ui/views/controls/menu/menu_model_adapter.h" | 26 #include "ui/views/controls/menu/menu_model_adapter.h" |
25 #include "ui/views/controls/menu/menu_runner.h" | 27 #include "ui/views/controls/menu/menu_runner.h" |
26 | 28 |
27 namespace app_list { | 29 namespace app_list { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 const int kTopBottomPadding = 10; | 33 const int kTopBottomPadding = 10; |
32 const int kTopPadding = 20; | 34 const int kTopPadding = 20; |
33 const int kIconTitleSpacing = 7; | 35 const int kIconTitleSpacing = 7; |
34 const int kProgressBarHorizontalPadding = 8; | 36 const int kProgressBarHorizontalPadding = 12; |
35 const int kProgressBarVerticalPadding = 4; | 37 const int kProgressBarVerticalPadding = 4; |
36 const int kProgressBarHeight = 4; | 38 const int kProgressBarHeight = 4; |
37 | 39 |
38 const SkColor kTitleColor = SkColorSetRGB(0x5A, 0x5A, 0x5A); | 40 const SkColor kTitleColor = SkColorSetRGB(0x5A, 0x5A, 0x5A); |
39 const SkColor kTitleHoverColor = SkColorSetRGB(0x3C, 0x3C, 0x3C); | 41 const SkColor kTitleHoverColor = SkColorSetRGB(0x3C, 0x3C, 0x3C); |
40 | 42 |
41 const SkColor kHoverAndPushedColor = SkColorSetARGB(0x19, 0, 0, 0); | 43 const SkColor kHoverAndPushedColor = SkColorSetARGB(0x19, 0, 0, 0); |
42 const SkColor kSelectedColor = SkColorSetARGB(0x0D, 0, 0, 0); | 44 const SkColor kSelectedColor = SkColorSetARGB(0x0D, 0, 0, 0); |
43 const SkColor kHighlightedColor = kHoverAndPushedColor; | 45 const SkColor kHighlightedColor = kHoverAndPushedColor; |
44 const SkColor kDownloadProgressBackgroundColor = | 46 const SkColor kDownloadProgressBackgroundColor = |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 } | 172 } |
171 | 173 |
172 void AppListItemView::ItemHighlightedChanged() { | 174 void AppListItemView::ItemHighlightedChanged() { |
173 apps_grid_view_->EnsureViewVisible(this); | 175 apps_grid_view_->EnsureViewVisible(this); |
174 SchedulePaint(); | 176 SchedulePaint(); |
175 } | 177 } |
176 | 178 |
177 void AppListItemView::ItemIsInstallingChanged() { | 179 void AppListItemView::ItemIsInstallingChanged() { |
178 if (model_->is_installing()) | 180 if (model_->is_installing()) |
179 apps_grid_view_->EnsureViewVisible(this); | 181 apps_grid_view_->EnsureViewVisible(this); |
182 title_->SetVisible(!model_->is_installing()); | |
180 SchedulePaint(); | 183 SchedulePaint(); |
181 } | 184 } |
182 | 185 |
183 void AppListItemView::ItemPercentDownloadedChanged() { | 186 void AppListItemView::ItemPercentDownloadedChanged() { |
184 SchedulePaint(); | 187 SchedulePaint(); |
185 } | 188 } |
186 | 189 |
187 std::string AppListItemView::GetClassName() const { | 190 std::string AppListItemView::GetClassName() const { |
188 return kViewClassName; | 191 return kViewClassName; |
189 } | 192 } |
(...skipping 10 matching lines...) Expand all Loading... | |
200 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); | 203 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); |
201 icon_->SetBoundsRect(icon_bounds); | 204 icon_->SetBoundsRect(icon_bounds); |
202 | 205 |
203 const gfx::Size title_size = title_->GetPreferredSize(); | 206 const gfx::Size title_size = title_->GetPreferredSize(); |
204 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, | 207 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, |
205 y + icon_size_.height() + kIconTitleSpacing, | 208 y + icon_size_.height() + kIconTitleSpacing, |
206 title_size.width(), | 209 title_size.width(), |
207 title_size.height()); | 210 title_size.height()); |
208 title_bounds.Intersect(rect); | 211 title_bounds.Intersect(rect); |
209 title_->SetBoundsRect(title_bounds); | 212 title_->SetBoundsRect(title_bounds); |
213 title_->SetVisible(!model_->is_installing()); | |
210 } | 214 } |
211 | 215 |
212 void AppListItemView::OnPaint(gfx::Canvas* canvas) { | 216 void AppListItemView::OnPaint(gfx::Canvas* canvas) { |
213 if (apps_grid_view_->IsDraggedView(this)) | 217 if (apps_grid_view_->IsDraggedView(this)) |
214 return; | 218 return; |
215 | 219 |
216 gfx::Rect rect(GetContentsBounds()); | 220 gfx::Rect rect(GetContentsBounds()); |
217 | 221 |
218 if (model_->highlighted()) { | 222 if (model_->highlighted()) { |
219 canvas->FillRect(rect, kHighlightedColor); | 223 canvas->FillRect(rect, kHighlightedColor); |
220 } else if (hover_animation_->is_animating()) { | 224 } else if (hover_animation_->is_animating()) { |
221 int alpha = SkColorGetA(kHoverAndPushedColor) * | 225 int alpha = SkColorGetA(kHoverAndPushedColor) * |
222 hover_animation_->GetCurrentValue(); | 226 hover_animation_->GetCurrentValue(); |
223 canvas->FillRect(rect, SkColorSetA(kHoverAndPushedColor, alpha)); | 227 canvas->FillRect(rect, SkColorSetA(kHoverAndPushedColor, alpha)); |
224 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) { | 228 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) { |
225 canvas->FillRect(rect, kHoverAndPushedColor); | 229 canvas->FillRect(rect, kHoverAndPushedColor); |
226 } else if (apps_grid_view_->IsSelectedView(this)) { | 230 } else if (apps_grid_view_->IsSelectedView(this)) { |
227 canvas->FillRect(rect, kSelectedColor); | 231 canvas->FillRect(rect, kSelectedColor); |
228 } | 232 } |
229 | 233 |
230 if (model_->is_installing()) { | 234 if (model_->is_installing()) { |
231 gfx::Rect progress_bar_background( | 235 gfx::ImageSkia background = *ResourceBundle::GetSharedInstance(). |
232 rect.x() + kProgressBarHorizontalPadding, | 236 GetImageSkiaNamed(IDR_APP_LIST_ITEM_PROGRESS_BACKGROUND); |
233 rect.bottom() - kProgressBarVerticalPadding - kProgressBarHeight, | 237 gfx::ImageSkia left = *ResourceBundle::GetSharedInstance(). |
234 rect.width() - 2 * kProgressBarHorizontalPadding, | 238 GetImageSkiaNamed(IDR_APP_LIST_ITEM_PROGRESS_LEFT); |
235 kProgressBarHeight); | 239 gfx::ImageSkia center = *ResourceBundle::GetSharedInstance(). |
236 canvas->FillRect(progress_bar_background, kDownloadProgressBackgroundColor); | 240 GetImageSkiaNamed(IDR_APP_LIST_ITEM_PROGRESS_CENTER); |
241 gfx::ImageSkia right = *ResourceBundle::GetSharedInstance(). | |
242 GetImageSkiaNamed(IDR_APP_LIST_ITEM_PROGRESS_RIGHT); | |
237 | 243 |
244 int bar_x = rect.x() + kProgressBarHorizontalPadding; | |
245 int bar_y = | |
246 icon_->bounds().bottom() + kIconTitleSpacing; | |
benwells
2013/02/12 07:55:17
This can fit on one line.
koz (OOO until 15th September)
2013/02/12 08:20:11
Done.
| |
247 // rect.y() + icon_size_.height() + kIconTitleSpacing; | |
benwells
2013/02/12 07:55:17
Did you mean these comments to be here?
koz (OOO until 15th September)
2013/02/12 08:20:11
Done.
| |
248 // rect.bottom() - kProgressBarVerticalPadding - kProgressBarHeight; | |
249 | |
250 canvas->DrawImageInt(background, bar_x, bar_y); | |
238 if (model_->percent_downloaded() != -1) { | 251 if (model_->percent_downloaded() != -1) { |
benwells
2013/02/12 07:55:17
Should this be > 0?
koz (OOO until 15th September)
2013/02/12 08:20:11
No, on a 0 percent downloaded item we still want t
| |
239 float percent = model_->percent_downloaded() / 100.0; | 252 float percent = model_->percent_downloaded() / 100.0; |
240 gfx::Rect progress_bar( | 253 int bar_width = percent * |
241 progress_bar_background.x(), | 254 (background.width() - (left.width() + right.width())); |
242 progress_bar_background.y(), | 255 |
243 progress_bar_background.width() * percent, | 256 canvas->DrawImageInt(left, bar_x, bar_y); |
244 progress_bar_background.height()); | 257 int x = bar_x + left.width(); |
245 canvas->FillRect(progress_bar, kDownloadProgressColor); | 258 canvas->TileImageInt(center, x, bar_y, bar_width, center.height()); |
259 x += bar_width; | |
260 canvas->DrawImageInt(right, x, bar_y); | |
246 } | 261 } |
247 } | 262 } |
248 } | 263 } |
249 | 264 |
250 void AppListItemView::GetAccessibleState(ui::AccessibleViewState* state) { | 265 void AppListItemView::GetAccessibleState(ui::AccessibleViewState* state) { |
251 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 266 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
252 state->name = UTF8ToUTF16(model_->title()); | 267 state->name = UTF8ToUTF16(model_->title()); |
253 } | 268 } |
254 | 269 |
255 void AppListItemView::ShowContextMenuForView(views::View* source, | 270 void AppListItemView::ShowContextMenuForView(views::View* source, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 SetTouchDragging(false); | 392 SetTouchDragging(false); |
378 break; | 393 break; |
379 default: | 394 default: |
380 break; | 395 break; |
381 } | 396 } |
382 if (!event->handled()) | 397 if (!event->handled()) |
383 CustomButton::OnGestureEvent(event); | 398 CustomButton::OnGestureEvent(event); |
384 } | 399 } |
385 | 400 |
386 } // namespace app_list | 401 } // namespace app_list |
OLD | NEW |