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

Side by Side Diff: services/ui/public/cpp/window_tree_client.cc

Issue 2424613002: Remove usage of FOR_EACH_OBSERVER macro in services/ (Closed)
Patch Set: Created 4 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 | « services/ui/public/cpp/window.cc ('k') | services/ui/ws/animation_runner.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 "services/ui/public/cpp/window_tree_client.h" 5 #include "services/ui/public/cpp/window_tree_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Allow for a null request in tests. 85 // Allow for a null request in tests.
86 if (request.is_pending()) 86 if (request.is_pending())
87 binding_.Bind(std::move(request)); 87 binding_.Bind(std::move(request));
88 if (window_manager_delegate) 88 if (window_manager_delegate)
89 window_manager_delegate->SetWindowManagerClient(this); 89 window_manager_delegate->SetWindowManagerClient(this);
90 } 90 }
91 91
92 WindowTreeClient::~WindowTreeClient() { 92 WindowTreeClient::~WindowTreeClient() {
93 in_destructor_ = true; 93 in_destructor_ = true;
94 94
95 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_, 95 for (auto& observer : observers_)
96 OnWillDestroyClient(this)); 96 observer.OnWillDestroyClient(this);
97 97
98 std::vector<Window*> non_owned; 98 std::vector<Window*> non_owned;
99 WindowTracker tracker; 99 WindowTracker tracker;
100 while (!windows_.empty()) { 100 while (!windows_.empty()) {
101 IdToWindowMap::iterator it = windows_.begin(); 101 IdToWindowMap::iterator it = windows_.begin();
102 if (it->second->WasCreatedByThisClient()) { 102 if (it->second->WasCreatedByThisClient()) {
103 it->second->Destroy(); 103 it->second->Destroy();
104 } else { 104 } else {
105 tracker.Add(it->second); 105 tracker.Add(it->second);
106 windows_.erase(it); 106 windows_.erase(it);
107 } 107 }
108 } 108 }
109 109
110 // Delete the non-owned windows last. In the typical case these are roots. The 110 // Delete the non-owned windows last. In the typical case these are roots. The
111 // exception is the window manager and embed roots, which may know about 111 // exception is the window manager and embed roots, which may know about
112 // other random windows that it doesn't own. 112 // other random windows that it doesn't own.
113 // NOTE: we manually delete as we're a friend. 113 // NOTE: we manually delete as we're a friend.
114 while (!tracker.windows().empty()) 114 while (!tracker.windows().empty())
115 delete tracker.windows().front(); 115 delete tracker.windows().front();
116 116
117 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_, 117 for (auto& observer : observers_)
118 OnDidDestroyClient(this)); 118 observer.OnDidDestroyClient(this);
119 } 119 }
120 120
121 void WindowTreeClient::ConnectViaWindowTreeFactory( 121 void WindowTreeClient::ConnectViaWindowTreeFactory(
122 shell::Connector* connector) { 122 shell::Connector* connector) {
123 // The client id doesn't really matter, we use 101 purely for debugging. 123 // The client id doesn't really matter, we use 101 purely for debugging.
124 client_id_ = 101; 124 client_id_ = 101;
125 125
126 mojom::WindowTreeFactoryPtr factory; 126 mojom::WindowTreeFactoryPtr factory;
127 connector->ConnectToInterface("service:ui", &factory); 127 connector->ConnectToInterface("service:ui", &factory);
128 mojom::WindowTreePtr window_tree; 128 mojom::WindowTreePtr window_tree;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 DCHECK(tree_); 363 DCHECK(tree_);
364 tree_->OnWindowSurfaceDetached(window_id, sequence); 364 tree_->OnWindowSurfaceDetached(window_id, sequence);
365 } 365 }
366 366
367 void WindowTreeClient::LocalSetCapture(Window* window) { 367 void WindowTreeClient::LocalSetCapture(Window* window) {
368 if (capture_window_ == window) 368 if (capture_window_ == window)
369 return; 369 return;
370 Window* lost_capture = capture_window_; 370 Window* lost_capture = capture_window_;
371 capture_window_ = window; 371 capture_window_ = window;
372 if (lost_capture) { 372 if (lost_capture) {
373 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(lost_capture).observers(), 373 for (auto& observer : *WindowPrivate(lost_capture).observers())
374 OnWindowLostCapture(lost_capture)); 374 observer.OnWindowLostCapture(lost_capture);
375 } 375 }
376 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_, 376 for (auto& observer : observers_)
377 OnWindowTreeCaptureChanged(window, lost_capture)); 377 observer.OnWindowTreeCaptureChanged(window, lost_capture);
378 } 378 }
379 379
380 void WindowTreeClient::LocalSetFocus(Window* focused) { 380 void WindowTreeClient::LocalSetFocus(Window* focused) {
381 Window* blurred = focused_window_; 381 Window* blurred = focused_window_;
382 // Update |focused_window_| before calling any of the observers, so that the 382 // Update |focused_window_| before calling any of the observers, so that the
383 // observers get the correct result from calling |Window::HasFocus()|, 383 // observers get the correct result from calling |Window::HasFocus()|,
384 // |WindowTreeClient::GetFocusedWindow()| etc. 384 // |WindowTreeClient::GetFocusedWindow()| etc.
385 focused_window_ = focused; 385 focused_window_ = focused;
386 if (blurred) { 386 if (blurred) {
387 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(blurred).observers(), 387 for (auto& observer : *WindowPrivate(blurred).observers())
388 OnWindowFocusChanged(focused, blurred)); 388 observer.OnWindowFocusChanged(focused, blurred);
389 } 389 }
390 if (focused) { 390 if (focused) {
391 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(focused).observers(), 391 for (auto& observer : *WindowPrivate(focused).observers())
392 OnWindowFocusChanged(focused, blurred)); 392 observer.OnWindowFocusChanged(focused, blurred);
393 } 393 }
394 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_, 394 for (auto& observer : observers_)
395 OnWindowTreeFocusChanged(focused, blurred)); 395 observer.OnWindowTreeFocusChanged(focused, blurred);
396 } 396 }
397 397
398 void WindowTreeClient::AddWindow(Window* window) { 398 void WindowTreeClient::AddWindow(Window* window) {
399 DCHECK(windows_.find(server_id(window)) == windows_.end()); 399 DCHECK(windows_.find(server_id(window)) == windows_.end());
400 windows_[server_id(window)] = window; 400 windows_[server_id(window)] = window;
401 } 401 }
402 402
403 void WindowTreeClient::OnWindowDestroying(Window* window) { 403 void WindowTreeClient::OnWindowDestroying(Window* window) {
404 if (window == capture_window_) { 404 if (window == capture_window_) {
405 // Normally the queue updates itself upon window destruction. However since 405 // Normally the queue updates itself upon window destruction. However since
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 WindowPrivate(root).LocalSetDisplay(display_id); 563 WindowPrivate(root).LocalSetDisplay(display_id);
564 roots_.insert(root); 564 roots_.insert(root);
565 565
566 focused_window_ = GetWindowByServerId(focused_window_id); 566 focused_window_ = GetWindowByServerId(focused_window_id);
567 567
568 WindowPrivate(root).LocalSetParentDrawn(drawn); 568 WindowPrivate(root).LocalSetParentDrawn(drawn);
569 569
570 delegate_->OnEmbed(root); 570 delegate_->OnEmbed(root);
571 571
572 if (focused_window_) { 572 if (focused_window_) {
573 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_, 573 for (auto& observer : observers_)
574 OnWindowTreeFocusChanged(focused_window_, nullptr)); 574 observer.OnWindowTreeFocusChanged(focused_window_, nullptr);
575 } 575 }
576 } 576 }
577 577
578 void WindowTreeClient::WmNewDisplayAddedImpl(const display::Display& display, 578 void WindowTreeClient::WmNewDisplayAddedImpl(const display::Display& display,
579 mojom::WindowDataPtr root_data, 579 mojom::WindowDataPtr root_data,
580 bool parent_drawn) { 580 bool parent_drawn) {
581 DCHECK(window_manager_delegate_); 581 DCHECK(window_manager_delegate_);
582 582
583 Window* root = AddWindowToClient(this, nullptr, root_data); 583 Window* root = AddWindowToClient(this, nullptr, root_data);
584 WindowPrivate(root).LocalSetDisplay(display.id()); 584 WindowPrivate(root).LocalSetDisplay(display.id());
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 tree_ptr_.associated_group())); 776 tree_ptr_.associated_group()));
777 } 777 }
778 778
779 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, 779 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id,
780 focused_window_id, drawn); 780 focused_window_id, drawn);
781 } 781 }
782 782
783 void WindowTreeClient::OnEmbeddedAppDisconnected(Id window_id) { 783 void WindowTreeClient::OnEmbeddedAppDisconnected(Id window_id) {
784 Window* window = GetWindowByServerId(window_id); 784 Window* window = GetWindowByServerId(window_id);
785 if (window) { 785 if (window) {
786 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), 786 for (auto& observer : *WindowPrivate(window).observers())
787 OnWindowEmbeddedAppDisconnected(window)); 787 observer.OnWindowEmbeddedAppDisconnected(window);
788 } 788 }
789 } 789 }
790 790
791 void WindowTreeClient::OnUnembed(Id window_id) { 791 void WindowTreeClient::OnUnembed(Id window_id) {
792 Window* window = GetWindowByServerId(window_id); 792 Window* window = GetWindowByServerId(window_id);
793 if (!window) 793 if (!window)
794 return; 794 return;
795 795
796 delegate_->OnUnembed(window); 796 delegate_->OnUnembed(window);
797 WindowPrivate(window).LocalDestroy(); 797 WindowPrivate(window).LocalDestroy();
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 window_manager_internal_.reset( 1240 window_manager_internal_.reset(
1241 new mojo::AssociatedBinding<mojom::WindowManager>(this, 1241 new mojo::AssociatedBinding<mojom::WindowManager>(this,
1242 std::move(internal))); 1242 std::move(internal)));
1243 } 1243 }
1244 1244
1245 void WindowTreeClient::RequestClose(uint32_t window_id) { 1245 void WindowTreeClient::RequestClose(uint32_t window_id) {
1246 Window* window = GetWindowByServerId(window_id); 1246 Window* window = GetWindowByServerId(window_id);
1247 if (!window || !IsRoot(window)) 1247 if (!window || !IsRoot(window))
1248 return; 1248 return;
1249 1249
1250 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), 1250 for (auto& observer : *WindowPrivate(window).observers())
1251 OnRequestClose(window)); 1251 observer.OnRequestClose(window);
1252 } 1252 }
1253 1253
1254 void WindowTreeClient::OnConnect(ClientSpecificId client_id) { 1254 void WindowTreeClient::OnConnect(ClientSpecificId client_id) {
1255 client_id_ = client_id; 1255 client_id_ = client_id;
1256 } 1256 }
1257 1257
1258 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, 1258 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display,
1259 mojom::WindowDataPtr root_data, 1259 mojom::WindowDataPtr root_data,
1260 bool parent_drawn) { 1260 bool parent_drawn) {
1261 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); 1261 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 Window* window, 1431 Window* window,
1432 const gfx::Vector2d& offset, 1432 const gfx::Vector2d& offset,
1433 const gfx::Insets& hit_area) { 1433 const gfx::Insets& hit_area) {
1434 if (window_manager_internal_client_) { 1434 if (window_manager_internal_client_) {
1435 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1435 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1436 server_id(window), offset.x(), offset.y(), hit_area); 1436 server_id(window), offset.x(), offset.y(), hit_area);
1437 } 1437 }
1438 } 1438 }
1439 1439
1440 } // namespace ui 1440 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/window.cc ('k') | services/ui/ws/animation_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698