OLD | NEW |
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 selection_empty_(false), | 59 selection_empty_(false), |
60 selection_editable_(false), | 60 selection_editable_(false), |
61 temporarily_hidden_(false), | 61 temporarily_hidden_(false), |
62 selection_handle_dragged_(false) { | 62 selection_handle_dragged_(false) { |
63 DCHECK(client_); | 63 DCHECK(client_); |
64 } | 64 } |
65 | 65 |
66 TouchSelectionController::~TouchSelectionController() { | 66 TouchSelectionController::~TouchSelectionController() { |
67 } | 67 } |
68 | 68 |
69 void TouchSelectionController::OnSelectionBoundsChanged( | 69 bool TouchSelectionController::OnSelectionBoundsUpdated( |
70 const SelectionBound& start, | 70 const SelectionBound& start, |
71 const SelectionBound& end) { | 71 const SelectionBound& end) { |
72 if (start == start_ && end_ == end) | 72 if (start == start_ && end_ == end) |
73 return; | 73 return false; |
74 | 74 |
75 start_ = start; | 75 start_ = start; |
76 end_ = end; | 76 end_ = end; |
77 start_orientation_ = ToTouchHandleOrientation(start_.type()); | 77 start_orientation_ = ToTouchHandleOrientation(start_.type()); |
78 end_orientation_ = ToTouchHandleOrientation(end_.type()); | 78 end_orientation_ = ToTouchHandleOrientation(end_.type()); |
79 | 79 |
80 if (!activate_selection_automatically_ && | 80 if (!activate_selection_automatically_ && |
81 !activate_insertion_automatically_) { | 81 !activate_insertion_automatically_) { |
82 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); | 82 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); |
83 return; | 83 return false; |
84 } | 84 } |
85 | 85 |
86 // Ensure that |response_pending_input_event_| is cleared after the method | 86 // Ensure that |response_pending_input_event_| is cleared after the method |
87 // completes, while also making its current value available for the duration | 87 // completes, while also making its current value available for the duration |
88 // of the call. | 88 // of the call. |
89 InputEventType causal_input_event = response_pending_input_event_; | 89 InputEventType causal_input_event = response_pending_input_event_; |
90 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; | 90 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; |
91 base::AutoReset<InputEventType> auto_reset_response_pending_input_event( | 91 base::AutoReset<InputEventType> auto_reset_response_pending_input_event( |
92 &response_pending_input_event_, causal_input_event); | 92 &response_pending_input_event_, causal_input_event); |
93 | 93 |
(...skipping 12 matching lines...) Expand all Loading... |
106 start_orientation_ = start_selection_handle_->orientation(); | 106 start_orientation_ = start_selection_handle_->orientation(); |
107 if (end_orientation_ == TouchHandleOrientation::CENTER) | 107 if (end_orientation_ == TouchHandleOrientation::CENTER) |
108 end_orientation_ = end_selection_handle_->orientation(); | 108 end_orientation_ = end_selection_handle_->orientation(); |
109 } | 109 } |
110 | 110 |
111 if (GetStartPosition() != GetEndPosition() || | 111 if (GetStartPosition() != GetEndPosition() || |
112 (is_selection_dragging && | 112 (is_selection_dragging && |
113 start_orientation_ != TouchHandleOrientation::UNDEFINED && | 113 start_orientation_ != TouchHandleOrientation::UNDEFINED && |
114 end_orientation_ != TouchHandleOrientation::UNDEFINED)) { | 114 end_orientation_ != TouchHandleOrientation::UNDEFINED)) { |
115 OnSelectionChanged(); | 115 OnSelectionChanged(); |
116 return; | 116 return true; |
117 } | 117 } |
118 | 118 |
119 if (start_orientation_ == TouchHandleOrientation::CENTER && | 119 if (start_orientation_ == TouchHandleOrientation::CENTER && |
120 selection_editable_) { | 120 selection_editable_) { |
121 OnInsertionChanged(); | 121 OnInsertionChanged(); |
122 return; | 122 return true; |
123 } | 123 } |
124 | 124 |
125 HideAndDisallowShowingAutomatically(); | 125 HideAndDisallowShowingAutomatically(); |
| 126 return true; |
126 } | 127 } |
127 | 128 |
128 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { | 129 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { |
129 if (is_insertion_active_) { | 130 if (is_insertion_active_) { |
130 DCHECK(insertion_handle_); | 131 DCHECK(insertion_handle_); |
131 return insertion_handle_->WillHandleTouchEvent(event); | 132 return insertion_handle_->WillHandleTouchEvent(event); |
132 } | 133 } |
133 | 134 |
134 if (is_selection_active_) { | 135 if (is_selection_active_) { |
135 DCHECK(start_selection_handle_); | 136 DCHECK(start_selection_handle_); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 DeactivateInsertion(); | 211 DeactivateInsertion(); |
211 } | 212 } |
212 | 213 |
213 void TouchSelectionController::OnSelectionEmpty(bool empty) { | 214 void TouchSelectionController::OnSelectionEmpty(bool empty) { |
214 if (selection_empty_ == empty) | 215 if (selection_empty_ == empty) |
215 return; | 216 return; |
216 selection_empty_ = empty; | 217 selection_empty_ = empty; |
217 ResetCachedValuesIfInactive(); | 218 ResetCachedValuesIfInactive(); |
218 } | 219 } |
219 | 220 |
| 221 void TouchSelectionController::OnNativeViewMoved() { |
| 222 if (is_selection_active_) |
| 223 client_->OnSelectionEvent(SELECTION_MOVED); |
| 224 else if (is_insertion_active_) |
| 225 client_->OnSelectionEvent(INSERTION_MOVED); |
| 226 } |
| 227 |
220 bool TouchSelectionController::Animate(base::TimeTicks frame_time) { | 228 bool TouchSelectionController::Animate(base::TimeTicks frame_time) { |
221 if (is_insertion_active_) | 229 if (is_insertion_active_) |
222 return insertion_handle_->Animate(frame_time); | 230 return insertion_handle_->Animate(frame_time); |
223 | 231 |
224 if (is_selection_active_) { | 232 if (is_selection_active_) { |
225 bool needs_animate = start_selection_handle_->Animate(frame_time); | 233 bool needs_animate = start_selection_handle_->Animate(frame_time); |
226 needs_animate |= end_selection_handle_->Animate(frame_time); | 234 needs_animate |= end_selection_handle_->Animate(frame_time); |
227 return needs_animate; | 235 return needs_animate; |
228 } | 236 } |
229 | 237 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 300 } |
293 | 301 |
294 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, | 302 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, |
295 const gfx::PointF& position) { | 303 const gfx::PointF& position) { |
296 // As the position corresponds to the bottom left point of the selection | 304 // As the position corresponds to the bottom left point of the selection |
297 // bound, offset it by half the corresponding line height. | 305 // bound, offset it by half the corresponding line height. |
298 gfx::Vector2dF line_offset = &handle == start_selection_handle_.get() | 306 gfx::Vector2dF line_offset = &handle == start_selection_handle_.get() |
299 ? GetStartLineOffset() | 307 ? GetStartLineOffset() |
300 : GetEndLineOffset(); | 308 : GetEndLineOffset(); |
301 gfx::PointF line_position = position + line_offset; | 309 gfx::PointF line_position = position + line_offset; |
302 if (&handle == insertion_handle_.get()) { | 310 if (&handle == insertion_handle_.get()) |
303 client_->MoveCaret(line_position); | 311 client_->MoveCaret(line_position); |
304 } else { | 312 else |
305 client_->MoveRangeSelectionExtent(line_position); | 313 client_->MoveRangeSelectionExtent(line_position); |
306 } | |
307 } | 314 } |
308 | 315 |
309 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { | 316 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { |
310 if (&handle == insertion_handle_.get()) | 317 if (&handle == insertion_handle_.get()) |
311 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED); | 318 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED); |
312 else | 319 else |
313 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED); | 320 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED); |
314 } | 321 } |
315 | 322 |
316 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { | 323 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 508 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
502 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 509 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
503 duration, | 510 duration, |
504 base::TimeDelta::FromMilliseconds(500), | 511 base::TimeDelta::FromMilliseconds(500), |
505 base::TimeDelta::FromSeconds(60), | 512 base::TimeDelta::FromSeconds(60), |
506 60); | 513 60); |
507 } | 514 } |
508 } | 515 } |
509 | 516 |
510 } // namespace ui | 517 } // namespace ui |
OLD | NEW |