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 "services/ui/ws/server_window.h" | 5 #include "services/ui/ws/server_window.h" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "services/ui/common/transient_window_utils.h" | 12 #include "services/ui/common/transient_window_utils.h" |
13 #include "services/ui/public/interfaces/window_manager.mojom.h" | 13 #include "services/ui/public/interfaces/window_manager.mojom.h" |
14 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" | 14 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
15 #include "services/ui/ws/server_window_delegate.h" | 15 #include "services/ui/ws/server_window_delegate.h" |
16 #include "services/ui/ws/server_window_observer.h" | 16 #include "services/ui/ws/server_window_observer.h" |
17 | 17 |
18 namespace ui { | 18 namespace ui { |
19 namespace ws { | 19 namespace ws { |
20 | 20 |
21 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, const WindowId& id) | 21 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, const WindowId& id) |
22 : ServerWindow(delegate, id, Properties()) {} | 22 : ServerWindow(delegate, id, Properties()) {} |
23 | 23 |
24 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, | 24 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, |
25 const WindowId& id, | 25 const WindowId& id, |
26 const Properties& properties) | 26 const Properties& properties) |
27 : delegate_(delegate), | 27 : delegate_(delegate), |
28 id_(id), | 28 id_(id), |
| 29 frame_sink_id_(WindowIdToTransportId(id), 0), |
29 parent_(nullptr), | 30 parent_(nullptr), |
30 stacking_target_(nullptr), | 31 stacking_target_(nullptr), |
31 transient_parent_(nullptr), | 32 transient_parent_(nullptr), |
32 is_modal_(false), | 33 is_modal_(false), |
33 visible_(false), | 34 visible_(false), |
34 // Default to POINTER as CURSOR_NULL doesn't change the cursor, it leaves | 35 // Default to POINTER as CURSOR_NULL doesn't change the cursor, it leaves |
35 // the last non-null cursor. | 36 // the last non-null cursor. |
36 cursor_id_(mojom::Cursor::POINTER), | 37 cursor_id_(mojom::Cursor::POINTER), |
37 non_client_cursor_id_(mojom::Cursor::POINTER), | 38 non_client_cursor_id_(mojom::Cursor::POINTER), |
38 opacity_(1), | 39 opacity_(1), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 if (children_.size() == 1) | 111 if (children_.size() == 1) |
111 return; // Already in the right position. | 112 return; // Already in the right position. |
112 child->Reorder(children_.back(), mojom::OrderDirection::ABOVE); | 113 child->Reorder(children_.back(), mojom::OrderDirection::ABOVE); |
113 return; | 114 return; |
114 } | 115 } |
115 | 116 |
116 ServerWindow* old_parent = child->parent(); | 117 ServerWindow* old_parent = child->parent(); |
117 for (auto& observer : child->observers_) | 118 for (auto& observer : child->observers_) |
118 observer.OnWillChangeWindowHierarchy(child, this, old_parent); | 119 observer.OnWillChangeWindowHierarchy(child, this, old_parent); |
119 | 120 |
120 ServerWindow* old_root = child->GetRoot(); | |
121 ServerWindow* new_root = GetRoot(); | |
122 | |
123 if (child->parent()) | 121 if (child->parent()) |
124 child->parent()->RemoveImpl(child); | 122 child->parent()->RemoveImpl(child); |
125 | 123 |
126 child->parent_ = this; | 124 child->parent_ = this; |
127 children_.push_back(child); | 125 children_.push_back(child); |
128 | 126 |
129 if (old_root != new_root) | |
130 child->ProcessRootChanged(old_root, new_root); | |
131 | |
132 // Stack the child properly if it is a transient child of a sibling. | 127 // Stack the child properly if it is a transient child of a sibling. |
133 if (child->transient_parent_ && child->transient_parent_->parent() == this) | 128 if (child->transient_parent_ && child->transient_parent_->parent() == this) |
134 RestackTransientDescendants(child->transient_parent_, &GetStackingTarget, | 129 RestackTransientDescendants(child->transient_parent_, &GetStackingTarget, |
135 &ReorderImpl); | 130 &ReorderImpl); |
136 | 131 |
137 for (auto& observer : child->observers_) | 132 for (auto& observer : child->observers_) |
138 observer.OnWindowHierarchyChanged(child, this, old_parent); | 133 observer.OnWindowHierarchyChanged(child, this, old_parent); |
139 } | 134 } |
140 | 135 |
141 void ServerWindow::Remove(ServerWindow* child) { | 136 void ServerWindow::Remove(ServerWindow* child) { |
142 // We assume validation checks happened else where. | 137 // We assume validation checks happened else where. |
143 DCHECK(child); | 138 DCHECK(child); |
144 DCHECK(child != this); | 139 DCHECK(child != this); |
145 DCHECK(child->parent() == this); | 140 DCHECK(child->parent() == this); |
146 | 141 |
147 for (auto& observer : child->observers_) | 142 for (auto& observer : child->observers_) |
148 observer.OnWillChangeWindowHierarchy(child, nullptr, this); | 143 observer.OnWillChangeWindowHierarchy(child, nullptr, this); |
149 | 144 |
150 RemoveImpl(child); | 145 RemoveImpl(child); |
151 | 146 |
152 if (GetRoot() != nullptr) | |
153 child->ProcessRootChanged(GetRoot(), nullptr); | |
154 | |
155 // Stack the child properly if it is a transient child of a sibling. | 147 // Stack the child properly if it is a transient child of a sibling. |
156 if (child->transient_parent_ && child->transient_parent_->parent() == this) | 148 if (child->transient_parent_ && child->transient_parent_->parent() == this) |
157 RestackTransientDescendants(child->transient_parent_, &GetStackingTarget, | 149 RestackTransientDescendants(child->transient_parent_, &GetStackingTarget, |
158 &ReorderImpl); | 150 &ReorderImpl); |
159 | 151 |
160 for (auto& observer : child->observers_) | 152 for (auto& observer : child->observers_) |
161 observer.OnWindowHierarchyChanged(child, nullptr, this); | 153 observer.OnWindowHierarchyChanged(child, nullptr, this); |
162 } | 154 } |
163 | 155 |
164 void ServerWindow::Reorder(ServerWindow* relative, | 156 void ServerWindow::Reorder(ServerWindow* relative, |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 for (const ServerWindow* child : children_) | 416 for (const ServerWindow* child : children_) |
425 child->BuildDebugInfo(depth + " ", result); | 417 child->BuildDebugInfo(depth + " ", result); |
426 } | 418 } |
427 #endif | 419 #endif |
428 | 420 |
429 void ServerWindow::RemoveImpl(ServerWindow* window) { | 421 void ServerWindow::RemoveImpl(ServerWindow* window) { |
430 window->parent_ = nullptr; | 422 window->parent_ = nullptr; |
431 children_.erase(std::find(children_.begin(), children_.end(), window)); | 423 children_.erase(std::find(children_.begin(), children_.end(), window)); |
432 } | 424 } |
433 | 425 |
434 void ServerWindow::ProcessRootChanged(ServerWindow* old_root, | |
435 ServerWindow* new_root) { | |
436 if (compositor_frame_sink_manager_) | |
437 compositor_frame_sink_manager_->OnRootChanged(old_root, new_root); | |
438 for (ServerWindow* child : children_) | |
439 child->ProcessRootChanged(old_root, new_root); | |
440 } | |
441 | |
442 void ServerWindow::OnStackingChanged() { | 426 void ServerWindow::OnStackingChanged() { |
443 if (stacking_target_) { | 427 if (stacking_target_) { |
444 Windows::const_iterator window_i = std::find( | 428 Windows::const_iterator window_i = std::find( |
445 parent()->children().begin(), parent()->children().end(), this); | 429 parent()->children().begin(), parent()->children().end(), this); |
446 DCHECK(window_i != parent()->children().end()); | 430 DCHECK(window_i != parent()->children().end()); |
447 if (window_i != parent()->children().begin() && | 431 if (window_i != parent()->children().begin() && |
448 (*(window_i - 1) == stacking_target_)) { | 432 (*(window_i - 1) == stacking_target_)) { |
449 return; | 433 return; |
450 } | 434 } |
451 } | 435 } |
(...skipping 29 matching lines...) Expand all Loading... |
481 window->OnStackingChanged(); | 465 window->OnStackingChanged(); |
482 } | 466 } |
483 | 467 |
484 // static | 468 // static |
485 ServerWindow** ServerWindow::GetStackingTarget(ServerWindow* window) { | 469 ServerWindow** ServerWindow::GetStackingTarget(ServerWindow* window) { |
486 return &window->stacking_target_; | 470 return &window->stacking_target_; |
487 } | 471 } |
488 | 472 |
489 } // namespace ws | 473 } // namespace ws |
490 } // namespace ui | 474 } // namespace ui |
OLD | NEW |