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

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

Issue 2071553002: Initial support of large mouse cursor on Exosphere (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add dependency to wm::test_support from ash::unittests Created 4 years, 5 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') | ui/aura/client/cursor_client_observer.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" 10 #include "ash/shell.h"
11 #include "components/exo/pointer_delegate.h" 11 #include "components/exo/pointer_delegate.h"
12 #include "components/exo/surface.h" 12 #include "components/exo/surface.h"
13 #include "ui/aura/env.h" 13 #include "ui/aura/env.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/events/event.h" 15 #include "ui/events/event.h"
16 #include "ui/gfx/geometry/vector2d_conversions.h" 16 #include "ui/gfx/geometry/vector2d_conversions.h"
17 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
18 18
19 namespace exo { 19 namespace exo {
20 namespace { 20 namespace {
21 21
22 static constexpr float kLargeCursorScale = 2.8;
23
22 // Synthesized events typically lack floating point precision so to avoid 24 // Synthesized events typically lack floating point precision so to avoid
23 // generating mouse event jitter we consider the location of these events 25 // generating mouse event jitter we consider the location of these events
24 // to be the same as |location| if floored values match. 26 // to be the same as |location| if floored values match.
25 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) { 27 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) {
26 if (event->flags() & ui::EF_IS_SYNTHESIZED) 28 if (event->flags() & ui::EF_IS_SYNTHESIZED)
27 return event->location() == gfx::ToFlooredPoint(location); 29 return event->location() == gfx::ToFlooredPoint(location);
28 30
29 return event->location_f() == location; 31 return event->location_f() == location;
30 } 32 }
31 33
32 } // namespace 34 } // namespace
33 35
34 //////////////////////////////////////////////////////////////////////////////// 36 ////////////////////////////////////////////////////////////////////////////////
35 // Pointer, public: 37 // Pointer, public:
36 38
37 Pointer::Pointer(PointerDelegate* delegate) : delegate_(delegate) { 39 Pointer::Pointer(PointerDelegate* delegate)
38 ash::Shell::GetInstance()->AddPreTargetHandler(this); 40 : delegate_(delegate),
41 surface_(nullptr),
42 focus_(nullptr),
43 cursor_scale_(1.0f) {
44 ash::Shell* ash_shell = ash::Shell::GetInstance();
45 ash_shell->AddPreTargetHandler(this);
46
47 wm::CursorManager* cursor_manager = ash_shell->cursor_manager();
48 DCHECK(cursor_manager);
49 cursor_manager->AddObserver(this);
39 } 50 }
40 51
41 Pointer::~Pointer() { 52 Pointer::~Pointer() {
42 delegate_->OnPointerDestroying(this); 53 delegate_->OnPointerDestroying(this);
43 if (surface_) 54 if (surface_)
44 surface_->RemoveSurfaceObserver(this); 55 surface_->RemoveSurfaceObserver(this);
45 if (focus_) { 56 if (focus_) {
46 focus_->RemoveSurfaceObserver(this); 57 focus_->RemoveSurfaceObserver(this);
47 focus_->UnregisterCursorProvider(this); 58 focus_->UnregisterCursorProvider(this);
48 } 59 }
49 if (widget_) 60 if (widget_)
50 widget_->CloseNow(); 61 widget_->CloseNow();
51 ash::Shell::GetInstance()->RemovePreTargetHandler(this); 62
63 ash::Shell* ash_shell = ash::Shell::GetInstance();
64 DCHECK(ash_shell->cursor_manager());
65 ash_shell->cursor_manager()->RemoveObserver(this);
66 ash_shell->RemovePreTargetHandler(this);
52 } 67 }
53 68
54 void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) { 69 void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) {
55 // Early out if the pointer doesn't have a surface in focus. 70 // Early out if the pointer doesn't have a surface in focus.
56 if (!focus_) 71 if (!focus_)
57 return; 72 return;
58 73
59 // If surface is different than the current pointer surface then remove the 74 // If surface is different than the current pointer surface then remove the
60 // current surface and add the new surface. 75 // current surface and add the new surface.
61 if (surface != surface_) { 76 if (surface != surface_) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 CreatePointerWidget(); 215 CreatePointerWidget();
201 216
202 // Update cursor location if mouse event caused it to change. 217 // Update cursor location if mouse event caused it to change.
203 gfx::Point mouse_location = aura::Env::GetInstance()->last_mouse_location(); 218 gfx::Point mouse_location = aura::Env::GetInstance()->last_mouse_location();
204 if (mouse_location != widget_->GetNativeWindow()->bounds().origin()) { 219 if (mouse_location != widget_->GetNativeWindow()->bounds().origin()) {
205 gfx::Rect bounds = widget_->GetNativeWindow()->bounds(); 220 gfx::Rect bounds = widget_->GetNativeWindow()->bounds();
206 bounds.set_origin(mouse_location); 221 bounds.set_origin(mouse_location);
207 widget_->GetNativeWindow()->SetBounds(bounds); 222 widget_->GetNativeWindow()->SetBounds(bounds);
208 } 223 }
209 224
210 // Update cursor scale if the effective UI scale has changed since last 225 UpdateCursorScale();
211 // mouse event.
212 display::Display display =
213 display::Screen::GetScreen()->GetDisplayNearestWindow(
214 widget_->GetNativeWindow());
215 float ui_scale = ash::Shell::GetInstance()
216 ->display_manager()
217 ->GetDisplayInfo(display.id())
218 .GetEffectiveUIScale();
219 if (ui_scale != cursor_scale_) {
220 gfx::Transform transform;
221 transform.Scale(ui_scale, ui_scale);
222 widget_->GetNativeWindow()->SetTransform(transform);
223 cursor_scale_ = ui_scale;
224 }
225 } else { 226 } else {
226 if (widget_ && widget_->IsVisible()) 227 if (widget_ && widget_->IsVisible())
227 widget_->Hide(); 228 widget_->Hide();
228 } 229 }
229 } 230 }
230 231
231 void Pointer::OnScrollEvent(ui::ScrollEvent* event) { 232 void Pointer::OnScrollEvent(ui::ScrollEvent* event) {
232 OnMouseEvent(event); 233 OnMouseEvent(event);
233 } 234 }
234 235
236 void Pointer::OnCursorSetChanged(ui::CursorSetType cursor_set) {
237 UpdateCursorScale();
238 }
239
235 //////////////////////////////////////////////////////////////////////////////// 240 ////////////////////////////////////////////////////////////////////////////////
236 // SurfaceDelegate overrides: 241 // SurfaceDelegate overrides:
237 242
238 void Pointer::OnSurfaceCommit() { 243 void Pointer::OnSurfaceCommit() {
239 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); 244 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces();
240 surface_->CommitSurfaceHierarchy(); 245 surface_->CommitSurfaceHierarchy();
241 surface_->window()->SetBounds( 246 surface_->window()->SetBounds(
242 gfx::Rect(gfx::Point() - hotspot_.OffsetFromOrigin(), 247 gfx::Rect(gfx::Point() - hotspot_.OffsetFromOrigin(),
243 surface_->window()->layer()->size())); 248 surface_->window()->layer()->size()));
244 } 249 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 288
284 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const { 289 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const {
285 Surface* target = 290 Surface* target =
286 Surface::AsSurface(static_cast<aura::Window*>(event->target())); 291 Surface::AsSurface(static_cast<aura::Window*>(event->target()));
287 if (!target) 292 if (!target)
288 return nullptr; 293 return nullptr;
289 294
290 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr; 295 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr;
291 } 296 }
292 297
298 void Pointer::UpdateCursorScale() {
299 if (!focus_)
300 return;
301
302 // Update cursor scale if the effective UI scale has changed.
303 display::Display display =
304 display::Screen::GetScreen()->GetDisplayNearestWindow(
305 widget_->GetNativeWindow());
306 float ui_scale = ash::Shell::GetInstance()
307 ->display_manager()
308 ->GetDisplayInfo(display.id())
309 .GetEffectiveUIScale();
310
311 ash::Shell* ash_shell = ash::Shell::GetInstance();
312 if (ash_shell->cursor_manager()->GetCursorSet() == ui::CURSOR_SET_LARGE)
313 ui_scale *= kLargeCursorScale;
314
315 if (ui_scale != cursor_scale_) {
316 gfx::Transform transform;
317 transform.Scale(ui_scale, ui_scale);
318 widget_->GetNativeWindow()->SetTransform(transform);
319 cursor_scale_ = ui_scale;
320 }
321 }
322
293 } // namespace exo 323 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/pointer.h ('k') | ui/aura/client/cursor_client_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698