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

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: Added enum for active status 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 }
(...skipping 16 matching lines...) Expand all
84 } 83 }
85 84
86 // Ensure that |response_pending_input_event_| is cleared after the method 85 // Ensure that |response_pending_input_event_| is cleared after the method
87 // completes, while also making its current value available for the duration 86 // completes, while also making its current value available for the duration
88 // of the call. 87 // of the call.
89 InputEventType causal_input_event = response_pending_input_event_; 88 InputEventType causal_input_event = response_pending_input_event_;
90 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 89 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
91 base::AutoReset<InputEventType> auto_reset_response_pending_input_event( 90 base::AutoReset<InputEventType> auto_reset_response_pending_input_event(
92 &response_pending_input_event_, causal_input_event); 91 &response_pending_input_event_, causal_input_event);
93 92
94 const bool is_selection_dragging = 93 const bool is_selection_dragging = active_status_ == SELECTION_ACTIVE &&
95 is_selection_active_ && (start_selection_handle_->is_dragging() || 94 (start_selection_handle_->is_dragging() ||
96 end_selection_handle_->is_dragging()); 95 end_selection_handle_->is_dragging());
97 96
98 // It's possible that the bounds temporarily overlap while a selection handle 97 // It's possible that the bounds temporarily overlap while a selection handle
99 // is being dragged, incorrectly reporting a CENTER orientation. 98 // is being dragged, incorrectly reporting a CENTER orientation.
100 // TODO(jdduke): This safeguard is racy, as it's possible the delayed response 99 // TODO(jdduke): This safeguard is racy, as it's possible the delayed response
101 // from handle positioning occurs *after* the handle dragging has ceased. 100 // from handle positioning occurs *after* the handle dragging has ceased.
102 // Instead, prevent selection -> insertion transitions without an intervening 101 // Instead, prevent selection -> insertion transitions without an intervening
103 // action or selection clearing of some sort, crbug.com/392696. 102 // action or selection clearing of some sort, crbug.com/392696.
104 if (is_selection_dragging) { 103 if (is_selection_dragging) {
105 if (start_orientation_ == TouchHandleOrientation::CENTER) 104 if (start_orientation_ == TouchHandleOrientation::CENTER)
106 start_orientation_ = start_selection_handle_->orientation(); 105 start_orientation_ = start_selection_handle_->orientation();
(...skipping 12 matching lines...) Expand all
119 if (start_orientation_ == TouchHandleOrientation::CENTER && 118 if (start_orientation_ == TouchHandleOrientation::CENTER &&
120 selection_editable_) { 119 selection_editable_) {
121 OnInsertionChanged(); 120 OnInsertionChanged();
122 return; 121 return;
123 } 122 }
124 123
125 HideAndDisallowShowingAutomatically(); 124 HideAndDisallowShowingAutomatically();
126 } 125 }
127 126
128 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { 127 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) {
129 if (is_insertion_active_) { 128 if (active_status_ == INSERTION_ACTIVE) {
130 DCHECK(insertion_handle_); 129 DCHECK(insertion_handle_);
131 return insertion_handle_->WillHandleTouchEvent(event); 130 return insertion_handle_->WillHandleTouchEvent(event);
132 } 131 }
133 132
134 if (is_selection_active_) { 133 if (active_status_ == SELECTION_ACTIVE) {
135 DCHECK(start_selection_handle_); 134 DCHECK(start_selection_handle_);
136 DCHECK(end_selection_handle_); 135 DCHECK(end_selection_handle_);
137 if (start_selection_handle_->is_dragging()) 136 if (start_selection_handle_->is_dragging())
138 return start_selection_handle_->WillHandleTouchEvent(event); 137 return start_selection_handle_->WillHandleTouchEvent(event);
139 138
140 if (end_selection_handle_->is_dragging()) 139 if (end_selection_handle_->is_dragging())
141 return end_selection_handle_->WillHandleTouchEvent(event); 140 return end_selection_handle_->WillHandleTouchEvent(event);
142 141
143 const gfx::PointF event_pos(event.GetX(), event.GetY()); 142 const gfx::PointF event_pos(event.GetX(), event.GetY());
144 if ((event_pos - GetStartPosition()).LengthSquared() <= 143 if ((event_pos - GetStartPosition()).LengthSquared() <=
145 (event_pos - GetEndPosition()).LengthSquared()) 144 (event_pos - GetEndPosition()).LengthSquared()) {
146 return start_selection_handle_->WillHandleTouchEvent(event); 145 return start_selection_handle_->WillHandleTouchEvent(event);
147 else 146 }
148 return end_selection_handle_->WillHandleTouchEvent(event); 147 return end_selection_handle_->WillHandleTouchEvent(event);
149 } 148 }
150 149
151 return false; 150 return false;
152 } 151 }
153 152
154 void TouchSelectionController::OnLongPressEvent() { 153 void TouchSelectionController::OnLongPressEvent() {
155 response_pending_input_event_ = LONG_PRESS; 154 response_pending_input_event_ = LONG_PRESS;
156 ShowSelectionHandlesAutomatically(); 155 ShowSelectionHandlesAutomatically();
157 ShowInsertionHandleAutomatically(); 156 ShowInsertionHandleAutomatically();
158 ResetCachedValuesIfInactive(); 157 ResetCachedValuesIfInactive();
159 } 158 }
160 159
161 void TouchSelectionController::AllowShowingFromCurrentSelection() { 160 void TouchSelectionController::AllowShowingFromCurrentSelection() {
162 if (is_selection_active_ || is_insertion_active_) 161 if (active_status_ != INACTIVE)
163 return; 162 return;
164 163
165 activate_selection_automatically_ = true; 164 activate_selection_automatically_ = true;
166 activate_insertion_automatically_ = true; 165 activate_insertion_automatically_ = true;
167 if (GetStartPosition() != GetEndPosition()) 166 if (GetStartPosition() != GetEndPosition())
168 OnSelectionChanged(); 167 OnSelectionChanged();
169 else if (start_orientation_ == TouchHandleOrientation::CENTER && 168 else if (start_orientation_ == TouchHandleOrientation::CENTER &&
170 selection_editable_) 169 selection_editable_)
171 OnInsertionChanged(); 170 OnInsertionChanged();
172 } 171 }
(...skipping 14 matching lines...) Expand all
187 activate_insertion_automatically_ = false; 186 activate_insertion_automatically_ = false;
188 activate_selection_automatically_ = false; 187 activate_selection_automatically_ = false;
189 } 188 }
190 189
191 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { 190 void TouchSelectionController::SetTemporarilyHidden(bool hidden) {
192 if (temporarily_hidden_ == hidden) 191 if (temporarily_hidden_ == hidden)
193 return; 192 return;
194 temporarily_hidden_ = hidden; 193 temporarily_hidden_ = hidden;
195 194
196 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); 195 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true);
197 if (is_selection_active_) { 196 if (active_status_ == SELECTION_ACTIVE) {
198 start_selection_handle_->SetVisible(GetStartVisible(), animation_style); 197 start_selection_handle_->SetVisible(GetStartVisible(), animation_style);
199 end_selection_handle_->SetVisible(GetEndVisible(), animation_style); 198 end_selection_handle_->SetVisible(GetEndVisible(), animation_style);
199 } else if (active_status_ == INSERTION_ACTIVE) {
200 insertion_handle_->SetVisible(GetStartVisible(), animation_style);
200 } 201 }
201 if (is_insertion_active_)
202 insertion_handle_->SetVisible(GetStartVisible(), animation_style);
203 } 202 }
204 203
205 void TouchSelectionController::OnSelectionEditable(bool editable) { 204 void TouchSelectionController::OnSelectionEditable(bool editable) {
206 if (selection_editable_ == editable) 205 if (selection_editable_ == editable)
207 return; 206 return;
208 selection_editable_ = editable; 207 selection_editable_ = editable;
209 ResetCachedValuesIfInactive(); 208 ResetCachedValuesIfInactive();
210 if (!selection_editable_) 209 if (!selection_editable_)
211 DeactivateInsertion(); 210 DeactivateInsertion();
212 } 211 }
213 212
214 void TouchSelectionController::OnSelectionEmpty(bool empty) { 213 void TouchSelectionController::OnSelectionEmpty(bool empty) {
215 if (selection_empty_ == empty) 214 if (selection_empty_ == empty)
216 return; 215 return;
217 selection_empty_ = empty; 216 selection_empty_ = empty;
218 ResetCachedValuesIfInactive(); 217 ResetCachedValuesIfInactive();
219 } 218 }
220 219
220 void TouchSelectionController::OnNativeViewMoved() {
221 if (active_status_ == SELECTION_ACTIVE)
222 client_->OnSelectionEvent(SELECTION_MOVED);
jdduke (slow) 2015/05/07 20:38:15 Have we come to a conclusion on whether this is st
mohsen 2015/05/07 21:21:55 This is here for the case where user drags a windo
223 else if (active_status_ == INSERTION_ACTIVE)
224 client_->OnSelectionEvent(INSERTION_MOVED);
225 }
226
221 bool TouchSelectionController::Animate(base::TimeTicks frame_time) { 227 bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
222 if (is_insertion_active_) 228 if (active_status_ == INSERTION_ACTIVE)
223 return insertion_handle_->Animate(frame_time); 229 return insertion_handle_->Animate(frame_time);
224 230
225 if (is_selection_active_) { 231 if (active_status_ == SELECTION_ACTIVE) {
226 bool needs_animate = start_selection_handle_->Animate(frame_time); 232 bool needs_animate = start_selection_handle_->Animate(frame_time);
227 needs_animate |= end_selection_handle_->Animate(frame_time); 233 needs_animate |= end_selection_handle_->Animate(frame_time);
228 return needs_animate; 234 return needs_animate;
229 } 235 }
230 236
231 return false; 237 return false;
232 } 238 }
233 239
234 gfx::RectF TouchSelectionController::GetRectBetweenBounds() const { 240 gfx::RectF TouchSelectionController::GetRectBetweenBounds() const {
235 // Short-circuit for efficiency. 241 // Short-circuit for efficiency.
236 if (!is_insertion_active_ && !is_selection_active_) 242 if (active_status_ == INACTIVE)
237 return gfx::RectF(); 243 return gfx::RectF();
238 244
239 if (start_.visible() && !end_.visible()) 245 if (start_.visible() && !end_.visible())
240 return gfx::BoundingRect(start_.edge_top(), start_.edge_bottom()); 246 return gfx::BoundingRect(start_.edge_top(), start_.edge_bottom());
241 247
242 if (end_.visible() && !start_.visible()) 248 if (end_.visible() && !start_.visible())
243 return gfx::BoundingRect(end_.edge_top(), end_.edge_bottom()); 249 return gfx::BoundingRect(end_.edge_top(), end_.edge_bottom());
244 250
245 // If both handles are visible, or both are invisible, use the entire rect. 251 // If both handles are visible, or both are invisible, use the entire rect.
246 return RectFBetweenSelectionBounds(start_, end_); 252 return RectFBetweenSelectionBounds(start_, end_);
247 } 253 }
248 254
249 gfx::RectF TouchSelectionController::GetStartHandleRect() const { 255 gfx::RectF TouchSelectionController::GetStartHandleRect() const {
250 if (is_insertion_active_) 256 if (active_status_ == INSERTION_ACTIVE)
251 return insertion_handle_->GetVisibleBounds(); 257 return insertion_handle_->GetVisibleBounds();
252 if (is_selection_active_) 258 if (active_status_ == SELECTION_ACTIVE)
253 return start_selection_handle_->GetVisibleBounds(); 259 return start_selection_handle_->GetVisibleBounds();
254 return gfx::RectF(); 260 return gfx::RectF();
255 } 261 }
256 262
257 gfx::RectF TouchSelectionController::GetEndHandleRect() const { 263 gfx::RectF TouchSelectionController::GetEndHandleRect() const {
258 if (is_insertion_active_) 264 if (active_status_ == INSERTION_ACTIVE)
259 return insertion_handle_->GetVisibleBounds(); 265 return insertion_handle_->GetVisibleBounds();
260 if (is_selection_active_) 266 if (active_status_ == SELECTION_ACTIVE)
261 return end_selection_handle_->GetVisibleBounds(); 267 return end_selection_handle_->GetVisibleBounds();
262 return gfx::RectF(); 268 return gfx::RectF();
263 } 269 }
264 270
265 const gfx::PointF& TouchSelectionController::GetStartPosition() const { 271 const gfx::PointF& TouchSelectionController::GetStartPosition() const {
266 return start_.edge_bottom(); 272 return start_.edge_bottom();
267 } 273 }
268 274
269 const gfx::PointF& TouchSelectionController::GetEndPosition() const { 275 const gfx::PointF& TouchSelectionController::GetEndPosition() const {
270 return end_.edge_bottom(); 276 return end_.edge_bottom();
(...skipping 22 matching lines...) Expand all
293 } 299 }
294 300
295 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, 301 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle,
296 const gfx::PointF& position) { 302 const gfx::PointF& position) {
297 // As the position corresponds to the bottom left point of the selection 303 // As the position corresponds to the bottom left point of the selection
298 // bound, offset it by half the corresponding line height. 304 // bound, offset it by half the corresponding line height.
299 gfx::Vector2dF line_offset = &handle == start_selection_handle_.get() 305 gfx::Vector2dF line_offset = &handle == start_selection_handle_.get()
300 ? GetStartLineOffset() 306 ? GetStartLineOffset()
301 : GetEndLineOffset(); 307 : GetEndLineOffset();
302 gfx::PointF line_position = position + line_offset; 308 gfx::PointF line_position = position + line_offset;
303 if (&handle == insertion_handle_.get()) { 309 if (&handle == insertion_handle_.get())
304 client_->MoveCaret(line_position); 310 client_->MoveCaret(line_position);
305 } else { 311 else
306 client_->MoveRangeSelectionExtent(line_position); 312 client_->MoveRangeSelectionExtent(line_position);
307 }
308 } 313 }
309 314
310 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { 315 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) {
311 if (&handle == insertion_handle_.get()) 316 if (&handle == insertion_handle_.get())
312 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED); 317 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED);
313 else 318 else
314 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED); 319 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED);
315 } 320 }
316 321
317 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { 322 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 359
355 if (response_pending_input_event_ == TAP && selection_empty_ && 360 if (response_pending_input_event_ == TAP && selection_empty_ &&
356 !show_on_tap_for_empty_editable_) { 361 !show_on_tap_for_empty_editable_) {
357 HideAndDisallowShowingAutomatically(); 362 HideAndDisallowShowingAutomatically();
358 return; 363 return;
359 } 364 }
360 365
361 if (!activate_insertion_automatically_) 366 if (!activate_insertion_automatically_)
362 return; 367 return;
363 368
364 const bool was_active = is_insertion_active_; 369 const bool was_active = active_status_ == INSERTION_ACTIVE;
365 const gfx::PointF position = GetStartPosition(); 370 const gfx::PointF position = GetStartPosition();
366 if (!is_insertion_active_) 371 if (!was_active)
367 ActivateInsertion(); 372 ActivateInsertion();
368 else 373 else
369 client_->OnSelectionEvent(INSERTION_MOVED); 374 client_->OnSelectionEvent(INSERTION_MOVED);
370 375
371 insertion_handle_->SetVisible(GetStartVisible(), 376 insertion_handle_->SetVisible(GetStartVisible(),
372 GetAnimationStyle(was_active)); 377 GetAnimationStyle(was_active));
373 insertion_handle_->SetPosition(position); 378 insertion_handle_->SetPosition(position);
374 } 379 }
375 380
376 void TouchSelectionController::OnSelectionChanged() { 381 void TouchSelectionController::OnSelectionChanged() {
377 DeactivateInsertion(); 382 DeactivateInsertion();
378 383
379 if (!activate_selection_automatically_) 384 if (!activate_selection_automatically_)
380 return; 385 return;
381 386
382 const bool was_active = is_selection_active_; 387 const bool was_active = active_status_ == SELECTION_ACTIVE;
383 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) 388 if (!was_active || response_pending_input_event_ == LONG_PRESS)
384 ActivateSelection(); 389 ActivateSelection();
385 else 390 else
386 client_->OnSelectionEvent(SELECTION_MOVED); 391 client_->OnSelectionEvent(SELECTION_MOVED);
387 392
388 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); 393 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active);
389 start_selection_handle_->SetVisible(GetStartVisible(), animation); 394 start_selection_handle_->SetVisible(GetStartVisible(), animation);
390 end_selection_handle_->SetVisible(GetEndVisible(), animation); 395 end_selection_handle_->SetVisible(GetEndVisible(), animation);
391 396
392 start_selection_handle_->SetPosition(GetStartPosition()); 397 start_selection_handle_->SetPosition(GetStartPosition());
393 end_selection_handle_->SetPosition(GetEndPosition()); 398 end_selection_handle_->SetPosition(GetEndPosition());
394 } 399 }
395 400
396 void TouchSelectionController::ActivateInsertion() { 401 void TouchSelectionController::ActivateInsertion() {
397 DCHECK(!is_selection_active_); 402 DCHECK_NE(SELECTION_ACTIVE, active_status_);
398 403
399 if (!insertion_handle_) 404 if (!insertion_handle_)
400 insertion_handle_.reset( 405 insertion_handle_.reset(
401 new TouchHandle(this, TouchHandleOrientation::CENTER)); 406 new TouchHandle(this, TouchHandleOrientation::CENTER));
402 407
403 if (!is_insertion_active_) { 408 if (active_status_ == INACTIVE) {
404 is_insertion_active_ = true; 409 active_status_ = INSERTION_ACTIVE;
405 insertion_handle_->SetEnabled(true); 410 insertion_handle_->SetEnabled(true);
406 client_->OnSelectionEvent(INSERTION_SHOWN); 411 client_->OnSelectionEvent(INSERTION_SHOWN);
407 } 412 }
408 } 413 }
409 414
410 void TouchSelectionController::DeactivateInsertion() { 415 void TouchSelectionController::DeactivateInsertion() {
411 if (!is_insertion_active_) 416 if (active_status_ != INSERTION_ACTIVE)
412 return; 417 return;
413 DCHECK(insertion_handle_); 418 DCHECK(insertion_handle_);
414 is_insertion_active_ = false; 419 active_status_ = INACTIVE;
415 insertion_handle_->SetEnabled(false); 420 insertion_handle_->SetEnabled(false);
416 client_->OnSelectionEvent(INSERTION_CLEARED); 421 client_->OnSelectionEvent(INSERTION_CLEARED);
417 } 422 }
418 423
419 void TouchSelectionController::ActivateSelection() { 424 void TouchSelectionController::ActivateSelection() {
420 DCHECK(!is_insertion_active_); 425 DCHECK_NE(INSERTION_ACTIVE, active_status_);
421 426
422 if (!start_selection_handle_) { 427 if (!start_selection_handle_) {
423 start_selection_handle_.reset(new TouchHandle(this, start_orientation_)); 428 start_selection_handle_.reset(new TouchHandle(this, start_orientation_));
424 } else { 429 } else {
425 start_selection_handle_->SetEnabled(true); 430 start_selection_handle_->SetEnabled(true);
426 start_selection_handle_->SetOrientation(start_orientation_); 431 start_selection_handle_->SetOrientation(start_orientation_);
427 } 432 }
428 433
429 if (!end_selection_handle_) { 434 if (!end_selection_handle_) {
430 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); 435 end_selection_handle_.reset(new TouchHandle(this, end_orientation_));
431 } else { 436 } else {
432 end_selection_handle_->SetEnabled(true); 437 end_selection_handle_->SetEnabled(true);
433 end_selection_handle_->SetOrientation(end_orientation_); 438 end_selection_handle_->SetOrientation(end_orientation_);
434 } 439 }
435 440
436 // As a long press received while a selection is already active may trigger 441 // As a long press received while a selection is already active may trigger
437 // an entirely new selection, notify the client but avoid sending an 442 // an entirely new selection, notify the client but avoid sending an
438 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. 443 // intervening SELECTION_CLEARED update to avoid unnecessary state changes.
439 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { 444 if (active_status_ == INACTIVE ||
440 if (is_selection_active_) { 445 response_pending_input_event_ == LONG_PRESS) {
446 if (active_status_ == SELECTION_ACTIVE) {
441 // The active selection session finishes with the start of the new one. 447 // The active selection session finishes with the start of the new one.
442 LogSelectionEnd(); 448 LogSelectionEnd();
443 } 449 }
444 is_selection_active_ = true; 450 active_status_ = SELECTION_ACTIVE;
445 selection_handle_dragged_ = false; 451 selection_handle_dragged_ = false;
446 selection_start_time_ = base::TimeTicks::Now(); 452 selection_start_time_ = base::TimeTicks::Now();
447 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 453 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
448 client_->OnSelectionEvent(SELECTION_SHOWN); 454 client_->OnSelectionEvent(SELECTION_SHOWN);
449 } 455 }
450 } 456 }
451 457
452 void TouchSelectionController::DeactivateSelection() { 458 void TouchSelectionController::DeactivateSelection() {
453 if (!is_selection_active_) 459 if (active_status_ != SELECTION_ACTIVE)
454 return; 460 return;
455 DCHECK(start_selection_handle_); 461 DCHECK(start_selection_handle_);
456 DCHECK(end_selection_handle_); 462 DCHECK(end_selection_handle_);
457 LogSelectionEnd(); 463 LogSelectionEnd();
458 start_selection_handle_->SetEnabled(false); 464 start_selection_handle_->SetEnabled(false);
459 end_selection_handle_->SetEnabled(false); 465 end_selection_handle_->SetEnabled(false);
460 is_selection_active_ = false; 466 active_status_ = INACTIVE;
461 client_->OnSelectionEvent(SELECTION_CLEARED); 467 client_->OnSelectionEvent(SELECTION_CLEARED);
462 } 468 }
463 469
464 void TouchSelectionController::ResetCachedValuesIfInactive() { 470 void TouchSelectionController::ResetCachedValuesIfInactive() {
465 if (is_selection_active_ || is_insertion_active_) 471 if (active_status_ != INACTIVE)
466 return; 472 return;
467 start_ = SelectionBound(); 473 start_ = SelectionBound();
468 end_ = SelectionBound(); 474 end_ = SelectionBound();
469 start_orientation_ = TouchHandleOrientation::UNDEFINED; 475 start_orientation_ = TouchHandleOrientation::UNDEFINED;
470 end_orientation_ = TouchHandleOrientation::UNDEFINED; 476 end_orientation_ = TouchHandleOrientation::UNDEFINED;
471 } 477 }
472 478
473 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { 479 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const {
474 return ComputeLineOffsetFromBottom(start_); 480 return ComputeLineOffsetFromBottom(start_);
475 } 481 }
(...skipping 26 matching lines...) Expand all
502 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; 508 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
503 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", 509 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
504 duration, 510 duration,
505 base::TimeDelta::FromMilliseconds(500), 511 base::TimeDelta::FromMilliseconds(500),
506 base::TimeDelta::FromSeconds(60), 512 base::TimeDelta::FromSeconds(60),
507 60); 513 60);
508 } 514 }
509 } 515 }
510 516
511 } // namespace ui 517 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698