Home | History | Annotate | Download | only in input
      1 // Copyright 2013 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_COMMON_INPUT_SYNTHETIC_WEB_INPUT_EVENT_BUILDERS_H_
      6 #define CONTENT_COMMON_INPUT_SYNTHETIC_WEB_INPUT_EVENT_BUILDERS_H_
      7 
      8 #include "base/time/time.h"
      9 #include "content/common/content_export.h"
     10 #include "third_party/WebKit/public/web/WebInputEvent.h"
     11 
     12 // Provides sensible creation of default WebInputEvents for testing purposes.
     13 
     14 namespace content {
     15 
     16 class CONTENT_EXPORT SyntheticWebMouseEventBuilder {
     17  public:
     18   static blink::WebMouseEvent Build(blink::WebInputEvent::Type type);
     19   static blink::WebMouseEvent Build(blink::WebInputEvent::Type type,
     20                                      int window_x,
     21                                      int window_y,
     22                                      int modifiers);
     23 };
     24 
     25 class CONTENT_EXPORT SyntheticWebMouseWheelEventBuilder {
     26  public:
     27   static blink::WebMouseWheelEvent Build(
     28       blink::WebMouseWheelEvent::Phase phase);
     29   static blink::WebMouseWheelEvent Build(float dx,
     30                                           float dy,
     31                                           int modifiers,
     32                                           bool precise);
     33 };
     34 
     35 class CONTENT_EXPORT SyntheticWebKeyboardEventBuilder {
     36  public:
     37   static blink::WebKeyboardEvent Build(blink::WebInputEvent::Type type);
     38 };
     39 
     40 class CONTENT_EXPORT SyntheticWebGestureEventBuilder {
     41  public:
     42   static blink::WebGestureEvent Build(
     43       blink::WebInputEvent::Type type,
     44       blink::WebGestureEvent::SourceDevice sourceDevice);
     45   static blink::WebGestureEvent BuildScrollUpdate(float dx,
     46                                                    float dY,
     47                                                    int modifiers);
     48   static blink::WebGestureEvent BuildPinchUpdate(float scale,
     49                                                   float anchor_x,
     50                                                   float anchor_y,
     51                                                   int modifiers);
     52   static blink::WebGestureEvent BuildFling(
     53       float velocity_x,
     54       float velocity_y,
     55       blink::WebGestureEvent::SourceDevice source_device);
     56 };
     57 
     58 class CONTENT_EXPORT SyntheticWebTouchEvent
     59     : public NON_EXPORTED_BASE(blink::WebTouchEvent) {
     60  public:
     61   SyntheticWebTouchEvent();
     62 
     63   // Mark all the points as stationary, and remove any released points.
     64   void ResetPoints();
     65 
     66   // Adds an additional point to the touch list, returning the point's index.
     67   int PressPoint(int x, int y);
     68   void MovePoint(int index, int x, int y);
     69   void ReleasePoint(int index);
     70   void CancelPoint(int index);
     71 
     72   void SetTimestamp(base::TimeDelta timestamp);
     73 };
     74 
     75 class CONTENT_EXPORT SyntheticWebTouchEventBuilder {
     76  public:
     77   static SyntheticWebTouchEvent Build(blink::WebInputEvent::Type type);
     78 };
     79 
     80 }  // namespace content
     81 
     82 #endif  // CONTENT_COMMON_INPUT_SYNTHETIC_WEB_INPUT_EVENT_BUILDERS_H_
     83