Changeset 167503 in webkit


Ignore:
Timestamp:
Apr 18, 2014 1:31:35 PM (10 years ago)
Author:
Simon Fraser
Message:

[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:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r167498 r167503  
     12014-04-18  Simon Fraser  <simon.fraser@apple.com>
     2
     3        [iOS WK2] Make window.scroll() and window.scrollBy() work
     4        https://bugs.webkit.org/show_bug.cgi?id=131848
     5        <rdar://problem/16638319>
     6
     7        Reviewed by Beth Dakin.
     8
     9        The scrolling-related functions in DOMWindow were #ifdeffed for iOS
     10        to use the hacky WK1-specific "actual scroll" functions, which do nothing
     11        in WK2.
     12       
     13        Fix by adding a scroll position wrapper (contentsScrollPosition) which does
     14        the right thing on WK1 and WK2, and change almost all the places that used "actualScrollPosition"
     15        to us it (with the exception of contentsScrollOffset() in MouseRelatedEvent.cpp, which has
     16        confusing scaling behavior).
     17
     18        * dom/MouseRelatedEvent.cpp:
     19        (WebCore::MouseRelatedEvent::MouseRelatedEvent):
     20        * dom/TreeScope.cpp:
     21        (WebCore::nodeFromPoint): Remove #ifdefs.
     22        * html/HTMLBodyElement.cpp:
     23        (WebCore::HTMLBodyElement::scrollLeft):
     24        (WebCore::HTMLBodyElement::scrollTop):
     25        * page/DOMWindow.cpp:
     26        (WebCore::DOMWindow::scrollX):
     27        (WebCore::DOMWindow::scrollY):
     28        (WebCore::DOMWindow::scrollBy):
     29        (WebCore::DOMWindow::scrollTo):
     30        * platform/ScrollView.cpp:
     31        (WebCore::ScrollView::contentsScrollPosition):
     32        (WebCore::ScrollView::setContentsScrollPosition):
     33        * platform/ScrollView.h:
     34
    1352014-04-18  Simon Fraser  <simon.fraser@apple.com>
    236
  • trunk/Source/WebCore/dom/MouseRelatedEvent.cpp

    r164871 r167503  
    7575    if (frame && !isSimulated) {
    7676        if (FrameView* frameView = frame->view()) {
    77 #if !PLATFORM(IOS)
    78             scrollPosition = frameView->scrollPosition();
    79 #else
    80             scrollPosition = frameView->actualScrollPosition();
    81 #endif
     77            scrollPosition = frameView->contentsScrollPosition();
    8278            adjustedPageLocation = frameView->windowToContents(windowLocation);
    8379            float scaleFactor = 1 / (frame->pageZoomFactor() * frame->frameScaleFactor());
  • trunk/Source/WebCore/dom/TreeScope.cpp

    r165211 r167503  
    228228
    229229    float scaleFactor = frame->pageZoomFactor() * frame->frameScaleFactor();
    230 #if !PLATFORM(IOS)
    231     IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor  + frameView->scrollX(), y * scaleFactor + frameView->scrollY()));
    232 
    233     if (!frameView->visibleContentRect().contains(point))
    234         return nullptr;
     230
     231    IntPoint scrollPosition = frameView->contentsScrollPosition();
     232    IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor  + scrollPosition.x(), y * scaleFactor + scrollPosition.y()));
     233
     234    IntRect visibleRect;
     235#if PLATFORM(IOS)
     236    visibleRect = frameView->unobscuredContentRect();
    235237#else
    236     IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor  + frameView->actualScrollX(), y * scaleFactor + frameView->actualScrollY()));
    237 
    238     if (!frameView->unobscuredContentRect().contains(point))
    239         return nullptr;
     238    visibleRect = frameView->visibleContentRect();
    240239#endif
     240    if (!visibleRect.contains(point))
     241        return nullptr;
     242
    241243    HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent);
    242244    HitTestResult result(point);
  • trunk/Source/WebCore/html/HTMLBodyElement.cpp

    r163092 r167503  
    219219    if (!view)
    220220        return 0;
    221 #if PLATFORM(IOS)
    222     return adjustForZoom(view->actualScrollX(), *frame);
    223 #else
    224     return adjustForZoom(view->scrollX(), *frame);
    225 #endif
     221    return adjustForZoom(view->contentsScrollPosition().x(), *frame);
    226222}
    227223
     
    247243    if (!view)
    248244        return 0;
    249 #if PLATFORM(IOS)
    250     return adjustForZoom(view->actualScrollY(), *frame);
    251 #else
    252     return adjustForZoom(view->scrollY(), *frame);
    253 #endif
     245    return adjustForZoom(view->contentsScrollPosition().y(), *frame);
    254246}
    255247
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r166883 r167503  
    11931193        return 0;
    11941194
    1195     int scrollX;
    1196 #if PLATFORM(IOS)
    1197     scrollX = view->actualScrollX();
    1198 #else
    1199     scrollX = view->scrollX();
    1200 #endif
     1195    int scrollX = view->contentsScrollPosition().x();
    12011196    if (!scrollX)
    12021197        return 0;
     
    12041199    m_frame->document()->updateLayoutIgnorePendingStylesheets();
    12051200
    1206 #if PLATFORM(IOS)
    1207     return view->mapFromLayoutToCSSUnits(view->actualScrollX());
    1208 #else
    1209     return view->mapFromLayoutToCSSUnits(view->scrollX());
    1210 #endif
     1201    return view->mapFromLayoutToCSSUnits(view->contentsScrollPosition().x());
    12111202}
    12121203
     
    12201211        return 0;
    12211212
    1222     int scrollY;
    1223 #if PLATFORM(IOS)
    1224     scrollY = view->actualScrollY();
    1225 #else
    1226     scrollY = view->scrollY();
    1227 #endif
     1213    int scrollY = view->contentsScrollPosition().y();
    12281214    if (!scrollY)
    12291215        return 0;
     
    12311217    m_frame->document()->updateLayoutIgnorePendingStylesheets();
    12321218
    1233 #if PLATFORM(IOS)
    1234     return view->mapFromLayoutToCSSUnits(view->actualScrollY());
    1235 #else
    1236     return view->mapFromLayoutToCSSUnits(view->scrollY());
    1237 #endif
     1219    return view->mapFromLayoutToCSSUnits(view->contentsScrollPosition().y());
    12381220}
    12391221
     
    14471429
    14481430    IntSize scaledOffset(view->mapFromCSSToLayoutUnits(x), view->mapFromCSSToLayoutUnits(y));
    1449 #if PLATFORM(IOS)
    1450     view->setActualScrollPosition(view->actualScrollPosition() + scaledOffset);
    1451 #else
    1452     view->scrollBy(scaledOffset);
    1453 #endif
     1431    view->setContentsScrollPosition(view->contentsScrollPosition() + scaledOffset);
    14541432}
    14551433
     
    14651443        return;
    14661444
    1467 
    1468 #if PLATFORM(IOS)
    1469     int zoomedX = static_cast<int>(x * m_frame->pageZoomFactor() * m_frame->frameScaleFactor());
    1470     int zoomedY = static_cast<int>(y * m_frame->pageZoomFactor() * m_frame->frameScaleFactor());
    1471     view->setActualScrollPosition(IntPoint(zoomedX, zoomedY));
    1472 #else
    14731445    IntPoint layoutPos(view->mapFromCSSToLayoutUnits(x), view->mapFromCSSToLayoutUnits(y));
    1474     view->setScrollPosition(layoutPos);
    1475 #endif
     1446    view->setContentsScrollPosition(layoutPos);
    14761447}
    14771448
  • trunk/Source/WebCore/platform/ScrollView.cpp

    r167415 r167503  
    237237}
    238238
     239IntPoint ScrollView::contentsScrollPosition() const
     240{
     241#if PLATFORM(IOS)
     242    if (platformWidget())
     243        return actualScrollPosition();
     244#endif
     245    return scrollPosition();
     246}
     247
     248void ScrollView::setContentsScrollPosition(const IntPoint& position)
     249{
     250#if PLATFORM(IOS)
     251    if (platformWidget())
     252        setActualScrollPosition(position);
     253#endif
     254    setScrollPosition(position);
     255}
     256
    239257#if !PLATFORM(IOS)
    240258IntRect ScrollView::unobscuredContentRect(VisibleContentRectIncludesScrollbars scrollbarInclusion) const
  • trunk/Source/WebCore/platform/ScrollView.h

    r166529 r167503  
    230230    int scrollY() const { return scrollPosition().y(); }
    231231
     232    // Scroll position used by web-exposed features (has legacy iOS behavior).
     233    IntPoint contentsScrollPosition() const;
     234    void setContentsScrollPosition(const IntPoint&);
     235
    232236#if PLATFORM(IOS)
    233237    int actualScrollX() const { return unobscuredContentRect().x(); }
Note: See TracChangeset for help on using the changeset viewer.