Skip to content

Commit 9f0651a

Browse files
committed
Merge wicg/overscroll-behavior project
Brings overscroll-behavior repo to csswg-drafts repo Fix issue w3c#2179
2 parents 3cc2eee + a03f559 commit 9f0651a

File tree

6 files changed

+2368
-0
lines changed

6 files changed

+2368
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Web Platform Incubator Community Group
2+
3+
This repository is being used for work in the Web Platform Incubator Community Group, governed by the [W3C Community License
4+
Agreement (CLA)](http://www.w3.org/community/about/agreements/cla/). To contribute, you must join
5+
the CG.
6+
7+
If you are not the sole contributor to a contribution (pull request), please identify all
8+
contributors in the pull request's body or in subsequent comments.
9+
10+
To add a contributor (other than yourself, that's automatic), mark them one per line as follows:
11+
12+
```
13+
+@github_username
14+
```
15+
16+
If you added a contributor by mistake, you can remove them in a comment with:
17+
18+
```
19+
-@github_username
20+
```
21+
22+
If you are making a pull request on behalf of someone else but you had no part in designing the
23+
feature, you can remove yourself with the above syntax.

css-overscroll-behavior/LICENSE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
All Reports in this Repository are licensed by Contributors under the
2+
[W3C Software and Document
3+
License](http://www.w3.org/Consortium/Legal/2015/copyright-software-and-document). Contributions to
4+
Specifications are made under the [W3C CLA](https://www.w3.org/community/about/agreements/cla/).
5+

css-overscroll-behavior/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Overscroll Behavior
2+
---
3+
# Draft Specification
4+
https://wicg.github.io/overscroll-behavior/
5+
6+
# Problem
7+
8+
Scroll chaining is the process of propagating the scroll event to the the nearest scrollable parent element once a scrollable reaches its limit. Scroll chaining is not always desirable. For example, consider a fixed/absolute position scroller whose scroll should not chain to the parent scroller, i.e. the document. You can find this UX pattern used in most chat boxes that live at the bottom of a page such as in Facebook or GMail UIs.
9+
10+
To give you a sense of how popular preventing scroll chaining may be, according to my quick http-archive search "-ms-scroll-chaining: none" is used in 0.4% of top 300K pages despite being limited in functionality and only supported on IE/Edge.
11+
12+
# Current Solution
13+
14+
-ms-scroll-chaining is a vendor specific API. The proposed CSS property provides a simple declarative way to prevent propagation of scroll gestures to parent containers but unfortunately it is limited to touch/touchpad scrolls only.
15+
16+
This means that currently the best cross-browser compatible way to prevent scroll propagation is to have a combination of a blocking wheel event listener (bad for performance), blocking keyboard listeners for all scroll inducing keys, carefully crafted touch-action values, and perhaps even -ms-scroll-chaining. These are rather ugly and complex hacks that "-ms-scroll-chaining" should have been able to replace but it cannot in its current form.
17+
18+
# Proposal
19+
20+
The current proposal is a summary of the public discussion from:
21+
https://github.com/w3c/csswg-drafts/issues/769
22+
23+
This proposal introduces a new CSS property to control the scrolling behavior once a scrollable element reaches the boundary of the scrollport. This property will allow the author to hint that the user agent should deny scrolling from being chained to any ancestor. Note that for certain input modes, particularly on devices with a limited screen size and limited alternative input modes, the user agent may ignore the hint and allow scroll chaining to some ancestor, like the document viewport, or all ancestors.
24+
25+
The property can also hint at the overscroll behavior that the browser should take when at the boundary of the scrollport. The overscroll behavior is implementor defined. The property should provide a hint to either allow or disallow the overscroll behavior of the user agent.
26+
27+
The proposal for the syntax is:
28+
```
29+
overscroll-behavior{-x,-y}: auto | contain | none
30+
```
31+
32+
where:
33+
* auto - Allow the default behavior for the user agent.
34+
* contain - Hint to disable scroll chaining. The user agent may show an appropriate overscroll affordance. If the scroll chaining would trigger a non-scroll action, such as a navigation action, this property should be a hint to disable the navigation action.
35+
* none - Same as contain but also hint that no overscroll affordance should be triggered.
36+
37+
This should apply to all, non-programatic, user scroll actions.

css-overscroll-behavior/index.bs

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
<pre class='metadata'>
2+
Title: CSS Overscroll Behavior Module Level 1
3+
Shortname: overscroll-behavior
4+
Level: 1
5+
Status: CG-DRAFT
6+
Work Status: Exploring
7+
Group: WICG
8+
URL: https://wicg.github.io/overscroll-behavior/
9+
Repository: wicg/overscroll-behavior
10+
Editor: Benoit Girard, Facebook, bgirard@fb.com
11+
Abstract: This module defines 'overscroll-behavior' to control the behavior when the scroll position of a <a>scroll container</a> reaches the edge of the <a>scrollport</a>.
12+
Abstract: This allows content authors to hint that the <a>boundary default actions</a>,
13+
Abstract: such as scroll chaining and overscroll, should not be triggered.
14+
</pre>
15+
16+
<pre class='anchors'>
17+
urlPrefix: https://www.w3.org/TR/css-display-3/
18+
type: dfn; text: containing block chain
19+
url: https://drafts.csswg.org/css-overflow-3/#scroll-container
20+
type: dfn; text: scroll container
21+
type: dfn; text: scroll containers
22+
url: https://www.w3.org/TR/uievents/#default-action
23+
type: dfn; text: default action
24+
type: dfn; text: default actions
25+
url: https://dom.spec.whatwg.org/#dom-event-preventdefault
26+
type: dfn; text: preventDefault
27+
url: https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener
28+
type: dfn; text: passive flag
29+
30+
</pre>
31+
32+
Introduction {#intro}
33+
=====================
34+
35+
<em>This section is not normative.</em>
36+
37+
A content author does not necessarily want <a>scroll chaining</a> to occur for all <a>scroll
38+
containers</a>. Some <a>scroll containers</a> may be part of a <a>containing block chain</a> but may
39+
serve a different logical purpose in the document and may want to prevent scrolling from continuing
40+
up the <a>scroll chain</a>. To achieve this, a content author will install event listeners without
41+
the <a>passive flag</a> set and will use <a>preventDefault</a> when there is a risk that scroll
42+
chaining will occur. This is detrimental for the following reasons:
43+
44+
* The user agent may in the future introduce new input methods for scrolling that are not supported
45+
by the content author's event listeners.
46+
* A non passive event listener will delay scrolling because the user agent will have to wait for the
47+
result of the event listener to determine if <a>preventDefault</a> was called causing increased
48+
scroll latency.
49+
* When scrolling is performed near the edge of the <a>scroll boundary</a>, the <a>default action</a>
50+
may cause both scrolling to the edge of the <a>scroll container</a> and a <a>boundary default
51+
action</a>. Calling <a>preventDefault</a> will not only cancel the <a>boundary default action</a>
52+
but also the scroll to the edge of the <a>scrollport</a>.
53+
* The <a>default action</a> for the event may also provide additional behavior that the author does
54+
not want to cancel such as an overscroll affordance. <a>preventDefault</a> doesn't allow the
55+
content author to cancel only some of the <a>default actions</a> such as scroll chaining.
56+
57+
Thus, it is not possible for a content author to control <a>scroll chaining</a> and overscroll in a
58+
robust, performant and forward compatible way. The 'overscroll-behavior' property fixes this
59+
shortcoming.
60+
61+
62+
Motivating Examples {#motivating-examples}
63+
=================
64+
65+
66+
<div class=example>
67+
A position fixed left navigation bar does not want to hand off scrolling to the document because a
68+
scroll gesture performed on the navigation bar is almost never meant to scroll the document. Note
69+
that using the native overscroll affordances are still desirable while scroll chaining is to be
70+
prevented.
71+
72+
<pre class="lang-css">
73+
#sidebar {
74+
overscroll-behavior: contain;
75+
}
76+
</pre>
77+
78+
In this case, the author can use <a value for=overscroll-behavior>contain</a> on the sidebar to
79+
prevent scrolling from being chained to the parent document element.
80+
</div>
81+
82+
<div class=example>
83+
A page wants to implement their own pull-to-refresh effect and thus needs to disable browser
84+
native overscroll action.
85+
86+
<pre class="lang-css">
87+
html {
88+
/* only disable pull-to-refresh but allow swipe navigations */
89+
overscroll-behavior-y: contain;
90+
}
91+
</pre>
92+
93+
In this case, the author can use <a value for=overscroll-behavior>contain</a> on the viewport
94+
defining element to prevent overscroll from triggering navigation actions.
95+
</div>
96+
97+
<div class=example>
98+
A infinite scrollers loads more content as user reaches the boundary and thus wants to disable the
99+
potentially confusing rubber banding effect in addition to scroll chaining.
100+
101+
<pre class="lang-css">
102+
#infinite_scroller {
103+
overscroll-behavior-y: none;
104+
}
105+
</pre>
106+
107+
In this case the the author can use <a value for=overscroll-behavior>none</a> on the infinite
108+
scroller to prevent both scroll chaining and overscroll affordance.
109+
</div>
110+
111+
Scroll chaining and boundary default actions {#scroll-chaining-and-boundary-default-actions}
112+
==========================
113+
114+
<em>Operating Systems have rules for scrolling such as scroll chaining and overscroll affordances.
115+
This specification does not mandate if and how scroll chaining or overscroll affordances be
116+
implemented. This specification only allows the content author to disable them if any are
117+
implemented.</em>
118+
119+
<dfn>Scroll chaining</dfn> is when scrolling is propagated from one <a>scroll container</a> to an
120+
ancestor <a>scroll container</a> following the <a>scroll chain</a>. Typically scroll chaining is
121+
performed starting at the event target recursing up the <a>containing block chain</a>. When a
122+
<a>scroll container</a> in this chain receives a scroll event or gesture it may act on it and/or
123+
pass it up the chain. Chaining typically occurs when the <a>scrollport</a> has reached its boundary.
124+
125+
A <dfn>scroll chain</dfn> is the order in which scrolling is propagated from one <a>scroll
126+
container</a> to another.
127+
128+
<dfn>Scroll boundary</dfn> refers to when the scroll position of a <a>scroll container</a> reaches
129+
the edge of the <a>scrollport</a>. If a scroll container has no potential to scroll, because it does
130+
not <a>overflow</a> in the direction of the scroll, the element is always considered to be at the
131+
scroll boundary.
132+
133+
<dfn>Boundary default action</dfn> refers to the user-agent-defined <a>default action</a> performed
134+
when scrolling against the edge of the <a>scrollport</a>. A <dfn>local boundary default action</dfn>
135+
is a <a>boundary default action</a> which is performed on the <a>scroll container</a> without
136+
interacting with the page, for example displaying a overscroll UI affordance. Conversely, a <dfn
137+
>non-local boundary default action</dfn> interacts with the page, for example scroll chaining or a
138+
navigation action.
139+
140+
Overview {#overview}
141+
==========================
142+
143+
This module introduces control over the behavior of a <a>scroll container</a> element when its
144+
<a>scrollport</a> reaches the boundary of its scroll box. It allows the content author to specify
145+
that a <a>scroll container</a> element must prevent scroll chaining and/or overscroll affordances.
146+
147+
Overscroll Behavior Properties {#overscroll-behavior-properties}
148+
==========================
149+
150+
These properties specify how a <a>scroll container</a> element must behave when scrolling. A element
151+
that is not <a>scroll container</a> must accept but ignore the values of this property. This
152+
property must be applied to all input methods supported by the user agent.
153+
154+
Note: This property should provide guarantees that are, at least, as strong as <a>preventDefault</a>
155+
for preventing both scroll chaining and overscroll. Doing otherwise would cause content authors to
156+
use <a>preventDefault</a> instead.
157+
158+
<pre class=propdef>
159+
Name: overscroll-behavior-x, overscroll-behavior-y
160+
Value: contain | none | auto
161+
Initial: auto
162+
Applies to: <a>scroll container</a> elements
163+
Inherited: no
164+
Percentages: N/A
165+
Media: visual
166+
Computed value: as specified
167+
Animatable: no
168+
Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
169+
</pre>
170+
171+
The 'overscroll-behavior-x' property specifies the behavior of the 'overscroll-behavior'
172+
in the horizontal direction and the 'overscroll-behavior-y' property specifies the handling of
173+
the 'overscroll-behavior' in the vertical direction. When scrolling is performed along both the
174+
horizontal and vertical axes at the same time, the 'overscroll-behavior' of each respective
175+
axis should be considered independently.
176+
177+
<pre class=propdef>
178+
Name: overscroll-behavior
179+
Value: [ contain | none | auto ]{1,2}
180+
Initial: auto auto
181+
Applies to: <a>scroll container</a> elements
182+
Inherited: no
183+
Media: visual
184+
Computed value: see individual properties
185+
Animatable: no
186+
Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
187+
</pre>
188+
189+
The two values specify the behavior in the horizontal and vertical direction, respectively. If only one value is specified, the second value defaults to the same value.
190+
191+
Values have the following meanings:
192+
193+
<dl dfn-for="overscroll-behavior, overscroll-behavior-x, overscroll-behavior-y" dfn-type="value">
194+
<dt><dfn>contain</dfn>
195+
<dd>
196+
This value indicates that the element must not perform <a>non-local boundary default actions</a>
197+
such as scroll chaining or navigation. The user agent must not perform scroll chaining to any
198+
ancestors along the <a>scroll chain</a> regardless of whether the scroll originated at this
199+
element or one of its descendants. This value must not modify the behavior of how <a>local
200+
boundary default actions</a> should behave, such as overscroll behavior.
201+
<dt><dfn>none</dfn>
202+
<dd>
203+
This value implies the same behavior as <a value for=overscroll-behavior>contain</a> and in
204+
addition this element must also not perform <a>local boundary default actions</a> such as
205+
showing any overscroll affordances.
206+
<dt><dfn>auto</dfn>
207+
<dd>
208+
This value indicates that the user agent should perform the usual <a>boundary default action</a>
209+
with respect to <a>scroll chaining</a>, overscroll and navigation gestures.
210+
</dl>
211+
212+
Note: In the case where a user agent does not implement scroll chaining and overscroll affordances,
213+
these values will have no side effects for a compliant implementation.
214+
215+
Note: Programmatic scrolling is clamped and can not trigger any <a>boundary default actions</a>.
216+
217+
218+
219+
Security and Privacy Considerations {#security-and-privacy}
220+
===================================
221+
There are no known security or privacy impacts of this feature. The feature may be used to prevent
222+
certain native UI features such as overscroll affordances and overscroll navigations (e.g., pull-
223+
to-refresh, swipe navigations). However, this does not expose any additional abilities beyond what
224+
is already possible in the platform e.g., by preventing the default action of the event that would
225+
cause a scroll.
226+
227+

0 commit comments

Comments
 (0)