Index: ui/touch_selection/longpress_drag_selector.h |
diff --git a/ui/touch_selection/longpress_drag_selector.h b/ui/touch_selection/longpress_drag_selector.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..922ce6fe2ae505efdc6ef531a67efe88cbae3493 |
--- /dev/null |
+++ b/ui/touch_selection/longpress_drag_selector.h |
@@ -0,0 +1,72 @@ |
+// 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 UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_ |
+#define UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_ |
+ |
+#include "base/time/time.h" |
+#include "ui/gfx/geometry/point_f.h" |
+#include "ui/gfx/geometry/vector2d_f.h" |
+#include "ui/touch_selection/touch_selection_draggable.h" |
+#include "ui/touch_selection/ui_touch_selection_export.h" |
+ |
+namespace ui { |
+ |
+class MotionEvent; |
+ |
+// Supports text selection via touch dragging after a longpress-initiated |
+// selection. |
+class UI_TOUCH_SELECTION_EXPORT LongPressDragSelector |
+ : public TouchSelectionDraggable { |
+ public: |
+ LongPressDragSelector(TouchSelectionDraggableClient* client, |
+ float slop_length); |
mfomitchev
2015/04/23 21:05:53
Can we put GetTapSlop() into TouchSelectionDraggab
jdduke (slow)
2015/04/27 20:24:25
Done (added a |IsWithinTapSlop| client routine).
|
+ ~LongPressDragSelector() override; |
+ |
+ // Allows selection dragging after a long-press initiated selection. Returns |
+ // true if the event was consumed, in which case the caller should cease |
+ // further handling. |
+ bool WillHandleTouchEvent(const MotionEvent& event); |
+ |
+ // Called when a longpress event is observed, before any of its side effects |
+ // (e.g., selection activation) have been realized. |
+ void OnLongPressEvent(base::TimeTicks event_time, |
+ const gfx::PointF& position); |
+ |
+ // Called when the active selection changes. |
+ void OnSelectionActivated(const gfx::PointF& start, const gfx::PointF& end); |
+ void OnSelectionDeactivated(); |
+ |
+ // Whether a drag is active or being detected for the current touch sequence. |
+ bool IsActive() const; |
+ |
+ private: |
+ enum SelectionState { |
+ INACTIVE, |
+ LONGPRESS_PENDING, |
+ SELECTION_PENDING, |
+ DRAG_PENDING, |
+ DRAGGING |
+ }; |
+ |
+ void SetState(SelectionState state); |
+ |
+ TouchSelectionDraggableClient* const client_; |
+ const float slop_length_; |
+ |
+ SelectionState state_; |
+ |
+ gfx::PointF selection_start_; |
mfomitchev
2015/04/23 21:05:53
Hmm.. this is not DRY (http://en.wikipedia.org/wik
jdduke (slow)
2015/04/27 20:24:25
"DRY" is a guideline, not a religion. I consider t
mfomitchev
2015/04/28 02:17:30
Sorry if I came off as a design snob, I guess it's
jdduke (slow)
2015/04/28 20:37:48
Too late :) It's possible we already needed OnLong
|
+ gfx::PointF selection_end_; |
+ |
+ gfx::PointF longpress_drag_start_position_; |
+ gfx::Vector2dF longpress_drag_selection_offset_; |
+ |
+ base::TimeTicks touch_down_time_; |
+ gfx::PointF touch_down_position_; |
+}; |
+ |
+} // namespace ui |
+ |
+#endif // UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_ |