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

Side by Side Diff: components/exo/pointer.cc

Issue 2934953002: exo: Reparent pointer surface (Closed)
Patch Set: Add comment Created 3 years, 6 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 | « components/exo/pointer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/exo/pointer.h" 5 #include "components/exo/pointer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "cc/output/copy_output_request.h" 10 #include "cc/output/copy_output_request.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // Pointer, public: 71 // Pointer, public:
72 72
73 Pointer::Pointer(PointerDelegate* delegate) 73 Pointer::Pointer(PointerDelegate* delegate)
74 : delegate_(delegate), 74 : delegate_(delegate),
75 cursor_(ui::CursorType::kNull), 75 cursor_(ui::CursorType::kNull),
76 cursor_capture_source_id_(base::UnguessableToken::Create()), 76 cursor_capture_source_id_(base::UnguessableToken::Create()),
77 cursor_capture_weak_ptr_factory_(this) { 77 cursor_capture_weak_ptr_factory_(this) {
78 auto* helper = WMHelper::GetInstance(); 78 auto* helper = WMHelper::GetInstance();
79 helper->AddPreTargetHandler(this); 79 helper->AddPreTargetHandler(this);
80 helper->AddCursorObserver(this); 80 helper->AddCursorObserver(this);
81 helper->AddDisplayConfigurationObserver(this);
81 } 82 }
82 83
83 Pointer::~Pointer() { 84 Pointer::~Pointer() {
84 delegate_->OnPointerDestroying(this); 85 delegate_->OnPointerDestroying(this);
85 if (surface_) 86 if (surface_)
86 surface_->RemoveSurfaceObserver(this); 87 surface_->RemoveSurfaceObserver(this);
87 if (focus_) { 88 if (focus_) {
88 focus_->RemoveSurfaceObserver(this); 89 focus_->RemoveSurfaceObserver(this);
89 focus_->UnregisterCursorProvider(this); 90 focus_->UnregisterCursorProvider(this);
90 } 91 }
91 auto* helper = WMHelper::GetInstance(); 92 auto* helper = WMHelper::GetInstance();
93 helper->RemoveDisplayConfigurationObserver(this);
92 helper->RemoveCursorObserver(this); 94 helper->RemoveCursorObserver(this);
93 helper->RemovePreTargetHandler(this); 95 helper->RemovePreTargetHandler(this);
94 } 96 }
95 97
96 void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) { 98 void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) {
97 // Early out if the pointer doesn't have a surface in focus. 99 // Early out if the pointer doesn't have a surface in focus.
98 if (!focus_) 100 if (!focus_)
99 return; 101 return;
100 102
101 // This is used to avoid unnecessary cursor changes. 103 // This is used to avoid unnecessary cursor changes.
102 bool cursor_changed = false; 104 bool cursor_changed = false;
103 105
104 // If surface is different than the current pointer surface then remove the 106 // If surface is different than the current pointer surface then remove the
105 // current surface and add the new surface. 107 // current surface and add the new surface.
106 if (surface != surface_) { 108 if (surface != surface_) {
107 if (surface && surface->HasSurfaceDelegate()) { 109 if (surface && surface->HasSurfaceDelegate()) {
108 DLOG(ERROR) << "Surface has already been assigned a role"; 110 DLOG(ERROR) << "Surface has already been assigned a role";
109 return; 111 return;
110 } 112 }
111 if (surface_) { 113 UpdatePointerSurface(surface);
112 surface_->window()->SetTransform(gfx::Transform());
113 if (surface_->window()->parent())
114 surface_->window()->parent()->RemoveChild(surface_->window());
115 surface_->SetSurfaceDelegate(nullptr);
116 surface_->RemoveSurfaceObserver(this);
117 }
118 surface_ = surface;
119 if (surface_) {
120 surface_->SetSurfaceDelegate(this);
121 surface_->AddSurfaceObserver(this);
122 // Note: Surface window needs to be added to the tree so we can take a
123 // snapshot. Where in the tree is not important but we might as well use
124 // the cursor container.
125 WMHelper::GetInstance()
126 ->GetPrimaryDisplayContainer(ash::kShellWindowId_MouseCursorContainer)
127 ->AddChild(surface_->window());
128 }
129 cursor_changed = true; 114 cursor_changed = true;
130 } 115 }
131 116
132 if (hotspot != hotspot_) 117 if (hotspot != hotspot_)
133 cursor_changed = true; 118 cursor_changed = true;
134 119
135 // Early out if cursor did not change. 120 // Early out if cursor did not change.
136 if (!cursor_changed) { 121 if (!cursor_changed) {
137 // Cursor scale or rotation may have changed. 122 // Cursor scale or rotation may have changed.
138 UpdateCursor(); 123 UpdateCursor();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 if (focus_) 259 if (focus_)
275 UpdateCursor(); 260 UpdateCursor();
276 } 261 }
277 262
278 void Pointer::OnCursorDisplayChanged(const display::Display& display) { 263 void Pointer::OnCursorDisplayChanged(const display::Display& display) {
279 if (focus_) 264 if (focus_)
280 UpdateCursor(); 265 UpdateCursor();
281 } 266 }
282 267
283 //////////////////////////////////////////////////////////////////////////////// 268 ////////////////////////////////////////////////////////////////////////////////
269 // WMHelper::DisplayConfigurationObserver overrides:
270
271 void Pointer::OnDisplayConfigurationChanged() {
272 UpdatePointerSurface(surface_);
273 }
274
275 ////////////////////////////////////////////////////////////////////////////////
284 // SurfaceDelegate overrides: 276 // SurfaceDelegate overrides:
285 277
286 void Pointer::OnSurfaceCommit() { 278 void Pointer::OnSurfaceCommit() {
287 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); 279 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces();
288 surface_->CommitSurfaceHierarchy(); 280 surface_->CommitSurfaceHierarchy();
289 281
290 // Capture new cursor to reflect result of commit. 282 // Capture new cursor to reflect result of commit.
291 if (focus_) 283 if (focus_)
292 CaptureCursor(hotspot_); 284 CaptureCursor(hotspot_);
293 } 285 }
(...skipping 20 matching lines...) Expand all
314 306
315 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const { 307 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const {
316 Surface* target = 308 Surface* target =
317 Surface::AsSurface(static_cast<aura::Window*>(event->target())); 309 Surface::AsSurface(static_cast<aura::Window*>(event->target()));
318 if (!target) 310 if (!target)
319 return nullptr; 311 return nullptr;
320 312
321 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr; 313 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr;
322 } 314 }
323 315
316 void Pointer::UpdatePointerSurface(Surface* surface) {
317 if (surface_) {
318 surface_->window()->SetTransform(gfx::Transform());
319 if (surface_->window()->parent())
320 surface_->window()->parent()->RemoveChild(surface_->window());
321 surface_->SetSurfaceDelegate(nullptr);
322 surface_->RemoveSurfaceObserver(this);
323 }
324 surface_ = surface;
325 if (surface_) {
326 surface_->SetSurfaceDelegate(this);
327 surface_->AddSurfaceObserver(this);
328 // Note: Surface window needs to be added to the tree so we can take a
329 // snapshot. Where in the tree is not important but we might as well use
330 // the cursor container.
331 WMHelper::GetInstance()
332 ->GetPrimaryDisplayContainer(ash::kShellWindowId_MouseCursorContainer)
333 ->AddChild(surface_->window());
334 }
335 }
336
324 void Pointer::CaptureCursor(const gfx::Point& hotspot) { 337 void Pointer::CaptureCursor(const gfx::Point& hotspot) {
325 DCHECK(surface_); 338 DCHECK(surface_);
326 DCHECK(focus_); 339 DCHECK(focus_);
327 340
328 // Surface size is in DIPs, while layer size is in pseudo-DIP units that 341 // Surface size is in DIPs, while layer size is in pseudo-DIP units that
329 // depend on the DSF of the display mode. Scale the layer to capture the 342 // depend on the DSF of the display mode. Scale the layer to capture the
330 // surface at a constant pixel size, regardless of the primary display's 343 // surface at a constant pixel size, regardless of the primary display's
331 // UI scale and display mode DSF. 344 // UI scale and display mode DSF.
332 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); 345 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
333 auto* helper = WMHelper::GetInstance(); 346 auto* helper = WMHelper::GetInstance();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 if (!root_window) 417 if (!root_window)
405 return; 418 return;
406 419
407 aura::client::CursorClient* cursor_client = 420 aura::client::CursorClient* cursor_client =
408 aura::client::GetCursorClient(root_window); 421 aura::client::GetCursorClient(root_window);
409 if (cursor_client) 422 if (cursor_client)
410 cursor_client->SetCursor(cursor_); 423 cursor_client->SetCursor(cursor_);
411 } 424 }
412 425
413 } // namespace exo 426 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/pointer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698