Changeset 194184 in webkit


Ignore:
Timestamp:
Dec 16, 2015 3:41:05 PM (8 years ago)
Author:
Simon Fraser
Message:

Simplify isOverlayScrollbar() logic
https://bugs.webkit.org/show_bug.cgi?id=152357

Reviewed by Beth Dakin.

Replace code that checks for isOverlayScrollbar() explicitly with calls to new
occupiedWidth()/occupiedHeight() functions on Scrollbar, which do the overlay
scrollbar check internally.

Add ScrollableArea::scrollbarIntrusion() which returns an IntSize with the occupiedWidth
and occupiedHeight of any scrollbars, and use it in a few places.

Source/WebCore:

  • page/FrameView.cpp:

(WebCore::FrameView::autoSizeIfEnabled):

  • platform/ScrollView.cpp:

(WebCore::ScrollView::unscaledVisibleContentSizeIncludingObscuredArea):
(WebCore::ScrollView::calculateOverhangAreasForPainting):

  • platform/ScrollableArea.cpp:

(WebCore::ScrollableArea::scrollbarIntrusion):
(WebCore::ScrollableArea::visibleContentRectInternal):

  • platform/ScrollableArea.h:
  • platform/Scrollbar.cpp:

(WebCore::Scrollbar::occupiedWidth):
(WebCore::Scrollbar::occupiedHeight):

  • platform/Scrollbar.h:
  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::visibleContentRectInternal):

  • rendering/RenderListBox.cpp:

(WebCore::RenderListBox::verticalScrollbarWidth):

Source/WebKit2:

  • WebProcess/Plugins/PDF/DeprecatedPDFPlugin.mm:

