Skip to content

Commit 132a55e

Browse files
authored
Upstream the innerText spec
From https://rocallahan.github.io/innerText-spec/ with the following normative changes: * Defined behavior for non-CSS UAs. * The setter is better defined. * Added [CEReactions, TreatNullAs=EmptyString] to the IDL. Fixes whatwg#465. Remaining issues: whatwg#1679
1 parent 8819855 commit 132a55e

File tree

1 file changed

+198
-2
lines changed

1 file changed

+198
-2
lines changed

source

Lines changed: 198 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,7 +3157,7 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
31573157
<li>The <dfn data-x-href="https://dom.spec.whatwg.org/#in-a-document-tree">in a document tree</dfn>, <dfn data-x-href="https://dom.spec.whatwg.org/#in-a-document">in a document</dfn> (legacy), and <dfn data-x-href="https://dom.spec.whatwg.org/#connected">connected</dfn> concepts</li>
31583158
<li>The <dfn data-noexport="" data-x="concept-slot" data-x-href="https://dom.spec.whatwg.org/#concept-slot">slot</dfn> concept, and its <dfn data-noexport="" data-x="slot-name" data-x-href="https://dom.spec.whatwg.org/#slot-name">name</dfn> and <dfn data-noexport="" data-x-href="https://dom.spec.whatwg.org/#slot-assigned-nodes">assigned nodes</dfn></li>
31593159
<li>The <dfn data-noexport="" data-x="finding flattened slotables" data-x-href="https://dom.spec.whatwg.org/#find-flattened-slotables">find flattened slotables</dfn> algorithm</li>
3160-
<li>The <dfn data-noexport="" data-x-href="https://dom.spec.whatwg.org/#concept-node-pre-insert">pre-insert</dfn>, <dfn data-noexport="" data-x="concept-node-insert" data-x-href="https://dom.spec.whatwg.org/#concept-node-insert">insert</dfn>, <dfn data-noexport="" data-x="concept-node-append" data-x-href="https://dom.spec.whatwg.org/#concept-node-append">append</dfn>, <dfn data-noexport="" data-x="concept-node-replace" data-x-href="https://dom.spec.whatwg.org/#concept-node-replace">replace</dfn>, <dfn data-noexport="" data-x="concept-node-remove" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove">remove</dfn>, and <dfn data-noexport="" data-x="concept-node-adopt" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt">adopt</dfn> algorithms for nodes</li>
3160+
<li>The <dfn data-noexport="" data-x-href="https://dom.spec.whatwg.org/#concept-node-pre-insert">pre-insert</dfn>, <dfn data-noexport="" data-x="concept-node-insert" data-x-href="https://dom.spec.whatwg.org/#concept-node-insert">insert</dfn>, <dfn data-noexport="" data-x="concept-node-append" data-x-href="https://dom.spec.whatwg.org/#concept-node-append">append</dfn>, <dfn data-noexport="" data-x="concept-node-replace" data-x-href="https://dom.spec.whatwg.org/#concept-node-replace">replace</dfn>, <dfn data-noexport="" data-x="concept-node-replace-all" data-x-href="https://dom.spec.whatwg.org/#concept-node-replace-all">replace all</dfn>, <dfn data-noexport="" data-x="concept-node-remove" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove">remove</dfn>, and <dfn data-noexport="" data-x="concept-node-adopt" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt">adopt</dfn> algorithms for nodes</li>
31613161
<li>The <dfn data-noexport="" data-x="concept-element-attributes-change" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-change">change</dfn>, <dfn data-noexport="" data-x="concept-element-attributes-append" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-append">append</dfn>, <dfn data-noexport="" data-x="concept-element-attributes-remove" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-remove">remove</dfn>, <dfn data-noexport="" data-x="concept-element-attributes-replace" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-replace">replace</dfn>, and <dfn data-noexport="" data-x="concept-element-attributes-set-value" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-set-value">set value</dfn> algorithms for attributes</li>
31623162
<li>The <dfn data-noexport="" data-x="concept-node-insert-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-insert-ext">insertion steps</dfn>,
31633163
<dfn data-noexport="" data-x="concept-node-remove-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove-ext">removing steps</dfn>,
@@ -3447,6 +3447,7 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
34473447
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css2/visudet.html#propdef-vertical-align">'vertical-align'</dfn> property</li>
34483448
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css2/generate.html#content">'content'</dfn> property</li>
34493449
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css2/visuren.html#value-def-inline-block">'inline-block'</dfn> value of the <span>'display'</span> property</li>
3450+
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css2/visufx.html#propdef-visibility">'visibility'</dfn> property</li>
34503451
</ul>
34513452

