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 3// found in the LICENSE file. 4 5#ifndef ASH_WM_APP_LIST_CONTROLLER_H_ 6#define ASH_WM_APP_LIST_CONTROLLER_H_ 7 8#include "ash/shelf/shelf_icon_observer.h" 9#include "ash/shell_observer.h" 10#include "base/basictypes.h" 11#include "base/compiler_specific.h" 12#include "base/timer/timer.h" 13#include "ui/app_list/pagination_model_observer.h" 14#include "ui/aura/client/focus_change_observer.h" 15#include "ui/aura/window_observer.h" 16#include "ui/compositor/layer_animation_observer.h" 17#include "ui/events/event_handler.h" 18#include "ui/gfx/rect.h" 19#include "ui/keyboard/keyboard_controller_observer.h" 20#include "ui/views/widget/widget_observer.h" 21 22namespace app_list { 23class ApplicationDragAndDropHost; 24class AppListView; 25} 26 27namespace ui { 28class LocatedEvent; 29} 30 31namespace ash { 32namespace test { 33class AppListControllerTestApi; 34} 35 36// AppListController is a controller that manages app list UI for shell. 37// It creates AppListView and schedules showing/hiding animation. 38// While the UI is visible, it monitors things such as app list widget's 39// activation state and desktop mouse click to auto dismiss the UI. 40class AppListController : public ui::EventHandler, 41 public aura::client::FocusChangeObserver, 42 public aura::WindowObserver, 43 public ui::ImplicitAnimationObserver, 44 public views::WidgetObserver, 45 public keyboard::KeyboardControllerObserver, 46 public ShellObserver, 47 public ShelfIconObserver, 48 public app_list::PaginationModelObserver { 49 public: 50 AppListController(); 51 virtual ~AppListController(); 52 53 // Show/hide app list window. The |window| is used to deterime in 54 // which display (in which the |window| exists) the app list should 55 // be shown. 56 void Show(aura::Window* window); 57 void Dismiss(); 58 59 // Whether app list window is visible (shown or being shown). 60 bool IsVisible() const; 61 62 // Returns target visibility. This differs from IsVisible() if an animation 63 // is ongoing. 64 bool GetTargetVisibility() const { return is_visible_; } 65 66 // Returns app list window or NULL if it is not visible. 67 aura::Window* GetWindow(); 68 69 // Returns app list view or NULL if it is not visible. 70 app_list::AppListView* GetView() { return view_; } 71 72 private: 73 friend class test::AppListControllerTestApi; 74 75 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop 76 // operations outside the application list. 77 void SetDragAndDropHostOfCurrentAppList( 78 app_list::ApplicationDragAndDropHost* drag_and_drop_host); 79 80 // Sets the app list view and attempts to show it. 81 void SetView(app_list::AppListView* view); 82 83 // Forgets the view. 84 void ResetView(); 85 86 // Starts show/hide animation. 87 void ScheduleAnimation(); 88 89 void ProcessLocatedEvent(ui::LocatedEvent* event); 90 91 // Makes app list bubble update its bounds. 92 void UpdateBounds(); 93 94 // ui::EventHandler overrides: 95 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 96 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 97 98 // aura::client::FocusChangeObserver overrides: 99 virtual void OnWindowFocused(aura::Window* gained_focus, 100 aura::Window* lost_focus) OVERRIDE; 101 102 // aura::WindowObserver overrides: 103 virtual void OnWindowBoundsChanged(aura::Window* root, 104 const gfx::Rect& old_bounds, 105 const gfx::Rect& new_bounds) OVERRIDE; 106 107 // ui::ImplicitAnimationObserver overrides: 108 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 109 110 // views::WidgetObserver overrides: 111 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 112 113 // KeyboardControllerObserver overrides: 114 virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE; 115 116 // ShellObserver overrides: 117 virtual void OnShelfAlignmentChanged(aura::Window* root_window) OVERRIDE; 118 119 // ShelfIconObserver overrides: 120 virtual void OnShelfIconPositionsChanged() OVERRIDE; 121 122 // app_list::PaginationModelObserver overrides: 123 virtual void TotalPagesChanged() OVERRIDE; 124 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE; 125 virtual void TransitionStarted() OVERRIDE; 126 virtual void TransitionChanged() OVERRIDE; 127 128 // Whether we should show or hide app list widget. 129 bool is_visible_; 130 131 // Whether the app list should remain centered. 132 bool is_centered_; 133 134 // The AppListView this class manages, owned by its widget. 135 app_list::AppListView* view_; 136 137 // The current page of the AppsGridView of |view_|. This is stored outside of 138 // the view's PaginationModel, so that it persists when the view is destroyed. 139 int current_apps_page_; 140 141 // Cached bounds of |view_| for snapping back animation after over-scroll. 142 gfx::Rect view_bounds_; 143 144 // Whether should schedule snap back animation. 145 bool should_snap_back_; 146 147 DISALLOW_COPY_AND_ASSIGN(AppListController); 148}; 149 150} // namespace ash 151 152#endif // ASH_WM_APP_LIST_CONTROLLER_H_ 153