RESOLVED FIXED144647
Scroll-snap points do not handle margins and padding properly
https://bugs.webkit.org/show_bug.cgi?id=144647
Summary Scroll-snap points do not handle margins and padding properly
Brent Fulgham
Reported 2015-05-05 17:18:24 PDT
If we decorate the container holding a scroll-snap region with padding or borders, the calculation of the snap points is not correct. See the attached example for details: 1. The initial color block fills the region and looks correct. 2. After performing a single swipe (which should move 100% to the next color block), we are off by about 2x the border width, resulting in display of the third color at the edge of the display region.
Attachments
border example (2.58 KB, text/html)
2015-05-05 17:18 PDT, Brent Fulgham
no flags
padding example (2.64 KB, text/html)
2015-05-05 17:36 PDT, Brent Fulgham
no flags
Patch (47.91 KB, patch)
2015-05-06 10:50 PDT, Brent Fulgham
no flags
Patch (64.68 KB, patch)
2015-05-06 15:34 PDT, Brent Fulgham
no flags
Patch v3 (Removed debugging code I accidentally uploaded) (64.67 KB, patch)
2015-05-06 15:38 PDT, Brent Fulgham
simon.fraser: review+
Brent Fulgham
Comment 1 2015-05-05 17:18:52 PDT
Created attachment 252422 [details] border example
Brent Fulgham
Comment 2 2015-05-05 17:36:00 PDT
Created attachment 252423 [details] padding example
Radar WebKit Bug Importer
Comment 3 2015-05-05 17:36:24 PDT
Brent Fulgham
Comment 4 2015-05-06 10:50:52 PDT
Simon Fraser (smfr)
Comment 5 2015-05-06 11:37:07 PDT
Comment on attachment 252492 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=252492&action=review > Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp:43 > + LayoutUnit adjustedSize = viewSize; "size" sounds like a LayoutSize. Why not just pass a LayoutSize and pick out the right axis? > Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp:50 > + if (axis == ScrollEventAxis::Horizontal) { > + adjustedSize -= valueForLength(style.paddingLeft(), viewSize); > + adjustedSize -= valueForLength(style.paddingRight(), viewSize); > + } else { > + adjustedSize -= valueForLength(style.paddingTop(), viewSize); > + adjustedSize -= valueForLength(style.paddingBottom(), viewSize); Isn't this just what contentBoxRect() would give you? > Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp:59 > for (auto& child : childrenOfType<Element>(parent)) { Wait, why are we iterating through elements here?
Brent Fulgham
Comment 6 2015-05-06 11:51:32 PDT
Comment on attachment 252492 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=252492&action=review >> Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp:50 >> + adjustedSize -= valueForLength(style.paddingBottom(), viewSize); > > Isn't this just what contentBoxRect() would give you? Yes! I finally found that after writing this silly code. :-( >> Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp:59 >> for (auto& child : childrenOfType<Element>(parent)) { > > Wait, why are we iterating through elements here? Bad code. I'll do a drive-by fix here.
Brent Fulgham
Comment 7 2015-05-06 15:34:55 PDT
Brent Fulgham
Comment 8 2015-05-06 15:38:40 PDT
Created attachment 252531 [details] Patch v3 (Removed debugging code I accidentally uploaded)
Simon Fraser (smfr)
Comment 9 2015-05-06 17:53:36 PDT
Comment on attachment 252531 [details] Patch v3 (Removed debugging code I accidentally uploaded) View in context: https://bugs.webkit.org/attachment.cgi?id=252531&action=review > Source/WebCore/testing/Internals.cpp:2814 > + RenderBox& box = *element->renderBox(); > + const auto& scrollSnapCoordinates = box.style().scrollSnapCoordinates(); > + if (scrollSnapCoordinates.isEmpty()) > + return "none"; > + > + LayoutRect viewSize = box.contentBoxRect(); > + LayoutUnit viewWidth = viewSize.width(); > + LayoutUnit viewHeight = viewSize.height(); > + > + StringBuilder result; > + result.append("{ "); > + for (auto& coordinate : scrollSnapCoordinates) { > + if (result.length() > 2) > + result.append(", "); > + > + LayoutUnit x = valueForLength(coordinate.width(), viewWidth); > + LayoutUnit y = valueForLength(coordinate.height(), viewHeight); > + result.append("("); > + result.append(String::number(x.toUnsigned())); > + result.append(", "); > + result.append(String::number(y.toUnsigned())); > + result.append(")"); > + } > + result.append(" }"); Is this code telling us anything that we don't get from computed style? Use of box.contentBoxRect() here isn't interesting, because this is test-only code.
Brent Fulgham
Comment 10 2015-05-06 19:14:29 PDT
Comment on attachment 252531 [details] Patch v3 (Removed debugging code I accidentally uploaded) View in context: https://bugs.webkit.org/attachment.cgi?id=252531&action=review >> Source/WebCore/testing/Internals.cpp:2814 >> + result.append(" }"); > > Is this code telling us anything that we don't get from computed style? Use of box.contentBoxRect() here isn't interesting, because this is test-only code. OK. I'll get rid of this for now. If I discover a need for it when delving into the corrdinate/destination stuff more thoroughly I'll put it back.
Brent Fulgham
Comment 11 2015-05-06 19:54:18 PDT
Note You need to log in before you can comment on or make changes to this bug.