Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / wm / core / transient_window_manager.h
blob7d37679f924d0cbf8b6b684b92eaa2430b3f518a
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.
5 #ifndef UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_
6 #define UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_
8 #include <vector>
10 #include "base/observer_list.h"
11 #include "ui/aura/window_observer.h"
12 #include "ui/wm/wm_export.h"
14 namespace wm {
16 class TransientWindowObserver;
18 // TransientWindowManager manages the set of transient children for a window
19 // along with the transient parent. Transient children get the following
20 // behavior:
21 // . The transient parent destroys any transient children when it is
22 // destroyed. This means a transient child is destroyed if either its parent
23 // or transient parent is destroyed.
24 // . If a transient child and its transient parent share the same parent, then
25 // transient children are always ordered above the transient parent.
26 // Transient windows are typically used for popups and menus.
27 // TODO(sky): when we nuke TransientWindowClient rename this to
28 // TransientWindowController.
29 class WM_EXPORT TransientWindowManager : public aura::WindowObserver {
30 public:
31 typedef std::vector<aura::Window*> Windows;
33 virtual ~TransientWindowManager();
35 // Returns the TransientWindowManager for |window|. This never returns NULL.
36 static TransientWindowManager* Get(aura::Window* window);
38 // Returns the TransientWindowManager for |window| only if it already exists.
39 // WARNING: this may return NULL.
40 static const TransientWindowManager* Get(const aura::Window* window);
42 void AddObserver(TransientWindowObserver* observer);
43 void RemoveObserver(TransientWindowObserver* observer);
45 // Adds or removes a transient child.
46 void AddTransientChild(aura::Window* child);
47 void RemoveTransientChild(aura::Window* child);
49 const Windows& transient_children() const { return transient_children_; }
51 aura::Window* transient_parent() { return transient_parent_; }
52 const aura::Window* transient_parent() const { return transient_parent_; }
54 // Returns true if in the process of stacking |window_| on top of |target|.
55 // That is, when the stacking order of a window changes
56 // (OnWindowStackingChanged()) the transients may get restacked as well. This
57 // function can be used to detect if TransientWindowManager is in the process
58 // of stacking a transient as the result of window stacking changing.
59 bool IsStackingTransient(const aura::Window* target) const;
61 private:
62 explicit TransientWindowManager(aura::Window* window);
64 // Stacks transient descendants of this window that are its siblings just
65 // above it.
66 void RestackTransientDescendants();
68 // WindowObserver:
69 virtual void OnWindowParentChanged(aura::Window* window,
70 aura::Window* parent) OVERRIDE;
71 virtual void OnWindowVisibilityChanging(aura::Window* window,
72 bool visible) OVERRIDE;
73 virtual void OnWindowStackingChanged(aura::Window* window) OVERRIDE;
74 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
76 aura::Window* window_;
77 aura::Window* transient_parent_;
78 Windows transient_children_;
80 // If non-null we're actively restacking transient as the result of a
81 // transient ancestor changing.
82 aura::Window* stacking_target_;
84 ObserverList<TransientWindowObserver> observers_;
86 DISALLOW_COPY_AND_ASSIGN(TransientWindowManager);
89 } // namespace wm
91 #endif // UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_