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

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

Issue 872083002: Ease selection dragging between large/small text lines (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 5 years, 11 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
« no previous file with comments | « no previous file | ui/touch_selection/touch_selection_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9
10 namespace ui { 10 namespace ui {
11 namespace { 11 namespace {
12 12
13 gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound) {
14 gfx::Vector2dF line_offset =
15 gfx::ScaleVector2d(bound.edge_top() - bound.edge_bottom(), 0.5f);
16 // An offset of 5 DIPs is sufficient for most line sizes. For small lines,
17 // using half the line height avoids synthesizing a point on a line above
18 // (or below) the intended line.
19 const gfx::Vector2dF kMaxLineOffset(5.f, 5.f);
20 line_offset.SetToMin(kMaxLineOffset);
21 line_offset.SetToMax(-kMaxLineOffset);
22 return line_offset;
23 }
24
13 TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) { 25 TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) {
14 switch (type) { 26 switch (type) {
15 case SelectionBound::LEFT: 27 case SelectionBound::LEFT:
16 return TOUCH_HANDLE_LEFT; 28 return TOUCH_HANDLE_LEFT;
17 case SelectionBound::RIGHT: 29 case SelectionBound::RIGHT:
18 return TOUCH_HANDLE_RIGHT; 30 return TOUCH_HANDLE_RIGHT;
19 case SelectionBound::CENTER: 31 case SelectionBound::CENTER:
20 return TOUCH_HANDLE_CENTER; 32 return TOUCH_HANDLE_CENTER;
21 case SelectionBound::EMPTY: 33 case SelectionBound::EMPTY:
22 return TOUCH_HANDLE_ORIENTATION_UNDEFINED; 34 return TOUCH_HANDLE_ORIENTATION_UNDEFINED;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // so we must make sure that the base point is set correctly. 244 // so we must make sure that the base point is set correctly.
233 client_->SelectBetweenCoordinates(base, extent); 245 client_->SelectBetweenCoordinates(base, extent);
234 246
235 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position()); 247 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position());
236 } 248 }
237 249
238 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, 250 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle,
239 const gfx::PointF& position) { 251 const gfx::PointF& position) {
240 // As the position corresponds to the bottom left point of the selection 252 // As the position corresponds to the bottom left point of the selection
241 // bound, offset it by half the corresponding line height. 253 // bound, offset it by half the corresponding line height.
242 gfx::Vector2dF line_offset = &handle == end_selection_handle_.get() 254 gfx::Vector2dF line_offset = &handle == start_selection_handle_.get()
243 ? GetStartLineOffset() 255 ? GetStartLineOffset()
244 : GetEndLineOffset(); 256 : GetEndLineOffset();
245 gfx::PointF line_position = position + line_offset; 257 gfx::PointF line_position = position + line_offset;
246 if (&handle == insertion_handle_.get()) { 258 if (&handle == insertion_handle_.get()) {
247 client_->MoveCaret(line_position); 259 client_->MoveCaret(line_position);
248 } else { 260 } else {
249 client_->MoveRangeSelectionExtent(line_position); 261 client_->MoveRangeSelectionExtent(line_position);
250 } 262 }
251 } 263 }
252 264
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 413
402 const gfx::PointF& TouchSelectionController::GetStartPosition() const { 414 const gfx::PointF& TouchSelectionController::GetStartPosition() const {
403 return start_.edge_bottom(); 415 return start_.edge_bottom();
404 } 416 }
405 417
406 const gfx::PointF& TouchSelectionController::GetEndPosition() const { 418 const gfx::PointF& TouchSelectionController::GetEndPosition() const {
407 return end_.edge_bottom(); 419 return end_.edge_bottom();
408 } 420 }
409 421
410 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { 422 gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const {
411 return gfx::ScaleVector2d(start_.edge_top() - start_.edge_bottom(), 0.5f); 423 return ComputeLineOffsetFromBottom(start_);
412 } 424 }
413 425
414 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { 426 gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const {
415 return gfx::ScaleVector2d(end_.edge_top() - end_.edge_bottom(), 0.5f); 427 return ComputeLineOffsetFromBottom(end_);
416 } 428 }
417 429
418 bool TouchSelectionController::GetStartVisible() const { 430 bool TouchSelectionController::GetStartVisible() const {
419 return start_.visible() && !temporarily_hidden_; 431 return start_.visible() && !temporarily_hidden_;
420 } 432 }
421 433
422 bool TouchSelectionController::GetEndVisible() const { 434 bool TouchSelectionController::GetEndVisible() const {
423 return end_.visible() && !temporarily_hidden_; 435 return end_.visible() && !temporarily_hidden_;
424 } 436 }
425 437
426 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( 438 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle(
427 bool was_active) const { 439 bool was_active) const {
428 return was_active && client_->SupportsAnimation() 440 return was_active && client_->SupportsAnimation()
429 ? TouchHandle::ANIMATION_SMOOTH 441 ? TouchHandle::ANIMATION_SMOOTH
430 : TouchHandle::ANIMATION_NONE; 442 : TouchHandle::ANIMATION_NONE;
431 } 443 }
432 444
433 } // namespace ui 445 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/touch_selection/touch_selection_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698