Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / ash / wm / overview / window_selector.h
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.
4
5 #ifndef ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_
6 #define ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_
7
8 #include <set>
9 #include <vector>
10
11 #include "ash/ash_export.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/time/time.h"
16 #include "ui/aura/window_observer.h"
17 #include "ui/wm/public/activation_change_observer.h"
18
19 namespace aura {
20 class RootWindow;
21 }
22
23 namespace ui {
24 class EventHandler;
25 }
26
27 namespace ash {
28
29 namespace internal {
30 class WindowSelectorTest;
31 }
32
33 class ScopedShowWindow;
34 class WindowOverview;
35 class WindowSelectorDelegate;
36 class WindowSelectorItem;
37
38 // The WindowSelector allows selecting a window by alt-tabbing (CYCLE mode) or
39 // by clicking or tapping on it (OVERVIEW mode). A WindowOverview will be shown
40 // in OVERVIEW mode or if the user lingers on a window while alt tabbing.
41 class ASH_EXPORT WindowSelector
42     : public aura::WindowObserver,
43       public aura::client::ActivationChangeObserver {
44  public:
45   enum Direction {
46     FORWARD,
47     BACKWARD
48   };
49   enum Mode {
50     CYCLE,
51     OVERVIEW
52   };
53
54   typedef std::vector<aura::Window*> WindowList;
55
56   WindowSelector(const WindowList& windows,
57                  Mode mode,
58                  WindowSelectorDelegate* delegate);
59   virtual ~WindowSelector();
60
61   // Step to the next window in |direction|.
62   void Step(Direction direction);
63
64   // Choose the currently selected window.
65   void SelectWindow();
66
67   // Choose |window| from the available windows to select.
68   void SelectWindow(aura::Window* window);
69
70   // Cancels window selection.
71   void CancelSelection();
72
73   Mode mode() { return mode_; }
74
75   // aura::WindowObserver:
76   virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE;
77   virtual void OnWindowBoundsChanged(aura::Window* window,
78                                      const gfx::Rect& old_bounds,
79                                      const gfx::Rect& new_bounds) OVERRIDE;
80   virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
81
82   // Overridden from aura::client::ActivationChangeObserver:
83   virtual void OnWindowActivated(aura::Window* gained_active,
84                                  aura::Window* lost_active) OVERRIDE;
85   virtual void OnAttemptToReactivateWindow(
86       aura::Window* request_active,
87       aura::Window* actual_active) OVERRIDE;
88
89  private:
90   friend class internal::WindowSelectorTest;
91
92   // Begins positioning windows such that all windows are visible on the screen.
93   void StartOverview();
94
95   // Resets the stored window from RemoveFocusAndSetRestoreWindow to NULL. If
96   // |focus|, restores focus to the stored window.
97   void ResetFocusRestoreWindow(bool focus);
98
99   // The collection of items in the overview wrapped by a helper class which
100   // restores their state and helps transform them to other root windows.
101   ScopedVector<WindowSelectorItem> windows_;
102
103   // Tracks observed windows.
104   std::set<aura::Window*> observed_windows_;
105
106   // The window selection mode.
107   Mode mode_;
108
109   // An event handler listening for the release of the alt key during alt-tab
110   // cycling.
111   scoped_ptr<ui::EventHandler> event_handler_;
112
113   // The currently selected window being shown (temporarily brought to the front
114   // of the stacking order and made visible).
115   scoped_ptr<ScopedShowWindow> showing_window_;
116
117   scoped_ptr<WindowOverview> window_overview_;
118
119   // The time when window cycling was started.
120   base::Time cycle_start_time_;
121
122   // Weak pointer to the selector delegate which will be called when a
123   // selection is made.
124   WindowSelectorDelegate* delegate_;
125
126   // Index of the currently selected window if the mode is CYCLE.
127   size_t selected_window_;
128
129   // A weak pointer to the window which was focused on beginning window
130   // selection. If window selection is canceled the focus should be restored to
131   // this window.
132   aura::Window* restore_focus_window_;
133
134   // True when performing operations that may cause window activations. This is
135   // used to prevent handling the resulting expected activation.
136   bool ignore_activations_;
137
138   DISALLOW_COPY_AND_ASSIGN(WindowSelector);
139 };
140
141 }  // namespace ash
142
143 #endif  // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_