Bug 1659457 - Do clone xml-pretty-printer's UA widget. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D87714
This commit is contained in:
Emilio Cobos Álvarez 2020-08-20 11:29:45 +00:00
Родитель cd26f4e727
Коммит 54b5a9f5f5
8 изменённых файлов: 42 добавлений и 4 удалений

Просмотреть файл

@ -50,7 +50,8 @@ ShadowRoot::ShadowRoot(Element* aElement, ShadowRootMode aMode,
: DocumentFragment(std::move(aNodeInfo)),
DocumentOrShadowRoot(this),
mMode(aMode),
mIsUAWidget(false) {
mIsUAWidget(false),
mIsStaticUAWidget(false) {
SetHost(aElement);
// Nodes in a shadow tree should never store a value
@ -95,7 +96,14 @@ JSObject* ShadowRoot::WrapNode(JSContext* aCx,
}
void ShadowRoot::CloneInternalDataFrom(ShadowRoot* aOther) {
MOZ_ASSERT(!aOther->IsUAWidget());
MOZ_ASSERT(aOther->ShouldStaticClone());
if (aOther->IsUAWidget()) {
SetIsUAWidget();
}
if (aOther->IsStaticUAWidget()) {
SetIsStaticUAWidget();
}
size_t sheetCount = aOther->SheetCount();
for (size_t i = 0; i < sheetCount; ++i) {

Просмотреть файл

@ -105,6 +105,9 @@ class ShadowRoot final : public DocumentFragment,
nsresult Bind();
private:
bool IsStaticUAWidget() const { return mIsStaticUAWidget; }
void InsertSheetIntoAuthorData(size_t aIndex, StyleSheet&,
const nsTArray<RefPtr<StyleSheet>>&);
@ -200,12 +203,24 @@ class ShadowRoot final : public DocumentFragment,
bool IsUAWidget() const { return mIsUAWidget; }
// Whether we should clone this shadow root for printing. We usually don't
// clone UA widgets (because they're attached and setup on bind), but we need
// to clone "static" UA widgets, which don't.
bool ShouldStaticClone() const {
return !IsUAWidget() || IsStaticUAWidget();
}
void SetIsUAWidget() {
MOZ_ASSERT(!HasChildren());
SetFlags(NODE_HAS_BEEN_IN_UA_WIDGET);
mIsUAWidget = true;
}
void SetIsStaticUAWidget() {
MOZ_ASSERT(IsUAWidget());
mIsStaticUAWidget = true;
}
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
// nsIRadioGroupContainer
@ -274,7 +289,10 @@ class ShadowRoot final : public DocumentFragment,
// tree.
nsTArray<const Element*> mParts;
bool mIsUAWidget;
bool mIsUAWidget : 1;
// Whether this shadow root is "static" and should be cloned for static
// documents.
bool mIsStaticUAWidget : 1;
nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
};

Просмотреть файл

@ -3305,7 +3305,7 @@ already_AddRefed<nsINode> nsINode::CloneAndAdopt(
// Clone the Shadow DOM
ShadowRoot* originalShadowRoot = aNode->AsElement()->GetShadowRoot();
if (originalShadowRoot && !originalShadowRoot->IsUAWidget()) {
if (originalShadowRoot && originalShadowRoot->ShouldStaticClone()) {
RefPtr<ShadowRoot> newShadowRoot =
clone->AsElement()->AttachShadowWithoutNameChecks(
originalShadowRoot->Mode());

Просмотреть файл

@ -89,6 +89,7 @@ nsresult nsXMLPrettyPrinter::PrettyPrint(Document* aDocument,
RefPtr<ShadowRoot> shadowRoot = rootElement->GetShadowRoot();
MOZ_RELEASE_ASSERT(shadowRoot && shadowRoot->IsUAWidget(),
"There should be a UA Shadow Root here.");
shadowRoot->SetIsStaticUAWidget();
// Append the document fragment to the shadow dom.
shadowRoot->AppendChild(*resultFragment, err);

Просмотреть файл

@ -27,6 +27,8 @@ support-files =
printpreview_images_sw.html
printpreview_images_sw_ref.html
printpreview_images_sw.js
printpreview_prettyprint.xml
printpreview_prettyprint_ref.xhtml
color_adjust.html
color_adjust_ref.html
test_document_adopted_styles.html

Просмотреть файл

@ -636,6 +636,11 @@ async function runTest22() {
exitprintpreview();
}
requestAnimationFrame(() => setTimeout(runTest23));
}
async function runTest23() {
await compareFiles("printpreview_prettyprint.xml", "printpreview_prettyprint_ref.xhtml");
finish();
}

Просмотреть файл

@ -0,0 +1 @@
<out>Here be sea hags</out>

Просмотреть файл

@ -0,0 +1,3 @@
<out><div id="top" xmlns="http://www.w3.org/1999/xhtml"><link href="chrome://global/content/xml/XMLPrettyPrint.css" type="text/css" rel="stylesheet"/><div id="header"><p>
This XML file does not appear to have any style information associated with it. The document tree is shown below.
</p></div><main id="tree" class="highlight"><div>&lt;<span class="start-tag">out</span>&gt;<span class="text">Here be sea hags</span>&lt;/<span class="end-tag">out</span>&gt;</div></main></div></out>