Bug 1083587 - Add host and olderShadowRoot properties to ShadowRoot interface. r=smaug

This commit is contained in:
William Chen 2014-10-15 18:25:45 -07:00
parent 2c68e442bb
commit 01e16b1aa3
10 changed files with 107 additions and 15 deletions

View File

@ -2954,6 +2954,6 @@ FragmentOrElement::SetIsElementInStyleScopeFlagOnShadowTree(bool aInStyleScope)
ShadowRoot* shadowRoot = GetShadowRoot();
while (shadowRoot) {
shadowRoot->SetIsElementInStyleScopeFlagOnSubtree(aInStyleScope);
shadowRoot = shadowRoot->GetOlderShadow();
shadowRoot = shadowRoot->GetOlderShadowRoot();
}
}

View File

@ -481,6 +481,16 @@ ShadowRoot::SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError)
SetInnerHTMLInternal(aInnerHTML, aError);
}
Element*
ShadowRoot::Host()
{
nsIContent* host = GetHost();
MOZ_ASSERT(host && host->IsElement(),
"ShadowRoot host should always be an element, "
"how else did we create this ShadowRoot?");
return host->AsElement();
}
bool
ShadowRoot::ApplyAuthorStyles()
{

View File

@ -93,8 +93,7 @@ public:
void RemoveInsertionPoint(HTMLContentElement* aInsertionPoint);
void SetYoungerShadow(ShadowRoot* aYoungerShadow);
ShadowRoot* GetOlderShadow() { return mOlderShadow; }
ShadowRoot* GetYoungerShadow() { return mYoungerShadow; }
ShadowRoot* GetYoungerShadowRoot() { return mYoungerShadow; }
void SetInsertionPointChanged() { mInsertionPointChanged = true; }
void SetAssociatedBinding(nsXBLBinding* aBinding) { mAssociatedBinding = aBinding; }
@ -125,6 +124,8 @@ public:
GetElementsByClassName(const nsAString& aClasses);
void GetInnerHTML(nsAString& aInnerHTML);
void SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError);
Element* Host();
ShadowRoot* GetOlderShadowRoot() { return mOlderShadow; }
void StyleSheetChanged();
protected:
virtual ~ShadowRoot();

View File

@ -6816,7 +6816,7 @@ nsContentUtils::HasDistributedChildren(nsIContent* aContent)
if (shadow) {
// Children of a shadow root are distributed to
// the shadow insertion point of the younger shadow root.
return shadow->GetYoungerShadow();
return shadow->GetYoungerShadowRoot();
}
HTMLShadowElement* shadowEl = HTMLShadowElement::FromContent(aContent);

View File

