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

Side by Side Diff: ui/touch_selection/touch_selection_controller.cc

Issue 996373002: Add Aura handles to be used in unified touch selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments Created 5 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
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 "ui/touch_selection/touch_selection_controller.h" 5 #include "ui/touch_selection/touch_selection_controller.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 base::TimeDelta tap_timeout, 45 base::TimeDelta tap_timeout,
46 float tap_slop, 46 float tap_slop,
47 bool show_on_tap_for_empty_editable) 47 bool show_on_tap_for_empty_editable)
48 : client_(client), 48 : client_(client),
49 tap_timeout_(tap_timeout), 49 tap_timeout_(tap_timeout),
50 tap_slop_(tap_slop), 50 tap_slop_(tap_slop),
51 show_on_tap_for_empty_editable_(show_on_tap_for_empty_editable), 51 show_on_tap_for_empty_editable_(show_on_tap_for_empty_editable),
52 response_pending_input_event_(INPUT_EVENT_TYPE_NONE), 52 response_pending_input_event_(INPUT_EVENT_TYPE_NONE),
53 start_orientation_(TouchHandleOrientation::UNDEFINED), 53 start_orientation_(TouchHandleOrientation::UNDEFINED),
54 end_orientation_(TouchHandleOrientation::UNDEFINED), 54 end_orientation_(TouchHandleOrientation::UNDEFINED),
55 is_insertion_active_(false), 55 active_status_(INACTIVE),
56 activate_insertion_automatically_(false), 56 activate_insertion_automatically_(false),
57 is_selection_active_(false),
58 activate_selection_automatically_(false), 57 activate_selection_automatically_(false),
59 selection_empty_(false), 58 selection_empty_(false),
60 selection_editable_(false), 59 selection_editable_(false),
61 temporarily_hidden_(false), 60 temporarily_hidden_(false),
62 selection_handle_dragged_(false) { 61 selection_handle_dragged_(false) {
63 DCHECK(client_); 62 DCHECK(client_);
64 } 63 }
65 64
66 TouchSelectionController::~TouchSelectionController() { 65 TouchSelectionController::~TouchSelectionController() {
67 } 66 }
68 67
69 void TouchSelectionController::OnSelectionBoundsChanged( 68 void TouchSelectionController::OnSelectionBoundsChanged(
70 const SelectionBound& start, 69 const SelectionBound& start,
71 const SelectionBound& end) { 70 const SelectionBound& end) {
72 if (start == start_ && end_ == end) 71 if (start == start_ && end_ == end)
73 return; 72 return;
74 73
75 start_ = start; 74 start_ = start;
76 end_ = end; 75 end_ = end;
77 start_orientation_ = ToTouchHandleOrientation(start_.type()); 76 start_orientation_ = ToTouchHandleOrientation(start_.type());
78 end_orientation_ = ToTouchHandleOrientation(end_.type()); 77 end_orientation_ = ToTouchHandleOrientation(end_.type());
79 78
80 if (!activate_selection_automatically_ && 79 if (!activate_selection_automatically_ &&
81 !activate_insertion_automatically_) { 80 !activate_insertion_automatically_) {
82 DCHECK(!is_insertion_active_); 81 DCHECK_EQ(INACTIVE, active_status_);
83 DCHECK(!is_selection_active_);
84 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); 82 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_);
85 return; 83 return;
86 } 84 }
87 85
88 // Ensure that |response_pending_input_event_| is cleared after the method 86 // Ensure that |response_pending_input_event_| is cleared after the method
89 // completes, while also making its current value available for the duration 87 // completes, while also making its current value available for the duration
90 // of the call. 88 // of the call.
91 InputEventType causal_input_event = response_pending_input_event_; 89 InputEventType causal_input_event = response_pending_input_event_;
92 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 90 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
93 base::AutoReset<InputEventType> auto_reset_response_pending_input_event( 91 base::AutoReset<InputEventType> auto_reset_response_pending_input_event(
94 &response_pending_input_event_, causal_input_event); 92 &response_pending_input_event_, causal_input_event);
95 93
96 const bool is_selection_dragging = 94 const bool is_selection_dragging = active_status_ == SELECTION_ACTIVE &&
97 is_selection_active_ && (start_selection_handle_->is_dragging() || 95 (start_selection_handle_->is_dragging() ||
98 end_selection_handle_->is_dragging()); 96 end_selection_handle_->is_dragging());
99 97
100 // It's possible that the bounds temporarily overlap while a selection handle 98 // It's possible that the bounds temporarily overlap while a selection handle
101 // is being dragged, incorrectly reporting a CENTER orientation. 99 // is being dragged, incorrectly reporting a CENTER orientation.
102 // TODO(jdduke): This safeguard is racy, as it's possible the delayed response 100 // TODO(jdduke): This safeguard is racy, as it's possible the delayed response
103 // from handle positioning occurs *after* the handle dragging has ceased. 101 // from handle positioning occurs *after* the handle dragging has ceased.
104 // Instead, prevent selection -> insertion transitions without an intervening 102 // Instead, prevent selection -> insertion transitions without an intervening
105 // action or selection clearing of some sort, crbug.com/392696. 103 // action or selection clearing of some sort, crbug.com/392696.
106 if (is_selection_dragging) { 104 if (is_selection_dragging) {
107 if (start_orientation_ == TouchHandleOrientation::CENTER) 105 if (start_orientation_ == TouchHandleOrientation::CENTER)
108 start_orientation_ = start_selection_handle_->orientation(); 106 start_orientation_ = start_selection_handle_->orientation();
(...skipping 12 matching lines...) Expand all
121 if (start_orientation_ == TouchHandleOrientation::CENTER && 119 if (start_orientation_ == TouchHandleOrientation::CENTER &&
122 selection_editable_) { 120 selection_editable_) {
123 OnInsertionChanged(); 121 OnInsertionChanged();
124 return; 122 return;
125 } 123 }
126 124
127 HideAndDisallowShowingAutomatically(); 125 HideAndDisallowShowingAutomatically();
128 } 126 }
129 127
130 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { 128 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) {
131 if (is_insertion_active_) { 129 if (active_status_ == INSERTION_ACTIVE) {
132 DCHECK(insertion_handle_); 130 DCHECK(insertion_handle_);
133 return insertion_handle_->WillHandleTouchEvent(event); 131 return insertion_handle_->WillHandleTouchEvent(event);
134 } 132 }
135 133
136 if (is_selection_active_) { 134 if (active_status_ == SELECTION_ACTIVE) {
137 DCHECK(start_selection_handle_); 135 DCHECK(start_selection_handle_);
138 DCHECK(end_selection_handle_); 136 DCHECK(end_selection_handle_);
139 if (start_selection_handle_->is_dragging()) 137 if (start_selection_handle_->is_dragging())
140 return start_selection_handle_->WillHandleTouchEvent(event); 138 return start_selection_handle_->WillHandleTouchEvent(event);
141 139
142 if (end_selection_handle_->is_dragging()) 140 if (end_selection_handle_->is_dragging())
143 return end_selection_handle_->WillHandleTouchEvent(event); 141 return end_selection_handle_->WillHandleTouchEvent(event);
144 142
145 const gfx::PointF event_pos(event.GetX(), event.GetY()); 143 const gfx::PointF event_pos(event.GetX(), event.GetY());
146 if ((event_pos - GetStartPosition()).LengthSquared() <= 144 if ((event_pos - GetStartPosition()).LengthSquared() <=
147 (event_pos - GetEndPosition()).LengthSquared()) 145 (event_pos - GetEndPosition()).LengthSquared()) {
148 return start_selection_handle_->WillHandleTouchEvent(event); 146 return start_selection_handle_->WillHandleTouchEvent(event);
149 else 147 }
150 return end_selection_handle_->WillHandleTouchEvent(event); 148 return end_selection_handle_->WillHandleTouchEvent(event);
151 } 149 }
152 150
153 return false; 151 return false;
154 } 152 }
155 153
156 void TouchSelectionController::OnLongPressEvent() { 154 void TouchSelectionController::OnLongPressEvent() {
157 response_pending_input_event_ = LONG_PRESS; 155 response_pending_input_event_ = LONG_PRESS;
158 ShowSelectionHandlesAutomatically(); 156 ShowSelectionHandlesAutomatically();
159 ShowInsertionHandleAutomatically(); 157 ShowInsertionHandleAutomatically();
160 ResetCachedValuesIfInactive(); 158 ResetCachedValuesIfInactive();
161 } 159 }
162 160
163 void TouchSelectionController::AllowShowingFromCurrentSelection() { 161 void TouchSelectionController::AllowShowingFromCurrentSelection() {
164 if (is_selection_active_ || is_insertion_active_) 162 if (active_status_ != INACTIVE)
165 return; 163 return;
166 164
167 activate_selection_automatically_ = true; 165 activate_selection_automatically_ = true;
168 activate_insertion_automatically_ = true; 166 activate_insertion_automatically_ = true;
169 if (GetStartPosition() != GetEndPosition()) 167 if (GetStartPosition() != GetEndPosition()) {
170 OnSelectionChanged(); 168 OnSelectionChanged();
171 else if (start_orientation_ == TouchHandleOrientation::CENTER && 169 } else if (start_orientation_ == TouchHandleOrientation::CENTER &&
172 selection_editable_) 170 selection_editable_) {
173 OnInsertionChanged(); 171 OnInsertionChanged();
172 }
174 } 173 }
175 174
176 void TouchSelectionController::OnTapEvent() { 175 void TouchSelectionController::OnTapEvent() {
177 response_pending_input_event_ = TAP; 176 response_pending_input_event_ = TAP;
178 if (!is_selection_active_) 177 if (active_status_ != SELECTION_ACTIVE)
179 activate_selection_automatically_ = false; 178 activate_selection_automatically_ = false;
180 ShowInsertionHandleAutomatically(); 179 ShowInsertionHandleAutomatically();
181 if (selection_empty_ && !show_on_tap_for_empty_editable_) 180 if (selection_empty_ && !show_on_tap_for_empty_editable_)
182 DeactivateInsertion(); 181 DeactivateInsertion();
183 ResetCachedValuesIfInactive(); 182 ResetCachedValuesIfInactive();
184 } 183 }
185 184
186 void TouchSelectionController::HideAndDisallowShowingAutomatically() { 185 void TouchSelectionController::HideAndDisallowShowingAutomatically() {
187 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 186 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
188 DeactivateInsertion(); 187 DeactivateInsertion();
189 DeactivateSelection(); 188 DeactivateSelection();
190 activate_insertion_automatically_ = false; 189 activate_insertion_automatically_ = false;
191 activate_selection_automatically_ = false; 190 activate_selection_automatically_ = false;
192 } 191 }
193 192
194 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { 193 void TouchSelectionController::SetTemporarilyHidden(bool hidden) {
195 if (temporarily_hidden_ == hidden) 194 if (temporarily_hidden_ == hidden)
196 return; 195 return;
197 temporarily_hidden_ = hidden; 196 temporarily_hidden_ = hidden;
198 197
199 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); 198 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true);
200 if (is_selection_active_) { 199 if (active_status_ == SELECTION_ACTIVE) {
201 start_selection_handle_->SetVisible(GetStartVisible(), animation_style); 200 start_selection_handle_->SetVisible(GetStartVisible(), animation_style);
202 end_selection_handle_->SetVisible(GetEndVisible(), animation_style); 201 end_selection_handle_->SetVisible(GetEndVisible(), animation_style);
202 } else if (active_status_ == INSERTION_ACTIVE) {
203 insertion_handle_->SetVisible(GetStartVisible(), animation_style);
203 } 204 }
204 if (is_insertion_active_)
205 insertion_handle_->SetVisible(GetStartVisible(), animation_style);
206 } 205 }
207 206
208 void TouchSelectionController::OnSelectionEditable(bool editable) { 207 void TouchSelectionController::OnSelectionEditable(bool editable) {
209 if (selection_editable_ == editable) 208 if (selection_editable_ == editable)
210 return; 209 return;
211 selection_editable_ = editable; 210 selection_editable_ = editable;
212 ResetCachedValuesIfInactive(); 211 ResetCachedValuesIfInactive();
213 if (!selection_editable_) 212 if (!selection_editable_)
214 DeactivateInsertion(); 213 DeactivateInsertion();
215 } 214 }
216 215
217 void TouchSelectionController::OnSelectionEmpty(bool empty) { 216 void TouchSelectionController::OnSelectionEmpty(bool empty) {
218 if (selection_empty_ == empty) 217 if (selection_empty_ == empty)
219 return; 218 return;
220 selection_empty_ = empty; 219 selection_empty_ = empty;
221 ResetCachedValuesIfInactive(); 220 ResetCachedValuesIfInactive();
222 } 221 }
223 222
224 bool TouchSelectionController::Animate(base::TimeTicks frame_time) { 223 bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
225 if (is_insertion_active_) 224 if (active_status_ == INSERTION_ACTIVE)
226 return insertion_handle_->Animate(frame_time); 225 return insertion_handle_->Animate(frame_time);
227 226
228 if (is_selection_active_) { 227 if (active_status_ == SELECTION_ACTIVE) {
229 bool needs_animate = start_selection_handle_->Animate(frame_time); 228 bool needs_animate = start_selection_handle_->Animate(frame_time);
230 needs_animate |= end_selection_handle_->Animate(frame_time); 229 needs_animate |= end_selection_handle_->Animate(frame_time);
231 return needs_animate; 230 return needs_animate;
232 } 231 }
233 232
234 return false; 233 return false;
235 } 234 }
236 235
237 gfx::RectF TouchSelectionController::GetRectBetweenBounds() const { 236 gfx::RectF TouchSelectionController::GetRectBetweenBounds() const {
238 // Short-circuit for efficiency. 237 // Short-circuit for efficiency.
239 if (!is_insertion_active_ && !is_selection_active_) 238 if (active_status_ == INACTIVE)
240 return gfx::RectF(); 239 return gfx::RectF();
241 240
242 if (start_.visible() && !end_.visible()) 241 if (start_.visible() && !end_.visible())
243 return gfx::BoundingRect(start_.edge_top(), start_.edge_bottom()); 242 return gfx::BoundingRect(start_.edge_top(), start_.edge_bottom());
244 243
245 if (end_.visible() && !start_.visible()) 244 if (end_.visible() && !start_.visible())
246 return gfx::BoundingRect(end_.edge_top(), end_.edge_bottom()); 245 return gfx::BoundingRect(end_.edge_top(), end_.edge_bottom());
247 246
248 // If both handles are visible, or both are invisible, use the entire rect. 247 // If both handles are visible, or both are invisible, use the entire rect.
249 return RectFBetweenSelectionBounds(start_, end_); 248 return RectFBetweenSelectionBounds(start_, end_);
250 } 249 }
251 250
252 gfx::RectF TouchSelectionController::GetStartHandleRect() const { 251 gfx::RectF TouchSelectionController::GetStartHandleRect() const {
253 if (is_insertion_active_) 252 if (active_status_ == INSERTION_ACTIVE)
254 return insertion_handle_->GetVisibleBounds(); 253 return insertion_handle_->GetVisibleBounds();
255 if (is_selection_active_) 254 if (active_status_ == SELECTION_ACTIVE)
256 return start_selection_handle_->GetVisibleBounds(); 255 return start_selection_handle_->GetVisibleBounds();
257 return gfx::RectF(); 256 return gfx::RectF();
258 } 257 }
259 258
260 gfx::RectF TouchSelectionController::GetEndHandleRect() const { 259 gfx::RectF TouchSelectionController::GetEndHandleRect() const {
261 if (is_insertion_active_) 260 if (active_status_ == INSERTION_ACTIVE)
262 return insertion_handle_->GetVisibleBounds(); 261 return insertion_handle_->GetVisibleBounds();
263 if (is_selection_active_) 262 if (active_status_ == SELECTION_ACTIVE)
264 return end_selection_handle_->GetVisibleBounds(); 263 return end_selection_handle_->GetVisibleBounds();
265 return gfx::RectF(); 264 return gfx::RectF();
266 } 265 }
267 266
268 const gfx::PointF& TouchSelectionController::GetStartPosition() const { 267 const gfx::PointF& TouchSelectionController::GetStartPosition() const {
269 return start_.edge_bottom(); 268 return start_.edge_bottom();
270 } 269 }
271 270
272 const gfx::PointF& TouchSelectionController::GetEndPosition() const { 271 const gfx::PointF& TouchSelectionController::GetEndPosition() const {
273 return end_.edge_bottom(); 272 return end_.edge_bottom();
(...skipping 22 matching lines...) Expand all
296 } 295 }
297 296
298 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, 297 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle,
299 const gfx::PointF& position) { 298 const gfx::PointF& position) {
300 // As the position corresponds to the bottom left point of the selection 299 // As the position corresponds to the bottom left point of the selection
301 // bound, offset it by half the corresponding line height. 300 // bound, offset it by half the corresponding line height.
302 gfx::Vector2dF line_offset = &handle == start_selection_handle_.get() 301 gfx::Vector2dF line_offset = &handle == start_selection_handle_.get()
303 ? GetStartLineOffset() 302 ? GetStartLineOffset()
304 : GetEndLineOffset(); 303 : GetEndLineOffset();
305 gfx::PointF line_position = position + line_offset; 304 gfx::PointF line_position = position + line_offset;
306 if (&handle == insertion_handle_.get()) { 305 if (&handle == insertion_handle_.get())
307 client_->MoveCaret(line_position); 306 client_->MoveCaret(line_position);
308 } else { 307 else
309 client_->MoveRangeSelectionExtent(line_position); 308 client_->MoveRangeSelectionExtent(line_position);
310 }
311 } 309 }
312 310
313 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { 311 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) {
314 if (&handle == insertion_handle_.get()) 312 if (&handle == insertion_handle_.get())
315 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED); 313 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED);
316 else 314 else
317 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED); 315 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED);
318 } 316 }
319 317
320 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { 318 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 355
358 if (response_pending_input_event_ == TAP && selection_empty_ && 356 if (response_pending_input_event_ == TAP && selection_empty_ &&
359 !show_on_tap_for_empty_editable_) { 357 !show_on_tap_for_empty_editable_) {
360 HideAndDisallowShowingAutomatically(); 358 HideAndDisallowShowingAutomatically();
361 return; 359 return;
362 } 360 }
363 361
364 if (!activate_insertion_automatically_) 362 if (!activate_insertion_automatically_)
365 return; 363 return;
366 364
367 const bool was_active = is_insertion_active_; 365 const bool was_active = active_status_ == INSERTION_ACTIVE;
368 const gfx::PointF position = GetStartPosition(); 366 const gfx::PointF position = GetStartPosition();
369 if (!is_insertion_active_) 367 if (!was_active)
370 ActivateInsertion(); 368 ActivateInsertion();
371 else 369 else
372 client_->OnSelectionEvent(INSERTION_MOVED); 370 client_->OnSelectionEvent(INSERTION_MOVED);
373 371
374 insertion_handle_->SetVisible(GetStartVisible(), 372 insertion_handle_->SetVisible(GetStartVisible(),
375 GetAnimationStyle(was_active)); 373 GetAnimationStyle(was_active));
376 insertion_handle_->SetPosition(position); 374 insertion_handle_->SetPosition(position);
377 } 375 }
378 376
379 void TouchSelectionController::OnSelectionChanged() { 377 void TouchSelectionController::OnSelectionChanged() {
380 DeactivateInsertion(); 378 DeactivateInsertion();
381 379
382 if (!activate_selection_automatically_) 380 if (!activate_selection_automatically_)
383 return; 381 return;
384 382
385 const bool was_active = is_selection_active_; 383 const bool was_active = active_status_ == SELECTION_ACTIVE;
386 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) 384 if (!was_active || response_pending_input_event_ == LONG_PRESS)
387 ActivateSelection(); 385 ActivateSelection();
388 else 386 else
389 client_->OnSelectionEvent(SELECTION_MOVED); 387 client_->OnSelectionEvent(SELECTION_MOVED);
390 388
391 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); 389 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active);
392 start_selection_handle_->SetVisible(GetStartVisible(), animation); 390 start_selection_handle_->SetVisible(GetStartVisible(), animation);
393 end_selection_handle_->SetVisible(GetEndVisible(), animation); 391 end_selection_handle_->SetVisible(GetEndVisible(), animation);
394 392
395 start_selection_handle_->SetPosition(GetStartPosition()); 393 start_selection_handle_->SetPosition(GetStartPosition());
396 end_selection_handle_->SetPosition(GetEndPosition()); 394 end_selection_handle_->SetPosition(GetEndPosition());
397 } 395 }
398 396
399 void TouchSelectionController::ActivateInsertion() { 397 void TouchSelectionController::ActivateInsertion() {
400 DCHECK(!is_selection_active_); 398 DCHECK_NE(SELECTION_ACTIVE, active_status_);
401 399
402 if (!insertion_handle_) 400 if (!insertion_handle_)
403 insertion_handle_.reset( 401 insertion_handle_.reset(
404 new TouchHandle(this, TouchHandleOrientation::CENTER)); 402 new TouchHandle(this, TouchHandleOrientation::CENTER));
405 403
406 if (!is_insertion_active_) { 404 if (active_status_ == INACTIVE) {
407 is_insertion_active_ = true; 405 active_status_ = INSERTION_ACTIVE;
408 insertion_handle_->SetEnabled(true); 406 insertion_handle_->SetEnabled(true);
409 client_->OnSelectionEvent(INSERTION_SHOWN); 407 client_->OnSelectionEvent(INSERTION_SHOWN);
410 } 408 }
411 } 409 }
412 410
413 void TouchSelectionController::DeactivateInsertion() { 411 void TouchSelectionController::DeactivateInsertion() {
414 if (!is_insertion_active_) 412 if (active_status_ != INSERTION_ACTIVE)
415 return; 413 return;
416 DCHECK(insertion_handle_); 414 DCHECK(insertion_handle_);
417 is_insertion_active_ = false; 415 active_status_ = INACTIVE;
418 insertion_handle_->SetEnabled(false); 416 insertion_handle_->SetEnabled(false);
419 client_->OnSelectionEvent(INSERTION_CLEARED); 417 client_->OnSelectionEvent(INSERTION_CLEARED);
420 } 418 }
421 419
422 void TouchSelectionController::ActivateSelection() { 420 void TouchSelectionController::ActivateSelection() {
423 DCHECK(!is_insertion_active_); 421 DCHECK_NE(INSERTION_ACTIVE, active_status_);
424 422
425 if (!start_selection_handle_) { 423 if (!start_selection_handle_) {
426 start_selection_handle_.reset(new TouchHandle(this, start_orientation_)); 424 start_selection_handle_.reset(new TouchHandle(this, start_orientation_));
427 } else { 425 } else {
428 start_selection_handle_->SetEnabled(true); 426 start_selection_handle_->SetEnabled(true);
429 start_selection_handle_->SetOrientation(start_orientation_); 427 start_selection_handle_->SetOrientation(start_orientation_);
430 } 428 }
431 429
432 if (!end_selection_handle_) { 430 if (!end_selection_handle_) {
433 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); 431 end_selection_handle_.reset(new TouchHandle(this, end_orientation_));
434 } else { 432 } else {
435 end_selection_handle_->SetEnabled(true); 433 end_selection_handle_->SetEnabled(true);
436 end_selection_handle_->SetOrientation(end_orientation_); 434 end_selection_handle_->SetOrientation(end_orientation_);
437 } 435 }
438 436
439 // As a long press received while a selection is already active may trigger 437 // As a long press received while a selection is already active may trigger
440 // an entirely new selection, notify the client but avoid sending an 438 // an entirely new selection, notify the client but avoid sending an
441 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. 439 // intervening SELECTION_CLEARED update to avoid unnecessary state changes.
442 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { 440 if (active_status_ == INACTIVE ||
443 if (is_selection_active_) { 441 response_pending_input_event_ == LONG_PRESS) {
442 if (active_status_ == SELECTION_ACTIVE) {
444 // The active selection session finishes with the start of the new one. 443 // The active selection session finishes with the start of the new one.
445 LogSelectionEnd(); 444 LogSelectionEnd();
446 } 445 }
447 is_selection_active_ = true; 446 active_status_ = SELECTION_ACTIVE;
448 selection_handle_dragged_ = false; 447 selection_handle_dragged_ = false;
449 selection_start_time_ = base::TimeTicks::Now(); 448 selection_start_time_ = base::TimeTicks::Now();
450 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 449 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
451 client_->OnSelectionEvent(SELECTION_SHOWN); 450 client_->OnSelectionEvent(SELECTION_SHOWN);
452 } 451 }
453 } 452 }
454 453
455 void TouchSelectionController::DeactivateSelection() { 454 void TouchSelectionController::DeactivateSelection() {
456 if (!is_selection_active_) 455 if (active_status_ != SELECTION_ACTIVE)
457 return; 456 return;
458 DCHECK(start_selection_handle_); 457 DCHECK(start_selection_handle_);
459 DCHECK(end_selection_handle_); 458 DCHECK(end_selection_handle_);
460 LogSelectionEnd(); 459 LogSelectionEnd();
461 start_selection_handle_->SetEnabled(false); 460 start_selection_handle_->SetEnabled(false);
462 end_selection_handle_->SetEnabled(false); 461 end_selection_handle_->SetEnabled(false);
463 is_selection_active_ = false; 462 active_status_ = INACTIVE;
464 client_->OnSelectionEvent(SELECTION_CLEARED); 463 client_->OnSelectionEvent(SELECTION_CLEARED);
465 } 464 }
466 465
467 void TouchSelectionController::ResetCachedValuesIfInactive() { 466 void TouchSelectionController::ResetCachedValuesIfInactive() {
468 if (is_selection_active_ || is_insertion_active_) 467 if (active_status_ != INACTIVE)
469 return; 468 return;
470 start_ = SelectionBound(); 469 start_ = SelectionBound();
471 end_ = SelectionBound(); 470 end_ = SelectionBound();
472 start_orientation_ = TouchHandleOrientation::UNDEFINED; 471 start_orientation_ = TouchHandleOrientation::UNDEFINED;
473 end_orientation_ = TouchHandleOrientation::UNDEFINED; 472 end_orientation_ = TouchHandleOrientation::UNDEFINED;
474 } 473 }
475 474
476 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { 475 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const {
477 return ComputeLineOffsetFromBottom(start_); 476 return ComputeLineOffsetFromBottom(start_);
478 } 477 }
(...skipping 26 matching lines...) Expand all
505 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; 504 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
506 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", 505 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
507 duration, 506 duration,
508 base::TimeDelta::FromMilliseconds(500), 507 base::TimeDelta::FromMilliseconds(500),
509 base::TimeDelta::FromSeconds(60), 508 base::TimeDelta::FromSeconds(60),
510 60); 509 60);
511 } 510 }
512 } 511 }
513 512
514 } // namespace ui 513 } // namespace ui
OLDNEW
« no previous file with comments | « ui/touch_selection/touch_selection_controller.h ('k') | ui/touch_selection/touch_selection_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698