• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 namespace app_list {
23 class ApplicationDragAndDropHost;
24 class AppListView;
25 }
26 
27 namespace ui {
28 class LocatedEvent;
29 }
30 
31 namespace ash {
32 namespace test {
33 class 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.
40 class 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 SetVisible(bool visible, aura::Window* window);
57 
58   // Whether app list window is visible (shown or being shown).
59   bool IsVisible() const;
60 
61   // Returns target visibility. This differs from IsVisible() if an animation
62   // is ongoing.
GetTargetVisibility()63   bool GetTargetVisibility() const { return is_visible_; }
64 
65   // Returns app list window or NULL if it is not visible.
66   aura::Window* GetWindow();
67 
68   // Returns app list view or NULL if it is not visible.
GetView()69   app_list::AppListView* GetView() { return view_; }
70 
71  private:
72   friend class test::AppListControllerTestApi;
73 
74   // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
75   // operations outside the application list.
76   void SetDragAndDropHostOfCurrentAppList(
77       app_list::ApplicationDragAndDropHost* drag_and_drop_host);
78 
79   // Sets the app list view and attempts to show it.
80   void SetView(app_list::AppListView* view);
81 
82   // Forgets the view.
83   void ResetView();
84 
85   // Starts show/hide animation.
86   void ScheduleAnimation();
87 
88   void ProcessLocatedEvent(ui::LocatedEvent* event);
89 
90   // Makes app list bubble update its bounds.
91   void UpdateBounds();
92 
93   // ui::EventHandler overrides:
94   virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
95   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
96 
97   // aura::client::FocusChangeObserver overrides:
98   virtual void OnWindowFocused(aura::Window* gained_focus,
99                                aura::Window* lost_focus) OVERRIDE;
100 
101   // aura::WindowObserver overrides:
102   virtual void OnWindowBoundsChanged(aura::Window* root,
103                                      const gfx::Rect& old_bounds,
104                                      const gfx::Rect& new_bounds) OVERRIDE;
105 
106   // ui::ImplicitAnimationObserver overrides:
107   virtual void OnImplicitAnimationsCompleted() OVERRIDE;
108 
109   // views::WidgetObserver overrides:
110   virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
111 
112   // KeyboardControllerObserver overrides:
113   virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE;
114 
115   // ShellObserver overrides:
116   virtual void OnShelfAlignmentChanged(aura::Window* root_window) OVERRIDE;
117 
118   // ShelfIconObserver overrides:
119   virtual void OnShelfIconPositionsChanged() OVERRIDE;
120 
121   // app_list::PaginationModelObserver overrides:
122   virtual void TotalPagesChanged() OVERRIDE;
123   virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE;
124   virtual void TransitionStarted() OVERRIDE;
125   virtual void TransitionChanged() OVERRIDE;
126 
127   // Whether we should show or hide app list widget.
128   bool is_visible_;
129 
130   // Whether the app list should remain centered.
131   bool is_centered_;
132 
133   // The AppListView this class manages, owned by its widget.
134   app_list::AppListView* view_;
135 
136   // The current page of the AppsGridView of |view_|. This is stored outside of
137   // the view's PaginationModel, so that it persists when the view is destroyed.
138   int current_apps_page_;
139 
140   // Cached bounds of |view_| for snapping back animation after over-scroll.
141   gfx::Rect view_bounds_;
142 
143   // Whether should schedule snap back animation.
144   bool should_snap_back_;
145 
146   DISALLOW_COPY_AND_ASSIGN(AppListController);
147 };
148 
149 }  // namespace ash
150 
151 #endif  // ASH_WM_APP_LIST_CONTROLLER_H_
152