Skip to content

Commit

Permalink
Bug 1514074 - Retarget results of offset* DOM APIs. r=smaug
Browse files Browse the repository at this point in the history
Per w3c/csswg-drafts#159.

The test is imported from WebKit, who has already implemented this, with a few
fixes to avoid duplicate test names and non-undefined return values from
add_cleanup.

See the diff attached to the bug.

Differential Revision: https://phabricator.services.mozilla.com/D15938

UltraBlame original commit: e0a5cb126f2f084e5f7f3d5f0be0222a7fd67479
  • Loading branch information
marco-c committed Oct 3, 2019
1 parent f9ca91a commit 8a89e39
Show file tree
Hide file tree
Showing 2 changed files with 2,328 additions and 23 deletions.
233 changes: 210 additions & 23 deletions dom/html/nsGenericHTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,34 +1591,38 @@ return
false
;
}
struct
OffsetResult
{
Element
*
nsGenericHTMLElement
:
:
GetOffsetRect
(
CSSIntRect
&
aRect
)
{
aRect
mParent
=
nullptr
;
CSSIntRect
mRect
;
}
;
static
OffsetResult
GetUnretargetedOffsetsFor
(
const
Element
&
aElement
)
;
{
nsIFrame
*
frame
=
aElement
.
GetPrimaryFrame
(
FlushType
:
:
Layout
)
;
if
Expand All @@ -1628,7 +1632,8 @@ frame
)
{
return
nullptr
{
}
;
}
nsIFrame
Expand Down Expand Up @@ -1671,6 +1676,8 @@ Element
*
docElement
=
aElement
.
GetComposedDoc
(
)
Expand Down Expand Up @@ -2085,6 +2092,8 @@ here
.
offsetParent
=
aElement
.
GetComposedDoc
(
)
Expand Down Expand Up @@ -2266,29 +2275,207 @@ MoveTo
origin
)
;
aRect
=
return
{
Element
:
:
FromNodeOrNull
(
offsetParent
)
CSSIntRect
:
:
FromAppUnitsRounded
(
rcFrame
)
}
;
}
static
bool
ShouldBeRetargeted
(
const
Element
&
aReferenceElement
const
Element
&
aElementToMaybeRetarget
)
{
ShadowRoot
*
shadow
=
aElementToMaybeRetarget
.
GetContainingShadow
(
)
;
if
(
!
shadow
)
{
return
offsetParent
?
offsetParent
false
;
}
for
(
ShadowRoot
*
scope
=
aReferenceElement
.
GetContainingShadow
(
)
;
scope
;
scope
=
scope
-
>
AsElement
Host
(
)
-
>
GetContainingShadow
(
)
)
{
if
(
scope
=
=
shadow
)
{
return
false
;
}
}
return
true
;
}
Element
*
nsGenericHTMLElement
:
:
GetOffsetRect
(
CSSIntRect
&
aRect
)
{
aRect
=
CSSIntRect
(
)
;
if
(
!
GetPrimaryFrame
(
FlushType
:
:
Layout
)
)
{
return
nullptr
;
}
OffsetResult
thisResult
=
GetUnretargetedOffsetsFor
(
*
this
)
;
aRect
=
thisResult
.
mRect
;
Element
*
parent
=
thisResult
.
mParent
;
while
(
parent
&
&
ShouldBeRetargeted
(
*
this
*
parent
)
)
{
OffsetResult
result
=
GetUnretargetedOffsetsFor
(
*
parent
)
;
aRect
+
=
result
.
mRect
.
TopLeft
(
)
;
parent
=
result
.
mParent
;
}
return
parent
;
}
bool
nsGenericHTMLElement
:
Expand Down
Loading

0 comments on commit 8a89e39

Please sign in to comment.