From e7d6f144d1a946dcd5ff6af54a2f7df2db88fa52 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Fri, 19 Apr 2002 22:29:24 +0000 Subject: [PATCH] Fix the "style rules" display for display:table elements. Bug 122557, r=caillon, sr=hewitt git-svn-id: svn://10.0.0.236/trunk@119428 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/style/src/nsIInspectorCSSUtils.h | 8 +++++ .../html/style/src/nsInspectorCSSUtils.cpp | 30 +++++++++++++++++++ .../html/style/src/nsInspectorCSSUtils.h | 4 ++- .../inspector/base/src/inDOMUtils.cpp | 9 +++--- mozilla/layout/style/nsIInspectorCSSUtils.h | 8 +++++ mozilla/layout/style/nsInspectorCSSUtils.cpp | 30 +++++++++++++++++++ mozilla/layout/style/nsInspectorCSSUtils.h | 4 ++- 7 files changed, 86 insertions(+), 7 deletions(-) diff --git a/mozilla/content/html/style/src/nsIInspectorCSSUtils.h b/mozilla/content/html/style/src/nsIInspectorCSSUtils.h index e10894a93ca..8f59b1f3ab2 100644 --- a/mozilla/content/html/style/src/nsIInspectorCSSUtils.h +++ b/mozilla/content/html/style/src/nsIInspectorCSSUtils.h @@ -46,6 +46,9 @@ class nsRuleNode; class nsIStyleRule; class nsIFrame; struct nsRect; +class nsIPresShell; +class nsIContent; +class nsIStyleContext; // 0252892b-419a-49f4-981d-4c6716099451 #define NS_IINSPECTORCSSUTILS_IID \ @@ -74,6 +77,11 @@ public: // Hooks to avoid having to use nsStyleCoord. NS_IMETHOD AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect) = 0; + + // Hooks to methods that need layout atoms (static vars in layout) + NS_IMETHOD GetStyleContextForContent(nsIPresShell* aPresShell, + nsIContent* aContent, + nsIStyleContext** aStyleContext) = 0; }; #endif /* nsIInspectorCSSUtils_h___ */ diff --git a/mozilla/content/html/style/src/nsInspectorCSSUtils.cpp b/mozilla/content/html/style/src/nsInspectorCSSUtils.cpp index d03b8c749ea..d0e1b85ad61 100644 --- a/mozilla/content/html/style/src/nsInspectorCSSUtils.cpp +++ b/mozilla/content/html/style/src/nsInspectorCSSUtils.cpp @@ -40,6 +40,7 @@ #include "nsInspectorCSSUtils.h" #include "nsRuleNode.h" #include "nsString.h" +#include "nsLayoutAtoms.h" nsInspectorCSSUtils::nsInspectorCSSUtils() { @@ -111,3 +112,32 @@ nsInspectorCSSUtils::AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect) return NS_OK; } +NS_IMETHODIMP +nsInspectorCSSUtils::GetStyleContextForContent(nsIPresShell* aPresShell, + nsIContent* aContent, + nsIStyleContext** aStyleContext) +{ + NS_PRECONDITION(aPresShell, "Null pres shell"); + + nsIFrame* frame = nsnull; + nsresult rv = aPresShell->GetPrimaryFrameFor(aContent, &frame); + if (NS_FAILED(rv) || !frame) return rv; + + /* 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 hierarchy.... + */ + nsCOMPtr frameType; + frame->GetFrameType(getter_AddRefs(frameType)); + if (frameType == nsLayoutAtoms::tableOuterFrame) { + nsCOMPtr presContext; + rv = aPresShell->GetPresContext(getter_AddRefs(presContext)); + if (! presContext) + return rv; + PRBool isChild; + rv = frame->GetParentStyleContextFrame(presContext, &frame, &isChild); + if (NS_FAILED(rv) || !frame) return rv; + } + return aPresShell->GetStyleContextFor(frame, aStyleContext); +} diff --git a/mozilla/content/html/style/src/nsInspectorCSSUtils.h b/mozilla/content/html/style/src/nsInspectorCSSUtils.h index 0ff484174a1..5daed8a8e66 100644 --- a/mozilla/content/html/style/src/nsInspectorCSSUtils.h +++ b/mozilla/content/html/style/src/nsInspectorCSSUtils.h @@ -57,7 +57,9 @@ public: NS_IMETHOD GetRuleNodeRule(nsRuleNode *aNode, nsIStyleRule **aRule); NS_IMETHOD IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot); NS_IMETHOD AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect); - + NS_IMETHOD GetStyleContextForContent(nsIPresShell* aPresShell, + nsIContent* aContent, + nsIStyleContext** aStyleContext); }; #endif /* nsInspectorCSSUtils_h___ */ diff --git a/mozilla/extensions/inspector/base/src/inDOMUtils.cpp b/mozilla/extensions/inspector/base/src/inDOMUtils.cpp index 002d1df8d46..f6ced0b3d30 100644 --- a/mozilla/extensions/inspector/base/src/inDOMUtils.cpp +++ b/mozilla/extensions/inspector/base/src/inDOMUtils.cpp @@ -86,12 +86,11 @@ inDOMUtils::GetStyleRules(nsIDOMElement *aElement, nsISupportsArray **_retval) // query to a content node nsCOMPtr content; content = do_QueryInterface(aElement); - - nsIFrame* frame = nsnull; nsCOMPtr styleContext; - nsresult rv = shell->GetPrimaryFrameFor(content, &frame); - if (NS_FAILED(rv) || !frame) return rv; - shell->GetStyleContextFor(frame, getter_AddRefs(styleContext)); + + nsresult rv = mCSSUtils->GetStyleContextForContent(shell, content, + getter_AddRefs(styleContext)); + if (NS_FAILED(rv) || !styleContext) return rv; // create a resource for all the style rules from the diff --git a/mozilla/layout/style/nsIInspectorCSSUtils.h b/mozilla/layout/style/nsIInspectorCSSUtils.h index e10894a93ca..8f59b1f3ab2 100644 --- a/mozilla/layout/style/nsIInspectorCSSUtils.h +++ b/mozilla/layout/style/nsIInspectorCSSUtils.h @@ -46,6 +46,9 @@ class nsRuleNode; class nsIStyleRule; class nsIFrame; struct nsRect; +class nsIPresShell; +class nsIContent; +class nsIStyleContext; // 0252892b-419a-49f4-981d-4c6716099451 #define NS_IINSPECTORCSSUTILS_IID \ @@ -74,6 +77,11 @@ public: // Hooks to avoid having to use nsStyleCoord. NS_IMETHOD AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect) = 0; + + // Hooks to methods that need layout atoms (static vars in layout) + NS_IMETHOD GetStyleContextForContent(nsIPresShell* aPresShell, + nsIContent* aContent, + nsIStyleContext** aStyleContext) = 0; }; #endif /* nsIInspectorCSSUtils_h___ */ diff --git a/mozilla/layout/style/nsInspectorCSSUtils.cpp b/mozilla/layout/style/nsInspectorCSSUtils.cpp index d03b8c749ea..d0e1b85ad61 100644 --- a/mozilla/layout/style/nsInspectorCSSUtils.cpp +++ b/mozilla/layout/style/nsInspectorCSSUtils.cpp @@ -40,6 +40,7 @@ #include "nsInspectorCSSUtils.h" #include "nsRuleNode.h" #include "nsString.h" +#include "nsLayoutAtoms.h" nsInspectorCSSUtils::nsInspectorCSSUtils() { @@ -111,3 +112,32 @@ nsInspectorCSSUtils::AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect) return NS_OK; } +NS_IMETHODIMP +nsInspectorCSSUtils::GetStyleContextForContent(nsIPresShell* aPresShell, + nsIContent* aContent, + nsIStyleContext** aStyleContext) +{ + NS_PRECONDITION(aPresShell, "Null pres shell"); + + nsIFrame* frame = nsnull; + nsresult rv = aPresShell->GetPrimaryFrameFor(aContent, &frame); + if (NS_FAILED(rv) || !frame) return rv; + + /* 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 hierarchy.... + */ + nsCOMPtr frameType; + frame->GetFrameType(getter_AddRefs(frameType)); + if (frameType == nsLayoutAtoms::tableOuterFrame) { + nsCOMPtr presContext; + rv = aPresShell->GetPresContext(getter_AddRefs(presContext)); + if (! presContext) + return rv; + PRBool isChild; + rv = frame->GetParentStyleContextFrame(presContext, &frame, &isChild); + if (NS_FAILED(rv) || !frame) return rv; + } + return aPresShell->GetStyleContextFor(frame, aStyleContext); +} diff --git a/mozilla/layout/style/nsInspectorCSSUtils.h b/mozilla/layout/style/nsInspectorCSSUtils.h index 0ff484174a1..5daed8a8e66 100644 --- a/mozilla/layout/style/nsInspectorCSSUtils.h +++ b/mozilla/layout/style/nsInspectorCSSUtils.h @@ -57,7 +57,9 @@ public: NS_IMETHOD GetRuleNodeRule(nsRuleNode *aNode, nsIStyleRule **aRule); NS_IMETHOD IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot); NS_IMETHOD AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect); - + NS_IMETHOD GetStyleContextForContent(nsIPresShell* aPresShell, + nsIContent* aContent, + nsIStyleContext** aStyleContext); }; #endif /* nsInspectorCSSUtils_h___ */