From 4e795fd4c0d13dd0efee001416aa4ea443198fa3 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Mon, 10 Aug 2009 15:52:29 -0700 Subject: [PATCH] Remove InspectorCSSUtils, part 1: Move GetStyleContextForContent to nsComputedDOMStyle. (Bug 371655) r=bzbarsky --- .../canvas/src/nsCanvasRenderingContext2D.cpp | 10 +-- layout/style/nsComputedDOMStyle.cpp | 69 +++++++++++++++++-- layout/style/nsComputedDOMStyle.h | 4 ++ layout/style/nsInspectorCSSUtils.cpp | 68 +----------------- layout/style/nsInspectorCSSUtils.h | 7 -- 5 files changed, 77 insertions(+), 81 deletions(-) diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index ac1ca2990817..e05d22922380 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -65,7 +65,7 @@ #include "nsICSSParser.h" #include "nsICSSStyleRule.h" -#include "nsInspectorCSSUtils.h" +#include "nsComputedDOMStyle.h" #include "nsStyleSet.h" #include "nsPrintfCString.h" @@ -1928,7 +1928,7 @@ nsCanvasRenderingContext2D::SetFont(const nsAString& font) if (content && content->IsInDoc()) { // inherit from the canvas element - parentContext = nsInspectorCSSUtils::GetStyleContextForContent( + parentContext = nsComputedDOMStyle::GetStyleContextForContent( content, nsnull, presShell); @@ -2273,9 +2273,9 @@ nsCanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText, if (content && content->IsInDoc()) { // try to find the closest context nsRefPtr canvasStyle = - nsInspectorCSSUtils::GetStyleContextForContent(content, - nsnull, - presShell); + nsComputedDOMStyle::GetStyleContextForContent(content, + nsnull, + presShell); if (!canvasStyle) return NS_ERROR_FAILURE; isRTL = canvasStyle->GetStyleVisibility()->mDirection == diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 9d74acb3fe63..3cf303d8532b 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -70,7 +70,6 @@ #include "nsCSSPseudoElements.h" #include "nsStyleSet.h" #include "imgIRequest.h" -#include "nsInspectorCSSUtils.h" #include "nsLayoutUtils.h" #include "nsFrameManager.h" #include "prlog.h" @@ -324,6 +323,68 @@ nsComputedDOMStyle::GetPropertyValue(const nsAString& aPropertyName, return rv; } +static nsStyleContext* +GetStyleContextForFrame(nsIFrame* aFrame) +{ + nsStyleContext* styleContext = aFrame->GetStyleContext(); + + /* For tables the primary frame is the "outer frame" but the style + * rules are applied to the "inner frame". Luckily, the "outer + * frame" actually inherits style from the "inner frame" so we can + * just move one level up in the style context hierarchy.... + */ + if (aFrame->GetType() == nsGkAtoms::tableOuterFrame) + return styleContext->GetParent(); + + return styleContext; +} + +/* static */ +already_AddRefed +nsComputedDOMStyle::GetStyleContextForContent(nsIContent* aContent, + nsIAtom* aPseudo, + nsIPresShell* aPresShell) +{ + if (!aPseudo) { + aPresShell->FlushPendingNotifications(Flush_Style); + nsIFrame* frame = aPresShell->GetPrimaryFrameFor(aContent); + if (frame) { + nsStyleContext* result = GetStyleContextForFrame(frame); + // Don't use the style context if it was influenced by + // pseudo-elements, since then it's not the primary style + // for this element. + if (!result->HasPseudoElementData()) { + // this function returns an addrefed style context + result->AddRef(); + return result; + } + } + } + + // No frame has been created or we have a pseudo, so resolve the + // style ourselves + nsRefPtr parentContext; + nsIContent* parent = aPseudo ? aContent : aContent->GetParent(); + if (parent) + parentContext = GetStyleContextForContent(parent, nsnull, aPresShell); + + nsPresContext *presContext = aPresShell->GetPresContext(); + if (!presContext) + return nsnull; + + nsStyleSet *styleSet = aPresShell->StyleSet(); + + if (!aContent->IsNodeOfType(nsINode::eELEMENT)) { + NS_ASSERTION(!aPseudo, "Shouldn't have a pseudo for a non-element!"); + return styleSet->ResolveStyleForNonElement(parentContext); + } + + if (aPseudo) { + return styleSet->ResolvePseudoStyleFor(aContent, aPseudo, parentContext); + } + + return styleSet->ResolveStyleFor(aContent, parentContext); +} NS_IMETHODIMP nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName, @@ -410,9 +471,9 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName, #endif // Need to resolve a style context mStyleContextHolder = - nsInspectorCSSUtils::GetStyleContextForContent(mContent, - mPseudo, - mPresShell); + nsComputedDOMStyle::GetStyleContextForContent(mContent, + mPseudo, + mPresShell); NS_ENSURE_TRUE(mStyleContextHolder, NS_ERROR_OUT_OF_MEMORY); NS_ASSERTION(mPseudo || !mStyleContextHolder->HasPseudoElementData(), "should not have pseudo-element data"); diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h index 5ecc5ce249ab..fc1da6e4158f 100644 --- a/layout/style/nsComputedDOMStyle.h +++ b/layout/style/nsComputedDOMStyle.h @@ -82,6 +82,10 @@ public: return mContent; } + static already_AddRefed + GetStyleContextForContent(nsIContent* aContent, nsIAtom* aPseudo, + nsIPresShell* aPresShell); + private: void AssertFlushedPendingReflows() { NS_ASSERTION(mFlushedPendingReflows, diff --git a/layout/style/nsInspectorCSSUtils.cpp b/layout/style/nsInspectorCSSUtils.cpp index 6d2263101760..7d85c46d44e2 100644 --- a/layout/style/nsInspectorCSSUtils.cpp +++ b/layout/style/nsInspectorCSSUtils.cpp @@ -54,6 +54,7 @@ #include "nsIDOMElement.h" #include "nsIMutableArray.h" #include "nsBindingManager.h" +#include "nsComputedDOMStyle.h" nsInspectorCSSUtils::nsInspectorCSSUtils() { @@ -96,70 +97,6 @@ nsInspectorCSSUtils::IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot) return NS_OK; } -/* static */ -nsStyleContext* -nsInspectorCSSUtils::GetStyleContextForFrame(nsIFrame* aFrame) -{ - nsStyleContext* styleContext = aFrame->GetStyleContext(); - - /* For tables the primary frame is the "outer frame" but the style - * rules are applied to the "inner frame". Luckily, the "outer - * frame" actually inherits style from the "inner frame" so we can - * just move one level up in the style context hierarchy.... - */ - if (aFrame->GetType() == nsGkAtoms::tableOuterFrame) - return styleContext->GetParent(); - - return styleContext; -} - -/* static */ -already_AddRefed -nsInspectorCSSUtils::GetStyleContextForContent(nsIContent* aContent, - nsIAtom* aPseudo, - nsIPresShell* aPresShell) -{ - if (!aPseudo) { - aPresShell->FlushPendingNotifications(Flush_Style); - nsIFrame* frame = aPresShell->GetPrimaryFrameFor(aContent); - if (frame) { - nsStyleContext* result = GetStyleContextForFrame(frame); - // Don't use the style context if it was influenced by - // pseudo-elements, since then it's not the primary style - // for this element. - if (!result->HasPseudoElementData()) { - // this function returns an addrefed style context - result->AddRef(); - return result; - } - } - } - - // No frame has been created or we have a pseudo, so resolve the - // style ourselves - nsRefPtr parentContext; - nsIContent* parent = aPseudo ? aContent : aContent->GetParent(); - if (parent) - parentContext = GetStyleContextForContent(parent, nsnull, aPresShell); - - nsPresContext *presContext = aPresShell->GetPresContext(); - if (!presContext) - return nsnull; - - nsStyleSet *styleSet = aPresShell->StyleSet(); - - if (!aContent->IsNodeOfType(nsINode::eELEMENT)) { - NS_ASSERTION(!aPseudo, "Shouldn't have a pseudo for a non-element!"); - return styleSet->ResolveStyleForNonElement(parentContext); - } - - if (aPseudo) { - return styleSet->ResolvePseudoStyleFor(aContent, aPseudo, parentContext); - } - - return styleSet->ResolveStyleFor(aContent, parentContext); -} - NS_IMETHODIMP nsInspectorCSSUtils::GetRuleNodeForContent(nsIContent* aContent, nsRuleNode** aRuleNode) @@ -173,7 +110,8 @@ nsInspectorCSSUtils::GetRuleNodeForContent(nsIContent* aContent, NS_ENSURE_TRUE(presShell, NS_ERROR_UNEXPECTED); nsRefPtr sContext = - GetStyleContextForContent(aContent, nsnull, presShell); + nsComputedDOMStyle::GetStyleContextForContent(aContent, nsnull, + presShell); *aRuleNode = sContext->GetRuleNode(); return NS_OK; } diff --git a/layout/style/nsInspectorCSSUtils.h b/layout/style/nsInspectorCSSUtils.h index 37258bcd01a2..7dfe95011938 100644 --- a/layout/style/nsInspectorCSSUtils.h +++ b/layout/style/nsInspectorCSSUtils.h @@ -65,13 +65,6 @@ public: NS_IMETHOD GetRuleNodeForContent(nsIContent* aContent, nsRuleNode** aRuleNode); NS_IMETHOD GetBindingURLs(nsIDOMElement *aElement, nsIArray **aResult); - - static already_AddRefed - GetStyleContextForContent(nsIContent* aContent, nsIAtom* aPseudo, - nsIPresShell* aPresShell); - -private: - static nsStyleContext* GetStyleContextForFrame(nsIFrame* aFrame); }; #endif /* nsInspectorCSSUtils_h___ */