Commit da71e35a authored by Tessa Nijssen's avatar Tessa Nijssen Committed by Commit Bot

[Mac] Look Up Overlay Appears on First Line

Currently, when a user selects multiple lines of text, right clicks, and
selects "Look Up", the yellow overlay appears on the last line of the
selected text but with the text of the first line of the selected text.

WebSubstringUtil::GetBaselinePoint() was modified to call
FirstRectForRange() instead of ComputeTextRect(). FirstRectForRange()
returns the IntRect for the first line of text which is needed to get
the baseline point of the first line of text.

WebViewTest.WebSubstringUtilBaselinePoint was added to test that the
baseline point does not change when multiple lines of text are selected
compared to a single line of text.

Bug: 819864
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: Iec0bac8d45baf2142ea5e826ebdfd7d997e7f584
Reviewed-on: https://chromium-review.googlesource.com/1103448
Commit-Queue: Tessa Nijssen <tnijssen@google.com>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarSarah Chan <spqchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579094}
parent 940dc201
......@@ -142,7 +142,7 @@ NSAttributedString* AttributedSubstringFromRange(const EphemeralRange& range,
WebPoint GetBaselinePoint(LocalFrameView* frame_view,
const EphemeralRange& range,
NSAttributedString* string) {
IntRect string_rect = frame_view->FrameToViewport(ComputeTextRect(range));
IntRect string_rect = frame_view->FrameToViewport(FirstRectForRange(range));
IntPoint string_point = string_rect.MinXMaxYCorner();
// Adjust for the font's descender. AppKit wants the baseline point.
......
......@@ -4467,6 +4467,24 @@ TEST_F(WebViewTest, WebSubstringUtil) {
ASSERT_TRUE(!!result);
}
TEST_F(WebViewTest, WebSubstringUtilBaselinePoint) {
RegisterMockedHttpURLLoad("content_editable_multiline.html");
WebViewImpl* web_view = web_view_helper_.InitializeAndLoad(
base_url_ + "content_editable_multiline.html");
web_view->GetSettings()->SetDefaultFontSize(12);
web_view->Resize(WebSize(400, 400));
WebLocalFrameImpl* frame = web_view->MainFrameImpl();
WebPoint old_point;
WebSubstringUtil::AttributedSubstringInRange(frame, 3, 1, &old_point);
WebPoint new_point;
WebSubstringUtil::AttributedSubstringInRange(frame, 3, 20, &new_point);
EXPECT_EQ(old_point.x, new_point.x);
EXPECT_EQ(old_point.y, new_point.y);
}
TEST_F(WebViewTest, WebSubstringUtilPinchZoom) {
RegisterMockedHttpURLLoad("content_editable_populated.html");
WebViewImpl* web_view = web_view_helper_.InitializeAndLoad(
......
<span contenteditable="true">0123456789<br>abcdefghijklmnopqrstuvwxyz</span>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment