Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Side by Side Diff: ash/launcher/launcher_view.cc

Issue 10827420: Revert 152221 - chromeos: Sync animation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/launcher/launcher_view.h ('k') | ash/launcher/launcher_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/scoped_ptr.h" 21 #include "base/utf_string_conversions.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"
24 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/models/simple_menu_model.h" 28 #include "ui/base/models/simple_menu_model.h"
26 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/compositor/layer.h" 30 #include "ui/compositor/layer.h"
31 #include "ui/gfx/image/image.h"
28 #include "ui/views/animation/bounds_animator.h" 32 #include "ui/views/animation/bounds_animator.h"
29 #include "ui/views/border.h" 33 #include "ui/views/border.h"
34 #include "ui/views/controls/button/image_button.h"
30 #include "ui/views/controls/menu/menu_model_adapter.h" 35 #include "ui/views/controls/menu/menu_model_adapter.h"
31 #include "ui/views/controls/menu/menu_runner.h" 36 #include "ui/views/controls/menu/menu_runner.h"
32 #include "ui/views/focus/focus_search.h" 37 #include "ui/views/focus/focus_search.h"
33 #include "ui/views/view_model.h" 38 #include "ui/views/view_model.h"
34 #include "ui/views/view_model_utils.h" 39 #include "ui/views/view_model_utils.h"
40 #include "ui/views/widget/root_view.h"
41 #include "ui/views/widget/widget.h"
35 42
36 using ui::Animation; 43 using ui::Animation;
37 using views::View; 44 using views::View;
38 45
39 namespace ash { 46 namespace ash {
40 namespace internal { 47 namespace internal {
41 48
42 // Default amount content is inset on the left edge. 49 // Default amount content is inset on the left edge.
43 const int kDefaultLeadingInset = 8; 50 static const int kDefaultLeadingInset = 8;
44 51
45 // Minimum distance before drag starts. 52 // Minimum distance before drag starts.
46 const int kMinimumDragDistance = 8; 53 static const int kMinimumDragDistance = 8;
47 54
48 // Size between the buttons. 55 // Size between the buttons.
49 const int kButtonSpacing = 4; 56 static const int kButtonSpacing = 4;
50 57
51 namespace { 58 namespace {
52 59
53 // Custom FocusSearch used to navigate the launcher in the order items are in 60 // Custom FocusSearch used to navigate the launcher in the order items are in
54 // the ViewModel. 61 // the ViewModel.
55 class LauncherFocusSearch : public views::FocusSearch { 62 class LauncherFocusSearch : public views::FocusSearch {
56 public: 63 public:
57 explicit LauncherFocusSearch(views::ViewModel* view_model) 64 explicit LauncherFocusSearch(views::ViewModel* view_model)
58 : FocusSearch(NULL, true, true), 65 : FocusSearch(NULL, true, true),
59 view_model_(view_model) {} 66 view_model_(view_model) {}
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); 170 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate);
164 }; 171 };
165 172
166 void ReflectItemStatus(const ash::LauncherItem& item, 173 void ReflectItemStatus(const ash::LauncherItem& item,
167 LauncherButton* button) { 174 LauncherButton* button) {
168 switch (item.status) { 175 switch (item.status) {
169 case STATUS_CLOSED: 176 case STATUS_CLOSED:
170 button->ClearState(LauncherButton::STATE_ACTIVE); 177 button->ClearState(LauncherButton::STATE_ACTIVE);
171 button->ClearState(LauncherButton::STATE_RUNNING); 178 button->ClearState(LauncherButton::STATE_RUNNING);
172 button->ClearState(LauncherButton::STATE_ATTENTION); 179 button->ClearState(LauncherButton::STATE_ATTENTION);
180 button->ClearState(LauncherButton::STATE_PENDING);
173 break; 181 break;
174 case STATUS_RUNNING: 182 case STATUS_RUNNING:
175 button->ClearState(LauncherButton::STATE_ACTIVE); 183 button->ClearState(LauncherButton::STATE_ACTIVE);
176 button->AddState(LauncherButton::STATE_RUNNING); 184 button->AddState(LauncherButton::STATE_RUNNING);
177 button->ClearState(LauncherButton::STATE_ATTENTION); 185 button->ClearState(LauncherButton::STATE_ATTENTION);
186 button->ClearState(LauncherButton::STATE_PENDING);
178 break; 187 break;
179 case STATUS_ACTIVE: 188 case STATUS_ACTIVE:
180 button->AddState(LauncherButton::STATE_ACTIVE); 189 button->AddState(LauncherButton::STATE_ACTIVE);
181 button->ClearState(LauncherButton::STATE_RUNNING); 190 button->ClearState(LauncherButton::STATE_RUNNING);
182 button->ClearState(LauncherButton::STATE_ATTENTION); 191 button->ClearState(LauncherButton::STATE_ATTENTION);
192 button->ClearState(LauncherButton::STATE_PENDING);
183 break; 193 break;
184 case STATUS_ATTENTION: 194 case STATUS_ATTENTION:
185 button->ClearState(LauncherButton::STATE_ACTIVE); 195 button->ClearState(LauncherButton::STATE_ACTIVE);
186 button->ClearState(LauncherButton::STATE_RUNNING); 196 button->ClearState(LauncherButton::STATE_RUNNING);
187 button->AddState(LauncherButton::STATE_ATTENTION); 197 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);
188 break; 205 break;
189 } 206 }
190 } 207 }
191 208
192 } // namespace 209 } // namespace
193 210
194 // AnimationDelegate used when inserting a new item. This steadily decreased the 211 // AnimationDelegate used when inserting a new item. This steadily decreased the
195 // opacity of the layer as the animation progress. 212 // opacity of the layer as the animation progress.
196 class LauncherView::FadeOutAnimationDelegate 213 class LauncherView::FadeOutAnimationDelegate
197 : public views::BoundsAnimator::OwnedAnimationDelegate { 214 : public views::BoundsAnimator::OwnedAnimationDelegate {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 model_->AddObserver(this); 297 model_->AddObserver(this);
281 298
282 const LauncherItems& items(model_->items()); 299 const LauncherItems& items(model_->items());
283 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { 300 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) {
284 views::View* child = CreateViewForItem(*i); 301 views::View* child = CreateViewForItem(*i);
285 child->SetPaintToLayer(true); 302 child->SetPaintToLayer(true);
286 view_model_->Add(child, static_cast<int>(i - items.begin())); 303 view_model_->Add(child, static_cast<int>(i - items.begin()));
287 AddChildView(child); 304 AddChildView(child);
288 } 305 }
289 UpdateFirstButtonPadding(); 306 UpdateFirstButtonPadding();
290 LauncherStatusChanged();
291 307
292 overflow_button_ = new OverflowButton(this); 308 overflow_button_ = new OverflowButton(this);
293 overflow_button_->set_context_menu_controller(this); 309 overflow_button_->set_context_menu_controller(this);
294 ConfigureChildView(overflow_button_); 310 ConfigureChildView(overflow_button_);
295 AddChildView(overflow_button_); 311 AddChildView(overflow_button_);
296 312
297 // We'll layout when our bounds change. 313 // We'll layout when our bounds change.
298 } 314 }
299 315
300 void LauncherView::SetAlignment(ShelfAlignment alignment) { 316 void LauncherView::SetAlignment(ShelfAlignment alignment) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 case TYPE_APP_PANEL: { 515 case TYPE_APP_PANEL: {
500 LauncherButton* button = LauncherButton::Create(this, this); 516 LauncherButton* button = LauncherButton::Create(this, this);
501 button->SetImage(item.image); 517 button->SetImage(item.image);
502 ReflectItemStatus(item, button); 518 ReflectItemStatus(item, button);
503 view = button; 519 view = button;
504 break; 520 break;
505 } 521 }
506 522
507 case TYPE_APP_LIST: { 523 case TYPE_APP_LIST: {
508 // TODO(dave): turn this into a LauncherButton too. 524 // TODO(dave): turn this into a LauncherButton too.
525 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
509 AppListButton* button = new AppListButton(this, this); 526 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));
510 view = button; 540 view = button;
511 break; 541 break;
512 } 542 }
513 543
514 case TYPE_BROWSER_SHORTCUT: { 544 case TYPE_BROWSER_SHORTCUT: {
515 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 545 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
516 LauncherButton* button = LauncherButton::Create(this, this); 546 LauncherButton* button = LauncherButton::Create(this, this);
517 int image_id = delegate_ ? 547 int image_id = delegate_ ?
518 delegate_->GetBrowserShortcutResourceId() : 548 delegate_->GetBrowserShortcutResourceId() :
519 IDR_AURA_LAUNCHER_BROWSER_SHORTCUT; 549 IDR_AURA_LAUNCHER_BROWSER_SHORTCUT;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 default: 880 default:
851 break; 881 break;
852 } 882 }
853 } 883 }
854 884
855 void LauncherView::LauncherItemMoved(int start_index, int target_index) { 885 void LauncherView::LauncherItemMoved(int start_index, int target_index) {
856 view_model_->Move(start_index, target_index); 886 view_model_->Move(start_index, target_index);
857 AnimateToIdealBounds(); 887 AnimateToIdealBounds();
858 } 888 }
859 889
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
869 void LauncherView::PointerPressedOnButton(views::View* view, 890 void LauncherView::PointerPressedOnButton(views::View* view,
870 Pointer pointer, 891 Pointer pointer,
871 const ui::LocatedEvent& event) { 892 const ui::LocatedEvent& event) {
872 if (drag_view_) 893 if (drag_view_)
873 return; 894 return;
874 895
875 tooltip_->Close(); 896 tooltip_->Close();
876 int index = view_model_->GetIndexOfView(view); 897 int index = view_model_->GetIndexOfView(view);
877 if (index == -1 || 898 if (index == -1 ||
878 view_model_->view_size() <= 1 || 899 view_model_->view_size() <= 1 ||
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 return string16(); 972 return string16();
952 973
953 switch (model_->items()[view_index].type) { 974 switch (model_->items()[view_index].type) {
954 case TYPE_TABBED: 975 case TYPE_TABBED:
955 case TYPE_APP_PANEL: 976 case TYPE_APP_PANEL:
956 case TYPE_APP_SHORTCUT: 977 case TYPE_APP_SHORTCUT:
957 case TYPE_PLATFORM_APP: 978 case TYPE_PLATFORM_APP:
958 return delegate_->GetTitle(model_->items()[view_index]); 979 return delegate_->GetTitle(model_->items()[view_index]);
959 980
960 case TYPE_APP_LIST: 981 case TYPE_APP_LIST:
961 return model_->status() == LauncherModel::STATUS_LOADING ? 982 return l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE);
962 l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_SYNCING_TITLE) :
963 l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE);
964 983
965 case TYPE_BROWSER_SHORTCUT: 984 case TYPE_BROWSER_SHORTCUT:
966 return l10n_util::GetStringUTF16(IDS_AURA_NEW_TAB); 985 return l10n_util::GetStringUTF16(IDS_AURA_NEW_TAB);
967 } 986 }
968 return string16(); 987 return string16();
969 } 988 }
970 989
971 void LauncherView::ButtonPressed(views::Button* sender, 990 void LauncherView::ButtonPressed(views::Button* sender,
972 const ui::Event& event) { 991 const ui::Event& event) {
973 // Do not handle mouse release during drag. 992 // Do not handle mouse release during drag.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, 1076 FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
1058 OnLauncherIconPositionsChanged()); 1077 OnLauncherIconPositionsChanged());
1059 PreferredSizeChanged(); 1078 PreferredSizeChanged();
1060 } 1079 }
1061 1080
1062 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { 1081 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
1063 } 1082 }
1064 1083
1065 } // namespace internal 1084 } // namespace internal
1066 } // namespace ash 1085 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_view.h ('k') | ash/launcher/launcher_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698