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

Side by Side Diff: services/ui/ws/window_manager_state.cc

Issue 2346253004: Makes display roots be destroyed by client (Closed)
Patch Set: cleanup Created 4 years, 3 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 | « services/ui/ws/window_manager_state.h ('k') | services/ui/ws/window_server.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/window_manager_state.h" 5 #include "services/ui/ws/window_manager_state.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "services/shell/public/interfaces/connector.mojom.h" 10 #include "services/shell/public/interfaces/connector.mojom.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 WindowManagerState::QueuedEvent::~QueuedEvent() {} 111 WindowManagerState::QueuedEvent::~QueuedEvent() {}
112 112
113 WindowManagerState::WindowManagerState(WindowTree* window_tree) 113 WindowManagerState::WindowManagerState(WindowTree* window_tree)
114 : window_tree_(window_tree), event_dispatcher_(this), weak_factory_(this) { 114 : window_tree_(window_tree), event_dispatcher_(this), weak_factory_(this) {
115 frame_decoration_values_ = mojom::FrameDecorationValues::New(); 115 frame_decoration_values_ = mojom::FrameDecorationValues::New();
116 frame_decoration_values_->max_title_bar_button_width = 0u; 116 frame_decoration_values_->max_title_bar_button_width = 0u;
117 117
118 AddDebugAccelerators(); 118 AddDebugAccelerators();
119 } 119 }
120 120
121 WindowManagerState::~WindowManagerState() {} 121 WindowManagerState::~WindowManagerState() {
122 for (auto& display_root : orphaned_window_manager_display_roots_)
123 display_root->root()->RemoveObserver(this);
124 }
122 125
123 void WindowManagerState::SetFrameDecorationValues( 126 void WindowManagerState::SetFrameDecorationValues(
124 mojom::FrameDecorationValuesPtr values) { 127 mojom::FrameDecorationValuesPtr values) {
125 got_frame_decoration_values_ = true; 128 got_frame_decoration_values_ = true;
126 frame_decoration_values_ = values.Clone(); 129 frame_decoration_values_ = values.Clone();
127 display_manager() 130 display_manager()
128 ->GetUserDisplayManager(user_id()) 131 ->GetUserDisplayManager(user_id())
129 ->OnFrameDecorationValuesChanged(); 132 ->OnFrameDecorationValuesChanged();
130 } 133 }
131 134
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return; 190 return;
188 191
189 // The WindowTree is dying. So it's not going to ack the event. 192 // The WindowTree is dying. So it's not going to ack the event.
190 // If the dying tree matches the root |tree_| marked as handled so we don't 193 // If the dying tree matches the root |tree_| marked as handled so we don't
191 // notify it of accelerators. 194 // notify it of accelerators.
192 OnEventAck(tree_awaiting_input_ack_, tree == window_tree_ 195 OnEventAck(tree_awaiting_input_ack_, tree == window_tree_
193 ? mojom::EventResult::HANDLED 196 ? mojom::EventResult::HANDLED
194 : mojom::EventResult::UNHANDLED); 197 : mojom::EventResult::UNHANDLED);
195 } 198 }
196 199
200 ServerWindow* WindowManagerState::GetOrphanedRootWithId(const WindowId& id) {
201 for (auto& display_root_ptr : orphaned_window_manager_display_roots_) {
202 if (display_root_ptr->root()->id() == id)
203 return display_root_ptr->root();
204 }
205 return nullptr;
206 }
207
197 bool WindowManagerState::IsActive() const { 208 bool WindowManagerState::IsActive() const {
198 return window_server()->user_id_tracker()->active_id() == user_id(); 209 return window_server()->user_id_tracker()->active_id() == user_id();
199 } 210 }
200 211
201 void WindowManagerState::Activate(const gfx::Point& mouse_location_on_screen) { 212 void WindowManagerState::Activate(const gfx::Point& mouse_location_on_screen) {
202 SetAllRootWindowsVisible(true); 213 SetAllRootWindowsVisible(true);
203 event_dispatcher_.Reset(); 214 event_dispatcher_.Reset();
204 event_dispatcher_.SetMousePointerScreenLocation(mouse_location_on_screen); 215 event_dispatcher_.SetMousePointerScreenLocation(mouse_location_on_screen);
205 } 216 }
206 217
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 297 }
287 298
288 DisplayManager* WindowManagerState::display_manager() { 299 DisplayManager* WindowManagerState::display_manager() {
289 return window_tree_->display_manager(); 300 return window_tree_->display_manager();
290 } 301 }
291 302
292 const DisplayManager* WindowManagerState::display_manager() const { 303 const DisplayManager* WindowManagerState::display_manager() const {
293 return window_tree_->display_manager(); 304 return window_tree_->display_manager();
294 } 305 }
295 306
307 void WindowManagerState::AddWindowManagerDisplayRoot(
308 std::unique_ptr<WindowManagerDisplayRoot> display_root) {
309 window_manager_display_roots_.push_back(std::move(display_root));
310 }
311
312 void WindowManagerState::OnDisplayDestroying(Display* display) {
313 if (display->platform_display() == platform_display_with_capture_)
314 platform_display_with_capture_ = nullptr;
315
316 for (auto iter = window_manager_display_roots_.begin();
317 iter != window_manager_display_roots_.end(); ++iter) {
318 if ((*iter)->display() == display) {
319 (*iter)->root()->AddObserver(this);
320 orphaned_window_manager_display_roots_.push_back(std::move(*iter));
321 window_manager_display_roots_.erase(iter);
322 window_tree_->OnDisplayDestroying(display->GetId());
323 return;
324 }
325 }
326 NOTREACHED();
327 }
328
296 void WindowManagerState::SetAllRootWindowsVisible(bool value) { 329 void WindowManagerState::SetAllRootWindowsVisible(bool value) {
297 for (Display* display : display_manager()->displays()) { 330 for (auto& display_root_ptr : window_manager_display_roots_)
298 WindowManagerDisplayRoot* display_root = 331 display_root_ptr->root()->SetVisible(value);
299 display->GetWindowManagerDisplayRootForUser(user_id());
300 if (display_root)
301 display_root->root()->SetVisible(value);
302 }
303 } 332 }
304 333
305 ServerWindow* WindowManagerState::GetWindowManagerRoot(ServerWindow* window) { 334 ServerWindow* WindowManagerState::GetWindowManagerRoot(ServerWindow* window) {
306 for (Display* display : display_manager()->displays()) { 335 for (auto& display_root_ptr : window_manager_display_roots_) {
307 WindowManagerDisplayRoot* display_root = 336 if (display_root_ptr->root()->parent() == window)
308 display->GetWindowManagerDisplayRootForUser(user_id()); 337 return display_root_ptr->root();
309 if (display_root && display_root->root()->parent() == window)
310 return display_root->root();
311 } 338 }
312 NOTREACHED(); 339 NOTREACHED();
313 return nullptr; 340 return nullptr;
314 } 341 }
315 342
316 void WindowManagerState::OnEventAckTimeout(ClientSpecificId client_id) { 343 void WindowManagerState::OnEventAckTimeout(ClientSpecificId client_id) {
317 WindowTree* hung_tree = window_server()->GetTreeWithId(client_id); 344 WindowTree* hung_tree = window_server()->GetTreeWithId(client_id);
318 if (hung_tree && !hung_tree->janky()) 345 if (hung_tree && !hung_tree->janky())
319 window_tree_->ClientJankinessChanged(hung_tree); 346 window_tree_->ClientJankinessChanged(hung_tree);
320 if (event_dispatch_phase_ == EventDispatchPhase::PRE_TARGET_ACCELERATOR) 347 if (event_dispatch_phase_ == EventDispatchPhase::PRE_TARGET_ACCELERATOR)
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 DCHECK(tree->HasRoot(embed_root)); 569 DCHECK(tree->HasRoot(embed_root));
543 tree = window_server()->GetTreeWithId(embed_root->id().client_id); 570 tree = window_server()->GetTreeWithId(embed_root->id().client_id);
544 embed_root = GetEmbedRoot(embed_root); 571 embed_root = GetEmbedRoot(embed_root);
545 } 572 }
546 DCHECK(tree); 573 DCHECK(tree);
547 return tree->id(); 574 return tree->id();
548 } 575 }
549 576
550 ServerWindow* WindowManagerState::GetRootWindowContaining( 577 ServerWindow* WindowManagerState::GetRootWindowContaining(
551 gfx::Point* location) { 578 gfx::Point* location) {
552 if (display_manager()->displays().empty()) 579 if (window_manager_display_roots_.empty())
553 return nullptr; 580 return nullptr;
554 581
555 Display* target_display = nullptr; 582 WindowManagerDisplayRoot* target_display_root = nullptr;
556 for (Display* display : display_manager()->displays()) { 583 for (auto& display_root_ptr : window_manager_display_roots_) {
557 if (display->platform_display()->GetBounds().Contains(*location)) { 584 if (display_root_ptr->display()->platform_display()->GetBounds().Contains(
558 target_display = display; 585 *location)) {
586 target_display_root = display_root_ptr.get();
559 break; 587 break;
560 } 588 }
561 } 589 }
562 590
563 // TODO(kylechar): Better handle locations outside the window. Overlapping X11 591 // TODO(kylechar): Better handle locations outside the window. Overlapping X11
564 // windows, dragging and touch sensors need to be handled properly. 592 // windows, dragging and touch sensors need to be handled properly.
565 if (!target_display) { 593 if (!target_display_root) {
566 DVLOG(1) << "Invalid event location " << location->ToString(); 594 DVLOG(1) << "Invalid event location " << location->ToString();
567 target_display = *(display_manager()->displays().begin()); 595 target_display_root = window_manager_display_roots_.begin()->get();
568 } 596 }
569 597
570 WindowManagerDisplayRoot* display_root =
571 target_display->GetWindowManagerDisplayRootForUser(user_id());
572
573 if (!display_root)
574 return nullptr;
575
576 // Translate the location to be relative to the display instead of relative 598 // Translate the location to be relative to the display instead of relative
577 // to the screen space. 599 // to the screen space.
578 gfx::Point origin = target_display->platform_display()->GetBounds().origin(); 600 gfx::Point origin =
601 target_display_root->display()->platform_display()->GetBounds().origin();
579 *location -= origin.OffsetFromOrigin(); 602 *location -= origin.OffsetFromOrigin();
580 return display_root->root(); 603 return target_display_root->root();
581 } 604 }
582 605
583 void WindowManagerState::OnEventTargetNotFound(const ui::Event& event) { 606 void WindowManagerState::OnEventTargetNotFound(const ui::Event& event) {
584 window_server()->SendToPointerWatchers(event, user_id(), nullptr, /* window */ 607 window_server()->SendToPointerWatchers(event, user_id(), nullptr, /* window */
585 nullptr /* ignore_tree */); 608 nullptr /* ignore_tree */);
586 } 609 }
587 610
611 void WindowManagerState::OnWindowEmbeddedAppDisconnected(ServerWindow* window) {
612 for (auto iter = orphaned_window_manager_display_roots_.begin();
613 iter != orphaned_window_manager_display_roots_.end(); ++iter) {
614 if ((*iter)->root() == window) {
615 window->RemoveObserver(this);
616 orphaned_window_manager_display_roots_.erase(iter);
617 return;
618 }
619 }
620 NOTREACHED();
621 }
622
588 } // namespace ws 623 } // namespace ws
589 } // namespace ui 624 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/window_manager_state.h ('k') | services/ui/ws/window_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698