summaryrefslogtreecommitdiff
path: root/xfa/fde/cfde_texteditengine.cpp
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-04-19 21:33:53 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-19 21:33:53 +0000
commit8549ab48a5f8b613ea35dfd64f925fd0438efd0d (patch)
treed3cfe056c721f956c9635ef69421e66e06ebc04a /xfa/fde/cfde_texteditengine.cpp
parentee96772e0878fa385b9a4a736a2fc109e19fd01e (diff)
downloadpdfium-8549ab48a5f8b613ea35dfd64f925fd0438efd0d.tar.xz
Fix caret moving to start of edit on click after the text.
It now moves to the end of the edit text instead. In a multiline edit, clicking after the end of a line in the middle of the text moves the caret to the beginning of the next line. This is a known issue to be addressed later. Bug: chromium:832293 Change-Id: I55ca1f7eebf935fbb7d9526f115489bdfbd8ba1c Reviewed-on: https://pdfium-review.googlesource.com/31012 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fde/cfde_texteditengine.cpp')
-rw-r--r--xfa/fde/cfde_texteditengine.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp
index 39396ad00d..ac66fd7f99 100644
--- a/xfa/fde/cfde_texteditengine.cpp
+++ b/xfa/fde/cfde_texteditengine.cpp
@@ -899,12 +899,19 @@ size_t CFDE_TextEditEngine::GetIndexForPoint(const CFX_PointF& point) {
size_t start_it_idx = start_it->nStart;
for (; start_it <= end_it; ++start_it) {
- if (!start_it->rtPiece.Contains(point))
+ // We need to handle clicking off the end of the line. Using Contains()
+ // would constrain the detection to the text on the line.
+ bool piece_contains_point_vertically =
+ (point.y >= start_it->rtPiece.top &&
+ point.y < start_it->rtPiece.bottom());
+ if (!piece_contains_point_vertically)
continue;
std::vector<CFX_RectF> rects = GetCharRects(*start_it);
for (size_t i = 0; i < rects.size(); ++i) {
- if (!rects[i].Contains(point))
+ bool character_contains_point_horizontally =
+ (point.x >= rects[i].left && point.x < rects[i].right());
+ if (!character_contains_point_horizontally)
continue;
size_t pos = start_it->nStart + i;
if (pos >= text_length_)
@@ -920,6 +927,13 @@ size_t CFDE_TextEditEngine::GetIndexForPoint(const CFX_PointF& point) {
// TODO(dsinclair): Old code had a before flag set based on bidi?
return pos;
}
+
+ // Point is not within the horizontal range of any characters, it's
+ // afterwards. Return the position after the the last character.
+ // The last line has nCount equal to the number of characters + 1 (sentinel
+ // character maybe?). Restrict to the text_length_ to account for that.
+ return std::min(static_cast<size_t>(start_it->nStart + start_it->nCount),
+ text_length_);
}
if (start_it == text_piece_info_.end())