Commit acd424b3 authored by Shimi Zhang's avatar Shimi Zhang Committed by Commit Bot

[Blink] Don't select placeholder text in <input> when long press below.

https://crbug.com/873999 shows that placeholder text in <input> could
be selected by long press below it.

This is because for this code path we passed a corrected click point.
y-coordinate was adjusted to 0, which will lead
|LayoutBlock::PositionForPointIfOutsideAtomicInlineLevel()| give a
incorrect result, then in
|SelectionController::SelectClosestWordFromHitTestResult()|, it gets
the placeholder <div> in the <input> Shadow DOM as the hit test result
position.

We now pass the normal point so it could figure out the position is
at <input>, which is more reasonable.

Bug: 873999
Change-Id: I6d9ee4d03778ad65493eff8735d58cf271d07a57
Reviewed-on: https://chromium-review.googlesource.com/1174963
Commit-Queue: Shimi Zhang <ctzsm@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585208}
parent 63e36b8b
......@@ -1024,6 +1024,32 @@ TEST_F(WebViewTest, FinishComposingTextDoesNotAssert) {
WebInputMethodController::kKeepSelection);
}
// Regression test for https://crbug.com/873999
TEST_F(WebViewTest, LongPressOutsideInputShouldNotSelectPlaceholderText) {
RegisterMockedHttpURLLoad("input_placeholder.html");
WebViewImpl* web_view =
web_view_helper_.InitializeAndLoad(base_url_ + "input_placeholder.html");
web_view->SetInitialFocus(false);
web_view->Resize(WebSize(500, 300));
web_view->UpdateAllLifecyclePhases();
RunPendingTasks();
WebString input_id = WebString::FromUTF8("input");
// Focus in input.
EXPECT_TRUE(TapElementById(WebInputEvent::kGestureTap, input_id));
// Long press below input.
WebGestureEvent event(WebInputEvent::kGestureLongPress,
WebInputEvent::kNoModifiers,
WebInputEvent::GetStaticTimeStampForTests(),
kWebGestureDeviceTouchscreen);
event.SetPositionInWidget(WebFloatPoint(100, 150));
EXPECT_EQ(WebInputEventResult::kHandledSystem,
web_view->HandleInputEvent(WebCoalescedInputEvent(event)));
EXPECT_TRUE(web_view->MainFrameImpl()->SelectionAsText().IsEmpty());
}
TEST_F(WebViewTest, FinishComposingTextCursorPositionChange) {
RegisterMockedHttpURLLoad("input_field_populated.html");
WebViewImpl* web_view = web_view_helper_.InitializeAndLoad(
......
......@@ -4757,14 +4757,20 @@ PositionWithAffinity LayoutBlockFlow::PositionForPoint(
}
}
if (closest_box->GetLineLayoutItem().IsAtomicInlineLevel()) {
// We want to pass the original point other than a corrected one.
LayoutPoint point(point_in_logical_contents);
if (!IsHorizontalWritingMode())
point = point.TransposedPoint();
return PositionForPointRespectingEditingBoundaries(
LineLayoutBox(closest_box->GetLineLayoutItem()), point);
}
// pass the box a top position that is inside it
LayoutPoint point(point_in_logical_contents.X(),
closest_box->Root().BlockDirectionPointInLine());
if (!IsHorizontalWritingMode())
point = point.TransposedPoint();
if (closest_box->GetLineLayoutItem().IsAtomicInlineLevel())
return PositionForPointRespectingEditingBoundaries(
LineLayoutBox(closest_box->GetLineLayoutItem()), point);
return closest_box->GetLineLayoutItem().PositionForPoint(point);
}
......
<input id="input" type="text" name="name" placeholder="username" />
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