summaryrefslogtreecommitdiffstats
path: root/components/html_viewer/touch_handler.h
blob: 4c5972b38e0818d06fabcaa328169916bf1d0a0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_HTML_VIEWER_TOUCH_HANDLER_H_
#define COMPONENTS_HTML_VIEWER_TOUCH_HANDLER_H_

#include "base/basictypes.h"
#include "ui/events/gesture_detection/filtered_gesture_provider.h"

namespace blink {
class WebWidget;
}

namespace mojo {
class Event;
}

namespace ui {
class MotionEventGeneric;
}

namespace html_viewer {

// TouchHandler is responsible for converting touch events into gesture events.
// It does this by converting mojo::Events into a MotionEventGeneric and using
// FilteredGestureProvider.
class TouchHandler : public ui::GestureProviderClient {
 public:
  explicit TouchHandler(blink::WebWidget* web_widget);
  ~TouchHandler() override;

  void OnTouchEvent(const mojo::Event& event);

  // ui::GestureProviderClient implementation.
  void OnGestureEvent(const ui::GestureEventData& gesture) override;

 private:
  // Updates |current_motion_event_| from |event|. Returns true on success.
  bool UpdateMotionEvent(const mojo::Event& event);

  // Sends |current_motion_event_| to the GestureProvider and WebView.
  void SendMotionEventToGestureProvider();

  // Does post processing after sending |current_motion_event_| to the
  // GestureProvider.
  void PostProcessMotionEvent(const mojo::Event& event);

  blink::WebWidget* web_widget_;

  ui::FilteredGestureProvider gesture_provider_;

  // As touch events are received they are converted to this event. If null no
  // touch events are in progress.
  scoped_ptr<ui::MotionEventGeneric> current_motion_event_;

  DISALLOW_COPY_AND_ASSIGN(TouchHandler);
};

}  // namespace html_viewer

#endif  // COMPONENTS_HTML_VIEWER_TOUCH_HANDLER_H_