Commit 66701aef authored by WangHui's avatar WangHui Committed by Commit Bot

FindInPage: Don't show tickmark for empty ActiveMatchRect.

The ActiveMatch may be null when make a FindRequest with options that kWrapAround is
false, while the active_rect in |FindRequestManager| will not update when it is
empty then we will show a incorrect tickmark(active_rect of last FindRequest)
on Android. so We should reset the active_rect in |FindRequestManager| when there
is a new FindRequest.

Bug: 1141374

Change-Id: Ieac210a2b72f4f92649e68e1b2e2969fd707dbf2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2491726Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Filip Gorski <fgorski@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825424}
parent c76d5aef
......@@ -276,25 +276,20 @@ public class FindResultBar extends View {
// Draw the active tickmark on top (covering up the inactive tickmark
// we probably already drew for it).
if (mActiveMatch != null) {
Tickmark tickmark;
if (mActiveMatch != null && !mActiveMatch.isEmpty()) {
int i = Arrays.binarySearch(mMatches, mActiveMatch, sComparator);
if (i >= 0) {
// We've already generated a tickmark for all rects in mMatches,
// so use the corresponding one. However it was generated
// assuming the match would be inactive. Keep the position, but
// re-expand it using mActiveMinHeight.
tickmark = expandTickmarkToMinHeight(mTickmarks.get(i), true);
} else {
// How strange - mActiveMatch isn't in mMatches. Do our best to
// draw it anyway (though it might not line up exactly).
tickmark = tickmarkForRect(mActiveMatch, true);
Tickmark tickmark = expandTickmarkToMinHeight(mTickmarks.get(i), true);
RectF rect = tickmark.toRectF();
mFillPaint.setColor(mActiveColor);
mStrokePaint.setColor(mActiveBorderColor);
canvas.drawRoundRect(rect, 2, 2, mFillPaint);
canvas.drawRoundRect(rect, 2, 2, mStrokePaint);
}
RectF rect = tickmark.toRectF();
mFillPaint.setColor(mActiveColor);
mStrokePaint.setColor(mActiveBorderColor);
canvas.drawRoundRect(rect, 2, 2, mFillPaint);
canvas.drawRoundRect(rect, 2, 2, mStrokePaint);
}
}
......
......@@ -519,6 +519,7 @@ void FindRequestManager::OnGetNearestFindResultReply(RenderFrameHostImpl* rfh,
void FindRequestManager::RequestFindMatchRects(int current_version) {
match_rects_.pending_replies.clear();
match_rects_.request_version = current_version;
match_rects_.active_rect = gfx::RectF();
// Request the latest find match rects from each frame.
for (WebContentsImpl* contents : contents_->GetWebContentsAndAllInner()) {
......
......@@ -693,6 +693,37 @@ IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindInPage_Issue644448)) {
}
#if defined(OS_ANDROID)
// Tests empty active match rect when kWrapAround is false.
IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, EmptyActiveMatchRect) {
LoadAndWait("/find_in_page.html");
// kWrapAround is false by default.
auto default_options = blink::mojom::FindOptions::New();
default_options->run_synchronously_for_testing = true;
Find("result 01", default_options.Clone());
delegate()->WaitForFinalReply();
EXPECT_EQ(1, delegate()->GetFindResults().number_of_matches);
// Request the find match rects.
contents()->RequestFindMatchRects(-1);
delegate()->WaitForMatchRects();
const std::vector<gfx::RectF>& rects = delegate()->find_match_rects();
// The first match should be active.
EXPECT_EQ(rects[0], delegate()->active_match_rect());
Find("result 00", default_options.Clone());
delegate()->WaitForFinalReply();
EXPECT_EQ(1, delegate()->GetFindResults().number_of_matches);
// Request the find match rects.
contents()->RequestFindMatchRects(-1);
delegate()->WaitForMatchRects();
// The active match rect should be empty.
EXPECT_EQ(gfx::RectF(), delegate()->active_match_rect());
}
// TODO(wjmaclean): This test, if re-enabled, may require work to make it
// OOPIF-compatible.
// Tests requesting find match rects.
......
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