OLD | NEW |
---|---|
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/shell_window_ids.h" | 7 #include "ash/common/shell_window_ids.h" |
8 #include "ash/display/display_info.h" | 8 #include "ash/display/display_info.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" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 //////////////////////////////////////////////////////////////////////////////// | 34 //////////////////////////////////////////////////////////////////////////////// |
35 // Pointer, public: | 35 // Pointer, public: |
36 | 36 |
37 Pointer::Pointer(PointerDelegate* delegate) | 37 Pointer::Pointer(PointerDelegate* delegate) |
38 : delegate_(delegate), | 38 : delegate_(delegate), |
39 surface_(nullptr), | 39 surface_(nullptr), |
40 focus_(nullptr), | 40 focus_(nullptr), |
41 cursor_scale_(1.0f) { | 41 cursor_scale_(1.0f) { |
42 ash::Shell::GetInstance()->AddPreTargetHandler(this); | 42 ash::Shell* ash_shell = ash::Shell::GetInstance(); |
reveman
2016/06/15 17:48:30
nit: not sure this temporary variable is needed bu
| |
43 ash_shell->AddPreTargetHandler(this); | |
44 | |
45 wm::CursorManager* cursor_manager = ash_shell->cursor_manager(); | |
46 DCHECK(cursor_manager); | |
47 cursor_manager->AddObserver(this); | |
48 use_large_cursor_ = (cursor_manager->GetCursorSet() == ui::CURSOR_SET_LARGE); | |
43 } | 49 } |
44 | 50 |
45 Pointer::~Pointer() { | 51 Pointer::~Pointer() { |
46 delegate_->OnPointerDestroying(this); | 52 delegate_->OnPointerDestroying(this); |
47 if (surface_) | 53 if (surface_) |
48 surface_->RemoveSurfaceObserver(this); | 54 surface_->RemoveSurfaceObserver(this); |
49 if (focus_) { | 55 if (focus_) { |
50 focus_->RemoveSurfaceObserver(this); | 56 focus_->RemoveSurfaceObserver(this); |
51 focus_->UnregisterCursorProvider(this); | 57 focus_->UnregisterCursorProvider(this); |
52 } | 58 } |
53 if (widget_) | 59 if (widget_) |
54 widget_->CloseNow(); | 60 widget_->CloseNow(); |
61 | |
62 DCHECK(ash::Shell::GetInstance()->cursor_manager()); | |
63 ash::Shell::GetInstance()->cursor_manager()->RemoveObserver(this); | |
55 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | 64 ash::Shell::GetInstance()->RemovePreTargetHandler(this); |
56 } | 65 } |
57 | 66 |
58 void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) { | 67 void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) { |
59 // Early out if the pointer doesn't have a surface in focus. | 68 // Early out if the pointer doesn't have a surface in focus. |
60 if (!focus_) | 69 if (!focus_) |
61 return; | 70 return; |
62 | 71 |
63 // If surface is different than the current pointer surface then remove the | 72 // If surface is different than the current pointer surface then remove the |
64 // current surface and add the new surface. | 73 // current surface and add the new surface. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 CreatePointerWidget(); | 213 CreatePointerWidget(); |
205 | 214 |
206 // Update cursor location if mouse event caused it to change. | 215 // Update cursor location if mouse event caused it to change. |
207 gfx::Point mouse_location = aura::Env::GetInstance()->last_mouse_location(); | 216 gfx::Point mouse_location = aura::Env::GetInstance()->last_mouse_location(); |
208 if (mouse_location != widget_->GetNativeWindow()->bounds().origin()) { | 217 if (mouse_location != widget_->GetNativeWindow()->bounds().origin()) { |
209 gfx::Rect bounds = widget_->GetNativeWindow()->bounds(); | 218 gfx::Rect bounds = widget_->GetNativeWindow()->bounds(); |
210 bounds.set_origin(mouse_location); | 219 bounds.set_origin(mouse_location); |
211 widget_->GetNativeWindow()->SetBounds(bounds); | 220 widget_->GetNativeWindow()->SetBounds(bounds); |
212 } | 221 } |
213 | 222 |
214 // Update cursor scale if the effective UI scale has changed since last | 223 ResetCursor(); |
215 // mouse event. | |
216 display::Display display = | |
217 display::Screen::GetScreen()->GetDisplayNearestWindow( | |
218 widget_->GetNativeWindow()); | |
219 float ui_scale = ash::Shell::GetInstance() | |
220 ->display_manager() | |
221 ->GetDisplayInfo(display.id()) | |
222 .GetEffectiveUIScale(); | |
223 if (ui_scale != cursor_scale_) { | |
224 gfx::Transform transform; | |
225 transform.Scale(ui_scale, ui_scale); | |
226 widget_->GetNativeWindow()->SetTransform(transform); | |
227 cursor_scale_ = ui_scale; | |
228 } | |
229 } else { | 224 } else { |
230 if (widget_ && widget_->IsVisible()) | 225 if (widget_ && widget_->IsVisible()) |
231 widget_->Hide(); | 226 widget_->Hide(); |
232 } | 227 } |
233 } | 228 } |
234 | 229 |
235 void Pointer::OnScrollEvent(ui::ScrollEvent* event) { | 230 void Pointer::OnScrollEvent(ui::ScrollEvent* event) { |
236 OnMouseEvent(event); | 231 OnMouseEvent(event); |
237 } | 232 } |
238 | 233 |
234 void Pointer::OnCursorSetChanged(ui::CursorSetType cursor_set) { | |
235 use_large_cursor_ = (cursor_set == ui::CURSOR_SET_LARGE); | |
236 ResetCursor(); | |
237 } | |
238 | |
239 //////////////////////////////////////////////////////////////////////////////// | 239 //////////////////////////////////////////////////////////////////////////////// |
240 // SurfaceDelegate overrides: | 240 // SurfaceDelegate overrides: |
241 | 241 |
242 void Pointer::OnSurfaceCommit() { | 242 void Pointer::OnSurfaceCommit() { |
243 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | 243 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
244 surface_->CommitSurfaceHierarchy(); | 244 surface_->CommitSurfaceHierarchy(); |
245 surface_->window()->SetBounds( | 245 surface_->window()->SetBounds( |
246 gfx::Rect(gfx::Point() - hotspot_.OffsetFromOrigin(), | 246 gfx::Rect(gfx::Point() - hotspot_.OffsetFromOrigin(), |
247 surface_->window()->layer()->size())); | 247 surface_->window()->layer()->size())); |
248 } | 248 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 | 287 |
288 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const { | 288 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const { |
289 Surface* target = | 289 Surface* target = |
290 Surface::AsSurface(static_cast<aura::Window*>(event->target())); | 290 Surface::AsSurface(static_cast<aura::Window*>(event->target())); |
291 if (!target) | 291 if (!target) |
292 return nullptr; | 292 return nullptr; |
293 | 293 |
294 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr; | 294 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr; |
295 } | 295 } |
296 | 296 |
297 void Pointer::ResetCursor() { | |
298 if (!focus_) | |
299 return; | |
300 | |
301 // Update cursor scale if the effective UI scale has changed. | |
302 display::Display display = | |
303 display::Screen::GetScreen()->GetDisplayNearestWindow( | |
304 widget_->GetNativeWindow()); | |
305 float ui_scale = ash::Shell::GetInstance() | |
306 ->display_manager() | |
307 ->GetDisplayInfo(display.id()) | |
308 .GetEffectiveUIScale(); | |
309 | |
310 // TODO(yoshiki): Use large cursor asset instead of scaling. | |
reveman
2016/06/15 17:48:30
nit: Remove this TODO as we should still apply the
| |
311 if (use_large_cursor_) | |
312 ui_scale *= 2; | |
313 | |
314 if (ui_scale != cursor_scale_) { | |
315 gfx::Transform transform; | |
316 transform.Scale(ui_scale, ui_scale); | |
317 widget_->GetNativeWindow()->SetTransform(transform); | |
318 cursor_scale_ = ui_scale; | |
319 } | |
320 } | |
321 | |
297 } // namespace exo | 322 } // namespace exo |
OLD | NEW |