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 "ash/launcher/launcher_view.h" | 5 #include "ash/launcher/launcher_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/launcher/app_list_button.h" | 9 #include "ash/launcher/app_list_button.h" |
| 10 #include "ash/launcher/app_placeholder_view.h" |
10 #include "ash/launcher/launcher_button.h" | 11 #include "ash/launcher/launcher_button.h" |
11 #include "ash/launcher/launcher_delegate.h" | 12 #include "ash/launcher/launcher_delegate.h" |
12 #include "ash/launcher/launcher_icon_observer.h" | 13 #include "ash/launcher/launcher_icon_observer.h" |
13 #include "ash/launcher/launcher_model.h" | 14 #include "ash/launcher/launcher_model.h" |
14 #include "ash/launcher/launcher_tooltip_manager.h" | 15 #include "ash/launcher/launcher_tooltip_manager.h" |
15 #include "ash/launcher/overflow_bubble.h" | 16 #include "ash/launcher/overflow_bubble.h" |
16 #include "ash/launcher/overflow_button.h" | 17 #include "ash/launcher/overflow_button.h" |
17 #include "ash/launcher/tabbed_launcher_button.h" | 18 #include "ash/launcher/tabbed_launcher_button.h" |
18 #include "ash/shell.h" | 19 #include "ash/shell.h" |
19 #include "ash/shell_delegate.h" | 20 #include "ash/shell_delegate.h" |
20 #include "base/auto_reset.h" | 21 #include "base/auto_reset.h" |
| 22 #include "base/memory/scoped_ptr.h" |
21 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
22 #include "grit/ash_strings.h" | 24 #include "grit/ash_strings.h" |
23 #include "grit/ui_resources.h" | 25 #include "grit/ui_resources.h" |
24 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
25 #include "ui/base/animation/animation.h" | 27 #include "ui/base/animation/animation.h" |
26 #include "ui/base/animation/throb_animation.h" | 28 #include "ui/base/animation/throb_animation.h" |
27 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/base/models/simple_menu_model.h" | 30 #include "ui/base/models/simple_menu_model.h" |
29 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
30 #include "ui/compositor/layer.h" | 32 #include "ui/compositor/layer.h" |
31 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
32 #include "ui/views/animation/bounds_animator.h" | 34 #include "ui/views/animation/bounds_animator.h" |
33 #include "ui/views/border.h" | 35 #include "ui/views/border.h" |
34 #include "ui/views/controls/button/image_button.h" | |
35 #include "ui/views/controls/menu/menu_model_adapter.h" | 36 #include "ui/views/controls/menu/menu_model_adapter.h" |
36 #include "ui/views/controls/menu/menu_runner.h" | 37 #include "ui/views/controls/menu/menu_runner.h" |
37 #include "ui/views/focus/focus_search.h" | 38 #include "ui/views/focus/focus_search.h" |
38 #include "ui/views/view_model.h" | 39 #include "ui/views/view_model.h" |
39 #include "ui/views/view_model_utils.h" | 40 #include "ui/views/view_model_utils.h" |
40 #include "ui/views/widget/root_view.h" | 41 #include "ui/views/widget/root_view.h" |
41 #include "ui/views/widget/widget.h" | 42 #include "ui/views/widget/widget.h" |
42 | 43 |
43 using ui::Animation; | 44 using ui::Animation; |
44 using views::View; | 45 using views::View; |
45 | 46 |
46 namespace ash { | 47 namespace ash { |
47 namespace internal { | 48 namespace internal { |
48 | 49 |
49 // Default amount content is inset on the left edge. | 50 // Default amount content is inset on the left edge. |
50 static const int kDefaultLeadingInset = 8; | 51 const int kDefaultLeadingInset = 8; |
51 | 52 |
52 // Minimum distance before drag starts. | 53 // Minimum distance before drag starts. |
53 static const int kMinimumDragDistance = 8; | 54 const int kMinimumDragDistance = 8; |
54 | 55 |
55 // Size between the buttons. | 56 // Size between the buttons. |
56 static const int kButtonSpacing = 4; | 57 const int kButtonSpacing = 4; |
57 | 58 |
58 namespace { | 59 namespace { |
59 | 60 |
60 // Custom FocusSearch used to navigate the launcher in the order items are in | 61 // Custom FocusSearch used to navigate the launcher in the order items are in |
61 // the ViewModel. | 62 // the ViewModel. |
62 class LauncherFocusSearch : public views::FocusSearch { | 63 class LauncherFocusSearch : public views::FocusSearch { |
63 public: | 64 public: |
64 explicit LauncherFocusSearch(views::ViewModel* view_model) | 65 explicit LauncherFocusSearch(views::ViewModel* view_model) |
65 : FocusSearch(NULL, true, true), | 66 : FocusSearch(NULL, true, true), |
66 view_model_(view_model) {} | 67 view_model_(view_model) {} |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); | 171 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); |
171 }; | 172 }; |
172 | 173 |
173 void ReflectItemStatus(const ash::LauncherItem& item, | 174 void ReflectItemStatus(const ash::LauncherItem& item, |
174 LauncherButton* button) { | 175 LauncherButton* button) { |
175 switch (item.status) { | 176 switch (item.status) { |
176 case STATUS_CLOSED: | 177 case STATUS_CLOSED: |
177 button->ClearState(LauncherButton::STATE_ACTIVE); | 178 button->ClearState(LauncherButton::STATE_ACTIVE); |
178 button->ClearState(LauncherButton::STATE_RUNNING); | 179 button->ClearState(LauncherButton::STATE_RUNNING); |
179 button->ClearState(LauncherButton::STATE_ATTENTION); | 180 button->ClearState(LauncherButton::STATE_ATTENTION); |
180 button->ClearState(LauncherButton::STATE_PENDING); | |
181 break; | 181 break; |
182 case STATUS_RUNNING: | 182 case STATUS_RUNNING: |
183 button->ClearState(LauncherButton::STATE_ACTIVE); | 183 button->ClearState(LauncherButton::STATE_ACTIVE); |
184 button->AddState(LauncherButton::STATE_RUNNING); | 184 button->AddState(LauncherButton::STATE_RUNNING); |
185 button->ClearState(LauncherButton::STATE_ATTENTION); | 185 button->ClearState(LauncherButton::STATE_ATTENTION); |
186 button->ClearState(LauncherButton::STATE_PENDING); | |
187 break; | 186 break; |
188 case STATUS_ACTIVE: | 187 case STATUS_ACTIVE: |
189 button->AddState(LauncherButton::STATE_ACTIVE); | 188 button->AddState(LauncherButton::STATE_ACTIVE); |
190 button->ClearState(LauncherButton::STATE_RUNNING); | 189 button->ClearState(LauncherButton::STATE_RUNNING); |
191 button->ClearState(LauncherButton::STATE_ATTENTION); | 190 button->ClearState(LauncherButton::STATE_ATTENTION); |
192 button->ClearState(LauncherButton::STATE_PENDING); | |
193 break; | 191 break; |
194 case STATUS_ATTENTION: | 192 case STATUS_ATTENTION: |
195 button->ClearState(LauncherButton::STATE_ACTIVE); | 193 button->ClearState(LauncherButton::STATE_ACTIVE); |
196 button->ClearState(LauncherButton::STATE_RUNNING); | 194 button->ClearState(LauncherButton::STATE_RUNNING); |
197 button->AddState(LauncherButton::STATE_ATTENTION); | 195 button->AddState(LauncherButton::STATE_ATTENTION); |
198 button->ClearState(LauncherButton::STATE_PENDING); | |
199 break; | |
200 case STATUS_IS_PENDING: | |
201 button->ClearState(LauncherButton::STATE_ACTIVE); | |
202 button->ClearState(LauncherButton::STATE_RUNNING); | |
203 button->ClearState(LauncherButton::STATE_ATTENTION); | |
204 button->AddState(LauncherButton::STATE_PENDING); | |
205 break; | 196 break; |
206 } | 197 } |
207 } | 198 } |
208 | 199 |
209 } // namespace | 200 } // namespace |
210 | 201 |
211 // AnimationDelegate used when inserting a new item. This steadily decreased the | 202 // AnimationDelegate used when inserting a new item. This steadily decreased the |
212 // opacity of the layer as the animation progress. | 203 // opacity of the layer as the animation progress. |
213 class LauncherView::FadeOutAnimationDelegate | 204 class LauncherView::FadeOutAnimationDelegate |
214 : public views::BoundsAnimator::OwnedAnimationDelegate { | 205 : public views::BoundsAnimator::OwnedAnimationDelegate { |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 case TYPE_APP_SHORTCUT: | 504 case TYPE_APP_SHORTCUT: |
514 case TYPE_PLATFORM_APP: | 505 case TYPE_PLATFORM_APP: |
515 case TYPE_APP_PANEL: { | 506 case TYPE_APP_PANEL: { |
516 LauncherButton* button = LauncherButton::Create(this, this); | 507 LauncherButton* button = LauncherButton::Create(this, this); |
517 button->SetImage(item.image); | 508 button->SetImage(item.image); |
518 ReflectItemStatus(item, button); | 509 ReflectItemStatus(item, button); |
519 view = button; | 510 view = button; |
520 break; | 511 break; |
521 } | 512 } |
522 | 513 |
| 514 case TYPE_APP_PLACEHOLDER: |
| 515 view = new AppPlaceholderView; |
| 516 break; |
| 517 |
523 case TYPE_APP_LIST: { | 518 case TYPE_APP_LIST: { |
524 // TODO(dave): turn this into a LauncherButton too. | 519 // TODO(dave): turn this into a LauncherButton too. |
525 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 520 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
526 AppListButton* button = new AppListButton(this, this); | 521 AppListButton* button = new AppListButton(this, this); |
527 button->SetImage( | 522 button->SetImage( |
528 views::CustomButton::BS_NORMAL, | 523 views::CustomButton::BS_NORMAL, |
529 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToImageSkia()); | 524 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToImageSkia()); |
530 button->SetImage( | 525 button->SetImage( |
531 views::CustomButton::BS_HOT, | 526 views::CustomButton::BS_HOT, |
532 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT). | 527 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT). |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 bool LauncherView::SameDragType(LauncherItemType typea, | 647 bool LauncherView::SameDragType(LauncherItemType typea, |
653 LauncherItemType typeb) const { | 648 LauncherItemType typeb) const { |
654 switch (typea) { | 649 switch (typea) { |
655 case TYPE_TABBED: | 650 case TYPE_TABBED: |
656 case TYPE_APP_PANEL: | 651 case TYPE_APP_PANEL: |
657 case TYPE_PLATFORM_APP: | 652 case TYPE_PLATFORM_APP: |
658 return (typeb == TYPE_TABBED || | 653 return (typeb == TYPE_TABBED || |
659 typeb == TYPE_APP_PANEL || | 654 typeb == TYPE_APP_PANEL || |
660 typeb == TYPE_PLATFORM_APP); | 655 typeb == TYPE_PLATFORM_APP); |
661 case TYPE_APP_SHORTCUT: | 656 case TYPE_APP_SHORTCUT: |
| 657 case TYPE_APP_PLACEHOLDER: |
662 case TYPE_APP_LIST: | 658 case TYPE_APP_LIST: |
663 case TYPE_BROWSER_SHORTCUT: | 659 case TYPE_BROWSER_SHORTCUT: |
664 return typeb == typea; | 660 return typeb == typea; |
665 } | 661 } |
666 NOTREACHED(); | 662 NOTREACHED(); |
667 return false; | 663 return false; |
668 } | 664 } |
669 | 665 |
670 std::pair<int, int> LauncherView::GetDragRange(int index) { | 666 std::pair<int, int> LauncherView::GetDragRange(int index) { |
671 int min_index = -1; | 667 int min_index = -1; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 if (!delegate_) | 963 if (!delegate_) |
968 return string16(); | 964 return string16(); |
969 int view_index = view_model_->GetIndexOfView(view); | 965 int view_index = view_model_->GetIndexOfView(view); |
970 // May be -1 while in the process of animating closed. | 966 // May be -1 while in the process of animating closed. |
971 if (view_index == -1) | 967 if (view_index == -1) |
972 return string16(); | 968 return string16(); |
973 | 969 |
974 switch (model_->items()[view_index].type) { | 970 switch (model_->items()[view_index].type) { |
975 case TYPE_TABBED: | 971 case TYPE_TABBED: |
976 case TYPE_APP_PANEL: | 972 case TYPE_APP_PANEL: |
| 973 case TYPE_APP_PLACEHOLDER: |
977 case TYPE_APP_SHORTCUT: | 974 case TYPE_APP_SHORTCUT: |
978 case TYPE_PLATFORM_APP: | 975 case TYPE_PLATFORM_APP: |
979 return delegate_->GetTitle(model_->items()[view_index]); | 976 return delegate_->GetTitle(model_->items()[view_index]); |
980 | 977 |
981 case TYPE_APP_LIST: | 978 case TYPE_APP_LIST: |
982 return l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE); | 979 return l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE); |
983 | 980 |
984 case TYPE_BROWSER_SHORTCUT: | 981 case TYPE_BROWSER_SHORTCUT: |
985 return l10n_util::GetStringUTF16(IDS_AURA_NEW_TAB); | 982 return l10n_util::GetStringUTF16(IDS_AURA_NEW_TAB); |
986 } | 983 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 case TYPE_BROWSER_SHORTCUT: | 1025 case TYPE_BROWSER_SHORTCUT: |
1029 // Click on browser icon is counted in app clicks. | 1026 // Click on browser icon is counted in app clicks. |
1030 Shell::GetInstance()->delegate()->RecordUserMetricsAction( | 1027 Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
1031 UMA_LAUNCHER_CLICK_ON_APP); | 1028 UMA_LAUNCHER_CLICK_ON_APP); |
1032 | 1029 |
1033 if (event.flags() & ui::EF_CONTROL_DOWN) | 1030 if (event.flags() & ui::EF_CONTROL_DOWN) |
1034 delegate_->CreateNewWindow(); | 1031 delegate_->CreateNewWindow(); |
1035 else | 1032 else |
1036 delegate_->CreateNewTab(); | 1033 delegate_->CreateNewTab(); |
1037 break; | 1034 break; |
| 1035 |
| 1036 case TYPE_APP_PLACEHOLDER: |
| 1037 // Do nothing. |
| 1038 break; |
1038 } | 1039 } |
1039 } | 1040 } |
1040 | 1041 |
1041 void LauncherView::ShowContextMenuForView(views::View* source, | 1042 void LauncherView::ShowContextMenuForView(views::View* source, |
1042 const gfx::Point& point) { | 1043 const gfx::Point& point) { |
1043 if (!delegate_) | 1044 if (!delegate_) |
1044 return; | 1045 return; |
1045 | 1046 |
1046 int view_index = view_model_->GetIndexOfView(source); | 1047 int view_index = view_model_->GetIndexOfView(source); |
1047 if (view_index != -1 && | 1048 if (view_index != -1 && |
(...skipping 28 matching lines...) Expand all Loading... |
1076 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, | 1077 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
1077 OnLauncherIconPositionsChanged()); | 1078 OnLauncherIconPositionsChanged()); |
1078 PreferredSizeChanged(); | 1079 PreferredSizeChanged(); |
1079 } | 1080 } |
1080 | 1081 |
1081 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { | 1082 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
1082 } | 1083 } |
1083 | 1084 |
1084 } // namespace internal | 1085 } // namespace internal |
1085 } // namespace ash | 1086 } // namespace ash |
OLD | NEW |