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

Side by Side Diff: content/browser/renderer_host/input/stylus_text_selector.cc

Issue 2885243003: [Android] Introduce state machine in stylus text selection (Closed)
Patch Set: Fixed the review comments related to naming and other issues. Created 3 years, 7 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
« no previous file with comments | « content/browser/renderer_host/input/stylus_text_selector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/input/stylus_text_selector.h" 5 #include "content/browser/renderer_host/input/stylus_text_selector.h"
6 6
7 #include "ui/events/event_constants.h" 7 #include "ui/events/event_constants.h"
8 #include "ui/events/gesture_detection/gesture_detector.h" 8 #include "ui/events/gesture_detection/gesture_detector.h"
9 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" 9 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
10 #include "ui/events/gesture_detection/motion_event.h" 10 #include "ui/events/gesture_detection/motion_event.h"
(...skipping 21 matching lines...) Expand all
32 32
33 return detector; 33 return detector;
34 } 34 }
35 35
36 } // namespace 36 } // namespace
37 37
38 StylusTextSelector::StylusTextSelector(StylusTextSelectorClient* client) 38 StylusTextSelector::StylusTextSelector(StylusTextSelectorClient* client)
39 : client_(client), 39 : client_(client),
40 text_selection_triggered_(false), 40 text_selection_triggered_(false),
41 secondary_button_pressed_(false), 41 secondary_button_pressed_(false),
42 dragging_(false), 42 drag_state_(NO_DRAG),
43 dragged_(false),
44 anchor_x_(0.0f), 43 anchor_x_(0.0f),
45 anchor_y_(0.0f) { 44 anchor_y_(0.0f) {
46 DCHECK(client); 45 DCHECK(client);
47 } 46 }
48 47
49 StylusTextSelector::~StylusTextSelector() { 48 StylusTextSelector::~StylusTextSelector() {
50 } 49 }
51 50
52 bool StylusTextSelector::OnTouchEvent(const MotionEvent& event) { 51 bool StylusTextSelector::OnTouchEvent(const MotionEvent& event) {
53 // Only trigger selection on ACTION_DOWN to prevent partial touch or gesture 52 // Only trigger selection on ACTION_DOWN to prevent partial touch or gesture
54 // sequences from being forwarded. 53 // sequences from being forwarded.
55 if (event.GetAction() == MotionEvent::ACTION_DOWN) 54 if (event.GetAction() == MotionEvent::ACTION_DOWN)
56 text_selection_triggered_ = ShouldStartTextSelection(event); 55 text_selection_triggered_ = ShouldStartTextSelection(event);
57 56
58 if (!text_selection_triggered_) 57 if (!text_selection_triggered_)
59 return false; 58 return false;
60 59
61 secondary_button_pressed_ = 60 secondary_button_pressed_ =
62 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY; 61 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY;
63 62
64 switch (event.GetAction()) { 63 switch (event.GetAction()) {
65 case MotionEvent::ACTION_DOWN: 64 case MotionEvent::ACTION_DOWN:
66 dragging_ = false; 65 drag_state_ = NO_DRAG;
67 dragged_ = false;
68 anchor_x_ = event.GetX(); 66 anchor_x_ = event.GetX();
69 anchor_y_ = event.GetY(); 67 anchor_y_ = event.GetY();
70 break; 68 break;
71 69
72 case MotionEvent::ACTION_MOVE: 70 case MotionEvent::ACTION_MOVE:
73 if (!secondary_button_pressed_) { 71 if (!secondary_button_pressed_) {
74 dragging_ = false; 72 if (drag_state_ == DRAGGING_WITH_BUTTON_PRESSED)
73 drag_state_ = DRAGGING_WITH_BUTTON_RELEASED;
75 anchor_x_ = event.GetX(); 74 anchor_x_ = event.GetX();
76 anchor_y_ = event.GetY(); 75 anchor_y_ = event.GetY();
77 } 76 }
78 break; 77 break;
79 78
80 case MotionEvent::ACTION_UP: 79 case MotionEvent::ACTION_UP:
81 case MotionEvent::ACTION_CANCEL: 80 case MotionEvent::ACTION_CANCEL:
82 if (dragged_) 81 if (drag_state_ == DRAGGING_WITH_BUTTON_PRESSED ||
82 drag_state_ == DRAGGING_WITH_BUTTON_RELEASED)
83 client_->OnStylusSelectEnd(); 83 client_->OnStylusSelectEnd();
84 dragged_ = false; 84 drag_state_ = NO_DRAG;
85 dragging_ = false;
86 break; 85 break;
87 86
88 case MotionEvent::ACTION_POINTER_UP: 87 case MotionEvent::ACTION_POINTER_UP:
89 case MotionEvent::ACTION_POINTER_DOWN: 88 case MotionEvent::ACTION_POINTER_DOWN:
90 break; 89 break;
91 case MotionEvent::ACTION_NONE: 90 case MotionEvent::ACTION_NONE:
92 case MotionEvent::ACTION_HOVER_ENTER: 91 case MotionEvent::ACTION_HOVER_ENTER:
93 case MotionEvent::ACTION_HOVER_EXIT: 92 case MotionEvent::ACTION_HOVER_EXIT:
94 case MotionEvent::ACTION_HOVER_MOVE: 93 case MotionEvent::ACTION_HOVER_MOVE:
95 case MotionEvent::ACTION_BUTTON_PRESS: 94 case MotionEvent::ACTION_BUTTON_PRESS:
96 case MotionEvent::ACTION_BUTTON_RELEASE: 95 case MotionEvent::ACTION_BUTTON_RELEASE:
97 NOTREACHED(); 96 NOTREACHED();
98 break; 97 break;
99 } 98 }
100 99
101 if (!gesture_detector_) 100 if (!gesture_detector_)
102 gesture_detector_ = CreateGestureDetector(this); 101 gesture_detector_ = CreateGestureDetector(this);
103 102
104 gesture_detector_->OnTouchEvent(event); 103 gesture_detector_->OnTouchEvent(event);
105 104
106 // Always return true, even if |gesture_detector_| technically doesn't 105 // Always return true, even if |gesture_detector_| technically doesn't
107 // consume the event. This prevents forwarding of a partial touch stream. 106 // consume the event. This prevents forwarding of a partial touch stream.
108 return true; 107 return true;
109 } 108 }
110 109
111 bool StylusTextSelector::OnSingleTapUp(const MotionEvent& e, int tap_count) { 110 bool StylusTextSelector::OnSingleTapUp(const MotionEvent& e, int tap_count) {
112 DCHECK(text_selection_triggered_); 111 DCHECK(text_selection_triggered_);
113 DCHECK(!dragging_); 112 DCHECK_NE(DRAGGING_WITH_BUTTON_PRESSED, drag_state_);
114 client_->OnStylusSelectTap(e.GetEventTime(), e.GetX(), e.GetY()); 113 client_->OnStylusSelectTap(e.GetEventTime(), e.GetX(), e.GetY());
115 return true; 114 return true;
116 } 115 }
117 116
118 bool StylusTextSelector::OnScroll(const MotionEvent& e1, 117 bool StylusTextSelector::OnScroll(const MotionEvent& e1,
119 const MotionEvent& e2, 118 const MotionEvent& e2,
120 const MotionEvent& secondary_pointer_down, 119 const MotionEvent& secondary_pointer_down,
121 float distance_x, 120 float distance_x,
122 float distance_y) { 121 float distance_y) {
123 DCHECK(text_selection_triggered_); 122 DCHECK(text_selection_triggered_);
124 123
125 // Return if Stylus button is not pressed. 124 // Return if Stylus button is not pressed.
126 if (!secondary_button_pressed_) 125 if (!secondary_button_pressed_)
127 return true; 126 return true;
128 127
129 if (!dragging_) { 128 if (drag_state_ == NO_DRAG || drag_state_ == DRAGGING_WITH_BUTTON_RELEASED) {
130 dragging_ = true; 129 drag_state_ = DRAGGING_WITH_BUTTON_PRESSED;
131 dragged_ = true;
132 client_->OnStylusSelectBegin(anchor_x_, anchor_y_, e2.GetX(), e2.GetY()); 130 client_->OnStylusSelectBegin(anchor_x_, anchor_y_, e2.GetX(), e2.GetY());
133 } else { 131 } else {
134 client_->OnStylusSelectUpdate(e2.GetX(), e2.GetY()); 132 client_->OnStylusSelectUpdate(e2.GetX(), e2.GetY());
135 } 133 }
136 134
137 return true; 135 return true;
138 } 136 }
139 137
140 // static 138 // static
141 bool StylusTextSelector::ShouldStartTextSelection(const MotionEvent& event) { 139 bool StylusTextSelector::ShouldStartTextSelection(const MotionEvent& event) {
142 DCHECK_GT(event.GetPointerCount(), 0u); 140 DCHECK_GT(event.GetPointerCount(), 0u);
143 // Currently we are supporting stylus-only cases. 141 // Currently we are supporting stylus-only cases.
144 const bool is_stylus = event.GetToolType(0) == MotionEvent::TOOL_TYPE_STYLUS; 142 const bool is_stylus = event.GetToolType(0) == MotionEvent::TOOL_TYPE_STYLUS;
145 const bool is_only_secondary_button_pressed = 143 const bool is_only_secondary_button_pressed =
146 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY; 144 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY;
147 return is_stylus && is_only_secondary_button_pressed; 145 return is_stylus && is_only_secondary_button_pressed;
148 } 146 }
149 147
150 } // namespace content 148 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/stylus_text_selector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698