From d53b9edd1db67a65ed249491aac568c7f6065cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 31 Jul 2019 19:26:32 +0200 Subject: [PATCH] Bug 1404140 - Factor out getting the outer and inner frame. r=heycam Differential Revision: https://phabricator.services.mozilla.com/D40296 --- layout/style/nsComputedDOMStyle.cpp | 66 ++++++++++++++++------------- layout/style/nsComputedDOMStyle.h | 1 + 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index f0aebce35c91..a480daba2391 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -787,6 +787,40 @@ bool nsComputedDOMStyle::NeedsToFlushStyle() const { return false; } +static nsIFrame* StyleFrame(nsIFrame* aOuterFrame) { + MOZ_ASSERT(aOuterFrame); + if (!aOuterFrame->IsTableWrapperFrame()) { + return aOuterFrame; + } + // If the frame is a table wrapper frame then we should get the style from the + // inner table frame. + nsIFrame* inner = aOuterFrame->PrincipalChildList().FirstChild(); + NS_ASSERTION(inner, "table wrapper must have an inner"); + NS_ASSERTION(!inner->GetNextSibling(), + "table wrapper frames should have just one child, the inner " + "table"); + return inner; +} + +nsIFrame* nsComputedDOMStyle::GetOuterFrame() const { + if (!mPseudo) { + return mElement->GetPrimaryFrame(); + } + nsAtom* property = nullptr; + if (mPseudo == nsCSSPseudoElements::before()) { + property = nsGkAtoms::beforePseudoProperty; + } else if (mPseudo == nsCSSPseudoElements::after()) { + property = nsGkAtoms::afterPseudoProperty; + } else if (mPseudo == nsCSSPseudoElements::marker()) { + property = nsGkAtoms::markerPseudoProperty; + } + if (!property) { + return nullptr; + } + auto* pseudo = static_cast(mElement->GetProperty(property)); + return pseudo ? pseudo->GetPrimaryFrame() : nullptr; +} + void nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush) { nsCOMPtr document = do_QueryReferent(mDocumentWeak); if (!document) { @@ -862,38 +896,10 @@ void nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush) { // check is needed due to bug 135040 (to avoid using // mPrimaryFrame). Remove it once that's fixed. if (mStyleType == eAll && !mElement->IsHTMLElement(nsGkAtoms::area)) { - mOuterFrame = nullptr; - - if (!mPseudo) { - mOuterFrame = mElement->GetPrimaryFrame(); - } else { - nsAtom* property = nullptr; - if (mPseudo == nsCSSPseudoElements::before()) { - property = nsGkAtoms::beforePseudoProperty; - } else if (mPseudo == nsCSSPseudoElements::after()) { - property = nsGkAtoms::afterPseudoProperty; - } else if (mPseudo == nsCSSPseudoElements::marker()) { - property = nsGkAtoms::markerPseudoProperty; - } - if (property) { - auto* pseudo = static_cast(mElement->GetProperty(property)); - mOuterFrame = pseudo ? pseudo->GetPrimaryFrame() : nullptr; - } - } - + mOuterFrame = GetOuterFrame(); mInnerFrame = mOuterFrame; if (mOuterFrame) { - LayoutFrameType type = mOuterFrame->Type(); - if (type == LayoutFrameType::TableWrapper) { - // If the frame is a table wrapper frame then we should get the style - // from the inner table frame. - mInnerFrame = mOuterFrame->PrincipalChildList().FirstChild(); - NS_ASSERTION(mInnerFrame, "table wrapper must have an inner"); - NS_ASSERTION(!mInnerFrame->GetNextSibling(), - "table wrapper frames should have just one child, " - "the inner table"); - } - + mInnerFrame = StyleFrame(mOuterFrame); SetFrameComputedStyle(mInnerFrame->Style(), currentGeneration); NS_ASSERTION(mComputedStyle, "Frame without style?"); } diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h index af4cc39e19cd..0c34d1d1d5ec 100644 --- a/layout/style/nsComputedDOMStyle.h +++ b/layout/style/nsComputedDOMStyle.h @@ -340,6 +340,7 @@ class nsComputedDOMStyle final : public nsDOMCSSDeclaration, // Find out if we can safely skip flushing (i.e. pending restyles do not // affect our element). bool NeedsToFlushStyle() const; + nsIFrame* GetOuterFrame() const; static ComputedStyleMap* GetComputedStyleMap();