Commit f113af7b authored by bokan@chromium.org's avatar bokan@chromium.org

Fixed touch selection handle manipulation when pinched in.

This patch applies the pinch viewport offset to selection handle
coordinates when passing the coordinates into Blink. This fixes the case
where selection handles would appear in the wrong place while being
manipulated while pinched in or when the ChromeOS on-screen keyboard is
showing.

BUG=376332

Review URL: https://codereview.chromium.org/319643002

git-svn-id: svn://svn.chromium.org/blink/trunk@175682 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 172ac74b
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
#include "core/editing/markup.h" #include "core/editing/markup.h"
#include "core/frame/Console.h" #include "core/frame/Console.h"
#include "core/frame/DOMWindow.h" #include "core/frame/DOMWindow.h"
#include "core/frame/FrameHost.h"
#include "core/frame/FrameView.h" #include "core/frame/FrameView.h"
#include "core/frame/Settings.h" #include "core/frame/Settings.h"
#include "core/html/HTMLCollection.h" #include "core/html/HTMLCollection.h"
...@@ -1306,8 +1307,12 @@ void WebLocalFrameImpl::setCaretVisible(bool visible) ...@@ -1306,8 +1307,12 @@ void WebLocalFrameImpl::setCaretVisible(bool visible)
VisiblePosition WebLocalFrameImpl::visiblePositionForWindowPoint(const WebPoint& point) VisiblePosition WebLocalFrameImpl::visiblePositionForWindowPoint(const WebPoint& point)
{ {
// FIXME(bokan): crbug.com/371902 - These scale/pinch transforms shouldn't
// be ad hoc and explicit.
PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport();
FloatPoint unscaledPoint(point); FloatPoint unscaledPoint(point);
unscaledPoint.scale(1 / view()->pageScaleFactor(), 1 / view()->pageScaleFactor()); unscaledPoint.scale(1 / view()->pageScaleFactor(), 1 / view()->pageScaleFactor());
unscaledPoint.moveBy(pinchViewport.visibleRect().location());
HitTestRequest request = HitTestRequest::Move | HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent; HitTestRequest request = HitTestRequest::Move | HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent;
HitTestResult result(frame()->view()->windowToContents(roundedIntPoint(unscaledPoint))); HitTestResult result(frame()->view()->windowToContents(roundedIntPoint(unscaledPoint)));
......
...@@ -598,6 +598,41 @@ TEST_F(PinchViewportTest, TestRestoredFromLegacyHistoryItem) ...@@ -598,6 +598,41 @@ TEST_F(PinchViewportTest, TestRestoredFromLegacyHistoryItem)
EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), pinchViewport.visibleRect().location()); EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), pinchViewport.visibleRect().location());
} }
// Test that the coordinates sent into moveRangeSelection are offset by the
// pinch viewport's location.
TEST_F(PinchViewportTest, TestWebFrameRangeAccountsForPinchViewportScroll)
{
initializeWithDesktopSettings();
webViewImpl()->settings()->setDefaultFontSize(12);
webViewImpl()->resize(WebSize(640, 480));
registerMockedHttpURLLoad("move_range.html");
navigateTo(m_baseURL + "move_range.html");
WebRect baseRect;
WebRect extentRect;
webViewImpl()->setPageScaleFactor(2);
WebFrame* mainFrame = webViewImpl()->mainFrame();
// Select some text and get the base and extent rects (that's the start of
// the range and its end). Do a sanity check that the expected text is
// selected
mainFrame->executeScript(WebScriptSource("selectRange();"));
EXPECT_EQ("ir", mainFrame->selectionAsText().utf8());
webViewImpl()->selectionBounds(baseRect, extentRect);
WebPoint initialPoint(baseRect.x, baseRect.y);
WebPoint endPoint(extentRect.x, extentRect.y);
// Move the pinch viewport over and make the selection in the same
// screen-space location. The selection should change to two characters to
// the right and down one line.
PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport();
pinchViewport.move(FloatPoint(60, 25));
mainFrame->moveRangeSelection(initialPoint, endPoint);
EXPECT_EQ("t ", mainFrame->selectionAsText().utf8());
}
// Test that the scrollFocusedNodeIntoRect method works with the pinch viewport. // Test that the scrollFocusedNodeIntoRect method works with the pinch viewport.
TEST_F(PinchViewportTest, TestScrollFocusedNodeIntoRect) TEST_F(PinchViewportTest, TestScrollFocusedNodeIntoRect)
{ {
......
<!DOCTYPE html>
<html>
<head>
<style>
.text {
font-family: courier;
font-size: 12px;
padding: 0px;
margin: 0px;
border: 0px;
}
</style>
</head>
<body>
<textarea id='target' class="text" type='text' rows="3" cols="20">
First Line
Second Text Row
</textarea>
<script>
function selectCaret() {
var text = document.getElementById('target');
text.focus();
text.setSelectionRange(17, 17);
}
function selectRange() {
var text = document.getElementById('target');
text.focus();
text.setSelectionRange(1, 3);
}
</script>
</body>
</html>
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