OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EMULATOR_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EMULATOR_H_ |
| 7 |
| 8 #include "content/browser/renderer_host/input/touch_emulator_client.h" |
| 9 #include "content/common/cursors/webcursor.h" |
| 10 #include "content/port/common/input_event_ack_state.h" |
| 11 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 12 #include "ui/events/gesture_detection/filtered_gesture_provider.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 // Emulates touch input with mouse and keyboard. |
| 17 class CONTENT_EXPORT TouchEmulator : public ui::GestureProviderClient { |
| 18 public: |
| 19 explicit TouchEmulator(TouchEmulatorClient* client); |
| 20 TouchEmulator(TouchEmulatorClient* client, |
| 21 ui::GestureProvider::Config gesture_config); |
| 22 virtual ~TouchEmulator(); |
| 23 |
| 24 void Enable(bool allow_pinch); |
| 25 void Disable(); |
| 26 |
| 27 // Returns |true| if the event was consumed. |
| 28 // TODO(dgozman): maybe pass latency info together with events. |
| 29 bool HandleMouseEvent(const blink::WebMouseEvent& event); |
| 30 bool HandleMouseWheelEvent(const blink::WebMouseWheelEvent& event); |
| 31 bool HandleKeyboardEvent(const blink::WebKeyboardEvent& event); |
| 32 |
| 33 // Returns |true| if the event ack was consumed. Consumed ack should not |
| 34 // propagate any further. |
| 35 bool HandleTouchEventAck(InputEventAckState ack_result); |
| 36 |
| 37 // Cancel any touches, for example, when focus is lost. |
| 38 void CancelTouch(); |
| 39 |
| 40 private: |
| 41 // ui::GestureProviderClient implementation. |
| 42 virtual void OnGestureEvent(const ui::GestureEventData& gesture) OVERRIDE; |
| 43 |
| 44 void Init(); |
| 45 void InitCursorFromResource(WebCursor* cursor, int resource_id); |
| 46 void UpdateCursor(); |
| 47 bool UpdateShiftPressed(bool shift_pressed); |
| 48 |
| 49 // Whether we should convert scrolls into pinches. |
| 50 bool InPinchGestureMode() const; |
| 51 |
| 52 bool FillTouchEventAndPoint(const blink::WebMouseEvent& mouse_event); |
| 53 void FillPinchEvent(const blink::WebInputEvent& event); |
| 54 |
| 55 // The following methods generate and pass gesture events to the renderer. |
| 56 void PinchBegin(const blink::WebGestureEvent& event); |
| 57 void PinchUpdate(const blink::WebGestureEvent& event); |
| 58 void PinchEnd(const blink::WebGestureEvent& event); |
| 59 void ScrollEnd(const blink::WebGestureEvent& event); |
| 60 |
| 61 TouchEmulatorClient* const client_; |
| 62 ui::FilteredGestureProvider gesture_provider_; |
| 63 |
| 64 // Disabled emulator does only process touch acks left from previous |
| 65 // emulation. It does not intercept any events. |
| 66 bool enabled_; |
| 67 bool allow_pinch_; |
| 68 |
| 69 // While emulation is on, default cursor is touch. Pressing shift changes |
| 70 // cursor to the pinch one. |
| 71 WebCursor pointer_cursor_; |
| 72 WebCursor touch_cursor_; |
| 73 WebCursor pinch_cursor_; |
| 74 |
| 75 bool mouse_pressed_; |
| 76 bool shift_pressed_; |
| 77 |
| 78 blink::WebTouchEvent touch_event_; |
| 79 bool touch_active_; |
| 80 |
| 81 // Whether we should suppress next fling cancel. This may happen when we |
| 82 // did not send fling start in pinch mode. |
| 83 bool suppress_next_fling_cancel_; |
| 84 |
| 85 blink::WebGestureEvent pinch_event_; |
| 86 // Point which does not move while pinch-zooming. |
| 87 gfx::Point pinch_anchor_; |
| 88 // The cumulative scale change from the start of pinch gesture. |
| 89 float pinch_scale_; |
| 90 bool pinch_gesture_active_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(TouchEmulator); |
| 93 }; |
| 94 |
| 95 } // namespace content |
| 96 |
| 97 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EMULATOR_H_ |
OLD | NEW |