blob: b2c7961a7fcb10ab6a922b1f299292bca2f52446 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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/launcher/launcher_icon_observer.h"
9#include "ash/shell_observer.h"
10#include "base/basictypes.h"
11#include "base/compiler_specific.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010012#include "base/timer/timer.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000013#include "ui/app_list/pagination_model_observer.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000014#include "ui/aura/client/focus_change_observer.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010015#include "ui/aura/window_observer.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000016#include "ui/base/events/event_handler.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000017#include "ui/compositor/layer_animation_observer.h"
18#include "ui/gfx/rect.h"
19#include "ui/views/widget/widget_observer.h"
20
21namespace app_list {
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +010022class ApplicationDragAndDropHost;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000023class AppListView;
24class PaginationModel;
25}
26
27namespace ui {
28class LocatedEvent;
29}
30
31namespace ash {
32namespace internal {
33
34// AppListController is a controller that manages app list UI for shell.
35// It creates AppListView and schedules showing/hiding animation.
36// While the UI is visible, it monitors things such as app list widget's
37// activation state and desktop mouse click to auto dismiss the UI.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000038class AppListController : public ui::EventHandler,
39 public aura::client::FocusChangeObserver,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010040 public aura::WindowObserver,
Torne (Richard Coles)58218062012-11-14 11:43:16 +000041 public ui::ImplicitAnimationObserver,
42 public views::WidgetObserver,
43 public ShellObserver,
44 public LauncherIconObserver,
45 public app_list::PaginationModelObserver {
46 public:
47 AppListController();
48 virtual ~AppListController();
49
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000050 // Show/hide app list window. The |window| is used to deterime in
51 // which display (in which the |window| exists) the app list should
52 // be shown.
53 void SetVisible(bool visible, aura::Window* window);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000054
55 // Whether app list window is visible (shown or being shown).
56 bool IsVisible() const;
57
58 // Returns target visibility. This differs from IsVisible() if an animation
59 // is ongoing.
60 bool GetTargetVisibility() const { return is_visible_; }
61
62 // Returns app list window or NULL if it is not visible.
63 aura::Window* GetWindow();
64
Ben Murdochbb1529c2013-08-08 10:24:53 +010065 private:
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +010066 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
67 // operations outside the application list.
68 void SetDragAndDropHostOfCurrentAppList(
69 app_list::ApplicationDragAndDropHost* drag_and_drop_host);
70
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000071 // Sets the app list view and attempts to show it.
Torne (Richard Coles)58218062012-11-14 11:43:16 +000072 void SetView(app_list::AppListView* view);
73
74 // Forgets the view.
75 void ResetView();
76
77 // Starts show/hide animation.
78 void ScheduleAnimation();
79
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000080 void ProcessLocatedEvent(ui::LocatedEvent* event);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000081
82 // Makes app list bubble update its bounds.
83 void UpdateBounds();
84
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000085 // ui::EventHandler overrides:
86 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
87 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000088
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000089 // aura::client::FocusChangeObserver overrides:
90 virtual void OnWindowFocused(aura::Window* gained_focus,
91 aura::Window* lost_focus) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000092
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010093 // aura::WindowObserver overrides:
94 virtual void OnWindowBoundsChanged(aura::Window* root,
95 const gfx::Rect& old_bounds,
96 const gfx::Rect& new_bounds) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000097
98 // ui::ImplicitAnimationObserver overrides:
99 virtual void OnImplicitAnimationsCompleted() OVERRIDE;
100
101 // views::WidgetObserver overrides:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000102 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000103
104 // ShellObserver overrides:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000105 virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000106
107 // LauncherIconObserver overrides:
108 virtual void OnLauncherIconPositionsChanged() OVERRIDE;
109
110 // app_list::PaginationModelObserver overrides:
111 virtual void TotalPagesChanged() OVERRIDE;
112 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100113 virtual void TransitionStarted() OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000114 virtual void TransitionChanged() OVERRIDE;
115
116 scoped_ptr<app_list::PaginationModel> pagination_model_;
117
118 // Whether we should show or hide app list widget.
119 bool is_visible_;
120
121 // The AppListView this class manages, owned by its widget.
122 app_list::AppListView* view_;
123
124 // Cached bounds of |view_| for snapping back animation after over-scroll.
125 gfx::Rect view_bounds_;
126
127 // Whether should schedule snap back animation.
128 bool should_snap_back_;
129
130 DISALLOW_COPY_AND_ASSIGN(AppListController);
131};
132
133} // namespace internal
134} // namespace ash
135
136#endif // ASH_WM_APP_LIST_CONTROLLER_H_