From 2a59bf895db07e07c2d6197e86c841c7d082f9ca Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Thu, 16 Mar 2017 17:43:44 +0800 Subject: [PATCH] Bug 1346623 - Part 1: Prevent canvas custom content from becoming NAC when reframing the root element. r=bholley MozReview-Commit-ID: K7jcUuz6KI4 --HG-- extra : rebase_source : 85c2939b020e7d4b401382c0d436f16c5af98b5e --- layout/base/nsCSSFrameConstructor.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 3f424d47ab45..fd6168f16b55 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -4243,13 +4243,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);