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