Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: ui/wm/core/transient_window_manager.cc

Issue 628413002: Show transient child when the transient parent is shown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/wm/core/transient_window_manager.h ('k') | ui/wm/core/transient_window_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/wm/core/transient_window_manager.h" 5 #include "ui/wm/core/transient_window_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 #include "ui/aura/window_property.h" 13 #include "ui/aura/window_property.h"
14 #include "ui/wm/core/transient_window_observer.h" 14 #include "ui/wm/core/transient_window_observer.h"
15 #include "ui/wm/core/transient_window_stacking_client.h" 15 #include "ui/wm/core/transient_window_stacking_client.h"
16 #include "ui/wm/core/window_util.h" 16 #include "ui/wm/core/window_util.h"
17 17
18 using aura::Window; 18 using aura::Window;
19 19
20 namespace wm { 20 namespace wm {
21 namespace {
21 22
22 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TransientWindowManager, kPropertyKey, NULL); 23 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TransientWindowManager, kPropertyKey, NULL);
23 24
25 } // namespace
26
24 TransientWindowManager::~TransientWindowManager() { 27 TransientWindowManager::~TransientWindowManager() {
25 } 28 }
26 29
27 // static 30 // static
28 TransientWindowManager* TransientWindowManager::Get(Window* window) { 31 TransientWindowManager* TransientWindowManager::Get(Window* window) {
29 TransientWindowManager* manager = window->GetProperty(kPropertyKey); 32 TransientWindowManager* manager = window->GetProperty(kPropertyKey);
30 if (!manager) { 33 if (!manager) {
31 manager = new TransientWindowManager(window); 34 manager = new TransientWindowManager(window);
32 window->SetProperty(kPropertyKey, manager); 35 window->SetProperty(kPropertyKey, manager);
33 } 36 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 93 }
91 94
92 bool TransientWindowManager::IsStackingTransient( 95 bool TransientWindowManager::IsStackingTransient(
93 const aura::Window* target) const { 96 const aura::Window* target) const {
94 return stacking_target_ == target; 97 return stacking_target_ == target;
95 } 98 }
96 99
97 TransientWindowManager::TransientWindowManager(Window* window) 100 TransientWindowManager::TransientWindowManager(Window* window)
98 : window_(window), 101 : window_(window),
99 transient_parent_(NULL), 102 transient_parent_(NULL),
100 stacking_target_(NULL) { 103 stacking_target_(NULL),
104 parent_controls_visibility_(false),
105 show_on_parent_visible_(false),
106 ignore_visibility_changed_event_(false) {
101 window_->AddObserver(this); 107 window_->AddObserver(this);
102 } 108 }
103 109
104 void TransientWindowManager::RestackTransientDescendants() { 110 void TransientWindowManager::RestackTransientDescendants() {
105 Window* parent = window_->parent(); 111 Window* parent = window_->parent();
106 if (!parent) 112 if (!parent)
107 return; 113 return;
108 114
109 // Stack any transient children that share the same parent to be in front of 115 // Stack any transient children that share the same parent to be in front of
110 // |window_|. The existing stacking order is preserved by iterating backwards 116 // |window_|. The existing stacking order is preserved by iterating backwards
(...skipping 16 matching lines...) Expand all
127 DCHECK_EQ(window_, window); 133 DCHECK_EQ(window_, window);
128 // Stack |window| properly if it is transient child of a sibling. 134 // Stack |window| properly if it is transient child of a sibling.
129 Window* transient_parent = wm::GetTransientParent(window); 135 Window* transient_parent = wm::GetTransientParent(window);
130 if (transient_parent && transient_parent->parent() == parent) { 136 if (transient_parent && transient_parent->parent() == parent) {
131 TransientWindowManager* transient_parent_manager = 137 TransientWindowManager* transient_parent_manager =
132 Get(transient_parent); 138 Get(transient_parent);
133 transient_parent_manager->RestackTransientDescendants(); 139 transient_parent_manager->RestackTransientDescendants();
134 } 140 }
135 } 141 }
136 142
143 void TransientWindowManager::UpdateTransientChildVisibility(
144 bool parent_visible) {
145 base::AutoReset<bool> reset(&ignore_visibility_changed_event_, true);
146 if (!parent_visible) {
147 show_on_parent_visible_ = window_->TargetVisibility();
148 window_->Hide();
149 } else {
150 if (show_on_parent_visible_ && parent_controls_visibility_)
151 window_->Show();
152 show_on_parent_visible_ = false;
153 }
154 }
155
137 void TransientWindowManager::OnWindowVisibilityChanging(Window* window, 156 void TransientWindowManager::OnWindowVisibilityChanging(Window* window,
138 bool visible) { 157 bool visible) {
139 // TODO(sky): move handling of becoming visible here. 158 DCHECK_EQ(window_, window);
140 if (!visible) { 159
141 std::for_each(transient_children_.begin(), transient_children_.end(), 160 for (auto* child : transient_children_)
142 std::mem_fun(&Window::Hide)); 161 Get(child)->UpdateTransientChildVisibility(visible);
162 }
163
164 void TransientWindowManager::OnWindowVisibilityChanged(Window* window,
165 bool visible) {
166 if (window_ != window || ignore_visibility_changed_event_ ||
167 !transient_parent_ || !parent_controls_visibility_) {
168 return;
169 }
170 if (!transient_parent_->TargetVisibility() && visible) {
171 base::AutoReset<bool> reset(&ignore_visibility_changed_event_, true);
172 show_on_parent_visible_ = true;
173 window_->Hide();
174 } else if (!visible) {
175 DCHECK(!show_on_parent_visible_);
143 } 176 }
144 } 177 }
145 178
146 void TransientWindowManager::OnWindowStackingChanged(Window* window) { 179 void TransientWindowManager::OnWindowStackingChanged(Window* window) {
147 DCHECK_EQ(window_, window); 180 DCHECK_EQ(window_, window);
148
149 // Do nothing if we initiated the stacking change. 181 // Do nothing if we initiated the stacking change.
150 const TransientWindowManager* transient_manager = 182 const TransientWindowManager* transient_manager =
151 Get(static_cast<const Window*>(window)); 183 Get(static_cast<const Window*>(window));
152 if (transient_manager && transient_manager->stacking_target_) { 184 if (transient_manager && transient_manager->stacking_target_) {
153 Windows::const_iterator window_i = std::find( 185 Windows::const_iterator window_i = std::find(
154 window->parent()->children().begin(), 186 window->parent()->children().begin(),
155 window->parent()->children().end(), 187 window->parent()->children().end(),
156 window); 188 window);
157 DCHECK(window_i != window->parent()->children().end()); 189 DCHECK(window_i != window->parent()->children().end());
158 if (window_i != window->parent()->children().begin() && 190 if (window_i != window->parent()->children().begin() &&
(...skipping 14 matching lines...) Expand all
173 205
174 // Destroy transient children, only after we've removed ourselves from our 206 // Destroy transient children, only after we've removed ourselves from our
175 // parent, as destroying an active transient child may otherwise attempt to 207 // parent, as destroying an active transient child may otherwise attempt to
176 // refocus us. 208 // refocus us.
177 Windows transient_children(transient_children_); 209 Windows transient_children(transient_children_);
178 STLDeleteElements(&transient_children); 210 STLDeleteElements(&transient_children);
179 DCHECK(transient_children_.empty()); 211 DCHECK(transient_children_.empty());
180 } 212 }
181 213
182 } // namespace wm 214 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/transient_window_manager.h ('k') | ui/wm/core/transient_window_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698