[iOS WK2] Make window.scroll() and window.scrollBy() work
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Apr 2014 20:31:35 +0000 (20:31 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Apr 2014 20:31:35 +0000 (20:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131848
<rdar://problem/16638319>

Reviewed by Beth Dakin.

The scrolling-related functions in DOMWindow were #ifdeffed for iOS
to use the hacky WK1-specific "actual scroll" functions, which do nothing
in WK2.

Fix by adding a scroll position wrapper (contentsScrollPosition) which does
the right thing on WK1 and WK2, and change almost all the places that used "actualScrollPosition"
to us it (with the exception of contentsScrollOffset() in MouseRelatedEvent.cpp, which has
confusing scaling behavior).

* dom/MouseRelatedEvent.cpp:
(WebCore::MouseRelatedEvent::MouseRelatedEvent):
* dom/TreeScope.cpp:
(WebCore::nodeFromPoint): Remove #ifdefs.
* html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::scrollLeft):
(WebCore::HTMLBodyElement::scrollTop):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::scrollX):
(WebCore::DOMWindow::scrollY):
(WebCore::DOMWindow::scrollBy):
(WebCore::DOMWindow::scrollTo):
* platform/ScrollView.cpp:
(WebCore::ScrollView::contentsScrollPosition):
(WebCore::ScrollView::setContentsScrollPosition):
* platform/ScrollView.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@167503 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/MouseRelatedEvent.cpp
Source/WebCore/dom/TreeScope.cpp
Source/WebCore/html/HTMLBodyElement.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/platform/ScrollView.cpp
Source/WebCore/platform/ScrollView.h

index b92d217..e76d762 100644 (file)
@@ -1,5 +1,39 @@
 2014-04-18  Simon Fraser  <simon.fraser@apple.com>
 
+        [iOS WK2] Make window.scroll() and window.scrollBy() work
+        https://bugs.webkit.org/show_bug.cgi?id=131848
+        <rdar://problem/16638319>
+
+        Reviewed by Beth Dakin.
+
+        The scrolling-related functions in DOMWindow were #ifdeffed for iOS
+        to use the hacky WK1-specific "actual scroll" functions, which do nothing
+        in WK2.
+        
+        Fix by adding a scroll position wrapper (contentsScrollPosition) which does
+        the right thing on WK1 and WK2, and change almost all the places that used "actualScrollPosition"
+        to us it (with the exception of contentsScrollOffset() in MouseRelatedEvent.cpp, which has
+        confusing scaling behavior).
+
+        * dom/MouseRelatedEvent.cpp:
+        (WebCore::MouseRelatedEvent::MouseRelatedEvent):
+        * dom/TreeScope.cpp:
+        (WebCore::nodeFromPoint): Remove #ifdefs. 
+        * html/HTMLBodyElement.cpp:
+        (WebCore::HTMLBodyElement::scrollLeft):
+        (WebCore::HTMLBodyElement::scrollTop):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::scrollX):
+        (WebCore::DOMWindow::scrollY):
+        (WebCore::DOMWindow::scrollBy):
+        (WebCore::DOMWindow::scrollTo):
+        * platform/ScrollView.cpp:
+        (WebCore::ScrollView::contentsScrollPosition):
+        (WebCore::ScrollView::setContentsScrollPosition):
+        * platform/ScrollView.h:
+
+2014-04-18  Simon Fraser  <simon.fraser@apple.com>
+
         Worse animation performance on pages with 3D transforms
         https://bugs.webkit.org/show_bug.cgi?id=131838
         <rdar://problem/16428630&15705876>
index 1dbef3b..53f914e 100644 (file)
@@ -74,11 +74,7 @@ MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubb
     Frame* frame = view() ? view()->frame() : 0;
     if (frame && !isSimulated) {
         if (FrameView* frameView = frame->view()) {
-#if !PLATFORM(IOS)
-            scrollPosition = frameView->scrollPosition();
-#else
-            scrollPosition = frameView->actualScrollPosition();
-#endif
+            scrollPosition = frameView->contentsScrollPosition();
             adjustedPageLocation = frameView->windowToContents(windowLocation);
             float scaleFactor = 1 / (frame->pageZoomFactor() * frame->frameScaleFactor());
             if (scaleFactor != 1.0f) {
index cfeef20..cd971ae 100644 (file)
@@ -227,17 +227,19 @@ Node* nodeFromPoint(Document* document, int x, int y, LayoutPoint* localPoint)
         return nullptr;
 
     float scaleFactor = frame->pageZoomFactor() * frame->frameScaleFactor();
-#if !PLATFORM(IOS)
-    IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor  + frameView->scrollX(), y * scaleFactor + frameView->scrollY()));
 
-    if (!frameView->visibleContentRect().contains(point))
-        return nullptr;
-#else
-    IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor  + frameView->actualScrollX(), y * scaleFactor + frameView->actualScrollY()));
+    IntPoint scrollPosition = frameView->contentsScrollPosition();
+    IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor  + scrollPosition.x(), y * scaleFactor + scrollPosition.y()));
 
-    if (!frameView->unobscuredContentRect().contains(point))
-        return nullptr;
+    IntRect visibleRect;
+#if PLATFORM(IOS)
+    visibleRect = frameView->unobscuredContentRect();
+#else
+    visibleRect = frameView->visibleContentRect();
 #endif
+    if (!visibleRect.contains(point))
+        return nullptr;
+
     HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent);
     HitTestResult result(point);
     document->renderView()->hitTest(request, result);
