Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / input / touch_emulator.h
blobe21287f2cac66e52e4b3acc92c08735b7aef58d6
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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EMULATOR_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EMULATOR_H_
8 #include "content/browser/renderer_host/input/touch_emulator_client.h"
9 #include "content/common/cursors/webcursor.h"
10 #include "content/common/input/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 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
14 #include "ui/gfx/geometry/size_f.h"
16 namespace content {
18 // Emulates touch input with mouse and keyboard.
19 class CONTENT_EXPORT TouchEmulator : public ui::GestureProviderClient {
20 public:
21 TouchEmulator(TouchEmulatorClient* client, float device_scale_factor);
22 ~TouchEmulator() override;
24 void Enable(ui::GestureProviderConfigType config_type);
25 void Disable();
27 // See GestureProvider::SetDoubleTapSupportForPageEnabled.
28 void SetDoubleTapSupportForPageEnabled(bool enabled);
30 // Note that TouchEmulator should always listen to touch events and their acks
31 // (even in disabled state) to track native stream presence.
32 bool enabled() const { return gesture_provider_; }
34 // Returns |true| if the event was consumed. Consumed event should not
35 // propagate any further.
36 // TODO(dgozman): maybe pass latency info together with events.
37 bool HandleMouseEvent(const blink::WebMouseEvent& event);
38 bool HandleMouseWheelEvent(const blink::WebMouseWheelEvent& event);
39 bool HandleKeyboardEvent(const blink::WebKeyboardEvent& event);
40 bool HandleTouchEvent(const blink::WebTouchEvent& event);
42 // Returns |true| if the event ack was consumed. Consumed ack should not
43 // propagate any further.
44 bool HandleTouchEventAck(const blink::WebTouchEvent& event,
45 InputEventAckState ack_result);
47 // Cancel any touches, for example, when focus is lost.
48 void CancelTouch();
50 private:
51 // ui::GestureProviderClient implementation.
52 void OnGestureEvent(const ui::GestureEventData& gesture) override;
54 // Returns cursor size in DIP.
55 gfx::SizeF InitCursorFromResource(
56 WebCursor* cursor, float scale, int resource_id);
57 void ResetState();
58 void UpdateCursor();
59 bool UpdateShiftPressed(bool shift_pressed);
61 // Whether we should convert scrolls into pinches.
62 bool InPinchGestureMode() const;
64 void FillTouchEventAndPoint(const blink::WebMouseEvent& mouse_event);
65 void FillPinchEvent(const blink::WebInputEvent& event);
67 // The following methods generate and pass gesture events to the renderer.
68 void PinchBegin(const blink::WebGestureEvent& event);
69 void PinchUpdate(const blink::WebGestureEvent& event);
70 void PinchEnd(const blink::WebGestureEvent& event);
71 void ScrollEnd(const blink::WebGestureEvent& event);
73 // Offers the emulated event to |gesture_provider_|, conditionally forwarding
74 // it to the client if appropriate.
75 void HandleEmulatedTouchEvent(blink::WebTouchEvent event);
77 TouchEmulatorClient* const client_;
79 // Emulator is enabled iff gesture provider is created.
80 // Disabled emulator does only process touch acks left from previous
81 // emulation. It does not intercept any events.
82 scoped_ptr<ui::FilteredGestureProvider> gesture_provider_;
83 ui::GestureProviderConfigType gesture_provider_config_type_;
84 bool double_tap_enabled_;
86 // While emulation is on, default cursor is touch. Pressing shift changes
87 // cursor to the pinch one.
88 WebCursor pointer_cursor_;
89 WebCursor touch_cursor_;
90 WebCursor pinch_cursor_;
91 gfx::SizeF cursor_size_;
93 // These are used to drop extra mouse move events coming too quickly, so
94 // we don't handle too much touches in gesture provider.
95 bool last_mouse_event_was_move_;
96 double last_mouse_move_timestamp_;
98 bool mouse_pressed_;
99 bool shift_pressed_;
101 blink::WebTouchEvent touch_event_;
102 int emulated_stream_active_sequence_count_;
103 int native_stream_active_sequence_count_;
105 // Whether we should suppress next fling cancel. This may happen when we
106 // did not send fling start in pinch mode.
107 bool suppress_next_fling_cancel_;
109 blink::WebGestureEvent pinch_event_;
110 // Point which does not move while pinch-zooming.
111 gfx::Point pinch_anchor_;
112 // The cumulative scale change from the start of pinch gesture.
113 float pinch_scale_;
114 bool pinch_gesture_active_;
116 DISALLOW_COPY_AND_ASSIGN(TouchEmulator);
119 } // namespace content
121 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EMULATOR_H_