From f22fbf46bd4d676a8cddb0373cf1c834ad064481 Mon Sep 17 00:00:00 2001 From: tcaptan-cr <105748547+tcaptan-cr@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:09:36 -0700 Subject: [PATCH] Add Scroll Margin to Intersection Observer (#511) * Added name to editors. * Added ScrollMargin definitions to IntersectionObserver interface section * Added ScrollMargin definitions to IntersectionObserverInit dictionary section * Added ScrollMargin definitions to Initialize a new IntersectionObserver section * Added ScrollMargin definitions to IntersectionObserver section * Add ScrollMargin to Intersection Computation section * Add ScrollMargin to Privacy and Security section * Change `scrollable intersection rectangles` to `scrollport` * Link 'margin' to css-box-3/#margins * Clarified application of both scroll and root margin to root rect * Update scrollMargin to match rootMargin * Fixed grammar and missed matching to rootMargin * Changed 'boxes' to 'clip rects' in scroll margin def * Clarified scrollable container * Simplified margin and scroll container links --- index.bs | 73 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/index.bs b/index.bs index e2d638d..38c8426 100644 --- a/index.bs +++ b/index.bs @@ -8,6 +8,7 @@ Previous version: from biblio Level: none Editor: Stefan Zager, Google, szager@google.com, w3cid 91208 Editor: Emilio Cobos Álvarez , Mozilla, emilio@mozilla.com, w3cid 106537 +Editor: Traian Captan, Google, tcaptan@google.com, w3cid 137959 Former Editor: Michael Blain, Google, mpb@google.com, w3cid 73819 Abstract: This specification describes an API that can be used to understand the visibility and position of DOM elements ("targets") relative to a containing element or to the top-level viewport ("root"). The position is delivered asynchronously and is useful for understanding the visibility of elements and implementing pre-loading and deferred loading of DOM content. Group: webapps @@ -221,6 +222,7 @@ interface IntersectionObserver { constructor(IntersectionObserverCallback callback, optional IntersectionObserverInit options = {}); readonly attribute (Element or Document)? root; readonly attribute DOMString rootMargin; + readonly attribute DOMString scrollMargin; readonly attribute FrozenArray<double> thresholds; undefined observe(Element target); undefined unobserve(Element target); @@ -282,6 +284,20 @@ interface IntersectionObserver { passed to the {{IntersectionObserver}} constructor. If no {{IntersectionObserverInit/rootMargin}} was passed to the {{IntersectionObserver}} constructor, the value of this attribute is "0px 0px 0px 0px". + : scrollMargin + :: + Offsets are applied to scrollports on the path from intersection root to target, + effectively growing or shrinking the clip rects used to calculate intersections. + These offsets are only applied when handling same-origin-domain targets; + for cross-origin-domain targets they are ignored. + + On getting, return the result of serializing the elements of {{[[scrollMargin]]}} + space-separated, where pixel lengths serialize as the numeric value followed by "px", + and percentages serialize as the numeric value followed by "%". Note that + this is not guaranteed to be identical to the |options|.{{IntersectionObserverInit/scrollMargin}} + passed to the {{IntersectionObserver}} constructor. If no + {{IntersectionObserverInit/scrollMargin}} was passed to the {{IntersectionObserver}} + constructor, the value of this attribute is "0px 0px 0px 0px". : thresholds :: A list of thresholds, sorted in increasing numeric order, @@ -325,11 +341,24 @@ If a target {{Element}} is clipped by an ances intersection root, that clipping is unaffected by {{IntersectionObserver/rootMargin}}. -Note: Root intersection rectangle is not affected by +When calculating a scrollport intersection rectangle for +a same-origin-domain target, the rectangle is expanded +according to the offsets in the {{IntersectionObserver}}’s {{[[scrollMargin]]}} slot +in a manner similar to CSS's 'margin' property, +with the four values indicating the amount the top, right, bottom, and left edges, respectively, are offset by, +with positive lengths indicating an outward offset. +Percentages are resolved relative to the width of the undilated rectangle. + +Note: {{IntersectionObserver/scrollMargin}} affects the clipping of target +by all scrollable ancestors up to and including the intersection root. +Both the {{IntersectionObserver/scrollMargin}} and the {{IntersectionObserver/rootMargin}} +are applied to a scrollable intersection root's rectangle. + +Note: Root intersection rectangle and scrollport intersection rectangles are not affected by pinch zoom and will report the unadjusted viewport, consistent with the intent of pinch zooming (to act like a magnifying glass and NOT change layout.) -To parse a root margin +To parse a margin (root or scroll) from an input string |marginString|, returning either a list of 4 pixel lengths or percentages, or failure: @@ -438,6 +467,7 @@ The IntersectionObserverInit dictionary dictionary IntersectionObserverInit { (Element or Document)? root = null; DOMString rootMargin = "0px"; + DOMString scrollMargin = "0px"; (double or sequence<double>) threshold = 0; }; @@ -459,6 +489,13 @@ dictionary IntersectionObserverInit { "-10px 5px 8px" // top = -10px, right & left = 5px, bottom = 8px "-10px -5px 5px 8px" // top = -10px, right = -5px, bottom = 5px, left = 8px + : scrollMargin + :: + Similar to {{IntersectionObserverInit/rootMargin}}, + this is a string of 1-4 components, + each either an absolute length or a percentage. + + See {{IntersectionObserverInit/rootMargin}} above for the example. : threshold :: List of threshold(s) at which to trigger callback. @@ -510,8 +547,9 @@ IntersectionObserver which are initialized to empty lists and an internal \[[callback]] slot which is initialized by {{IntersectionObserver(callback, options)}}. -They also have an internal \[[rootMargin]] slot -which is a list of four pixel lengths or percentages. +They also have internal \[[rootMargin]] +and \[[scrollMargin]] slots +which are lists of four pixel lengths or percentages.
0
to |thresholds|.
-8. The {{IntersectionObserver/thresholds}} attribute getter will return
+7. Sort |thresholds| in ascending order.
+8. If |thresholds| is empty, append 0
to |thresholds|.
+9. The {{IntersectionObserver/thresholds}} attribute getter will return
this sorted |thresholds| list.
-9. Return |this|.
+10. Return |this|.