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" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 const int kFolderPreviewRadius = 40; | 53 const int kFolderPreviewRadius = 40; |
54 | 54 |
55 const int kLeftRightPaddingChars = 1; | 55 const int kLeftRightPaddingChars = 1; |
56 | 56 |
57 // Scale to transform the icon when a drag starts. | 57 // Scale to transform the icon when a drag starts. |
58 const float kDraggingIconScale = 1.5f; | 58 const float kDraggingIconScale = 1.5f; |
59 | 59 |
60 // Delay in milliseconds of when the dragging UI should be shown for mouse drag. | 60 // Delay in milliseconds of when the dragging UI should be shown for mouse drag. |
61 const int kMouseDragUIDelayInMs = 200; | 61 const int kMouseDragUIDelayInMs = 200; |
62 | 62 |
63 const gfx::ShadowValues& GetIconShadows() { | |
64 CR_DEFINE_STATIC_LOCAL( | |
65 const gfx::ShadowValues, | |
66 icon_shadows, | |
67 (1, | |
68 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)))); | |
69 return icon_shadows; | |
70 } | |
71 | |
63 } // namespace | 72 } // namespace |
64 | 73 |
65 // static | 74 // static |
66 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; | 75 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; |
67 | 76 |
68 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, | 77 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, |
69 AppListItem* item) | 78 AppListItem* item) |
70 : CustomButton(apps_grid_view), | 79 : CustomButton(apps_grid_view), |
71 item_(item), | 80 item_(item), |
72 apps_grid_view_(apps_grid_view), | 81 apps_grid_view_(apps_grid_view), |
73 icon_(new views::ImageView), | 82 icon_(new views::ImageView), |
74 title_(new CachedLabel), | 83 title_(new CachedLabel), |
75 progress_bar_(new ProgressBarView), | 84 progress_bar_(new ProgressBarView), |
76 ui_state_(UI_STATE_NORMAL), | 85 ui_state_(UI_STATE_NORMAL), |
77 touch_dragging_(false) { | 86 touch_dragging_(false) { |
78 icon_->set_interactive(false); | 87 icon_->set_interactive(false); |
79 | 88 |
80 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
81 title_->SetBackgroundColor(0); | 90 title_->SetBackgroundColor(0); |
82 title_->SetAutoColorReadabilityEnabled(false); | 91 title_->SetAutoColorReadabilityEnabled(false); |
83 title_->SetEnabledColor(kGridTitleColor); | 92 title_->SetEnabledColor(kGridTitleColor); |
84 title_->SetFontList( | 93 title_->SetFontList( |
85 rb.GetFontList(kItemTextFontStyle).DeriveWithSizeDelta(kFontSizeDelta)); | 94 rb.GetFontList(kItemTextFontStyle).DeriveWithSizeDelta(kFontSizeDelta)); |
86 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 95 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
87 title_->SetVisible(!item_->is_installing()); | 96 title_->SetVisible(!item_->is_installing()); |
88 title_->Invalidate(); | 97 title_->Invalidate(); |
89 SetTitleSubpixelAA(); | 98 SetTitleSubpixelAA(); |
90 | 99 |
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_); | 100 AddChildView(icon_); |
97 AddChildView(title_); | 101 AddChildView(title_); |
98 AddChildView(progress_bar_); | 102 AddChildView(progress_bar_); |
99 | 103 |
100 ItemIconChanged(); | 104 ItemIconChanged(); |
101 ItemNameChanged(); | 105 ItemNameChanged(); |
102 ItemIsInstallingChanged(); | 106 ItemIsInstallingChanged(); |
103 item_->AddObserver(this); | 107 item_->AddObserver(this); |
104 | 108 |
105 set_context_menu_controller(this); | 109 set_context_menu_controller(this); |
106 set_request_focus_on_press(false); | 110 set_request_focus_on_press(false); |
107 | 111 |
108 SetAnimationDuration(0); | 112 SetAnimationDuration(0); |
109 } | 113 } |
110 | 114 |
111 AppListItemView::~AppListItemView() { | 115 AppListItemView::~AppListItemView() { |
112 item_->RemoveObserver(this); | 116 item_->RemoveObserver(this); |
113 } | 117 } |
114 | 118 |
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() { | 119 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(); | 120 gfx::ImageSkia icon = item_->icon(); |
129 // Clear icon and bail out if item icon is empty. | 121 // Clear icon and bail out if item icon is empty. |
130 if (icon.isNull()) { | 122 if (icon.isNull()) { |
131 icon_->SetImage(NULL); | 123 icon_->SetImage(NULL); |
132 return; | 124 return; |
133 } | 125 } |
134 | 126 |
135 gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage(icon, | 127 gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage( |
136 skia::ImageOperations::RESIZE_BEST, icon_size_)); | 128 icon, |
129 skia::ImageOperations::RESIZE_BEST, | |
130 gfx::Size(kPreferredIconDimension, kPreferredIconDimension))); | |
137 if (item_->has_shadow()) { | 131 if (item_->has_shadow()) { |
138 gfx::ImageSkia shadow( | 132 gfx::ImageSkia shadow(gfx::ImageSkiaOperations::CreateImageWithDropShadow( |
139 gfx::ImageSkiaOperations::CreateImageWithDropShadow(resized, | 133 resized, GetIconShadows())); |
140 icon_shadows_)); | |
141 icon_->SetImage(shadow); | 134 icon_->SetImage(shadow); |
142 return; | 135 return; |
143 } | 136 } |
144 | 137 |
145 icon_->SetImage(resized); | 138 icon_->SetImage(resized); |
146 } | 139 } |
147 | 140 |
148 void AppListItemView::UpdateTooltip() { | 141 void AppListItemView::UpdateTooltip() { |
149 std::string display_name = item_->GetDisplayName(); | 142 std::string display_name = item_->GetDisplayName(); |
150 title_->SetTooltipText(display_name == item_->name() ? base::string16() | 143 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()); | 299 gfx::Rect rect(GetContentsBounds()); |
307 | 300 |
308 const int left_right_padding = | 301 const int left_right_padding = |
309 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); | 302 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); |
310 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | 303 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); |
311 const int y = rect.y(); | 304 const int y = rect.y(); |
312 | 305 |
313 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); | 306 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); |
314 const gfx::Size title_size = title_->GetPreferredSize(); | 307 const gfx::Size title_size = title_->GetPreferredSize(); |
315 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, | 308 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, |
316 y + icon_size_.height() + kIconTitleSpacing, | 309 y + kPreferredIconDimension + kIconTitleSpacing, |
benwells
2014/08/13 22:47:06
i think this name is misleading now. It isn't the
tapted
2014/08/14 00:54:34
Changed to app_list::kGridIconDimension. Looks lik
| |
317 title_size.width(), | 310 title_size.width(), |
318 title_size.height()); | 311 title_size.height()); |
319 title_bounds.Intersect(rect); | 312 title_bounds.Intersect(rect); |
320 title_->SetBoundsRect(title_bounds); | 313 title_->SetBoundsRect(title_bounds); |
321 | 314 |
322 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); | 315 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); |
323 progress_bar_bounds.set_x(GetContentsBounds().x() + | 316 progress_bar_bounds.set_x(GetContentsBounds().x() + |
324 kProgressBarHorizontalPadding); | 317 kProgressBarHorizontalPadding); |
325 progress_bar_bounds.set_y(title_bounds.y()); | 318 progress_bar_bounds.set_y(title_bounds.y()); |
326 progress_bar_->SetBoundsRect(progress_bar_bounds); | 319 progress_bar_->SetBoundsRect(progress_bar_bounds); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 } | 511 } |
519 | 512 |
520 gfx::Rect AppListItemView::GetIconBoundsForTargetViewBounds( | 513 gfx::Rect AppListItemView::GetIconBoundsForTargetViewBounds( |
521 const gfx::Rect& target_bounds) { | 514 const gfx::Rect& target_bounds) { |
522 gfx::Rect rect(target_bounds); | 515 gfx::Rect rect(target_bounds); |
523 | 516 |
524 const int left_right_padding = | 517 const int left_right_padding = |
525 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); | 518 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); |
526 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | 519 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); |
527 | 520 |
528 gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), icon_size_.height()); | 521 gfx::Rect icon_bounds( |
529 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); | 522 rect.x(), rect.y(), rect.width(), kPreferredIconDimension); |
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 |