зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
cd26f4e727
Коммит
54b5a9f5f5
|
@ -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><<span class="start-tag">out</span>><span class="text">Here be sea hags</span></<span class="end-tag">out</span>></div></main></div></out>
|
Загрузка…
Ссылка в новой задаче