mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-26 03:35:33 +00:00
Changed resizing code to use ave char width for calculating the width of a text field in strict/standard mode
I had to put in an ifdef _WIN32 because no other platform implements the call in nsIFontMetrics I will have to address this ifdef in the next release (Bug 50998), which means I will probably implement GetAveCharWidth for all platforms that don't have a native call Bug 44656 r=kmcclusk
This commit is contained in:
parent
2ec6128d8f
commit
4aa51e763f
@ -97,6 +97,7 @@
|
||||
#include "nsITransactionListener.h"
|
||||
|
||||
#define DEFAULT_COLUMN_WIDTH 20
|
||||
#define GUESS_INPUT_SIZE 150 // 10 pixels wide
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
||||
@ -1319,27 +1320,7 @@ nsGfxTextControlFrame2::CalculateSizeStandard (nsIPresContext* aPresContex
|
||||
}
|
||||
|
||||
float p2t;
|
||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||
|
||||
// Calculate the min size of the text control as one char
|
||||
// save the current default col size
|
||||
nscoord tmpCol = aSpec.mColDefaultSize;
|
||||
aSpec.mColDefaultSize = 1;
|
||||
charWidth = nsFormControlHelper::GetTextSize(aPresContext, aFrame, aSpec.mColDefaultSize, aDesiredSize, aRendContext);
|
||||
|
||||
// set the default col size back
|
||||
aMinSize.width = aDesiredSize.width;
|
||||
aMinSize.height = aDesiredSize.height;
|
||||
aSpec.mColDefaultSize = tmpCol;
|
||||
|
||||
// determine the width, char height, row height
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == colStatus) { // col attr will provide width
|
||||
PRInt32 col = ((colAttr.GetUnit() == eHTMLUnit_Pixel) ? colAttr.GetPixelValue() : colAttr.GetIntValue());
|
||||
col = (col <= 0) ? 1 : col; // XXX why a default of 1 char, why hide it
|
||||
charWidth = nsFormControlHelper::GetTextSize(aPresContext, aFrame, col, aDesiredSize, aRendContext);
|
||||
} else {
|
||||
charWidth = nsFormControlHelper::GetTextSize(aPresContext, aFrame, aSpec.mColDefaultSize, aDesiredSize, aRendContext);
|
||||
}
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
|
||||
nscoord fontHeight = 0;
|
||||
// get leading
|
||||
@ -1348,7 +1329,49 @@ nsGfxTextControlFrame2::CalculateSizeStandard (nsIPresContext* aPresContex
|
||||
if (NS_SUCCEEDED(res) && fontMet) {
|
||||
aRendContext->SetFont(fontMet);
|
||||
fontMet->GetHeight(fontHeight);
|
||||
aDesiredSize.height = fontHeight;
|
||||
} else {
|
||||
aDesiredSize.height = GUESS_INPUT_SIZE; // punt
|
||||
}
|
||||
|
||||
// Get the Average char width to calc the min width and
|
||||
// pref width. Pref Width is calced by multiplying the size times avecharwidth
|
||||
//
|
||||
// XXX Currently, WIN32 is the only platform to implement the GetAveCharWidth in
|
||||
// nsIFontMetrics. The other need to have it implemeneted (Bug 50998)
|
||||
// and then this if def removed. We are too close to RTM to implement it in all
|
||||
// the platforms and ports.
|
||||
#ifdef _WIN32
|
||||
fontMet->GetAveCharWidth(charWidth);
|
||||
#else
|
||||
// XP implementation of AveCharWidth
|
||||
nsAutoString aveStr;
|
||||
aveStr.AssignWithConversion(" ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+=-0987654321~`';\":[]}{?><,./\\|");
|
||||
aRendContext->GetWidth(aveStr, charWidth);
|
||||
charWidth /= aveStr.Length();
|
||||
// Round to the nearest twip
|
||||
charWidth = nscoord((float(charWidth) / p2t) + 0.5)*nscoord(p2t);
|
||||
#endif
|
||||
aDesiredSize.width = charWidth;
|
||||
|
||||
#ifdef DEBUG_rodsXXX
|
||||
printf("Ave: %d MA: %d %d\n", charWidth, measAveWidth, charWidth-measAveWidth);
|
||||
printf("Ave: %d MA: %d %d\n", charWidth/15, measAveWidth/15, (charWidth/15)-(measAveWidth/15));
|
||||
#endif
|
||||
|
||||
// set the default col size back
|
||||
aMinSize.width = aDesiredSize.width;
|
||||
aMinSize.height = aDesiredSize.height;
|
||||
|
||||
// determine the width, char height, row height
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == colStatus) { // col attr will provide width
|
||||
PRInt32 col = ((colAttr.GetUnit() == eHTMLUnit_Pixel) ? colAttr.GetPixelValue() : colAttr.GetIntValue());
|
||||
col = (col <= 0) ? 1 : col; // XXX why a default of 1 char, why hide it
|
||||
aDesiredSize.width = (col+1) * charWidth;
|
||||
} else {
|
||||
aDesiredSize.width = (aSpec.mColDefaultSize+1) * charWidth;
|
||||
}
|
||||
|
||||
aRowHeight = aDesiredSize.height;
|
||||
aMinSize.height = aDesiredSize.height;
|
||||
PRInt32 numRows = 0;
|
||||
@ -2625,7 +2648,15 @@ nsGfxTextControlFrame2::AttributeChanged(nsIPresContext* aPresContext,
|
||||
mEditor->SetFlags(flags);
|
||||
}
|
||||
else if ((nsHTMLAtoms::size == aAttribute ||
|
||||
nsHTMLAtoms::rows == aAttribute) && aHint != NS_STYLE_HINT_REFLOW) {
|
||||
nsHTMLAtoms::rows == aAttribute ||
|
||||
nsHTMLAtoms::cols == aAttribute) && aHint != NS_STYLE_HINT_REFLOW) {
|
||||
// XXX Bug 34573 & 50280
|
||||
// The following code should be all we need for these two bugs (it does work for bug 50280)
|
||||
// This doesn't wrong entirely for rows/cols, the borders don't get painted
|
||||
// to fix that I have added a REFLOW hint in nsHTMLTextAreaElement::GetMappedAttributeImpact
|
||||
// but it appears there are some problems when you hold down the return key
|
||||
mPrefSize.width = -1;
|
||||
mPrefSize.height = -1;
|
||||
nsFormFrame::StyleChangeReflow(aPresContext, this);
|
||||
}
|
||||
// Allow the base class to handle common attributes supported
|
||||
|
Loading…
Reference in New Issue
Block a user