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

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

Issue 1102933003: [Contextual Search] Add support for tap on the selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 if ((event_pos - GetStartPosition()).LengthSquared() <= 144 if ((event_pos - GetStartPosition()).LengthSquared() <=
145 (event_pos - GetEndPosition()).LengthSquared()) 145 (event_pos - GetEndPosition()).LengthSquared())
146 return start_selection_handle_->WillHandleTouchEvent(event); 146 return start_selection_handle_->WillHandleTouchEvent(event);
147 else 147 else
148 return end_selection_handle_->WillHandleTouchEvent(event); 148 return end_selection_handle_->WillHandleTouchEvent(event);
149 } 149 }
150 150
151 return false; 151 return false;
152 } 152 }
153 153
154 void TouchSelectionController::OnLongPressEvent() { 154 bool TouchSelectionController::WillHandleLongPressEvent(
155 const gfx::PointF& location) {
156 // If there is an active selection that was not triggered by a user gesture,
157 // allow showing the handles for that selection if a long-press occurs within
158 // the selection rect. Note that this hit test is at best a crude
159 // approximation, and may swallow taps that actually fall outside the
160 // real selection.
161 if (!is_selection_active_ && !is_insertion_active_) {
162 if (GetStartPosition() != GetEndPosition() &&
163 RectFBetweenSelectionBounds(start_, end_).Contains(location)) {
164 AllowShowingFromCurrentSelection();
165 return true;
166 }
167 }
168
155 response_pending_input_event_ = LONG_PRESS; 169 response_pending_input_event_ = LONG_PRESS;
156 ShowSelectionHandlesAutomatically(); 170 ShowSelectionHandlesAutomatically();
157 ShowInsertionHandleAutomatically(); 171 ShowInsertionHandleAutomatically();
158 ResetCachedValuesIfInactive(); 172 ResetCachedValuesIfInactive();
173 return false;
159 } 174 }
160 175
161 void TouchSelectionController::AllowShowingFromCurrentSelection() { 176 void TouchSelectionController::AllowShowingFromCurrentSelection() {
162 if (is_selection_active_ || is_insertion_active_) 177 if (is_selection_active_ || is_insertion_active_)
163 return; 178 return;
164 179
165 activate_selection_automatically_ = true; 180 activate_selection_automatically_ = true;
166 activate_insertion_automatically_ = true; 181 activate_insertion_automatically_ = true;
167 if (GetStartPosition() != GetEndPosition()) 182 if (GetStartPosition() != GetEndPosition())
168 OnSelectionChanged(); 183 OnSelectionChanged();
169 else if (start_orientation_ == TouchHandleOrientation::CENTER && 184 else if (start_orientation_ == TouchHandleOrientation::CENTER &&
170 selection_editable_) 185 selection_editable_)
171 OnInsertionChanged(); 186 OnInsertionChanged();
172 } 187 }
173 188
174 void TouchSelectionController::OnTapEvent() { 189 bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location) {
190 // If there is an active selection that was not triggered by a user gesture,
191 // allow showing the handles for that selection if the tap occurs within the
192 // selection rect. Note that this hit test is at best a crude approximation,
193 // and may swallow taps that actually fall outside the real selection.
194 if (!is_selection_active_ && !is_insertion_active_) {
jdduke (slow) 2015/05/01 20:52:06 Can we split this logic out into a shared function
Donn Denman 2015/05/01 22:46:03 Done.
195 if (GetStartPosition() != GetEndPosition() &&
196 RectFBetweenSelectionBounds(start_, end_).Contains(location)) {
197 AllowShowingFromCurrentSelection();
198 return true;
199 }
200 }
175 response_pending_input_event_ = TAP; 201 response_pending_input_event_ = TAP;
176 ShowInsertionHandleAutomatically(); 202 ShowInsertionHandleAutomatically();
177 if (selection_empty_ && !show_on_tap_for_empty_editable_) 203 if (selection_empty_ && !show_on_tap_for_empty_editable_)
178 DeactivateInsertion(); 204 DeactivateInsertion();
179 ResetCachedValuesIfInactive(); 205 ResetCachedValuesIfInactive();
206 return false;
180 } 207 }
181 208
182 void TouchSelectionController::HideAndDisallowShowingAutomatically() { 209 void TouchSelectionController::HideAndDisallowShowingAutomatically() {
183 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 210 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
184 DeactivateInsertion(); 211 DeactivateInsertion();
185 DeactivateSelection(); 212 DeactivateSelection();
186 activate_insertion_automatically_ = false; 213 activate_insertion_automatically_ = false;
187 activate_selection_automatically_ = false; 214 activate_selection_automatically_ = false;
188 } 215 }
189 216
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; 528 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
502 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", 529 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
503 duration, 530 duration,
504 base::TimeDelta::FromMilliseconds(500), 531 base::TimeDelta::FromMilliseconds(500),
505 base::TimeDelta::FromSeconds(60), 532 base::TimeDelta::FromSeconds(60),
506 60); 533 60);
507 } 534 }
508 } 535 }
509 536
510 } // namespace ui 537 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698