07ce55459588c5c78f8b8debb89b531ad5f6080d
[platform/framework/web/crosswalk-tizen.git] /
1 // Copyright 2017 Samsung Electronics. 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 EVENT_RESAMPLER
6 #define EVENT_RESAMPLER
7
8 #include <Ecore.h>
9 #include <queue>
10
11 #include "ui/gfx/geometry/point_f.h"
12 #include "third_party/WebKit/public/platform/WebGestureEvent.h"
13
14 #define MAX_TOUCH_COUNT 2
15
16 namespace ui {
17 class TouchEvent;
18 }
19
20 namespace content {
21
22 class RenderWidgetHostViewEfl;
23
24 class EventResamplerClient {
25  public:
26   // Forward resampled touch event.
27   virtual void ForwardTouchEvent(ui::TouchEvent*) {}
28
29   // Forward resampled gesture event.
30   virtual void ForwardGestureEvent(const blink::WebGestureEvent&) {}
31
32   virtual void OnAnimatorCallback() {}
33
34   // Return number of touch point.
35   virtual unsigned TouchPointCount() const { return 0; }
36 };
37
38 class EventResampler {
39  public:
40   explicit EventResampler(EventResamplerClient* client);
41   ~EventResampler();
42
43   bool HandleTouchMoveEvent(ui::TouchEvent event);
44   bool HandleGestureEvent(blink::WebGestureEvent& event);
45   bool HasActiveAnimator();
46
47  private:
48   static Eina_Bool VsyncAnimatorCallback(void* data);
49
50   void ResampleTouchMove(int id);
51   void ResampleScrollUpdate();
52   void ResamplePinchUpdate();
53   void NotifyAnimatorCallback();
54
55   void ClearTouchMoveEventQueue();
56   bool CanDeleteAnimator();
57
58   EventResamplerClient* client_;
59
60   Ecore_Animator* vsync_animator_;
61   bool has_pending_touch_move_event_[MAX_TOUCH_COUNT];
62   bool has_pending_scroll_event_;
63   bool has_pending_pinch_event_;
64
65   // To process without delay if event isn't processed in last callback.
66   bool is_scroll_processed_in_last_callback_;
67   bool is_pinch_processed_in_last_callback_;
68
69   std::queue<ui::TouchEvent> touch_move_event_queue_[MAX_TOUCH_COUNT];
70   blink::WebGestureEvent last_scroll_update_event_;
71   blink::WebGestureEvent last_pinch_update_event_;
72
73   gfx::PointF pending_scroll_delta_;
74   float pending_pinch_scale_;
75 };
76
77 }  // namespace
78
79 #endif  // EVENT_RESAMPLER