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_MRU_WINDOW_TRACKER_H_ 6 #define ASH_WM_MRU_WINDOW_TRACKER_H_ 7 8 #include <list> 9 #include <vector> 10 11 #include "ash/ash_export.h" 12 #include "base/basictypes.h" 13 #include "base/memory/scoped_ptr.h" 14 #include "ui/aura/client/activation_change_observer.h" 15 #include "ui/aura/window_observer.h" 16 17 namespace aura { 18 class RootWindow; 19 class Window; 20 namespace client { 21 class ActivationClient; 22 } 23 } 24 25 namespace ash { 26 27 // List of containers which contain windows that can be switched to. 28 ASH_EXPORT extern const int kSwitchableWindowContainerIds[]; 29 30 // The number of elements in kSwitchableWindowContainerIds. 31 ASH_EXPORT extern const size_t kSwitchableWindowContainerIdsLength; 32 33 // Maintains a most recently used list of windows. This is used for window 34 // cycling using Alt+Tab and overview mode. 35 class ASH_EXPORT MruWindowTracker 36 : public aura::client::ActivationChangeObserver, 37 public aura::WindowObserver { 38 public: 39 typedef std::vector<aura::Window*> WindowList; 40 41 explicit MruWindowTracker( 42 aura::client::ActivationClient* activation_client); 43 virtual ~MruWindowTracker(); 44 45 // Returns the set of windows which can be cycled through. This method creates 46 // the vector based on the current set of windows across all valid root 47 // windows. As a result it is not necessarily the same as the set of 48 // windows being iterated over. 49 // If |top_most_at_end| the window list will return in ascending (lowest 50 // window in stacking order first) order instead of the default descending 51 // (top most window first) order. 52 static WindowList BuildWindowList(bool top_most_at_end); 53 54 // Returns the set of windows which can be cycled through using the tracked 55 // list of most recently used windows. 56 WindowList BuildMruWindowList(); 57 58 // Starts or stops ignoring window activations. If no longer ignoring 59 // activations the currently active window is moved to the front of the 60 // MRU window list. Used by WindowCycleList to avoid adding all cycled 61 // windows to the front of the MRU window list. 62 void SetIgnoreActivations(bool ignore); 63 64 private: 65 // Updates the mru_windows_ list to insert/move |active_window| at/to the 66 // front. 67 void SetActiveWindow(aura::Window* active_window); 68 69 // Overridden from aura::client::ActivationChangeObserver: 70 virtual void OnWindowActivated(aura::Window* gained_active, 71 aura::Window* lost_active) OVERRIDE; 72 73 // Overridden from WindowObserver: 74 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; 75 76 // List of windows that have been activated in containers that we cycle 77 // through, sorted by most recently used. 78 std::list<aura::Window*> mru_windows_; 79 80 aura::client::ActivationClient* activation_client_; 81 82 bool ignore_window_activations_; 83 84 DISALLOW_COPY_AND_ASSIGN(MruWindowTracker); 85 }; 86 87 } // namespace ash 88 89 #endif // ASH_WM_MRU_WINDOW_TRACKER_H_ 90