Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Unified Diff: third_party/WebKit/Source/core/page/scrolling/SnapCoordinator.cpp

Issue 2932593004: Update the snap points css properties (Closed)
Patch Set: Fix nits Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/page/scrolling/SnapCoordinator.cpp
diff --git a/third_party/WebKit/Source/core/page/scrolling/SnapCoordinator.cpp b/third_party/WebKit/Source/core/page/scrolling/SnapCoordinator.cpp
index 5762342d791e277c83062282b04b168fe34e445e..b39e90014c482f6e21a7be27bb3628957ef86aae 100644
--- a/third_party/WebKit/Source/core/page/scrolling/SnapCoordinator.cpp
+++ b/third_party/WebKit/Source/core/page/scrolling/SnapCoordinator.cpp
@@ -43,10 +43,10 @@ static LayoutBox* FindSnapContainer(const LayoutBox& snap_area) {
return box;
}
-void SnapCoordinator::SnapAreaDidChange(
- LayoutBox& snap_area,
- const Vector<LengthPoint>& snap_coordinates) {
- if (snap_coordinates.IsEmpty()) {
+void SnapCoordinator::SnapAreaDidChange(LayoutBox& snap_area,
+ ScrollSnapAlign scroll_snap_align) {
+ if (scroll_snap_align.alignmentX == kSnapAlignmentNone &&
+ scroll_snap_align.alignmentY == kSnapAlignmentNone) {
snap_area.SetSnapContainer(nullptr);
return;
}
@@ -62,7 +62,7 @@ void SnapCoordinator::SnapAreaDidChange(
void SnapCoordinator::SnapContainerDidChange(LayoutBox& snap_container,
ScrollSnapType scroll_snap_type) {
- if (scroll_snap_type == kScrollSnapTypeNone) {
+ if (scroll_snap_type.is_none) {
// TODO(majidvp): Track and report these removals to CompositorWorker
// instance responsible for snapping
snap_containers_.erase(&snap_container);
@@ -79,88 +79,6 @@ void SnapCoordinator::SnapContainerDidChange(LayoutBox& snap_container,
// container or from existing areas in orphan pool.
}
-// Translate local snap coordinates into snap container's scrolling content
-// coordinate space.
-static Vector<FloatPoint> LocalToContainerSnapCoordinates(
- const LayoutBox& container_box,
- const LayoutBox& snap_area) {
- Vector<FloatPoint> result;
- LayoutPoint scroll_offset(container_box.ScrollLeft(),
- container_box.ScrollTop());
-
- const Vector<LengthPoint>& snap_coordinates =
- snap_area.Style()->ScrollSnapCoordinate();
- for (auto& coordinate : snap_coordinates) {
- FloatPoint local_point =
- FloatPointForLengthPoint(coordinate, FloatSize(snap_area.Size()));
- FloatPoint container_point =
- snap_area.LocalToAncestorPoint(local_point, &container_box);
- container_point.MoveBy(scroll_offset);
- result.push_back(container_point);
- }
- return result;
-}
-
-Vector<double> SnapCoordinator::SnapOffsets(const ContainerNode& element,
- ScrollbarOrientation orientation) {
- const ComputedStyle* style = element.GetComputedStyle();
- const LayoutBox* snap_container = element.GetLayoutBox();
- DCHECK(style);
- DCHECK(snap_container);
-
- Vector<double> result;
-
- if (style->GetScrollSnapType() == kScrollSnapTypeNone)
- return result;
-
- const ScrollSnapPoints& snap_points = (orientation == kHorizontalScrollbar)
- ? style->ScrollSnapPointsX()
- : style->ScrollSnapPointsY();
-
- LayoutUnit client_size = (orientation == kHorizontalScrollbar)
- ? snap_container->ClientWidth()
- : snap_container->ClientHeight();
- LayoutUnit scroll_size = (orientation == kHorizontalScrollbar)
- ? snap_container->ScrollWidth()
- : snap_container->ScrollHeight();
-
- if (snap_points.has_repeat) {
- LayoutUnit repeat = ValueForLength(snap_points.repeat_offset, client_size);
-
- // calc() values may be negative or zero in which case we clamp them to 1px.
- // See: https://lists.w3.org/Archives/Public/www-style/2015Jul/0075.html
- repeat = std::max<LayoutUnit>(repeat, LayoutUnit(1));
- for (LayoutUnit offset = repeat; offset <= (scroll_size - client_size);
- offset += repeat) {
- result.push_back(offset.ToFloat());
- }
- }
-
- // Compute element-based snap points by mapping the snap coordinates from
- // snap areas to snap container.
- bool did_add_snap_area_offset = false;
- if (SnapAreaSet* snap_areas = snap_container->SnapAreas()) {
- for (auto& snap_area : *snap_areas) {
- Vector<FloatPoint> snap_coordinates =
- LocalToContainerSnapCoordinates(*snap_container, *snap_area);
- for (const FloatPoint& snap_coordinate : snap_coordinates) {
- float snap_offset = (orientation == kHorizontalScrollbar)
- ? snap_coordinate.X()
- : snap_coordinate.Y();
- if (snap_offset > scroll_size - client_size)
- continue;
- result.push_back(snap_offset);
- did_add_snap_area_offset = true;
- }
- }
- }
-
- if (did_add_snap_area_offset)
- std::sort(result.begin(), result.end());
-
- return result;
-}
-
#ifndef NDEBUG
void SnapCoordinator::ShowSnapAreaMap() {

Powered by Google App Engine
This is Rietveld 408576698