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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/touch_selection/touch_selection_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/touch_selection/touch_selection_controller.cc
diff --git a/ui/touch_selection/touch_selection_controller.cc b/ui/touch_selection/touch_selection_controller.cc
index f5a4bda90a6d6704702a2c57a1099b78c54c544f..d53f4095e05195aa24e52ff1f6ea2a45770a8632 100644
--- a/ui/touch_selection/touch_selection_controller.cc
+++ b/ui/touch_selection/touch_selection_controller.cc
@@ -10,6 +10,18 @@
namespace ui {
namespace {
+gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound) {
+ gfx::Vector2dF line_offset =
+ gfx::ScaleVector2d(bound.edge_top() - bound.edge_bottom(), 0.5f);
+ // An offset of 5 DIPs is sufficient for most line sizes. For small lines,
+ // using half the line height avoids synthesizing a point on a line above
+ // (or below) the intended line.
+ const gfx::Vector2dF kMaxLineOffset(5.f, 5.f);
+ line_offset.SetToMin(kMaxLineOffset);
+ line_offset.SetToMax(-kMaxLineOffset);
+ return line_offset;
+}
+
TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) {
switch (type) {
case SelectionBound::LEFT:
@@ -239,7 +251,7 @@ void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle,
const gfx::PointF& position) {
// As the position corresponds to the bottom left point of the selection
// bound, offset it by half the corresponding line height.
- gfx::Vector2dF line_offset = &handle == end_selection_handle_.get()
+ gfx::Vector2dF line_offset = &handle == start_selection_handle_.get()
? GetStartLineOffset()
: GetEndLineOffset();
gfx::PointF line_position = position + line_offset;
@@ -408,11 +420,11 @@ const gfx::PointF& TouchSelectionController::GetEndPosition() const {
}
gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const {
- return gfx::ScaleVector2d(start_.edge_top() - start_.edge_bottom(), 0.5f);
+ return ComputeLineOffsetFromBottom(start_);
}
gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const {
- return gfx::ScaleVector2d(end_.edge_top() - end_.edge_bottom(), 0.5f);
+ return ComputeLineOffsetFromBottom(end_);
}
bool TouchSelectionController::GetStartVisible() const {
« 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