(WebKit::PDFPlugin::updateScrollbars):
(WebKit::PDFPlugin::maximumScrollPosition):

Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r194183 r194184  
     12015-12-16  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Simplify isOverlayScrollbar() logic
     4        https://bugs.webkit.org/show_bug.cgi?id=152357
     5
     6        Reviewed by Beth Dakin.
     7
     8        Replace code that checks for isOverlayScrollbar() explicitly with calls to new
     9        occupiedWidth()/occupiedHeight() functions on Scrollbar, which do the overlay
     10        scrollbar check internally.
     11       
     12        Add ScrollableArea::scrollbarIntrusion() which returns an IntSize with the occupiedWidth
     13        and occupiedHeight of any scrollbars, and use it in a few places.
     14
     15        * page/FrameView.cpp:
     16        (WebCore::FrameView::autoSizeIfEnabled):
     17        * platform/ScrollView.cpp:
     18        (WebCore::ScrollView::unscaledVisibleContentSizeIncludingObscuredArea):
     19        (WebCore::ScrollView::calculateOverhangAreasForPainting):
     20        * platform/ScrollableArea.cpp:
     21        (WebCore::ScrollableArea::scrollbarIntrusion):
     22        (WebCore::ScrollableArea::visibleContentRectInternal):
     23        * platform/ScrollableArea.h:
     24        * platform/Scrollbar.cpp:
     25        (WebCore::Scrollbar::occupiedWidth):
     26        (WebCore::Scrollbar::occupiedHeight):
     27        * platform/Scrollbar.h:
     28        * rendering/RenderLayer.cpp:
     29        (WebCore::RenderLayer::visibleContentRectInternal):
     30        * rendering/RenderListBox.cpp:
     31        (WebCore::RenderListBox::verticalScrollbarWidth):
     32
    1332015-12-16  Alex Christensen  <achristensen@webkit.org>
    234
  • trunk/Source/WebCore/page/FrameView.cpp

    r192966 r194184  
    32633263            if (!localHorizontalScrollbar)
    32643264                localHorizontalScrollbar = createScrollbar(HorizontalScrollbar);
    3265             if (!localHorizontalScrollbar->isOverlayScrollbar())
    3266                 newSize.setHeight(newSize.height() + localHorizontalScrollbar->height());
     3265            newSize.expand(0, localHorizontalScrollbar->occupiedHeight());
    32673266
    32683267            // Don't bother checking for a vertical scrollbar because the width is at
     
    32723271            if (!localVerticalScrollbar)
    32733272                localVerticalScrollbar = createScrollbar(VerticalScrollbar);
    3274             if (!localVerticalScrollbar->isOverlayScrollbar())
    3275                 newSize.setWidth(newSize.width() + localVerticalScrollbar->width());
     3273            newSize.expand(localVerticalScrollbar->occupiedWidth(), 0);
    32763274
    32773275            // Don't bother checking for a horizontal scrollbar because the height is
  • trunk/Source/WebCore/platform/ScrollView.cpp

    r194155 r194184  
    276276#endif
    277277
    278     int verticalScrollbarWidth = 0;
    279     int horizontalScrollbarHeight = 0;
    280 
    281     if (scrollbarInclusion == ExcludeScrollbars) {
    282         if (Scrollbar* verticalBar = verticalScrollbar())
    283             verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBar->width() : 0;
    284         if (Scrollbar* horizontalBar = horizontalScrollbar())
    285             horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horizontalBar->height() : 0;
    286     }
    287 
    288     return IntSize(width() - verticalScrollbarWidth, height() - horizontalScrollbarHeight).expandedTo(IntSize());
     278    IntSize scrollbarSpace;
     279    if (scrollbarInclusion == ExcludeScrollbars)
     280        scrollbarSpace = scrollbarIntrusion();
     281
     282    return IntSize(width() - scrollbarSpace.width(), height() - scrollbarSpace.height()).expandedTo(IntSize());
    289283}
    290284   
     
    12501244void ScrollView::calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntRect& verticalOverhangRect)
    12511245{
    1252     int verticalScrollbarWidth = (verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar())
    1253         ? verticalScrollbar()->width() : 0;
    1254     int horizontalScrollbarHeight = (horizontalScrollbar() && !horizontalScrollbar()->isOverlayScrollbar())
    1255         ? horizontalScrollbar()->height() : 0;
     1246    IntSize scrollbarSpace = scrollbarIntrusion();
    12561247
    12571248    int physicalScrollY = scrollPosition().y() + scrollOrigin().y();
     
    12591250        horizontalOverhangRect = frameRect();
    12601251        horizontalOverhangRect.setHeight(-physicalScrollY);
    1261         horizontalOverhangRect.setWidth(horizontalOverhangRect.width() - verticalScrollbarWidth);
     1252        horizontalOverhangRect.setWidth(horizontalOverhangRect.width() - scrollbarSpace.width());
    12621253    } else if (totalContentsSize().height() && physicalScrollY > totalContentsSize().height() - visibleHeight()) {
    12631254        int height = physicalScrollY - (totalContentsSize().height() - visibleHeight());
    12641255        horizontalOverhangRect = frameRect();
    1265         horizontalOverhangRect.setY(frameRect().maxY() - height - horizontalScrollbarHeight);
     1256        horizontalOverhangRect.setY(frameRect().maxY() - height - scrollbarSpace.height());
    12661257        horizontalOverhangRect.setHeight(height);
    1267         horizontalOverhangRect.setWidth(horizontalOverhangRect.width() - verticalScrollbarWidth);
     1258        horizontalOverhangRect.setWidth(horizontalOverhangRect.width() - scrollbarSpace.width());
    12681259    }
    12691260
     
    12711262    if (physicalScrollX < 0) {
    12721263        verticalOverhangRect.setWidth(-physicalScrollX);
    1273         verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhangRect.height() - horizontalScrollbarHeight);
     1264        verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhangRect.height() - scrollbarSpace.height());
    12741265        verticalOverhangRect.setX(frameRect().x());
    12751266        if (horizontalOverhangRect.y() == frameRect().y())
     
    12801271        int width = physicalScrollX - (contentsWidth() - visibleWidth());
    12811272        verticalOverhangRect.setWidth(width);
    1282         verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhangRect.height() - horizontalScrollbarHeight);
    1283         verticalOverhangRect.setX(frameRect().maxX() - width - verticalScrollbarWidth);
     1273        verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhangRect.height() - scrollbarSpace.height());
     1274        verticalOverhangRect.setX(frameRect().maxX() - width - scrollbarSpace.width());
    12841275        if (horizontalOverhangRect.y() == frameRect().y())
    12851276            verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.height());
  • trunk/Source/WebCore/platform/ScrollableArea.cpp

    r191735 r194184  
    517517#endif // PLATFORM(IOS)
    518518
     519IntSize ScrollableArea::scrollbarIntrusion() const
     520{
     521    return IntSize(
     522        verticalScrollbar() ? verticalScrollbar()->occupiedWidth() : 0,
     523        horizontalScrollbar() ? horizontalScrollbar()->occupiedHeight() : 0);
     524}
     525
    519526IntPoint ScrollableArea::scrollPosition() const
    520527{
     
    583590    if (scrollbarInclusion == IncludeScrollbars) {
    584591        if (Scrollbar* verticalBar = verticalScrollbar())
    585             verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBar->width() : 0;
     592            verticalScrollbarWidth = verticalBar->occupiedWidth();
    586593        if (Scrollbar* horizontalBar = horizontalScrollbar())
    587             horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horizontalBar->height() : 0;
     594            horizontalScrollbarHeight = horizontalBar->occupiedHeight();
    588595    }
    589596
  • trunk/Source/WebCore/platform/ScrollableArea.h

    r192193 r194184  
    174174        return scrollbar->Widget::convertFromContainingView(parentPoint);
    175175    }
     176   
     177    WEBCORE_EXPORT IntSize scrollbarIntrusion() const;
    176178
    177179    virtual Scrollbar* horizontalScrollbar() const { return 0; }
  • trunk/Source/WebCore/platform/Scrollbar.cpp

    r191735 r194184  
    9898}
    9999
     100int Scrollbar::occupiedWidth() const
     101{
     102    return isOverlayScrollbar() ? 0 : width();
     103}
     104
     105int Scrollbar::occupiedHeight() const
     106{
     107    return isOverlayScrollbar() ? 0 : height();
     108}
     109
    100110void Scrollbar::offsetDidChange()
    101111{
  • trunk/Source/WebCore/platform/Scrollbar.h

    r189270 r194184  
    7070    int maximum() const { return m_totalSize - m_visibleSize; }
    7171    ScrollbarControlSize controlSize() const { return m_controlSize; }
     72   
     73    int occupiedWidth() const;
     74    int occupiedHeight() const;
    7275
    7376    int lineStep() const { return m_lineStep; }
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r193614 r194184  
    27482748IntRect RenderLayer::visibleContentRectInternal(VisibleContentRectIncludesScrollbars scrollbarInclusion, VisibleContentRectBehavior) const
    27492749{
    2750     int verticalScrollbarWidth = 0;
    2751     int horizontalScrollbarHeight = 0;
    2752     if (showsOverflowControls() && scrollbarInclusion == IncludeScrollbars) {
    2753         verticalScrollbarWidth = (verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar()) ? verticalScrollbar()->width() : 0;
    2754         horizontalScrollbarHeight = (horizontalScrollbar() && !horizontalScrollbar()->isOverlayScrollbar()) ? horizontalScrollbar()->height() : 0;
    2755     }
    2756    
    2757     return IntRect(scrollPosition(), IntSize(std::max(0, m_layerSize.width() - verticalScrollbarWidth), std::max(0, m_layerSize.height() - horizontalScrollbarHeight)));
     2750    IntSize scrollbarSpace;
     2751    if (showsOverflowControls() && scrollbarInclusion == IncludeScrollbars)
     2752        scrollbarSpace = scrollbarIntrusion();
     2753   
     2754    return IntRect(scrollPosition(), IntSize(std::max(0, m_layerSize.width() - scrollbarSpace.width()), std::max(0, m_layerSize.height() - scrollbarSpace.height())));
    27582755}
    27592756
  • trunk/Source/WebCore/rendering/RenderListBox.cpp

    r192193 r194184  
    631631int RenderListBox::verticalScrollbarWidth() const
    632632{
    633     return m_vBar && !m_vBar->isOverlayScrollbar() ? m_vBar->width() : 0;
     633    return m_vBar ? m_vBar->occupiedWidth() : 0;
    634634}
    635635
  • trunk/Source/WebKit2/ChangeLog

    r194168 r194184  
     12015-12-16  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Simplify isOverlayScrollbar() logic
     4        https://bugs.webkit.org/show_bug.cgi?id=152357
     5
     6        Reviewed by Beth Dakin.
     7
     8        Replace code that checks for isOverlayScrollbar() explicitly with calls to new
     9        occupiedWidth()/occupiedHeight() functions on Scrollbar, which do the overlay
     10        scrollbar check internally.
     11       
     12        Add ScrollableArea::scrollbarIntrusion() which returns an IntSize with the occupiedWidth
     13        and occupiedHeight of any scrollbars, and use it in a few places.
     14
     15        * WebProcess/Plugins/PDF/DeprecatedPDFPlugin.mm:
     16        (WebKit::PDFPlugin::updateScrollbars):
     17        (WebKit::PDFPlugin::maximumScrollPosition):
     18
    1192015-12-16  Alex Christensen  <achristensen@webkit.org>
    220
  • trunk/Source/WebKit2/WebProcess/Plugins/PDF/DeprecatedPDFPlugin.mm

    r192900 r194184  
    588588        m_verticalScrollbar = createScrollbar(VerticalScrollbar);
    589589
    590     int horizontalScrollbarHeight = (m_horizontalScrollbar && !m_horizontalScrollbar->isOverlayScrollbar()) ? m_horizontalScrollbar->height() : 0;
    591     int verticalScrollbarWidth = (m_verticalScrollbar && !m_verticalScrollbar->isOverlayScrollbar()) ? m_verticalScrollbar->width() : 0;
     590    IntSize scrollbarSpace = scrollbarIntrusion();
    592591
    593592    int pageStep = m_pageBoxes.isEmpty() ? 0 : m_pageBoxes[0].height();
     
    595594    if (m_horizontalScrollbar) {
    596595        m_horizontalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep);
    597         m_horizontalScrollbar->setProportion(m_size.width() - verticalScrollbarWidth, m_pdfDocumentSize.width());
     596        m_horizontalScrollbar->setProportion(m_size.width() - scrollbarSpace.width(), m_pdfDocumentSize.width());
    598597        IntRect scrollbarRect(pluginView()->x(), pluginView()->y() + m_size.height() - m_horizontalScrollbar->height(), m_size.width(), m_horizontalScrollbar->height());
    599598        if (m_verticalScrollbar)
     
    603602    if (m_verticalScrollbar) {
    604603        m_verticalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep);
    605         m_verticalScrollbar->setProportion(m_size.height() - horizontalScrollbarHeight, m_pdfDocumentSize.height());
     604        m_verticalScrollbar->setProportion(m_size.height() - scrollbarSpace.height(), m_pdfDocumentSize.height());
    606605        IntRect scrollbarRect(IntRect(pluginView()->x() + m_size.width() - m_verticalScrollbar->width(), pluginView()->y(), m_verticalScrollbar->width(), m_size.height()));
    607606        if (m_horizontalScrollbar)
     
    797796IntPoint PDFPlugin::maximumScrollPosition() const
    798797{
    799     int horizontalScrollbarHeight = (m_horizontalScrollbar && !m_horizontalScrollbar->isOverlayScrollbar()) ? m_horizontalScrollbar->height() : 0;
    800     int verticalScrollbarWidth = (m_verticalScrollbar && !m_verticalScrollbar->isOverlayScrollbar()) ? m_verticalScrollbar->width() : 0;
    801 
    802     IntPoint maximumOffset(m_pdfDocumentSize.width() - m_size.width() + verticalScrollbarWidth, m_pdfDocumentSize.height() - m_size.height() + horizontalScrollbarHeight);
     798    IntSize scrollbarSpace = scrollbarIntrusion();
     799
     800    IntPoint maximumOffset(m_pdfDocumentSize.width() - m_size.width() + scrollbarSpace.width(), m_pdfDocumentSize.height() - m_size.height() + scrollbarSpace.height());
    803801    maximumOffset.clampNegativeToZero();
    804802    return maximumOffset;
Note: See TracChangeset for help on using the changeset viewer.