platformKeys: Add per-extension sign permissions.
[chromium-blink-merge.git] / ash / wm / overview / window_selector.h
blobc8e25a3a1233ed18add49504b292b0cabccae8de
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_
8 #include <set>
9 #include <vector>
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"
23 namespace aura {
24 class RootWindow;
25 class Window;
28 namespace gfx {
29 class Rect;
32 namespace ui {
33 class LocatedEvent;
36 namespace views {
37 class Textfield;
38 class Widget;
41 namespace ash {
42 class WindowSelectorDelegate;
43 class WindowSelectorItem;
44 class WindowSelectorTest;
45 class WindowGrid;
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 {
54 public:
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 enum Direction {
60 LEFT,
61 UP,
62 RIGHT,
63 DOWN
66 typedef std::vector<aura::Window*> WindowList;
67 typedef ScopedVector<WindowSelectorItem> WindowSelectorItemList;
69 explicit WindowSelector(WindowSelectorDelegate* delegate);
70 ~WindowSelector() override;
72 // Initialize with the windows that can be selected.
73 void Init(const WindowList& windows);
75 // Perform cleanup that cannot be done in the destructor.
76 void Shutdown();
78 // Cancels window selection.
79 void CancelSelection();
81 // Called when the last window selector item from a grid is deleted.
82 void OnGridEmpty(WindowGrid* grid);
84 bool restoring_minimized_windows() const {
85 return restoring_minimized_windows_;
88 // gfx::DisplayObserver:
89 void OnDisplayAdded(const gfx::Display& display) override;
90 void OnDisplayRemoved(const gfx::Display& display) override;
91 void OnDisplayMetricsChanged(const gfx::Display& display,
92 uint32_t metrics) override;
94 // aura::WindowObserver:
95 void OnWindowAdded(aura::Window* new_window) override;
96 void OnWindowDestroying(aura::Window* window) override;
98 // aura::client::ActivationChangeObserver:
99 void OnWindowActivated(aura::Window* gained_active,
100 aura::Window* lost_active) override;
101 void OnAttemptToReactivateWindow(aura::Window* request_active,
102 aura::Window* actual_active) override;
104 // views::TextfieldController:
105 void ContentsChanged(views::Textfield* sender,
106 const base::string16& new_contents) override;
107 bool HandleKeyEvent(views::Textfield* sender,
108 const ui::KeyEvent& key_event) override;
110 private:
111 friend class WindowSelectorTest;
113 // Begins positioning windows such that all windows are visible on the screen.
114 void StartOverview();
116 // Position all of the windows in the overview.
117 void PositionWindows(bool animate);
119 // Hide and track all hidden windows not in the overview item list.
120 void HideAndTrackNonOverviewWindows();
122 // |focus|, restores focus to the stored window.
123 void ResetFocusRestoreWindow(bool focus);
125 // Helper function that moves the selection widget to |direction| on the
126 // corresponding window grid.
127 void Move(Direction direction, bool animate);
129 // Removes all observers that were registered during construction and/or
130 // initialization.
131 void RemoveAllObservers();
133 // Tracks observed windows.
134 std::set<aura::Window*> observed_windows_;
136 // Weak pointer to the selector delegate which will be called when a
137 // selection is made.
138 WindowSelectorDelegate* delegate_;
140 // A weak pointer to the window which was focused on beginning window
141 // selection. If window selection is canceled the focus should be restored to
142 // this window.
143 aura::Window* restore_focus_window_;
145 // True when performing operations that may cause window activations. This is
146 // used to prevent handling the resulting expected activation.
147 bool ignore_activations_;
149 // List of all the window overview grids, one for each root window.
150 ScopedVector<WindowGrid> grid_list_;
152 // Tracks windows which were hidden because they were not part of the
153 // overview.
154 aura::WindowTracker hidden_windows_;
156 // Tracks the index of the root window the selection widget is in.
157 size_t selected_grid_index_;
159 // The following variables are used for metric collection purposes. All of
160 // them refer to this particular overview session and are not cumulative:
161 // The time when overview was started.
162 base::Time overview_start_time_;
164 // The number of arrow key presses.
165 size_t num_key_presses_;
167 // The number of items in the overview.
168 size_t num_items_;
170 // Indicates if we are showing the selection widget.
171 bool showing_selection_widget_;
173 // Window text filter widget. As the user writes on it, we filter the items
174 // in the overview. It is also responsible for handling overview key events,
175 // such as enter key to select.
176 scoped_ptr<views::Widget> text_filter_widget_;
178 // The current length of the string entered into the text filtering textfield.
179 size_t text_filter_string_length_;
181 // The number of times the text filtering textfield has been cleared of text
182 // during this overview mode session.
183 size_t num_times_textfield_cleared_;
185 // Tracks whether minimized windows are currently being restored for overview
186 // mode.
187 bool restoring_minimized_windows_;
189 DISALLOW_COPY_AND_ASSIGN(WindowSelector);
192 } // namespace ash
194 #endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_