From de45820b64ab03768336c7242622ef9f499347cf Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Thu, 16 Apr 2020 20:19:06 -0400 Subject: Bug 1346623 - Allow anonymous content created with nsIDocument::InsertAnonymousContent can change from non-native to native AC * Prevent canvas custom content from becoming NAC when reframing the root element * Add an API to get computed style values through an AnonymousContent object Tag #1375 --- layout/base/nsCSSFrameConstructor.cpp | 23 ++++++++-- layout/style/test/chrome/chrome.ini | 1 + layout/style/test/chrome/test_bug1346623.html | 60 +++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 layout/style/test/chrome/test_bug1346623.html (limited to 'layout') diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 374764203..3be7c2a0b 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -4192,13 +4192,28 @@ nsCSSFrameConstructor::GetAnonymousContent(nsIContent* aParent, ConnectAnonymousTreeDescendants(content, aContent[i].mChildren); - // least-surprise CSS binding until we do the SVG specified - // cascading rules for - bug 265894 - if (aParentFrame->GetType() == nsGkAtoms::svgUseFrame) { + nsIAtom* parentFrameType = aParentFrame->GetType(); + if (parentFrameType == nsGkAtoms::svgUseFrame) { + // least-surprise CSS binding until we do the SVG specified + // cascading rules for - bug 265894 content->SetFlags(NODE_IS_ANONYMOUS_ROOT); } else { content->SetIsNativeAnonymousRoot(); - SetNativeAnonymousBitOnDescendants(content); + // Don't mark descendants of the custom content container + // as native anonymous. When canvas custom content is initially + // created and appended to the custom content container, in + // nsIDocument::InsertAnonymousContent, it is not considered native + // anonymous content. But if we end up reframing the root element, + // we will re-create the nsCanvasFrame, and we would end up in here, + // marking it as NAC. Existing uses of canvas custom content would + // break if it becomes NAC (since each element starts inheriting + // styles from its closest non-NAC ancestor, rather than from its + // parent). + if (!(parentFrameType == nsGkAtoms::canvasFrame && + content == static_cast(aParentFrame) + ->GetCustomContentContainer())) { + SetNativeAnonymousBitOnDescendants(content); + } } bool anonContentIsEditable = content->HasFlag(NODE_IS_EDITABLE); diff --git a/layout/style/test/chrome/chrome.ini b/layout/style/test/chrome/chrome.ini index e34fce671..dd3bdf8f5 100644 --- a/layout/style/test/chrome/chrome.ini +++ b/layout/style/test/chrome/chrome.ini @@ -10,6 +10,7 @@ support-files = mismatch.png [test_author_specified_style.html] +[test_bug1346623.html] [test_bug418986-2.xul] [test_bug1157097.html] [test_bug1160724.xul] diff --git a/layout/style/test/chrome/test_bug1346623.html b/layout/style/test/chrome/test_bug1346623.html new file mode 100644 index 000000000..d24d66646 --- /dev/null +++ b/layout/style/test/chrome/test_bug1346623.html @@ -0,0 +1,60 @@ + + + + Test for bug 1346623 + + + + + +Mozilla Bug 1346623 +
+ +
+
+
+
+ + -- cgit v1.2.3