DCHECK if shader compilation fails that it's due to context loss.
[chromium-blink-merge.git] / ui / events / gesture_detection / scale_gesture_detector.h
blobd45ca4e3796aa087566b97dca32ecc19138afbdb
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 UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_
6 #define UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_
8 #include "base/time/time.h"
9 #include "ui/events/gesture_detection/gesture_detection_export.h"
11 namespace ui {
13 class MotionEvent;
14 class ScaleGestureListener;
16 // Port of ScaleGestureDetector.java from Android
17 // * platform/frameworks/base/core/java/android/view/ScaleGestureDetector.java
18 // * Change-Id: I3e7926a4f6f9ab4951f380bd004499c78b3bda69
19 // * Please update the Change-Id as upstream Android changes are pulled.
20 class GESTURE_DETECTION_EXPORT ScaleGestureDetector {
21 public:
22 struct GESTURE_DETECTION_EXPORT Config {
23 Config();
24 ~Config();
26 // Distance the current span can deviate from the initial span before
27 // scaling will start (in dips). The span is the diameter of the circle with
28 // a radius of average pointer deviation from the focal point.
29 float span_slop;
31 // Minimum accepted value for TouchMajor while scaling (in dips).
32 float min_scaling_touch_major;
34 // Minimum span needed to initiate a scaling gesture (in dips).
35 float min_scaling_span;
37 // Minimum pinch span change before pinch occurs (in dips). See
38 // crbug.com/373318.
39 float min_pinch_update_span_delta;
42 ScaleGestureDetector(const Config& config, ScaleGestureListener* listener);
43 virtual ~ScaleGestureDetector();
45 // Accepts MotionEvents and dispatches events to a |ScaleGestureListener|
46 // when appropriate.
48 // Note: Applications should pass a complete and consistent event stream to
49 // this method. A complete and consistent event stream involves all
50 // MotionEvents from the initial ACTION_DOWN to the final ACTION_UP or
51 // ACTION_CANCEL.
53 // Returns true if the event was processed and the detector wants to receive
54 // the rest of the MotionEvents in this event stream.
55 bool OnTouchEvent(const MotionEvent& event);
57 // This method may be called by the owner when a a double-tap event has been
58 // detected *for the same event stream* being fed to this instance of the
59 // ScaleGestureDetector. As call order is important here, the double-tap
60 // detector should always be offered events *before* the ScaleGestureDetector.
61 bool OnDoubleTap(const MotionEvent& event);
63 // Set whether the associated |ScaleGestureListener| should receive
64 // OnScale callbacks when the user performs a doubletap followed by a swipe.
65 bool IsInProgress() const;
66 bool InDoubleTapMode() const;
67 float GetFocusX() const;
68 float GetFocusY() const;
69 float GetCurrentSpan() const;
70 float GetCurrentSpanX() const;
71 float GetCurrentSpanY() const;
72 float GetPreviousSpan() const;
73 float GetPreviousSpanX() const;
74 float GetPreviousSpanY() const;
75 float GetScaleFactor() const;
76 base::TimeDelta GetTimeDelta() const;
77 base::TimeTicks GetEventTime() const;
79 private:
80 enum DoubleTapMode { DOUBLE_TAP_MODE_NONE, DOUBLE_TAP_MODE_IN_PROGRESS };
82 // The TouchMajor/TouchMinor elements of a MotionEvent can flutter/jitter on
83 // some hardware/driver combos. Smooth out to get kinder, gentler behavior.
84 void AddTouchHistory(const MotionEvent& ev);
85 void ResetTouchHistory();
87 void ResetScaleWithSpan(float span);
89 ScaleGestureListener* const listener_;
91 float focus_x_;
92 float focus_y_;
93 float curr_span_;
94 float prev_span_;
95 float initial_span_;
96 float curr_span_x_;
97 float curr_span_y_;
98 float prev_span_x_;
99 float prev_span_y_;
100 base::TimeTicks curr_time_;
101 base::TimeTicks prev_time_;
102 bool in_progress_;
103 float span_slop_;
104 float min_span_;
106 // Bounds for recently seen values.
107 float touch_upper_;
108 float touch_lower_;
109 float touch_history_last_accepted_;
110 int touch_history_direction_;
111 base::TimeTicks touch_history_last_accepted_time_;
112 float touch_min_major_;
113 float touch_max_major_;
114 float double_tap_focus_x_;
115 float double_tap_focus_y_;
116 DoubleTapMode double_tap_mode_;
118 bool event_before_or_above_starting_gesture_event_;
120 DISALLOW_COPY_AND_ASSIGN(ScaleGestureDetector);
123 } // namespace ui
125 #endif // UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_