Skip to content

Commit ac1363b

Browse files
committed
[css-anchor-position] Redesign position fallbacks. #9196 (comment)
1 parent 16e42ed commit ac1363b

File tree

1 file changed

+188
-57
lines changed

1 file changed

+188
-57
lines changed

css-anchor-position-1/Overview.bs

+188-57
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ Animation type: discrete
291291
The 'anchor-default' property defines the <dfn>default anchor specifier</dfn>
292292
for all [=anchor functions=] on the element,
293293
allowing multiple elements to use the same set of [=anchor functions=]
294-
(and [=position fallback lists=]!)
294+
(and [=position options lists=]!)
295295
while changing which [=anchor element=] each is referring to.
296296

297297
The [=target anchor element=] selected by the [=default anchor specifier=]
@@ -853,7 +853,7 @@ we define:
853853
or |query el|'s used [=self-alignment property=] value
854854
in the axis is ''anchor-center''.
855855

856-
Note: If |query el| has a [=position fallback list=],
856+
Note: If |query el| has a [=position options list=],
857857
then whether it [=needs scroll adjustment=] in an axis
858858
is also affected by the applied fallback style.
859859

@@ -985,17 +985,18 @@ If no fallback value is specified,
985985
it resolves to ''0px''.
986986

987987

988-
<!--
989-
████████ ███ ██ ██ ████████ ███ ██████ ██ ██
990-
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
991-
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
992-
██████ ██ ██ ██ ██ ████████ ██ ██ ██ █████
993-
██ █████████ ██ ██ ██ ██ █████████ ██ ██ ██
994-
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
995-
██ ██ ██ ████████ ████████ ████████ ██ ██ ██████ ██ ██
988+
<!-- Big Text: fallback
989+
990+
█████▌ ███▌ █▌ █▌ ████▌ ███▌ ███▌ █▌ █▌
991+
█▌ ▐█ ▐█ █▌ █▌ █▌ █▌ ▐█ ▐█ █▌ █▌ █▌ █▌
992+
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌█▌
993+
████ █▌ █▌ █▌ █▌ █████ █▌ █▌ █▌ ██
994+
█▌ █████▌ █▌ █▌ █▌ █▌ █████▌ █▌ █▌█▌
995+
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
996+
█▌ █▌ █▌ █████ █████ ████▌ █▌ █▌ ███▌ █▌ █▌
996997
-->
997998

