Chromium Code Reviews| 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/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/pointer_stylus_delegate.h" | |
| 12 #include "components/exo/surface.h" | 13 #include "components/exo/surface.h" |
| 13 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 16 #include "ui/gfx/geometry/vector2d_conversions.h" | 17 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 18 | 19 |
| 19 namespace exo { | 20 namespace exo { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 44 ash::Shell* ash_shell = ash::Shell::GetInstance(); | 45 ash::Shell* ash_shell = ash::Shell::GetInstance(); |
| 45 ash_shell->AddPreTargetHandler(this); | 46 ash_shell->AddPreTargetHandler(this); |
| 46 | 47 |
| 47 wm::CursorManager* cursor_manager = ash_shell->cursor_manager(); | 48 wm::CursorManager* cursor_manager = ash_shell->cursor_manager(); |
| 48 DCHECK(cursor_manager); | 49 DCHECK(cursor_manager); |
| 49 cursor_manager->AddObserver(this); | 50 cursor_manager->AddObserver(this); |
| 50 } | 51 } |
| 51 | 52 |
| 52 Pointer::~Pointer() { | 53 Pointer::~Pointer() { |
| 53 delegate_->OnPointerDestroying(this); | 54 delegate_->OnPointerDestroying(this); |
| 55 if (stylus_delegate_) | |
| 56 stylus_delegate_->OnPointerDestroying(this); | |
| 54 if (surface_) | 57 if (surface_) |
| 55 surface_->RemoveSurfaceObserver(this); | 58 surface_->RemoveSurfaceObserver(this); |
| 56 if (focus_) { | 59 if (focus_) { |
| 57 focus_->RemoveSurfaceObserver(this); | 60 focus_->RemoveSurfaceObserver(this); |
| 58 focus_->UnregisterCursorProvider(this); | 61 focus_->UnregisterCursorProvider(this); |
| 59 } | 62 } |
| 60 if (widget_) | 63 if (widget_) |
| 61 widget_->CloseNow(); | 64 widget_->CloseNow(); |
| 62 | 65 |
| 63 ash::Shell* ash_shell = ash::Shell::GetInstance(); | 66 ash::Shell* ash_shell = ash::Shell::GetInstance(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 | 115 |
| 113 // Update cursor in case the registration of pointer as cursor provider | 116 // Update cursor in case the registration of pointer as cursor provider |
| 114 // caused the cursor to change. | 117 // caused the cursor to change. |
| 115 aura::client::CursorClient* cursor_client = | 118 aura::client::CursorClient* cursor_client = |
| 116 aura::client::GetCursorClient(focus_->window()->GetRootWindow()); | 119 aura::client::GetCursorClient(focus_->window()->GetRootWindow()); |
| 117 if (cursor_client) | 120 if (cursor_client) |
| 118 cursor_client->SetCursor( | 121 cursor_client->SetCursor( |
| 119 focus_->window()->GetCursor(gfx::ToFlooredPoint(location_))); | 122 focus_->window()->GetCursor(gfx::ToFlooredPoint(location_))); |
| 120 } | 123 } |
| 121 | 124 |
| 125 void Pointer::SetStylusDelegate(PointerStylusDelegate* delegate) { | |
| 126 stylus_delegate_ = delegate; | |
| 127 } | |
| 128 | |
| 122 //////////////////////////////////////////////////////////////////////////////// | 129 //////////////////////////////////////////////////////////////////////////////// |
| 123 // ui::EventHandler overrides: | 130 // ui::EventHandler overrides: |
| 124 | 131 |
| 125 void Pointer::OnMouseEvent(ui::MouseEvent* event) { | 132 void Pointer::OnMouseEvent(ui::MouseEvent* event) { |
| 126 Surface* target = GetEffectiveTargetForEvent(event); | 133 Surface* target = GetEffectiveTargetForEvent(event); |
| 127 | 134 |
| 128 // If target is different than the current pointer focus then we need to | 135 // If target is different than the current pointer focus then we need to |
| 129 // generate enter and leave events. | 136 // generate enter and leave events. |
| 130 if (target != focus_) { | 137 if (target != focus_) { |
| 131 // First generate a leave event if we currently have a target in focus. | 138 // First generate a leave event if we currently have a target in focus. |
| 132 if (focus_) { | 139 if (focus_) { |
| 133 delegate_->OnPointerLeave(focus_); | 140 delegate_->OnPointerLeave(focus_); |
| 134 focus_->RemoveSurfaceObserver(this); | 141 focus_->RemoveSurfaceObserver(this); |
| 135 // Require SetCursor() to be called and cursor to be re-defined in | 142 // Require SetCursor() to be called and cursor to be re-defined in |
| 136 // response to each OnPointerEnter() call. | 143 // response to each OnPointerEnter() call. |
| 137 focus_->UnregisterCursorProvider(this); | 144 focus_->UnregisterCursorProvider(this); |
| 138 focus_ = nullptr; | 145 focus_ = nullptr; |
| 139 } | 146 } |
| 140 // Second generate an enter event if focus moved to a new target. | 147 // Second generate an enter event if focus moved to a new target. |
| 141 if (target) { | 148 if (target) { |
| 142 delegate_->OnPointerEnter(target, event->location_f(), | 149 delegate_->OnPointerEnter(target, event->location_f(), |
| 143 event->button_flags()); | 150 event->button_flags()); |
| 144 location_ = event->location_f(); | 151 location_ = event->location_f(); |
| 152 // Defaulting pointer_type to POINTER_TYPE_MOUSE prevents the tool change | |
| 153 // event from being fired when using a mouse. | |
| 154 pointer_type_ = ui::EventPointerType::POINTER_TYPE_MOUSE; | |
| 155 | |
| 145 focus_ = target; | 156 focus_ = target; |
| 146 focus_->AddSurfaceObserver(this); | 157 focus_->AddSurfaceObserver(this); |
| 147 } | 158 } |
| 148 delegate_->OnPointerFrame(); | 159 delegate_->OnPointerFrame(); |
| 149 } | 160 } |
| 150 | 161 |
| 162 // Report changes in pointer type. We treat unknown devices as a mouse. | |
| 163 auto new_pointer_type = event->pointer_details().pointer_type; | |
| 164 if (new_pointer_type == ui::EventPointerType::POINTER_TYPE_UNKNOWN) | |
| 165 new_pointer_type = ui::EventPointerType::POINTER_TYPE_MOUSE; | |
| 166 if (focus_ && stylus_delegate_ && new_pointer_type != pointer_type_) { | |
| 167 stylus_delegate_->OnPointerToolChange(new_pointer_type); | |
| 168 pointer_type_ = new_pointer_type; | |
| 169 } | |
| 170 | |
| 151 switch (event->type()) { | 171 switch (event->type()) { |
| 152 case ui::ET_MOUSE_PRESSED: | 172 case ui::ET_MOUSE_PRESSED: |
| 153 case ui::ET_MOUSE_RELEASED: | 173 case ui::ET_MOUSE_RELEASED: |
| 154 if (focus_) { | 174 if (focus_) { |
| 155 delegate_->OnPointerButton(event->time_stamp(), | 175 delegate_->OnPointerButton(event->time_stamp(), |
| 156 event->changed_button_flags(), | 176 event->changed_button_flags(), |
| 157 event->type() == ui::ET_MOUSE_PRESSED); | 177 event->type() == ui::ET_MOUSE_PRESSED); |
| 158 delegate_->OnPointerFrame(); | 178 delegate_->OnPointerFrame(); |
| 159 } | 179 } |
| 160 break; | 180 break; |
| 161 case ui::ET_MOUSE_MOVED: | 181 case ui::ET_MOUSE_MOVED: |
| 162 case ui::ET_MOUSE_DRAGGED: | 182 case ui::ET_MOUSE_DRAGGED: |
| 163 // Generate motion event if location changed. We need to check location | 183 if (focus_) { |
| 164 // here as mouse movement can generate both "moved" and "entered" events | 184 bool send_frame = false; |
| 165 // but OnPointerMotion should only be called if location changed since | 185 // Generate motion event if location changed. We need to check location |
| 166 // OnPointerEnter was called. | 186 // here as mouse movement can generate both "moved" and "entered" events |
| 167 if (focus_ && !SameLocation(event, location_)) { | 187 // but OnPointerMotion should only be called if location changed since |
| 168 delegate_->OnPointerMotion(event->time_stamp(), event->location_f()); | 188 // OnPointerEnter was called. |
| 169 delegate_->OnPointerFrame(); | 189 if (!SameLocation(event, location_)) { |
| 170 location_ = event->location_f(); | 190 location_ = event->location_f(); |
| 191 delegate_->OnPointerMotion(event->time_stamp(), location_); | |
| 192 send_frame = true; | |
| 193 } | |
| 194 if (stylus_delegate_ && | |
| 195 pointer_type_ != ui::EventPointerType::POINTER_TYPE_MOUSE) { | |
| 196 constexpr float kEpsilon = std::numeric_limits<float>::epsilon(); | |
|
reveman
2016/07/28 04:01:45
is this useful? why are these type of events not f
denniskempin
2016/07/28 17:17:39
as discussed we will keep this for consistency wit
| |
| 197 gfx::Vector2dF new_tilt = gfx::Vector2dF( | |
| 198 event->pointer_details().tilt_x, event->pointer_details().tilt_y); | |
| 199 if (std::abs(new_tilt.x() - tilt_.x()) > kEpsilon || | |
| 200 std::abs(new_tilt.y() - tilt_.y()) > kEpsilon) { | |
| 201 tilt_ = new_tilt; | |
| 202 stylus_delegate_->OnPointerTilt(event->time_stamp(), new_tilt); | |
| 203 send_frame = true; | |
| 204 } | |
| 205 | |
| 206 float new_force = event->pointer_details().force; | |
| 207 if (std::abs(new_force - force_) > kEpsilon) { | |
| 208 force_ = new_force; | |
| 209 stylus_delegate_->OnPointerForce(event->time_stamp(), new_force); | |
| 210 send_frame = true; | |
| 211 } | |
| 212 } | |
| 213 if (send_frame) | |
| 214 delegate_->OnPointerFrame(); | |
| 171 } | 215 } |
| 172 break; | 216 break; |
| 173 case ui::ET_SCROLL: | 217 case ui::ET_SCROLL: |
| 174 if (focus_) { | 218 if (focus_) { |
| 175 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event); | 219 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event); |
| 176 delegate_->OnPointerScroll( | 220 delegate_->OnPointerScroll( |
| 177 event->time_stamp(), | 221 event->time_stamp(), |
| 178 gfx::Vector2dF(scroll_event->x_offset(), scroll_event->y_offset()), | 222 gfx::Vector2dF(scroll_event->x_offset(), scroll_event->y_offset()), |
| 179 false); | 223 false); |
| 180 delegate_->OnPointerFrame(); | 224 delegate_->OnPointerFrame(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 | 358 |
| 315 if (ui_scale != cursor_scale_) { | 359 if (ui_scale != cursor_scale_) { |
| 316 gfx::Transform transform; | 360 gfx::Transform transform; |
| 317 transform.Scale(ui_scale, ui_scale); | 361 transform.Scale(ui_scale, ui_scale); |
| 318 widget_->GetNativeWindow()->SetTransform(transform); | 362 widget_->GetNativeWindow()->SetTransform(transform); |
| 319 cursor_scale_ = ui_scale; | 363 cursor_scale_ = ui_scale; |
| 320 } | 364 } |
| 321 } | 365 } |
| 322 | 366 |
| 323 } // namespace exo | 367 } // namespace exo |
| OLD | NEW |