Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: ui/touch_selection/longpress_drag_selector.h

Issue 1087893003: Support longpress drag selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Factor out logic Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_
6 #define UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_
7
8 #include "base/time/time.h"
9 #include "ui/gfx/geometry/point_f.h"
10 #include "ui/gfx/geometry/vector2d_f.h"
11 #include "ui/touch_selection/touch_selection_draggable.h"
12 #include "ui/touch_selection/ui_touch_selection_export.h"
13
14 namespace ui {
15
16 class MotionEvent;
17
18 // Supports text selection via touch dragging after a longpress-initiated
19 // selection.
20 class UI_TOUCH_SELECTION_EXPORT LongPressDragSelector
21 : public TouchSelectionDraggable {
22 public:
23 LongPressDragSelector(TouchSelectionDraggableClient* client,
24 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).
25 ~LongPressDragSelector() override;
26
27 // Allows selection dragging after a long-press initiated selection. Returns
28 // true if the event was consumed, in which case the caller should cease
29 // further handling.
30 bool WillHandleTouchEvent(const MotionEvent& event);
31
32 // Called when a longpress event is observed, before any of its side effects
33 // (e.g., selection activation) have been realized.
34 void OnLongPressEvent(base::TimeTicks event_time,
35 const gfx::PointF& position);
36
37 // Called when the active selection changes.
38 void OnSelectionActivated(const gfx::PointF& start, const gfx::PointF& end);
39 void OnSelectionDeactivated();
40
41 // Whether a drag is active or being detected for the current touch sequence.
42 bool IsActive() const;
43
44 private:
45 enum SelectionState {
46 INACTIVE,
47 LONGPRESS_PENDING,
48 SELECTION_PENDING,
49 DRAG_PENDING,
50 DRAGGING
51 };
52
53 void SetState(SelectionState state);
54
55 TouchSelectionDraggableClient* const client_;
56 const float slop_length_;
57
58 SelectionState state_;
59
60 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
61 gfx::PointF selection_end_;
62
63 gfx::PointF longpress_drag_start_position_;
64 gfx::Vector2dF longpress_drag_selection_offset_;
65
66 base::TimeTicks touch_down_time_;
67 gfx::PointF touch_down_position_;
68 };
69
70 } // namespace ui
71
72 #endif // UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698