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

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: Removed OnNativeViewMoved 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();
sadrul 2015/05/11 16:06:57 Add braces in this block.
mohsen 2015/05/11 16:55:40 Done.
172 } 171 }
173 172
174 void TouchSelectionController::OnTapEvent() { 173 void TouchSelectionController::OnTapEvent() {
175 response_pending_input_event_ = TAP; 174 response_pending_input_event_ = TAP;
176 activate_selection_automatically_ = false; 175 activate_selection_automatically_ = false;
177 ShowInsertionHandleAutomatically(); 176 ShowInsertionHandleAutomatically();
178 if (selection_empty_ && !show_on_tap_for_empty_editable_) 177 if (selection_empty_ && !show_on_tap_for_empty_editable_)
179 DeactivateInsertion(); 178 DeactivateInsertion();
180 ResetCachedValuesIfInactive(); 179 ResetCachedValuesIfInactive();
181 } 180 }
182 181
183 void TouchSelectionController::HideAndDisallowShowingAutomatically() { 182 void TouchSelectionController::HideAndDisallowShowingAutomatically() {
184 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 183 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
185 DeactivateInsertion(); 184 DeactivateInsertion();
186 DeactivateSelection(); 185 DeactivateSelection();
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
221 bool TouchSelectionController::Animate(base::TimeTicks frame_time) { 220 bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
222 if (is_insertion_active_) 221 if (active_status_ == INSERTION_ACTIVE)
223 return insertion_handle_->Animate(frame_time); 222 return insertion_handle_->Animate(frame_time);
224 223
225 if (is_selection_active_) { 224 if (active_status_ == SELECTION_ACTIVE) {
226 bool needs_animate = start_selection_handle_->Animate(frame_time); 225 bool needs_animate = start_selection_handle_->Animate(frame_time);
227 needs_animate |= end_selection_handle_->Animate(frame_time); 226 needs_animate |= end_selection_handle_->Animate(frame_time);
228 return needs_animate; 227 return needs_animate;
229 } 228 }
230 229
231 return false; 230 return false;
232 } 231 }
233 232
234 gfx::RectF TouchSelectionController::GetRectBetweenBounds() const { 233 gfx::RectF TouchSelectionController::GetRectBetweenBounds() const {
235 // Short-circuit for efficiency. 234 // Short-circuit for efficiency.
236 if (!is_insertion_active_ && !is_selection_active_) 235 if (active_status_ == INACTIVE)
237 return gfx::RectF(); 236 return gfx::RectF();
238 237
239 if (start_.visible() && !end_.visible()) 238 if (start_.visible() && !end_.visible())
240 return gfx::BoundingRect(start_.edge_top(), start_.edge_bottom()); 239 return gfx::BoundingRect(start_.edge_top(), start_.edge_bottom());
241 240
242 if (end_.visible() && !start_.visible()) 241 if (end_.visible() && !start_.visible())
243 return gfx::BoundingRect(end_.edge_top(), end_.edge_bottom()); 242 return gfx::BoundingRect(end_.edge_top(), end_.edge_bottom());
244 243
245 // If both handles are visible, or both are invisible, use the entire rect. 244 // If both handles are visible, or both are invisible, use the entire rect.
246 return RectFBetweenSelectionBounds(start_, end_); 245 return RectFBetweenSelectionBounds(start_, end_);
247 } 246 }
248 247
249 gfx::RectF TouchSelectionController::GetStartHandleRect() const { 248 gfx::RectF TouchSelectionController::GetStartHandleRect() const {
250 if (is_insertion_active_) 249 if (active_status_ == INSERTION_ACTIVE)
251 return insertion_handle_->GetVisibleBounds(); 250 return insertion_handle_->GetVisibleBounds();
252 if (is_selection_active_) 251 if (active_status_ == SELECTION_ACTIVE)
253 return start_selection_handle_->GetVisibleBounds(); 252 return start_selection_handle_->GetVisibleBounds();
254 return gfx::RectF(); 253 return gfx::RectF();
255 } 254 }
256 255
257 gfx::RectF TouchSelectionController::GetEndHandleRect() const { 256 gfx::RectF TouchSelectionController::GetEndHandleRect() const {
258 if (is_insertion_active_) 257 if (active_status_ == INSERTION_ACTIVE)
259 return insertion_handle_->GetVisibleBounds(); 258 return insertion_handle_->GetVisibleBounds();
260 if (is_selection_active_) 259 if (active_status_ == SELECTION_ACTIVE)
261 return end_selection_handle_->GetVisibleBounds(); 260 return end_selection_handle_->GetVisibleBounds();
262 return gfx::RectF(); 261 return gfx::RectF();
263 } 262 }
264 263
265 const gfx::PointF& TouchSelectionController::GetStartPosition() const { 264 const gfx::PointF& TouchSelectionController::GetStartPosition() const {
266 return start_.edge_bottom(); 265 return start_.edge_bottom();
267 } 266 }
268 267
269 const gfx::PointF& TouchSelectionController::GetEndPosition() const { 268 const gfx::PointF& TouchSelectionController::GetEndPosition() const {
270 return end_.edge_bottom(); 269 return end_.edge_bottom();
(...skipping 22 matching lines...) Expand all
293 } 292 }
294 293
295 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, 294 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle,
296 const gfx::PointF& position) { 295 const gfx::PointF& position) {
297 // As the position corresponds to the bottom left point of the selection 296 // As the position corresponds to the bottom left point of the selection
298 // bound, offset it by half the corresponding line height. 297 // bound, offset it by half the corresponding line height.
299 gfx::Vector2dF line_offset = &handle == start_selection_handle_.get() 298 gfx::Vector2dF line_offset = &handle == start_selection_handle_.get()
300 ? GetStartLineOffset() 299 ? GetStartLineOffset()
301 : GetEndLineOffset(); 300 : GetEndLineOffset();
302 gfx::PointF line_position = position + line_offset; 301 gfx::PointF line_position = position + line_offset;
303 if (&handle == insertion_handle_.get()) { 302 if (&handle == insertion_handle_.get())
304 client_->MoveCaret(line_position); 303 client_->MoveCaret(line_position);
305 } else { 304 else
306 client_->MoveRangeSelectionExtent(line_position); 305 client_->MoveRangeSelectionExtent(line_position);
307 }
308 } 306 }
309 307
310 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { 308 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) {
311 if (&handle == insertion_handle_.get()) 309 if (&handle == insertion_handle_.get())
312 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED); 310 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED);
313 else 311 else
314 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED); 312 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED);
315 } 313 }
316 314
317 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { 315 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 352
355 if (response_pending_input_event_ == TAP && selection_empty_ && 353 if (response_pending_input_event_ == TAP && selection_empty_ &&
356 !show_on_tap_for_empty_editable_) { 354 !show_on_tap_for_empty_editable_) {
357 HideAndDisallowShowingAutomatically(); 355 HideAndDisallowShowingAutomatically();
358 return; 356 return;
359 } 357 }
360 358
361 if (!activate_insertion_automatically_) 359 if (!activate_insertion_automatically_)
362 return; 360 return;
363 361
364 const bool was_active = is_insertion_active_; 362 const bool was_active = active_status_ == INSERTION_ACTIVE;
365 const gfx::PointF position = GetStartPosition(); 363 const gfx::PointF position = GetStartPosition();
366 if (!is_insertion_active_) 364 if (!was_active)
367 ActivateInsertion(); 365 ActivateInsertion();
368 else 366 else
369 client_->OnSelectionEvent(INSERTION_MOVED); 367 client_->OnSelectionEvent(INSERTION_MOVED);
370 368
371 insertion_handle_->SetVisible(GetStartVisible(), 369 insertion_handle_->SetVisible(GetStartVisible(),
372 GetAnimationStyle(was_active)); 370 GetAnimationStyle(was_active));
373 insertion_handle_->SetPosition(position); 371 insertion_handle_->SetPosition(position);
374 } 372 }
375 373
376 void TouchSelectionController::OnSelectionChanged() { 374 void TouchSelectionController::OnSelectionChanged() {
377 DeactivateInsertion(); 375 DeactivateInsertion();
378 376
379 if (!activate_selection_automatically_) 377 if (!activate_selection_automatically_)
380 return; 378 return;
381 379
382 const bool was_active = is_selection_active_; 380 const bool was_active = active_status_ == SELECTION_ACTIVE;
383 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) 381 if (!was_active || response_pending_input_event_ == LONG_PRESS)
384 ActivateSelection(); 382 ActivateSelection();
385 else 383 else
386 client_->OnSelectionEvent(SELECTION_MOVED); 384 client_->OnSelectionEvent(SELECTION_MOVED);
387 385
388 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); 386 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active);
389 start_selection_handle_->SetVisible(GetStartVisible(), animation); 387 start_selection_handle_->SetVisible(GetStartVisible(), animation);
390 end_selection_handle_->SetVisible(GetEndVisible(), animation); 388 end_selection_handle_->SetVisible(GetEndVisible(), animation);
391 389
392 start_selection_handle_->SetPosition(GetStartPosition()); 390 start_selection_handle_->SetPosition(GetStartPosition());
393 end_selection_handle_->SetPosition(GetEndPosition()); 391 end_selection_handle_->SetPosition(GetEndPosition());
394 } 392 }
395 393
396 void TouchSelectionController::ActivateInsertion() { 394 void TouchSelectionController::ActivateInsertion() {
397 DCHECK(!is_selection_active_); 395 DCHECK_NE(SELECTION_ACTIVE, active_status_);
398 396
399 if (!insertion_handle_) 397 if (!insertion_handle_)
400 insertion_handle_.reset( 398 insertion_handle_.reset(
401 new TouchHandle(this, TouchHandleOrientation::CENTER)); 399 new TouchHandle(this, TouchHandleOrientation::CENTER));
402 400
403 if (!is_insertion_active_) { 401 if (active_status_ == INACTIVE) {
404 is_insertion_active_ = true; 402 active_status_ = INSERTION_ACTIVE;
405 insertion_handle_->SetEnabled(true); 403 insertion_handle_->SetEnabled(true);
406 client_->OnSelectionEvent(INSERTION_SHOWN); 404 client_->OnSelectionEvent(INSERTION_SHOWN);
407 } 405 }
408 } 406 }
409 407
410 void TouchSelectionController::DeactivateInsertion() { 408 void TouchSelectionController::DeactivateInsertion() {
411 if (!is_insertion_active_) 409 if (active_status_ != INSERTION_ACTIVE)
412 return; 410 return;
413 DCHECK(insertion_handle_); 411 DCHECK(insertion_handle_);
414 is_insertion_active_ = false; 412 active_status_ = INACTIVE;
415 insertion_handle_->SetEnabled(false); 413 insertion_handle_->SetEnabled(false);
416 client_->OnSelectionEvent(INSERTION_CLEARED); 414 client_->OnSelectionEvent(INSERTION_CLEARED);
417 } 415 }
418 416
419 void TouchSelectionController::ActivateSelection() { 417 void TouchSelectionController::ActivateSelection() {
420 DCHECK(!is_insertion_active_); 418 DCHECK_NE(INSERTION_ACTIVE, active_status_);
421 419
422 if (!start_selection_handle_) { 420 if (!start_selection_handle_) {
423 start_selection_handle_.reset(new TouchHandle(this, start_orientation_)); 421 start_selection_handle_.reset(new TouchHandle(this, start_orientation_));
424 } else { 422 } else {
425 start_selection_handle_->SetEnabled(true); 423 start_selection_handle_->SetEnabled(true);
426 start_selection_handle_->SetOrientation(start_orientation_); 424 start_selection_handle_->SetOrientation(start_orientation_);
427 } 425 }
428 426
429 if (!end_selection_handle_) { 427 if (!end_selection_handle_) {
430 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); 428 end_selection_handle_.reset(new TouchHandle(this, end_orientation_));
431 } else { 429 } else {
432 end_selection_handle_->SetEnabled(true); 430 end_selection_handle_->SetEnabled(true);
433 end_selection_handle_->SetOrientation(end_orientation_); 431 end_selection_handle_->SetOrientation(end_orientation_);
434 } 432 }
435 433
436 // As a long press received while a selection is already active may trigger 434 // 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 435 // an entirely new selection, notify the client but avoid sending an
438 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. 436 // intervening SELECTION_CLEARED update to avoid unnecessary state changes.
439 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { 437 if (active_status_ == INACTIVE ||
440 if (is_selection_active_) { 438 response_pending_input_event_ == LONG_PRESS) {
439 if (active_status_ == SELECTION_ACTIVE) {
441 // The active selection session finishes with the start of the new one. 440 // The active selection session finishes with the start of the new one.
442 LogSelectionEnd(); 441 LogSelectionEnd();
443 } 442 }
444 is_selection_active_ = true; 443 active_status_ = SELECTION_ACTIVE;
445 selection_handle_dragged_ = false; 444 selection_handle_dragged_ = false;
446 selection_start_time_ = base::TimeTicks::Now(); 445 selection_start_time_ = base::TimeTicks::Now();
447 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 446 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
448 client_->OnSelectionEvent(SELECTION_SHOWN); 447 client_->OnSelectionEvent(SELECTION_SHOWN);
449 } 448 }
450 } 449 }
451 450
452 void TouchSelectionController::DeactivateSelection() { 451 void TouchSelectionController::DeactivateSelection() {
453 if (!is_selection_active_) 452 if (active_status_ != SELECTION_ACTIVE)
454 return; 453 return;
455 DCHECK(start_selection_handle_); 454 DCHECK(start_selection_handle_);
456 DCHECK(end_selection_handle_); 455 DCHECK(end_selection_handle_);
457 LogSelectionEnd(); 456 LogSelectionEnd();
458 start_selection_handle_->SetEnabled(false); 457 start_selection_handle_->SetEnabled(false);
459 end_selection_handle_->SetEnabled(false); 458 end_selection_handle_->SetEnabled(false);
460 is_selection_active_ = false; 459 active_status_ = INACTIVE;
461 client_->OnSelectionEvent(SELECTION_CLEARED); 460 client_->OnSelectionEvent(SELECTION_CLEARED);
462 } 461 }
463 462
464 void TouchSelectionController::ResetCachedValuesIfInactive() { 463 void TouchSelectionController::ResetCachedValuesIfInactive() {
465 if (is_selection_active_ || is_insertion_active_) 464 if (active_status_ != INACTIVE)
466 return; 465 return;
467 start_ = SelectionBound(); 466 start_ = SelectionBound();
468 end_ = SelectionBound(); 467 end_ = SelectionBound();
469 start_orientation_ = TouchHandleOrientation::UNDEFINED; 468 start_orientation_ = TouchHandleOrientation::UNDEFINED;
470 end_orientation_ = TouchHandleOrientation::UNDEFINED; 469 end_orientation_ = TouchHandleOrientation::UNDEFINED;
471 } 470 }
472 471
473 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { 472 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const {
474 return ComputeLineOffsetFromBottom(start_); 473 return ComputeLineOffsetFromBottom(start_);
475 } 474 }
(...skipping 26 matching lines...) Expand all
502 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; 501 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
503 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", 502 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
504 duration, 503 duration,
505 base::TimeDelta::FromMilliseconds(500), 504 base::TimeDelta::FromMilliseconds(500),
506 base::TimeDelta::FromSeconds(60), 505 base::TimeDelta::FromSeconds(60),
507 60); 506 60);
508 } 507 }
509 } 508 }
510 509
511 } // namespace ui 510 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698