| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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_COMMON_WM_WINDOW_CYCLE_LIST_H_ | |
| 6 #define ASH_COMMON_WM_WINDOW_CYCLE_LIST_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "ash/ash_export.h" | |
| 12 #include "ash/common/wm/window_cycle_controller.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/scoped_observer.h" | |
| 15 #include "base/timer/timer.h" | |
| 16 #include "ui/aura/window_observer.h" | |
| 17 #include "ui/display/display_observer.h" | |
| 18 | |
| 19 namespace display { | |
| 20 class Screen; | |
| 21 } | |
| 22 | |
| 23 namespace views { | |
| 24 class Widget; | |
| 25 } | |
| 26 | |
| 27 namespace ash { | |
| 28 | |
| 29 class WindowCycleView; | |
| 30 | |
| 31 // Tracks a set of Windows that can be stepped through. This class is used by | |
| 32 // the WindowCycleController. | |
| 33 class ASH_EXPORT WindowCycleList : public aura::WindowObserver, | |
| 34 public display::DisplayObserver { | |
| 35 public: | |
| 36 using WindowList = std::vector<WmWindow*>; | |
| 37 | |
| 38 explicit WindowCycleList(const WindowList& windows); | |
| 39 ~WindowCycleList() override; | |
| 40 | |
| 41 bool empty() const { return windows_.empty(); } | |
| 42 | |
| 43 // Cycles to the next or previous window based on |direction|. | |
| 44 void Step(WindowCycleController::Direction direction); | |
| 45 | |
| 46 int current_index() const { return current_index_; } | |
| 47 | |
| 48 void set_user_did_accept(bool user_did_accept) { | |
| 49 user_did_accept_ = user_did_accept; | |
| 50 } | |
| 51 | |
| 52 private: | |
| 53 friend class WindowCycleControllerTest; | |
| 54 | |
| 55 static void DisableInitialDelayForTesting(); | |
| 56 const views::Widget* widget() const { return cycle_ui_widget_; } | |
| 57 | |
| 58 const WindowList& windows() const { return windows_; } | |
| 59 | |
| 60 // aura::WindowObserver overrides: | |
| 61 // There is a chance a window is destroyed, for example by JS code. We need to | |
| 62 // take care of that even if it is not intended for the user to close a window | |
| 63 // while window cycling. | |
| 64 void OnWindowDestroying(aura::Window* window) override; | |
| 65 | |
| 66 // display::DisplayObserver overrides: | |
| 67 void OnDisplayAdded(const display::Display& new_display) override; | |
| 68 void OnDisplayRemoved(const display::Display& old_display) override; | |
| 69 void OnDisplayMetricsChanged(const display::Display& display, | |
| 70 uint32_t changed_metrics) override; | |
| 71 | |
| 72 // Returns true if the window list overlay should be shown. | |
| 73 bool ShouldShowUi(); | |
| 74 | |
| 75 // Initializes and shows |cycle_view_|. | |
| 76 void InitWindowCycleView(); | |
| 77 | |
| 78 // List of weak pointers to windows to use while cycling with the keyboard. | |
| 79 // List is built when the user initiates the gesture (i.e. hits alt-tab the | |
| 80 // first time) and is emptied when the gesture is complete (i.e. releases the | |
| 81 // alt key). | |
| 82 WindowList windows_; | |
| 83 | |
| 84 // Current position in the |windows_|. Can be used to query selection depth, | |
| 85 // i.e., the position of an active window in a global MRU ordering. | |
| 86 int current_index_ = 0; | |
| 87 | |
| 88 // True if the user accepted the window switch (as opposed to cancelling or | |
| 89 // interrupting the interaction). | |
| 90 bool user_did_accept_ = false; | |
| 91 | |
| 92 // The top level View for the window cycle UI. May be null if the UI is not | |
| 93 // showing. | |
| 94 WindowCycleView* cycle_view_ = nullptr; | |
| 95 | |
| 96 // The widget that hosts the window cycle UI. | |
| 97 views::Widget* cycle_ui_widget_ = nullptr; | |
| 98 | |
| 99 // The window list will dismiss if the display metrics change. | |
| 100 ScopedObserver<display::Screen, display::DisplayObserver> screen_observer_; | |
| 101 | |
| 102 // A timer to delay showing the UI. Quick Alt+Tab should not flash a UI. | |
| 103 base::OneShotTimer show_ui_timer_; | |
| 104 | |
| 105 DISALLOW_COPY_AND_ASSIGN(WindowCycleList); | |
| 106 }; | |
| 107 | |
| 108 } // namespace ash | |
| 109 | |
| 110 #endif // ASH_COMMON_WM_WINDOW_CYCLE_LIST_H_ | |
| OLD | NEW |