1 // Copyright 2013 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_WINDOW_SELECTOR_H_
6 #define ASH_WM_WINDOW_SELECTOR_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "ui/aura/window_observer.h"
14 #include "ui/base/events/event_handler.h"
15 #include "ui/gfx/transform.h"
31 class WindowSelectorDelegate
;
32 class WindowSelectorWindow
;
34 // The WindowSelector shows a grid of all of your windows and allows selecting
35 // a window by clicking or tapping on it (OVERVIEW mode) or by alt-tabbing to
37 class WindowSelector
: public ui::EventHandler
,
38 public aura::WindowObserver
{
49 typedef std::vector
<aura::Window
*> WindowList
;
51 WindowSelector(const WindowList
& windows
,
53 WindowSelectorDelegate
* delegate
);
54 virtual ~WindowSelector();
56 // Step to the next window in |direction|.
57 void Step(Direction direction
);
59 // Select the current window.
62 Mode
mode() { return mode_
; }
65 virtual void OnEvent(ui::Event
* event
) OVERRIDE
;
66 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
;
67 virtual void OnGestureEvent(ui::GestureEvent
* event
) OVERRIDE
;
69 // aura::WindowObserver:
70 virtual void OnWindowDestroyed(aura::Window
* window
) OVERRIDE
;
73 // Returns the target of |event| or NULL if the event is not targeted at
74 // any of the windows in the selector.
75 WindowSelectorWindow
* GetEventTarget(ui::LocatedEvent
* event
);
77 // Handles a selection event for |target|.
78 void HandleSelectionEvent(WindowSelectorWindow
* target
);
80 // Position all of the windows based on the current selection mode.
81 void PositionWindows();
82 // Position all of the windows from |root_window| on |root_window|.
83 void PositionWindowsFromRoot(aura::RootWindow
* root_window
);
84 // Position all of the |windows| to fit on the |root_window|.
85 void PositionWindowsOnRoot(aura::RootWindow
* root_window
,
86 const std::vector
<WindowSelectorWindow
*>& windows
);
88 void InitializeSelectionWidget();
90 // Updates the selection widget's location to the currently selected window.
91 // If |animate| the transition to the new location is animated.
92 void UpdateSelectionLocation(bool animate
);
94 // The collection of windows in the overview wrapped by a helper class which
95 // restores their state and helps transform them to other root windows.
96 ScopedVector
<WindowSelectorWindow
> windows_
;
98 // The window selection mode.
101 // Weak pointer to the selector delegate which will be called when a
102 // selection is made.
103 WindowSelectorDelegate
* delegate_
;
105 // Index of the currently selected window if the mode is CYCLE.
106 size_t selected_window_
;
108 // Widget indicating which window is currently selected.
109 scoped_ptr
<views::Widget
> selection_widget_
;
111 // In CYCLE mode, the root window in which selection is taking place.
113 aura::RootWindow
* selection_root_
;
115 DISALLOW_COPY_AND_ASSIGN(WindowSelector
);
120 #endif // ASH_WM_WINDOW_SELECTOR_H_