| 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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
| 11 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 12 #include "ui/app_list/app_list_constants.h" | 12 #include "ui/app_list/app_list_constants.h" |
| 13 #include "ui/app_list/app_list_folder_item.h" | 13 #include "ui/app_list/app_list_folder_item.h" |
| 14 #include "ui/app_list/app_list_item.h" | 14 #include "ui/app_list/app_list_item.h" |
| 15 #include "ui/app_list/app_list_switches.h" | 15 #include "ui/app_list/app_list_switches.h" |
| 16 #include "ui/app_list/views/apps_grid_view.h" | 16 #include "ui/app_list/views/apps_grid_view.h" |
| 17 #include "ui/app_list/views/cached_label.h" | 17 #include "ui/app_list/views/cached_label.h" |
| 18 #include "ui/app_list/views/progress_bar_view.h" | 18 #include "ui/app_list/views/progress_bar_view.h" |
| 19 #include "ui/base/dragdrop/drag_utils.h" | 19 #include "ui/base/dragdrop/drag_utils.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" |
| 23 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 24 #include "ui/gfx/animation/throb_animation.h" | 24 #include "ui/gfx/animation/throb_animation.h" |
| 25 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 26 #include "ui/gfx/font_list.h" | 26 #include "ui/gfx/font_list.h" |
| 27 #include "ui/gfx/image/image_skia_operations.h" | 27 #include "ui/gfx/image/image_skia_operations.h" |
| 28 #include "ui/gfx/point.h" | 28 #include "ui/gfx/point.h" |
| 29 #include "ui/gfx/transform_util.h" | 29 #include "ui/gfx/transform_util.h" |
| 30 #include "ui/views/background.h" |
| 30 #include "ui/views/controls/image_view.h" | 31 #include "ui/views/controls/image_view.h" |
| 31 #include "ui/views/controls/label.h" | 32 #include "ui/views/controls/label.h" |
| 32 #include "ui/views/controls/menu/menu_item_view.h" | 33 #include "ui/views/controls/menu/menu_item_view.h" |
| 33 #include "ui/views/controls/menu/menu_runner.h" | 34 #include "ui/views/controls/menu/menu_runner.h" |
| 34 #include "ui/views/drag_controller.h" | 35 #include "ui/views/drag_controller.h" |
| 35 | 36 |
| 36 namespace app_list { | 37 namespace app_list { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 const int kTopPadding = 20; | 41 const int kTopPadding = 20; |
| 41 const int kIconTitleSpacing = 7; | 42 const int kIconTitleSpacing = 7; |
| 42 const int kProgressBarHorizontalPadding = 12; | 43 const int kProgressBarHorizontalPadding = 12; |
| 43 | 44 |
| 44 // Radius of the folder dropping preview circle. | 45 // Radius of the folder dropping preview circle. |
| 45 const int kFolderPreviewRadius = 40; | 46 const int kFolderPreviewRadius = 40; |
| 46 | 47 |
| 47 const int kLeftRightPaddingChars = 1; | 48 const int kLeftRightPaddingChars = 1; |
| 48 | 49 |
| 49 // Scale to transform the icon when a drag starts. | |
| 50 const float kDraggingIconScale = 1.5f; | |
| 51 | |
| 52 // Delay in milliseconds of when the dragging UI should be shown for mouse drag. | 50 // Delay in milliseconds of when the dragging UI should be shown for mouse drag. |
| 53 const int kMouseDragUIDelayInMs = 200; | 51 const int kMouseDragUIDelayInMs = 200; |
| 54 | 52 |
| 55 } // namespace | 53 } // namespace |
| 56 | 54 |
| 57 // static | 55 // static |
| 58 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; | 56 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; |
| 59 | 57 |
| 60 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, | 58 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, |
| 61 AppListItem* item) | 59 AppListItem* item) |
| 62 : CustomButton(apps_grid_view), | 60 : CustomButton(apps_grid_view), |
| 63 item_(item), | 61 item_(item), |
| 64 apps_grid_view_(apps_grid_view), | 62 apps_grid_view_(apps_grid_view), |
| 65 icon_(new views::ImageView), | 63 icon_(new views::ImageView), |
| 66 title_(new CachedLabel), | 64 title_(new CachedLabel), |
| 67 progress_bar_(new ProgressBarView), | 65 progress_bar_(new ProgressBarView), |
| 68 ui_state_(UI_STATE_NORMAL), | 66 ui_state_(UI_STATE_NORMAL), |
| 69 touch_dragging_(false) { | 67 touch_dragging_(false) { |
| 70 icon_->set_interactive(false); | 68 icon_->set_interactive(false); |
| 71 | 69 |
| 72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 70 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 73 title_->SetBackgroundColor(0); | |
| 74 title_->SetAutoColorReadabilityEnabled(false); | 71 title_->SetAutoColorReadabilityEnabled(false); |
| 75 title_->SetEnabledColor(kGridTitleColor); | 72 title_->SetEnabledColor(kGridTitleColor); |
| 76 title_->SetFontList(rb.GetFontList(kItemTextFontStyle)); | 73 title_->SetFontList(rb.GetFontList(kItemTextFontStyle)); |
| 77 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 74 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 78 title_->SetVisible(!item_->is_installing()); | 75 title_->SetVisible(!item_->is_installing()); |
| 79 title_->Invalidate(); | 76 title_->Invalidate(); |
| 80 | 77 |
| 78 title_->SetBackgroundColor(app_list::kContentsBackgroundColor); |
| 79 title_->set_background(views::Background::CreateSolidBackground( |
| 80 app_list::kContentsBackgroundColor)); |
| 81 |
| 81 const gfx::ShadowValue kIconShadows[] = { | 82 const gfx::ShadowValue kIconShadows[] = { |
| 82 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)), | 83 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)), |
| 83 }; | 84 }; |
| 84 icon_shadows_.assign(kIconShadows, kIconShadows + arraysize(kIconShadows)); | 85 icon_shadows_.assign(kIconShadows, kIconShadows + arraysize(kIconShadows)); |
| 85 | 86 |
| 86 AddChildView(icon_); | 87 AddChildView(icon_); |
| 87 AddChildView(title_); | 88 AddChildView(title_); |
| 88 AddChildView(progress_bar_); | 89 AddChildView(progress_bar_); |
| 89 | 90 |
| 90 ItemIconChanged(); | 91 ItemIconChanged(); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 void AppListItemView::ShowContextMenuForView(views::View* source, | 326 void AppListItemView::ShowContextMenuForView(views::View* source, |
| 326 const gfx::Point& point, | 327 const gfx::Point& point, |
| 327 ui::MenuSourceType source_type) { | 328 ui::MenuSourceType source_type) { |
| 328 ui::MenuModel* menu_model = item_->GetContextMenuModel(); | 329 ui::MenuModel* menu_model = item_->GetContextMenuModel(); |
| 329 if (!menu_model) | 330 if (!menu_model) |
| 330 return; | 331 return; |
| 331 | 332 |
| 332 context_menu_runner_.reset(new views::MenuRunner(menu_model)); | 333 context_menu_runner_.reset(new views::MenuRunner(menu_model)); |
| 333 if (context_menu_runner_->RunMenuAt( | 334 if (context_menu_runner_->RunMenuAt( |
| 334 GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 335 GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
| 335 views::MenuItemView::TOPLEFT, source_type, | 336 ui::TOPLEFT_MENU_ANCHOR, source_type, |
| 336 views::MenuRunner::HAS_MNEMONICS) == | 337 views::MenuRunner::HAS_MNEMONICS) == |
| 337 views::MenuRunner::MENU_DELETED) | 338 views::MenuRunner::MENU_DELETED) |
| 338 return; | 339 return; |
| 339 } | 340 } |
| 340 | 341 |
| 341 void AppListItemView::StateChanged() { | 342 void AppListItemView::StateChanged() { |
| 342 const bool is_folder_ui_enabled = switches::IsFolderUIEnabled(); | 343 const bool is_folder_ui_enabled = switches::IsFolderUIEnabled(); |
| 343 if (is_folder_ui_enabled) | 344 if (is_folder_ui_enabled) |
| 344 apps_grid_view_->ClearAnySelectedView(); | 345 apps_grid_view_->ClearAnySelectedView(); |
| 345 | 346 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 const int left_right_padding = | 487 const int left_right_padding = |
| 487 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); | 488 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); |
| 488 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | 489 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); |
| 489 | 490 |
| 490 gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), icon_size_.height()); | 491 gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), icon_size_.height()); |
| 491 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); | 492 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); |
| 492 return icon_bounds; | 493 return icon_bounds; |
| 493 } | 494 } |
| 494 | 495 |
| 495 } // namespace app_list | 496 } // namespace app_list |
| OLD | NEW |