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

Side by Side Diff: ui/aura/mus/window_tree_client.cc

Issue 2536943005: Adds couple of functions to WindowManagerDelegate: (Closed)
Patch Set: comment Created 4 years 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 | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/test/aura_test_base.h » ('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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after 138 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after
139 // https://codereview.chromium.org/2361283002/ is landed. 139 // https://codereview.chromium.org/2361283002/ is landed.
140 return display::Screen::GetScreen() 140 return display::Screen::GetScreen()
141 ->GetDisplayNearestWindow(window) 141 ->GetDisplayNearestWindow(window)
142 .device_scale_factor(); 142 .device_scale_factor();
143 } 143 }
144 144
145 } // namespace 145 } // namespace
146 146
147 WindowTreeClient::WindowTreeClient( 147 WindowTreeClient::WindowTreeClient(
148 service_manager::Connector* connector,
148 WindowTreeClientDelegate* delegate, 149 WindowTreeClientDelegate* delegate,
149 WindowManagerDelegate* window_manager_delegate, 150 WindowManagerDelegate* window_manager_delegate,
150 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) 151 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request)
151 : client_id_(0), 152 : connector_(connector),
153 client_id_(0),
152 next_window_id_(1), 154 next_window_id_(1),
153 next_change_id_(1), 155 next_change_id_(1),
154 delegate_(delegate), 156 delegate_(delegate),
155 window_manager_delegate_(window_manager_delegate), 157 window_manager_delegate_(window_manager_delegate),
156 binding_(this), 158 binding_(this),
157 tree_(nullptr), 159 tree_(nullptr),
158 in_destructor_(false), 160 in_destructor_(false),
159 weak_factory_(this) { 161 weak_factory_(this) {
160 // Allow for a null request in tests. 162 // Allow for a null request in tests.
161 if (request.is_pending()) 163 if (request.is_pending())
(...skipping 30 matching lines...) Expand all
192 delete tracker.windows().front(); 194 delete tracker.windows().front();
193 195
194 for (WindowTreeClientObserver& observer : observers_) 196 for (WindowTreeClientObserver& observer : observers_)
195 observer.OnDidDestroyClient(this); 197 observer.OnDidDestroyClient(this);
196 198
197 capture_synchronizer_.reset(); 199 capture_synchronizer_.reset();
198 200
199 client::GetTransientWindowClient()->RemoveObserver(this); 201 client::GetTransientWindowClient()->RemoveObserver(this);
200 } 202 }
201 203
202 void WindowTreeClient::ConnectViaWindowTreeFactory( 204 void WindowTreeClient::ConnectViaWindowTreeFactory() {
203 service_manager::Connector* connector) {
204 // The client id doesn't really matter, we use 101 purely for debugging. 205 // The client id doesn't really matter, we use 101 purely for debugging.
205 client_id_ = 101; 206 client_id_ = 101;
206 207
207 ui::mojom::WindowTreeFactoryPtr factory; 208 ui::mojom::WindowTreeFactoryPtr factory;
208 connector->ConnectToInterface(ui::mojom::kServiceName, &factory); 209 connector_->ConnectToInterface(ui::mojom::kServiceName, &factory);
209 ui::mojom::WindowTreePtr window_tree; 210 ui::mojom::WindowTreePtr window_tree;
210 factory->CreateWindowTree(GetProxy(&window_tree), 211 factory->CreateWindowTree(GetProxy(&window_tree),
211 binding_.CreateInterfacePtrAndBind()); 212 binding_.CreateInterfacePtrAndBind());
212 SetWindowTree(std::move(window_tree)); 213 SetWindowTree(std::move(window_tree));
213 } 214 }
214 215
215 void WindowTreeClient::ConnectAsWindowManager( 216 void WindowTreeClient::ConnectAsWindowManager() {
216 service_manager::Connector* connector) {
217 DCHECK(window_manager_delegate_); 217 DCHECK(window_manager_delegate_);
218 218
219 ui::mojom::WindowManagerWindowTreeFactoryPtr factory; 219 ui::mojom::WindowManagerWindowTreeFactoryPtr factory;
220 connector->ConnectToInterface(ui::mojom::kServiceName, &factory); 220 connector_->ConnectToInterface(ui::mojom::kServiceName, &factory);
221 ui::mojom::WindowTreePtr window_tree; 221 ui::mojom::WindowTreePtr window_tree;
222 factory->CreateWindowTree(GetProxy(&window_tree), 222 factory->CreateWindowTree(GetProxy(&window_tree),
223 binding_.CreateInterfacePtrAndBind()); 223 binding_.CreateInterfacePtrAndBind());
224 SetWindowTree(std::move(window_tree)); 224 SetWindowTree(std::move(window_tree));
225 } 225 }
226 226
227 client::CaptureClient* WindowTreeClient::GetCaptureClient() { 227 client::CaptureClient* WindowTreeClient::GetCaptureClient() {
228 return delegate_->GetCaptureClient(); 228 return delegate_->GetCaptureClient();
229 } 229 }
230 230
(...skipping 28 matching lines...) Expand all
259 259
260 void WindowTreeClient::Embed( 260 void WindowTreeClient::Embed(
261 Id window_id, 261 Id window_id,
262 ui::mojom::WindowTreeClientPtr client, 262 ui::mojom::WindowTreeClientPtr client,
263 uint32_t flags, 263 uint32_t flags,
264 const ui::mojom::WindowTree::EmbedCallback& callback) { 264 const ui::mojom::WindowTree::EmbedCallback& callback) {
265 DCHECK(tree_); 265 DCHECK(tree_);
266 tree_->Embed(window_id, std::move(client), flags, callback); 266 tree_->Embed(window_id, std::move(client), flags, callback);
267 } 267 }
268 268
269 void WindowTreeClient::RequestClose(Window* window) {
270 DCHECK(window);
271 if (window_manager_internal_client_)
272 window_manager_internal_client_->WmRequestClose(
273 WindowMus::Get(window)->server_id());
274 }
275
276 void WindowTreeClient::AttachCompositorFrameSink( 269 void WindowTreeClient::AttachCompositorFrameSink(
277 Id window_id, 270 Id window_id,
278 ui::mojom::CompositorFrameSinkType type, 271 ui::mojom::CompositorFrameSinkType type,
279 cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink, 272 cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink,
280 cc::mojom::MojoCompositorFrameSinkClientPtr client) { 273 cc::mojom::MojoCompositorFrameSinkClientPtr client) {
281 DCHECK(tree_); 274 DCHECK(tree_);
282 tree_->AttachCompositorFrameSink( 275 tree_->AttachCompositorFrameSink(
283 window_id, type, std::move(compositor_frame_sink), std::move(client)); 276 window_id, type, std::move(compositor_frame_sink), std::move(client));
284 } 277 }
285 278
286 void WindowTreeClient::RegisterWindowMus(WindowMus* window) { 279 void WindowTreeClient::RegisterWindowMus(WindowMus* window) {
287 DCHECK(windows_.find(window->server_id()) == windows_.end()); 280 DCHECK(windows_.find(window->server_id()) == windows_.end());
288 windows_[window->server_id()] = window; 281 windows_[window->server_id()] = window;
289 } 282 }
290 283
291 WindowMus* WindowTreeClient::GetWindowByServerId(Id id) { 284 WindowMus* WindowTreeClient::GetWindowByServerId(Id id) {
292 IdToWindowMap::const_iterator it = windows_.find(id); 285 IdToWindowMap::const_iterator it = windows_.find(id);
293 return it != windows_.end() ? it->second : nullptr; 286 return it != windows_.end() ? it->second : nullptr;
294 } 287 }
295 288
296 bool WindowTreeClient::WasCreatedByThisClient(const WindowMus* window) const {
297 // Windows created via CreateTopLevelWindow() are not owned by us, but have
298 // our client id. const_cast is required by set.
299 return HiWord(window->server_id()) == client_id_ &&
300 roots_.count(const_cast<WindowMus*>(window)) == 0;
301 }
302
303 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( 289 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching(
304 const InFlightChange& change) { 290 const InFlightChange& change) {
305 for (const auto& pair : in_flight_map_) { 291 for (const auto& pair : in_flight_map_) {
306 if (pair.second->window() == change.window() && 292 if (pair.second->window() == change.window() &&
307 pair.second->change_type() == change.change_type() && 293 pair.second->change_type() == change.change_type() &&
308 pair.second->Matches(change)) { 294 pair.second->Matches(change)) {
309 return pair.second.get(); 295 return pair.second.get();
310 } 296 }
311 } 297 }
312 return nullptr; 298 return nullptr;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 455
470 delegate_->OnEmbed(std::move(window_tree_host)); 456 delegate_->OnEmbed(std::move(window_tree_host));
471 } 457 }
472 458
473 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( 459 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl(
474 const display::Display& display, 460 const display::Display& display,
475 ui::mojom::WindowDataPtr root_data, 461 ui::mojom::WindowDataPtr root_data,
476 bool parent_drawn) { 462 bool parent_drawn) {
477 DCHECK(window_manager_delegate_); 463 DCHECK(window_manager_delegate_);
478 464
465 window_manager_delegate_->OnWmWillCreateDisplay(display);
466
479 std::unique_ptr<WindowTreeHostMus> window_tree_host = 467 std::unique_ptr<WindowTreeHostMus> window_tree_host =
480 CreateWindowTreeHost(WindowMusType::DISPLAY, root_data, display.id()); 468 CreateWindowTreeHost(WindowMusType::DISPLAY, root_data, display.id());
481 469
482 WindowTreeHost* window_tree_host_ptr = window_tree_host.get(); 470 WindowTreeHost* window_tree_host_ptr = window_tree_host.get();
483 window_manager_delegate_->OnWmNewDisplay(std::move(window_tree_host), 471 window_manager_delegate_->OnWmNewDisplay(std::move(window_tree_host),
484 display); 472 display);
485 return window_tree_host_ptr; 473 return window_tree_host_ptr;
486 } 474 }
487 475
488 std::unique_ptr<EventResultCallback> 476 std::unique_ptr<EventResultCallback>
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 } 714 }
727 } 715 }
728 716
729 std::set<Window*> WindowTreeClient::GetRoots() { 717 std::set<Window*> WindowTreeClient::GetRoots() {
730 std::set<Window*> roots; 718 std::set<Window*> roots;
731 for (WindowMus* window : roots_) 719 for (WindowMus* window : roots_)
732 roots.insert(window->GetWindow()); 720 roots.insert(window->GetWindow());
733 return roots; 721 return roots;
734 } 722 }
735 723
724 bool WindowTreeClient::WasCreatedByThisClient(const WindowMus* window) const {
725 // Windows created via CreateTopLevelWindow() are not owned by us, but have
726 // our client id. const_cast is required by set.
727 return HiWord(window->server_id()) == client_id_ &&
728 roots_.count(const_cast<WindowMus*>(window)) == 0;
729 }
730
736 gfx::Point WindowTreeClient::GetCursorScreenPoint() { 731 gfx::Point WindowTreeClient::GetCursorScreenPoint() {
737 // We raced initialization. Return (0, 0). 732 // We raced initialization. Return (0, 0).
738 if (!cursor_location_memory()) 733 if (!cursor_location_memory())
739 return gfx::Point(); 734 return gfx::Point();
740 735
741 base::subtle::Atomic32 location = 736 base::subtle::Atomic32 location =
742 base::subtle::NoBarrier_Load(cursor_location_memory()); 737 base::subtle::NoBarrier_Load(cursor_location_memory());
743 return gfx::Point(static_cast<int16_t>(location >> 16), 738 return gfx::Point(static_cast<int16_t>(location >> 16),
744 static_cast<int16_t>(location & 0xFFFF)); 739 static_cast<int16_t>(location & 0xFFFF));
745 } 740 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 if (ApplyServerChangeToExistingInFlightChange(new_change)) 920 if (ApplyServerChangeToExistingInFlightChange(new_change))
926 return; 921 return;
927 922
928 SetWindowBoundsFromServer(window, new_bounds); 923 SetWindowBoundsFromServer(window, new_bounds);
929 } 924 }
930 925
931 void WindowTreeClient::OnClientAreaChanged( 926 void WindowTreeClient::OnClientAreaChanged(
932 uint32_t window_id, 927 uint32_t window_id,
933 const gfx::Insets& new_client_area, 928 const gfx::Insets& new_client_area,
934 const std::vector<gfx::Rect>& new_additional_client_areas) { 929 const std::vector<gfx::Rect>& new_additional_client_areas) {
935 // TODO: client area. 930 WindowMus* window = GetWindowByServerId(window_id);
936 // TODO(riajiang): Convert from pixel to DIP. (http://crbug.com/600815) 931 if (!window)
937 /* 932 return;
938 Window* window = GetWindowByServerId(window_id); 933
939 if (window) { 934 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow());
940 WindowPrivate(window).LocalSetClientArea( 935 std::vector<gfx::Rect> new_additional_client_areas_in_dip;
941 new_client_area, 936 for (const gfx::Rect& area : new_additional_client_areas) {
942 new_additional_client_areas); 937 new_additional_client_areas_in_dip.push_back(
938 gfx::ConvertRectToDIP(device_scale_factor, area));
943 } 939 }
944 */ 940 window_manager_delegate_->OnWmSetClientArea(
941 window->GetWindow(),
942 gfx::ConvertInsetsToDIP(device_scale_factor, new_client_area),
943 new_additional_client_areas_in_dip);
945 } 944 }
946 945
947 void WindowTreeClient::OnTransientWindowAdded(uint32_t window_id, 946 void WindowTreeClient::OnTransientWindowAdded(uint32_t window_id,
948 uint32_t transient_window_id) { 947 uint32_t transient_window_id) {
949 WindowMus* window = GetWindowByServerId(window_id); 948 WindowMus* window = GetWindowByServerId(window_id);
950 WindowMus* transient_window = GetWindowByServerId(transient_window_id); 949 WindowMus* transient_window = GetWindowByServerId(transient_window_id);
951 // window or transient_window or both may be null if a local delete occurs 950 // window or transient_window or both may be null if a local delete occurs
952 // with an in flight add from the server. 951 // with an in flight add from the server.
953 if (window && transient_window) 952 if (window && transient_window)
954 window->AddTransientChildFromServer(transient_window); 953 window->AddTransientChildFromServer(transient_window);
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 const gfx::Insets& hit_area) { 1462 const gfx::Insets& hit_area) {
1464 if (window_manager_internal_client_) { 1463 if (window_manager_internal_client_) {
1465 // TODO(riajiang): Figure out if |offset| needs to be converted. 1464 // TODO(riajiang): Figure out if |offset| needs to be converted.
1466 // (http://crbugs.com/646932) 1465 // (http://crbugs.com/646932)
1467 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1466 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1468 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), 1467 WindowMus::Get(window)->server_id(), offset.x(), offset.y(),
1469 gfx::ConvertInsetsToDIP(ScaleFactorForDisplay(window), hit_area)); 1468 gfx::ConvertInsetsToDIP(ScaleFactorForDisplay(window), hit_area));
1470 } 1469 }
1471 } 1470 }
1472 1471
1472 void WindowTreeClient::RequestClose(Window* window) {
1473 DCHECK(window);
1474 if (window_manager_internal_client_)
1475 window_manager_internal_client_->WmRequestClose(
1476 WindowMus::Get(window)->server_id());
1477 }
1478
1473 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( 1479 void WindowTreeClient::OnWindowTreeHostBoundsWillChange(
1474 WindowTreeHostMus* window_tree_host, 1480 WindowTreeHostMus* window_tree_host,
1475 const gfx::Rect& bounds) { 1481 const gfx::Rect& bounds) {
1476 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), 1482 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()),
1477 window_tree_host->GetBoundsInPixels(), bounds); 1483 window_tree_host->GetBoundsInPixels(), bounds);
1478 } 1484 }
1479 1485
1480 void WindowTreeClient::OnWindowTreeHostClientAreaWillChange( 1486 void WindowTreeClient::OnWindowTreeHostClientAreaWillChange(
1481 WindowTreeHostMus* window_tree_host, 1487 WindowTreeHostMus* window_tree_host,
1482 const gfx::Insets& client_area, 1488 const gfx::Insets& client_area,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( 1589 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>(
1584 this, capture_synchronizer_.get(), window)); 1590 this, capture_synchronizer_.get(), window));
1585 } 1591 }
1586 1592
1587 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { 1593 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
1588 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( 1594 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>(
1589 this, focus_synchronizer_.get(), window)); 1595 this, focus_synchronizer_.get(), window));
1590 } 1596 }
1591 1597
1592 } // namespace aura 1598 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/test/aura_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698