34523453
<p>The CSS specification also defines the following border properties: <ref spec=CSS></p>
@@ -3541,6 +3542,10 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
35413542
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-backgrounds/#position">&lt;position></dfn> CSS data type</li>
35423543
</ul>
35433544

3545+
<p>The term <dfn data-noexport=""
3546+
data-x-href="https://drafts.csswg.org/css-display/#block-level">block-level</dfn> is defined in
3547+
the <cite>CSS Display</cite> specification. <ref spec=CSSDISPLAY></p>
3548+
35443549
<p>The following features are defined in the <cite>CSS Fonts</cite> specification: <ref
35453550
spec=CSSFONTS></p>
35463551

@@ -3578,13 +3583,18 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
35783583
<ul class="brief">
35793584
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-tables/#propdef-border-spacing">'border-spacing'</dfn> property</li>
35803585
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-tables/#border-collapse-property">'border-collapse'</dfn> property</li>
3581-
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-tables/#table-cell">'table-cell'</dfn> value of the <span>'display'</span> property</li>
3586+
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-tables/#table-cell">'table-cell'</dfn>,
3587+
<dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-tables/#table-row">'table-row'</dfn>,
3588+
<dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-tables/#table-caption">'table-caption'</dfn>, and
3589+
<dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-tables/#table">'table'</dfn>
3590+
values of the <span>'display'</span> property</li>
35823591
</ul>
35833592

35843593
<p>The following features are defined in the <cite>CSS Text</cite> specification:
35853594
<ref spec=CSSTEXT></p>
35863595

