Commit 25fcb272 authored by David Bokan's avatar David Bokan Committed by Commit Bot

[root layer scrolls] Fix Android Find in page

This patch fixes the Android find-in-page feature when used by dragging
down the tickmarks. The issue was that prior to RLS, absolute
coordinates were equivalent to "document" coordinates. That meant that
after scrolling, they don't change. When RLS is turned on, absolute
coordinates are frame-relative so scrolling will change the location of
an absolute rect.

This find in page feature would scroll the text match into view and then
attempt to zoom in on it. However, because of the above change, the
coordinates used for the zoom have now changed. The solution here is to
simply query the bounding rect after the scroll into view again.

Bug: 828758
Change-Id: I807a05b89707080b1eed1bb3682147411776aa44
Reviewed-on: https://chromium-review.googlesource.com/1004010Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549526}
parent e5d2356b
......@@ -766,6 +766,21 @@ int TextFinder::SelectFindMatch(unsigned index, WebRect* selection_rect) {
WebScrollIntoViewParams(ScrollAlignment::kAlignCenterIfNeeded,
ScrollAlignment::kAlignCenterIfNeeded,
kUserScroll));
if (RuntimeEnabledFeatures::RootLayerScrollingEnabled()) {
// If RLS is on, absolute coordinates are scroll-variant so the
// bounding box will change if the page is scrolled by
// ScrollRectToVisible above. Recompute the bounding box so we have the
// updated location for the zoom below.
// TODO(bokan): This should really use the return value from
// ScrollRectToVisible which returns the updated position of the
// scrolled rect. However, this was recently added and this is a fix
// that needs to be merged to a release branch.
// https://crbug.com/823365.
active_match_bounding_box =
EnclosingIntRect(LayoutObject::AbsoluteBoundingBoxRectForRange(
EphemeralRange(active_match_.Get())));
}
}
// Zoom to the active match.
......
......@@ -11737,6 +11737,80 @@ TEST_P(WebFrameSimTest, TickmarksDocumentRelative) {
EXPECT_EQ(IntPoint(800, 2000), original_tickmarks[0].Location());
}
TEST_P(WebFrameSimTest, FindInPageSelectNextMatch) {
WebView().Resize(WebSize(500, 300));
WebView().GetPage()->GetSettings().SetTextAutosizingEnabled(false);
SimRequest request("https://example.com/test.html", "text/html");
LoadURL("https://example.com/test.html");
request.Complete(R"HTML(
<!DOCTYPE html>
<style>
body, html {
width: 4000px;
height: 4000px;
margin: 0;
}
#box1 {
position: absolute;
left: 800px;
top: 2000px;
}
#box2 {
position: absolute;
left: 1000px;
top: 3000px;
}
</style>
<div id="box1">test</div>
<div id="box2">test</div>
)HTML");
Compositor().BeginFrame();
WebLocalFrameImpl* frame = ToWebLocalFrameImpl(WebView().MainFrame());
LocalFrameView* frame_view =
ToLocalFrame(WebView().GetPage()->MainFrame())->View();
Element* box1 = GetDocument().getElementById("box1");
Element* box2 = GetDocument().getElementById("box2");
IntRect box1_rect = box1->GetLayoutObject()->AbsoluteBoundingBoxRect();
IntRect box2_rect = box2->GetLayoutObject()->AbsoluteBoundingBoxRect();
frame_view->GetScrollableArea()->SetScrollOffset(ScrollOffset(3000, 1000),
kProgrammaticScroll);
WebFindOptions options;
WebString search_text = WebString::FromUTF8("test");
const int kFindIdentifier = 12345;
EXPECT_TRUE(frame->Find(kFindIdentifier, search_text, options, false));
frame->EnsureTextFinder().ResetMatchCount();
frame->EnsureTextFinder().StartScopingStringMatches(kFindIdentifier,
search_text, options);
RunPendingTasks();
WebVector<WebFloatRect> web_match_rects;
frame->FindMatchRects(web_match_rects);
ASSERT_EQ(2ul, web_match_rects.size());
FloatRect result_rect = static_cast<FloatRect>(web_match_rects[0]);
frame->SelectNearestFindMatch(result_rect.Center(), nullptr);
LocalFrame* local_frame = ToLocalFrame(WebView().GetPage()->MainFrame());
VisualViewport& visual_viewport = local_frame->GetPage()->GetVisualViewport();
EXPECT_TRUE(visual_viewport.VisibleRectInDocument().Contains(box1_rect));
result_rect = static_cast<FloatRect>(web_match_rects[1]);
frame->SelectNearestFindMatch(result_rect.Center(), nullptr);
EXPECT_TRUE(visual_viewport.VisibleRectInDocument().Contains(box2_rect))
<< "Box [" << box2_rect.ToString() << "] is not visible in viewport ["
<< visual_viewport.VisibleRectInDocument().ToString() << "]";
}
TEST_P(WebFrameSimTest, TestScrollFocusedEditableElementIntoView) {
WebView().Resize(WebSize(500, 300));
WebView().SetDefaultPageScaleLimits(1.f, 4);
......
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