Revert of Add Masonry to key_silk_cases. (patchset #3 id:40001 of https://codereview...
[chromium-blink-merge.git] / ui / wm / core / transient_window_manager.h
blob6a17d9fdc8da05842959fa3c590038c7c1398ba0
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 // . If a transient parent is hidden, it hides all transient children.
27 // For show operation, please refer to |set_parent_controls_visibility(bool)|.
28 // Transient windows are typically used for popups and menus.
29 // TODO(sky): when we nuke TransientWindowClient rename this to
30 // TransientWindowController.
31 class WM_EXPORT TransientWindowManager : public aura::WindowObserver {
32 public:
33 typedef std::vector<aura::Window*> Windows;
35 ~TransientWindowManager() override;
37 // Returns the TransientWindowManager for |window|. This never returns NULL.
38 static TransientWindowManager* Get(aura::Window* window);
40 // Returns the TransientWindowManager for |window| only if it already exists.
41 // WARNING: this may return NULL.
42 static const TransientWindowManager* Get(const aura::Window* window);
44 void AddObserver(TransientWindowObserver* observer);
45 void RemoveObserver(TransientWindowObserver* observer);
47 // Adds or removes a transient child.
48 void AddTransientChild(aura::Window* child);
49 void RemoveTransientChild(aura::Window* child);
51 // Setting true lets the transient parent show this transient
52 // child when the parent is shown. If this was shown when the
53 // transient parent is hidden, it remains hidden and gets shown
54 // when the transient parent is shown. This is false by default.
55 void set_parent_controls_visibility(bool parent_controls_visibility) {
56 parent_controls_visibility_ = parent_controls_visibility;
59 const Windows& transient_children() const { return transient_children_; }
61 aura::Window* transient_parent() { return transient_parent_; }
62 const aura::Window* transient_parent() const { return transient_parent_; }
64 // Returns true if in the process of stacking |window_| on top of |target|.
65 // That is, when the stacking order of a window changes
66 // (OnWindowStackingChanged()) the transients may get restacked as well. This
67 // function can be used to detect if TransientWindowManager is in the process
68 // of stacking a transient as the result of window stacking changing.
69 bool IsStackingTransient(const aura::Window* target) const;
71 private:
72 explicit TransientWindowManager(aura::Window* window);
74 // Stacks transient descendants of this window that are its siblings just
75 // above it.
76 void RestackTransientDescendants();
78 // Update the window's visibility following the transient parent's
79 // visibility. See |set_parent_controls_visibility(bool)| for more details.
80 void UpdateTransientChildVisibility(bool visible);
82 // WindowObserver:
83 void OnWindowParentChanged(aura::Window* window,
84 aura::Window* parent) override;
85 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
86 void OnWindowStackingChanged(aura::Window* window) override;
87 void OnWindowDestroying(aura::Window* window) override;
89 aura::Window* window_;
90 aura::Window* transient_parent_;
91 Windows transient_children_;
93 // If non-null we're actively restacking transient as the result of a
94 // transient ancestor changing.
95 aura::Window* stacking_target_;
97 bool parent_controls_visibility_;
98 bool show_on_parent_visible_;
99 bool ignore_visibility_changed_event_;
101 ObserverList<TransientWindowObserver> observers_;
103 DISALLOW_COPY_AND_ASSIGN(TransientWindowManager);
106 } // namespace wm
108 #endif // UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_