Fix the "style rules" display for display:table elements. Bug 122557,

r=caillon, sr=hewitt
This commit is contained in:
bzbarsky%mit.edu 2002-04-19 22:29:24 +00:00
Родитель b4db8085e5
Коммит 20b44485af
7 изменённых файлов: 86 добавлений и 7 удалений

Просмотреть файл

@ -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___ */

Просмотреть файл

@ -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<nsIAtom> frameType;
frame->GetFrameType(getter_AddRefs(frameType));
if (frameType == nsLayoutAtoms::tableOuterFrame) {
nsCOMPtr<nsIPresContext> 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);
}

Просмотреть файл

@ -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___ */

Просмотреть файл

@ -86,12 +86,11 @@ inDOMUtils::GetStyleRules(nsIDOMElement *aElement, nsISupportsArray **_retval)
// query to a content node
nsCOMPtr<nsIContent> content;
content = do_QueryInterface(aElement);
nsIFrame* frame = nsnull;
nsCOMPtr<nsIStyleContext> 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

Просмотреть файл

@ -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___ */

Просмотреть файл

@ -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<nsIAtom> frameType;
frame->GetFrameType(getter_AddRefs(frameType));
if (frameType == nsLayoutAtoms::tableOuterFrame) {
nsCOMPtr<nsIPresContext> 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);
}

Просмотреть файл

@ -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___ */