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/launcher_button.h" | 10 #include "ash/launcher/launcher_button.h" |
11 #include "ash/launcher/launcher_delegate.h" | 11 #include "ash/launcher/launcher_delegate.h" |
12 #include "ash/launcher/launcher_icon_observer.h" | 12 #include "ash/launcher/launcher_icon_observer.h" |
13 #include "ash/launcher/launcher_model.h" | 13 #include "ash/launcher/launcher_model.h" |
14 #include "ash/launcher/launcher_tooltip_manager.h" | 14 #include "ash/launcher/launcher_tooltip_manager.h" |
15 #include "ash/launcher/overflow_bubble.h" | 15 #include "ash/launcher/overflow_bubble.h" |
16 #include "ash/launcher/overflow_button.h" | 16 #include "ash/launcher/overflow_button.h" |
17 #include "ash/launcher/tabbed_launcher_button.h" | 17 #include "ash/launcher/tabbed_launcher_button.h" |
18 #include "ash/shell.h" | 18 #include "ash/shell.h" |
19 #include "ash/shell_delegate.h" | 19 #include "ash/shell_delegate.h" |
20 #include "base/auto_reset.h" | 20 #include "base/auto_reset.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/memory/scoped_ptr.h" |
22 #include "grit/ash_strings.h" | 22 #include "grit/ash_strings.h" |
23 #include "grit/ui_resources.h" | 23 #include "grit/ui_resources.h" |
24 #include "ui/aura/window.h" | |
25 #include "ui/base/animation/animation.h" | |
26 #include "ui/base/animation/throb_animation.h" | |
27 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/base/models/simple_menu_model.h" | 25 #include "ui/base/models/simple_menu_model.h" |
29 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
30 #include "ui/compositor/layer.h" | 27 #include "ui/compositor/layer.h" |
31 #include "ui/gfx/image/image.h" | |
32 #include "ui/views/animation/bounds_animator.h" | 28 #include "ui/views/animation/bounds_animator.h" |
33 #include "ui/views/border.h" | 29 #include "ui/views/border.h" |
34 #include "ui/views/controls/button/image_button.h" | |
35 #include "ui/views/controls/menu/menu_model_adapter.h" | 30 #include "ui/views/controls/menu/menu_model_adapter.h" |
36 #include "ui/views/controls/menu/menu_runner.h" | 31 #include "ui/views/controls/menu/menu_runner.h" |
37 #include "ui/views/focus/focus_search.h" | 32 #include "ui/views/focus/focus_search.h" |
38 #include "ui/views/view_model.h" | 33 #include "ui/views/view_model.h" |
39 #include "ui/views/view_model_utils.h" | 34 #include "ui/views/view_model_utils.h" |
40 #include "ui/views/widget/root_view.h" | |
41 #include "ui/views/widget/widget.h" | |
42 | 35 |
43 using ui::Animation; | 36 using ui::Animation; |
44 using views::View; | 37 using views::View; |
45 | 38 |
46 namespace ash { | 39 namespace ash { |
47 namespace internal { | 40 namespace internal { |
48 | 41 |
49 // Default amount content is inset on the left edge. | 42 // Default amount content is inset on the left edge. |
50 static const int kDefaultLeadingInset = 8; | 43 const int kDefaultLeadingInset = 8; |
51 | 44 |
52 // Minimum distance before drag starts. | 45 // Minimum distance before drag starts. |
53 static const int kMinimumDragDistance = 8; | 46 const int kMinimumDragDistance = 8; |
54 | 47 |
55 // Size between the buttons. | 48 // Size between the buttons. |
56 static const int kButtonSpacing = 4; | 49 const int kButtonSpacing = 4; |
57 | 50 |
58 namespace { | 51 namespace { |
59 | 52 |
60 // Custom FocusSearch used to navigate the launcher in the order items are in | 53 // Custom FocusSearch used to navigate the launcher in the order items are in |
61 // the ViewModel. | 54 // the ViewModel. |
62 class LauncherFocusSearch : public views::FocusSearch { | 55 class LauncherFocusSearch : public views::FocusSearch { |
63 public: | 56 public: |
64 explicit LauncherFocusSearch(views::ViewModel* view_model) | 57 explicit LauncherFocusSearch(views::ViewModel* view_model) |
65 : FocusSearch(NULL, true, true), | 58 : FocusSearch(NULL, true, true), |
66 view_model_(view_model) {} | 59 view_model_(view_model) {} |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); | 163 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); |
171 }; | 164 }; |
172 | 165 |
173 void ReflectItemStatus(const ash::LauncherItem& item, | 166 void ReflectItemStatus(const ash::LauncherItem& item, |
174 LauncherButton* button) { | 167 LauncherButton* button) { |
175 switch (item.status) { | 168 switch (item.status) { |
176 case STATUS_CLOSED: | 169 case STATUS_CLOSED: |
177 button->ClearState(LauncherButton::STATE_ACTIVE); | 170 button->ClearState(LauncherButton::STATE_ACTIVE); |
178 button->ClearState(LauncherButton::STATE_RUNNING); | 171 button->ClearState(LauncherButton::STATE_RUNNING); |
179 button->ClearState(LauncherButton::STATE_ATTENTION); | 172 button->ClearState(LauncherButton::STATE_ATTENTION); |
180 button->ClearState(LauncherButton::STATE_PENDING); | |
181 break; | 173 break; |
182 case STATUS_RUNNING: | 174 case STATUS_RUNNING: |
183 button->ClearState(LauncherButton::STATE_ACTIVE); | 175 button->ClearState(LauncherButton::STATE_ACTIVE); |
184 button->AddState(LauncherButton::STATE_RUNNING); | 176 button->AddState(LauncherButton::STATE_RUNNING); |
185 button->ClearState(LauncherButton::STATE_ATTENTION); | 177 button->ClearState(LauncherButton::STATE_ATTENTION); |
186 button->ClearState(LauncherButton::STATE_PENDING); | |
187 break; | 178 break; |
188 case STATUS_ACTIVE: | 179 case STATUS_ACTIVE: |
189 button->AddState(LauncherButton::STATE_ACTIVE); | 180 button->AddState(LauncherButton::STATE_ACTIVE); |
190 button->ClearState(LauncherButton::STATE_RUNNING); | 181 button->ClearState(LauncherButton::STATE_RUNNING); |
191 button->ClearState(LauncherButton::STATE_ATTENTION); | 182 button->ClearState(LauncherButton::STATE_ATTENTION); |
192 button->ClearState(LauncherButton::STATE_PENDING); | |
193 break; | 183 break; |
194 case STATUS_ATTENTION: | 184 case STATUS_ATTENTION: |
195 button->ClearState(LauncherButton::STATE_ACTIVE); | 185 button->ClearState(LauncherButton::STATE_ACTIVE); |
196 button->ClearState(LauncherButton::STATE_RUNNING); | 186 button->ClearState(LauncherButton::STATE_RUNNING); |
197 button->AddState(LauncherButton::STATE_ATTENTION); | 187 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; | 188 break; |
206 } | 189 } |
207 } | 190 } |
208 | 191 |
209 } // namespace | 192 } // namespace |
210 | 193 |
211 // AnimationDelegate used when inserting a new item. This steadily decreased the | 194 // AnimationDelegate used when inserting a new item. This steadily decreased the |
212 // opacity of the layer as the animation progress. | 195 // opacity of the layer as the animation progress. |
213 class LauncherView::FadeOutAnimationDelegate | 196 class LauncherView::FadeOutAnimationDelegate |
214 : public views::BoundsAnimator::OwnedAnimationDelegate { | 197 : public views::BoundsAnimator::OwnedAnimationDelegate { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 model_->AddObserver(this); | 280 model_->AddObserver(this); |
298 | 281 |
299 const LauncherItems& items(model_->items()); | 282 const LauncherItems& items(model_->items()); |
300 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 283 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
301 views::View* child = CreateViewForItem(*i); | 284 views::View* child = CreateViewForItem(*i); |
302 child->SetPaintToLayer(true); | 285 child->SetPaintToLayer(true); |
303 view_model_->Add(child, static_cast<int>(i - items.begin())); | 286 view_model_->Add(child, static_cast<int>(i - items.begin())); |
304 AddChildView(child); | 287 AddChildView(child); |
305 } | 288 } |
306 UpdateFirstButtonPadding(); | 289 UpdateFirstButtonPadding(); |
| 290 LauncherStatusChanged(); |
307 | 291 |
308 overflow_button_ = new OverflowButton(this); | 292 overflow_button_ = new OverflowButton(this); |
309 overflow_button_->set_context_menu_controller(this); | 293 overflow_button_->set_context_menu_controller(this); |
310 ConfigureChildView(overflow_button_); | 294 ConfigureChildView(overflow_button_); |
311 AddChildView(overflow_button_); | 295 AddChildView(overflow_button_); |
312 | 296 |
313 // We'll layout when our bounds change. | 297 // We'll layout when our bounds change. |
314 } | 298 } |
315 | 299 |
316 void LauncherView::SetAlignment(ShelfAlignment alignment) { | 300 void LauncherView::SetAlignment(ShelfAlignment alignment) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 case TYPE_APP_PANEL: { | 499 case TYPE_APP_PANEL: { |
516 LauncherButton* button = LauncherButton::Create(this, this); | 500 LauncherButton* button = LauncherButton::Create(this, this); |
517 button->SetImage(item.image); | 501 button->SetImage(item.image); |
518 ReflectItemStatus(item, button); | 502 ReflectItemStatus(item, button); |
519 view = button; | 503 view = button; |
520 break; | 504 break; |
521 } | 505 } |
522 | 506 |
523 case TYPE_APP_LIST: { | 507 case TYPE_APP_LIST: { |
524 // TODO(dave): turn this into a LauncherButton too. | 508 // TODO(dave): turn this into a LauncherButton too. |
525 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
526 AppListButton* button = new AppListButton(this, this); | 509 AppListButton* button = new AppListButton(this, this); |
527 button->SetImage( | |
528 views::CustomButton::BS_NORMAL, | |
529 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToImageSkia()); | |
530 button->SetImage( | |
531 views::CustomButton::BS_HOT, | |
532 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT). | |
533 ToImageSkia()); | |
534 button->SetImage( | |
535 views::CustomButton::BS_PUSHED, | |
536 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED). | |
537 ToImageSkia()); | |
538 button->SetAccessibleName( | |
539 l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE)); | |
540 view = button; | 510 view = button; |
541 break; | 511 break; |
542 } | 512 } |
543 | 513 |
544 case TYPE_BROWSER_SHORTCUT: { | 514 case TYPE_BROWSER_SHORTCUT: { |
545 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 515 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
546 LauncherButton* button = LauncherButton::Create(this, this); | 516 LauncherButton* button = LauncherButton::Create(this, this); |
547 int image_id = delegate_ ? | 517 int image_id = delegate_ ? |
548 delegate_->GetBrowserShortcutResourceId() : | 518 delegate_->GetBrowserShortcutResourceId() : |
549 IDR_AURA_LAUNCHER_BROWSER_SHORTCUT; | 519 IDR_AURA_LAUNCHER_BROWSER_SHORTCUT; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 default: | 850 default: |
881 break; | 851 break; |
882 } | 852 } |
883 } | 853 } |
884 | 854 |
885 void LauncherView::LauncherItemMoved(int start_index, int target_index) { | 855 void LauncherView::LauncherItemMoved(int start_index, int target_index) { |
886 view_model_->Move(start_index, target_index); | 856 view_model_->Move(start_index, target_index); |
887 AnimateToIdealBounds(); | 857 AnimateToIdealBounds(); |
888 } | 858 } |
889 | 859 |
| 860 void LauncherView::LauncherStatusChanged() { |
| 861 AppListButton* app_list_button = |
| 862 static_cast<AppListButton*>(GetAppListButtonView()); |
| 863 if (model_->status() == LauncherModel::STATUS_LOADING) |
| 864 app_list_button->StartLoadingAnimation(); |
| 865 else |
| 866 app_list_button->StopLoadingAnimation(); |
| 867 } |
| 868 |
890 void LauncherView::PointerPressedOnButton(views::View* view, | 869 void LauncherView::PointerPressedOnButton(views::View* view, |
891 Pointer pointer, | 870 Pointer pointer, |
892 const ui::LocatedEvent& event) { | 871 const ui::LocatedEvent& event) { |
893 if (drag_view_) | 872 if (drag_view_) |
894 return; | 873 return; |
895 | 874 |
896 tooltip_->Close(); | 875 tooltip_->Close(); |
897 int index = view_model_->GetIndexOfView(view); | 876 int index = view_model_->GetIndexOfView(view); |
898 if (index == -1 || | 877 if (index == -1 || |
899 view_model_->view_size() <= 1 || | 878 view_model_->view_size() <= 1 || |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 return string16(); | 951 return string16(); |
973 | 952 |
974 switch (model_->items()[view_index].type) { | 953 switch (model_->items()[view_index].type) { |
975 case TYPE_TABBED: | 954 case TYPE_TABBED: |
976 case TYPE_APP_PANEL: | 955 case TYPE_APP_PANEL: |
977 case TYPE_APP_SHORTCUT: | 956 case TYPE_APP_SHORTCUT: |
978 case TYPE_PLATFORM_APP: | 957 case TYPE_PLATFORM_APP: |
979 return delegate_->GetTitle(model_->items()[view_index]); | 958 return delegate_->GetTitle(model_->items()[view_index]); |
980 | 959 |
981 case TYPE_APP_LIST: | 960 case TYPE_APP_LIST: |
982 return l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE); | 961 return model_->status() == LauncherModel::STATUS_LOADING ? |
| 962 l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_SYNCING_TITLE) : |
| 963 l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE); |
983 | 964 |
984 case TYPE_BROWSER_SHORTCUT: | 965 case TYPE_BROWSER_SHORTCUT: |
985 return l10n_util::GetStringUTF16(IDS_AURA_NEW_TAB); | 966 return l10n_util::GetStringUTF16(IDS_AURA_NEW_TAB); |
986 } | 967 } |
987 return string16(); | 968 return string16(); |
988 } | 969 } |
989 | 970 |
990 void LauncherView::ButtonPressed(views::Button* sender, | 971 void LauncherView::ButtonPressed(views::Button* sender, |
991 const ui::Event& event) { | 972 const ui::Event& event) { |
992 // Do not handle mouse release during drag. | 973 // Do not handle mouse release during drag. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, | 1057 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
1077 OnLauncherIconPositionsChanged()); | 1058 OnLauncherIconPositionsChanged()); |
1078 PreferredSizeChanged(); | 1059 PreferredSizeChanged(); |
1079 } | 1060 } |
1080 | 1061 |
1081 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { | 1062 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
1082 } | 1063 } |
1083 | 1064 |
1084 } // namespace internal | 1065 } // namespace internal |
1085 } // namespace ash | 1066 } // namespace ash |
OLD | NEW |