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_node_data.h" | 11 #include "ui/accessibility/ax_node_data.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_features.h" |
13 #include "ui/app_list/app_list_folder_item.h" | 14 #include "ui/app_list/app_list_folder_item.h" |
14 #include "ui/app_list/app_list_item.h" | 15 #include "ui/app_list/app_list_item.h" |
15 #include "ui/app_list/app_list_switches.h" | 16 #include "ui/app_list/app_list_switches.h" |
16 #include "ui/app_list/views/apps_grid_view.h" | 17 #include "ui/app_list/views/apps_grid_view.h" |
17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
20 #include "ui/compositor/scoped_layer_animation_settings.h" | 21 #include "ui/compositor/scoped_layer_animation_settings.h" |
21 #include "ui/gfx/animation/throb_animation.h" | 22 #include "ui/gfx/animation/throb_animation.h" |
22 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
23 #include "ui/gfx/font_list.h" | 24 #include "ui/gfx/font_list.h" |
24 #include "ui/gfx/geometry/point.h" | 25 #include "ui/gfx/geometry/point.h" |
25 #include "ui/gfx/geometry/vector2d.h" | 26 #include "ui/gfx/geometry/vector2d.h" |
26 #include "ui/gfx/image/image_skia_operations.h" | 27 #include "ui/gfx/image/image_skia_operations.h" |
27 #include "ui/gfx/shadow_value.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/strings/grit/ui_strings.h" | 30 #include "ui/strings/grit/ui_strings.h" |
30 #include "ui/views/background.h" | 31 #include "ui/views/background.h" |
31 #include "ui/views/controls/image_view.h" | 32 #include "ui/views/controls/image_view.h" |
32 #include "ui/views/controls/label.h" | 33 #include "ui/views/controls/label.h" |
33 #include "ui/views/controls/menu/menu_runner.h" | 34 #include "ui/views/controls/menu/menu_runner.h" |
34 #include "ui/views/controls/progress_bar.h" | 35 #include "ui/views/controls/progress_bar.h" |
35 #include "ui/views/drag_controller.h" | 36 #include "ui/views/drag_controller.h" |
36 | 37 |
37 namespace app_list { | 38 namespace app_list { |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 const int kTopPadding = 18; | 42 constexpr int kTopPadding = 18; |
42 const int kIconTitleSpacing = 6; | 43 constexpr int kIconTitleSpacing = 6; |
43 | 44 |
44 // Radius of the folder dropping preview circle. | 45 // Radius of the folder dropping preview circle. |
45 const int kFolderPreviewRadius = 40; | 46 constexpr int kFolderPreviewRadius = 40; |
46 | 47 |
47 const int kLeftRightPaddingChars = 1; | 48 constexpr int kLeftRightPaddingChars = 1; |
48 | 49 |
49 // 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. |
50 const int kMouseDragUIDelayInMs = 200; | 51 constexpr int kMouseDragUIDelayInMs = 200; |
51 | 52 |
52 gfx::FontList GetFontList() { | 53 gfx::FontList GetFontList() { |
53 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 54 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
54 return rb.GetFontList(kItemTextFontStyle); | 55 return rb.GetFontList(kItemTextFontStyle); |
55 } | 56 } |
56 | 57 |
57 } // namespace | 58 } // namespace |
58 | 59 |
59 // static | 60 // static |
60 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; | 61 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; |
61 | 62 |
62 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, | 63 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, |
63 AppListItem* item) | 64 AppListItem* item) |
64 : CustomButton(apps_grid_view), | 65 : CustomButton(apps_grid_view), |
65 is_folder_(item->GetItemType() == AppListFolderItem::kItemType), | 66 is_folder_(item->GetItemType() == AppListFolderItem::kItemType), |
66 is_in_folder_(item->IsInFolder()), | 67 is_in_folder_(item->IsInFolder()), |
67 item_weak_(item), | 68 item_weak_(item), |
68 apps_grid_view_(apps_grid_view), | 69 apps_grid_view_(apps_grid_view), |
69 icon_(new views::ImageView), | 70 icon_(new views::ImageView), |
70 title_(new views::Label), | 71 title_(new views::Label), |
71 progress_bar_(new views::ProgressBar), | 72 progress_bar_(new views::ProgressBar), |
72 ui_state_(UI_STATE_NORMAL), | |
73 touch_dragging_(false), | |
74 shadow_animator_(this), | 73 shadow_animator_(this), |
75 is_installing_(false), | 74 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { |
76 is_highlighted_(false) { | |
77 shadow_animator_.animation()->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); | 75 shadow_animator_.animation()->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); |
78 shadow_animator_.SetStartAndEndShadows(IconStartShadows(), IconEndShadows()); | 76 shadow_animator_.SetStartAndEndShadows(IconStartShadows(), IconEndShadows()); |
79 | 77 |
80 icon_->set_can_process_events_within_subtree(false); | 78 icon_->set_can_process_events_within_subtree(false); |
81 icon_->SetVerticalAlignment(views::ImageView::LEADING); | 79 icon_->SetVerticalAlignment(views::ImageView::LEADING); |
82 | 80 |
83 title_->SetBackgroundColor(0); | 81 title_->SetBackgroundColor(SK_ColorTRANSPARENT); |
84 title_->SetAutoColorReadabilityEnabled(false); | 82 title_->SetAutoColorReadabilityEnabled(false); |
85 title_->SetEnabledColor(kGridTitleColor); | |
86 title_->SetHandlesTooltips(false); | 83 title_->SetHandlesTooltips(false); |
87 | 84 |
88 static const gfx::FontList font_list = GetFontList(); | 85 if (is_fullscreen_app_list_enabled_) { |
89 title_->SetFontList(font_list); | 86 const gfx::FontList& base_font = |
90 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 87 ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 88 ui::ResourceBundle::BaseFont); |
| 89 title_->SetFontList(base_font.DeriveWithSizeDelta(1)); |
| 90 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 91 title_->SetEnabledColor(kGridTitleColorFullscreen); |
| 92 } else { |
| 93 const gfx::FontList& font_list = GetFontList(); |
| 94 title_->SetFontList(font_list); |
| 95 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 96 title_->SetEnabledColor(kGridTitleColor); |
| 97 } |
91 SetTitleSubpixelAA(); | 98 SetTitleSubpixelAA(); |
92 | 99 |
93 AddChildView(icon_); | 100 AddChildView(icon_); |
94 AddChildView(title_); | 101 AddChildView(title_); |
95 AddChildView(progress_bar_); | 102 AddChildView(progress_bar_); |
96 | 103 |
97 SetIcon(item->icon()); | 104 SetIcon(item->icon()); |
98 SetItemName(base::UTF8ToUTF16(item->GetDisplayName()), | 105 SetItemName(base::UTF8ToUTF16(item->GetDisplayName()), |
99 base::UTF8ToUTF16(item->name())); | 106 base::UTF8ToUTF16(item->name())); |
100 SetItemIsInstalling(item->is_installing()); | 107 SetItemIsInstalling(item->is_installing()); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 313 } |
307 return true; | 314 return true; |
308 } | 315 } |
309 | 316 |
310 const char* AppListItemView::GetClassName() const { | 317 const char* AppListItemView::GetClassName() const { |
311 return kViewClassName; | 318 return kViewClassName; |
312 } | 319 } |
313 | 320 |
314 void AppListItemView::Layout() { | 321 void AppListItemView::Layout() { |
315 gfx::Rect rect(GetContentsBounds()); | 322 gfx::Rect rect(GetContentsBounds()); |
| 323 if (rect.IsEmpty()) |
| 324 return; |
316 | 325 |
317 const int left_right_padding = | 326 if (is_fullscreen_app_list_enabled_) { |
318 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); | 327 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); |
319 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | |
320 const int y = rect.y(); | |
321 | 328 |
322 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); | 329 rect.Inset(kGridTitleHorizontalPadding, |
| 330 kGridIconTopPadding + kGridIconDimension + kGridTitleSpacing, |
| 331 kGridTitleHorizontalPadding, 0); |
| 332 rect.set_height(title_->GetPreferredSize().height()); |
| 333 title_->SetBoundsRect(rect); |
| 334 SetTitleSubpixelAA(); |
323 | 335 |
324 const gfx::Size title_size = title_->GetPreferredSize(); | 336 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); |
325 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, | 337 progress_bar_bounds.set_x( |
326 y + kGridIconDimension + kIconTitleSpacing, | 338 (GetContentsBounds().width() - progress_bar_bounds.width()) / 2); |
327 title_size.width(), title_size.height()); | 339 progress_bar_bounds.set_y(rect.y()); |
328 title_bounds.Intersect(rect); | 340 progress_bar_->SetBoundsRect(progress_bar_bounds); |
329 title_->SetBoundsRect(title_bounds); | 341 } else { |
330 SetTitleSubpixelAA(); | 342 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); |
331 | 343 |
332 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); | 344 const int left_right_padding = |
333 progress_bar_bounds.set_x( | 345 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); |
334 (GetContentsBounds().width() - progress_bar_bounds.width()) / 2); | 346 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); |
335 progress_bar_bounds.set_y(title_bounds.y()); | 347 const int y = rect.y(); |
336 progress_bar_->SetBoundsRect(progress_bar_bounds); | 348 |
| 349 const gfx::Size title_size = title_->GetPreferredSize(); |
| 350 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, |
| 351 y + kGridIconDimension + kIconTitleSpacing, |
| 352 title_size.width(), title_size.height()); |
| 353 title_bounds.Intersect(rect); |
| 354 title_->SetBoundsRect(title_bounds); |
| 355 SetTitleSubpixelAA(); |
| 356 |
| 357 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); |
| 358 progress_bar_bounds.set_x( |
| 359 (GetContentsBounds().width() - progress_bar_bounds.width()) / 2); |
| 360 progress_bar_bounds.set_y(title_bounds.y()); |
| 361 progress_bar_->SetBoundsRect(progress_bar_bounds); |
| 362 } |
| 363 } |
| 364 |
| 365 gfx::Size AppListItemView::CalculatePreferredSize() const { |
| 366 if (is_fullscreen_app_list_enabled_) { |
| 367 return gfx::Size(kGridTileWidth, kGridTileHeight); |
| 368 } |
| 369 |
| 370 return views::View::CalculatePreferredSize(); |
337 } | 371 } |
338 | 372 |
339 bool AppListItemView::OnKeyPressed(const ui::KeyEvent& event) { | 373 bool AppListItemView::OnKeyPressed(const ui::KeyEvent& event) { |
340 // Disable space key to press the button. The keyboard events received | 374 // Disable space key to press the button. The keyboard events received |
341 // by this view are forwarded from a Textfield (SearchBoxView) and key | 375 // by this view are forwarded from a Textfield (SearchBoxView) and key |
342 // released events are not forwarded. This leaves the button in pressed | 376 // released events are not forwarded. This leaves the button in pressed |
343 // state. | 377 // state. |
344 if (event.key_code() == ui::VKEY_SPACE) | 378 if (event.key_code() == ui::VKEY_SPACE) |
345 return false; | 379 return false; |
346 | 380 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 return icon_->bounds(); | 487 return icon_->bounds(); |
454 } | 488 } |
455 | 489 |
456 void AppListItemView::SetDragUIState() { | 490 void AppListItemView::SetDragUIState() { |
457 SetUIState(UI_STATE_DRAGGING); | 491 SetUIState(UI_STATE_DRAGGING); |
458 } | 492 } |
459 | 493 |
460 gfx::Rect AppListItemView::GetIconBoundsForTargetViewBounds( | 494 gfx::Rect AppListItemView::GetIconBoundsForTargetViewBounds( |
461 const gfx::Rect& target_bounds) { | 495 const gfx::Rect& target_bounds) { |
462 gfx::Rect rect(target_bounds); | 496 gfx::Rect rect(target_bounds); |
463 rect.Inset(0, kTopPadding, 0, 0); | 497 rect.Inset( |
| 498 0, is_fullscreen_app_list_enabled_ ? kGridIconTopPadding : kTopPadding, 0, |
| 499 0); |
464 rect.set_height(icon_->GetImage().height()); | 500 rect.set_height(icon_->GetImage().height()); |
465 rect.ClampToCenteredSize(icon_->GetImage().size()); | 501 rect.ClampToCenteredSize(icon_->GetImage().size()); |
466 return rect; | 502 return rect; |
467 } | 503 } |
468 | 504 |
469 void AppListItemView::SetTitleSubpixelAA() { | 505 void AppListItemView::SetTitleSubpixelAA() { |
470 // TODO(tapted): Enable AA for folders as well, taking care to play nice with | 506 // TODO(tapted): Enable AA for folders as well, taking care to play nice with |
471 // the folder bubble animation. | 507 // the folder bubble animation. |
472 bool enable_aa = !is_in_folder_ && ui_state_ == UI_STATE_NORMAL && | 508 bool enable_aa = !is_in_folder_ && ui_state_ == UI_STATE_NORMAL && |
473 !is_highlighted_ && !apps_grid_view_->IsSelectedView(this) && | 509 !is_highlighted_ && !apps_grid_view_->IsSelectedView(this) && |
(...skipping 30 matching lines...) Expand all Loading... |
504 SetItemPercentDownloaded(item_weak_->percent_downloaded()); | 540 SetItemPercentDownloaded(item_weak_->percent_downloaded()); |
505 } | 541 } |
506 | 542 |
507 void AppListItemView::ItemBeingDestroyed() { | 543 void AppListItemView::ItemBeingDestroyed() { |
508 DCHECK(item_weak_); | 544 DCHECK(item_weak_); |
509 item_weak_->RemoveObserver(this); | 545 item_weak_->RemoveObserver(this); |
510 item_weak_ = NULL; | 546 item_weak_ = NULL; |
511 } | 547 } |
512 | 548 |
513 } // namespace app_list | 549 } // namespace app_list |
OLD | NEW |