| 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_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_ | |
| 6 #define UI_WM_CORE_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/wm/wm_export.h" | |
| 13 | |
| 14 namespace wm { | |
| 15 | |
| 16 class TransientWindowObserver; | |
| 17 | |
| 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; | |
| 34 | |
| 35 virtual ~TransientWindowManager(); | |
| 36 | |
| 37 // Returns the TransientWindowManager for |window|. This never returns NULL. | |
| 38 static TransientWindowManager* Get(aura::Window* window); | |
| 39 | |
| 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); | |
| 43 | |
| 44 void AddObserver(TransientWindowObserver* observer); | |
| 45 void RemoveObserver(TransientWindowObserver* observer); | |
| 46 | |
| 47 // Adds or removes a transient child. | |
| 48 void AddTransientChild(aura::Window* child); | |
| 49 void RemoveTransientChild(aura::Window* child); | |
| 50 | |
| 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; | |
| 57 } | |
| 58 | |
| 59 const Windows& transient_children() const { return transient_children_; } | |
| 60 | |
| 61 aura::Window* transient_parent() { return transient_parent_; } | |
| 62 const aura::Window* transient_parent() const { return transient_parent_; } | |
| 63 | |
| 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; | |
| 70 | |
| 71 private: | |
| 72 explicit TransientWindowManager(aura::Window* window); | |
| 73 | |
| 74 // Stacks transient descendants of this window that are its siblings just | |
| 75 // above it. | |
| 76 void RestackTransientDescendants(); | |
| 77 | |
| 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); | |
| 81 | |
| 82 // WindowObserver: | |
| 83 virtual void OnWindowParentChanged(aura::Window* window, | |
| 84 aura::Window* parent) override; | |
| 85 virtual void OnWindowVisibilityChanging(aura::Window* window, | |
| 86 bool visible) override; | |
| 87 virtual void OnWindowVisibilityChanged(aura::Window* window, | |
| 88 bool visible) override; | |
| 89 virtual void OnWindowStackingChanged(aura::Window* window) override; | |
| 90 virtual void OnWindowDestroying(aura::Window* window) override; | |
| 91 | |
| 92 aura::Window* window_; | |
| 93 aura::Window* transient_parent_; | |
| 94 Windows transient_children_; | |
| 95 | |
| 96 // If non-null we're actively restacking transient as the result of a | |
| 97 // transient ancestor changing. | |
| 98 aura::Window* stacking_target_; | |
| 99 | |
| 100 bool parent_controls_visibility_; | |
| 101 bool show_on_parent_visible_; | |
| 102 bool ignore_visibility_changed_event_; | |
| 103 | |
| 104 ObserverList<TransientWindowObserver> observers_; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(TransientWindowManager); | |
| 107 }; | |
| 108 | |
| 109 } // namespace wm | |
| 110 | |
| 111 #endif // UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_ | |
| OLD | NEW |