| 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/ui_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 23 matching lines...) Expand all Loading... |
| 68 ui_state_(UI_STATE_NORMAL), | 69 ui_state_(UI_STATE_NORMAL), |
| 69 touch_dragging_(false) { | 70 touch_dragging_(false) { |
| 70 icon_->set_interactive(false); | 71 icon_->set_interactive(false); |
| 71 | 72 |
| 72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 73 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 73 title_->SetBackgroundColor(0); | 74 title_->SetBackgroundColor(0); |
| 74 title_->SetAutoColorReadabilityEnabled(false); | 75 title_->SetAutoColorReadabilityEnabled(false); |
| 75 title_->SetEnabledColor(kTitleColor); | 76 title_->SetEnabledColor(kTitleColor); |
| 76 title_->SetFont(rb.GetFont(ui::ResourceBundle::SmallBoldFont)); | 77 title_->SetFont(rb.GetFont(ui::ResourceBundle::SmallBoldFont)); |
| 77 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 78 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 79 title_->SetVisible(!model_->is_installing()); |
| 78 | 80 |
| 79 const gfx::ShadowValue kIconShadows[] = { | 81 const gfx::ShadowValue kIconShadows[] = { |
| 80 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)), | 82 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)), |
| 81 }; | 83 }; |
| 82 icon_shadows_.assign(kIconShadows, kIconShadows + arraysize(kIconShadows)); | 84 icon_shadows_.assign(kIconShadows, kIconShadows + arraysize(kIconShadows)); |
| 83 | 85 |
| 84 AddChildView(icon_); | 86 AddChildView(icon_); |
| 85 AddChildView(title_); | 87 AddChildView(title_); |
| 86 | 88 |
| 87 ItemIconChanged(); | 89 ItemIconChanged(); |
| (...skipping 82 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |