Skip to content

Commit c3b1efa

Browse files
committed
cleanup getBoundingClientRect and getClientRects
1 parent 49a13a1 commit c3b1efa

2 files changed

Lines changed: 90 additions & 65 deletions

File tree

cssom/Overview.html

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,11 +2329,11 @@ <h3 id=the-elementlayout><span class=secno>4.3. </span>The <code><a
23292329
<a href="#textrectanglelist">TextRectangleList</a> <a href="#elementlayout-getclientrects">getClientRects</a>();
23302330
<a href="#textrectangle">TextRectangle</a> <a href="#elementlayout-getboundingclientrect">getBoundingClientRect</a>();
23312331

2332+
readonly attribute Element <a href="#elementlayout-offsetparent">offsetParent</a>;
23322333
readonly attribute float <a href="#elementlayout-offsettop">offsetTop</a>;
23332334
readonly attribute float <a href="#elementlayout-offsetleft">offsetLeft</a>;
23342335
readonly attribute float <a href="#elementlayout-offsetwidth">offsetWidth</a>;
23352336
readonly attribute float <a href="#elementlayout-offsetheight">offsetHeight</a>;
2336-
readonly attribute HTMLElement <a href="#elementlayout-offsetparent">offsetParent</a>; // HTMLElement
23372337

23382338
attribute float <a href="#elementlayout-scrolltop">scrollTop</a>; // scroll on setting
23392339
attribute float <a href="#elementlayout-scrollleft">scrollLeft</a>; // scroll on setting
@@ -2356,43 +2356,56 @@ <h4 id=the-getclientrects><span class=secno>4.3.1. </span>The <code><a
23562356
multiple boxes it's the amount of boxes. -->
23572357

23582358
<p>The <dfn
2359-
id=elementlayout-getclientrects><code>getClientRects()</code></dfn> method
2360-
<em class=ct>must</em>, when invoked, return a <code><a
2361-
href="#textrectanglelist">TextRectangleList</a></code> object containing a
2362-
list of <code><a href="#textrectangle">TextRectangle</a></code> objects
2363-
describing the border boxes for the element on which it was invoked.
2359+
id=elementlayout-getclientrects><code>getClientRects()</code></dfn>
2360+
method, when invoked, <em class=ct>must</em> return the result of the
2361+
following algorithm:
2362+
2363+
<ol>
2364+
<li>
2365+
<p>If the element on which it was invoked does not have an associated CSS
2366+
layout box return an empty (static) <code><a
2367+
href="#textrectanglelist">TextRectangleList</a></code> object and stop
2368+
this algorithm.
2369+
2370+
<li>
2371+
<p>Return a (static) <code><a
2372+
href="#textrectanglelist">TextRectangleList</a></code> object containing
2373+
a list of (static) <code><a
2374+
href="#textrectangle">TextRectangle</a></code> objects describing the
2375+
border boxes for the element (in content order) on which it was invoked.
2376+
</ol>
23642377

