| OLD | NEW |
| 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/client/transient_window_client_observer.h" |
| 12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_property.h" | 14 #include "ui/aura/window_property.h" |
| 14 #include "ui/aura/window_tracker.h" | 15 #include "ui/aura/window_tracker.h" |
| 16 #include "ui/wm/core/transient_window_controller.h" |
| 15 #include "ui/wm/core/transient_window_observer.h" | 17 #include "ui/wm/core/transient_window_observer.h" |
| 16 #include "ui/wm/core/transient_window_stacking_client.h" | 18 #include "ui/wm/core/transient_window_stacking_client.h" |
| 17 #include "ui/wm/core/window_util.h" | 19 #include "ui/wm/core/window_util.h" |
| 18 | 20 |
| 19 using aura::Window; | 21 using aura::Window; |
| 20 | 22 |
| 21 DECLARE_WINDOW_PROPERTY_TYPE(wm::TransientWindowManager*); | 23 DECLARE_WINDOW_PROPERTY_TYPE(wm::TransientWindowManager*); |
| 22 | 24 |
| 23 namespace wm { | 25 namespace wm { |
| 24 namespace { | 26 namespace { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 DCHECK(TransientWindowStackingClient::instance_); | 62 DCHECK(TransientWindowStackingClient::instance_); |
| 61 | 63 |
| 62 TransientWindowManager* child_manager = Get(child); | 64 TransientWindowManager* child_manager = Get(child); |
| 63 if (child_manager->transient_parent_) | 65 if (child_manager->transient_parent_) |
| 64 Get(child_manager->transient_parent_)->RemoveTransientChild(child); | 66 Get(child_manager->transient_parent_)->RemoveTransientChild(child); |
| 65 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), | 67 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), |
| 66 child) == transient_children_.end()); | 68 child) == transient_children_.end()); |
| 67 transient_children_.push_back(child); | 69 transient_children_.push_back(child); |
| 68 child_manager->transient_parent_ = window_; | 70 child_manager->transient_parent_ = window_; |
| 69 | 71 |
| 72 for (aura::client::TransientWindowClientObserver& observer : |
| 73 TransientWindowController::Get()->observers_) { |
| 74 observer.OnTransientChildWindowAdded(window_, child); |
| 75 } |
| 76 |
| 70 // Restack |child| properly above its transient parent, if they share the same | 77 // Restack |child| properly above its transient parent, if they share the same |
| 71 // parent. | 78 // parent. |
| 72 if (child->parent() == window_->parent()) | 79 if (child->parent() == window_->parent()) |
| 73 RestackTransientDescendants(); | 80 RestackTransientDescendants(); |
| 74 | 81 |
| 75 for (auto& observer : observers_) | 82 for (auto& observer : observers_) |
| 76 observer.OnTransientChildAdded(window_, child); | 83 observer.OnTransientChildAdded(window_, child); |
| 77 } | 84 } |
| 78 | 85 |
| 79 void TransientWindowManager::RemoveTransientChild(Window* child) { | 86 void TransientWindowManager::RemoveTransientChild(Window* child) { |
| 80 Windows::iterator i = | 87 Windows::iterator i = |
| 81 std::find(transient_children_.begin(), transient_children_.end(), child); | 88 std::find(transient_children_.begin(), transient_children_.end(), child); |
| 82 DCHECK(i != transient_children_.end()); | 89 DCHECK(i != transient_children_.end()); |
| 83 transient_children_.erase(i); | 90 transient_children_.erase(i); |
| 84 TransientWindowManager* child_manager = Get(child); | 91 TransientWindowManager* child_manager = Get(child); |
| 85 DCHECK_EQ(window_, child_manager->transient_parent_); | 92 DCHECK_EQ(window_, child_manager->transient_parent_); |
| 86 child_manager->transient_parent_ = NULL; | 93 child_manager->transient_parent_ = nullptr; |
| 94 |
| 95 for (aura::client::TransientWindowClientObserver& observer : |
| 96 TransientWindowController::Get()->observers_) { |
| 97 observer.OnTransientChildWindowRemoved(window_, child); |
| 98 } |
| 87 | 99 |
| 88 // If |child| and its former transient parent share the same parent, |child| | 100 // If |child| and its former transient parent share the same parent, |child| |
| 89 // should be restacked properly so it is not among transient children of its | 101 // should be restacked properly so it is not among transient children of its |
| 90 // former parent, anymore. | 102 // former parent, anymore. |
| 91 if (window_->parent() == child->parent()) | 103 if (window_->parent() == child->parent()) |
| 92 RestackTransientDescendants(); | 104 RestackTransientDescendants(); |
| 93 | 105 |
| 94 for (auto& observer : observers_) | 106 for (auto& observer : observers_) |
| 95 observer.OnTransientChildRemoved(window_, child); | 107 observer.OnTransientChildRemoved(window_, child); |
| 96 } | 108 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 229 |
| 218 // Destroy transient children, only after we've removed ourselves from our | 230 // Destroy transient children, only after we've removed ourselves from our |
| 219 // parent, as destroying an active transient child may otherwise attempt to | 231 // parent, as destroying an active transient child may otherwise attempt to |
| 220 // refocus us. | 232 // refocus us. |
| 221 Windows transient_children(transient_children_); | 233 Windows transient_children(transient_children_); |
| 222 base::STLDeleteElements(&transient_children); | 234 base::STLDeleteElements(&transient_children); |
| 223 DCHECK(transient_children_.empty()); | 235 DCHECK(transient_children_.empty()); |
| 224 } | 236 } |
| 225 | 237 |
| 226 } // namespace wm | 238 } // namespace wm |
| OLD | NEW |