mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-14 12:13:22 +00:00
properly setup fonts and backgound colors
This commit is contained in:
parent
4fcf7056d8
commit
c56d6f8416
@ -43,6 +43,7 @@
|
||||
#include "nsIImage.h"
|
||||
#include "nsHTMLForms.h"
|
||||
#include "nsHTMLImage.h"
|
||||
#include "nsStyleUtil.h"
|
||||
|
||||
enum nsButtonTagType {
|
||||
kButtonTag_Button,
|
||||
@ -544,18 +545,40 @@ nsInputButtonFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
||||
void
|
||||
nsInputButtonFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
|
||||
{
|
||||
nsInputButton* content;
|
||||
GetContent((nsIContent*&) content);
|
||||
|
||||
nsIButton* button;
|
||||
if (NS_OK == GetWidget(aView, (nsIWidget **)&button)) {
|
||||
nsFont font("foo", 0, 0, 0, 0, 0);
|
||||
GetFont(aPresContext, font);
|
||||
button->SetFont(font);
|
||||
if (kButton_Browse != content->GetButtonType()) { // browse button always uses default
|
||||
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
|
||||
}
|
||||
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 {
|
||||
NS_ASSERTION(0, "no widget in button control");
|
||||
}
|
||||
|
||||
nsInputButton* content;
|
||||
GetContent((nsIContent*&) content);
|
||||
nsString value;
|
||||
nsContentAttr status = content->GetAttribute(nsHTMLAtoms::value, value);
|
||||
if (eContentAttr_HasValue == status) {
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "nsIView.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsStyleUtil.h"
|
||||
|
||||
class nsInputCheckboxFrame : public nsInputFrame {
|
||||
public:
|
||||
@ -109,6 +110,17 @@ nsInputCheckboxFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aV
|
||||
nsICheckButton* checkbox;
|
||||
if (NS_OK == GetWidget(aView, (nsIWidget **)&checkbox)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -422,13 +422,9 @@ nscoord
|
||||
nsInputFrame::GetTextSize(nsIPresContext& aPresContext, nsInputFrame* aFrame,
|
||||
const nsString& aString, nsSize& aSize)
|
||||
{
|
||||
//printf("\n GetTextSize %s", aString.ToNewCString());
|
||||
nsIStyleContext* styleContext;
|
||||
aFrame->GetStyleContext(&aPresContext, styleContext);
|
||||
nsFont font("foo", 0, 0, 0, 0, 0);
|
||||
nsFont font = aPresContext.GetDefaultFixedFont();
|
||||
aFrame->GetFont(&aPresContext, font);
|
||||
//const nsStyleFont* styleFont = (const nsStyleFont*)styleContext->GetStyleData(eStyleStruct_Font);
|
||||
NS_RELEASE(styleContext);
|
||||
//printf("\n GetTextSize %s", aString.ToNewCString());
|
||||
nsIDeviceContext* deviceContext = aPresContext.GetDeviceContext();
|
||||
nsIFontCache* fontCache = deviceContext->GetFontCache();
|
||||
|
||||
@ -584,18 +580,16 @@ const void
|
||||
nsInputFrame::GetFont(nsIPresContext* aPresContext, nsFont& aFont)
|
||||
{
|
||||
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;
|
||||
((nsInput*)mContent)->GetType(type);
|
||||
|
||||
// XXX shouldn't this be atom compares instead?
|
||||
if (type.EqualsIgnoreCase("text") || type.EqualsIgnoreCase("textarea") ||
|
||||
type.EqualsIgnoreCase("password")) {
|
||||
aFont.name = fixedFont;
|
||||
aFont = styleFont->mFixedFont;
|
||||
} else {
|
||||
aFont.name = varFont;
|
||||
aFont = styleFont->mFont;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "nsIFormManager.h"
|
||||
#include "nsIView.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsStyleUtil.h"
|
||||
|
||||
class nsInputRadioFrame : public nsInputFrame {
|
||||
public:
|
||||
@ -104,6 +105,17 @@ nsInputRadioFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView
|
||||
nsIRadioButton* radio;
|
||||
if (NS_OK == GetWidget(aView, (nsIWidget **)&radio)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "nsString.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsHTMLForms.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsFont.h"
|
||||
|
||||
class nsInputTextFrame : public nsInputFrame {
|
||||
@ -226,9 +227,8 @@ nsInputTextFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
|
||||
{
|
||||
nsITextWidget* text;
|
||||
if (NS_OK == GetWidget(aView, (nsIWidget **)&text)) {
|
||||
nsFont font("foo", 0, 0, 0, 0, 0);
|
||||
GetFont(aPresContext, font);
|
||||
text->SetFont(font);
|
||||
const nsStyleFont* fontStyle = (const nsStyleFont*)(mStyleContext->GetStyleData(eStyleStruct_Font));
|
||||
text->SetFont(fontStyle->mFixedFont);
|
||||
nsInputText* content;
|
||||
GetContent((nsIContent *&) content);
|
||||
nsAutoString valAttr;
|
||||
@ -238,6 +238,7 @@ nsInputTextFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
|
||||
if (ATTR_NOTSET != maxLength) {
|
||||
text->SetMaxTextLength(maxLength);
|
||||
}
|
||||
text->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
|
||||
NS_RELEASE(text);
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
|
@ -38,6 +38,9 @@
|
||||
#include "nsIListBox.h"
|
||||
#include "nsInput.h"
|
||||
#include "nsHTMLForms.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsStyleUtil.h"
|
||||
#include "nsFont.h"
|
||||
|
||||
static NS_DEFINE_IID(kListWidgetIID, NS_ILISTWIDGET_IID);
|
||||
@ -314,9 +317,30 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
|
||||
return;
|
||||
}
|
||||
|
||||
nsFont font("foo", 0, 0, 0, 0, 0);
|
||||
GetFont(aPresContext, font);
|
||||
list->SetFont(font);
|
||||
list->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
|
||||
|
||||
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();
|
||||
for (int i = 0; i < numChildren; i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user