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

Side by Side Diff: content/browser/renderer_host/input/touch_selection_controller.cc

Issue 657803002: Update touch selection to only modify one selection point at a time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 "content/browser/renderer_host/input/touch_selection_controller.h" 5 #include "content/browser/renderer_host/input/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 "third_party/WebKit/public/web/WebInputEvent.h" 9 #include "third_party/WebKit/public/web/WebInputEvent.h"
10 10
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 202
203 return false; 203 return false;
204 } 204 }
205 205
206 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { 206 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) {
207 if (&handle == insertion_handle_.get()) { 207 if (&handle == insertion_handle_.get()) {
208 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position()); 208 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position());
209 return; 209 return;
210 } 210 }
211 211
212 gfx::PointF fixed_handle_position;
212 if (&handle == start_selection_handle_.get()) { 213 if (&handle == start_selection_handle_.get()) {
213 fixed_handle_position_ = 214 fixed_handle_position =
214 end_selection_handle_->position() + GetEndLineOffset(); 215 end_selection_handle_->position() + GetEndLineOffset();
215 } else { 216 } else {
216 fixed_handle_position_ = 217 fixed_handle_position =
217 start_selection_handle_->position() + GetStartLineOffset(); 218 start_selection_handle_->position() + GetStartLineOffset();
218 } 219 }
220
221 // When moving the handle we want to move only the extent point. Before doing
222 // so we must make sure that the base point is set correctly.
223 gfx::Vector2dF line_offset = &handle == end_selection_handle_.get()
jdduke (slow) 2014/10/15 15:46:07 This could might be more simply folded into the ab
christiank 2014/10/17 14:33:05 Good idea!
224 ? GetStartLineOffset()
225 : GetEndLineOffset();
226 gfx::PointF handle_position = handle.position() + line_offset;
227 client_->SelectBetweenCoordinates(fixed_handle_position, handle_position);
christiank 2014/10/15 09:55:03 Instead of adding a new code path for swapping the
jdduke (slow) 2014/10/15 15:46:07 Ah, I think what you have is reasonable, maybe we
christiank 2014/10/17 14:33:05 I agree, I'll update the names.
228
219 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position()); 229 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position());
220 } 230 }
221 231
222 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, 232 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle,
223 const gfx::PointF& position) { 233 const gfx::PointF& position) {
224 // As the position corresponds to the bottom left point of the selection 234 // As the position corresponds to the bottom left point of the selection
225 // bound, offset it by half the corresponding line height. 235 // bound, offset it by half the corresponding line height.
226 gfx::Vector2dF line_offset = &handle == end_selection_handle_.get() 236 gfx::Vector2dF line_offset = &handle == end_selection_handle_.get()
227 ? GetStartLineOffset() 237 ? GetStartLineOffset()
228 : GetEndLineOffset(); 238 : GetEndLineOffset();
229 gfx::PointF line_position = position + line_offset; 239 gfx::PointF line_position = position + line_offset;
230 if (&handle == insertion_handle_.get()) { 240 if (&handle == insertion_handle_.get()) {
231 client_->MoveCaret(line_position); 241 client_->MoveCaret(line_position);
232 } else { 242 } else {
233 client_->SelectBetweenCoordinates(fixed_handle_position_, line_position); 243 client_->MoveSelectionExtent(line_position);
jdduke (slow) 2014/10/15 15:46:07 Could add a test (or update an existing test) in t
christiank 2014/10/17 14:33:05 Sure, will do!
234 } 244 }
235 } 245 }
236 246
237 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { 247 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) {
238 if (&handle != insertion_handle_.get()) 248 if (&handle != insertion_handle_.get())
239 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED, handle.position()); 249 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED, handle.position());
240 } 250 }
241 251
242 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { 252 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) {
243 if (insertion_handle_ && &handle == insertion_handle_.get()) 253 if (insertion_handle_ && &handle == insertion_handle_.get())
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 } 418 }
409 419
410 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( 420 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle(
411 bool was_active) const { 421 bool was_active) const {
412 return was_active && client_->SupportsAnimation() 422 return was_active && client_->SupportsAnimation()
413 ? TouchHandle::ANIMATION_SMOOTH 423 ? TouchHandle::ANIMATION_SMOOTH
414 : TouchHandle::ANIMATION_NONE; 424 : TouchHandle::ANIMATION_NONE;
415 } 425 }
416 426
417 } // namespace content 427 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698