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

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: fix check 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
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_control_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_control_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 if (window_ != window)
sky 2014/10/07 15:19:14 Why the if, at best this should be a DCHECK
oshima 2014/10/07 17:41:14 Done. I was confused by the difference between Cha
oshima 2014/10/07 17:41:56 oops, I meant "Changed (called in hierarchy chain)
140 if (!visible) { 159 return;
141 std::for_each(transient_children_.begin(), transient_children_.end(), 160
142 std::mem_fun(&Window::Hide)); 161 for (auto* child : transient_children_)
sky 2014/10/07 15:19:14 From the style guide: "auto is permitted, for loca
oshima 2014/10/07 17:41:14 Where is it? I was looking at http://chromium-cpp
oshima 2014/10/07 17:46:25 I guess you meant the description in https://googl
sky 2014/10/07 19:34:21 Yes, you are right. My mistake.
162 Get(child)->UpdateTransientChildVisibility(visible);
163 }
164
165 void TransientWindowManager::OnWindowVisibilityChanged(Window* window,
sky 2014/10/07 15:19:14 Why do you need to do something in both changed an
oshima 2014/10/07 17:41:14 I tried and had problem because OnWindowVisibiltyC
sky 2014/10/07 19:34:21 That seems wrong. It should only be called once.
166 bool visible) {
167 if (window_ != window || ignore_visibility_changed_event_ ||
sky 2014/10/07 15:19:14 You shouldn't need the window_ != window. Add a DC
oshima 2014/10/07 17:41:14 I needed this because OnWindowVisibilityChanged is
sky 2014/10/07 19:34:21 Ah, ok.
168 !transient_parent_ || !parent_control_visibility_) {
169 return;
170 }
171 if (!transient_parent_->TargetVisibility() && visible) {
172 base::AutoReset<bool> reset(&ignore_visibility_changed_event_, true);
173 show_on_parent_visible_ = true;
174 window_->Hide();
175 } else if (!visible) {
176 DCHECK(!show_on_parent_visible_);
143 } 177 }
144 } 178 }
145 179
146 void TransientWindowManager::OnWindowStackingChanged(Window* window) { 180 void TransientWindowManager::OnWindowStackingChanged(Window* window) {
147 DCHECK_EQ(window_, window); 181 DCHECK_EQ(window_, window);
148
149 // Do nothing if we initiated the stacking change. 182 // Do nothing if we initiated the stacking change.
150 const TransientWindowManager* transient_manager = 183 const TransientWindowManager* transient_manager =
151 Get(static_cast<const Window*>(window)); 184 Get(static_cast<const Window*>(window));
152 if (transient_manager && transient_manager->stacking_target_) { 185 if (transient_manager && transient_manager->stacking_target_) {
153 Windows::const_iterator window_i = std::find( 186 Windows::const_iterator window_i = std::find(
154 window->parent()->children().begin(), 187 window->parent()->children().begin(),
155 window->parent()->children().end(), 188 window->parent()->children().end(),
156 window); 189 window);
157 DCHECK(window_i != window->parent()->children().end()); 190 DCHECK(window_i != window->parent()->children().end());
158 if (window_i != window->parent()->children().begin() && 191 if (window_i != window->parent()->children().begin() &&
(...skipping 14 matching lines...) Expand all
173 206
174 // Destroy transient children, only after we've removed ourselves from our 207 // Destroy transient children, only after we've removed ourselves from our
175 // parent, as destroying an active transient child may otherwise attempt to 208 // parent, as destroying an active transient child may otherwise attempt to
176 // refocus us. 209 // refocus us.
177 Windows transient_children(transient_children_); 210 Windows transient_children(transient_children_);
178 STLDeleteElements(&transient_children); 211 STLDeleteElements(&transient_children);
179 DCHECK(transient_children_.empty()); 212 DCHECK(transient_children_.empty());
180 } 213 }
181 214
182 } // namespace wm 215 } // namespace wm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698