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

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: Address review comments. 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
« no previous file with comments | « ui/app_list/views/apps_container_view.h ('k') | ui/app_list/views/apps_grid_view.h » ('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 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),
27 top_icon_animation_pending_count_(0) {
120 apps_grid_view_ = new AppsGridView( 28 apps_grid_view_ = new AppsGridView(
121 app_list_main_view, pagination_model, start_page_contents); 29 app_list_main_view, pagination_model, start_page_contents);
122 apps_grid_view_->SetLayout(kPreferredIconDimension, 30 apps_grid_view_->SetLayout(kPreferredIconDimension,
123 kPreferredCols, 31 kPreferredCols,
124 kPreferredRows); 32 kPreferredRows);
125 AddChildView(apps_grid_view_); 33 AddChildView(apps_grid_view_);
126 34
35 folder_background_view_ = new FolderBackgroundView();
36 AddChildView(folder_background_view_);
37
127 app_list_folder_view_ = new AppListFolderView( 38 app_list_folder_view_ = new AppListFolderView(
128 this, 39 this,
129 model, 40 model,
130 app_list_main_view, 41 app_list_main_view,
131 start_page_contents); 42 start_page_contents);
132 AddChildView(app_list_folder_view_); 43 AddChildView(app_list_folder_view_);
133 44
134 apps_grid_view_->SetModel(model_); 45 apps_grid_view_->SetModel(model_);
135 apps_grid_view_->SetItemList(model_->item_list()); 46 apps_grid_view_->SetItemList(model_->item_list());
136 } 47 }
137 48
138 AppsContainerView::~AppsContainerView() { 49 AppsContainerView::~AppsContainerView() {
139 } 50 }
140 51
141 void AppsContainerView::ShowActiveFolder(AppListFolderItem* folder_item) { 52 void AppsContainerView::ShowActiveFolder(AppListFolderItem* folder_item) {
142 app_list_folder_view_->SetAppListFolderItem(folder_item); 53 app_list_folder_view_->SetAppListFolderItem(folder_item);
143 SetShowState(SHOW_ACTIVE_FOLDER); 54 SetShowState(SHOW_ACTIVE_FOLDER);
144 55
145 CreateViewsForFolderTopItemsAnimation(folder_item, true); 56 CreateViewsForFolderTopItemsAnimation(folder_item, true);
146 } 57 }
147 58
148 void AppsContainerView::ShowApps(AppListFolderItem* folder_item) { 59 void AppsContainerView::ShowApps(AppListFolderItem* folder_item) {
149 if (folder_item) 60 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); 61 SetShowState(SHOW_APPS);
156 } 62 }
157 63
64 void AppsContainerView::SetDragAndDropHostOfCurrentAppList(
65 ApplicationDragAndDropHost* drag_and_drop_host) {
66 apps_grid_view()->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
67 app_list_folder_view()->items_grid_view()->
68 SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
69 }
70
71 void AppsContainerView::ReparentFolderItemTransit(
72 AppListFolderItem* folder_item) {
73 PrepareToShowApps(folder_item);
74 SetShowState(SHOW_ITEM_REPARENT);
75 }
76
158 gfx::Size AppsContainerView::GetPreferredSize() { 77 gfx::Size AppsContainerView::GetPreferredSize() {
159 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); 78 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize();
160 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize(); 79 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize();
161 80
162 int width = std::max(grid_size.width(), folder_view_size.width()); 81 int width = std::max(grid_size.width(), folder_view_size.width());
163 int height = std::max(grid_size.height(), folder_view_size.height()); 82 int height = std::max(grid_size.height(), folder_view_size.height());
164 return gfx::Size(width, height); 83 return gfx::Size(width, height);
165 } 84 }
166 85
167 void AppsContainerView::Layout() { 86 void AppsContainerView::Layout() {
168 gfx::Rect rect(GetContentsBounds()); 87 gfx::Rect rect(GetContentsBounds());
169 if (rect.IsEmpty()) 88 if (rect.IsEmpty())
170 return; 89 return;
171 90
172 switch (show_state_) { 91 switch (show_state_) {
173 case SHOW_APPS: 92 case SHOW_APPS:
174 app_list_folder_view_->ScheduleShowHideAnimation(false); 93 folder_background_view_->SetVisible(false);
94 app_list_folder_view_->ScheduleShowHideAnimation(false, false);
175 apps_grid_view_->SetBoundsRect(rect); 95 apps_grid_view_->SetBoundsRect(rect);
176 apps_grid_view_->ScheduleShowHideAnimation(true); 96 apps_grid_view_->ScheduleShowHideAnimation(true);
177 break; 97 break;
178 case SHOW_ACTIVE_FOLDER: 98 case SHOW_ACTIVE_FOLDER:
99 folder_background_view_->SetBoundsRect(rect);
100 folder_background_view_->SetVisible(true);
179 apps_grid_view_->ScheduleShowHideAnimation(false); 101 apps_grid_view_->ScheduleShowHideAnimation(false);
180 app_list_folder_view_->SetBoundsRect(rect); 102 app_list_folder_view_->SetBoundsRect(rect);
181 app_list_folder_view_->ScheduleShowHideAnimation(true); 103 app_list_folder_view_->ScheduleShowHideAnimation(true, false);
104 break;
105 case SHOW_ITEM_REPARENT:
106 folder_background_view_->SetVisible(false);
107 folder_background_view_->UpdateFolderContainerBubble(
108 FolderBackgroundView::NO_BUBBLE);
109 app_list_folder_view_->ScheduleShowHideAnimation(false, true);
110 apps_grid_view_->ScheduleShowHideAnimation(true);
182 break; 111 break;
183 default: 112 default:
184 NOTREACHED(); 113 NOTREACHED();
185 } 114 }
186 } 115 }
187 116
188 bool AppsContainerView::OnKeyPressed(const ui::KeyEvent& event) { 117 bool AppsContainerView::OnKeyPressed(const ui::KeyEvent& event) {
189 if (show_state_ == SHOW_APPS) 118 if (show_state_ == SHOW_APPS)
190 return apps_grid_view_->OnKeyPressed(event); 119 return apps_grid_view_->OnKeyPressed(event);
191 else 120 else
192 return app_list_folder_view_->OnKeyPressed(event); 121 return app_list_folder_view_->OnKeyPressed(event);
193 } 122 }
194 123
195 void AppsContainerView::OnTopIconAnimationsComplete(views::View* icon_view) { 124 void AppsContainerView::OnTopIconAnimationsComplete() {
196 bool animations_done = true; 125 --top_icon_animation_pending_count_;
197 for (size_t i = 0; i < top_icon_views_.size(); ++i) {
198 if (top_icon_views_[i]->visible()) {
199 animations_done = false;
200 break;
201 }
202 }
203 126
204 if (animations_done) { 127 if (!top_icon_animation_pending_count_) {
205 // Clean up the transitional views using for top item icon animation. 128 // Clean up the transitional views used for top item icon animation.
206 for (size_t i = 0; i < top_icon_views_.size(); ++i) {
207 TopIconAnimationView* icon_view =
208 static_cast<TopIconAnimationView*>(top_icon_views_[i]);
209 icon_view->RemoveObserver(this);
210 delete icon_view;
211 }
212 top_icon_views_.clear(); 129 top_icon_views_.clear();
213 130
214 // Show the folder icon when closing the folder. 131 // Show the folder icon when closing the folder.
215 if (show_state_ == SHOW_APPS && apps_grid_view_->activated_item_view()) 132 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) &&
133 apps_grid_view_->activated_item_view()) {
216 apps_grid_view_->activated_item_view()->SetVisible(true); 134 apps_grid_view_->activated_item_view()->SetVisible(true);
135 }
217 } 136 }
218 } 137 }
219 138
220 void AppsContainerView::SetShowState(ShowState show_state) { 139 void AppsContainerView::SetShowState(ShowState show_state) {
221 if (show_state_ == show_state) 140 if (show_state_ == show_state)
222 return; 141 return;
223 142
224 show_state_ = show_state; 143 show_state_ = show_state;
225 Layout(); 144 Layout();
226 } 145 }
227 146
228 Rects AppsContainerView::GetTopItemIconBoundsInActiveFolder() { 147 Rects AppsContainerView::GetTopItemIconBoundsInActiveFolder() {
229 // Get the active folder's icon bounds relative to AppsContainerView. 148 // Get the active folder's icon bounds relative to AppsContainerView.
230 AppListItemView* folder_view = apps_grid_view_->activated_item_view(); 149 AppListItemView* folder_item_view = apps_grid_view_->activated_item_view();
231 gfx::Rect to_grid_view = folder_view->ConvertRectToParent( 150 gfx::Rect to_grid_view = folder_item_view->ConvertRectToParent(
232 folder_view->GetIconBounds()); 151 folder_item_view->GetIconBounds());
233 gfx::Rect to_container = apps_grid_view_->ConvertRectToParent(to_grid_view); 152 gfx::Rect to_container = apps_grid_view_->ConvertRectToParent(to_grid_view);
234 153
235 return AppListFolderItem::GetTopIconsBounds(to_container); 154 return AppListFolderItem::GetTopIconsBounds(to_container);
236 } 155 }
237 156
238 void AppsContainerView::CreateViewsForFolderTopItemsAnimation( 157 void AppsContainerView::CreateViewsForFolderTopItemsAnimation(
239 AppListFolderItem* active_folder, 158 AppListFolderItem* active_folder,
240 bool open_folder) { 159 bool open_folder) {
241 top_icon_views_.clear(); 160 top_icon_views_.clear();
242 std::vector<gfx::Rect> top_items_bounds = 161 std::vector<gfx::Rect> top_items_bounds =
243 GetTopItemIconBoundsInActiveFolder(); 162 GetTopItemIconBoundsInActiveFolder();
244 size_t top_items_count = 163 top_icon_animation_pending_count_ =
245 std::min(kNumFolderTopItems, active_folder->item_list()->item_count()); 164 std::min(kNumFolderTopItems, active_folder->item_list()->item_count());
246 for (size_t i = 0; i < top_items_count; ++i) { 165 for (size_t i = 0; i < top_icon_animation_pending_count_; ++i) {
247 TopIconAnimationView* icon_view = new TopIconAnimationView( 166 TopIconAnimationView* icon_view = new TopIconAnimationView(
248 active_folder->GetTopIcon(i), top_items_bounds[i], open_folder); 167 active_folder->GetTopIcon(i), top_items_bounds[i], open_folder);
249 icon_view->AddObserver(this); 168 icon_view->AddObserver(this);
250 top_icon_views_.push_back(icon_view); 169 top_icon_views_.push_back(icon_view);
251 170
252 // Add the transitional views into child views, and set its bounds to the 171 // Add the transitional views into child views, and set its bounds to the
253 // same location of the item in the folder list view. 172 // same location of the item in the folder list view.
254 AddChildView(top_icon_views_[i]); 173 AddChildView(top_icon_views_[i]);
255 top_icon_views_[i]->SetBoundsRect( 174 top_icon_views_[i]->SetBoundsRect(
256 app_list_folder_view_->ConvertRectToParent( 175 app_list_folder_view_->ConvertRectToParent(
257 app_list_folder_view_->GetItemIconBoundsAt(i))); 176 app_list_folder_view_->GetItemIconBoundsAt(i)));
258 static_cast<TopIconAnimationView*>(top_icon_views_[i])->TransformView(); 177 static_cast<TopIconAnimationView*>(top_icon_views_[i])->TransformView();
259 } 178 }
260 } 179 }
261 180
181 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) {
182 if (folder_item)
183 CreateViewsForFolderTopItemsAnimation(folder_item, false);
184
185 // Hide the active folder item until the animation completes.
186 if (apps_grid_view_->activated_item_view())
187 apps_grid_view_->activated_item_view()->SetVisible(false);
188 }
189
262 } // namespace app_list 190 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/apps_container_view.h ('k') | ui/app_list/views/apps_grid_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698