properly setup fonts and backgound colors

This commit is contained in:
peterl%netscape.com 1998-07-23 18:16:11 +00:00
Родитель 4fcf7056d8
Коммит c56d6f8416
6 изменённых файлов: 89 добавлений и 23 удалений

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

@ -43,6 +43,7 @@
#include "nsIImage.h" #include "nsIImage.h"
#include "nsHTMLForms.h" #include "nsHTMLForms.h"
#include "nsHTMLImage.h" #include "nsHTMLImage.h"
#include "nsStyleUtil.h"
enum nsButtonTagType { enum nsButtonTagType {
kButtonTag_Button, kButtonTag_Button,
@ -544,18 +545,40 @@ nsInputButtonFrame::GetDesiredSize(nsIPresContext* aPresContext,
void void
nsInputButtonFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView) nsInputButtonFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
{ {
nsInputButton* content;
GetContent((nsIContent*&) content);
nsIButton* button; nsIButton* button;
if (NS_OK == GetWidget(aView, (nsIWidget **)&button)) { if (NS_OK == GetWidget(aView, (nsIWidget **)&button)) {
nsFont font("foo", 0, 0, 0, 0, 0); if (kButton_Browse != content->GetButtonType()) { // browse button always uses default
GetFont(aPresContext, font); const nsStyleFont* styleFont = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
button->SetFont(font); if ((styleFont->mFlags & NS_STYLE_FONT_FACE_EXPLICIT) ||
(styleFont->mFlags & NS_STYLE_FONT_SIZE_EXPLICIT)) {
nsFont widgetFont(styleFont->mFixedFont);
widgetFont.weight = NS_FONT_WEIGHT_NORMAL; // always normal weight
widgetFont.size = styleFont->mFont.size; // normal font size
if (0 == (styleFont->mFlags & NS_STYLE_FONT_FACE_EXPLICIT)) {
widgetFont.name = "Arial"; // XXX windows specific font
}
button->SetFont(widgetFont);
}
else {
// use arial, scaled down one HTML size
// italics, decoration & variant(?) get used
nsFont widgetFont(styleFont->mFont);
widgetFont.name = "Arail"; // XXX windows specific font
widgetFont.weight = NS_FONT_WEIGHT_NORMAL;
const nsFont& normal = aPresContext->GetDefaultFont();
PRInt32 fontIndex = nsStyleUtil::FindNextSmallerFontSize(widgetFont.size, (PRInt32)normal.size);
widgetFont.size = nsStyleUtil::CalcFontPointSize(fontIndex, (PRInt32)normal.size);
button->SetFont(widgetFont);
}
}
} }
else { else {
NS_ASSERTION(0, "no widget in button control"); NS_ASSERTION(0, "no widget in button control");
} }
nsInputButton* content;
GetContent((nsIContent*&) content);
nsString value; nsString value;
nsContentAttr status = content->GetAttribute(nsHTMLAtoms::value, value); nsContentAttr status = content->GetAttribute(nsHTMLAtoms::value, value);
if (eContentAttr_HasValue == status) { if (eContentAttr_HasValue == status) {

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

@ -31,6 +31,7 @@
#include "nsIView.h" #include "nsIView.h"
#include "nsHTMLAtoms.h" #include "nsHTMLAtoms.h"
#include "nsIStyleContext.h" #include "nsIStyleContext.h"
#include "nsStyleUtil.h"
class nsInputCheckboxFrame : public nsInputFrame { class nsInputCheckboxFrame : public nsInputFrame {
public: public:
@ -109,6 +110,17 @@ nsInputCheckboxFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aV
nsICheckButton* checkbox; nsICheckButton* checkbox;
if (NS_OK == GetWidget(aView, (nsIWidget **)&checkbox)) { if (NS_OK == GetWidget(aView, (nsIWidget **)&checkbox)) {
checkbox->SetState(checked); checkbox->SetState(checked);
const nsStyleColor* color =
nsStyleUtil::FindNonTransparentBackground(mStyleContext);
if (nsnull != color) {
checkbox->SetBackgroundColor(color->mBackgroundColor);
}
else {
checkbox->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
}
NS_RELEASE(checkbox); NS_RELEASE(checkbox);
} }
} }

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

@ -422,13 +422,9 @@ nscoord
nsInputFrame::GetTextSize(nsIPresContext& aPresContext, nsInputFrame* aFrame, nsInputFrame::GetTextSize(nsIPresContext& aPresContext, nsInputFrame* aFrame,
const nsString& aString, nsSize& aSize) const nsString& aString, nsSize& aSize)
{ {
//printf("\n GetTextSize %s", aString.ToNewCString()); nsFont font = aPresContext.GetDefaultFixedFont();
nsIStyleContext* styleContext;
aFrame->GetStyleContext(&aPresContext, styleContext);
nsFont font("foo", 0, 0, 0, 0, 0);
aFrame->GetFont(&aPresContext, font); aFrame->GetFont(&aPresContext, font);
//const nsStyleFont* styleFont = (const nsStyleFont*)styleContext->GetStyleData(eStyleStruct_Font); //printf("\n GetTextSize %s", aString.ToNewCString());
NS_RELEASE(styleContext);
nsIDeviceContext* deviceContext = aPresContext.GetDeviceContext(); nsIDeviceContext* deviceContext = aPresContext.GetDeviceContext();
nsIFontCache* fontCache = deviceContext->GetFontCache(); nsIFontCache* fontCache = deviceContext->GetFontCache();
@ -584,18 +580,16 @@ const void
nsInputFrame::GetFont(nsIPresContext* aPresContext, nsFont& aFont) nsInputFrame::GetFont(nsIPresContext* aPresContext, nsFont& aFont)
{ {
const nsStyleFont* styleFont = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font); const nsStyleFont* styleFont = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
aFont = styleFont->mFont;
nscoord fontSize = styleFont->mFont.size;
nsAutoString fixedFont("Courier New");
nsAutoString varFont("Times New Roman");
nsString type; nsString type;
((nsInput*)mContent)->GetType(type); ((nsInput*)mContent)->GetType(type);
// XXX shouldn't this be atom compares instead?
if (type.EqualsIgnoreCase("text") || type.EqualsIgnoreCase("textarea") || if (type.EqualsIgnoreCase("text") || type.EqualsIgnoreCase("textarea") ||
type.EqualsIgnoreCase("password")) { type.EqualsIgnoreCase("password")) {
aFont.name = fixedFont; aFont = styleFont->mFixedFont;
} else { } else {
aFont.name = varFont; aFont = styleFont->mFont;
} }
} }

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

@ -33,6 +33,7 @@
#include "nsIFormManager.h" #include "nsIFormManager.h"
#include "nsIView.h" #include "nsIView.h"
#include "nsIStyleContext.h" #include "nsIStyleContext.h"
#include "nsStyleUtil.h"
class nsInputRadioFrame : public nsInputFrame { class nsInputRadioFrame : public nsInputFrame {
public: public:
@ -104,6 +105,17 @@ nsInputRadioFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView
nsIRadioButton* radio; nsIRadioButton* radio;
if (NS_OK == GetWidget(aView, (nsIWidget **)&radio)) { if (NS_OK == GetWidget(aView, (nsIWidget **)&radio)) {
radio->SetState(content->mForcedChecked); radio->SetState(content->mForcedChecked);
const nsStyleColor* color =
nsStyleUtil::FindNonTransparentBackground(mStyleContext);
if (nsnull != color) {
radio->SetBackgroundColor(color->mBackgroundColor);
}
else {
radio->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
}
NS_RELEASE(radio); NS_RELEASE(radio);
} }
} }

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

@ -33,6 +33,7 @@
#include "nsString.h" #include "nsString.h"
#include "nsHTMLAtoms.h" #include "nsHTMLAtoms.h"
#include "nsHTMLForms.h" #include "nsHTMLForms.h"
#include "nsIStyleContext.h"
#include "nsFont.h" #include "nsFont.h"
class nsInputTextFrame : public nsInputFrame { class nsInputTextFrame : public nsInputFrame {
@ -226,9 +227,8 @@ nsInputTextFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
{ {
nsITextWidget* text; nsITextWidget* text;
if (NS_OK == GetWidget(aView, (nsIWidget **)&text)) { if (NS_OK == GetWidget(aView, (nsIWidget **)&text)) {
nsFont font("foo", 0, 0, 0, 0, 0); const nsStyleFont* fontStyle = (const nsStyleFont*)(mStyleContext->GetStyleData(eStyleStruct_Font));
GetFont(aPresContext, font); text->SetFont(fontStyle->mFixedFont);
text->SetFont(font);
nsInputText* content; nsInputText* content;
GetContent((nsIContent *&) content); GetContent((nsIContent *&) content);
nsAutoString valAttr; nsAutoString valAttr;
@ -238,6 +238,7 @@ nsInputTextFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
if (ATTR_NOTSET != maxLength) { if (ATTR_NOTSET != maxLength) {
text->SetMaxTextLength(maxLength); text->SetMaxTextLength(maxLength);
} }
text->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
NS_RELEASE(text); NS_RELEASE(text);
NS_RELEASE(content); NS_RELEASE(content);
} }

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

@ -38,6 +38,9 @@
#include "nsIListBox.h" #include "nsIListBox.h"
#include "nsInput.h" #include "nsInput.h"
#include "nsHTMLForms.h" #include "nsHTMLForms.h"
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
#include "nsStyleUtil.h"
#include "nsFont.h" #include "nsFont.h"
static NS_DEFINE_IID(kListWidgetIID, NS_ILISTWIDGET_IID); static NS_DEFINE_IID(kListWidgetIID, NS_ILISTWIDGET_IID);
@ -314,9 +317,30 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
return; return;
} }
nsFont font("foo", 0, 0, 0, 0, 0); list->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
GetFont(aPresContext, font);
list->SetFont(font); const nsStyleFont* styleFont = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
if ((styleFont->mFlags & NS_STYLE_FONT_FACE_EXPLICIT) ||
(styleFont->mFlags & NS_STYLE_FONT_SIZE_EXPLICIT)) {
nsFont widgetFont(styleFont->mFixedFont);
widgetFont.weight = NS_FONT_WEIGHT_NORMAL; // always normal weight
widgetFont.size = styleFont->mFont.size; // normal font size
if (0 == (styleFont->mFlags & NS_STYLE_FONT_FACE_EXPLICIT)) {
widgetFont.name = "Arial"; // XXX windows specific font
}
list->SetFont(widgetFont);
}
else {
// use arial, scaled down one HTML size
// italics, decoration & variant(?) get used
nsFont widgetFont(styleFont->mFont);
widgetFont.name = "Arail"; // XXX windows specific font
widgetFont.weight = NS_FONT_WEIGHT_NORMAL;
const nsFont& normal = aPresContext->GetDefaultFont();
PRInt32 fontIndex = nsStyleUtil::FindNextSmallerFontSize(widgetFont.size, (PRInt32)normal.size);
widgetFont.size = nsStyleUtil::CalcFontPointSize(fontIndex, (PRInt32)normal.size);
list->SetFont(widgetFont);
}
PRInt32 numChildren = select->ChildCount(); PRInt32 numChildren = select->ChildCount();
for (int i = 0; i < numChildren; i++) { for (int i = 0; i < numChildren; i++) {