35873596
<ul class="brief">
3597+
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-text/#text-transform-property">'text-transform'</dfn> property</li>
35883598
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-text/#white-space-property">'white-space'</dfn> property</li>
35893599
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-text/#text-align-property">'text-align'</dfn> property</li>
35903600
<li>The <dfn data-noexport="" data-x-href="https://drafts.csswg.org/css-text/#letter-spacing-property">'letter-spacing'</dfn> property</li>
@@ -9648,6 +9658,8 @@ interface <dfn>HTMLElement</dfn> : <span>Element</span> {
96489658
[<span>CEReactions</span>] attribute <span>HTMLMenuElement</span>? <span data-x="dom-contextMenu">contextMenu</span>;
96499659
[<span>CEReactions</span>] attribute boolean <span data-x="dom-spellcheck">spellcheck</span>;
96509660
void <span data-x="dom-forceSpellCheck">forceSpellCheck</span>();
9661+
9662+
[<span>CEReactions</span>, TreatNullAs=EmptyString] attribute DOMString <span data-x="dom-innerText">innerText</span>;
96519663
};
96529664
<span>HTMLElement</span> implements <span>GlobalEventHandlers</span>;
96539665
<span>HTMLElement</span> implements <span>DocumentAndElementEventHandlers</span>;
@@ -11959,6 +11971,180 @@ interface <dfn>DOMStringMap</dfn> {
1195911971
</div>
1196011972

1196111973

11974+
<h4>The <code data-x="dom-innerText">innerText</code> IDL attribute</h4>
11975+
11976+
<dl class="domintro">
11977+
11978+
<dt><var>element</var> . <code subdfn data-x="dom-innerText">innerText</code> [ = <var>value</var> ]</dt>
11979+
11980+
<dd>
11981+
11982+
<p>Returns the element's text content "as rendered".</p>
11983+
11984+
<p>Can be set, to replace the element's children with the given value, but with line breaks
11985+
converted to <code>br</code> elements.</p>
11986+
11987+
</dl>
11988+
11989+
<div w-nodev>
11990+
11991+
<p>On getting, the <dfn><code data-x="dom-innerText">innerText</code></dfn> attribute must follow
11992+
these steps:</p>
11993+
11994+
<ol>
11995+
<li><p>If this element is not <span>being rendered</span>, or if the user agent is a non-CSS user
11996+
agent, then return the same value as the <code>textContent</code> IDL attribute on this
11997+
element.</p></li>
11998+
11999+
<li>
12000+
<p>Compute a list of items each of which is a string or a positive integer (a <i>required line
12001+
break count</i>), by applying the following recursive procedure to each child node
12002+
<var>node</var> of this element in <span>tree order</span>, and then concatenating the results
12003+
to a single list of items.</p>
12004+
12005+
<p class="note">Intuitively, a <i>required line break count</i> item means that a certain number
12006+
of line breaks appear at that point, but they can be collapsed with the line breaks induced by
12007+
adjacent <i>required line break count</i> items, reminiscent to CSS margin-collapsing.</p>
12008+
12009+
<ol>
12010+
<li><p>Let <var>items</var> be the result of recursively applying this procedure to each child
12011+
of <var>node</var> in <span>tree order</span>, and then concatenating the results to a single
12012+
list of items.</p></li>
12013+
12014+
<li><p>If <var>node</var>'s <span>computed value</span> of <span>'visibility'</span> is not
12015+
'visible', then let the result of these substeps be <var>items</var> and abort these
12016+
substeps.</p></li>
12017+
12018+
<li>
12019+
<p>If <var>node</var> is a <code>Text</code> node child of an <code>rp</code> element, then
12020+
let the result of these substeps be a single string item containing the <span
12021+
data-x="concept-cd-data">text</span> of <var>node</var> and abort these substeps.</p>
12022+
12023+
<p class="note">The <code>rp</code> element is normally 'display:none' but we want to include
12024+
its text.</p>
12025+
</li>
12026+
12027+
<li>
12028+
<p>If <var>node</var> has no associated CSS box, then let the result of these substeps be
12029+
<var>items</var> and abort these substeps.</p>
12030+
12031+
<p class="note"><var>items</var> can be non-empty due to 'display:contents'.</p>
12032+
</li>
12033+
12034+
<li><p>If <var>node</var> is a <code>Text</code> node, then for each CSS text box produced by
12035+
<var>node</var>, in content order, compute the text of the box after application of the CSS
12036+
<span>'white-space'</span> processing rules and <span>'text-transform'</span> rules, let the
12037+
result of these substeps be a list of the resulting strings, and abort these substeps. The CSS
12038+
<span>'white-space'</span> processing rules are slightly modified: collapsible spaces at the
12039+
end of lines are always collapsed, but they are only removed if the line is the last line of
12040+
the block, or it ends with a <code>br</code> element. Soft hyphens should be preserved. <ref
12041+
spec=CSSTEXT></p></li>
12042+
12043+
<li><p>If <var>node</var> is a <code>br</code> element, then append a string containing a
12044+
single U+000A LINE FEED (LF) character to <var>items</var>.</p></li>
12045+
12046+
<li><p>If <var>node</var>'s <span>computed value</span> of <span>'display'</span> is
12047+
<span>'table-cell'</span>, and <var>node</var>'s CSS box is not the last
12048+
<span>'table-cell'</span> box of its enclosing <span>'table-row'</span> box, then append a
12049+
string containing a single U+0009 CHARACTER TABULATION (tab) character to
12050+
<var>items</var>.</p></li>
12051+
12052+
<li><p>If <var>node</var>'s <span>computed value</span> of <span>'display'</span> is
12053+
<span>'table-row'</span>, and <var>node</var>'s CSS box is not the last
12054+
<span>'table-row'</span> box of the nearest ancestor <span>'table'</span> box, then append a
12055+
string containing a single U+000A LINE FEED (LF) character to <var>items</var>.</p></li>
12056+
12057+
<li><p>If <var>node</var> is a <code>p</code> element, then add 2 (a <i>required line break
12058+
count</i>) at the beginning and end of <var>items</var>.</p></li>
12059+
12060+
<li>
12061+
<p>If <var>node</var>'s <span>used value</span> of <span>'display'</span> is
12062+
<span>block-level</span> or <span>'table-caption'</span>, then add 1 (a <i>required line break
12063+
count</i>) at the beginning and end of <var>items</var>. <ref spec=CSSDISPLAY></p>
12064+
12065+
<p class="note">Floats and absolutely-positioned elements fall into this category.</p>
12066+
</li>
12067+
12068+
<li><p>Let the result of these substeps be <var>items</var>.</p></li>
12069+
</ol>
12070+
</li>
12071+
12072+
<li><p>Delete any string items whose strings are empty.</p></li>
12073+
12074+
<li><p>Delete any runs of consecutive <i>required line break count</i> items at the start or end
12075+
of the list.</p></li>
12076+
12077+
<li><p>Replace each remaining run of consecutive <i>required line break count</i> items with a
12078+
string consisting of as many U+000A LINE FEED (LF) characters as the maximum of the values in the
12079+
<i>required line break count</i> items.</p></li>
12080+
12081+
<li><p>Return the concatenation of the string items.</p></li>
12082+
</ol>
12083+
12084+
<p class="note">Note that descendant nodes of most replaced elements (e.g., <code>textarea</code>,
12085+
<code>select</code>, and <code>video</code> &mdash; but not <code>button</code>) are not rendered
12086+
by CSS, strictly speaking, and therefore have no CSS boxes for the purposes of this algorithm.</p>
12087+
12088+
<p class="big-issue">This algorithm is amenable to being generalized to work on <span
12089+
data-x="concept-range">ranges</span>. Then we can use it as the basis for <code>Selection</code>'s
12090+
stringifier and maybe expose it directly on <span data-x="concept-range">ranges</span>. See <a
12091+
href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=10583">Bugzilla bug 10583</a>.</p>
12092+
12093+
<p>On setting, the <code data-x="dom-innerText">innerText</code> attribute must follow these
12094+
steps:</p>
12095+
12096+
<ol>
12097+
<li><p>Let <var>document</var> be this element's <span>node document</span>.</p></li>
12098+
12099+
<li><p>Let <var>fragment</var> be a new <code>DocumentFragment</code> object whose <span>node
12100+
document</span> is <var>document</var>.</p></li>
12101+
12102+
<li><p>Let <var>input</var> be the given value.</p></li>
12103+
12104+
<li><p>Let <var>pointer</var> be a pointer into <var>input</var>, initially pointing at the start
12105+
of the string.</p></li>
12106+
12107+
<li><p>Let <var>text</var> be the empty string.</p></li>
12108+
12109+
<li>
12110+
<p>While <var>pointer</var> is not past the end of <var>input</var>:</p>
12111+
12112+
<ol>
12113+
<li><p><span>Collect a sequence of characters</span> that are not U+000A LINE FEED (LF) or
12114+
U+000D CARRIAGE RETURN (CR) characters. Set <var>text</var> to the collected
12115+
characters.</p></li>
12116+
12117+
<li><p>If <var>text</var> is not the empty string, then <span
12118+
data-x="concept-node-append">append</span> a new <code>Text</code> node whose <span
12119+
data-x="concept-cd-data">data</span> is <var>text</var> and <span>node document</span> is
12120+
<var>document</var> to <var>fragment</var>.</p></li>
12121+
12122+
<li>
12123+
<p>While <var>pointer</var> is not past the end of <var>input</var>, and the character at
12124+
<var>position</var> is either a U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR)
12125+
character:</p>
12126+
12127+
<ol>
12128+
<li><p>If the character at <var>position</var> is a U+000D CARRIAGE RETURN (CR) character and
12129+
the next character is a U+000A LINE FEED (LF) character, then advance <var>position</var> to
12130+
the next character in <var>input</var>.</p></li>
12131+
12132+
<li><p>Advance <var>position</var> to the next character in <var>input</var>.</p></li>
12133+
12134+
<li><p><span data-x="concept-node-append">Append</span> the result of <span
12135+
data-x="create an element">creating an element</span> given <var>document</var>,
12136+
<code>br</code>, and the <span>HTML namespace</span> to <var>fragment</var>.</p></li>
12137+
</ol>
12138+
</li>
12139+
</ol>
12140+
</li>
12141+
12142+
<li><p><span data-x="concept-node-replace-all">Replace all</span> with <var>fragment</var> within
12143+
this element.</p></li>
12144+
</ol>
12145+
12146+
</div>
12147+
1196212148
<h4>Requirements relating to the bidirectional algorithm</h4>
1196312149