index ac24359..d0412e6 100644 (file)
@@ -218,11 +218,7 @@ int HTMLBodyElement::scrollLeft()
     FrameView* view = frame->view();
     if (!view)
         return 0;
-#if PLATFORM(IOS)
-    return adjustForZoom(view->actualScrollX(), *frame);
-#else
-    return adjustForZoom(view->scrollX(), *frame);
-#endif
+    return adjustForZoom(view->contentsScrollPosition().x(), *frame);
 }
 
 void HTMLBodyElement::setScrollLeft(int scrollLeft)
@@ -246,11 +242,7 @@ int HTMLBodyElement::scrollTop()
     FrameView* view = frame->view();
     if (!view)
         return 0;
-#if PLATFORM(IOS)
-    return adjustForZoom(view->actualScrollY(), *frame);
-#else
-    return adjustForZoom(view->scrollY(), *frame);
-#endif
+    return adjustForZoom(view->contentsScrollPosition().y(), *frame);
 }
 
 void HTMLBodyElement::setScrollTop(int scrollTop)
index cbc3554..a47c69b 100644 (file)
@@ -1192,22 +1192,13 @@ int DOMWindow::scrollX() const
     if (!view)
         return 0;
 
-    int scrollX;
-#if PLATFORM(IOS)
-    scrollX = view->actualScrollX();
-#else
-    scrollX = view->scrollX();
-#endif
+    int scrollX = view->contentsScrollPosition().x();
     if (!scrollX)
         return 0;
 
     m_frame->document()->updateLayoutIgnorePendingStylesheets();
 
-#if PLATFORM(IOS)
-    return view->mapFromLayoutToCSSUnits(view->actualScrollX());
-#else
-    return view->mapFromLayoutToCSSUnits(view->scrollX());
-#endif
+    return view->mapFromLayoutToCSSUnits(view->contentsScrollPosition().x());
 }
 
 int DOMWindow::scrollY() const
@@ -1219,22 +1210,13 @@ int DOMWindow::scrollY() const
     if (!view)
         return 0;
 
-    int scrollY;
-#if PLATFORM(IOS)
-    scrollY = view->actualScrollY();
-#else
-    scrollY = view->scrollY();
-#endif
+    int scrollY = view->contentsScrollPosition().y();
     if (!scrollY)
         return 0;
 
     m_frame->document()->updateLayoutIgnorePendingStylesheets();
 
-#if PLATFORM(IOS)
-    return view->mapFromLayoutToCSSUnits(view->actualScrollY());
-#else
-    return view->mapFromLayoutToCSSUnits(view->scrollY());
-#endif
+    return view->mapFromLayoutToCSSUnits(view->contentsScrollPosition().y());
 }
 
 bool DOMWindow::closed() const
@@ -1446,11 +1428,7 @@ void DOMWindow::scrollBy(int x, int y) const
         return;
 
     IntSize scaledOffset(view->mapFromCSSToLayoutUnits(x), view->mapFromCSSToLayoutUnits(y));
-#if PLATFORM(IOS)
-    view->setActualScrollPosition(view->actualScrollPosition() + scaledOffset);
-#else
-    view->scrollBy(scaledOffset);
-#endif
+    view->setContentsScrollPosition(view->contentsScrollPosition() + scaledOffset);
 }
 
 void DOMWindow::scrollTo(int x, int y) const
@@ -1464,15 +1442,8 @@ void DOMWindow::scrollTo(int x, int y) const
     if (!view)
         return;
 
-
-#if PLATFORM(IOS)
-    int zoomedX = static_cast<int>(x * m_frame->pageZoomFactor() * m_frame->frameScaleFactor());
-    int zoomedY = static_cast<int>(y * m_frame->pageZoomFactor() * m_frame->frameScaleFactor());
-    view->setActualScrollPosition(IntPoint(zoomedX, zoomedY));
-#else
     IntPoint layoutPos(view->mapFromCSSToLayoutUnits(x), view->mapFromCSSToLayoutUnits(y));
-    view->setScrollPosition(layoutPos);
-#endif
+    view->setContentsScrollPosition(layoutPos);
 }
 
 bool DOMWindow::allowedToChangeWindowGeometry() const
index 104cb7a..87e98f0 100644 (file)
@@ -236,6 +236,24 @@ void ScrollView::setDelegatesScrolling(bool delegatesScrolling)
     delegatesScrollingDidChange();
 }
 
+IntPoint ScrollView::contentsScrollPosition() const
+{
+#if PLATFORM(IOS)
+    if (platformWidget())
+        return actualScrollPosition();
+#endif
+    return scrollPosition();
+}
+
+void ScrollView::setContentsScrollPosition(const IntPoint& position)
+{
+#if PLATFORM(IOS)
+    if (platformWidget())
+        setActualScrollPosition(position);
+#endif
+    setScrollPosition(position);
+}
+
 #if !PLATFORM(IOS)
 IntRect ScrollView::unobscuredContentRect(VisibleContentRectIncludesScrollbars scrollbarInclusion) const
 {
index 8927c1c..2d61b29 100644 (file)
@@ -229,6 +229,10 @@ public:
     int scrollX() const { return scrollPosition().x(); }
     int scrollY() const { return scrollPosition().y(); }
 
+    // Scroll position used by web-exposed features (has legacy iOS behavior).
+    IntPoint contentsScrollPosition() const;
+    void setContentsScrollPosition(const IntPoint&);
+
 #if PLATFORM(IOS)
     int actualScrollX() const { return unobscuredContentRect().x(); }
     int actualScrollY() const { return unobscuredContentRect().y(); }