998-
Fallback Sizing/Positioning {#fallback}
999+
Overflow Management {#fallback}
9991000
===========================
10001001

10011002
Anchor positioning,
@@ -1007,95 +1008,225 @@ so positioning an element in any particular fashion
10071008
might result in the positioned element overflowing its [=containing block=]
10081009
or being positioned partially off screen.
10091010

1010-
To ameliorate this, an [=absolutely positioned=] element
1011+
<s>To ameliorate this, an [=absolutely positioned=] element
10111012
can use the 'position-fallback' property
10121013
to refer to a ''@position-fallback'' block,
10131014
giving a list of possible style rules to try out.
10141015
Each is applied to the element, one by one,
10151016
and the first that doesn't cause the element
10161017
to overflow its [=containing block=]
1017-
is taken as the winner.
1018+
is taken as the winner.</s>
10181019

1019-
The 'position-fallback' Property {#fallback-property}
1020+
Giving Fallback Options: the 'position-try-options' property {#position-try-options}
10201021
--------------------------------
10211022

10221023
<pre class=propdef>
1023-
Name: position-fallback
1024-
Value: none | <<dashed-ident>>
1024+
Name: position-try-options
1025+
Value: none | [ <<dashed-ident>> | <<try-tactic>> ]#
10251026
Initial: none
10261027
Inherited: no
10271028
Applies to: [=absolutely-positioned=] elements
10281029
Animation type: discrete
10291030
</pre>
10301031

1032+
This property provides a list of alternate positioning styles
1033+
to try when the [=absolutely positioned box=]
1034+
overflows its [=inset-modified containing block=].
1035+
This <dfn export>position options list</dfn>
1036+
initially contains the element's own computed style.
1037+
1038+
Each comma-separated entry in the list is a separate option:
1039+
either the name of a ''@position-try'' block,
1040+
or a <<try-tactic>> representing an automatic transformation of the element's existing computed style.
1041+
10311042
Values have the following meanings:
10321043

1033-
<dl dfn-type=value dfn-for=position-fallback>
1044+
<dl dfn-type=value dfn-for=position-try-options>
10341045
: <dfn>none</dfn>
1035-
:: The property has no effect;
1036-
the element does not use a [=position fallback list=].
1046+
::
1047+
The property has no effect;
1048+
the only entry in the [=position options list=]
1049+
is the element's computed style.
10371050

10381051
: <dfn><<dashed-ident>></dfn>
1039-
:: If there is a ''@position-fallback'' rule
1040-
with a name matching the specified ident,
1041-
then the element uses that [=position fallback list=].
1052+
::
1053+
If there is a ''@position-try'' rule
1054+
with the given name,
1055+
its associated [=position option=]
1056+
is added to the [=position options list=].
10421057

10431058
Otherwise,
10441059
this value has no effect.
1060+
1061+
: <dfn><<try-tactic>></dfn>
1062+
::
1063+
Automatically creates a [=position option=]
1064+
from the element's computed style,
1065+
by swapping the
1066+
[=margin property|margin=],
1067+
[=sizing property|sizing=],
1068+
[=inset property|inset=],
1069+
and [=self-alignment property|self-alignment=] property values
1070+
among the element's sides,
1071+
and adds it to the [=position options list=].
1072+
1073+
<pre class=prod>
1074+
<dfn type><<try-tactic>></dfn> = flip-block || flip-inline || flip-start
1075+
</pre>
1076+
1077+
: <dfn>flip-block</dfn>
1078+
::
1079+
swaps the values in the [=block axis=]
1080+
(between, for example, 'margin-block-start' and 'margin-block-end'),
1081+
essentially mirroring across an [=inline-axis=] line.
1082+
1083+
: <dfn>flip-inline</dfn>
1084+
::
1085+
swaps the values in the [=inline axis=],
1086+
essentially mirroring across a [=block-axis=] line.
1087+
1088+
: <dfn>flip-start</dfn>
1089+
::
1090+
swaps the values of the [=start=] properties with each other,
1091+
and the [=end=] properties with each other
1092+
(between, for example,
1093+
'margin-block-start' and 'margin-inline-start'),
1094+
essentially mirroring across a diagonal drawn
1095+
from the [=block-start|start=]-[=inline-start|start=] corner
1096+
to the [=block-end|end=]-[=inline-end|end=] corner.
1097+
1098+
If multiple keywords are given,
1099+
the transformations are composed in order
1100+
to produce a single [=position option=].
1101+
1102+
Issue: Define how the values themselves are changed upon flipping:
1103+
anchor(top) becomes anchor(bottom);
1104+
start becomes end;
1105+
etc.
1106+
</dl>
1107+
1108+
1109+
Determining Fallback Order: the 'position-try-order' property {#position-try-order-property}
1110+
----------------------------------
1111+
1112+
<pre class=propdef>
1113+
Name: position-try-order
1114+
Value: normal | <<try-size>>
1115+
Initial: normal
1116+
Applies to: [=absolutely positioned elements=]
1117+
Inherited: no
1118+
Animation Type: discrete
1119+
</pre>
1120+
1121+
This property specifies the order in which
1122+
the [=position options list=] will be tried.
1123+
1124+
<pre class=prod>
1125+
<dfn type><<try-size>></dfn> = most-width | most-height | most-block-size | most-inline-size
1126+
</pre>
1127+
1128+
<dl dfn-type=value dfn-for=position-try-order>
1129+
: <dfn>normal</dfn>
1130+
::
1131+
Try the [=position options=]
1132+
in the order specified by 'position-try-options'.
1133+
1134+
: <dfn>most-width</dfn>
1135+
: <dfn>most-height</dfn>
1136+
: <dfn>most-block-size</dfn>
1137+
: <dfn>most-inline-size</dfn>
1138+
::
1139+
Stable sort the [=position options list=]
1140+
in order of greatest to least
1141+
[=inset-modified containing block=] size
1142+
in the matching axis.
10451143
</dl>
10461144

1047-
The ''@position-fallback'' Rule {#fallback-rule}
1145+
Final Fallback Strategy: the 'position-try-final' property {#position-try-final-property}
1146+
----------------------
1147+
1148+
<pre class=propdef>
1149+
Name: position-try-final
1150+
Value: [ always? && [ first | <<try-size>> ] ] | hide
1151+
Initial: first
1152+
Applies to: [=absolutely positioned elements=]
1153+
Inherited: no
1154+
Animation Type: discrete
1155+
</pre>
1156+
1157+
When all options in the [=position options list=]
1158+
would result in the element overflowing its [=inset-modified containing block=],
1159+
this property determines which [=position option=] to use.
1160+
1161+
<dl dfn-type=value dfn-for=position-try-final>
1162+
: <dfn>first</dfn>
1163+
::
1164+
Use the first option in the [=position options list=]
1165+
(after sorting by 'position-try-order').
1166+
1167+
: <dfn lt="<try-size> | most-width | most-height | most-block-size | most-inline-size"><<try-size>></dfn>
1168+
::
1169+
Stable sort the [=position options list=] as if this was the specified 'position-try-order',
1170+
then use the first option.
1171+
1172+
: <dfn>always</dfn>
1173+
::
1174+
If this keyword is <em>not</em> specified,
1175+
and this box has previously been laid out
1176+
with a [=position option=]
1177+
that didn't result in overflow,
1178+
use that option.
1179+
1180+
: <dfn>hide</dfn>
1181+
::
1182+
Use the first option (as for ''first''),
1183+
but also hide the box such that it (and all of its contents)
1184+
are invisible (like ''visibility: hidden'')
1185+
and do not contribute to [=scrollable overflow=].
1186+
</dl>
1187+
1188+
1189+
The ''@position-try'' Rule {#fallback-rule}
10481190
-------------------------------
10491191

1050-
The <dfn>@position-fallback</dfn> rule
1051-
defines a [=position fallback list=]
1192+
The <dfn>@position-try</dfn> rule
1193+
defines a <dfn>position option</dfn>
10521194
with a given name,
10531195
specifying one or more sets of positioning properties
1054-
inside of <dfn>@try</dfn> blocks
1055-
that will be applied to an element,
1056-
with each successive one serving as fallback
1057-
if the previous would cause the element
1058-
to partially or fully overflow its [=containing block=].
1196+
that will be applied to an element
1197+
via 'position-try-options',
10591198

1060-
The grammar of the ''@position-fallback'' rule is:
1199+
The syntax of the ''@position-try'' rule is:
10611200

10621201
<pre class=prod>
1063-
@position-fallback <<dashed-ident>> {
1064-
<<rule-list>>
1202+
@position-try <<dashed-ident>> {
1203+
<<declaration-list>>
10651204
}
1066-
1067-
@try { <<declaration-list>> }
10681205
</pre>
10691206

1070-
The ''@position-fallback'' rule only accepts ''@try'' rules.
10711207
The <<dashed-ident>> specified in the prelude
10721208
is the rule's name.
1073-
If multiple ''@position-fallback'' rules are declared with the same name,
1209+
If multiple ''@position-try'' rules are declared with the same name,
10741210
the last one in document order "wins".
10751211

1076-
The ''@try'' rule only <dfn lt="accepted @try properties">accepts</dfn>
1212+
Issue: Or should they cascade together?
1213+
1214+
The ''@position-try'' rule only <dfn lt="accepted @position-try properties">accepts</dfn>
10771215
the following [=properties=]:
10781216

10791217
* [=inset properties=]
10801218
* [=margin properties=]
1081-
* [=border properties=]
1082-
* [=padding properties=]
10831219
* [=sizing properties=]
1084-
* [=box alignment properties=]
1220+
* [=self-alignment properties=]
10851221

1086-
Issue: What exactly are the constraints that determine what's allowed here?
1222+
Issue(#9195): What exactly are the constraints that determine what's allowed here?
10871223
Current list is based off of what's reasonable
10881224
from Chrome's experimental impl.
10891225
We can make a CQ that keys off of which fallback was used
10901226
to allow more general styling,
10911227
at least for descendants.
10921228

1093-
The ''@try'' rules inside a ''@position-fallback''
1094-
specify a <dfn>position fallback list</dfn>,
1095-
where each entry consists of the properties specified by each ''@try'',
1096-
in order.
1097-
1098-
Issue: Would be useful to be able to detect
1229+
Issue(#7758): Would be useful to be able to detect
10991230
when your anchor(s) are fully off-screen
11001231
and suppress your display entirely.
11011232
For example, tooltips living outside the scroller
@@ -1113,9 +1244,9 @@ and specify each element's anchor in 'anchor-default' instead.
11131244
Note: The most common types of fallback positioning
11141245
(putting the positioned element on one side of the anchor normally,
11151246
but flipping to the opposite side if needed)
1116-
can be done automatically,
1117-
without using ''@position-fallback'' at all,
1118-
by using TODO FILL ME IN WITH NEW DETAILS.
1247+
can be done automatically
1248+
with keywords in 'position-try-options',
1249+
without using ''@position-try'' at all.
11191250

11201251
Applying Stronger Fallback Bounds: the 'position-fallback-bounds' property {#fallback-bounds}
11211252
--------------------------------------------------------------------------
@@ -1156,7 +1287,7 @@ Animation type: discrete
11561287
: <dfn>normal</dfn>
11571288
:: The element uses its normal (scroll-adjusted, inset-modified) containing block
11581289
to determine if it's overflowing
1159-
for the purpose of selecting a [=position fallback list=] entry.
1290+
for the purpose of selecting a [=position options list=] entry.
11601291

11611292
: <<dashed-ident>>
11621293
::
@@ -1178,7 +1309,7 @@ Animation type: discrete
11781309
Applying Position Fallback {#fallback-apply}
11791310
--------------------------
11801311

1181-
When an element uses a [=position fallback list=],
1312+
When an element uses a [=position options list=],
11821313
it selects one entry from the list
11831314
as defined below,
11841315
and applies those properties to itself as [=used values=].
@@ -1203,9 +1334,9 @@ to trigger automatic "animation" of the fallback'd properties.
12031334

12041335
1. Let |base styles| be the current used styles of |el|.
12051336

1206-
2. [=list/For each=] |fallback styles| in the [=position fallback list=]:
1337+
2. [=list/For each=] |fallback styles| in the [=position options list=]:
12071338

1208-
1. Apply the values of the [=accepted @try properties=]
1339+
1. Apply the values of the [=accepted @position-try properties=]
12091340
in |fallback styles| to |el|,
12101341
overriding the corresponding properties in |base styles|.
12111342

@@ -1239,7 +1370,7 @@ to trigger automatic "animation" of the fallback'd properties.
12391370

12401371
3. If the previous step finished without selecting a set of styles,
12411372
use the |adjusted styles|
1242-
corresponding to the final entry in the [=position fallback list=].
1373+
corresponding to the final entry in the [=position options list=].
12431374

12441375
Note: Descendants overflowing |el|
12451376
don't affect this calculation,
@@ -1250,7 +1381,7 @@ The styles returned by [=determining the position fallback styles=]
12501381
are taken as the final values for the specified properties.
12511382

12521383
Implementations may choose to impose an implementation-defined limit
1253-
on the length of [=position fallback lists=],
1384+
on the length of [=position options lists=],
12541385
to limit the amount of excess layout work that may be required.
12551386
This limit must be <em>at least</em> five.
12561387

0 commit comments

Comments
 (0)