Index: ui/views/corewm/transient_window_manager.h |
diff --git a/ui/views/corewm/transient_window_manager.h b/ui/views/corewm/transient_window_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5624e40c44d1ca5bb164a9dd08f430082c1f0125 |
--- /dev/null |
+++ b/ui/views/corewm/transient_window_manager.h |
@@ -0,0 +1,110 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef UI_VIEWS_COREWM_TRANSIENT_WINDOW_MANAGER_H_ |
+#define UI_VIEWS_COREWM_TRANSIENT_WINDOW_MANAGER_H_ |
+ |
+#include <vector> |
+ |
+#include "ui/aura/window_observer.h" |
+#include "ui/views/views_export.h" |
+ |
+namespace views { |
+namespace corewm { |
+ |
+// Convenience functions that get the TransientWindowManager for the window and |
+// redirect appropriately. These are preferable to calling functions on |
+// TransientWindowManager as they handle the appropriate NULL checks. |
+VIEWS_EXPORT aura::Window* GetTransientParent(aura::Window* window); |
Ben Goodger (Google)
2013/12/18 00:32:38
maybe move these functions to window_util.cc/h in
sky
2014/01/06 18:42:48
Done.
|
+VIEWS_EXPORT const aura::Window* GetTransientParent(const aura::Window* window); |
+VIEWS_EXPORT const std::vector<aura::Window*>& GetTransientChildren( |
+ const aura::Window* window); |
+VIEWS_EXPORT void AddTransientChild(aura::Window* parent, aura::Window* child); |
+VIEWS_EXPORT void RemoveTransientChild(aura::Window* parent, |
+ aura::Window* child); |
+ |
+// Returns true if |window| has |ancestor| as a transient ancestor. A transient |
+// ancestor is found by following the transient parent chain of the window. |
+VIEWS_EXPORT bool HasTransientAncestor(const aura::Window* window, |
+ const aura::Window* ancestor); |
+ |
+// TransientWindowManager manages the set of transient children for a window |
+// along with the transient parent. Transient children get the following |
+// behavior: |
+// . The transient parent destroys any transient children when it is |
+// destroyed. This means a transient child is destroyed if either its parent |
+// or transient parent is destroyed. |
+// . If a transient child and its transient parent share the same parent, then |
+// transient children are always ordered above the transient parent. |
+// Transient windows are typically used for popups and menus. |
+class VIEWS_EXPORT TransientWindowManager : public aura::WindowObserver { |
Ben Goodger (Google)
2013/12/18 00:32:38
soft preference for this to be TransientWindowCont
sky
2014/01/06 18:42:48
I ended up needing aura/client/transient_window_cl
|
+ public: |
+ typedef std::vector<aura::Window*> Windows; |
+ |
+ virtual ~TransientWindowManager(); |
+ |
+ // Returns the TransientWindowManager for |window|. This never returns NULL. |
+ static TransientWindowManager* Get(aura::Window* window); |
+ |
+ // Returns the TransientWindowManager for |window| only if it already exists. |
+ // WARNING: this may return NULL. |
+ static const TransientWindowManager* Get(const aura::Window* window); |
+ |
+ // Adds or removes a transient child. |
+ void AddTransientChild(aura::Window* child); |
+ void RemoveTransientChild(aura::Window* child); |
+ |
+ const Windows& transient_children() const { return transient_children_; } |
+ |
+ aura::Window* transient_parent() { return transient_parent_; } |
+ const aura::Window* transient_parent() const { return transient_parent_; } |
+ |
+ // Returns true if in the process of stacking |child| on top of |target|. That |
+ // is, when the stacking order of a window changes (OnWindowStackingChanged()) |
+ // the transients may get restacked as well. This function can be used to |
+ // detect if TransientWindowManager is in the process of stacking a transient |
+ // as the result of window stacking changing. |
+ bool IsStackingTransient(const aura::Window* child, |
+ const aura::Window* target) const; |
+ |
+ // WindowObserver: |
Ben Goodger (Google)
2013/12/18 00:32:38
private
|
+ virtual void OnWindowVisibilityChanging(aura::Window* window, |
+ bool visible) OVERRIDE; |
+ virtual void OnWindowStackingChanged(aura::Window* window) OVERRIDE; |
+ virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
+ |
+ private: |
+ // Used to identify when a stacking change needs to restack transients. |
+ struct StackingPair { |
+ StackingPair(const aura::Window* child, const aura::Window* target) |
+ : child(child), |
+ target(target) {} |
+ |
+ // The window being moved. |
+ const aura::Window* child; |
+ |
+ // |child| is being stacked on top of this. |
+ const aura::Window* target; |
+ }; |
+ |
+ explicit TransientWindowManager(aura::Window* window); |
+ |
+ // Invoked whne |child|'s stacking order changes. |
+ void OnChildStackingChanged(aura::Window* child); |
+ |
+ aura::Window* window_; |
+ aura::Window* transient_parent_; |
+ Windows transient_children_; |
+ |
+ // If non-null we're actively restacking transient as the result of a |
+ // transient ancestor changing. This is a pointer to a value on the stack. |
+ StackingPair* stacking_pair_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TransientWindowManager); |
+}; |
+ |
+} // namespace corewm |
+} // namespace views |
+ |
+#endif // UI_VIEWS_COREWM_TRANSIENT_WINDOW_MANAGER_H_ |