| 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 UI_VIEWS_COREWM_TRANSIENT_WINDOW_MANAGER_H_ | |
| 6 #define UI_VIEWS_COREWM_TRANSIENT_WINDOW_MANAGER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/observer_list.h" | |
| 11 #include "ui/aura/window_observer.h" | |
| 12 #include "ui/views/views_export.h" | |
| 13 | |
| 14 namespace views { | |
| 15 namespace corewm { | |
| 16 | |
| 17 class TransientWindowObserver; | |
| 18 | |
| 19 // TransientWindowManager manages the set of transient children for a window | |
| 20 // along with the transient parent. Transient children get the following | |
| 21 // behavior: | |
| 22 // . The transient parent destroys any transient children when it is | |
| 23 // destroyed. This means a transient child is destroyed if either its parent | |
| 24 // or transient parent is destroyed. | |
| 25 // . If a transient child and its transient parent share the same parent, then | |
| 26 // transient children are always ordered above the transient parent. | |
| 27 // Transient windows are typically used for popups and menus. | |
| 28 // TODO(sky): when we nuke TransientWindowClient rename this to | |
| 29 // TransientWindowController. | |
| 30 class VIEWS_EXPORT TransientWindowManager : public aura::WindowObserver { | |
| 31 public: | |
| 32 typedef std::vector<aura::Window*> Windows; | |
| 33 | |
| 34 virtual ~TransientWindowManager(); | |
| 35 | |
| 36 // Returns the TransientWindowManager for |window|. This never returns NULL. | |
| 37 static TransientWindowManager* Get(aura::Window* window); | |
| 38 | |
| 39 // Returns the TransientWindowManager for |window| only if it already exists. | |
| 40 // WARNING: this may return NULL. | |
| 41 static const TransientWindowManager* Get(const aura::Window* window); | |
| 42 | |
| 43 void AddObserver(TransientWindowObserver* observer); | |
| 44 void RemoveObserver(TransientWindowObserver* observer); | |
| 45 | |
| 46 // Adds or removes a transient child. | |
| 47 void AddTransientChild(aura::Window* child); | |
| 48 void RemoveTransientChild(aura::Window* child); | |
| 49 | |
| 50 const Windows& transient_children() const { return transient_children_; } | |
| 51 | |
| 52 aura::Window* transient_parent() { return transient_parent_; } | |
| 53 const aura::Window* transient_parent() const { return transient_parent_; } | |
| 54 | |
| 55 // Returns true if in the process of stacking |child| on top of |target|. That | |
| 56 // is, when the stacking order of a window changes (OnWindowStackingChanged()) | |
| 57 // the transients may get restacked as well. This function can be used to | |
| 58 // detect if TransientWindowManager is in the process of stacking a transient | |
| 59 // as the result of window stacking changing. | |
| 60 bool IsStackingTransient(const aura::Window* child, | |
| 61 const aura::Window* target) const; | |
| 62 | |
| 63 private: | |
| 64 // Used to identify when a stacking change needs to restack transients. | |
| 65 struct StackingPair { | |
| 66 StackingPair(const aura::Window* child, const aura::Window* target) | |
| 67 : child(child), | |
| 68 target(target) {} | |
| 69 | |
| 70 // The window being moved. | |
| 71 const aura::Window* child; | |
| 72 | |
| 73 // |child| is being stacked on top of this. | |
| 74 const aura::Window* target; | |
| 75 }; | |
| 76 | |
| 77 explicit TransientWindowManager(aura::Window* window); | |
| 78 | |
| 79 // Invoked whne |child|'s stacking order changes. | |
| 80 void OnChildStackingChanged(aura::Window* child); | |
| 81 | |
| 82 // WindowObserver: | |
| 83 virtual void OnWindowVisibilityChanging(aura::Window* window, | |
| 84 bool visible) OVERRIDE; | |
| 85 virtual void OnWindowStackingChanged(aura::Window* window) OVERRIDE; | |
| 86 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; | |
| 87 | |
| 88 aura::Window* window_; | |
| 89 aura::Window* transient_parent_; | |
| 90 Windows transient_children_; | |
| 91 | |
| 92 // If non-null we're actively restacking transient as the result of a | |
| 93 // transient ancestor changing. This is a pointer to a value on the stack. | |
| 94 StackingPair* stacking_pair_; | |
| 95 | |
| 96 ObserverList<TransientWindowObserver> observers_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(TransientWindowManager); | |
| 99 }; | |
| 100 | |
| 101 } // namespace corewm | |
| 102 } // namespace views | |
| 103 | |
| 104 #endif // UI_VIEWS_COREWM_TRANSIENT_WINDOW_MANAGER_H_ | |
| OLD | NEW |