Chromium Code Reviews| 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/views/apps_grid_view.h" | 15 #include "ui/app_list/views/apps_grid_view.h" |
| 16 #include "ui/app_list/views/cached_label.h" | 16 #include "ui/app_list/views/cached_label.h" |
| 17 #include "ui/app_list/views/progress_bar_view.h" | 17 #include "ui/app_list/views/progress_bar_view.h" |
| 18 #include "ui/base/dragdrop/drag_utils.h" | 18 #include "ui/base/dragdrop/drag_utils.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" | 22 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/gfx/animation/throb_animation.h" | 23 #include "ui/gfx/animation/throb_animation.h" |
| 24 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
| 25 #include "ui/gfx/font_list.h" | 25 #include "ui/gfx/font_list.h" |
| 26 #include "ui/gfx/image/image_skia_operations.h" | 26 #include "ui/gfx/image/image_skia_operations.h" |
| 27 #include "ui/gfx/point.h" | 27 #include "ui/gfx/point.h" |
| 28 #include "ui/gfx/shadow_value.h" | |
| 28 #include "ui/gfx/transform_util.h" | 29 #include "ui/gfx/transform_util.h" |
| 29 #include "ui/views/background.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_runner.h" | 33 #include "ui/views/controls/menu/menu_runner.h" |
| 33 #include "ui/views/drag_controller.h" | 34 #include "ui/views/drag_controller.h" |
| 34 | 35 |
| 35 namespace app_list { | 36 namespace app_list { |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 53 const int kFolderPreviewRadius = 40; | 54 const int kFolderPreviewRadius = 40; |
| 54 | 55 |
| 55 const int kLeftRightPaddingChars = 1; | 56 const int kLeftRightPaddingChars = 1; |
| 56 | 57 |
| 57 // Scale to transform the icon when a drag starts. | 58 // Scale to transform the icon when a drag starts. |
| 58 const float kDraggingIconScale = 1.5f; | 59 const float kDraggingIconScale = 1.5f; |
| 59 | 60 |
| 60 // Delay in milliseconds of when the dragging UI should be shown for mouse drag. | 61 // Delay in milliseconds of when the dragging UI should be shown for mouse drag. |
| 61 const int kMouseDragUIDelayInMs = 200; | 62 const int kMouseDragUIDelayInMs = 200; |
| 62 | 63 |
| 64 const gfx::ShadowValues& GetIconShadows() { | |
| 65 CR_DEFINE_STATIC_LOCAL( | |
|
benwells
2014/08/14 01:55:35
This seems yucky, but whatevs. I guess we save som
tapted
2014/08/14 04:10:56
Yeah I considered constructing it each time - stat
| |
| 66 const gfx::ShadowValues, | |
| 67 icon_shadows, | |
| 68 (1, | |
| 69 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)))); | |
| 70 return icon_shadows; | |
| 71 } | |
| 72 | |
| 63 } // namespace | 73 } // namespace |
| 64 | 74 |
| 65 // static | 75 // static |
| 66 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; | 76 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; |
| 67 | 77 |
| 68 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, | 78 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, |
| 69 AppListItem* item) | 79 AppListItem* item) |
| 70 : CustomButton(apps_grid_view), | 80 : CustomButton(apps_grid_view), |
| 71 item_(item), | 81 item_(item), |
| 72 apps_grid_view_(apps_grid_view), | 82 apps_grid_view_(apps_grid_view), |
| 73 icon_(new views::ImageView), | 83 icon_(new views::ImageView), |
| 74 title_(new CachedLabel), | 84 title_(new CachedLabel), |
| 75 progress_bar_(new ProgressBarView), | 85 progress_bar_(new ProgressBarView), |
| 76 ui_state_(UI_STATE_NORMAL), | 86 ui_state_(UI_STATE_NORMAL), |
| 77 touch_dragging_(false) { | 87 touch_dragging_(false) { |
| 78 icon_->set_interactive(false); | 88 icon_->set_interactive(false); |
| 79 | 89 |
| 80 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 81 title_->SetBackgroundColor(0); | 91 title_->SetBackgroundColor(0); |
| 82 title_->SetAutoColorReadabilityEnabled(false); | 92 title_->SetAutoColorReadabilityEnabled(false); |
| 83 title_->SetEnabledColor(kGridTitleColor); | 93 title_->SetEnabledColor(kGridTitleColor); |
| 84 title_->SetFontList( | 94 title_->SetFontList( |
| 85 rb.GetFontList(kItemTextFontStyle).DeriveWithSizeDelta(kFontSizeDelta)); | 95 rb.GetFontList(kItemTextFontStyle).DeriveWithSizeDelta(kFontSizeDelta)); |
| 86 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 96 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 87 title_->SetVisible(!item_->is_installing()); | 97 title_->SetVisible(!item_->is_installing()); |
| 88 title_->Invalidate(); | 98 title_->Invalidate(); |
| 89 SetTitleSubpixelAA(); | 99 SetTitleSubpixelAA(); |
| 90 | 100 |
| 91 const gfx::ShadowValue kIconShadows[] = { | |
| 92 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)), | |
| 93 }; | |
| 94 icon_shadows_.assign(kIconShadows, kIconShadows + arraysize(kIconShadows)); | |
| 95 | |
| 96 AddChildView(icon_); | 101 AddChildView(icon_); |
| 97 AddChildView(title_); | 102 AddChildView(title_); |
| 98 AddChildView(progress_bar_); | 103 AddChildView(progress_bar_); |
| 99 | 104 |
| 100 ItemIconChanged(); | 105 ItemIconChanged(); |
| 101 ItemNameChanged(); | 106 ItemNameChanged(); |
| 102 ItemIsInstallingChanged(); | 107 ItemIsInstallingChanged(); |
| 103 item_->AddObserver(this); | 108 item_->AddObserver(this); |
| 104 | 109 |
| 105 set_context_menu_controller(this); | 110 set_context_menu_controller(this); |
| 106 set_request_focus_on_press(false); | 111 set_request_focus_on_press(false); |
| 107 | 112 |
| 108 SetAnimationDuration(0); | 113 SetAnimationDuration(0); |
| 109 } | 114 } |
| 110 | 115 |
| 111 AppListItemView::~AppListItemView() { | 116 AppListItemView::~AppListItemView() { |
| 112 item_->RemoveObserver(this); | 117 item_->RemoveObserver(this); |
| 113 } | 118 } |
| 114 | 119 |
| 115 void AppListItemView::SetIconSize(const gfx::Size& size) { | |
| 116 if (icon_size_ == size) | |
| 117 return; | |
| 118 | |
| 119 icon_size_ = size; | |
| 120 UpdateIcon(); | |
| 121 } | |
| 122 | |
| 123 void AppListItemView::UpdateIcon() { | 120 void AppListItemView::UpdateIcon() { |
| 124 // Skip if |icon_size_| has not been determined. | |
| 125 if (icon_size_.IsEmpty()) | |
| 126 return; | |
| 127 | |
| 128 gfx::ImageSkia icon = item_->icon(); | 121 gfx::ImageSkia icon = item_->icon(); |
| 129 // Clear icon and bail out if item icon is empty. | 122 // Clear icon and bail out if item icon is empty. |
| 130 if (icon.isNull()) { | 123 if (icon.isNull()) { |
| 131 icon_->SetImage(NULL); | 124 icon_->SetImage(NULL); |
| 132 return; | 125 return; |
| 133 } | 126 } |
| 134 | 127 |
| 135 gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage(icon, | 128 gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage( |
| 136 skia::ImageOperations::RESIZE_BEST, icon_size_)); | 129 icon, |
| 130 skia::ImageOperations::RESIZE_BEST, | |
| 131 gfx::Size(kGridIconDimension, kGridIconDimension))); | |
| 137 if (item_->has_shadow()) { | 132 if (item_->has_shadow()) { |
| 138 gfx::ImageSkia shadow( | 133 gfx::ImageSkia shadow(gfx::ImageSkiaOperations::CreateImageWithDropShadow( |
| 139 gfx::ImageSkiaOperations::CreateImageWithDropShadow(resized, | 134 resized, GetIconShadows())); |
| 140 icon_shadows_)); | |
| 141 icon_->SetImage(shadow); | 135 icon_->SetImage(shadow); |
| 142 return; | 136 return; |
| 143 } | 137 } |
| 144 | 138 |
| 145 icon_->SetImage(resized); | 139 icon_->SetImage(resized); |
| 146 } | 140 } |
| 147 | 141 |
| 148 void AppListItemView::UpdateTooltip() { | 142 void AppListItemView::UpdateTooltip() { |
| 149 std::string display_name = item_->GetDisplayName(); | 143 std::string display_name = item_->GetDisplayName(); |
| 150 title_->SetTooltipText(display_name == item_->name() ? base::string16() | 144 title_->SetTooltipText(display_name == item_->name() ? base::string16() |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 gfx::Rect rect(GetContentsBounds()); | 300 gfx::Rect rect(GetContentsBounds()); |
| 307 | 301 |
| 308 const int left_right_padding = | 302 const int left_right_padding = |
| 309 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); | 303 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); |
| 310 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | 304 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); |
| 311 const int y = rect.y(); | 305 const int y = rect.y(); |
| 312 | 306 |
| 313 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); | 307 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); |
| 314 const gfx::Size title_size = title_->GetPreferredSize(); | 308 const gfx::Size title_size = title_->GetPreferredSize(); |
| 315 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, | 309 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, |
| 316 y + icon_size_.height() + kIconTitleSpacing, | 310 y + kGridIconDimension + kIconTitleSpacing, |
| 317 title_size.width(), | 311 title_size.width(), |
| 318 title_size.height()); | 312 title_size.height()); |
| 319 title_bounds.Intersect(rect); | 313 title_bounds.Intersect(rect); |
| 320 title_->SetBoundsRect(title_bounds); | 314 title_->SetBoundsRect(title_bounds); |
| 321 | 315 |
| 322 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); | 316 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); |
| 323 progress_bar_bounds.set_x(GetContentsBounds().x() + | 317 progress_bar_bounds.set_x(GetContentsBounds().x() + |
| 324 kProgressBarHorizontalPadding); | 318 kProgressBarHorizontalPadding); |
| 325 progress_bar_bounds.set_y(title_bounds.y()); | 319 progress_bar_bounds.set_y(title_bounds.y()); |
| 326 progress_bar_->SetBoundsRect(progress_bar_bounds); | 320 progress_bar_->SetBoundsRect(progress_bar_bounds); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 } | 512 } |
| 519 | 513 |
| 520 gfx::Rect AppListItemView::GetIconBoundsForTargetViewBounds( | 514 gfx::Rect AppListItemView::GetIconBoundsForTargetViewBounds( |
| 521 const gfx::Rect& target_bounds) { | 515 const gfx::Rect& target_bounds) { |
| 522 gfx::Rect rect(target_bounds); | 516 gfx::Rect rect(target_bounds); |
| 523 | 517 |
| 524 const int left_right_padding = | 518 const int left_right_padding = |
| 525 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); | 519 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); |
| 526 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | 520 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); |
| 527 | 521 |
| 528 gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), icon_size_.height()); | 522 gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), kGridIconDimension); |
| 529 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); | 523 icon_bounds.Inset(gfx::ShadowValue::GetMargin(GetIconShadows())); |
| 530 return icon_bounds; | 524 return icon_bounds; |
| 531 } | 525 } |
| 532 | 526 |
| 533 } // namespace app_list | 527 } // namespace app_list |
| OLD | NEW |