зеркало из https://github.com/mozilla/gecko-dev.git
Remove InspectorCSSUtils, part 1: Move GetStyleContextForContent to nsComputedDOMStyle. (Bug 371655) r=bzbarsky
This commit is contained in:
Родитель
863d371153
Коммит
8befa369a6
|
@ -65,7 +65,7 @@
|
||||||
|
|
||||||
#include "nsICSSParser.h"
|
#include "nsICSSParser.h"
|
||||||
#include "nsICSSStyleRule.h"
|
#include "nsICSSStyleRule.h"
|
||||||
#include "nsInspectorCSSUtils.h"
|
#include "nsComputedDOMStyle.h"
|
||||||
#include "nsStyleSet.h"
|
#include "nsStyleSet.h"
|
||||||
|
|
||||||
#include "nsPrintfCString.h"
|
#include "nsPrintfCString.h"
|
||||||
|
@ -1928,7 +1928,7 @@ nsCanvasRenderingContext2D::SetFont(const nsAString& font)
|
||||||
|
|
||||||
if (content && content->IsInDoc()) {
|
if (content && content->IsInDoc()) {
|
||||||
// inherit from the canvas element
|
// inherit from the canvas element
|
||||||
parentContext = nsInspectorCSSUtils::GetStyleContextForContent(
|
parentContext = nsComputedDOMStyle::GetStyleContextForContent(
|
||||||
content,
|
content,
|
||||||
nsnull,
|
nsnull,
|
||||||
presShell);
|
presShell);
|
||||||
|
@ -2273,9 +2273,9 @@ nsCanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,
|
||||||
if (content && content->IsInDoc()) {
|
if (content && content->IsInDoc()) {
|
||||||
// try to find the closest context
|
// try to find the closest context
|
||||||
nsRefPtr<nsStyleContext> canvasStyle =
|
nsRefPtr<nsStyleContext> canvasStyle =
|
||||||
nsInspectorCSSUtils::GetStyleContextForContent(content,
|
nsComputedDOMStyle::GetStyleContextForContent(content,
|
||||||
nsnull,
|
nsnull,
|
||||||
presShell);
|
presShell);
|
||||||
if (!canvasStyle)
|
if (!canvasStyle)
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
isRTL = canvasStyle->GetStyleVisibility()->mDirection ==
|
isRTL = canvasStyle->GetStyleVisibility()->mDirection ==
|
||||||
|
|
|
@ -70,7 +70,6 @@
|
||||||
#include "nsCSSPseudoElements.h"
|
#include "nsCSSPseudoElements.h"
|
||||||
#include "nsStyleSet.h"
|
#include "nsStyleSet.h"
|
||||||
#include "imgIRequest.h"
|
#include "imgIRequest.h"
|
||||||
#include "nsInspectorCSSUtils.h"
|
|
||||||
#include "nsLayoutUtils.h"
|
#include "nsLayoutUtils.h"
|
||||||
#include "nsFrameManager.h"
|
#include "nsFrameManager.h"
|
||||||
#include "prlog.h"
|
#include "prlog.h"
|
||||||
|
@ -324,6 +323,68 @@ nsComputedDOMStyle::GetPropertyValue(const nsAString& aPropertyName,
|
||||||
return rv;
|
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<nsStyleContext>
|
||||||
|
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<nsStyleContext> 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
|
NS_IMETHODIMP
|
||||||
nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName,
|
nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName,
|
||||||
|
@ -410,9 +471,9 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName,
|
||||||
#endif
|
#endif
|
||||||
// Need to resolve a style context
|
// Need to resolve a style context
|
||||||
mStyleContextHolder =
|
mStyleContextHolder =
|
||||||
nsInspectorCSSUtils::GetStyleContextForContent(mContent,
|
nsComputedDOMStyle::GetStyleContextForContent(mContent,
|
||||||
mPseudo,
|
mPseudo,
|
||||||
mPresShell);
|
mPresShell);
|
||||||
NS_ENSURE_TRUE(mStyleContextHolder, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(mStyleContextHolder, NS_ERROR_OUT_OF_MEMORY);
|
||||||
NS_ASSERTION(mPseudo || !mStyleContextHolder->HasPseudoElementData(),
|
NS_ASSERTION(mPseudo || !mStyleContextHolder->HasPseudoElementData(),
|
||||||
"should not have pseudo-element data");
|
"should not have pseudo-element data");
|
||||||
|
|
|
@ -82,6 +82,10 @@ public:
|
||||||
return mContent;
|
return mContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static already_AddRefed<nsStyleContext>
|
||||||
|
GetStyleContextForContent(nsIContent* aContent, nsIAtom* aPseudo,
|
||||||
|
nsIPresShell* aPresShell);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AssertFlushedPendingReflows() {
|
void AssertFlushedPendingReflows() {
|
||||||
NS_ASSERTION(mFlushedPendingReflows,
|
NS_ASSERTION(mFlushedPendingReflows,
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
#include "nsIDOMElement.h"
|
#include "nsIDOMElement.h"
|
||||||
#include "nsIMutableArray.h"
|
#include "nsIMutableArray.h"
|
||||||
#include "nsBindingManager.h"
|
#include "nsBindingManager.h"
|
||||||
|
#include "nsComputedDOMStyle.h"
|
||||||
|
|
||||||
nsInspectorCSSUtils::nsInspectorCSSUtils()
|
nsInspectorCSSUtils::nsInspectorCSSUtils()
|
||||||
{
|
{
|
||||||
|
@ -96,70 +97,6 @@ nsInspectorCSSUtils::IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot)
|
||||||
return NS_OK;
|
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<nsStyleContext>
|
|
||||||
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<nsStyleContext> 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
|
NS_IMETHODIMP
|
||||||
nsInspectorCSSUtils::GetRuleNodeForContent(nsIContent* aContent,
|
nsInspectorCSSUtils::GetRuleNodeForContent(nsIContent* aContent,
|
||||||
nsRuleNode** aRuleNode)
|
nsRuleNode** aRuleNode)
|
||||||
|
@ -173,7 +110,8 @@ nsInspectorCSSUtils::GetRuleNodeForContent(nsIContent* aContent,
|
||||||
NS_ENSURE_TRUE(presShell, NS_ERROR_UNEXPECTED);
|
NS_ENSURE_TRUE(presShell, NS_ERROR_UNEXPECTED);
|
||||||
|
|
||||||
nsRefPtr<nsStyleContext> sContext =
|
nsRefPtr<nsStyleContext> sContext =
|
||||||
GetStyleContextForContent(aContent, nsnull, presShell);
|
nsComputedDOMStyle::GetStyleContextForContent(aContent, nsnull,
|
||||||
|
presShell);
|
||||||
*aRuleNode = sContext->GetRuleNode();
|
*aRuleNode = sContext->GetRuleNode();
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,13 +65,6 @@ public:
|
||||||
NS_IMETHOD GetRuleNodeForContent(nsIContent* aContent,
|
NS_IMETHOD GetRuleNodeForContent(nsIContent* aContent,
|
||||||
nsRuleNode** aRuleNode);
|
nsRuleNode** aRuleNode);
|
||||||
NS_IMETHOD GetBindingURLs(nsIDOMElement *aElement, nsIArray **aResult);
|
NS_IMETHOD GetBindingURLs(nsIDOMElement *aElement, nsIArray **aResult);
|
||||||
|
|
||||||
static already_AddRefed<nsStyleContext>
|
|
||||||
GetStyleContextForContent(nsIContent* aContent, nsIAtom* aPseudo,
|
|
||||||
nsIPresShell* aPresShell);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static nsStyleContext* GetStyleContextForFrame(nsIFrame* aFrame);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* nsInspectorCSSUtils_h___ */
|
#endif /* nsInspectorCSSUtils_h___ */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче