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

Side by Side Diff: ash/wm/app_list_controller.cc

Issue 302803002: Refactor app list so AppsGridView owns the PaginationModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests and bugs. Created 6 years, 6 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 (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/wm/app_list_controller.h" 5 #include "ash/wm/app_list_controller.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/screen_util.h" 9 #include "ash/screen_util.h"
10 #include "ash/shelf/shelf.h" 10 #include "ash/shelf/shelf.h"
11 #include "ash/shelf/shelf_layout_manager.h" 11 #include "ash/shelf/shelf_layout_manager.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_delegate.h" 13 #include "ash/shell_delegate.h"
14 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "ui/app_list/app_list_constants.h" 16 #include "ui/app_list/app_list_constants.h"
17 #include "ui/app_list/app_list_switches.h" 17 #include "ui/app_list/app_list_switches.h"
18 #include "ui/app_list/pagination_model.h" 18 #include "ui/app_list/pagination_model.h"
19 #include "ui/app_list/views/app_list_main_view.h"
19 #include "ui/app_list/views/app_list_view.h" 20 #include "ui/app_list/views/app_list_view.h"
21 #include "ui/app_list/views/apps_container_view.h"
22 #include "ui/app_list/views/apps_grid_view.h"
23 #include "ui/app_list/views/contents_view.h"
20 #include "ui/aura/client/focus_client.h" 24 #include "ui/aura/client/focus_client.h"
21 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
22 #include "ui/aura/window_event_dispatcher.h" 26 #include "ui/aura/window_event_dispatcher.h"
23 #include "ui/compositor/layer.h" 27 #include "ui/compositor/layer.h"
24 #include "ui/compositor/scoped_layer_animation_settings.h" 28 #include "ui/compositor/scoped_layer_animation_settings.h"
25 #include "ui/events/event.h" 29 #include "ui/events/event.h"
26 #include "ui/gfx/transform_util.h" 30 #include "ui/gfx/transform_util.h"
27 #include "ui/keyboard/keyboard_controller.h" 31 #include "ui/keyboard/keyboard_controller.h"
28 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
29 33
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 int GetMinimumBoundsHeightForAppList(const app_list::AppListView* app_list) { 150 int GetMinimumBoundsHeightForAppList(const app_list::AppListView* app_list) {
147 return app_list->bounds().height() + 2 * kMinimalCenteredAppListMargin; 151 return app_list->bounds().height() + 2 * kMinimalCenteredAppListMargin;
148 } 152 }
149 153
150 } // namespace 154 } // namespace
151 155
152 //////////////////////////////////////////////////////////////////////////////// 156 ////////////////////////////////////////////////////////////////////////////////
153 // AppListController, public: 157 // AppListController, public:
154 158
155 AppListController::AppListController() 159 AppListController::AppListController()
156 : pagination_model_(new app_list::PaginationModel), 160 : is_visible_(false),
157 is_visible_(false),
158 is_centered_(false), 161 is_centered_(false),
159 view_(NULL), 162 view_(NULL),
163 pagination_model_(NULL),
164 current_app_page_(-1),
160 should_snap_back_(false) { 165 should_snap_back_(false) {
161 Shell::GetInstance()->AddShellObserver(this); 166 Shell::GetInstance()->AddShellObserver(this);
162 pagination_model_->AddObserver(this);
163 } 167 }
164 168
165 AppListController::~AppListController() { 169 AppListController::~AppListController() {
166 // Ensures app list view goes before the controller since pagination model 170 // Ensures app list view goes before the controller since pagination model
167 // lives in the controller and app list view would access it on destruction. 171 // lives in the controller and app list view would access it on destruction.
168 if (view_ && view_->GetWidget()) 172 if (view_) {
169 view_->GetWidget()->CloseNow(); 173 DCHECK(pagination_model_);
174 pagination_model_->RemoveObserver(this);
175 if (view_->GetWidget())
176 view_->GetWidget()->CloseNow();
177 } else {
178 DCHECK(!pagination_model_);
179 }
170 180
171 Shell::GetInstance()->RemoveShellObserver(this); 181 Shell::GetInstance()->RemoveShellObserver(this);
172 pagination_model_->RemoveObserver(this);
173 } 182 }
174 183
175 void AppListController::SetVisible(bool visible, aura::Window* window) { 184 void AppListController::SetVisible(bool visible, aura::Window* window) {
176 if (visible == is_visible_) 185 if (visible == is_visible_)
177 return; 186 return;
178 187
179 is_visible_ = visible; 188 is_visible_ = visible;
180 189
181 // App list needs to know the new shelf layout in order to calculate its 190 // App list needs to know the new shelf layout in order to calculate its
182 // UI layout when AppListView visibility changes. 191 // UI layout when AppListView visibility changes.
(...skipping 18 matching lines...) Expand all
201 aura::Window* container = GetRootWindowController(root_window)-> 210 aura::Window* container = GetRootWindowController(root_window)->
202 GetContainer(kShellWindowId_AppListContainer); 211 GetContainer(kShellWindowId_AppListContainer);
203 views::View* applist_button = 212 views::View* applist_button =
204 Shelf::ForWindow(container)->GetAppListButtonView(); 213 Shelf::ForWindow(container)->GetAppListButtonView();
205 is_centered_ = view->ShouldCenterWindow(); 214 is_centered_ = view->ShouldCenterWindow();
206 if (is_centered_) { 215 if (is_centered_) {
207 // Note: We can't center the app list until we have its dimensions, so we 216 // Note: We can't center the app list until we have its dimensions, so we
208 // init at (0, 0) and then reset its anchor point. 217 // init at (0, 0) and then reset its anchor point.
209 view->InitAsBubbleAtFixedLocation( 218 view->InitAsBubbleAtFixedLocation(
210 container, 219 container,
211 pagination_model_.get(),
212 gfx::Point(), 220 gfx::Point(),
213 views::BubbleBorder::FLOAT, 221 views::BubbleBorder::FLOAT,
214 true /* border_accepts_events */); 222 true /* border_accepts_events */);
215 // The experimental app list is centered over the display of the app list 223 // The experimental app list is centered over the display of the app list
216 // button that was pressed (if triggered via keyboard, this is the display 224 // button that was pressed (if triggered via keyboard, this is the display
217 // with the currently focused window). 225 // with the currently focused window).
218 view->SetAnchorPoint(GetCenterOfDisplayForView( 226 view->SetAnchorPoint(GetCenterOfDisplayForView(
219 applist_button, GetMinimumBoundsHeightForAppList(view))); 227 applist_button, GetMinimumBoundsHeightForAppList(view)));
220 } else { 228 } else {
221 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); 229 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen();
222 // We need the location of the button within the local screen. 230 // We need the location of the button within the local screen.
223 applist_button_bounds = ScreenUtil::ConvertRectFromScreen( 231 applist_button_bounds = ScreenUtil::ConvertRectFromScreen(
224 root_window, 232 root_window,
225 applist_button_bounds); 233 applist_button_bounds);
226 view->InitAsBubbleAttachedToAnchor( 234 view->InitAsBubbleAttachedToAnchor(
227 container, 235 container,
228 pagination_model_.get(),
229 Shelf::ForWindow(container)->GetAppListButtonView(), 236 Shelf::ForWindow(container)->GetAppListButtonView(),
230 GetAnchorPositionOffsetToShelf(applist_button_bounds, 237 GetAnchorPositionOffsetToShelf(applist_button_bounds,
231 Shelf::ForWindow(container)->GetAppListButtonView()-> 238 Shelf::ForWindow(container)->GetAppListButtonView()->
232 GetWidget()), 239 GetWidget()),
233 GetBubbleArrow(container), 240 GetBubbleArrow(container),
234 true /* border_accepts_events */); 241 true /* border_accepts_events */);
235 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 242 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
236 } 243 }
237 SetView(view); 244 SetView(view);
238 // By setting us as DnD recipient, the app list knows that we can 245 // By setting us as DnD recipient, the app list knows that we can
(...skipping 17 matching lines...) Expand all
256 // AppListController, private: 263 // AppListController, private:
257 264
258 void AppListController::SetDragAndDropHostOfCurrentAppList( 265 void AppListController::SetDragAndDropHostOfCurrentAppList(
259 app_list::ApplicationDragAndDropHost* drag_and_drop_host) { 266 app_list::ApplicationDragAndDropHost* drag_and_drop_host) {
260 if (view_ && is_visible_) 267 if (view_ && is_visible_)
261 view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); 268 view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
262 } 269 }
263 270
264 void AppListController::SetView(app_list::AppListView* view) { 271 void AppListController::SetView(app_list::AppListView* view) {
265 DCHECK(view_ == NULL); 272 DCHECK(view_ == NULL);
273 DCHECK(pagination_model_ == NULL);
266 DCHECK(is_visible_); 274 DCHECK(is_visible_);
267 275
268 view_ = view; 276 view_ = view;
269 views::Widget* widget = view_->GetWidget(); 277 views::Widget* widget = view_->GetWidget();
270 widget->AddObserver(this); 278 widget->AddObserver(this);
271 keyboard::KeyboardController* keyboard_controller = 279 keyboard::KeyboardController* keyboard_controller =
272 keyboard::KeyboardController::GetInstance(); 280 keyboard::KeyboardController::GetInstance();
273 if (keyboard_controller) 281 if (keyboard_controller)
274 keyboard_controller->AddObserver(this); 282 keyboard_controller->AddObserver(this);
275 Shell::GetInstance()->AddPreTargetHandler(this); 283 Shell::GetInstance()->AddPreTargetHandler(this);
276 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); 284 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this);
277 widget->GetNativeView()->GetRootWindow()->AddObserver(this); 285 widget->GetNativeView()->GetRootWindow()->AddObserver(this);
278 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); 286 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this);
279 287
288 pagination_model_ = view_->app_list_main_view()
tapted 2014/06/02 04:02:21 I think this justifies a GetPaginationModel() acce
Matt Giuca 2014/06/02 07:11:23 Done & Done.
289 ->contents_view()
290 ->apps_container_view()
291 ->apps_grid_view()
292 ->GetPaginationModel();
293 pagination_model_->AddObserver(this);
294 if (pagination_model_->is_valid_page(current_app_page_))
295 pagination_model_->SelectPage(current_app_page_, false);
296
280 view_->ShowWhenReady(); 297 view_->ShowWhenReady();
281 } 298 }
282 299
283 void AppListController::ResetView() { 300 void AppListController::ResetView() {
284 if (!view_) 301 if (!view_)
285 return; 302 return;
286 303
287 views::Widget* widget = view_->GetWidget(); 304 views::Widget* widget = view_->GetWidget();
288 widget->RemoveObserver(this); 305 widget->RemoveObserver(this);
289 GetLayer(widget)->GetAnimator()->RemoveObserver(this); 306 GetLayer(widget)->GetAnimator()->RemoveObserver(this);
290 keyboard::KeyboardController* keyboard_controller = 307 keyboard::KeyboardController* keyboard_controller =
291 keyboard::KeyboardController::GetInstance(); 308 keyboard::KeyboardController::GetInstance();
292 if (keyboard_controller) 309 if (keyboard_controller)
293 keyboard_controller->RemoveObserver(this); 310 keyboard_controller->RemoveObserver(this);
294 Shell::GetInstance()->RemovePreTargetHandler(this); 311 Shell::GetInstance()->RemovePreTargetHandler(this);
295 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); 312 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this);
296 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); 313 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this);
297 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); 314 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this);
315
316 DCHECK(pagination_model_);
317 pagination_model_->RemoveObserver(this);
318 pagination_model_ = NULL;
319
298 view_ = NULL; 320 view_ = NULL;
299 } 321 }
300 322
301 void AppListController::ScheduleAnimation() { 323 void AppListController::ScheduleAnimation() {
302 // Stop observing previous animation. 324 // Stop observing previous animation.
303 StopObservingImplicitAnimations(); 325 StopObservingImplicitAnimations();
304 326
305 views::Widget* widget = view_->GetWidget(); 327 views::Widget* widget = view_->GetWidget();
306 ui::Layer* layer = GetLayer(widget); 328 ui::Layer* layer = GetLayer(widget);
307 layer->GetAnimator()->StopAnimating(); 329 layer->GetAnimator()->StopAnimating();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 } 464 }
443 465
444 //////////////////////////////////////////////////////////////////////////////// 466 ////////////////////////////////////////////////////////////////////////////////
445 // AppListController, PaginationModelObserver implementation: 467 // AppListController, PaginationModelObserver implementation:
446 468
447 void AppListController::TotalPagesChanged() { 469 void AppListController::TotalPagesChanged() {
448 } 470 }
449 471
450 void AppListController::SelectedPageChanged(int old_selected, 472 void AppListController::SelectedPageChanged(int old_selected,
451 int new_selected) { 473 int new_selected) {
474 current_app_page_ = new_selected;
452 } 475 }
453 476
454 void AppListController::TransitionStarted() { 477 void AppListController::TransitionStarted() {
455 } 478 }
456 479
457 void AppListController::TransitionChanged() { 480 void AppListController::TransitionChanged() {
458 // |view_| could be NULL when app list is closed with a running transition. 481 // |view_| could be NULL when app list is closed with a running transition.
459 if (!view_) 482 if (!view_)
460 return; 483 return;
461 484
485 DCHECK(pagination_model_);
486
462 const app_list::PaginationModel::Transition& transition = 487 const app_list::PaginationModel::Transition& transition =
463 pagination_model_->transition(); 488 pagination_model_->transition();
464 if (pagination_model_->is_valid_page(transition.target_page)) 489 if (pagination_model_->is_valid_page(transition.target_page))
465 return; 490 return;
466 491
467 views::Widget* widget = view_->GetWidget(); 492 views::Widget* widget = view_->GetWidget();
468 ui::LayerAnimator* widget_animator = GetLayer(widget)->GetAnimator(); 493 ui::LayerAnimator* widget_animator = GetLayer(widget)->GetAnimator();
469 if (!pagination_model_->IsRevertingCurrentTransition()) { 494 if (!pagination_model_->IsRevertingCurrentTransition()) {
470 // Update cached |view_bounds_| if it is the first over-scroll move and 495 // Update cached |view_bounds_| if it is the first over-scroll move and
471 // widget does not have running animations. 496 // widget does not have running animations.
(...skipping 13 matching lines...) Expand all
485 } else if (should_snap_back_) { 510 } else if (should_snap_back_) {
486 should_snap_back_ = false; 511 should_snap_back_ = false;
487 ui::ScopedLayerAnimationSettings animation(widget_animator); 512 ui::ScopedLayerAnimationSettings animation(widget_animator);
488 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( 513 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
489 app_list::kOverscrollPageTransitionDurationMs)); 514 app_list::kOverscrollPageTransitionDurationMs));
490 widget->SetBounds(view_bounds_); 515 widget->SetBounds(view_bounds_);
491 } 516 }
492 } 517 }
493 518
494 } // namespace ash 519 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698