event.clientX/clientY should be in layout viewport coordinates
https://bugs.webkit.org/show_bug.cgi?id=172018
Reviewed by Zalan Bujtas.
Source/WebCore:
Fix clientX and clientY on mouse events to be relative to the layout viewport, to match
getBoundingClientRect(), getClientRects() and fixed-position objects.
Also minor cleanup of MouseRelatedEvent to use initializers.
Test: fast/visual-viewport/client-coordinates-relative-to-layout-viewport.html
* dom/MouseRelatedEvent.cpp:
(WebCore::MouseRelatedEvent::MouseRelatedEvent):
(WebCore::MouseRelatedEvent::init):
(WebCore::MouseRelatedEvent::initCoordinates):
(WebCore::contentsScrollOffset): Deleted.
* dom/MouseRelatedEvent.h:
LayoutTests:
* fast/events/clientXY-in-zoom-and-scroll.html:
* fast/visual-viewport/client-coordinates-relative-to-layout-viewport-expected.txt: Added.
* fast/visual-viewport/client-coordinates-relative-to-layout-viewport.html: Added.
* platform/ios/TestExpectations:
* platform/mac/fast/events/clientXY-in-zoom-and-scroll-expected.txt:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@216824 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/dom/MouseRelatedEvent.cpp b/Source/WebCore/dom/MouseRelatedEvent.cpp
index 829126b..7eb8453 100644
--- a/Source/WebCore/dom/MouseRelatedEvent.cpp
+++ b/Source/WebCore/dom/MouseRelatedEvent.cpp
@@ -31,30 +31,6 @@
namespace WebCore {
-MouseRelatedEvent::MouseRelatedEvent()
- : m_isSimulated(false)
- , m_hasCachedRelativePosition(false)
-{
-}
-
-static LayoutSize contentsScrollOffset(DOMWindow* DOMWindow)
-{
- if (!DOMWindow)
- return LayoutSize();
- Frame* frame = DOMWindow->frame();
- if (!frame)
- return LayoutSize();
- FrameView* frameView = frame->view();
- if (!frameView)
- return LayoutSize();
-#if !PLATFORM(IOS)
- float scaleFactor = frame->pageZoomFactor() * frame->frameScaleFactor();
- return LayoutSize(frameView->scrollX() / scaleFactor, frameView->scrollY() / scaleFactor);
-#else
- return LayoutSize(frameView->actualScrollX(), frameView->actualScrollY());
-#endif
-}
-
MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubble, bool cancelable, double timestamp, DOMWindow* DOMWindow,
int detail, const IntPoint& screenLocation, const IntPoint& windowLocation,
#if ENABLE(POINTER_LOCK)
@@ -77,32 +53,22 @@
#if ENABLE(POINTER_LOCK)
, m_movementDelta(IntPoint(0, 0))
#endif
- , m_isSimulated(false)
{
init(false, IntPoint(0, 0));
}
void MouseRelatedEvent::init(bool isSimulated, const IntPoint& windowLocation)
{
- LayoutPoint adjustedPageLocation;
- LayoutPoint scrollPosition;
-
- Frame* frame = view() ? view()->frame() : nullptr;
+ auto* frame = view() ? view()->frame() : nullptr;
if (frame && !isSimulated) {
if (FrameView* frameView = frame->view()) {
- scrollPosition = frameView->contentsScrollPosition();
- adjustedPageLocation = frameView->windowToContents(windowLocation);
- float scaleFactor = 1 / (frame->pageZoomFactor() * frame->frameScaleFactor());
- if (scaleFactor != 1.0f) {
- adjustedPageLocation.scale(scaleFactor);
- scrollPosition.scale(scaleFactor);
- }
+ FloatPoint absolutePoint = frameView->windowToContents(windowLocation);
+ FloatPoint documentPoint = frameView->absoluteToDocumentPoint(absolutePoint);
+ m_pageLocation = flooredLayoutPoint(documentPoint);
+ m_clientLocation = flooredLayoutPoint(frameView->documentToClientPoint(documentPoint));
}
}
- m_clientLocation = adjustedPageLocation - toLayoutSize(scrollPosition);
- m_pageLocation = adjustedPageLocation;
-
initCoordinates();
}
@@ -121,8 +87,15 @@
{
// Set up initial values for coordinates.
// Correct values are computed lazily, see computeRelativePosition.
+ FloatSize documentToClientOffset;
+ auto* frame = view() ? view()->frame() : nullptr;
+ if (frame) {
+ if (FrameView* frameView = frame->view())
+ documentToClientOffset = frameView->documentToClientOffset();
+ }
+
m_clientLocation = clientLocation;
- m_pageLocation = clientLocation + contentsScrollOffset(view());
+ m_pageLocation = clientLocation - LayoutSize(documentToClientOffset);
m_layerLocation = m_pageLocation;
m_offsetLocation = m_pageLocation;