1196412150
<div w-nodev>
@@ -118624,6 +118810,9 @@ INSERT INTERFACES HERE
118624118810
<dt id="refsCSSCOLOR">[CSSCOLOR]</dt>
118625118811
<dd><cite><a href="https://drafts.csswg.org/css-color/">CSS Color Module Level 3</a></cite>, T. &Ccedil;elik, C. Lilley, L. Baron. W3C.</dd>
118626118812

118813+
<dt id="refsCSSDISPLAY">[CSSDISPLAY]</dt>
118814+
<dd><cite><a href="https://drafts.csswg.org/css-font-loading/">CSS Display</a></cite>, T. Atkins, E. Etemad. W3C.</dd>
118815+
118627118816
<dt id="refsCSSFONTLOAD">[CSSFONTLOAD]</dt>
118628118817
<dd><cite><a href="https://drafts.csswg.org/css-font-loading/">CSS Font Loading</a></cite>, T. Atkins, J. Daggett. W3C.</dd>
118629118818

@@ -119956,6 +120145,13 @@ INSERT INTERFACES HERE
119956120145
href="https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document">W3C Permissive
119957120146
Document License</a>.</p>
119958120147

120148+
<p itemscope itemtype="http://n.whatwg.org/work">Part of the revision history of the <code
120149+
data-x="dom-innerText">innerText</code> IDL attribute can be found in the <a
120150+
href="https://github.com/rocallahan/innerText-spec"><code>rocallahan/innerText-spec</code>
120151+
repository</a>, which is available under the <a itemprop="license"
120152+
href="https://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0
120153+
License</a>.</p>
120154+
119959120155
<p>For about ten years starting in 2003, this specification was almost entirely written by Ian
119960120156
Hickson (Google, ian@hixie.ch). More recently, Simon Pieters (Opera, simonp@opera.com), Anne van
119961120157
Kesteren (Mozilla, annevk@annevk.nl), Philip J&auml;genstedt (Google, philip@foolip.org), and

0 commit comments

Comments
 (0)