From ef14f3a242d43cbdf1370ddecb4851713799ee1f Mon Sep 17 00:00:00 2001 From: "peterl%netscape.com" Date: Thu, 17 Sep 1998 00:19:47 +0000 Subject: [PATCH] connected xheight, fixed font realtive sizes, fixed text-decoration git-svn-id: svn://10.0.0.236/trunk@10230 18797224-902f-48f8-a5cc-f745e15eee43 --- .../content/html/style/src/nsCSSStyleRule.cpp | 41 +++++--- .../html/style/src/nsHTMLCSSStyleSheet.cpp | 98 ++++++++++++++++++- .../html/style/src/nsHTMLStyleSheet.cpp | 10 ++ .../layout/html/style/src/nsCSSStyleRule.cpp | 41 +++++--- .../html/style/src/nsHTMLCSSStyleSheet.cpp | 98 ++++++++++++++++++- .../html/style/src/nsHTMLStyleSheet.cpp | 10 ++ mozilla/layout/style/nsCSSStyleRule.cpp | 41 +++++--- mozilla/layout/style/nsHTMLCSSStyleSheet.cpp | 98 ++++++++++++++++++- mozilla/layout/style/nsHTMLStyleSheet.cpp | 10 ++ 9 files changed, 408 insertions(+), 39 deletions(-) diff --git a/mozilla/content/html/style/src/nsCSSStyleRule.cpp b/mozilla/content/html/style/src/nsCSSStyleRule.cpp index 68fe61176a3..fc26d528144 100644 --- a/mozilla/content/html/style/src/nsCSSStyleRule.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleRule.cpp @@ -28,6 +28,7 @@ #include "nsHTMLAtoms.h" #include "nsUnitConversion.h" #include "nsStyleUtil.h" +#include "nsIFontMetrics.h" //#define DEBUG_REFS @@ -553,16 +554,27 @@ nscoord CalcLength(const nsCSSValue& aValue, nsCSSUnit unit = aValue.GetUnit(); switch (unit) { case eCSSUnit_EM: - return aFont->mFont.size; + return NSToCoordRound(aValue.GetFloatValue() * (float)aFont->mFont.size); case eCSSUnit_EN: - return (aFont->mFont.size / 2); - case eCSSUnit_XHeight: -// NS_NOTYETIMPLEMENTED("x height unit"); - return ((aFont->mFont.size / 3) * 2); // XXX HACK! - case eCSSUnit_CapHeight: + return NSToCoordRound((aValue.GetFloatValue() * (float)aFont->mFont.size) / 2.0f); + case eCSSUnit_XHeight: { + nsIFontMetrics* fm = aPresContext->GetMetricsFor(aFont->mFont); + NS_ASSERTION(nsnull != fm, "can't get font metrics"); + nscoord xHeight; + if (nsnull != fm) { + fm->GetXHeight(xHeight); + NS_RELEASE(fm); + } + else { + xHeight = ((aFont->mFont.size / 3) * 2); + } + return NSToCoordRound(aValue.GetFloatValue() * (float)xHeight); + } + case eCSSUnit_CapHeight: { NS_NOTYETIMPLEMENTED("cap height unit"); - return ((aFont->mFont.size / 3) * 2); // XXX HACK! - + nscoord capHeight = ((aFont->mFont.size / 3) * 2); // XXX HACK! + return NSToCoordRound(aValue.GetFloatValue() * (float)capHeight); + } case eCSSUnit_Pixel: return NSFloatPixelsToTwips(aValue.GetFloatValue(), aPresContext->GetPixelsToTwips()); } @@ -781,9 +793,16 @@ void MapDeclarationInto(nsICSSDeclaration* aDeclaration, if ((ourText->mDecoration.GetUnit() == eCSSUnit_Enumerated) || (ourText->mDecoration.GetUnit() == eCSSUnit_Integer)) { PRInt32 td = ourText->mDecoration.GetIntValue(); - font->mFont.decorations = td; - font->mFixedFont.decorations = td; - text->mTextDecoration = td; + if (NS_STYLE_TEXT_DECORATION_NONE == td) { + font->mFont.decorations = td; + font->mFixedFont.decorations = td; + text->mTextDecoration = td; + } + else { + font->mFont.decorations |= td; + font->mFixedFont.decorations |= td; + text->mTextDecoration |= td; + } } // text-transform diff --git a/mozilla/content/html/style/src/nsHTMLCSSStyleSheet.cpp b/mozilla/content/html/style/src/nsHTMLCSSStyleSheet.cpp index 4db1e93ec41..5b22ca42453 100644 --- a/mozilla/content/html/style/src/nsHTMLCSSStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsHTMLCSSStyleSheet.cpp @@ -27,11 +27,87 @@ #include "nsIFrame.h" #include "nsHTMLIIDs.h" #include "nsICSSStyleRule.h" +#include "nsIStyleContext.h" +#include "nsIPresContext.h" static NS_DEFINE_IID(kIHTMLCSSStyleSheetIID, NS_IHTML_CSS_STYLE_SHEET_IID); static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID); static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID); +static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID); +class BodyFixupRule : public nsIStyleRule { +public: + BodyFixupRule(); + ~BodyFixupRule(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const; + NS_IMETHOD HashValue(PRUint32& aValue) const; + // Strength is an out-of-band weighting, always 0 here + NS_IMETHOD GetStrength(PRInt32& aStrength); + + NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext); + + NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const; +}; + +BodyFixupRule::BodyFixupRule() +{ + NS_INIT_REFCNT(); +} + +BodyFixupRule::~BodyFixupRule() +{ +} + +NS_IMPL_ISUPPORTS(BodyFixupRule, kIStyleRuleIID); + +NS_IMETHODIMP +BodyFixupRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const +{ + aResult = PRBool(this == aRule); + return NS_OK; +} + +NS_IMETHODIMP +BodyFixupRule::HashValue(PRUint32& aValue) const +{ + aValue = (PRUint32)(this); + return NS_OK; +} + +// Strength is an out-of-band weighting, always MaxInt here +NS_IMETHODIMP +BodyFixupRule::GetStrength(PRInt32& aStrength) +{ + aStrength = 2000000000; + return NS_OK; +} + +NS_IMETHODIMP +BodyFixupRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext) +{ + nsStyleColor* styleColor = (nsStyleColor*)(aContext->GetStyleData(eStyleStruct_Color)); + + if (nsnull != styleColor) { + aPresContext->SetDefaultColor(styleColor->mColor); + aPresContext->SetDefaultBackgroundColor(styleColor->mBackgroundColor); + } + return NS_OK; +} + +NS_IMETHODIMP +BodyFixupRule::List(FILE* out, PRInt32 aIndent) const +{ + // Indent + for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out); + + fputs("Special BODY tag fixup rule\n", out); + return NS_OK; +} + +// ------------------------------------------------------------- class HTMLCSSStyleSheetImpl : public nsIHTMLCSSStyleSheet { public: @@ -73,7 +149,8 @@ protected: PRUint32 mInHeap : 1; PRUint32 mRefCnt : 31; - nsIURL* mURL; + nsIURL* mURL; + nsIStyleRule* mBodyRule; }; @@ -115,7 +192,8 @@ void HTMLCSSStyleSheetImpl::operator delete(void* ptr) HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL) : nsIHTMLCSSStyleSheet(), - mURL(aURL) + mURL(aURL), + mBodyRule(nsnull) { NS_INIT_REFCNT(); NS_ADDREF(mURL); @@ -124,6 +202,7 @@ HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL) HTMLCSSStyleSheetImpl::~HTMLCSSStyleSheetImpl() { NS_RELEASE(mURL); + NS_IF_RELEASE(mBodyRule); } NS_IMPL_ADDREF(HTMLCSSStyleSheetImpl) @@ -197,6 +276,21 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext, } } } + nsIAtom* tag; + htmlContent->GetTag(tag); + if (tag == nsHTMLAtoms::body) { + if (nsnull == mBodyRule) { + BodyFixupRule* bodyRule = new BodyFixupRule(); + if ((nsnull != bodyRule) && + (NS_OK != bodyRule->QueryInterface(kIStyleRuleIID, (void**)&mBodyRule))) { + delete bodyRule; + } + } + if (nsnull != mBodyRule) { + aResults->AppendElement(mBodyRule); + matchCount++; + } + } NS_RELEASE(htmlContent); } } diff --git a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp index 4c42673bb5a..9b9b9c3c973 100644 --- a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp @@ -1138,6 +1138,8 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // Construct the root frame object frame = ConstructRootFrame(aPresContext, aContent); + frame->SetStyleContext(aPresContext, styleContext); + // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); @@ -1181,6 +1183,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, else if (nsHTMLAtoms::body == tag) { rv = NS_NewBodyFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content rv = ProcessChildren(aPresContext, frame, aContent, childList); } @@ -1215,6 +1218,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, case NS_STYLE_DISPLAY_LIST_ITEM: rv = NS_NewBlockFrame(&frame, aContent, aParentFrame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1222,6 +1226,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, case NS_STYLE_DISPLAY_INLINE: rv = NS_NewInlineFrame(&frame, aContent, aParentFrame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1238,6 +1243,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // table then create an anonynmous table frame rv = NS_NewTableRowGroupFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1246,6 +1252,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table column group... rv = NS_NewTableColFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1254,6 +1261,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table... rv = NS_NewTableColGroupFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1262,6 +1270,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table row group... rv = NS_NewTableRowFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1270,6 +1279,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table row frame... rv = NS_NewTableCellFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; diff --git a/mozilla/layout/html/style/src/nsCSSStyleRule.cpp b/mozilla/layout/html/style/src/nsCSSStyleRule.cpp index 68fe61176a3..fc26d528144 100644 --- a/mozilla/layout/html/style/src/nsCSSStyleRule.cpp +++ b/mozilla/layout/html/style/src/nsCSSStyleRule.cpp @@ -28,6 +28,7 @@ #include "nsHTMLAtoms.h" #include "nsUnitConversion.h" #include "nsStyleUtil.h" +#include "nsIFontMetrics.h" //#define DEBUG_REFS @@ -553,16 +554,27 @@ nscoord CalcLength(const nsCSSValue& aValue, nsCSSUnit unit = aValue.GetUnit(); switch (unit) { case eCSSUnit_EM: - return aFont->mFont.size; + return NSToCoordRound(aValue.GetFloatValue() * (float)aFont->mFont.size); case eCSSUnit_EN: - return (aFont->mFont.size / 2); - case eCSSUnit_XHeight: -// NS_NOTYETIMPLEMENTED("x height unit"); - return ((aFont->mFont.size / 3) * 2); // XXX HACK! - case eCSSUnit_CapHeight: + return NSToCoordRound((aValue.GetFloatValue() * (float)aFont->mFont.size) / 2.0f); + case eCSSUnit_XHeight: { + nsIFontMetrics* fm = aPresContext->GetMetricsFor(aFont->mFont); + NS_ASSERTION(nsnull != fm, "can't get font metrics"); + nscoord xHeight; + if (nsnull != fm) { + fm->GetXHeight(xHeight); + NS_RELEASE(fm); + } + else { + xHeight = ((aFont->mFont.size / 3) * 2); + } + return NSToCoordRound(aValue.GetFloatValue() * (float)xHeight); + } + case eCSSUnit_CapHeight: { NS_NOTYETIMPLEMENTED("cap height unit"); - return ((aFont->mFont.size / 3) * 2); // XXX HACK! - + nscoord capHeight = ((aFont->mFont.size / 3) * 2); // XXX HACK! + return NSToCoordRound(aValue.GetFloatValue() * (float)capHeight); + } case eCSSUnit_Pixel: return NSFloatPixelsToTwips(aValue.GetFloatValue(), aPresContext->GetPixelsToTwips()); } @@ -781,9 +793,16 @@ void MapDeclarationInto(nsICSSDeclaration* aDeclaration, if ((ourText->mDecoration.GetUnit() == eCSSUnit_Enumerated) || (ourText->mDecoration.GetUnit() == eCSSUnit_Integer)) { PRInt32 td = ourText->mDecoration.GetIntValue(); - font->mFont.decorations = td; - font->mFixedFont.decorations = td; - text->mTextDecoration = td; + if (NS_STYLE_TEXT_DECORATION_NONE == td) { + font->mFont.decorations = td; + font->mFixedFont.decorations = td; + text->mTextDecoration = td; + } + else { + font->mFont.decorations |= td; + font->mFixedFont.decorations |= td; + text->mTextDecoration |= td; + } } // text-transform diff --git a/mozilla/layout/html/style/src/nsHTMLCSSStyleSheet.cpp b/mozilla/layout/html/style/src/nsHTMLCSSStyleSheet.cpp index 4db1e93ec41..5b22ca42453 100644 --- a/mozilla/layout/html/style/src/nsHTMLCSSStyleSheet.cpp +++ b/mozilla/layout/html/style/src/nsHTMLCSSStyleSheet.cpp @@ -27,11 +27,87 @@ #include "nsIFrame.h" #include "nsHTMLIIDs.h" #include "nsICSSStyleRule.h" +#include "nsIStyleContext.h" +#include "nsIPresContext.h" static NS_DEFINE_IID(kIHTMLCSSStyleSheetIID, NS_IHTML_CSS_STYLE_SHEET_IID); static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID); static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID); +static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID); +class BodyFixupRule : public nsIStyleRule { +public: + BodyFixupRule(); + ~BodyFixupRule(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const; + NS_IMETHOD HashValue(PRUint32& aValue) const; + // Strength is an out-of-band weighting, always 0 here + NS_IMETHOD GetStrength(PRInt32& aStrength); + + NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext); + + NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const; +}; + +BodyFixupRule::BodyFixupRule() +{ + NS_INIT_REFCNT(); +} + +BodyFixupRule::~BodyFixupRule() +{ +} + +NS_IMPL_ISUPPORTS(BodyFixupRule, kIStyleRuleIID); + +NS_IMETHODIMP +BodyFixupRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const +{ + aResult = PRBool(this == aRule); + return NS_OK; +} + +NS_IMETHODIMP +BodyFixupRule::HashValue(PRUint32& aValue) const +{ + aValue = (PRUint32)(this); + return NS_OK; +} + +// Strength is an out-of-band weighting, always MaxInt here +NS_IMETHODIMP +BodyFixupRule::GetStrength(PRInt32& aStrength) +{ + aStrength = 2000000000; + return NS_OK; +} + +NS_IMETHODIMP +BodyFixupRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext) +{ + nsStyleColor* styleColor = (nsStyleColor*)(aContext->GetStyleData(eStyleStruct_Color)); + + if (nsnull != styleColor) { + aPresContext->SetDefaultColor(styleColor->mColor); + aPresContext->SetDefaultBackgroundColor(styleColor->mBackgroundColor); + } + return NS_OK; +} + +NS_IMETHODIMP +BodyFixupRule::List(FILE* out, PRInt32 aIndent) const +{ + // Indent + for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out); + + fputs("Special BODY tag fixup rule\n", out); + return NS_OK; +} + +// ------------------------------------------------------------- class HTMLCSSStyleSheetImpl : public nsIHTMLCSSStyleSheet { public: @@ -73,7 +149,8 @@ protected: PRUint32 mInHeap : 1; PRUint32 mRefCnt : 31; - nsIURL* mURL; + nsIURL* mURL; + nsIStyleRule* mBodyRule; }; @@ -115,7 +192,8 @@ void HTMLCSSStyleSheetImpl::operator delete(void* ptr) HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL) : nsIHTMLCSSStyleSheet(), - mURL(aURL) + mURL(aURL), + mBodyRule(nsnull) { NS_INIT_REFCNT(); NS_ADDREF(mURL); @@ -124,6 +202,7 @@ HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL) HTMLCSSStyleSheetImpl::~HTMLCSSStyleSheetImpl() { NS_RELEASE(mURL); + NS_IF_RELEASE(mBodyRule); } NS_IMPL_ADDREF(HTMLCSSStyleSheetImpl) @@ -197,6 +276,21 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext, } } } + nsIAtom* tag; + htmlContent->GetTag(tag); + if (tag == nsHTMLAtoms::body) { + if (nsnull == mBodyRule) { + BodyFixupRule* bodyRule = new BodyFixupRule(); + if ((nsnull != bodyRule) && + (NS_OK != bodyRule->QueryInterface(kIStyleRuleIID, (void**)&mBodyRule))) { + delete bodyRule; + } + } + if (nsnull != mBodyRule) { + aResults->AppendElement(mBodyRule); + matchCount++; + } + } NS_RELEASE(htmlContent); } } diff --git a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp index 4c42673bb5a..9b9b9c3c973 100644 --- a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp @@ -1138,6 +1138,8 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // Construct the root frame object frame = ConstructRootFrame(aPresContext, aContent); + frame->SetStyleContext(aPresContext, styleContext); + // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); @@ -1181,6 +1183,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, else if (nsHTMLAtoms::body == tag) { rv = NS_NewBodyFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content rv = ProcessChildren(aPresContext, frame, aContent, childList); } @@ -1215,6 +1218,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, case NS_STYLE_DISPLAY_LIST_ITEM: rv = NS_NewBlockFrame(&frame, aContent, aParentFrame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1222,6 +1226,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, case NS_STYLE_DISPLAY_INLINE: rv = NS_NewInlineFrame(&frame, aContent, aParentFrame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1238,6 +1243,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // table then create an anonynmous table frame rv = NS_NewTableRowGroupFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1246,6 +1252,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table column group... rv = NS_NewTableColFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1254,6 +1261,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table... rv = NS_NewTableColGroupFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1262,6 +1270,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table row group... rv = NS_NewTableRowFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1270,6 +1279,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table row frame... rv = NS_NewTableCellFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; diff --git a/mozilla/layout/style/nsCSSStyleRule.cpp b/mozilla/layout/style/nsCSSStyleRule.cpp index 68fe61176a3..fc26d528144 100644 --- a/mozilla/layout/style/nsCSSStyleRule.cpp +++ b/mozilla/layout/style/nsCSSStyleRule.cpp @@ -28,6 +28,7 @@ #include "nsHTMLAtoms.h" #include "nsUnitConversion.h" #include "nsStyleUtil.h" +#include "nsIFontMetrics.h" //#define DEBUG_REFS @@ -553,16 +554,27 @@ nscoord CalcLength(const nsCSSValue& aValue, nsCSSUnit unit = aValue.GetUnit(); switch (unit) { case eCSSUnit_EM: - return aFont->mFont.size; + return NSToCoordRound(aValue.GetFloatValue() * (float)aFont->mFont.size); case eCSSUnit_EN: - return (aFont->mFont.size / 2); - case eCSSUnit_XHeight: -// NS_NOTYETIMPLEMENTED("x height unit"); - return ((aFont->mFont.size / 3) * 2); // XXX HACK! - case eCSSUnit_CapHeight: + return NSToCoordRound((aValue.GetFloatValue() * (float)aFont->mFont.size) / 2.0f); + case eCSSUnit_XHeight: { + nsIFontMetrics* fm = aPresContext->GetMetricsFor(aFont->mFont); + NS_ASSERTION(nsnull != fm, "can't get font metrics"); + nscoord xHeight; + if (nsnull != fm) { + fm->GetXHeight(xHeight); + NS_RELEASE(fm); + } + else { + xHeight = ((aFont->mFont.size / 3) * 2); + } + return NSToCoordRound(aValue.GetFloatValue() * (float)xHeight); + } + case eCSSUnit_CapHeight: { NS_NOTYETIMPLEMENTED("cap height unit"); - return ((aFont->mFont.size / 3) * 2); // XXX HACK! - + nscoord capHeight = ((aFont->mFont.size / 3) * 2); // XXX HACK! + return NSToCoordRound(aValue.GetFloatValue() * (float)capHeight); + } case eCSSUnit_Pixel: return NSFloatPixelsToTwips(aValue.GetFloatValue(), aPresContext->GetPixelsToTwips()); } @@ -781,9 +793,16 @@ void MapDeclarationInto(nsICSSDeclaration* aDeclaration, if ((ourText->mDecoration.GetUnit() == eCSSUnit_Enumerated) || (ourText->mDecoration.GetUnit() == eCSSUnit_Integer)) { PRInt32 td = ourText->mDecoration.GetIntValue(); - font->mFont.decorations = td; - font->mFixedFont.decorations = td; - text->mTextDecoration = td; + if (NS_STYLE_TEXT_DECORATION_NONE == td) { + font->mFont.decorations = td; + font->mFixedFont.decorations = td; + text->mTextDecoration = td; + } + else { + font->mFont.decorations |= td; + font->mFixedFont.decorations |= td; + text->mTextDecoration |= td; + } } // text-transform diff --git a/mozilla/layout/style/nsHTMLCSSStyleSheet.cpp b/mozilla/layout/style/nsHTMLCSSStyleSheet.cpp index 4db1e93ec41..5b22ca42453 100644 --- a/mozilla/layout/style/nsHTMLCSSStyleSheet.cpp +++ b/mozilla/layout/style/nsHTMLCSSStyleSheet.cpp @@ -27,11 +27,87 @@ #include "nsIFrame.h" #include "nsHTMLIIDs.h" #include "nsICSSStyleRule.h" +#include "nsIStyleContext.h" +#include "nsIPresContext.h" static NS_DEFINE_IID(kIHTMLCSSStyleSheetIID, NS_IHTML_CSS_STYLE_SHEET_IID); static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID); static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID); +static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID); +class BodyFixupRule : public nsIStyleRule { +public: + BodyFixupRule(); + ~BodyFixupRule(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const; + NS_IMETHOD HashValue(PRUint32& aValue) const; + // Strength is an out-of-band weighting, always 0 here + NS_IMETHOD GetStrength(PRInt32& aStrength); + + NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext); + + NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const; +}; + +BodyFixupRule::BodyFixupRule() +{ + NS_INIT_REFCNT(); +} + +BodyFixupRule::~BodyFixupRule() +{ +} + +NS_IMPL_ISUPPORTS(BodyFixupRule, kIStyleRuleIID); + +NS_IMETHODIMP +BodyFixupRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const +{ + aResult = PRBool(this == aRule); + return NS_OK; +} + +NS_IMETHODIMP +BodyFixupRule::HashValue(PRUint32& aValue) const +{ + aValue = (PRUint32)(this); + return NS_OK; +} + +// Strength is an out-of-band weighting, always MaxInt here +NS_IMETHODIMP +BodyFixupRule::GetStrength(PRInt32& aStrength) +{ + aStrength = 2000000000; + return NS_OK; +} + +NS_IMETHODIMP +BodyFixupRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext) +{ + nsStyleColor* styleColor = (nsStyleColor*)(aContext->GetStyleData(eStyleStruct_Color)); + + if (nsnull != styleColor) { + aPresContext->SetDefaultColor(styleColor->mColor); + aPresContext->SetDefaultBackgroundColor(styleColor->mBackgroundColor); + } + return NS_OK; +} + +NS_IMETHODIMP +BodyFixupRule::List(FILE* out, PRInt32 aIndent) const +{ + // Indent + for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out); + + fputs("Special BODY tag fixup rule\n", out); + return NS_OK; +} + +// ------------------------------------------------------------- class HTMLCSSStyleSheetImpl : public nsIHTMLCSSStyleSheet { public: @@ -73,7 +149,8 @@ protected: PRUint32 mInHeap : 1; PRUint32 mRefCnt : 31; - nsIURL* mURL; + nsIURL* mURL; + nsIStyleRule* mBodyRule; }; @@ -115,7 +192,8 @@ void HTMLCSSStyleSheetImpl::operator delete(void* ptr) HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL) : nsIHTMLCSSStyleSheet(), - mURL(aURL) + mURL(aURL), + mBodyRule(nsnull) { NS_INIT_REFCNT(); NS_ADDREF(mURL); @@ -124,6 +202,7 @@ HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL) HTMLCSSStyleSheetImpl::~HTMLCSSStyleSheetImpl() { NS_RELEASE(mURL); + NS_IF_RELEASE(mBodyRule); } NS_IMPL_ADDREF(HTMLCSSStyleSheetImpl) @@ -197,6 +276,21 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext, } } } + nsIAtom* tag; + htmlContent->GetTag(tag); + if (tag == nsHTMLAtoms::body) { + if (nsnull == mBodyRule) { + BodyFixupRule* bodyRule = new BodyFixupRule(); + if ((nsnull != bodyRule) && + (NS_OK != bodyRule->QueryInterface(kIStyleRuleIID, (void**)&mBodyRule))) { + delete bodyRule; + } + } + if (nsnull != mBodyRule) { + aResults->AppendElement(mBodyRule); + matchCount++; + } + } NS_RELEASE(htmlContent); } } diff --git a/mozilla/layout/style/nsHTMLStyleSheet.cpp b/mozilla/layout/style/nsHTMLStyleSheet.cpp index 4c42673bb5a..9b9b9c3c973 100644 --- a/mozilla/layout/style/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/style/nsHTMLStyleSheet.cpp @@ -1138,6 +1138,8 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // Construct the root frame object frame = ConstructRootFrame(aPresContext, aContent); + frame->SetStyleContext(aPresContext, styleContext); + // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); @@ -1181,6 +1183,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, else if (nsHTMLAtoms::body == tag) { rv = NS_NewBodyFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content rv = ProcessChildren(aPresContext, frame, aContent, childList); } @@ -1215,6 +1218,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, case NS_STYLE_DISPLAY_LIST_ITEM: rv = NS_NewBlockFrame(&frame, aContent, aParentFrame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1222,6 +1226,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, case NS_STYLE_DISPLAY_INLINE: rv = NS_NewInlineFrame(&frame, aContent, aParentFrame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1238,6 +1243,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // table then create an anonynmous table frame rv = NS_NewTableRowGroupFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1246,6 +1252,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table column group... rv = NS_NewTableColFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1254,6 +1261,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table... rv = NS_NewTableColGroupFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1262,6 +1270,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table row group... rv = NS_NewTableRowFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break; @@ -1270,6 +1279,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, // XXX We should check for being inside of a table row frame... rv = NS_NewTableCellFrame(aContent, aParentFrame, frame); + frame->SetStyleContext(aPresContext, styleContext); // Process the child content ProcessChildren(aPresContext, frame, aContent, childList); break;