connected xheight, fixed font realtive sizes,
fixed text-decoration git-svn-id: svn://10.0.0.236/trunk@10230 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user