23652378
<p>The <dfn
23662379
id=elementlayout-getboundingclientrect><code>getBoundingClientRect()</code></dfn>
2367-
method <em class=ct>must</em>, when invoked, return a union of the
2368-
rectangles returned by <code><a
2369-
href="#elementlayout-getclientrects">getClientRects()</a></code> in a
2370-
single <code><a href="#textrectangle">TextRectangle</a></code> object for
2371-
the element on which it was invoked.
2372-
2373-
<p>The values of the attributes of the <code><a
2374-
href="#textrectangle">TextRectAngle</a></code> object <em
2375-
class=ct>must</em> all be expressed in CSS pixels. They are all relative
2376-
to the top left corner of the canvas (0, 0) and calculated as if nothing
2377-
has been scrolled. If the element is a descendent of an
2378-
<code>svg:foreignObject</code> element the dimensions are measured
2379-
relative to the origin of the nearest <code>svg:foreignObject</code>
2380-
ancestor, in the <code>svg:foreignObject</code> subtree's CSS coordinate
2381-
system.
2382-
2383-
<p class=issue>...</p>
2380+
method, when invoked, <em class=ct>must</em> return the result of the
2381+
following algorithm:
2382+
2383+
<ol>
2384+
<li>
2385+
<p>If the element on which it was invoked does not have an associated CSS
2386+
layout box return a (static) <code><a
2387+
href="#textrectangle">TextRectangle</a></code> object whose <code
2388+
title=textrectangle-top><a href="#textrectangle-top">top</a></code>,
2389+
<code title=textrectangle-right><a
2390+
href="#textrectangle-right">right</a></code>, <code
2391+
title=textrectangle-bottom><a
2392+
href="#textrectangle-bottom">bottom</a></code> and <code
2393+
title=textrectangle-left><a href="#textrectangle-left">left</a></code>
2394+
members are zero.
2395+
2396+
<li>
2397+
<p>Return a union of the rectangles returned by <code><a
2398+
href="#elementlayout-getclientrects">getClientRects()</a></code> method
2399+
as a single <code><a href="#textrectangle">TextRectangle</a></code>
2400+
object for the element on which it was invoked.
2401+
</ol>
23842402
<!--
23852403
XXX
23862404
23872405
- The returned rectangles do not include the bounds of any child elements
23882406
that might happen to overflow (ok, this was not ambiguous in the above
23892407
definition, it's just a note)
23902408
2391-
- For HTML AREA elements, SVG elements that do not render anything
2392-
themselves, display:none elements, and generally any elements that are not
2393-
directly rendered, we return an empty list or a (0,0,0,0) rect (arguably this
2394-
also follows from the definition)
2395-
23962409
- for getClientRects we return rectangles even for CSS boxes that have empty
23972410
border-boxes. The left, top, right and bottom coordinates can still be
23982411
meaningful.
@@ -2456,23 +2469,27 @@ <h5 id=the-textrectangle><span class=secno>4.3.1.2. </span>The <code><a
24562469

24572470
<p>The <dfn id=textrectangle-top
24582471
title=textrectangle-top><code>top</code></dfn> attribute, on getting, <em
2459-
class=ct>must</em> return the distance between the top of the viewport and
2460-
the top of the rectangle box.
2472+
class=ct>must</em> return the distance between the top of the initial
2473+
containing block and the top of the rectangle box in CSS pixels as number
2474+
of CSS pixels assuming nothing has been scrolled.
24612475

24622476
<p>The <dfn id=textrectangle-right
24632477
title=textrectangle-right><code>right</code></dfn> attribute, on getting,
2464-
<em class=ct>must</em> return the distance between the left of the
2465-
viewport and the right of the rectangle box.
2478+
<em class=ct>must</em> return the distance between the left of the initial
2479+
containing block and the right of the rectangle box in CSS pixels as
2480+
number of CSS pixels assuming nothing has been scrolled.
24662481

24672482
<p>The <dfn id=textrectangle-bottom
24682483
title=textrectangle-bottom><code>bottom</code></dfn> attribute, on
24692484
getting, <em class=ct>must</em> return the distance between the top of the
2470-
viewport and the bottom of the rectangle box.
2485+
initial containing block and the bottom of the rectangle box in CSS pixels
2486+
as number of CSS pixels assuming nothing has been scrolled.
24712487

24722488
<p>The <dfn id=textrectangle-left
24732489
title=textrectangle-left><code>left</code></dfn> attribute, on getting,
2474-
<em class=ct>must</em> return the distance between the left of the
2475-
viewport and the left of the rectangle box.
2490+
<em class=ct>must</em> return the distance between the left of the initial
2491+
containing block and the left of the rectangle box in CSS pixels as number
2492+
of CSS pixels assuming nothing has been scrolled.
24762493

24772494
<h4 id=the-offset><span class=secno>4.3.2. </span>The <code
24782495
title="">offset<var title="">*</var></code> attributes</h4>

cssom/Overview.src.html

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,11 +1920,11 @@ <h3>The <code>ElementLayout</code> Interface</h3>
19201920
<span>TextRectangleList</span> <span>getClientRects</span>();
19211921
<span>TextRectangle</span> <span>getBoundingClientRect</span>();
19221922

1923+
readonly attribute Element <span>offsetParent</span>;
19231924
readonly attribute float <span>offsetTop</span>;
19241925
readonly attribute float <span>offsetLeft</span>;
19251926
readonly attribute float <span>offsetWidth</span>;
19261927
readonly attribute float <span>offsetHeight</span>;
1927-
readonly attribute HTMLElement <span>offsetParent</span>; // HTMLElement
19281928

19291929
attribute float <span>scrollTop</span>; // scroll on setting
19301930
attribute float <span>scrollLeft</span>; // scroll on setting
@@ -1946,26 +1946,36 @@ <h4>The <code>getClientRects()</code> and <code>getBoundingClientRect</code>
19461946

19471947
<p>The
19481948
<dfn id="elementlayout-getclientrects"><code>getClientRects()</code></dfn>
1949-
method <em class="ct">must</em>, when invoked, return a
1950-
<code>TextRectangleList</code> object containing a list of
1951-
<code>TextRectangle</code> objects describing the border boxes for the element
1952-
on which it was invoked.</p>
1949+
method, when invoked, <em class="ct">must</em> return the result of the
1950+
following algorithm:</p>
1951+
1952+
<ol>
1953+
<li><p>If the element on which it was invoked does not have an associated CSS
1954+
layout box return an empty (static) <code>TextRectangleList</code> object and
1955+
stop this algorithm.</p></li>
1956+
1957+
<li><p>Return a (static) <code>TextRectangleList</code> object containing a
1958+
list of (static) <code>TextRectangle</code> objects describing the border
1959+
boxes for the element (in content order) on which it was invoked.</p></li>
1960+
</ol>
19531961

19541962
<p>The
19551963
<dfn id="elementlayout-getboundingclientrect"><code>getBoundingClientRect()</code></dfn>
1956-
method <em class="ct">must</em>, when invoked, return a union of the
1957-
rectangles returned by <code>getClientRects()</code> in a single
1958-
<code>TextRectangle</code> object for the element on which it was invoked.</p>
1959-
1960-
<p>The values of the attributes of the <code>TextRectAngle</code> object
1961-
<em class="ct">must</em> all be expressed in CSS pixels. They are all relative
1962-
to the top left corner of the canvas (0, 0) and calculated as if nothing has
1963-
been scrolled. If the element is a descendent of an
1964-
<code>svg:foreignObject</code> element the dimensions are measured relative to
1965-
the origin of the nearest <code>svg:foreignObject</code> ancestor, in the
1966-
<code>svg:foreignObject</code> subtree's CSS coordinate system.</p>
1967-
1968-
<p class="issue">...</p>
1964+
method, when invoked, <em class="ct">must</em> return the result of the
1965+
following algorithm:</p>
1966+
1967+
<ol>
1968+
<li><p>If the element on which it was invoked does not have an associated CSS
1969+
layout box return a (static) <code>TextRectangle</code> object whose
1970+
<code title="textrectangle-top">top</code>,
1971+
<code title="textrectangle-right">right</code>,
1972+
<code title="textrectangle-bottom">bottom</code> and
1973+
<code title="textrectangle-left">left</code> members are zero.</p></li>
1974+
1975+
<li><p>Return a union of the rectangles returned by
1976+
<code>getClientRects()</code> method as a single <code>TextRectangle</code>
1977+
object for the element on which it was invoked.</p></li>
1978+
</ol>
19691979

19701980
<!--
19711981
XXX
@@ -1974,11 +1984,6 @@ <h4>The <code>getClientRects()</code> and <code>getBoundingClientRect</code>
19741984
that might happen to overflow (ok, this was not ambiguous in the above
19751985
definition, it's just a note)
19761986
1977-
- For HTML AREA elements, SVG elements that do not render anything
1978-
themselves, display:none elements, and generally any elements that are not
1979-
directly rendered, we return an empty list or a (0,0,0,0) rect (arguably this
1980-
also follows from the definition)
1981-
19821987
- for getClientRects we return rectangles even for CSS boxes that have empty
19831988
border-boxes. The left, top, right and bottom coordinates can still be
19841989
meaningful.
@@ -2030,27 +2035,30 @@ <h5>The <code>TextRectangle</code> Interface</h5>
20302035
readonly attribute float <span title="textrectangle-bottom">bottom</span>;
20312036
readonly attribute float <span title="textrectangle-left">left</span>;
20322037
};</pre>
2033-
2038+
20342039
<p>The
20352040
<dfn id="textrectangle-top" title="textrectangle-top"><code>top</code></dfn>
20362041
attribute, on getting, <em class="ct">must</em> return the distance between
2037-
the top of the viewport and the top of the rectangle box.</p>
2042+
the top of the initial containing block and the top of the rectangle box in
2043+
CSS pixels as number of CSS pixels assuming nothing has been scrolled.</p>
20382044

20392045
<p>The
20402046
<dfn id="textrectangle-right" title="textrectangle-right"><code>right</code></dfn>
20412047
attribute, on getting, <em class="ct">must</em> return the distance between
2042-
the left of the viewport and the right of the rectangle box.</p>
2043-
2048+
the left of the initial containing block and the right of the rectangle box in
2049+
CSS pixels as number of CSS pixels assuming nothing has been scrolled.</p>
2050+
20442051
<p>The
20452052
<dfn id="textrectangle-bottom" title="textrectangle-bottom"><code>bottom</code></dfn>
20462053
attribute, on getting, <em class="ct">must</em> return the distance between
2047-
the top of the viewport and the bottom of the rectangle box.</p>
2048-
2054+
the top of the initial containing block and the bottom of the rectangle box in
2055+
CSS pixels as number of CSS pixels assuming nothing has been scrolled.</p>
20492056

20502057
<p>The
20512058
<dfn id="textrectangle-left" title="textrectangle-left"><code>left</code></dfn>
20522059
attribute, on getting, <em class="ct">must</em> return the distance between
2053-
the left of the viewport and the left of the rectangle box.</p>
2060+
the left of the initial containing block and the left of the rectangle box in
2061+
CSS pixels as number of CSS pixels assuming nothing has been scrolled.</p>
20542062

20552063

20562064

0 commit comments

Comments
 (0)