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/display/display_info.h" | 7 #include "ash/display/display_info.h" |
8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
(...skipping 28 matching lines...) Expand all Loading... |
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::GetInstance()->AddPreTargetHandler(this); |
43 } | 43 } |
44 | 44 |
45 Pointer::~Pointer() { | 45 Pointer::~Pointer() { |
46 delegate_->OnPointerDestroying(this); | 46 delegate_->OnPointerDestroying(this); |
47 if (surface_) | 47 if (surface_) |
48 surface_->RemoveSurfaceObserver(this); | 48 surface_->RemoveSurfaceObserver(this); |
49 if (focus_) | 49 if (focus_) { |
50 focus_->RemoveSurfaceObserver(this); | 50 focus_->RemoveSurfaceObserver(this); |
| 51 focus_->UnregisterCursorProvider(this); |
| 52 } |
51 if (widget_) | 53 if (widget_) |
52 widget_->CloseNow(); | 54 widget_->CloseNow(); |
53 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | 55 ash::Shell::GetInstance()->RemovePreTargetHandler(this); |
54 } | 56 } |
55 | 57 |
56 void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) { | 58 void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) { |
57 // Early out if the pointer doesn't have a surface in focus. | 59 // Early out if the pointer doesn't have a surface in focus. |
58 if (!focus_) | 60 if (!focus_) |
59 return; | 61 return; |
60 | 62 |
(...skipping 18 matching lines...) Expand all Loading... |
79 } | 81 } |
80 } | 82 } |
81 | 83 |
82 // Update hotspot and show cursor surface if not already visible. | 84 // Update hotspot and show cursor surface if not already visible. |
83 hotspot_ = hotspot; | 85 hotspot_ = hotspot; |
84 if (surface_) { | 86 if (surface_) { |
85 surface_->SetBounds(gfx::Rect(gfx::Point() - hotspot_.OffsetFromOrigin(), | 87 surface_->SetBounds(gfx::Rect(gfx::Point() - hotspot_.OffsetFromOrigin(), |
86 surface_->layer()->size())); | 88 surface_->layer()->size())); |
87 if (!surface_->IsVisible()) | 89 if (!surface_->IsVisible()) |
88 surface_->Show(); | 90 surface_->Show(); |
| 91 |
| 92 // Show widget now that cursor has been defined. |
| 93 if (!widget_->IsVisible()) |
| 94 widget_->Show(); |
89 } | 95 } |
| 96 |
| 97 // Register pointer as cursor provider now that the cursor for |focus_| has |
| 98 // been defined. |
| 99 focus_->RegisterCursorProvider(this); |
| 100 |
| 101 // Update cursor in case the registration of pointer as cursor provider |
| 102 // caused the cursor to change. |
| 103 aura::client::CursorClient* cursor_client = |
| 104 aura::client::GetCursorClient(focus_->GetRootWindow()); |
| 105 if (cursor_client) |
| 106 cursor_client->SetCursor(focus_->GetCursor(gfx::ToFlooredPoint(location_))); |
90 } | 107 } |
91 | 108 |
92 //////////////////////////////////////////////////////////////////////////////// | 109 //////////////////////////////////////////////////////////////////////////////// |
93 // ui::EventHandler overrides: | 110 // ui::EventHandler overrides: |
94 | 111 |
95 void Pointer::OnMouseEvent(ui::MouseEvent* event) { | 112 void Pointer::OnMouseEvent(ui::MouseEvent* event) { |
96 Surface* target = GetEffectiveTargetForEvent(event); | 113 Surface* target = GetEffectiveTargetForEvent(event); |
97 | 114 |
98 // If target is different than the current pointer focus then we need to | 115 // If target is different than the current pointer focus then we need to |
99 // generate enter and leave events. | 116 // generate enter and leave events. |
100 if (target != focus_) { | 117 if (target != focus_) { |
101 // First generate a leave event if we currently have a target in focus. | 118 // First generate a leave event if we currently have a target in focus. |
102 if (focus_) { | 119 if (focus_) { |
103 delegate_->OnPointerLeave(focus_); | 120 delegate_->OnPointerLeave(focus_); |
104 focus_->RemoveSurfaceObserver(this); | 121 focus_->RemoveSurfaceObserver(this); |
| 122 // Require SetCursor() to be called and cursor to be re-defined in |
| 123 // response to each OnPointerEnter() call. |
| 124 focus_->UnregisterCursorProvider(this); |
105 focus_ = nullptr; | 125 focus_ = nullptr; |
106 } | 126 } |
107 // Second generate an enter event if focus moved to a new target. | 127 // Second generate an enter event if focus moved to a new target. |
108 if (target) { | 128 if (target) { |
109 delegate_->OnPointerEnter(target, event->location_f(), | 129 delegate_->OnPointerEnter(target, event->location_f(), |
110 event->button_flags()); | 130 event->button_flags()); |
111 location_ = event->location_f(); | 131 location_ = event->location_f(); |
112 focus_ = target; | 132 focus_ = target; |
113 focus_->AddSurfaceObserver(this); | 133 focus_->AddSurfaceObserver(this); |
114 } | 134 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 float ui_scale = ash::Shell::GetInstance() | 217 float ui_scale = ash::Shell::GetInstance() |
198 ->display_manager() | 218 ->display_manager() |
199 ->GetDisplayInfo(display.id()) | 219 ->GetDisplayInfo(display.id()) |
200 .GetEffectiveUIScale(); | 220 .GetEffectiveUIScale(); |
201 if (ui_scale != cursor_scale_) { | 221 if (ui_scale != cursor_scale_) { |
202 gfx::Transform transform; | 222 gfx::Transform transform; |
203 transform.Scale(ui_scale, ui_scale); | 223 transform.Scale(ui_scale, ui_scale); |
204 widget_->GetNativeWindow()->SetTransform(transform); | 224 widget_->GetNativeWindow()->SetTransform(transform); |
205 cursor_scale_ = ui_scale; | 225 cursor_scale_ = ui_scale; |
206 } | 226 } |
207 | |
208 if (!widget_->IsVisible()) | |
209 widget_->Show(); | |
210 } else { | 227 } else { |
211 if (widget_ && widget_->IsVisible()) | 228 if (widget_ && widget_->IsVisible()) |
212 widget_->Hide(); | 229 widget_->Hide(); |
213 } | 230 } |
214 } | 231 } |
215 | 232 |
216 void Pointer::OnScrollEvent(ui::ScrollEvent* event) { | 233 void Pointer::OnScrollEvent(ui::ScrollEvent* event) { |
217 OnMouseEvent(event); | 234 OnMouseEvent(event); |
218 } | 235 } |
219 | 236 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const { | 284 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const { |
268 Surface* target = | 285 Surface* target = |
269 Surface::AsSurface(static_cast<aura::Window*>(event->target())); | 286 Surface::AsSurface(static_cast<aura::Window*>(event->target())); |
270 if (!target) | 287 if (!target) |
271 return nullptr; | 288 return nullptr; |
272 | 289 |
273 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr; | 290 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr; |
274 } | 291 } |
275 | 292 |
276 } // namespace exo | 293 } // namespace exo |
OLD | NEW |