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 "ui/app_list/app_list_item_model.h" | 10 #include "ui/app_list/app_list_item_model.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ui/views/controls/menu/menu_model_adapter.h" | 24 #include "ui/views/controls/menu/menu_model_adapter.h" |
25 #include "ui/views/controls/menu/menu_runner.h" | 25 #include "ui/views/controls/menu/menu_runner.h" |
26 | 26 |
27 namespace app_list { | 27 namespace app_list { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 const int kTopBottomPadding = 10; | 31 const int kTopBottomPadding = 10; |
32 const int kTopPadding = 20; | 32 const int kTopPadding = 20; |
33 const int kIconTitleSpacing = 7; | 33 const int kIconTitleSpacing = 7; |
| 34 const int kProgressBarHorizontalPadding = 8; |
| 35 const int kProgressBarVerticalPadding = 4; |
| 36 const int kProgressBarHeight = 4; |
34 | 37 |
35 const SkColor kTitleColor = SkColorSetRGB(0x5A, 0x5A, 0x5A); | 38 const SkColor kTitleColor = SkColorSetRGB(0x5A, 0x5A, 0x5A); |
36 const SkColor kTitleHoverColor = SkColorSetRGB(0x3C, 0x3C, 0x3C); | 39 const SkColor kTitleHoverColor = SkColorSetRGB(0x3C, 0x3C, 0x3C); |
37 | 40 |
38 const SkColor kHoverAndPushedColor = SkColorSetARGB(0x19, 0, 0, 0); | 41 const SkColor kHoverAndPushedColor = SkColorSetARGB(0x19, 0, 0, 0); |
39 const SkColor kSelectedColor = SkColorSetARGB(0x0D, 0, 0, 0); | 42 const SkColor kSelectedColor = SkColorSetARGB(0x0D, 0, 0, 0); |
40 const SkColor kHighlightedColor = kHoverAndPushedColor; | 43 const SkColor kHighlightedColor = kHoverAndPushedColor; |
| 44 const SkColor kDownloadProgressBackgroundColor = |
| 45 SkColorSetRGB(0x90, 0x90, 0x90); |
| 46 const SkColor kDownloadProgressColor = SkColorSetRGB(0x20, 0xAA, 0x20); |
41 | 47 |
42 const int kLeftRightPaddingChars = 1; | 48 const int kLeftRightPaddingChars = 1; |
43 | 49 |
44 // Scale to transform the icon when a drag starts. | 50 // Scale to transform the icon when a drag starts. |
45 const float kDraggingIconScale = 1.5f; | 51 const float kDraggingIconScale = 1.5f; |
46 | 52 |
47 // Delay in milliseconds of when the dragging UI should be shown for mouse drag. | 53 // Delay in milliseconds of when the dragging UI should be shown for mouse drag. |
48 const int kMouseDragUIDelayInMs = 100; | 54 const int kMouseDragUIDelayInMs = 100; |
49 | 55 |
50 } // namespace | 56 } // namespace |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 167 |
162 void AppListItemView::ItemTitleChanged() { | 168 void AppListItemView::ItemTitleChanged() { |
163 title_->SetText(UTF8ToUTF16(model_->title())); | 169 title_->SetText(UTF8ToUTF16(model_->title())); |
164 } | 170 } |
165 | 171 |
166 void AppListItemView::ItemHighlightedChanged() { | 172 void AppListItemView::ItemHighlightedChanged() { |
167 apps_grid_view_->EnsureViewVisible(this); | 173 apps_grid_view_->EnsureViewVisible(this); |
168 SchedulePaint(); | 174 SchedulePaint(); |
169 } | 175 } |
170 | 176 |
| 177 void AppListItemView::ItemIsInstallingChanged() { |
| 178 if (model_->is_installing()) |
| 179 apps_grid_view_->EnsureViewVisible(this); |
| 180 SchedulePaint(); |
| 181 } |
| 182 |
| 183 void AppListItemView::ItemPercentDownloadedChanged() { |
| 184 SchedulePaint(); |
| 185 } |
| 186 |
171 std::string AppListItemView::GetClassName() const { | 187 std::string AppListItemView::GetClassName() const { |
172 return kViewClassName; | 188 return kViewClassName; |
173 } | 189 } |
174 | 190 |
175 void AppListItemView::Layout() { | 191 void AppListItemView::Layout() { |
176 gfx::Rect rect(GetContentsBounds()); | 192 gfx::Rect rect(GetContentsBounds()); |
177 | 193 |
178 const int left_right_padding = kLeftRightPaddingChars * | 194 const int left_right_padding = kLeftRightPaddingChars * |
179 title_->font().GetAverageCharacterWidth(); | 195 title_->font().GetAverageCharacterWidth(); |
180 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | 196 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); |
(...skipping 22 matching lines...) Expand all Loading... |
203 canvas->FillRect(rect, kHighlightedColor); | 219 canvas->FillRect(rect, kHighlightedColor); |
204 } else if (hover_animation_->is_animating()) { | 220 } else if (hover_animation_->is_animating()) { |
205 int alpha = SkColorGetA(kHoverAndPushedColor) * | 221 int alpha = SkColorGetA(kHoverAndPushedColor) * |
206 hover_animation_->GetCurrentValue(); | 222 hover_animation_->GetCurrentValue(); |
207 canvas->FillRect(rect, SkColorSetA(kHoverAndPushedColor, alpha)); | 223 canvas->FillRect(rect, SkColorSetA(kHoverAndPushedColor, alpha)); |
208 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) { | 224 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) { |
209 canvas->FillRect(rect, kHoverAndPushedColor); | 225 canvas->FillRect(rect, kHoverAndPushedColor); |
210 } else if (apps_grid_view_->IsSelectedView(this)) { | 226 } else if (apps_grid_view_->IsSelectedView(this)) { |
211 canvas->FillRect(rect, kSelectedColor); | 227 canvas->FillRect(rect, kSelectedColor); |
212 } | 228 } |
| 229 |
| 230 if (model_->is_installing()) { |
| 231 gfx::Rect progress_bar_background( |
| 232 rect.x() + kProgressBarHorizontalPadding, |
| 233 rect.bottom() - kProgressBarVerticalPadding - kProgressBarHeight, |
| 234 rect.width() - 2 * kProgressBarHorizontalPadding, |
| 235 kProgressBarHeight); |
| 236 canvas->FillRect(progress_bar_background, kDownloadProgressBackgroundColor); |
| 237 |
| 238 if (model_->percent_downloaded() != -1) { |
| 239 float percent = model_->percent_downloaded() / 100.0; |
| 240 gfx::Rect progress_bar( |
| 241 progress_bar_background.x(), |
| 242 progress_bar_background.y(), |
| 243 progress_bar_background.width() * percent, |
| 244 progress_bar_background.height()); |
| 245 canvas->FillRect(progress_bar, kDownloadProgressColor); |
| 246 } |
| 247 } |
213 } | 248 } |
214 | 249 |
215 void AppListItemView::GetAccessibleState(ui::AccessibleViewState* state) { | 250 void AppListItemView::GetAccessibleState(ui::AccessibleViewState* state) { |
216 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 251 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
217 state->name = UTF8ToUTF16(model_->title()); | 252 state->name = UTF8ToUTF16(model_->title()); |
218 } | 253 } |
219 | 254 |
220 void AppListItemView::ShowContextMenuForView(views::View* source, | 255 void AppListItemView::ShowContextMenuForView(views::View* source, |
221 const gfx::Point& point) { | 256 const gfx::Point& point) { |
222 ui::MenuModel* menu_model = model_->GetContextMenuModel(); | 257 ui::MenuModel* menu_model = model_->GetContextMenuModel(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 SetTouchDragging(false); | 377 SetTouchDragging(false); |
343 break; | 378 break; |
344 default: | 379 default: |
345 break; | 380 break; |
346 } | 381 } |
347 if (!event->handled()) | 382 if (!event->handled()) |
348 CustomButton::OnGestureEvent(event); | 383 CustomButton::OnGestureEvent(event); |
349 } | 384 } |
350 | 385 |
351 } // namespace app_list | 386 } // namespace app_list |
OLD | NEW |