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

Side by Side Diff: ui/app_list/views/apps_container_view.cc

Issue 136303008: Implement ui for re-parenting an item from an app list folder to another position or folder in the … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/apps_container_view.h" 5 #include "ui/app_list/views/apps_container_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/app_list/app_list_constants.h" 9 #include "ui/app_list/app_list_constants.h"
10 #include "ui/app_list/app_list_folder_item.h" 10 #include "ui/app_list/app_list_folder_item.h"
11 #include "ui/app_list/pagination_model.h" 11 #include "ui/app_list/pagination_model.h"
12 #include "ui/app_list/views/app_list_folder_view.h" 12 #include "ui/app_list/views/app_list_folder_view.h"
13 #include "ui/app_list/views/app_list_item_view.h" 13 #include "ui/app_list/views/app_list_item_view.h"
14 #include "ui/app_list/views/app_list_main_view.h" 14 #include "ui/app_list/views/app_list_main_view.h"
15 #include "ui/app_list/views/apps_grid_view.h" 15 #include "ui/app_list/views/apps_grid_view.h"
16 #include "ui/compositor/scoped_layer_animation_settings.h" 16 #include "ui/app_list/views/folder_background_view.h"
17 #include "ui/events/event.h" 17 #include "ui/events/event.h"
18 #include "ui/gfx/image/image_skia_operations.h"
19 #include "ui/views/controls/image_view.h"
20 18
21 namespace app_list { 19 namespace app_list {
22 20
23 namespace {
24
25 // Transitional view used for top item icons animation when opening or closing
26 // a folder.
27 class TopIconAnimationView : public views::View,
28 public ui::ImplicitAnimationObserver {
29 public:
30 TopIconAnimationView(const gfx::ImageSkia& icon,
31 const gfx::Rect& scaled_rect,
32 bool open_folder)
33 : icon_size_(kPreferredIconDimension, kPreferredIconDimension),
34 icon_(new views::ImageView),
35 scaled_rect_(scaled_rect),
36 open_folder_(open_folder) {
37 DCHECK(!icon.isNull());
38 gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage(
39 icon,
40 skia::ImageOperations::RESIZE_BEST, icon_size_));
41 icon_->SetImage(resized);
42 AddChildView(icon_);
43
44 #if defined(USE_AURA)
45 SetPaintToLayer(true);
46 SetFillsBoundsOpaquely(false);
47 #endif
48 }
49 virtual ~TopIconAnimationView() {}
50
51 void AddObserver(TopIconAnimationObserver* observer) {
52 observers_.AddObserver(observer);
53 }
54
55 void RemoveObserver(TopIconAnimationObserver* observer) {
56 observers_.RemoveObserver(observer);
57 }
58
59 void TransformView() {
60 // Transform used for scaling down the icon and move it back inside to the
61 // original folder icon.
62 const float kIconTransformScale = 0.33333f;
63 gfx::Transform transform;
64 transform.Translate(scaled_rect_.x() - layer()->bounds().x(),
65 scaled_rect_.y() - layer()->bounds().y());
66 transform.Scale(kIconTransformScale, kIconTransformScale);
67
68 if (open_folder_) {
69 // Transform to a scaled down icon inside the original folder icon.
70 layer()->SetTransform(transform);
71 }
72
73 // Animate the icon to its target location and scale when opening or
74 // closing a folder.
75 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
76 settings.AddObserver(this);
77 settings.SetTransitionDuration(
78 base::TimeDelta::FromMilliseconds(kFolderTransitionInDurationMs));
79 layer()->SetTransform(open_folder_ ? gfx::Transform() : transform);
80 }
81
82 private:
83 // views::View overrides:
84 virtual gfx::Size GetPreferredSize() OVERRIDE {
85 return icon_size_;
86 }
87
88 virtual void Layout() OVERRIDE {
89 icon_->SetBoundsRect(GetContentsBounds());
90 }
91
92 // ui::ImplicitAnimationObserver overrides:
93 virtual void OnImplicitAnimationsCompleted() OVERRIDE {
94 SetVisible(false);
95 FOR_EACH_OBSERVER(TopIconAnimationObserver,
96 observers_,
97 OnTopIconAnimationsComplete(this));
98 }
99
100 gfx::Size icon_size_;
101 views::ImageView* icon_; // Owned by views hierarchy.
102 // Rect of the scaled down top item icon inside folder icon's ink bubble.
103 gfx::Rect scaled_rect_;
104 // True: opening folder; False: closing folder.
105 bool open_folder_;
106
107 ObserverList<TopIconAnimationObserver> observers_;
108
109 DISALLOW_COPY_AND_ASSIGN(TopIconAnimationView);
110 };
111
112 } // namespace
113
114 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, 21 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view,
115 PaginationModel* pagination_model, 22 PaginationModel* pagination_model,
116 AppListModel* model, 23 AppListModel* model,
117 content::WebContents* start_page_contents) 24 content::WebContents* start_page_contents)
118 : model_(model), 25 : model_(model),
119 show_state_(SHOW_APPS) { 26 show_state_(SHOW_APPS) {
120 apps_grid_view_ = new AppsGridView( 27 apps_grid_view_ = new AppsGridView(
121 app_list_main_view, pagination_model, start_page_contents); 28 app_list_main_view, pagination_model, start_page_contents);
122 apps_grid_view_->SetLayout(kPreferredIconDimension, 29 apps_grid_view_->SetLayout(kPreferredIconDimension,
123 kPreferredCols, 30 kPreferredCols,
124 kPreferredRows); 31 kPreferredRows);
125 AddChildView(apps_grid_view_); 32 AddChildView(apps_grid_view_);
126 33
34 folder_background_view_ = new FolderBackgroundView();
35 AddChildView(folder_background_view_);
36
127 app_list_folder_view_ = new AppListFolderView( 37 app_list_folder_view_ = new AppListFolderView(
128 this, 38 this,
129 model, 39 model,
130 app_list_main_view, 40 app_list_main_view,
131 start_page_contents); 41 start_page_contents);
132 AddChildView(app_list_folder_view_); 42 AddChildView(app_list_folder_view_);
133 43
134 apps_grid_view_->SetModel(model_); 44 apps_grid_view_->SetModel(model_);
135 apps_grid_view_->SetItemList(model_->item_list()); 45 apps_grid_view_->SetItemList(model_->item_list());
136 } 46 }
137 47
138 AppsContainerView::~AppsContainerView() { 48 AppsContainerView::~AppsContainerView() {
139 } 49 }
140 50
141 void AppsContainerView::ShowActiveFolder(AppListFolderItem* folder_item) { 51 void AppsContainerView::ShowActiveFolder(AppListFolderItem* folder_item) {
142 app_list_folder_view_->SetAppListFolderItem(folder_item); 52 app_list_folder_view_->SetAppListFolderItem(folder_item);
143 SetShowState(SHOW_ACTIVE_FOLDER); 53 SetShowState(SHOW_ACTIVE_FOLDER);
144 54
145 CreateViewsForFolderTopItemsAnimation(folder_item, true); 55 CreateViewsForFolderTopItemsAnimation(folder_item, true);
146 } 56 }
147 57
148 void AppsContainerView::ShowApps(AppListFolderItem* folder_item) { 58 void AppsContainerView::ShowApps(AppListFolderItem* folder_item) {
149 if (folder_item) 59 PrepareToShowApps(folder_item);
150 CreateViewsForFolderTopItemsAnimation(folder_item, false);
151 else
152 top_icon_views_.clear();
153 // Hide the active folder view until the animation completes.
154 apps_grid_view_->activated_item_view()->SetVisible(false);
155 SetShowState(SHOW_APPS); 60 SetShowState(SHOW_APPS);
156 } 61 }
157 62
63 void AppsContainerView::SetDragAndDropHostOfCurrentAppList(
64 ApplicationDragAndDropHost* drag_and_drop_host) {
65 apps_grid_view()->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
66 app_list_folder_view()->items_grid_view()->
67 SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
68 }
69
70 void AppsContainerView::ReparentFolderItemTransit(
71 AppListFolderItem* folder_item) {
72 PrepareToShowApps(folder_item);
73 SetShowState(SHOW_ITEM_REPARENT);
74 }
75
158 gfx::Size AppsContainerView::GetPreferredSize() { 76 gfx::Size AppsContainerView::GetPreferredSize() {
159 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); 77 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize();
160 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize(); 78 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize();
161 79
162 int width = std::max(grid_size.width(), folder_view_size.width()); 80 int width = std::max(grid_size.width(), folder_view_size.width());
163 int height = std::max(grid_size.height(), folder_view_size.height()); 81 int height = std::max(grid_size.height(), folder_view_size.height());
164 return gfx::Size(width, height); 82 return gfx::Size(width, height);
165 } 83 }
166 84
167 void AppsContainerView::Layout() { 85 void AppsContainerView::Layout() {
168 gfx::Rect rect(GetContentsBounds()); 86 gfx::Rect rect(GetContentsBounds());
169 if (rect.IsEmpty()) 87 if (rect.IsEmpty())
170 return; 88 return;
171 89
172 switch (show_state_) { 90 switch (show_state_) {
173 case SHOW_APPS: 91 case SHOW_APPS:
174 app_list_folder_view_->ScheduleShowHideAnimation(false); 92 folder_background_view_->SetVisible(false);
93 app_list_folder_view_->ScheduleShowHideAnimation(false, false);
175 apps_grid_view_->SetBoundsRect(rect); 94 apps_grid_view_->SetBoundsRect(rect);
176 apps_grid_view_->ScheduleShowHideAnimation(true); 95 apps_grid_view_->ScheduleShowHideAnimation(true);
177 break; 96 break;
178 case SHOW_ACTIVE_FOLDER: 97 case SHOW_ACTIVE_FOLDER:
98 folder_background_view_->SetBoundsRect(rect);
99 folder_background_view_->SetVisible(true);
179 apps_grid_view_->ScheduleShowHideAnimation(false); 100 apps_grid_view_->ScheduleShowHideAnimation(false);
180 app_list_folder_view_->SetBoundsRect(rect); 101 app_list_folder_view_->SetBoundsRect(rect);
181 app_list_folder_view_->ScheduleShowHideAnimation(true); 102 app_list_folder_view_->ScheduleShowHideAnimation(true, false);
103 break;
104 case SHOW_ITEM_REPARENT:
105 folder_background_view_->SetVisible(false);
106 folder_background_view_->UpdateFolderContainerBubble(
107 FolderBackgroundView::NO_BUBBLE);
108 app_list_folder_view_->ScheduleShowHideAnimation(false, true);
109 apps_grid_view_->ScheduleShowHideAnimation(true);
182 break; 110 break;
183 default: 111 default:
184 NOTREACHED(); 112 NOTREACHED();
185 } 113 }
186 } 114 }
187 115
188 bool AppsContainerView::OnKeyPressed(const ui::KeyEvent& event) { 116 bool AppsContainerView::OnKeyPressed(const ui::KeyEvent& event) {
189 if (show_state_ == SHOW_APPS) 117 if (show_state_ == SHOW_APPS)
190 return apps_grid_view_->OnKeyPressed(event); 118 return apps_grid_view_->OnKeyPressed(event);
191 else 119 else
(...skipping 13 matching lines...) Expand all
205 // Clean up the transitional views using for top item icon animation. 133 // Clean up the transitional views using for top item icon animation.
206 for (size_t i = 0; i < top_icon_views_.size(); ++i) { 134 for (size_t i = 0; i < top_icon_views_.size(); ++i) {
207 TopIconAnimationView* icon_view = 135 TopIconAnimationView* icon_view =
208 static_cast<TopIconAnimationView*>(top_icon_views_[i]); 136 static_cast<TopIconAnimationView*>(top_icon_views_[i]);
209 icon_view->RemoveObserver(this); 137 icon_view->RemoveObserver(this);
210 delete icon_view; 138 delete icon_view;
211 } 139 }
212 top_icon_views_.clear(); 140 top_icon_views_.clear();
213 141
214 // Show the folder icon when closing the folder. 142 // Show the folder icon when closing the folder.
215 if (show_state_ == SHOW_APPS && apps_grid_view_->activated_item_view()) 143 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) &&
144 apps_grid_view_->activated_item_view()) {
216 apps_grid_view_->activated_item_view()->SetVisible(true); 145 apps_grid_view_->activated_item_view()->SetVisible(true);
146 }
217 } 147 }
218 } 148 }
219 149
220 void AppsContainerView::SetShowState(ShowState show_state) { 150 void AppsContainerView::SetShowState(ShowState show_state) {
221 if (show_state_ == show_state) 151 if (show_state_ == show_state)
222 return; 152 return;
223 153
224 show_state_ = show_state; 154 show_state_ = show_state;
225 Layout(); 155 Layout();
226 } 156 }
227 157
228 Rects AppsContainerView::GetTopItemIconBoundsInActiveFolder() { 158 Rects AppsContainerView::GetTopItemIconBoundsInActiveFolder() {
229 // Get the active folder's icon bounds relative to AppsContainerView. 159 // Get the active folder's icon bounds relative to AppsContainerView.
230 AppListItemView* folder_view = apps_grid_view_->activated_item_view(); 160 AppListItemView* folder_item_view = apps_grid_view_->activated_item_view();
231 gfx::Rect to_grid_view = folder_view->ConvertRectToParent( 161 gfx::Rect to_grid_view = folder_item_view->ConvertRectToParent(
232 folder_view->GetIconBounds()); 162 folder_item_view->GetIconBounds());
233 gfx::Rect to_container = apps_grid_view_->ConvertRectToParent(to_grid_view); 163 gfx::Rect to_container = apps_grid_view_->ConvertRectToParent(to_grid_view);
234 164
235 return AppListFolderItem::GetTopIconsBounds(to_container); 165 return AppListFolderItem::GetTopIconsBounds(to_container);
236 } 166 }
237 167
238 void AppsContainerView::CreateViewsForFolderTopItemsAnimation( 168 void AppsContainerView::CreateViewsForFolderTopItemsAnimation(
239 AppListFolderItem* active_folder, 169 AppListFolderItem* active_folder,
240 bool open_folder) { 170 bool open_folder) {
241 top_icon_views_.clear(); 171 top_icon_views_.clear();
242 std::vector<gfx::Rect> top_items_bounds = 172 std::vector<gfx::Rect> top_items_bounds =
243 GetTopItemIconBoundsInActiveFolder(); 173 GetTopItemIconBoundsInActiveFolder();
244 size_t top_items_count = 174 size_t top_items_count =
245 std::min(kNumFolderTopItems, active_folder->item_list()->item_count()); 175 std::min(kNumFolderTopItems, active_folder->item_list()->item_count());
246 for (size_t i = 0; i < top_items_count; ++i) { 176 for (size_t i = 0; i < top_items_count; ++i) {
247 TopIconAnimationView* icon_view = new TopIconAnimationView( 177 TopIconAnimationView* icon_view = new TopIconAnimationView(
248 active_folder->GetTopIcon(i), top_items_bounds[i], open_folder); 178 active_folder->GetTopIcon(i), top_items_bounds[i], open_folder, false);
249 icon_view->AddObserver(this); 179 icon_view->AddObserver(this);
250 top_icon_views_.push_back(icon_view); 180 top_icon_views_.push_back(icon_view);
251 181
252 // Add the transitional views into child views, and set its bounds to the 182 // Add the transitional views into child views, and set its bounds to the
253 // same location of the item in the folder list view. 183 // same location of the item in the folder list view.
254 AddChildView(top_icon_views_[i]); 184 AddChildView(top_icon_views_[i]);
255 top_icon_views_[i]->SetBoundsRect( 185 top_icon_views_[i]->SetBoundsRect(
256 app_list_folder_view_->ConvertRectToParent( 186 app_list_folder_view_->ConvertRectToParent(
257 app_list_folder_view_->GetItemIconBoundsAt(i))); 187 app_list_folder_view_->GetItemIconBoundsAt(i)));
258 static_cast<TopIconAnimationView*>(top_icon_views_[i])->TransformView(); 188 static_cast<TopIconAnimationView*>(top_icon_views_[i])->TransformView();
259 } 189 }
260 } 190 }
261 191
192 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) {
193 if (folder_item)
194 CreateViewsForFolderTopItemsAnimation(folder_item, false);
195
196 // Hide the active folder item until the animation completes.
197 if (apps_grid_view_->activated_item_view())
198 apps_grid_view_->activated_item_view()->SetVisible(false);
199 }
200
262 } // namespace app_list 201 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698