blob: d2408d8bac4afba0be8384b8eb541311b07a71eb [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"
12#include "base/timer.h"
13#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)58218062012-11-14 11:43:16 +000015#include "ui/aura/root_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 {
22class AppListView;
23class PaginationModel;
24}
25
26namespace ui {
27class LocatedEvent;
28}
29
30namespace ash {
31namespace internal {
32
33// AppListController is a controller that manages app list UI for shell.
34// It creates AppListView and schedules showing/hiding animation.
35// While the UI is visible, it monitors things such as app list widget's
36// activation state and desktop mouse click to auto dismiss the UI.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000037class AppListController : public ui::EventHandler,
38 public aura::client::FocusChangeObserver,
Torne (Richard Coles)58218062012-11-14 11:43:16 +000039 public aura::RootWindowObserver,
40 public ui::ImplicitAnimationObserver,
41 public views::WidgetObserver,
42 public ShellObserver,
43 public LauncherIconObserver,
44 public app_list::PaginationModelObserver {
45 public:
46 AppListController();
47 virtual ~AppListController();
48
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000049 // Show/hide app list window. The |window| is used to deterime in
50 // which display (in which the |window| exists) the app list should
51 // be shown.
52 void SetVisible(bool visible, aura::Window* window);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000053
54 // Whether app list window is visible (shown or being shown).
55 bool IsVisible() const;
56
57 // Returns target visibility. This differs from IsVisible() if an animation
58 // is ongoing.
59 bool GetTargetVisibility() const { return is_visible_; }
60
61 // Returns app list window or NULL if it is not visible.
62 aura::Window* GetWindow();
63
64 private:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000065 // Sets the app list view and attempts to show it.
Torne (Richard Coles)58218062012-11-14 11:43:16 +000066 void SetView(app_list::AppListView* view);
67
68 // Forgets the view.
69 void ResetView();
70
71 // Starts show/hide animation.
72 void ScheduleAnimation();
73
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000074 void ProcessLocatedEvent(ui::LocatedEvent* event);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000075
76 // Makes app list bubble update its bounds.
77 void UpdateBounds();
78
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000079 // ui::EventHandler overrides:
80 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
81 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000082
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000083 // aura::client::FocusChangeObserver overrides:
84 virtual void OnWindowFocused(aura::Window* gained_focus,
85 aura::Window* lost_focus) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000086
87 // aura::RootWindowObserver overrides:
88 virtual void OnRootWindowResized(const aura::RootWindow* root,
89 const gfx::Size& old_size) OVERRIDE;
90
91 // ui::ImplicitAnimationObserver overrides:
92 virtual void OnImplicitAnimationsCompleted() OVERRIDE;
93
94 // views::WidgetObserver overrides:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000095 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000096
97 // ShellObserver overrides:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000098 virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000099
100 // LauncherIconObserver overrides:
101 virtual void OnLauncherIconPositionsChanged() OVERRIDE;
102
103 // app_list::PaginationModelObserver overrides:
104 virtual void TotalPagesChanged() OVERRIDE;
105 virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE;
106 virtual void TransitionChanged() OVERRIDE;
107
108 scoped_ptr<app_list::PaginationModel> pagination_model_;
109
110 // Whether we should show or hide app list widget.
111 bool is_visible_;
112
113 // The AppListView this class manages, owned by its widget.
114 app_list::AppListView* view_;
115
116 // Cached bounds of |view_| for snapping back animation after over-scroll.
117 gfx::Rect view_bounds_;
118
119 // Whether should schedule snap back animation.
120 bool should_snap_back_;
121
122 DISALLOW_COPY_AND_ASSIGN(AppListController);
123};
124
125} // namespace internal
126} // namespace ash
127
128#endif // ASH_WM_APP_LIST_CONTROLLER_H_