• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2017 The Chromium Embedded Framework Authors.
2 // Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #ifndef CEF_LIBCEF_BROWSER_OSR_MOTION_EVENT_OSR_H_
7 #define CEF_LIBCEF_BROWSER_OSR_MOTION_EVENT_OSR_H_
8 #pragma once
9 
10 #include "include/cef_base.h"
11 
12 #include "third_party/blink/public/common/input/web_touch_event.h"
13 #include "ui/events/gesture_detection/motion_event_generic.h"
14 
15 // Implementation of MotionEvent which takes a stream of CefTouchEvents.
16 // This class is based on ui::MotionEventAura.
17 class CefMotionEventOSR : public ui::MotionEventGeneric {
18  public:
19   CefMotionEventOSR();
20 
21   CefMotionEventOSR(const CefMotionEventOSR&) = delete;
22   CefMotionEventOSR& operator=(const CefMotionEventOSR&) = delete;
23 
24   ~CefMotionEventOSR() override;
25 
26   int GetSourceDeviceId(size_t pointer_index) const override;
27 
28   // Returns true if the touch was valid.
29   bool OnTouch(const CefTouchEvent& touch);
30 
31   // We can't cleanup removed touch points immediately upon receipt of a
32   // TouchCancel or TouchRelease, as the MotionEvent needs to be able to report
33   // information about those touch events. Once the MotionEvent has been
34   // processed, we call CleanupRemovedTouchPoints to do the required
35   // book-keeping.
36   void CleanupRemovedTouchPoints(const CefTouchEvent& event);
37 
38   // Reset unchanged touch point to StateStationary for touchmove and
39   // touchcancel to make sure only send one ack per WebTouchEvent.
40   void MarkUnchangedTouchPointsAsStationary(blink::WebTouchEvent* event,
41                                             const CefTouchEvent& cef_event);
42 
43  private:
44   // Chromium can't cope with touch ids >31, so let's map the incoming
45   // ids to a safe range.
46   int id_map_[blink::WebTouchEvent::kTouchesLengthCap];
47 
48   int LookupId(int id);
49   int AddId(int id);
50   void RemoveId(int id);
51 
52   bool AddTouch(const CefTouchEvent& touch, int id);
53   void UpdateTouch(const CefTouchEvent& touch, int id);
54   void UpdateCachedAction(const CefTouchEvent& touch, int id);
55   bool IsValidIndex(int index) const;
56   ui::PointerProperties GetPointerPropertiesFromTouchEvent(
57       const CefTouchEvent& touch,
58       int id);
59 };
60 
61 #endif
62