зеркало из https://github.com/mozilla/gecko-dev.git
Cleanup font usage in form input controls, b=251637, r=jshin, sr=bzbarsky
This commit is contained in:
Родитель
b345891dda
Коммит
e2527bce29
|
@ -444,15 +444,6 @@ nsComboboxControlFrame::GetFormContent(nsIContent*& aContent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsComboboxControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
nscoord
|
||||
nsComboboxControlFrame::GetVerticalBorderWidth(float aPixToTwip) const
|
||||
|
@ -788,13 +779,9 @@ nsComboboxControlFrame::ReflowItems(nsIPresContext* aPresContext,
|
|||
nsHTMLReflowMetrics& aDesiredSize)
|
||||
{
|
||||
//printf("*****************\n");
|
||||
const nsStyleFont* dspFont = mDisplayFrame->GetStyleFont();
|
||||
nsIFontMetrics * fontMet;
|
||||
aPresContext->DeviceContext()->GetMetricsFor(dspFont->mFont, fontMet);
|
||||
|
||||
nscoord visibleHeight;
|
||||
//nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
//nsresult res = nsFormControlHelper::GetFrameFontFM(aPresContext, this, getter_AddRefs(fontMet));
|
||||
nscoord visibleHeight = 0;
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
nsresult res = nsFormControlHelper::GetFrameFontFM(mDisplayFrame, getter_AddRefs(fontMet));
|
||||
if (fontMet) {
|
||||
fontMet->GetHeight(visibleHeight);
|
||||
}
|
||||
|
@ -854,7 +841,6 @@ nsComboboxControlFrame::ReflowItems(nsIPresContext* aPresContext,
|
|||
frmWidth-aDesiredSize.width, frmHeight-aDesiredSize.height,
|
||||
(frmWidth-aDesiredSize.width)/15, (frmHeight-aDesiredSize.height)/15);
|
||||
#endif
|
||||
NS_RELEASE(fontMet);
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -150,9 +150,6 @@ public:
|
|||
void ScrollIntoView(nsIPresContext* aPresContext);
|
||||
virtual void InitializeControl(nsIPresContext* aPresContext);
|
||||
NS_IMETHOD OnContentReset();
|
||||
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
virtual nscoord GetVerticalBorderWidth(float aPixToTwip) const;
|
||||
virtual nscoord GetHorizontalBorderWidth(float aPixToTwip) const;
|
||||
|
|
|
@ -598,12 +598,6 @@ nsFileControlFrame::GetFormContent(nsIContent*& aContent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
nscoord
|
||||
nsFileControlFrame::GetVerticalInsidePadding(nsIPresContext* aPresContext,
|
||||
float aPixToTwip,
|
||||
|
|
|
@ -109,9 +109,6 @@ public:
|
|||
void SetFocus(PRBool aOn, PRBool aRepaint);
|
||||
void ScrollIntoView(nsIPresContext* aPresContext);
|
||||
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
virtual nscoord GetVerticalInsidePadding(nsIPresContext* aPresContext,
|
||||
float aPixToTwip,
|
||||
|
|
|
@ -779,13 +779,6 @@ nsFormControlFrame::GetFormContent(nsIContent*& aContent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFormControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFormControlFrame::GetDefaultCheckState(PRBool *aState)
|
||||
{
|
||||
|
|
|
@ -197,9 +197,6 @@ public:
|
|||
|
||||
virtual void SetClickPoint(nscoord aX, nscoord aY);
|
||||
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
|
||||
/**
|
||||
|
|
|
@ -119,19 +119,14 @@ void nsFormControlHelper::GetBoolString(const PRBool aValue,
|
|||
}
|
||||
|
||||
|
||||
nsresult nsFormControlHelper::GetFrameFontFM(nsIPresContext* aPresContext,
|
||||
nsIFormControlFrame * aFrame,
|
||||
nsIFontMetrics** aFontMet)
|
||||
nsresult nsFormControlHelper::GetFrameFontFM(nsIFrame* aFrame,
|
||||
nsIFontMetrics** aFontMet)
|
||||
{
|
||||
// Initialize with default font
|
||||
const nsFont * font = nsnull;
|
||||
// Get frame font
|
||||
if (NS_SUCCEEDED(aFrame->GetFont(aPresContext, font))) {
|
||||
if (font) { // Get font metrics
|
||||
return aPresContext->DeviceContext()->GetMetricsFor(*font, *aFontMet);
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
nsStyleContext* sc = aFrame->GetStyleContext();
|
||||
return aFrame->GetPresContext()->DeviceContext()->
|
||||
GetMetricsFor(sc->GetStyleFont()->mFont,
|
||||
sc->GetStyleVisibility()->mLangGroup,
|
||||
*aFontMet);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -175,64 +170,6 @@ nsFormControlHelper::GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap&
|
|||
return rv;
|
||||
}
|
||||
|
||||
nscoord
|
||||
nsFormControlHelper::GetTextSize(nsIPresContext* aPresContext, nsIFormControlFrame* aFrame,
|
||||
const nsString& aString, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext)
|
||||
{
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
nsresult res = GetFrameFontFM(aPresContext, aFrame, getter_AddRefs(fontMet));
|
||||
if (NS_SUCCEEDED(res) && fontMet) {
|
||||
aRendContext->SetFont(fontMet);
|
||||
|
||||
// measure string
|
||||
aRendContext->GetWidth(aString, aSize.width);
|
||||
fontMet->GetHeight(aSize.height);
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "Couldn't get Font Metrics");
|
||||
aSize.width = 0;
|
||||
}
|
||||
|
||||
char char1, char2;
|
||||
GetRepChars(char1, char2);
|
||||
nscoord char1Width, char2Width;
|
||||
aRendContext->GetWidth(char1, char1Width);
|
||||
aRendContext->GetWidth(char2, char2Width);
|
||||
|
||||
return ((char1Width + char2Width) / 2) + 1;
|
||||
}
|
||||
|
||||
nscoord
|
||||
nsFormControlHelper::GetTextSize(nsIPresContext* aPresContext, nsIFormControlFrame* aFrame,
|
||||
PRInt32 aNumChars, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext)
|
||||
{
|
||||
nsAutoString val;
|
||||
char char1, char2;
|
||||
GetRepChars(char1, char2);
|
||||
int i;
|
||||
for (i = 0; i < aNumChars; i+=2) {
|
||||
val.Append(PRUnichar(char1));
|
||||
}
|
||||
for (i = 1; i < aNumChars; i+=2) {
|
||||
val.Append(PRUnichar(char2));
|
||||
}
|
||||
return GetTextSize(aPresContext, aFrame, val, aSize, aRendContext);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFormControlHelper::GetFont(nsIFormControlFrame * aFormFrame,
|
||||
nsIPresContext* aPresContext,
|
||||
nsStyleContext * aStyleContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
const nsStyleFont* styleFont = (const nsStyleFont*)aStyleContext->GetStyleData(eStyleStruct_Font);
|
||||
|
||||
aFont = &styleFont->mFont;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
// Utility methods for rendering Form Elements using GFX
|
||||
|
|
|
@ -84,24 +84,8 @@ class nsFormControlHelper
|
|||
|
||||
public:
|
||||
|
||||
|
||||
static nscoord GetTextSize(nsIPresContext* aContext, nsIFormControlFrame* aFrame,
|
||||
const nsString& aString, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext);
|
||||
|
||||
static nscoord GetTextSize(nsIPresContext* aContext, nsIFormControlFrame* aFrame,
|
||||
PRInt32 aNumChars, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext);
|
||||
|
||||
// XXX This could be removed now that we no longer have form quirks.
|
||||
static nsresult GetFont(nsIFormControlFrame * aFormFrame,
|
||||
nsIPresContext* aPresContext,
|
||||
nsStyleContext * aStyleContext,
|
||||
const nsFont*& aFont);
|
||||
|
||||
// returns the an addref'ed FontMetrics for the default font for the frame
|
||||
static nsresult GetFrameFontFM(nsIPresContext* aPresContext,
|
||||
nsIFormControlFrame * aFrame,
|
||||
static nsresult GetFrameFontFM(nsIFrame* aFrame,
|
||||
nsIFontMetrics** aFontMet);
|
||||
|
||||
// Map platform line endings (CR, CRLF, LF) to DOM line endings (LF)
|
||||
|
|
|
@ -568,13 +568,6 @@ nsHTMLButtonControlFrame::GetSkipSides() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLButtonControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLButtonControlFrame::GetFormContent(nsIContent*& aContent) const
|
||||
{
|
||||
|
|
|
@ -150,9 +150,6 @@ public:
|
|||
void SetFocus(PRBool aOn, PRBool aRepaint);
|
||||
void ScrollIntoView(nsIPresContext* aPresContext);
|
||||
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
virtual nscoord GetVerticalInsidePadding(nsIPresContext* aPresContext,
|
||||
float aPixToTwip,
|
||||
|
|
|
@ -82,8 +82,6 @@ public:
|
|||
|
||||
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight) = 0;
|
||||
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont) = 0;
|
||||
/**
|
||||
* Get the content object associated with this frame. Adds a reference to
|
||||
* the content object so the caller must do a release.
|
||||
|
|
|
@ -107,8 +107,6 @@ public:
|
|||
|
||||
void SetFocus(PRBool aOn, PRBool aRepaint);
|
||||
void ScrollIntoView(nsIPresContext* aPresContext);
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
virtual nscoord GetVerticalInsidePadding(nsIPresContext* aPresContext,
|
||||
|
@ -321,13 +319,6 @@ nsImageControlFrame::MouseClicked(nsIPresContext* aPresContext)
|
|||
// nsHTMLInputElement::HandleDOMEvent().
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImageControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImageControlFrame::GetFormContent(nsIContent*& aContent) const
|
||||
{
|
||||
|
|
|
@ -1281,7 +1281,7 @@ nsListControlFrame::Reflow(nsIPresContext* aPresContext,
|
|||
if (visibleHeight == 0) {
|
||||
if (aReflowState.mComputedHeight != 0) {
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
nsresult rvv = nsFormControlHelper::GetFrameFontFM(aPresContext, this, getter_AddRefs(fontMet));
|
||||
nsresult rvv = nsFormControlHelper::GetFrameFontFM(this, getter_AddRefs(fontMet));
|
||||
if (NS_SUCCEEDED(rvv) && fontMet) {
|
||||
aReflowState.rendContext->SetFont(fontMet);
|
||||
fontMet->GetHeight(visibleHeight);
|
||||
|
@ -1416,15 +1416,6 @@ nsListControlFrame::GetScrollbarStyles() const
|
|||
verticalStyle);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsListControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
PRBool
|
||||
nsListControlFrame::IsOptionElement(nsIContent* aContent)
|
||||
|
|
|
@ -139,8 +139,6 @@ public:
|
|||
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAString& aValue);
|
||||
NS_IMETHOD GetProperty(nsIAtom* aName, nsAString& aValue);
|
||||
NS_IMETHOD GetMultiple(PRBool* aResult, nsIDOMHTMLSelectElement* aSelect = nsnull);
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
NS_IMETHOD OnContentReset();
|
||||
|
||||
|
|
|
@ -1420,7 +1420,7 @@ nsTextControlFrame::CalculateSizeStandard(nsIPresContext* aPresContext,
|
|||
nscoord charMaxAdvance = 0;
|
||||
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
nsresult rv = nsFormControlHelper::GetFrameFontFM(aPresContext, this, getter_AddRefs(fontMet));
|
||||
nsresult rv = nsFormControlHelper::GetFrameFontFM(this, getter_AddRefs(fontMet));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aRendContext->SetFont(fontMet);
|
||||
fontMet->GetHeight(fontHeight);
|
||||
|
@ -2120,13 +2120,6 @@ nsTextControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextControlFrame::GetFormContent(nsIContent*& aContent) const
|
||||
{
|
||||
|
|
|
@ -144,8 +144,6 @@ public:
|
|||
nscoord aInnerWidth,
|
||||
nscoord aCharWidth) const;/**/
|
||||
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAString& aValue);
|
||||
NS_IMETHOD GetProperty(nsIAtom* aName, nsAString& aValue);
|
||||
|
|
|
@ -82,8 +82,6 @@ public:
|
|||
|
||||
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight) = 0;
|
||||
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont) = 0;
|
||||
/**
|
||||
* Get the content object associated with this frame. Adds a reference to
|
||||
* the content object so the caller must do a release.
|
||||
|
|
|
@ -444,15 +444,6 @@ nsComboboxControlFrame::GetFormContent(nsIContent*& aContent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsComboboxControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
nscoord
|
||||
nsComboboxControlFrame::GetVerticalBorderWidth(float aPixToTwip) const
|
||||
|
@ -788,13 +779,9 @@ nsComboboxControlFrame::ReflowItems(nsIPresContext* aPresContext,
|
|||
nsHTMLReflowMetrics& aDesiredSize)
|
||||
{
|
||||
//printf("*****************\n");
|
||||
const nsStyleFont* dspFont = mDisplayFrame->GetStyleFont();
|
||||
nsIFontMetrics * fontMet;
|
||||
aPresContext->DeviceContext()->GetMetricsFor(dspFont->mFont, fontMet);
|
||||
|
||||
nscoord visibleHeight;
|
||||
//nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
//nsresult res = nsFormControlHelper::GetFrameFontFM(aPresContext, this, getter_AddRefs(fontMet));
|
||||
nscoord visibleHeight = 0;
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
nsresult res = nsFormControlHelper::GetFrameFontFM(mDisplayFrame, getter_AddRefs(fontMet));
|
||||
if (fontMet) {
|
||||
fontMet->GetHeight(visibleHeight);
|
||||
}
|
||||
|
@ -854,7 +841,6 @@ nsComboboxControlFrame::ReflowItems(nsIPresContext* aPresContext,
|
|||
frmWidth-aDesiredSize.width, frmHeight-aDesiredSize.height,
|
||||
(frmWidth-aDesiredSize.width)/15, (frmHeight-aDesiredSize.height)/15);
|
||||
#endif
|
||||
NS_RELEASE(fontMet);
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -150,9 +150,6 @@ public:
|
|||
void ScrollIntoView(nsIPresContext* aPresContext);
|
||||
virtual void InitializeControl(nsIPresContext* aPresContext);
|
||||
NS_IMETHOD OnContentReset();
|
||||
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
virtual nscoord GetVerticalBorderWidth(float aPixToTwip) const;
|
||||
virtual nscoord GetHorizontalBorderWidth(float aPixToTwip) const;
|
||||
|
|
|
@ -598,12 +598,6 @@ nsFileControlFrame::GetFormContent(nsIContent*& aContent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
nscoord
|
||||
nsFileControlFrame::GetVerticalInsidePadding(nsIPresContext* aPresContext,
|
||||
float aPixToTwip,
|
||||
|
|
|
@ -109,9 +109,6 @@ public:
|
|||
void SetFocus(PRBool aOn, PRBool aRepaint);
|
||||
void ScrollIntoView(nsIPresContext* aPresContext);
|
||||
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
virtual nscoord GetVerticalInsidePadding(nsIPresContext* aPresContext,
|
||||
float aPixToTwip,
|
||||
|
|
|
@ -779,13 +779,6 @@ nsFormControlFrame::GetFormContent(nsIContent*& aContent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFormControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFormControlFrame::GetDefaultCheckState(PRBool *aState)
|
||||
{
|
||||
|
|
|
@ -197,9 +197,6 @@ public:
|
|||
|
||||
virtual void SetClickPoint(nscoord aX, nscoord aY);
|
||||
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
|
||||
/**
|
||||
|
|
|
@ -119,19 +119,14 @@ void nsFormControlHelper::GetBoolString(const PRBool aValue,
|
|||
}
|
||||
|
||||
|
||||
nsresult nsFormControlHelper::GetFrameFontFM(nsIPresContext* aPresContext,
|
||||
nsIFormControlFrame * aFrame,
|
||||
nsIFontMetrics** aFontMet)
|
||||
nsresult nsFormControlHelper::GetFrameFontFM(nsIFrame* aFrame,
|
||||
nsIFontMetrics** aFontMet)
|
||||
{
|
||||
// Initialize with default font
|
||||
const nsFont * font = nsnull;
|
||||
// Get frame font
|
||||
if (NS_SUCCEEDED(aFrame->GetFont(aPresContext, font))) {
|
||||
if (font) { // Get font metrics
|
||||
return aPresContext->DeviceContext()->GetMetricsFor(*font, *aFontMet);
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
nsStyleContext* sc = aFrame->GetStyleContext();
|
||||
return aFrame->GetPresContext()->DeviceContext()->
|
||||
GetMetricsFor(sc->GetStyleFont()->mFont,
|
||||
sc->GetStyleVisibility()->mLangGroup,
|
||||
*aFontMet);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -175,64 +170,6 @@ nsFormControlHelper::GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap&
|
|||
return rv;
|
||||
}
|
||||
|
||||
nscoord
|
||||
nsFormControlHelper::GetTextSize(nsIPresContext* aPresContext, nsIFormControlFrame* aFrame,
|
||||
const nsString& aString, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext)
|
||||
{
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
nsresult res = GetFrameFontFM(aPresContext, aFrame, getter_AddRefs(fontMet));
|
||||
if (NS_SUCCEEDED(res) && fontMet) {
|
||||
aRendContext->SetFont(fontMet);
|
||||
|
||||
// measure string
|
||||
aRendContext->GetWidth(aString, aSize.width);
|
||||
fontMet->GetHeight(aSize.height);
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "Couldn't get Font Metrics");
|
||||
aSize.width = 0;
|
||||
}
|
||||
|
||||
char char1, char2;
|
||||
GetRepChars(char1, char2);
|
||||
nscoord char1Width, char2Width;
|
||||
aRendContext->GetWidth(char1, char1Width);
|
||||
aRendContext->GetWidth(char2, char2Width);
|
||||
|
||||
return ((char1Width + char2Width) / 2) + 1;
|
||||
}
|
||||
|
||||
nscoord
|
||||
nsFormControlHelper::GetTextSize(nsIPresContext* aPresContext, nsIFormControlFrame* aFrame,
|
||||
PRInt32 aNumChars, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext)
|
||||
{
|
||||
nsAutoString val;
|
||||
char char1, char2;
|
||||
GetRepChars(char1, char2);
|
||||
int i;
|
||||
for (i = 0; i < aNumChars; i+=2) {
|
||||
val.Append(PRUnichar(char1));
|
||||
}
|
||||
for (i = 1; i < aNumChars; i+=2) {
|
||||
val.Append(PRUnichar(char2));
|
||||
}
|
||||
return GetTextSize(aPresContext, aFrame, val, aSize, aRendContext);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFormControlHelper::GetFont(nsIFormControlFrame * aFormFrame,
|
||||
nsIPresContext* aPresContext,
|
||||
nsStyleContext * aStyleContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
const nsStyleFont* styleFont = (const nsStyleFont*)aStyleContext->GetStyleData(eStyleStruct_Font);
|
||||
|
||||
aFont = &styleFont->mFont;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
// Utility methods for rendering Form Elements using GFX
|
||||
|
|
|
@ -84,24 +84,8 @@ class nsFormControlHelper
|
|||
|
||||
public:
|
||||
|
||||
|
||||
static nscoord GetTextSize(nsIPresContext* aContext, nsIFormControlFrame* aFrame,
|
||||
const nsString& aString, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext);
|
||||
|
||||
static nscoord GetTextSize(nsIPresContext* aContext, nsIFormControlFrame* aFrame,
|
||||
PRInt32 aNumChars, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext);
|
||||
|
||||
// XXX This could be removed now that we no longer have form quirks.
|
||||
static nsresult GetFont(nsIFormControlFrame * aFormFrame,
|
||||
nsIPresContext* aPresContext,
|
||||
nsStyleContext * aStyleContext,
|
||||
const nsFont*& aFont);
|
||||
|
||||
// returns the an addref'ed FontMetrics for the default font for the frame
|
||||
static nsresult GetFrameFontFM(nsIPresContext* aPresContext,
|
||||
nsIFormControlFrame * aFrame,
|
||||
static nsresult GetFrameFontFM(nsIFrame* aFrame,
|
||||
nsIFontMetrics** aFontMet);
|
||||
|
||||
// Map platform line endings (CR, CRLF, LF) to DOM line endings (LF)
|
||||
|
|
|
@ -568,13 +568,6 @@ nsHTMLButtonControlFrame::GetSkipSides() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLButtonControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLButtonControlFrame::GetFormContent(nsIContent*& aContent) const
|
||||
{
|
||||
|
|
|
@ -150,9 +150,6 @@ public:
|
|||
void SetFocus(PRBool aOn, PRBool aRepaint);
|
||||
void ScrollIntoView(nsIPresContext* aPresContext);
|
||||
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
virtual nscoord GetVerticalInsidePadding(nsIPresContext* aPresContext,
|
||||
float aPixToTwip,
|
||||
|
|
|
@ -107,8 +107,6 @@ public:
|
|||
|
||||
void SetFocus(PRBool aOn, PRBool aRepaint);
|
||||
void ScrollIntoView(nsIPresContext* aPresContext);
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
virtual nscoord GetVerticalInsidePadding(nsIPresContext* aPresContext,
|
||||
|
@ -321,13 +319,6 @@ nsImageControlFrame::MouseClicked(nsIPresContext* aPresContext)
|
|||
// nsHTMLInputElement::HandleDOMEvent().
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImageControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImageControlFrame::GetFormContent(nsIContent*& aContent) const
|
||||
{
|
||||
|
|
|
@ -1281,7 +1281,7 @@ nsListControlFrame::Reflow(nsIPresContext* aPresContext,
|
|||
if (visibleHeight == 0) {
|
||||
if (aReflowState.mComputedHeight != 0) {
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
nsresult rvv = nsFormControlHelper::GetFrameFontFM(aPresContext, this, getter_AddRefs(fontMet));
|
||||
nsresult rvv = nsFormControlHelper::GetFrameFontFM(this, getter_AddRefs(fontMet));
|
||||
if (NS_SUCCEEDED(rvv) && fontMet) {
|
||||
aReflowState.rendContext->SetFont(fontMet);
|
||||
fontMet->GetHeight(visibleHeight);
|
||||
|
@ -1416,15 +1416,6 @@ nsListControlFrame::GetScrollbarStyles() const
|
|||
verticalStyle);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsListControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
PRBool
|
||||
nsListControlFrame::IsOptionElement(nsIContent* aContent)
|
||||
|
|
|
@ -139,8 +139,6 @@ public:
|
|||
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAString& aValue);
|
||||
NS_IMETHOD GetProperty(nsIAtom* aName, nsAString& aValue);
|
||||
NS_IMETHOD GetMultiple(PRBool* aResult, nsIDOMHTMLSelectElement* aSelect = nsnull);
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
NS_IMETHOD OnContentReset();
|
||||
|
||||
|
|
|
@ -1420,7 +1420,7 @@ nsTextControlFrame::CalculateSizeStandard(nsIPresContext* aPresContext,
|
|||
nscoord charMaxAdvance = 0;
|
||||
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
nsresult rv = nsFormControlHelper::GetFrameFontFM(aPresContext, this, getter_AddRefs(fontMet));
|
||||
nsresult rv = nsFormControlHelper::GetFrameFontFM(this, getter_AddRefs(fontMet));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aRendContext->SetFont(fontMet);
|
||||
fontMet->GetHeight(fontHeight);
|
||||
|
@ -2120,13 +2120,6 @@ nsTextControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextControlFrame::GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont)
|
||||
{
|
||||
return nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextControlFrame::GetFormContent(nsIContent*& aContent) const
|
||||
{
|
||||
|
|
|
@ -144,8 +144,6 @@ public:
|
|||
nscoord aInnerWidth,
|
||||
nscoord aCharWidth) const;/**/
|
||||
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
|
||||
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
||||
const nsFont*& aFont);
|
||||
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
||||
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAString& aValue);
|
||||
NS_IMETHOD GetProperty(nsIAtom* aName, nsAString& aValue);
|
||||
|
|
Загрузка…
Ссылка в новой задаче