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

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

Issue 2242283002: Add an adapter layer (WMHelper) between exo and ash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build errors. Created 4 years, 4 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') | components/exo/shell_surface.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 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 "ash/common/display/display_info.h" 7 #include "ash/common/display/display_info.h"
8 #include "ash/common/shell_window_ids.h" 8 #include "ash/common/shell_window_ids.h"
9 #include "ash/display/display_manager.h" 9 #include "ash/display/display_manager.h"
10 #include "ash/shell.h"
11 #include "components/exo/pointer_delegate.h" 10 #include "components/exo/pointer_delegate.h"
12 #include "components/exo/pointer_stylus_delegate.h" 11 #include "components/exo/pointer_stylus_delegate.h"
13 #include "components/exo/surface.h" 12 #include "components/exo/surface.h"
13 #include "components/exo/wm_helper.h"
14 #include "ui/aura/client/cursor_client.h"
14 #include "ui/aura/env.h" 15 #include "ui/aura/env.h"
15 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/display/screen.h"
16 #include "ui/events/event.h" 18 #include "ui/events/event.h"
17 #include "ui/gfx/geometry/vector2d_conversions.h" 19 #include "ui/gfx/geometry/vector2d_conversions.h"
18 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
19 21
20 namespace exo { 22 namespace exo {
21 namespace { 23 namespace {
22 24
23 static constexpr float kLargeCursorScale = 2.8; 25 static constexpr float kLargeCursorScale = 2.8;
24 26
25 // Synthesized events typically lack floating point precision so to avoid 27 // Synthesized events typically lack floating point precision so to avoid
26 // generating mouse event jitter we consider the location of these events 28 // generating mouse event jitter we consider the location of these events
27 // to be the same as |location| if floored values match. 29 // to be the same as |location| if floored values match.
28 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) { 30 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) {
29 if (event->flags() & ui::EF_IS_SYNTHESIZED) 31 if (event->flags() & ui::EF_IS_SYNTHESIZED)
30 return event->location() == gfx::ToFlooredPoint(location); 32 return event->location() == gfx::ToFlooredPoint(location);
31 33
32 return event->location_f() == location; 34 return event->location_f() == location;
33 } 35 }
34 36
35 } // namespace 37 } // namespace
36 38
37 //////////////////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////////////////
38 // Pointer, public: 40 // Pointer, public:
39 41
40 Pointer::Pointer(PointerDelegate* delegate) 42 Pointer::Pointer(PointerDelegate* delegate)
41 : delegate_(delegate), 43 : delegate_(delegate),
42 surface_(nullptr), 44 surface_(nullptr),
43 focus_(nullptr), 45 focus_(nullptr),
44 cursor_scale_(1.0f) { 46 cursor_scale_(1.0f) {
45 ash::Shell* ash_shell = ash::Shell::GetInstance(); 47 auto* helper = WMHelper::GetInstance();
46 ash_shell->AddPreTargetHandler(this); 48 helper->AddPreTargetHandler(this);
47 49 helper->AddCursorObserver(this);
48 wm::CursorManager* cursor_manager = ash_shell->cursor_manager();
49 DCHECK(cursor_manager);
50 cursor_manager->AddObserver(this);
51 } 50 }
52 51
53 Pointer::~Pointer() { 52 Pointer::~Pointer() {
54 delegate_->OnPointerDestroying(this); 53 delegate_->OnPointerDestroying(this);
55 if (stylus_delegate_) 54 if (stylus_delegate_)
56 stylus_delegate_->OnPointerDestroying(this); 55 stylus_delegate_->OnPointerDestroying(this);
57 if (surface_) 56 if (surface_)
58 surface_->RemoveSurfaceObserver(this); 57 surface_->RemoveSurfaceObserver(this);
59 if (focus_) { 58 if (focus_) {
60 focus_->RemoveSurfaceObserver(this); 59 focus_->RemoveSurfaceObserver(this);
61 focus_->UnregisterCursorProvider(this); 60 focus_->UnregisterCursorProvider(this);
62 } 61 }
63 if (widget_) 62 if (widget_)
64 widget_->CloseNow(); 63 widget_->CloseNow();
65 64
66 ash::Shell* ash_shell = ash::Shell::GetInstance(); 65 auto* helper = WMHelper::GetInstance();
67 DCHECK(ash_shell->cursor_manager()); 66 helper->RemoveCursorObserver(this);
68 ash_shell->cursor_manager()->RemoveObserver(this); 67 helper->RemovePreTargetHandler(this);
69 ash_shell->RemovePreTargetHandler(this);
70 } 68 }
71 69
72 void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) { 70 void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) {
73 // Early out if the pointer doesn't have a surface in focus. 71 // Early out if the pointer doesn't have a surface in focus.
74 if (!focus_) 72 if (!focus_)
75 return; 73 return;
76 74
77 // If surface is different than the current pointer surface then remove the 75 // If surface is different than the current pointer surface then remove the
78 // current surface and add the new surface. 76 // current surface and add the new surface.
79 if (surface != surface_) { 77 if (surface != surface_) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 312
315 void Pointer::CreatePointerWidget() { 313 void Pointer::CreatePointerWidget() {
316 DCHECK(!widget_); 314 DCHECK(!widget_);
317 315
318 views::Widget::InitParams params; 316 views::Widget::InitParams params;
319 params.type = views::Widget::InitParams::TYPE_TOOLTIP; 317 params.type = views::Widget::InitParams::TYPE_TOOLTIP;
320 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 318 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
321 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; 319 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
322 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 320 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
323 params.accept_events = false; 321 params.accept_events = false;
324 params.parent = 322 params.parent = WMHelper::GetInstance()->GetContainer(
325 ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), 323 ash::kShellWindowId_MouseCursorContainer);
326 ash::kShellWindowId_MouseCursorContainer);
327 widget_.reset(new views::Widget); 324 widget_.reset(new views::Widget);
328 widget_->Init(params); 325 widget_->Init(params);
329 widget_->GetNativeWindow()->set_owned_by_parent(false); 326 widget_->GetNativeWindow()->set_owned_by_parent(false);
330 widget_->GetNativeWindow()->SetName("ExoPointer"); 327 widget_->GetNativeWindow()->SetName("ExoPointer");
331 } 328 }
332 329
333 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const { 330 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const {
334 Surface* target = 331 Surface* target =
335 Surface::AsSurface(static_cast<aura::Window*>(event->target())); 332 Surface::AsSurface(static_cast<aura::Window*>(event->target()));
336 if (!target) 333 if (!target)
337 return nullptr; 334 return nullptr;
338 335
339 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr; 336 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr;
340 } 337 }
341 338
342 void Pointer::UpdateCursorScale() { 339 void Pointer::UpdateCursorScale() {
343 if (!focus_) 340 if (!focus_)
344 return; 341 return;
345 342
346 // Update cursor scale if the effective UI scale has changed. 343 // Update cursor scale if the effective UI scale has changed.
347 display::Display display = 344 display::Display display =
348 display::Screen::GetScreen()->GetDisplayNearestWindow( 345 display::Screen::GetScreen()->GetDisplayNearestWindow(
349 widget_->GetNativeWindow()); 346 widget_->GetNativeWindow());
350 float ui_scale = ash::Shell::GetInstance() 347 float ui_scale = WMHelper::GetInstance()
351 ->display_manager()
352 ->GetDisplayInfo(display.id()) 348 ->GetDisplayInfo(display.id())
353 .GetEffectiveUIScale(); 349 .GetEffectiveUIScale();
354 350 if (WMHelper::GetInstance()->GetCursorSet() == ui::CURSOR_SET_LARGE)
355 ash::Shell* ash_shell = ash::Shell::GetInstance();
356 if (ash_shell->cursor_manager()->GetCursorSet() == ui::CURSOR_SET_LARGE)
357 ui_scale *= kLargeCursorScale; 351 ui_scale *= kLargeCursorScale;
358 352
359 if (ui_scale != cursor_scale_) { 353 if (ui_scale != cursor_scale_) {
360 gfx::Transform transform; 354 gfx::Transform transform;
361 transform.Scale(ui_scale, ui_scale); 355 transform.Scale(ui_scale, ui_scale);
362 widget_->GetNativeWindow()->SetTransform(transform); 356 widget_->GetNativeWindow()->SetTransform(transform);
363 cursor_scale_ = ui_scale; 357 cursor_scale_ = ui_scale;
364 } 358 }
365 } 359 }
366 360
367 } // namespace exo 361 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/pointer.h ('k') | components/exo/shell_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698