Unify SVG parent checks for LayoutObject construction using always the light tree parent. This is the last cleanup spawned from [1]. I've used the light tree parent because there are a lot of other checks that are wrong, as noted in that discussion, and updating all those and ensuring it's correct is a fair amount of work. This patch ensures we're consistent, and that there's only one place to change if we want to change the isLayoutObjectNeeded check to use the flat tree. [1]: https://codereview.chromium.org/2684833003/ Review-Url: https://codereview.chromium.org/2688343002 Cr-Commit-Position: refs/heads/master@{#449893}
diff --git a/third_party/WebKit/Source/core/svg/SVGElement.cpp b/third_party/WebKit/Source/core/svg/SVGElement.cpp index 961d67e..d6b1fec8 100644 --- a/third_party/WebKit/Source/core/svg/SVGElement.cpp +++ b/third_party/WebKit/Source/core/svg/SVGElement.cpp
@@ -1027,18 +1027,14 @@ } bool SVGElement::layoutObjectIsNeeded(const ComputedStyle& style) { - // SVG elements only render when inside <svg>, or if the element is an <svg> - // itself. - if (!isSVGSVGElement(*this)) { - ContainerNode* parent = FlatTreeTraversal::parent(*this); - if (!parent || !parent->isSVGElement()) - return false; - } + return isValid() && hasSVGParent() && Element::layoutObjectIsNeeded(style); +} - if (!isValid()) - return false; - - return Element::layoutObjectIsNeeded(style); +bool SVGElement::hasSVGParent() const { + // Should we use the flat tree parent instead? If so, we should probably fix a + // few other checks. + return parentOrShadowHostElement() && + parentOrShadowHostElement()->isSVGElement(); } MutableStylePropertySet* SVGElement::animatedSMILStyleProperties() const {
diff --git a/third_party/WebKit/Source/core/svg/SVGElement.h b/third_party/WebKit/Source/core/svg/SVGElement.h index 22a6c1e..bc0f6355 100644 --- a/third_party/WebKit/Source/core/svg/SVGElement.h +++ b/third_party/WebKit/Source/core/svg/SVGElement.h
@@ -236,6 +236,8 @@ virtual bool selfHasRelativeLengths() const { return false; } + bool hasSVGParent() const; + SVGElementRareData* ensureSVGRareData(); inline bool hasSVGRareData() const { return m_SVGRareData; } inline SVGElementRareData* svgRareData() const {
diff --git a/third_party/WebKit/Source/core/svg/SVGGElement.cpp b/third_party/WebKit/Source/core/svg/SVGGElement.cpp index 3198284c..1d5541a 100644 --- a/third_party/WebKit/Source/core/svg/SVGGElement.cpp +++ b/third_party/WebKit/Source/core/svg/SVGGElement.cpp
@@ -48,8 +48,7 @@ // Unlike SVGElement::layoutObjectIsNeeded(), we still create layoutObjects, // even if display is set to 'none' - which is special to SVG <g> container // elements. - return parentOrShadowHostElement() && - parentOrShadowHostElement()->isSVGElement() && isValid(); + return isValid() && hasSVGParent(); } } // namespace blink
diff --git a/third_party/WebKit/Source/core/svg/SVGMarkerElement.cpp b/third_party/WebKit/Source/core/svg/SVGMarkerElement.cpp index f44a077..1925c5d 100644 --- a/third_party/WebKit/Source/core/svg/SVGMarkerElement.cpp +++ b/third_party/WebKit/Source/core/svg/SVGMarkerElement.cpp
@@ -159,8 +159,7 @@ } bool SVGMarkerElement::layoutObjectIsNeeded(const ComputedStyle&) { - ContainerNode* parent = FlatTreeTraversal::parent(*this); - return parent && parent->isSVGElement() && isValid(); + return isValid() && hasSVGParent(); } } // namespace blink
diff --git a/third_party/WebKit/Source/core/svg/SVGSVGElement.cpp b/third_party/WebKit/Source/core/svg/SVGSVGElement.cpp index 7b4c270..79dcc61 100644 --- a/third_party/WebKit/Source/core/svg/SVGSVGElement.cpp +++ b/third_party/WebKit/Source/core/svg/SVGSVGElement.cpp
@@ -510,7 +510,10 @@ // https://bugs.webkit.org/show_bug.cgi?id=103493 if (document().documentElement() == this) return true; - return SVGElement::layoutObjectIsNeeded(style); + + // <svg> elements don't need an SVG parent to render, so we bypass + // SVGElement::layoutObjectIsNeeded. + return isValid() && Element::layoutObjectIsNeeded(style); } LayoutObject* SVGSVGElement::createLayoutObject(const ComputedStyle&) {