⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181855 in webkit


Ignore:
Timestamp:
Mar 23, 2015, 9:57:06 AM (11 years ago)
Author:
Brent Fulgham
Message:

scroll-snap-destination and scroll-snap-coordinate do not seem to work together properly
https://bugs.webkit.org/show_bug.cgi?id=142552
<rdar://problem/20114743>

Reviewed by Dean Jackson.

Revise the snap point logic as follows:
(1) Put the snap point destination handling in a helper function to make the rest of the code

easier to read.

(2) Make sure we always have a left-hand snap point (i.e., position 0), but don't add multiple

left-hand snap points.

(3) Create a helper function to determine if we should be working with the scroll snap 'elements'

behavior. We want to use this for scroll-snap-destination/scroll-snap-coordinate markup.

(4) Create per-element snap point offsets when using scroll-snap-destination/scroll-snap-coordinate.

  • css/CSSParser.cpp:

(WebCore::CSSParser::parseScrollSnapDestination): Add assertion to try to catch bad parser state.

  • page/scrolling/AxisScrollSnapOffsets.cpp:

(WebCore::destinationOffsetForViewSize): Added helper function to consolidate logic for handling
destination coordinates.
(WebCore::updateFromStyle): Make sure a left-hand snap point is always provided.
(WebCore::styleUsesElements): Added helper function.
(WebCore::updateSnapOffsetsForScrollableArea): Revise logic to generate 'per-element' snap point
offsets.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r181849 r181855  
     12015-03-23  Brent Fulgham  <bfulgham@apple.com>
     2
     3        scroll-snap-destination and scroll-snap-coordinate do not seem to work together properly
     4        https://bugs.webkit.org/show_bug.cgi?id=142552
     5        <rdar://problem/20114743>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Revise the snap point logic as follows:
     10        (1) Put the snap point destination handling in a helper function to make the rest of the code
     11            easier to read.
     12        (2) Make sure we always have a left-hand snap point (i.e., position 0), but don't add multiple
     13            left-hand snap points.
     14        (3) Create a helper function to determine if we should be working with the scroll snap 'elements'
     15            behavior. We want to use this for scroll-snap-destination/scroll-snap-coordinate markup.
     16        (4) Create per-element snap point offsets when using scroll-snap-destination/scroll-snap-coordinate.
     17
     18        * css/CSSParser.cpp:
     19        (WebCore::CSSParser::parseScrollSnapDestination): Add assertion to try to catch bad parser state.
     20        * page/scrolling/AxisScrollSnapOffsets.cpp:
     21        (WebCore::destinationOffsetForViewSize): Added helper function to consolidate logic for handling
     22        destination coordinates.
     23        (WebCore::updateFromStyle): Make sure a left-hand snap point is always provided.
     24        (WebCore::styleUsesElements): Added helper function.
     25        (WebCore::updateSnapOffsetsForScrollableArea): Revise logic to generate 'per-element' snap point
     26        offsets.
     27
    1282015-03-23  Yoav Weiss  <yoav@yoav.ws>
    229
  • trunk/Source/WebCore/css/CSSParser.cpp

    r181832 r181855  
    33543354{
    33553355    RefPtr<CSSValueList> position = CSSValueList::createSpaceSeparated();
     3356    ASSERT(m_valueList->size() == 2);
    33563357    if (m_valueList->size() != 2)
    33573358        return false;
  • trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp

    r181504 r181855  
    3030#include "HTMLCollection.h"
    3131#include "HTMLElement.h"
     32#include "Length.h"
    3233#include "RenderBox.h"
    3334#include "ScrollableArea.h"
     
    6970}
    7071
     72static LayoutUnit destinationOffsetForViewSize(ScrollEventAxis axis, const LengthSize& destination, LayoutUnit viewSize)
     73{
     74    const Length& dimension = (axis == ScrollEventAxis::Horizontal) ? destination.width() : destination.height();
     75    return valueForLength(dimension, viewSize);
     76}
     77   
    7178static void updateFromStyle(Vector<LayoutUnit>& snapOffsets, const RenderStyle& style, ScrollEventAxis axis, LayoutUnit viewSize, LayoutUnit scrollSize, Vector<LayoutUnit>& snapOffsetSubsequence)
    7279{
     
    7582        snapOffsetSubsequence.append(0);
    7683
    77     bool isHorizontalAxis = axis == ScrollEventAxis::Horizontal;
    78     auto* points = isHorizontalAxis ? style.scrollSnapPointsX() : style.scrollSnapPointsY();
    79     auto& destination = style.scrollSnapDestination();
     84    // Always put a snap point on the zero offset.
     85    snapOffsets.append(0);
     86
     87    auto* points = (axis == ScrollEventAxis::Horizontal) ? style.scrollSnapPointsX() : style.scrollSnapPointsY();
    8088    bool hasRepeat = points ? points->hasRepeat : false;
    8189    LayoutUnit repeatOffset = points ? valueForLength(points->repeatOffset, viewSize) : LayoutUnit();
    82     LayoutUnit destinationOffset = valueForLength(isHorizontalAxis ? destination.width() : destination.height(), viewSize);
     90    LayoutUnit destinationOffset = destinationOffsetForViewSize(axis, style.scrollSnapDestination(), viewSize);
    8391    LayoutUnit curSnapPositionShift = 0;
    8492    LayoutUnit maxScrollOffset = scrollSize - viewSize;
     
    93101                break;
    94102
    95             snapOffsets.append(potentialSnapPosition);
     103            // Don't add another zero offset value.
     104            if (potentialSnapPosition)
     105                snapOffsets.append(potentialSnapPosition);
     106
    96107            lastSnapPosition = potentialSnapPosition + destinationOffset;
    97108        }
    98109        curSnapPositionShift = lastSnapPosition + repeatOffset;
    99110    } while (hasRepeat && curSnapPositionShift < maxScrollOffset);
    100 
    101     if (snapOffsets.isEmpty())
    102         snapOffsets.append(0);
    103111
    104112    // Always put a snap point on the maximum scroll offset.
     
    108116}
    109117
     118static bool styleUsesElements(ScrollEventAxis axis, const RenderStyle& style)
     119{
     120    const ScrollSnapPoints* scrollSnapPoints = (axis == ScrollEventAxis::Horizontal) ? style.scrollSnapPointsX() : style.scrollSnapPointsY();
     121    if (scrollSnapPoints)
     122        return scrollSnapPoints->usesElements;
     123
     124    const Length& destination = (axis == ScrollEventAxis::Horizontal) ? style.scrollSnapDestination().width() : style.scrollSnapDestination().height();
     125
     126    return !destination.isUndefined();
     127}
     128   
    110129void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, HTMLElement& scrollingElement, const RenderBox& scrollingElementBox, const RenderStyle& scrollingElementStyle)
    111130{
     
    134153    Vector<LayoutUnit> verticalSnapOffsetSubsequence;
    135154
    136     bool scrollSnapPointsXUsesElements = scrollingElementStyle.scrollSnapPointsX() ? scrollingElementStyle.scrollSnapPointsX()->usesElements : false;
    137     bool scrollSnapPointsYUsesElements = scrollingElementStyle.scrollSnapPointsY() ? scrollingElementStyle.scrollSnapPointsY()->usesElements : false;
     155    bool scrollSnapPointsXUsesElements = styleUsesElements(ScrollEventAxis::Horizontal, scrollingElementStyle);
     156    bool scrollSnapPointsYUsesElements = styleUsesElements(ScrollEventAxis::Vertical , scrollingElementStyle);
    138157
    139158    if (scrollSnapPointsXUsesElements || scrollSnapPointsYUsesElements) {
Note: See TracChangeset for help on using the changeset viewer.