summaryrefslogtreecommitdiff
path: root/xfa/fde
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-04-24 16:19:08 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-24 16:19:08 +0000
commit273c598ef5e7e9ee210a8e6645b3a83b9f21a1da (patch)
tree300429912d599179dc2d1faf9ab6c28a0d88234f /xfa/fde
parent90e03b9b3f459e8812301b58ec0952b136f23a53 (diff)
downloadpdfium-273c598ef5e7e9ee210a8e6645b3a83b9f21a1da.tar.xz
Fix caret moving to next line on click in multiline XFA edit.
On a mouse click after the end of a line (except for the last line) in an XFA text edit, the caret was moved to the beginning of the next line, as the position after the space was actually in the next line. This CL changes the behavior so that the caret is positioned before the space in this case. Note it's possible to click directly to that position by clicking on the beginning of the next line. Bug: chromium:832293 Change-Id: Ib376e4cca7b32a87d478d3346cb3d8f3bd825daa Reviewed-on: https://pdfium-review.googlesource.com/31110 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'xfa/fde')
-rw-r--r--xfa/fde/cfde_texteditengine.cpp14
-rw-r--r--xfa/fde/cfde_texteditengine_unittest.cpp11
2 files changed, 22 insertions, 3 deletions
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp
index fd5b10119b..1b6e29de08 100644
--- a/xfa/fde/cfde_texteditengine.cpp
+++ b/xfa/fde/cfde_texteditengine.cpp
@@ -937,8 +937,18 @@ size_t CFDE_TextEditEngine::GetIndexForPoint(const CFX_PointF& point) {
// 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_);
+ size_t pos = std::min(
+ static_cast<size_t>(start_it->nStart + start_it->nCount), text_length_);
+
+ // The line is not the last one and it was broken right after a space, the
+ // cursor should not be placed after the space, but before it. If the
+ // cursor is moved after the space, it goes to the beginning of the next
+ // line.
+ bool is_last_line = (std::next(start_it) == text_piece_info_.end());
+ if (!is_last_line && pos > 0 && GetChar(pos - 1) == L' ')
+ --pos;
+
+ return pos;
}
if (start_it == text_piece_info_.end())
diff --git a/xfa/fde/cfde_texteditengine_unittest.cpp b/xfa/fde/cfde_texteditengine_unittest.cpp
index 7ae001af91..bd74868438 100644
--- a/xfa/fde/cfde_texteditengine_unittest.cpp
+++ b/xfa/fde/cfde_texteditengine_unittest.cpp
@@ -427,11 +427,20 @@ TEST_F(CFDE_TextEditEngineTest, GetIndexForPointMultiline) {
L"getting indexes on multi-line edits.");
EXPECT_EQ(0U, engine()->GetIndexForPoint({0.0f, 0.0f}));
EXPECT_EQ(87U, engine()->GetIndexForPoint({999999.0f, 9999999.0f}));
- EXPECT_EQ(12U, engine()->GetIndexForPoint({999999.0f, 0.0f}));
+ EXPECT_EQ(11U, engine()->GetIndexForPoint({999999.0f, 0.0f}));
+ EXPECT_EQ(12U, engine()->GetIndexForPoint({1.0f, 10.0f}));
EXPECT_EQ(1U, engine()->GetIndexForPoint({5.0f, 5.0f}));
EXPECT_EQ(2U, engine()->GetIndexForPoint({10.0f, 5.0f}));
}
+TEST_F(CFDE_TextEditEngineTest, GetIndexForPointSpaceAtEnd) {
+ engine()->SetFontSize(10.0f);
+ engine()->Insert(0, L"Hello World ");
+ EXPECT_EQ(0U, engine()->GetIndexForPoint({0.0f, 0.0f}));
+ EXPECT_EQ(12U, engine()->GetIndexForPoint({999999.0f, 9999999.0f}));
+ EXPECT_EQ(12U, engine()->GetIndexForPoint({999999.0f, 0.0f}));
+}
+
TEST_F(CFDE_TextEditEngineTest, BoundsForWordAt) {
size_t start_idx;
size_t count;