OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/renderer_host/input/touch_emulator.h" | 5 #include "content/browser/renderer_host/input/touch_emulator.h" |
6 | 6 |
7 #include "content/browser/renderer_host/input/motion_event_web.h" | 7 #include "content/browser/renderer_host/input/motion_event_web.h" |
8 #include "content/browser/renderer_host/input/web_input_event_util.h" | 8 #include "content/browser/renderer_host/input/web_input_event_util.h" |
9 #include "content/common/input/web_touch_event_traits.h" | 9 #include "content/common/input/web_touch_event_traits.h" |
10 #include "content/public/common/content_client.h" | 10 #include "content/public/common/content_client.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 148 |
149 if (mouse_event.type == WebInputEvent::MouseDown) | 149 if (mouse_event.type == WebInputEvent::MouseDown) |
150 mouse_pressed_ = true; | 150 mouse_pressed_ = true; |
151 else if (mouse_event.type == WebInputEvent::MouseUp) | 151 else if (mouse_event.type == WebInputEvent::MouseUp) |
152 mouse_pressed_ = false; | 152 mouse_pressed_ = false; |
153 | 153 |
154 UpdateShiftPressed((mouse_event.modifiers & WebInputEvent::ShiftKey) != 0); | 154 UpdateShiftPressed((mouse_event.modifiers & WebInputEvent::ShiftKey) != 0); |
155 | 155 |
156 if (FillTouchEventAndPoint(mouse_event) && | 156 if (FillTouchEventAndPoint(mouse_event) && |
157 gesture_provider_.OnTouchEvent(MotionEventWeb(touch_event_))) { | 157 gesture_provider_.OnTouchEvent(MotionEventWeb(touch_event_))) { |
158 client_->ForwardTouchEvent(touch_event_); | 158 client_->ForwardEmulatedTouchEvent(touch_event_); |
159 } | 159 } |
160 | 160 |
161 // Do not pass mouse events to the renderer. | 161 // Do not pass mouse events to the renderer. |
162 return true; | 162 return true; |
163 } | 163 } |
164 | 164 |
165 bool TouchEmulator::HandleMouseWheelEvent(const WebMouseWheelEvent& event) { | 165 bool TouchEmulator::HandleMouseWheelEvent(const WebMouseWheelEvent& event) { |
166 if (!enabled_) | 166 if (!enabled_) |
167 return false; | 167 return false; |
168 | 168 |
(...skipping 17 matching lines...) Expand all Loading... |
186 if (shift_pressed_) { | 186 if (shift_pressed_) { |
187 // TODO(dgozman): Add secondary touch point and set anchor. | 187 // TODO(dgozman): Add secondary touch point and set anchor. |
188 } else { | 188 } else { |
189 // TODO(dgozman): Remove secondary touch point and anchor. | 189 // TODO(dgozman): Remove secondary touch point and anchor. |
190 } | 190 } |
191 | 191 |
192 // Never block keyboard events. | 192 // Never block keyboard events. |
193 return false; | 193 return false; |
194 } | 194 } |
195 | 195 |
196 bool TouchEmulator::HandleTouchEventAck(InputEventAckState ack_result) { | 196 void TouchEmulator::HandleTouchEventAck(InputEventAckState ack_result) { |
197 const bool event_consumed = ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; | 197 const bool event_consumed = ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; |
198 gesture_provider_.OnTouchEventAck(event_consumed); | 198 gesture_provider_.OnTouchEventAck(event_consumed); |
199 // TODO(dgozman): Disable emulation when real touch events are available. | |
200 return true; | |
201 } | 199 } |
202 | 200 |
203 void TouchEmulator::OnGestureEvent(const ui::GestureEventData& gesture) { | 201 void TouchEmulator::OnGestureEvent(const ui::GestureEventData& gesture) { |
204 WebGestureEvent gesture_event = | 202 WebGestureEvent gesture_event = |
205 CreateWebGestureEventFromGestureEventData(gesture); | 203 CreateWebGestureEventFromGestureEventData(gesture); |
206 | 204 |
207 switch (gesture_event.type) { | 205 switch (gesture_event.type) { |
208 case WebInputEvent::Undefined: | 206 case WebInputEvent::Undefined: |
209 NOTREACHED() << "Undefined WebInputEvent type"; | 207 NOTREACHED() << "Undefined WebInputEvent type"; |
210 // Bail without sending the junk event to the client. | 208 // Bail without sending the junk event to the client. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 void TouchEmulator::CancelTouch() { | 267 void TouchEmulator::CancelTouch() { |
270 if (!touch_active_) | 268 if (!touch_active_) |
271 return; | 269 return; |
272 | 270 |
273 WebTouchEventTraits::ResetTypeAndTouchStates( | 271 WebTouchEventTraits::ResetTypeAndTouchStates( |
274 WebInputEvent::TouchCancel, | 272 WebInputEvent::TouchCancel, |
275 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(), | 273 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(), |
276 &touch_event_); | 274 &touch_event_); |
277 touch_active_ = false; | 275 touch_active_ = false; |
278 if (gesture_provider_.OnTouchEvent(MotionEventWeb(touch_event_))) | 276 if (gesture_provider_.OnTouchEvent(MotionEventWeb(touch_event_))) |
279 client_->ForwardTouchEvent(touch_event_); | 277 client_->ForwardEmulatedTouchEvent(touch_event_); |
280 } | 278 } |
281 | 279 |
282 void TouchEmulator::UpdateCursor() { | 280 void TouchEmulator::UpdateCursor() { |
283 if (!enabled_) | 281 if (!enabled_) |
284 client_->SetCursor(pointer_cursor_); | 282 client_->SetCursor(pointer_cursor_); |
285 else | 283 else |
286 client_->SetCursor(InPinchGestureMode() ? pinch_cursor_ : touch_cursor_); | 284 client_->SetCursor(InPinchGestureMode() ? pinch_cursor_ : touch_cursor_); |
287 } | 285 } |
288 | 286 |
289 bool TouchEmulator::UpdateShiftPressed(bool shift_pressed) { | 287 bool TouchEmulator::UpdateShiftPressed(bool shift_pressed) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 point.screenPosition.y = mouse_event.globalY; | 380 point.screenPosition.y = mouse_event.globalY; |
383 | 381 |
384 return true; | 382 return true; |
385 } | 383 } |
386 | 384 |
387 bool TouchEmulator::InPinchGestureMode() const { | 385 bool TouchEmulator::InPinchGestureMode() const { |
388 return shift_pressed_ && allow_pinch_; | 386 return shift_pressed_ && allow_pinch_; |
389 } | 387 } |
390 | 388 |
391 } // namespace content | 389 } // namespace content |
OLD | NEW |