File: transient_window_manager.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (125 lines) | stat: -rw-r--r-- 5,239 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_
#define UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_

#include <vector>

#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "ui/aura/window_observer.h"

namespace wm {

class TransientWindowObserver;

// 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.
// . If a transient parent is hidden, it hides all transient children.
//   For show operation, please refer to |set_parent_controls_visibility(bool)|.
// Transient windows are typically used for popups and menus.
class COMPONENT_EXPORT(UI_WM) TransientWindowManager
    : public aura::WindowObserver {
 public:
  using Windows = std::vector<raw_ptr<aura::Window, VectorExperimental>>;

  TransientWindowManager(const TransientWindowManager&) = delete;
  TransientWindowManager& operator=(const TransientWindowManager&) = delete;

  ~TransientWindowManager() override;

  // Returns the TransientWindowManager for |window|, creating if necessary.
  // This never returns nullptr.
  static TransientWindowManager* GetOrCreate(aura::Window* window);

  // Returns the TransientWindowManager for |window| only if it already exists.
  // WARNING: this may return nullptr.
  static const TransientWindowManager* GetIfExists(const aura::Window* window);

  void AddObserver(TransientWindowObserver* observer);
  void RemoveObserver(TransientWindowObserver* observer);

  // Adds or removes a transient child.
  void AddTransientChild(aura::Window* child);
  void RemoveTransientChild(aura::Window* child);

  // Setting true lets the transient parent show this transient
  // child when the parent is shown. If this was shown when the
  // transient parent is hidden, it remains hidden and gets shown
  // when the transient parent is shown. This is false by default.
  void set_parent_controls_visibility(bool parent_controls_visibility) {
    parent_controls_visibility_ = parent_controls_visibility;
  }

  // Sets whether the transient parent should control the lifetime of the
  // transient child or not. `parent_controls_lifetime_` is default set to true
  // and needs to be set to false when the lifetime of the transient child is
  // not managed by its transient parent.
  void set_parent_controls_lifetime(bool parent_controls_lifetime) {
    parent_controls_lifetime_ = parent_controls_lifetime;
  }

  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 |window_| 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* target) const;

 private:
  explicit TransientWindowManager(aura::Window* window);

  // Stacks transient descendants of this window that are its siblings just
  // above it.
  void RestackTransientDescendants();

  // Update the window's visibility following the transient parent's
  // visibility. See |set_parent_controls_visibility(bool)| for more details.
  void UpdateTransientChildVisibility(bool visible);

  // WindowObserver:
  void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
  void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
  void OnWindowStackingChanged(aura::Window* window) override;
  void OnWindowDestroying(aura::Window* window) override;

  raw_ptr<aura::Window> window_;
  raw_ptr<aura::Window> transient_parent_;
  Windows transient_children_;

  // If non-null we're actively restacking transient as the result of a
  // transient ancestor changing.
  raw_ptr<aura::Window> stacking_target_;

  bool parent_controls_visibility_;
  bool parent_controls_lifetime_;
  bool show_on_parent_visible_;
  bool ignore_visibility_changed_event_;

  // Set to true to pause updating the stacking order of transient descandant
  // windows while we reparent those transient children which used to be on the
  // the same old parent as that of |window| to its new parent.
  // This avoid recursively restacking multiple times when we have to reparent
  // multiple transient children.
  bool pause_transient_descendants_restacking_ = false;

  base::ObserverList<TransientWindowObserver>::Unchecked observers_;
};

}  // namespace wm

#endif  // UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_