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_OVERVIEW_WINDOW_SELECTOR_H_
6 #define ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_
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/aura/window_tracker.h"
18 #include "ui/events/event_handler.h"
19 #include "ui/gfx/display_observer.h"
20 #include "ui/views/controls/textfield/textfield_controller.h"
21 #include "ui/wm/public/activation_change_observer.h"
42 class WindowSelectorDelegate
;
43 class WindowSelectorItem
;
44 class WindowSelectorTest
;
47 // The WindowSelector shows a grid of all of your windows, allowing to select
48 // one by clicking or tapping on it.
49 class ASH_EXPORT WindowSelector
50 : public gfx::DisplayObserver
,
51 public aura::WindowObserver
,
52 public aura::client::ActivationChangeObserver
,
53 public views::TextfieldController
{
55 // The distance between the top edge of the screen and the bottom edge of
56 // the text filtering textfield.
57 static const int kTextFilterBottomEdge
;
59 // Returns true if the window can be selected in overview mode.
60 static bool IsSelectable(aura::Window
* window
);
69 typedef std::vector
<aura::Window
*> WindowList
;
70 typedef ScopedVector
<WindowSelectorItem
> WindowSelectorItemList
;
72 explicit WindowSelector(WindowSelectorDelegate
* delegate
);
73 ~WindowSelector() override
;
75 // Initialize with the windows that can be selected.
76 void Init(const WindowList
& windows
);
78 // Perform cleanup that cannot be done in the destructor.
81 // Cancels window selection.
82 void CancelSelection();
84 // Called when the last window selector item from a grid is deleted.
85 void OnGridEmpty(WindowGrid
* grid
);
87 // Activates |window|.
88 void SelectWindow(aura::Window
* window
);
90 bool restoring_minimized_windows() const {
91 return restoring_minimized_windows_
;
94 // gfx::DisplayObserver:
95 void OnDisplayAdded(const gfx::Display
& display
) override
;
96 void OnDisplayRemoved(const gfx::Display
& display
) override
;
97 void OnDisplayMetricsChanged(const gfx::Display
& display
,
98 uint32_t metrics
) override
;
100 // aura::WindowObserver:
101 void OnWindowAdded(aura::Window
* new_window
) override
;
102 void OnWindowDestroying(aura::Window
* window
) override
;
104 // aura::client::ActivationChangeObserver:
105 void OnWindowActivated(
106 aura::client::ActivationChangeObserver::ActivationReason reason
,
107 aura::Window
* gained_active
,
108 aura::Window
* lost_active
) override
;
109 void OnAttemptToReactivateWindow(aura::Window
* request_active
,
110 aura::Window
* actual_active
) override
;
112 // views::TextfieldController:
113 void ContentsChanged(views::Textfield
* sender
,
114 const base::string16
& new_contents
) override
;
115 bool HandleKeyEvent(views::Textfield
* sender
,
116 const ui::KeyEvent
& key_event
) override
;
119 friend class WindowSelectorTest
;
121 // Begins positioning windows such that all windows are visible on the screen.
122 void StartOverview();
124 // Position all of the windows in the overview.
125 void PositionWindows(bool animate
);
127 // Repositions and resizes |text_filter_widget_| on
128 // DisplayMetricsChanged event.
129 void RepositionTextFilterOnDisplayMetricsChange();
131 // |focus|, restores focus to the stored window.
132 void ResetFocusRestoreWindow(bool focus
);
134 // Helper function that moves the selection widget to |direction| on the
135 // corresponding window grid.
136 void Move(Direction direction
, bool animate
);
138 // Removes all observers that were registered during construction and/or
140 void RemoveAllObservers();
142 // Tracks observed windows.
143 std::set
<aura::Window
*> observed_windows_
;
145 // Weak pointer to the selector delegate which will be called when a
146 // selection is made.
147 WindowSelectorDelegate
* delegate_
;
149 // A weak pointer to the window which was focused on beginning window
150 // selection. If window selection is canceled the focus should be restored to
152 aura::Window
* restore_focus_window_
;
154 // True when performing operations that may cause window activations. This is
155 // used to prevent handling the resulting expected activation.
156 bool ignore_activations_
;
158 // List of all the window overview grids, one for each root window.
159 ScopedVector
<WindowGrid
> grid_list_
;
161 // Tracks the index of the root window the selection widget is in.
162 size_t selected_grid_index_
;
164 // The following variables are used for metric collection purposes. All of
165 // them refer to this particular overview session and are not cumulative:
166 // The time when overview was started.
167 base::Time overview_start_time_
;
169 // The number of arrow key presses.
170 size_t num_key_presses_
;
172 // The number of items in the overview.
175 // Indicates if we are showing the selection widget.
176 bool showing_selection_widget_
;
178 // Window text filter widget. As the user writes on it, we filter the items
179 // in the overview. It is also responsible for handling overview key events,
180 // such as enter key to select.
181 scoped_ptr
<views::Widget
> text_filter_widget_
;
183 // The current length of the string entered into the text filtering textfield.
184 size_t text_filter_string_length_
;
186 // The number of times the text filtering textfield has been cleared of text
187 // during this overview mode session.
188 size_t num_times_textfield_cleared_
;
190 // Tracks whether minimized windows are currently being restored for overview
192 bool restoring_minimized_windows_
;
194 DISALLOW_COPY_AND_ASSIGN(WindowSelector
);
199 #endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_