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 "build/build_config.h" | 10 #include "build/build_config.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" | |
18 #include "ui/app_list/views/progress_bar_view.h" | 17 #include "ui/app_list/views/progress_bar_view.h" |
19 #include "ui/base/dragdrop/drag_utils.h" | 18 #include "ui/base/dragdrop/drag_utils.h" |
20 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/base/ui_base_switches_util.h" | 21 #include "ui/base/ui_base_switches_util.h" |
23 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" |
24 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
25 #include "ui/gfx/animation/throb_animation.h" | 24 #include "ui/gfx/animation/throb_animation.h" |
26 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/font_list.h" | 26 #include "ui/gfx/font_list.h" |
(...skipping 14 matching lines...) Expand all Loading... |
42 namespace { | 41 namespace { |
43 | 42 |
44 const int kTopPadding = 18; | 43 const int kTopPadding = 18; |
45 const int kIconTitleSpacing = 6; | 44 const int kIconTitleSpacing = 6; |
46 | 45 |
47 // Radius of the folder dropping preview circle. | 46 // Radius of the folder dropping preview circle. |
48 const int kFolderPreviewRadius = 40; | 47 const int kFolderPreviewRadius = 40; |
49 | 48 |
50 const int kLeftRightPaddingChars = 1; | 49 const int kLeftRightPaddingChars = 1; |
51 | 50 |
52 #if !defined(OS_WIN) | |
53 // Scale to transform the icon when a drag starts. | |
54 const float kDraggingIconScale = 1.5f; | |
55 #endif | |
56 | |
57 // Delay in milliseconds of when the dragging UI should be shown for mouse drag. | 51 // Delay in milliseconds of when the dragging UI should be shown for mouse drag. |
58 const int kMouseDragUIDelayInMs = 200; | 52 const int kMouseDragUIDelayInMs = 200; |
59 | 53 |
60 gfx::FontList GetFontList() { | 54 gfx::FontList GetFontList() { |
61 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 55 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
62 const gfx::FontList& font_list = rb.GetFontList(kItemTextFontStyle); | 56 const gfx::FontList& font_list = rb.GetFontList(kItemTextFontStyle); |
63 // The font is different on each platform. The font size is adjusted on some | 57 // The font is different on each platform. The font size is adjusted on some |
64 // platforms to keep a consistent look. | 58 // platforms to keep a consistent look. |
65 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 59 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
66 // Reducing the font size by 2 makes it the same as the Windows font size. | 60 // Reducing the font size by 2 makes it the same as the Windows font size. |
(...skipping 10 matching lines...) Expand all Loading... |
77 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; | 71 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; |
78 | 72 |
79 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, | 73 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, |
80 AppListItem* item) | 74 AppListItem* item) |
81 : CustomButton(apps_grid_view), | 75 : CustomButton(apps_grid_view), |
82 is_folder_(item->GetItemType() == AppListFolderItem::kItemType), | 76 is_folder_(item->GetItemType() == AppListFolderItem::kItemType), |
83 is_in_folder_(item->IsInFolder()), | 77 is_in_folder_(item->IsInFolder()), |
84 item_weak_(item), | 78 item_weak_(item), |
85 apps_grid_view_(apps_grid_view), | 79 apps_grid_view_(apps_grid_view), |
86 icon_(new views::ImageView), | 80 icon_(new views::ImageView), |
87 title_(new CachedLabel), | 81 title_(new views::Label), |
88 progress_bar_(new ProgressBarView), | 82 progress_bar_(new ProgressBarView), |
89 ui_state_(UI_STATE_NORMAL), | 83 ui_state_(UI_STATE_NORMAL), |
90 touch_dragging_(false), | 84 touch_dragging_(false), |
91 shadow_animator_(this), | 85 shadow_animator_(this), |
92 is_installing_(false), | 86 is_installing_(false), |
93 is_highlighted_(false) { | 87 is_highlighted_(false) { |
94 shadow_animator_.animation()->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); | 88 shadow_animator_.animation()->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); |
95 shadow_animator_.SetStartAndEndShadows(IconStartShadows(), IconEndShadows()); | 89 shadow_animator_.SetStartAndEndShadows(IconStartShadows(), IconEndShadows()); |
96 | 90 |
97 icon_->set_interactive(false); | 91 icon_->set_interactive(false); |
98 icon_->SetVerticalAlignment(views::ImageView::LEADING); | 92 icon_->SetVerticalAlignment(views::ImageView::LEADING); |
99 | 93 |
100 title_->SetBackgroundColor(0); | 94 title_->SetBackgroundColor(0); |
101 title_->SetAutoColorReadabilityEnabled(false); | 95 title_->SetAutoColorReadabilityEnabled(false); |
102 title_->SetEnabledColor(kGridTitleColor); | 96 title_->SetEnabledColor(kGridTitleColor); |
103 title_->SetHandlesTooltips(false); | 97 title_->SetHandlesTooltips(false); |
104 | 98 |
105 static const gfx::FontList font_list = GetFontList(); | 99 static const gfx::FontList font_list = GetFontList(); |
106 title_->SetFontList(font_list); | 100 title_->SetFontList(font_list); |
107 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 101 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
108 title_->Invalidate(); | |
109 SetTitleSubpixelAA(); | 102 SetTitleSubpixelAA(); |
110 | 103 |
111 AddChildView(icon_); | 104 AddChildView(icon_); |
112 AddChildView(title_); | 105 AddChildView(title_); |
113 AddChildView(progress_bar_); | 106 AddChildView(progress_bar_); |
114 | 107 |
115 SetIcon(item->icon()); | 108 SetIcon(item->icon()); |
116 SetItemName(base::UTF8ToUTF16(item->GetDisplayName()), | 109 SetItemName(base::UTF8ToUTF16(item->GetDisplayName()), |
117 base::UTF8ToUTF16(item->name())); | 110 base::UTF8ToUTF16(item->name())); |
118 SetItemIsInstalling(item->is_installing()); | 111 SetItemIsInstalling(item->is_installing()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 title_->SetVisible(!is_installing_); | 147 title_->SetVisible(!is_installing_); |
155 progress_bar_->SetVisible(is_installing_); | 148 progress_bar_->SetVisible(is_installing_); |
156 break; | 149 break; |
157 case UI_STATE_DRAGGING: | 150 case UI_STATE_DRAGGING: |
158 title_->SetVisible(false); | 151 title_->SetVisible(false); |
159 progress_bar_->SetVisible(false); | 152 progress_bar_->SetVisible(false); |
160 break; | 153 break; |
161 case UI_STATE_DROPPING_IN_FOLDER: | 154 case UI_STATE_DROPPING_IN_FOLDER: |
162 break; | 155 break; |
163 } | 156 } |
164 #if !defined(OS_WIN) | |
165 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); | |
166 switch (ui_state_) { | |
167 case UI_STATE_NORMAL: | |
168 layer()->SetTransform(gfx::Transform()); | |
169 break; | |
170 case UI_STATE_DRAGGING: { | |
171 const gfx::Rect bounds(layer()->bounds().size()); | |
172 layer()->SetTransform(gfx::GetScaleTransform( | |
173 bounds.CenterPoint(), | |
174 kDraggingIconScale)); | |
175 break; | |
176 } | |
177 case UI_STATE_DROPPING_IN_FOLDER: | |
178 break; | |
179 } | |
180 #endif // !OS_WIN | |
181 | 157 |
182 SetTitleSubpixelAA(); | 158 SetTitleSubpixelAA(); |
183 SchedulePaint(); | 159 SchedulePaint(); |
184 } | 160 } |
185 | 161 |
186 void AppListItemView::SetTouchDragging(bool touch_dragging) { | 162 void AppListItemView::SetTouchDragging(bool touch_dragging) { |
187 if (touch_dragging_ == touch_dragging) | 163 if (touch_dragging_ == touch_dragging) |
188 return; | 164 return; |
189 | 165 |
190 touch_dragging_ = touch_dragging; | 166 touch_dragging_ = touch_dragging; |
191 SetState(STATE_NORMAL); | 167 SetState(STATE_NORMAL); |
192 SetUIState(touch_dragging_ ? UI_STATE_DRAGGING : UI_STATE_NORMAL); | 168 SetUIState(touch_dragging_ ? UI_STATE_DRAGGING : UI_STATE_NORMAL); |
193 } | 169 } |
194 | 170 |
195 void AppListItemView::OnMouseDragTimer() { | 171 void AppListItemView::OnMouseDragTimer() { |
196 DCHECK(apps_grid_view_->IsDraggedView(this)); | 172 DCHECK(apps_grid_view_->IsDraggedView(this)); |
197 SetUIState(UI_STATE_DRAGGING); | 173 SetUIState(UI_STATE_DRAGGING); |
198 } | 174 } |
199 | 175 |
200 void AppListItemView::Prerender() { | |
201 title_->PaintToBackingImage(); | |
202 } | |
203 | |
204 void AppListItemView::CancelContextMenu() { | 176 void AppListItemView::CancelContextMenu() { |
205 if (context_menu_runner_) | 177 if (context_menu_runner_) |
206 context_menu_runner_->Cancel(); | 178 context_menu_runner_->Cancel(); |
207 } | 179 } |
208 | 180 |
209 gfx::ImageSkia AppListItemView::GetDragImage() { | 181 gfx::ImageSkia AppListItemView::GetDragImage() { |
210 return icon_->GetImage(); | 182 return icon_->GetImage(); |
211 } | 183 } |
212 | 184 |
213 void AppListItemView::OnDragEnded() { | 185 void AppListItemView::OnDragEnded() { |
214 mouse_drag_timer_.Stop(); | 186 mouse_drag_timer_.Stop(); |
215 SetUIState(UI_STATE_NORMAL); | 187 SetUIState(UI_STATE_NORMAL); |
216 } | 188 } |
217 | 189 |
218 gfx::Point AppListItemView::GetDragImageOffset() { | 190 gfx::Point AppListItemView::GetDragImageOffset() { |
219 gfx::Point image = icon_->GetImageBounds().origin(); | 191 gfx::Point image = icon_->GetImageBounds().origin(); |
220 return gfx::Point(icon_->x() + image.x(), icon_->y() + image.y()); | 192 return gfx::Point(icon_->x() + image.x(), icon_->y() + image.y()); |
221 } | 193 } |
222 | 194 |
223 void AppListItemView::SetAsAttemptedFolderTarget(bool is_target_folder) { | 195 void AppListItemView::SetAsAttemptedFolderTarget(bool is_target_folder) { |
224 if (is_target_folder) | 196 if (is_target_folder) |
225 SetUIState(UI_STATE_DROPPING_IN_FOLDER); | 197 SetUIState(UI_STATE_DROPPING_IN_FOLDER); |
226 else | 198 else |
227 SetUIState(UI_STATE_NORMAL); | 199 SetUIState(UI_STATE_NORMAL); |
228 } | 200 } |
229 | 201 |
230 void AppListItemView::SetItemName(const base::string16& display_name, | 202 void AppListItemView::SetItemName(const base::string16& display_name, |
231 const base::string16& full_name) { | 203 const base::string16& full_name) { |
232 title_->SetText(display_name); | 204 title_->SetText(display_name); |
233 title_->Invalidate(); | |
234 | 205 |
235 tooltip_text_ = display_name == full_name ? base::string16() : full_name; | 206 tooltip_text_ = display_name == full_name ? base::string16() : full_name; |
236 | 207 |
237 // Use full name for accessibility. | 208 // Use full name for accessibility. |
238 SetAccessibleName( | 209 SetAccessibleName( |
239 is_folder_ ? l10n_util::GetStringFUTF16( | 210 is_folder_ ? l10n_util::GetStringFUTF16( |
240 IDS_APP_LIST_FOLDER_BUTTON_ACCESSIBILE_NAME, full_name) | 211 IDS_APP_LIST_FOLDER_BUTTON_ACCESSIBILE_NAME, full_name) |
241 : full_name); | 212 : full_name); |
242 Layout(); | 213 Layout(); |
243 } | 214 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 return false; | 373 return false; |
403 | 374 |
404 return CustomButton::OnKeyPressed(event); | 375 return CustomButton::OnKeyPressed(event); |
405 } | 376 } |
406 | 377 |
407 void AppListItemView::OnMouseReleased(const ui::MouseEvent& event) { | 378 void AppListItemView::OnMouseReleased(const ui::MouseEvent& event) { |
408 CustomButton::OnMouseReleased(event); | 379 CustomButton::OnMouseReleased(event); |
409 apps_grid_view_->EndDrag(false); | 380 apps_grid_view_->EndDrag(false); |
410 } | 381 } |
411 | 382 |
412 void AppListItemView::OnMouseCaptureLost() { | |
413 // We don't cancel the dag on mouse capture lost for windows as entering a | |
414 // synchronous drag causes mouse capture to be lost and pressing escape | |
415 // dismisses the app list anyway. | |
416 #if !defined(OS_WIN) | |
417 CustomButton::OnMouseCaptureLost(); | |
418 apps_grid_view_->EndDrag(true); | |
419 #endif | |
420 } | |
421 | |
422 bool AppListItemView::OnMouseDragged(const ui::MouseEvent& event) { | 383 bool AppListItemView::OnMouseDragged(const ui::MouseEvent& event) { |
423 CustomButton::OnMouseDragged(event); | 384 CustomButton::OnMouseDragged(event); |
424 if (apps_grid_view_->IsDraggedView(this)) { | 385 if (apps_grid_view_->IsDraggedView(this)) { |
425 // If the drag is no longer happening, it could be because this item | 386 // If the drag is no longer happening, it could be because this item |
426 // got removed, in which case this item has been destroyed. So, bail out | 387 // got removed, in which case this item has been destroyed. So, bail out |
427 // now as there will be nothing else to do anyway as | 388 // now as there will be nothing else to do anyway as |
428 // apps_grid_view_->dragging() will be false. | 389 // apps_grid_view_->dragging() will be false. |
429 if (!apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, event)) | 390 if (!apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, event)) |
430 return true; | 391 return true; |
431 } | 392 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 if (enable_aa) { | 505 if (enable_aa) { |
545 title_->SetBackgroundColor(app_list::kLabelBackgroundColor); | 506 title_->SetBackgroundColor(app_list::kLabelBackgroundColor); |
546 title_->set_background(views::Background::CreateSolidBackground( | 507 title_->set_background(views::Background::CreateSolidBackground( |
547 app_list::kLabelBackgroundColor)); | 508 app_list::kLabelBackgroundColor)); |
548 } else { | 509 } else { |
549 // In other cases, keep the background transparent to ensure correct | 510 // In other cases, keep the background transparent to ensure correct |
550 // interactions with animations. This will temporarily disable subpixel AA. | 511 // interactions with animations. This will temporarily disable subpixel AA. |
551 title_->SetBackgroundColor(0); | 512 title_->SetBackgroundColor(0); |
552 title_->set_background(NULL); | 513 title_->set_background(NULL); |
553 } | 514 } |
554 title_->Invalidate(); | |
555 title_->SchedulePaint(); | 515 title_->SchedulePaint(); |
556 } | 516 } |
557 | 517 |
558 void AppListItemView::ItemIconChanged() { | 518 void AppListItemView::ItemIconChanged() { |
559 SetIcon(item_weak_->icon()); | 519 SetIcon(item_weak_->icon()); |
560 } | 520 } |
561 | 521 |
562 void AppListItemView::ItemNameChanged() { | 522 void AppListItemView::ItemNameChanged() { |
563 SetItemName(base::UTF8ToUTF16(item_weak_->GetDisplayName()), | 523 SetItemName(base::UTF8ToUTF16(item_weak_->GetDisplayName()), |
564 base::UTF8ToUTF16(item_weak_->name())); | 524 base::UTF8ToUTF16(item_weak_->name())); |
565 } | 525 } |
566 | 526 |
567 void AppListItemView::ItemIsInstallingChanged() { | 527 void AppListItemView::ItemIsInstallingChanged() { |
568 SetItemIsInstalling(item_weak_->is_installing()); | 528 SetItemIsInstalling(item_weak_->is_installing()); |
569 } | 529 } |
570 | 530 |
571 void AppListItemView::ItemPercentDownloadedChanged() { | 531 void AppListItemView::ItemPercentDownloadedChanged() { |
572 SetItemPercentDownloaded(item_weak_->percent_downloaded()); | 532 SetItemPercentDownloaded(item_weak_->percent_downloaded()); |
573 } | 533 } |
574 | 534 |
575 void AppListItemView::ItemBeingDestroyed() { | 535 void AppListItemView::ItemBeingDestroyed() { |
576 DCHECK(item_weak_); | 536 DCHECK(item_weak_); |
577 item_weak_->RemoveObserver(this); | 537 item_weak_->RemoveObserver(this); |
578 item_weak_ = NULL; | 538 item_weak_ = NULL; |
579 } | 539 } |
580 | 540 |
581 } // namespace app_list | 541 } // namespace app_list |
OLD | NEW |