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