@ -144,7 +144,7 @@ HTMLShadowElement::BindToTree(nsIDocument* aDocument,
if (mIsInsertionPoint && containingShadow) {
// Propagate BindToTree calls to projected shadow root children.
ShadowRoot* projectedShadow = containingShadow->GetOlderShadow();
ShadowRoot* projectedShadow = containingShadow->GetOlderShadowRoot();
if (projectedShadow) {
for (nsIContent* child = projectedShadow->GetFirstChild(); child;
child = child->GetNextSibling()) {
@ -167,7 +167,7 @@ HTMLShadowElement::UnbindFromTree(bool aDeep, bool aNullParent)
if (mIsInsertionPoint && oldContainingShadow) {
// Propagate UnbindFromTree call to previous projected shadow
// root children.
ShadowRoot* projectedShadow = oldContainingShadow->GetOlderShadow();
ShadowRoot* projectedShadow = oldContainingShadow->GetOlderShadowRoot();
if (projectedShadow) {
for (nsIContent* child = projectedShadow->GetFirstChild(); child;
child = child->GetNextSibling()) {
@ -220,7 +220,7 @@ HTMLShadowElement::DistributeSingleNode(nsIContent* aContent)
// Handle the case where the parent of this shadow element is a ShadowRoot
// that is projected into a shadow insertion point in the younger ShadowRoot.
ShadowRoot* containingShadow = GetContainingShadow();
ShadowRoot* youngerShadow = containingShadow->GetYoungerShadow();
ShadowRoot* youngerShadow = containingShadow->GetYoungerShadowRoot();
if (youngerShadow && GetParent() == containingShadow) {
HTMLShadowElement* youngerShadowElement = youngerShadow->GetShadowElement();
if (youngerShadowElement) {
@ -247,7 +247,7 @@ HTMLShadowElement::RemoveDistributedNode(nsIContent* aContent)
// Handle the case where the parent of this shadow element is a ShadowRoot
// that is projected into a shadow insertion point in the younger ShadowRoot.
ShadowRoot* containingShadow = GetContainingShadow();
ShadowRoot* youngerShadow = containingShadow->GetYoungerShadow();
ShadowRoot* youngerShadow = containingShadow->GetYoungerShadowRoot();
if (youngerShadow && GetParent() == containingShadow) {
HTMLShadowElement* youngerShadowElement = youngerShadow->GetShadowElement();
if (youngerShadowElement) {
@ -263,7 +263,7 @@ HTMLShadowElement::DistributeAllNodes()
// into this shadow insertion point so update the destination insertion
// points.
ShadowRoot* containingShadow = GetContainingShadow();
ShadowRoot* olderShadow = containingShadow->GetOlderShadow();
ShadowRoot* olderShadow = containingShadow->GetOlderShadowRoot();
if (olderShadow) {
ExplicitChildIterator childIterator(olderShadow);
for (nsIContent* content = childIterator.GetNextChild();
@ -286,7 +286,7 @@ HTMLShadowElement::DistributeAllNodes()
// Handle the case where the parent of this shadow element is a ShadowRoot
// that is projected into a shadow insertion point in the younger ShadowRoot.
ShadowRoot* youngerShadow = containingShadow->GetYoungerShadow();
ShadowRoot* youngerShadow = containingShadow->GetYoungerShadowRoot();
if (youngerShadow && GetParent() == containingShadow) {
HTMLShadowElement* youngerShadowElement = youngerShadow->GetShadowElement();
if (youngerShadowElement) {

View File

@ -24,7 +24,9 @@ support-files =
[test_template_xhtml.html]
[test_shadowroot.html]
[test_shadowroot_inert_element.html]
[test_shadowroot_host.html]
[test_shadowroot_style.html]
[test_shadowroot_style_multiple_shadow.html]
[test_shadowroot_style_order.html]
[test_shadowroot_youngershadowroot.html]
[test_style_fallback_content.html]

View File

@ -0,0 +1,41 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1083587
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1083587</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1083587">Mozilla Bug 1083587</a>
<p id="display"></p>
<div id="content" style="display: none">
<div id="host"></div>
</div>
<pre id="test">
</pre>
<script type="application/javascript">
/** Test for Bug 1083587 **/
var hostInDoc = document.getElementById("host");
var shadowOne = hostInDoc.createShadowRoot();
is(shadowOne.host, hostInDoc);
var shadowTwo = hostInDoc.createShadowRoot();
is(shadowOne.host, hostInDoc);
is(shadowTwo.host, hostInDoc);
var hostNotInDoc = document.createElement("div");
var shadowThree = hostNotInDoc.createShadowRoot();
is(shadowThree.host, hostNotInDoc);
var shadowFour = hostNotInDoc.createShadowRoot();
is(shadowThree.host, hostNotInDoc);
is(shadowFour.host, hostNotInDoc);
</script>
</body>
</html>

View File

@ -0,0 +1,41 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1083587
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1083587</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1083587">Mozilla Bug 1083587</a>
<p id="display"></p>
<div id="content" style="display: none">
<div id="host"></div>
</div>
<pre id="test">
</pre>
<script type="application/javascript">
/** Test for Bug 1083587 **/
var hostInDoc = document.getElementById("host");
var shadowOne = hostInDoc.createShadowRoot();
is(shadowOne.olderShadowRoot, null);
var shadowTwo = hostInDoc.createShadowRoot();
is(shadowOne.olderShadowRoot, null);
is(shadowTwo.olderShadowRoot, shadowOne);
var hostNotInDoc = document.createElement("div");
var shadowThree = hostNotInDoc.createShadowRoot();
is(shadowThree.olderShadowRoot, null);
var shadowFour = hostNotInDoc.createShadowRoot();
is(shadowThree.olderShadowRoot, null);
is(shadowFour.olderShadowRoot, shadowThree);
</script>
</body>
</html>

View File

@ -19,6 +19,8 @@ interface ShadowRoot : DocumentFragment
HTMLCollection getElementsByClassName(DOMString classNames);
[SetterThrows,TreatNullAs=EmptyString]
attribute DOMString innerHTML;
readonly attribute Element host;
readonly attribute ShadowRoot? olderShadowRoot;
attribute boolean applyAuthorStyles;
readonly attribute StyleSheetList styleSheets;
};

View File

@ -1,5 +0,0 @@
[test-014.html]
type: testharness
[ShadowRoot.olderShadowRoot_T01]
expected: FAIL