Skip to content

Commit

Permalink
Bug 353575 - Allow IDTracker to look up elements in <svg:use> shadow …
Browse files Browse the repository at this point in the history
…trees. r=smaug

Other UAs allow this, and it seems in the general consensus of
WICG/webcomponents#179.

This matches WebKit's behavior. Blink, for some reason shows red on the
test-case, probably because they're not doing quite this, but they
manage to render masks inside the display: none symbol element or such.

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

UltraBlame original commit: 8efff752175e177108adceddb73a60f98f8cdd27
  • Loading branch information
marco-c committed Apr 28, 2020
1 parent f369a07 commit 008ac25
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 45 deletions.
209 changes: 168 additions & 41 deletions dom/base/IDTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ h
#
include
"
mozilla
/
dom
/
DocumentOrShadowRoot
.
h
"
#
include
"
nsAtom
.
h
"
#
include
"
nsContentUtils
.
h
Expand Down Expand Up @@ -165,20 +183,72 @@ nsCycleCollectionParticipant
.
h
"
#
include
"
nsStringFwd
.
h
"
namespace
mozilla
{
namespace
dom
{
static
Element
*
LookupElement
(
DocumentOrShadowRoot
&
aDocOrShadow
const
nsAString
&
aRef
bool
aReferenceImage
)
{
if
(
aReferenceImage
)
{
return
aDocOrShadow
.
LookupImageElement
(
aRef
)
;
}
return
aDocOrShadow
.
GetElementById
(
aRef
)
;
}
static
DocumentOrShadowRoot
*
DocOrShadowFromContent
FindTreeToWatch
(
nsIContent
&
aContent
const
nsAString
&
aID
bool
aReferenceImage
)
{
ShadowRoot
Expand All @@ -194,16 +264,17 @@ GetContainingShadow
/
/
We
never
look
in
allow
looking
outside
an
<
svg
:
use
>
shadow
trees
tree
for
backwards
compat
Expand All @@ -230,6 +301,58 @@ use
)
)
{
/
/
<
svg
:
use
>
shadow
trees
are
immutable
so
we
can
just
early
-
out
if
we
find
/
/
our
relevant
element
instead
of
having
to
support
watching
multiple
/
/
trees
.
if
(
LookupElement
(
*
shadow
aID
aReferenceImage
)
)
{
return
shadow
;
}
shadow
=
shadow
Expand Down Expand Up @@ -371,16 +494,6 @@ OwnerDoc
(
)
;
DocumentOrShadowRoot
*
docOrShadow
=
DocOrShadowFromContent
(
*
aFromContent
)
;
auto
encoding
=
Expand Down Expand Up @@ -553,6 +666,10 @@ GetDocumentURI
isEqualExceptRef
)
;
DocumentOrShadowRoot
*
docOrShadow
;
if
(
NS_FAILED
Expand Down Expand Up @@ -658,6 +775,19 @@ a
bit
}
}
else
{
docOrShadow
=
FindTreeToWatch
(
*
aFromContent
ref
aReferenceImage
)
;
}
if
(
aWatch
Expand Down Expand Up @@ -718,23 +848,34 @@ mReferencingImage
=
false
;
nsDependentAtomString
str
(
aID
)
;
DocumentOrShadowRoot
*
docOrShadow
=
DocOrShadowFromContent
FindTreeToWatch
(
aFrom
str
/
*
aReferenceImage
=
*
/
false
)
;
HaveNewDocumentOrShadowRoot
(
docOrShadow
aWatch
nsDependentAtomString
(
aID
)
str
)
;
}
Expand Down Expand Up @@ -805,31 +946,19 @@ aDocOrShadow
return
;
}
if
(
Element
*
e
=
mReferencingImage
?
aDocOrShadow
-
>
LookupImageElement
LookupElement
(
aRef
)
:
*
aDocOrShadow
-
>
GetElementById
(
aRef
mReferencingImage
)
;
if
(
e
)
{
mElement
Expand Down Expand Up @@ -1131,7 +1260,8 @@ aData
{
NS_ASSERTION
(
PL_strcmp
!
strcmp
(
aTopic
"
Expand All @@ -1144,9 +1274,6 @@ document
created
"
)
=
=
0
"
Unexpected
topic
Expand Down
4 changes: 2 additions & 2 deletions layout/reftests/svg/fragid-shadow-7.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
fill
=
"
lime
red
"
width
=
Expand Down Expand Up @@ -204,7 +204,7 @@
fill
=
"
red
lime
"
width
=
Expand Down
4 changes: 2 additions & 2 deletions layout/reftests/svg/fragid-shadow-8.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
fill
=
"
lime
red
"
width
=
Expand Down Expand Up @@ -91,7 +91,7 @@
fill
=
"
red
lime
"
width
=
Expand Down

0 comments on commit 008ac25

Please sign in to comment.