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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 if ((event_pos - GetStartPosition()).LengthSquared() <= | 146 if ((event_pos - GetStartPosition()).LengthSquared() <= |
147 (event_pos - GetEndPosition()).LengthSquared()) { | 147 (event_pos - GetEndPosition()).LengthSquared()) { |
148 return start_selection_handle_->WillHandleTouchEvent(event); | 148 return start_selection_handle_->WillHandleTouchEvent(event); |
149 } | 149 } |
150 return end_selection_handle_->WillHandleTouchEvent(event); | 150 return end_selection_handle_->WillHandleTouchEvent(event); |
151 } | 151 } |
152 | 152 |
153 return false; | 153 return false; |
154 } | 154 } |
155 | 155 |
156 void TouchSelectionController::OnLongPressEvent() { | 156 bool TouchSelectionController::WillHandleLongPressEvent( |
157 const gfx::PointF& location) { | |
158 if (WillHandleTapOrLongPress(location)) | |
159 return true; | |
160 | |
157 response_pending_input_event_ = LONG_PRESS; | 161 response_pending_input_event_ = LONG_PRESS; |
158 ShowSelectionHandlesAutomatically(); | 162 ShowSelectionHandlesAutomatically(); |
159 ShowInsertionHandleAutomatically(); | 163 ShowInsertionHandleAutomatically(); |
160 ForceNextUpdateIfInactive(); | 164 ForceNextUpdateIfInactive(); |
165 return false; | |
166 } | |
167 | |
168 bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location) { | |
169 if (WillHandleTapOrLongPress(location)) | |
170 return true; | |
171 | |
172 response_pending_input_event_ = TAP; | |
173 if (active_status_ != SELECTION_ACTIVE) | |
174 activate_selection_automatically_ = false; | |
175 ShowInsertionHandleAutomatically(); | |
176 if (selection_empty_ && !show_on_tap_for_empty_editable_) | |
177 DeactivateInsertion(); | |
178 ForceNextUpdateIfInactive(); | |
179 return false; | |
180 } | |
181 | |
182 bool TouchSelectionController::WillHandleTapOrLongPress( | |
jdduke (slow)
2015/05/12 22:33:01
Nit: The implementation order should match the dec
Donn Denman
2015/05/12 22:52:48
Oh, didn't know that!
Done.
| |
183 const gfx::PointF& location) { | |
184 // If there is an active selection that was not triggered by a user gesture, | |
185 // allow showing the handles for that selection if a gesture occurs within | |
186 // the selection rect. Note that this hit test is at best a crude | |
187 // approximation, and may swallow taps that actually fall outside the | |
188 // real selection. | |
189 if (active_status_ != SELECTION_ACTIVE && | |
Donn Denman
2015/05/12 21:42:49
Jared, please double-check this conditional -- I n
jdduke (slow)
2015/05/12 22:33:00
This can just be
if (active_status_ == INACTIVE
Donn Denman
2015/05/12 22:52:48
Done.
Noticed we don't need separate nested if's,
| |
190 active_status_ != INSERTION_ACTIVE) { | |
191 if (GetStartPosition() != GetEndPosition() && | |
192 RectFBetweenSelectionBounds(start_, end_).Contains(location)) { | |
193 AllowShowingFromCurrentSelection(); | |
194 return true; | |
195 } | |
196 } | |
197 return false; | |
161 } | 198 } |
162 | 199 |
163 void TouchSelectionController::AllowShowingFromCurrentSelection() { | 200 void TouchSelectionController::AllowShowingFromCurrentSelection() { |
164 if (active_status_ != INACTIVE) | 201 if (active_status_ != INACTIVE) |
165 return; | 202 return; |
166 | 203 |
167 activate_selection_automatically_ = true; | 204 activate_selection_automatically_ = true; |
168 activate_insertion_automatically_ = true; | 205 activate_insertion_automatically_ = true; |
169 if (GetStartPosition() != GetEndPosition()) { | 206 if (GetStartPosition() != GetEndPosition()) { |
170 OnSelectionChanged(); | 207 OnSelectionChanged(); |
171 } else if (start_orientation_ == TouchHandleOrientation::CENTER && | 208 } else if (start_orientation_ == TouchHandleOrientation::CENTER && |
172 selection_editable_) { | 209 selection_editable_) { |
173 OnInsertionChanged(); | 210 OnInsertionChanged(); |
174 } | 211 } |
175 } | 212 } |
176 | 213 |
177 void TouchSelectionController::OnTapEvent() { | |
178 response_pending_input_event_ = TAP; | |
179 if (active_status_ != SELECTION_ACTIVE) | |
180 activate_selection_automatically_ = false; | |
181 ShowInsertionHandleAutomatically(); | |
182 if (selection_empty_ && !show_on_tap_for_empty_editable_) | |
183 DeactivateInsertion(); | |
184 ForceNextUpdateIfInactive(); | |
185 } | |
186 | |
187 void TouchSelectionController::HideAndDisallowShowingAutomatically() { | 214 void TouchSelectionController::HideAndDisallowShowingAutomatically() { |
188 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; | 215 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; |
189 DeactivateInsertion(); | 216 DeactivateInsertion(); |
190 DeactivateSelection(); | 217 DeactivateSelection(); |
191 activate_insertion_automatically_ = false; | 218 activate_insertion_automatically_ = false; |
192 activate_selection_automatically_ = false; | 219 activate_selection_automatically_ = false; |
193 } | 220 } |
194 | 221 |
195 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { | 222 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { |
196 if (temporarily_hidden_ == hidden) | 223 if (temporarily_hidden_ == hidden) |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 529 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
503 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 530 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
504 duration, | 531 duration, |
505 base::TimeDelta::FromMilliseconds(500), | 532 base::TimeDelta::FromMilliseconds(500), |
506 base::TimeDelta::FromSeconds(60), | 533 base::TimeDelta::FromSeconds(60), |
507 60); | 534 60); |
508 } | 535 } |
509 } | 536 } |
510 | 537 |
511 } // namespace ui | 538 } // namespace ui |
OLD | NEW |