|
Lines 198-204
static LayoutUnit computeScrollSnapAlignOffset(LayoutUnit minLocation, LayoutUni
a/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp_sec1
|
| 198 |
} |
198 |
} |
| 199 |
} |
199 |
} |
| 200 |
|
200 |
|
| 201 |
void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, const RenderBox& scrollingElementBox, const RenderStyle& scrollingElementStyle, LayoutRect viewportRectInBorderBoxCoordinates) |
201 |
void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, const RenderBox& scrollingElementBox, const RenderStyle& scrollingElementStyle, LayoutRect viewportRectInBorderBoxCoordinates, WritingMode writingMode, TextDirection textDirection) |
| 202 |
{ |
202 |
{ |
| 203 |
auto scrollSnapType = scrollingElementStyle.scrollSnapType(); |
203 |
auto scrollSnapType = scrollingElementStyle.scrollSnapType(); |
| 204 |
const auto& boxesWithScrollSnapPositions = scrollingElementBox.view().boxesWithScrollSnapPositions(); |
204 |
const auto& boxesWithScrollSnapPositions = scrollingElementBox.view().boxesWithScrollSnapPositions(); |
|
Lines 218-229
void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, const Re
a/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp_sec2
|
| 218 |
HashMap<float, SnapOffset<LayoutUnit>> verticalSnapOffsetsMap; |
218 |
HashMap<float, SnapOffset<LayoutUnit>> verticalSnapOffsetsMap; |
| 219 |
HashMap<float, SnapOffset<LayoutUnit>> horizontalSnapOffsetsMap; |
219 |
HashMap<float, SnapOffset<LayoutUnit>> horizontalSnapOffsetsMap; |
| 220 |
Vector<LayoutRect> snapAreas; |
220 |
Vector<LayoutRect> snapAreas; |
| 221 |
bool hasHorizontalSnapOffsets = scrollSnapType.axis == ScrollSnapAxis::Both || scrollSnapType.axis == ScrollSnapAxis::XAxis || scrollSnapType.axis == ScrollSnapAxis::Inline; |
|
|
| 222 |
bool hasVerticalSnapOffsets = scrollSnapType.axis == ScrollSnapAxis::Both || scrollSnapType.axis == ScrollSnapAxis::YAxis || scrollSnapType.axis == ScrollSnapAxis::Block; |
| 223 |
|
221 |
|
| 224 |
auto maxScrollOffset = scrollableArea.maximumScrollOffset(); |
222 |
auto maxScrollOffset = scrollableArea.maximumScrollOffset(); |
| 225 |
auto scrollPosition = LayoutPoint { scrollableArea.scrollPosition() }; |
223 |
auto scrollPosition = LayoutPoint { scrollableArea.scrollPosition() }; |
| 226 |
bool scrollerIsRTL = !scrollingElementBox.style().isLeftToRightDirection(); |
224 |
bool scrollerIsRTL = textDirection == TextDirection::RTL || writingMode == WritingMode::RightToLeft; |
|
|
225 |
bool scrollerHasVerticalWritingMode = isVerticalWritingMode(writingMode); |
| 226 |
|
| 227 |
bool hasHorizontalSnapOffsets = scrollSnapType.axis == ScrollSnapAxis::Both || scrollSnapType.axis == ScrollSnapAxis::XAxis; |
| 228 |
bool hasVerticalSnapOffsets = scrollSnapType.axis == ScrollSnapAxis::Both || scrollSnapType.axis == ScrollSnapAxis::YAxis; |
| 229 |
if (scrollSnapType.axis == ScrollSnapAxis::Block) { |
| 230 |
hasHorizontalSnapOffsets = scrollerHasVerticalWritingMode; |
| 231 |
hasVerticalSnapOffsets = !scrollerHasVerticalWritingMode; |
| 232 |
} |
| 233 |
if (scrollSnapType.axis == ScrollSnapAxis::Inline) { |
| 234 |
hasHorizontalSnapOffsets = !scrollerHasVerticalWritingMode; |
| 235 |
hasVerticalSnapOffsets = scrollerHasVerticalWritingMode; |
| 236 |
} |
| 227 |
|
237 |
|
| 228 |
// The bounds of the scrolling container's snap port, where the top left of the scrolling container's border box is the origin. |
238 |
// The bounds of the scrolling container's snap port, where the top left of the scrolling container's border box is the origin. |
| 229 |
auto scrollSnapPort = computeScrollSnapPortOrAreaRect(viewportRectInBorderBoxCoordinates, scrollingElementStyle.scrollPadding(), InsetOrOutset::Inset); |
239 |
auto scrollSnapPort = computeScrollSnapPortOrAreaRect(viewportRectInBorderBoxCoordinates, scrollingElementStyle.scrollPadding(), InsetOrOutset::Inset); |
|
Lines 247-254
void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, const Re
a/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp_sec3
|
| 247 |
auto alignment = child->style().scrollSnapAlign(); |
257 |
auto alignment = child->style().scrollSnapAlign(); |
| 248 |
auto stop = child->style().scrollSnapStop(); |
258 |
auto stop = child->style().scrollSnapStop(); |
| 249 |
|
259 |
|
| 250 |
bool snapsHorizontally = hasHorizontalSnapOffsets && alignment.x != ScrollSnapAxisAlignType::None; |
260 |
ScrollSnapAxisAlignType xAlign = !scrollerHasVerticalWritingMode ? alignment.inlineAlign : alignment.blockAlign; |
| 251 |
bool snapsVertically = hasVerticalSnapOffsets && alignment.y != ScrollSnapAxisAlignType::None; |
261 |
ScrollSnapAxisAlignType yAlign = !scrollerHasVerticalWritingMode ? alignment.blockAlign : alignment.inlineAlign; |
|
|
262 |
bool snapsHorizontally = hasHorizontalSnapOffsets && xAlign != ScrollSnapAxisAlignType::None; |
| 263 |
bool snapsVertically = hasVerticalSnapOffsets && yAlign != ScrollSnapAxisAlignType::None; |
| 264 |
|
| 252 |
if (!snapsHorizontally && !snapsVertically) |
265 |
if (!snapsHorizontally && !snapsVertically) |
| 253 |
continue; |
266 |
continue; |
| 254 |
|
267 |
|
|
Lines 258-275
void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, const Re
a/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp_sec4
|
| 258 |
snapAreas.append(scrollSnapAreaAsOffsets); |
271 |
snapAreas.append(scrollSnapAreaAsOffsets); |
| 259 |
|
272 |
|
| 260 |
if (snapsHorizontally) { |
273 |
if (snapsHorizontally) { |
| 261 |
auto absoluteScrollXPosition = computeScrollSnapAlignOffset(scrollSnapArea.x(), scrollSnapArea.maxX(), alignment.x, scrollerIsRTL) - computeScrollSnapAlignOffset(scrollSnapPort.x(), scrollSnapPort.maxX(), alignment.x, scrollerIsRTL); |
274 |
auto absoluteScrollXPosition = computeScrollSnapAlignOffset(scrollSnapArea.x(), scrollSnapArea.maxX(), xAlign, scrollerIsRTL) - computeScrollSnapAlignOffset(scrollSnapPort.x(), scrollSnapPort.maxX(), xAlign, scrollerIsRTL); |
| 262 |
auto absoluteScrollOffset = clampTo<int>(scrollableArea.scrollOffsetFromPosition({ roundToInt(absoluteScrollXPosition), 0 }).x(), 0, maxScrollOffset.x()); |
275 |
auto absoluteScrollOffset = clampTo<int>(scrollableArea.scrollOffsetFromPosition({ roundToInt(absoluteScrollXPosition), 0 }).x(), 0, maxScrollOffset.x()); |
| 263 |
addOrUpdateStopForSnapOffset(horizontalSnapOffsetsMap, { absoluteScrollOffset, stop, snapAreas.size() - 1 }); |
276 |
addOrUpdateStopForSnapOffset(horizontalSnapOffsetsMap, { absoluteScrollOffset, stop, snapAreas.size() - 1 }); |
| 264 |
} |
277 |
} |
| 265 |
if (snapsVertically) { |
278 |
if (snapsVertically) { |
| 266 |
auto absoluteScrollYPosition = computeScrollSnapAlignOffset(scrollSnapArea.y(), scrollSnapArea.maxY(), alignment.y, false) - computeScrollSnapAlignOffset(scrollSnapPort.y(), scrollSnapPort.maxY(), alignment.y, false); |
279 |
auto absoluteScrollYPosition = computeScrollSnapAlignOffset(scrollSnapArea.y(), scrollSnapArea.maxY(), yAlign, false) - computeScrollSnapAlignOffset(scrollSnapPort.y(), scrollSnapPort.maxY(), yAlign, false); |
| 267 |
auto absoluteScrollOffset = clampTo<int>(scrollableArea.scrollOffsetFromPosition({ 0, roundToInt(absoluteScrollYPosition) }).y(), 0, maxScrollOffset.y()); |
280 |
auto absoluteScrollOffset = clampTo<int>(scrollableArea.scrollOffsetFromPosition({ 0, roundToInt(absoluteScrollYPosition) }).y(), 0, maxScrollOffset.y()); |
| 268 |
addOrUpdateStopForSnapOffset(verticalSnapOffsetsMap, { absoluteScrollOffset, stop, snapAreas.size() - 1 }); |
281 |
addOrUpdateStopForSnapOffset(verticalSnapOffsetsMap, { absoluteScrollOffset, stop, snapAreas.size() - 1 }); |
| 269 |
} |
282 |
} |
| 270 |
|
|
|
| 271 |
if (!snapAreas.isEmpty()) |
| 272 |
LOG_WITH_STREAM(ScrollSnap, stream << " => Computed snap areas: " << snapAreas); |
| 273 |
} |
283 |
} |
| 274 |
|
284 |
|
| 275 |
auto compareSnapOffsets = [](const SnapOffset<LayoutUnit>& a, const SnapOffset<LayoutUnit>& b) |
285 |
auto compareSnapOffsets = [](const SnapOffset<LayoutUnit>& a, const SnapOffset<LayoutUnit>& b) |
|
Lines 277-282
void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, const Re
a/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp_sec5
|
| 277 |
return a.offset < b.offset; |
287 |
return a.offset < b.offset; |
| 278 |
}; |
288 |
}; |
| 279 |
|
289 |
|
|
|
290 |
if (!snapAreas.isEmpty()) |
| 291 |
LOG_WITH_STREAM(ScrollSnap, stream << " => Computed snap areas: " << snapAreas); |
| 292 |
|
| 280 |
Vector<SnapOffset<LayoutUnit>> horizontalSnapOffsets = copyToVector(horizontalSnapOffsetsMap.values()); |
293 |
Vector<SnapOffset<LayoutUnit>> horizontalSnapOffsets = copyToVector(horizontalSnapOffsetsMap.values()); |
| 281 |
if (!horizontalSnapOffsets.isEmpty()) { |
294 |
if (!horizontalSnapOffsets.isEmpty()) { |
| 282 |
std::sort(horizontalSnapOffsets.begin(), horizontalSnapOffsets.end(), compareSnapOffsets); |
295 |
std::sort(horizontalSnapOffsets.begin(), horizontalSnapOffsets.end(), compareSnapOffsets); |