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.
5 #ifndef ASH_WM_APP_LIST_CONTROLLER_H_
6 #define ASH_WM_APP_LIST_CONTROLLER_H_
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/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/base/events/event_handler.h"
17 #include "ui/compositor/layer_animation_observer.h"
18 #include "ui/gfx/rect.h"
19 #include "ui/views/widget/widget_observer.h"
22 class ApplicationDragAndDropHost
;
24 class PaginationModel
;
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.
38 class AppListController
: public ui::EventHandler
,
39 public aura::client::FocusChangeObserver
,
40 public aura::WindowObserver
,
41 public ui::ImplicitAnimationObserver
,
42 public views::WidgetObserver
,
44 public LauncherIconObserver
,
45 public app_list::PaginationModelObserver
{
48 virtual ~AppListController();
50 // Show/hide app list window. The |window| is used to deterime in
51 // which display (in which the |window| exists) the app list should
53 void SetVisible(bool visible
, aura::Window
* window
);
55 // Whether app list window is visible (shown or being shown).
56 bool IsVisible() const;
58 // Returns target visibility. This differs from IsVisible() if an animation
60 bool GetTargetVisibility() const { return is_visible_
; }
62 // Returns app list window or NULL if it is not visible.
63 aura::Window
* GetWindow();
66 // 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
);
71 // Sets the app list view and attempts to show it.
72 void SetView(app_list::AppListView
* view
);
77 // Starts show/hide animation.
78 void ScheduleAnimation();
80 void ProcessLocatedEvent(ui::LocatedEvent
* event
);
82 // Makes app list bubble update its bounds.
85 // ui::EventHandler overrides:
86 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
;
87 virtual void OnGestureEvent(ui::GestureEvent
* event
) OVERRIDE
;
89 // aura::client::FocusChangeObserver overrides:
90 virtual void OnWindowFocused(aura::Window
* gained_focus
,
91 aura::Window
* lost_focus
) OVERRIDE
;
93 // aura::WindowObserver overrides:
94 virtual void OnWindowBoundsChanged(aura::Window
* root
,
95 const gfx::Rect
& old_bounds
,
96 const gfx::Rect
& new_bounds
) OVERRIDE
;
98 // ui::ImplicitAnimationObserver overrides:
99 virtual void OnImplicitAnimationsCompleted() OVERRIDE
;
101 // views::WidgetObserver overrides:
102 virtual void OnWidgetDestroying(views::Widget
* widget
) OVERRIDE
;
104 // ShellObserver overrides:
105 virtual void OnShelfAlignmentChanged(aura::RootWindow
* root_window
) OVERRIDE
;
107 // LauncherIconObserver overrides:
108 virtual void OnLauncherIconPositionsChanged() OVERRIDE
;
110 // app_list::PaginationModelObserver overrides:
111 virtual void TotalPagesChanged() OVERRIDE
;
112 virtual void SelectedPageChanged(int old_selected
, int new_selected
) OVERRIDE
;
113 virtual void TransitionStarted() OVERRIDE
;
114 virtual void TransitionChanged() OVERRIDE
;
116 scoped_ptr
<app_list::PaginationModel
> pagination_model_
;
118 // Whether we should show or hide app list widget.
121 // The AppListView this class manages, owned by its widget.
122 app_list::AppListView
* view_
;
124 // Cached bounds of |view_| for snapping back animation after over-scroll.
125 gfx::Rect view_bounds_
;
127 // Whether should schedule snap back animation.
128 bool should_snap_back_
;
130 DISALLOW_COPY_AND_ASSIGN(AppListController
);
133 } // namespace internal
136 #endif // ASH_WM_APP_LIST_CONTROLLER_H_