зеркало из https://github.com/mozilla/gecko-dev.git
Make default wrap soft again, fix up text reflow, remove cruft from button reflow (bug 164641), r=rods@netscape.com, sr=kin@netscape.com
This commit is contained in:
Родитель
287e8c1516
Коммит
02c9151814
|
@ -78,12 +78,9 @@ static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
|||
|
||||
|
||||
// For figuring out the "WRAP" property
|
||||
// See GetWrapPropertyEnum for details
|
||||
#define kTextControl_Wrap_Soft "SOFT"
|
||||
#define kTextControl_Wrap_Virtual "VIRTUAL" // "virtual" is a synonym for "soft"
|
||||
#define kTextControl_Wrap_Hard "HARD"
|
||||
#define kTextControl_Wrap_Physical "PHYSICAL" // "physical" should be a synonym
|
||||
// for "hard" but NS 4.x and IE make
|
||||
// it a synonym for "soft"
|
||||
#define kTextControl_Wrap_Off "OFF"
|
||||
|
||||
|
||||
|
@ -186,155 +183,27 @@ nsFormControlHelper::GetWrapProperty(nsIContent * aContent, nsString &aOutValue)
|
|||
nsresult
|
||||
nsFormControlHelper::GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap& aWrapProp)
|
||||
{
|
||||
nsString wrap;
|
||||
aWrapProp = eHTMLTextWrap_Off; // the default
|
||||
// soft is the default; "physical" defaults to soft as well because all other
|
||||
// browsers treat it that way and there is no real reason to maintain physical
|
||||
// and virtual as separate entities if no one else does. Only hard and off
|
||||
// do anything different.
|
||||
aWrapProp = eHTMLTextWrap_Soft; // the default
|
||||
|
||||
nsresult result = GetWrapProperty(aContent, wrap);
|
||||
nsAutoString wrap;
|
||||
nsresult rv = GetWrapProperty(aContent, wrap);
|
||||
|
||||
if (NS_CONTENT_ATTR_NOT_THERE != result) {
|
||||
if (rv != NS_CONTENT_ATTR_NOT_THERE) {
|
||||
|
||||
if (wrap.EqualsIgnoreCase(kTextControl_Wrap_Hard)) {
|
||||
aWrapProp = eHTMLTextWrap_Hard;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (wrap.EqualsIgnoreCase(kTextControl_Wrap_Soft) ||
|
||||
wrap.EqualsIgnoreCase(kTextControl_Wrap_Virtual) ||
|
||||
wrap.EqualsIgnoreCase(kTextControl_Wrap_Physical)) {
|
||||
aWrapProp = eHTMLTextWrap_Soft;
|
||||
return result;
|
||||
} else if (wrap.EqualsIgnoreCase(kTextControl_Wrap_Off)) {
|
||||
aWrapProp = eHTMLTextWrap_Off;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nscoord
|
||||
nsFormControlHelper::CalcNavQuirkSizing(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFontMetrics* aFontMet,
|
||||
nsIFormControlFrame* aFrame,
|
||||
nsInputDimensionSpec& aSpec,
|
||||
nsSize& aSize)
|
||||
{
|
||||
float p2t;
|
||||
float t2p;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
aPresContext->GetTwipsToPixels(&t2p);
|
||||
|
||||
nscoord ascent;
|
||||
nscoord descent;
|
||||
nscoord maxCharWidth;
|
||||
aFontMet->GetMaxAscent(ascent);
|
||||
aFontMet->GetMaxDescent(descent);
|
||||
aFontMet->GetMaxAdvance(maxCharWidth);
|
||||
|
||||
ascent = NSToCoordRound(ascent * t2p);
|
||||
descent = NSToCoordRound(descent * t2p);
|
||||
maxCharWidth = NSToCoordRound(maxCharWidth * t2p);
|
||||
|
||||
char char1, char2;
|
||||
GetRepChars(char1, char2);
|
||||
|
||||
nscoord char1Width, char2Width;
|
||||
aRendContext->GetWidth(char1, char1Width);
|
||||
aRendContext->GetWidth(char2, char2Width);
|
||||
char1Width = NSToCoordRound(char1Width * t2p);
|
||||
char2Width = NSToCoordRound(char2Width * t2p);
|
||||
|
||||
// Nav Quirk Calculation for TextField
|
||||
PRInt32 type;
|
||||
aFrame->GetType(&type);
|
||||
nscoord width;
|
||||
nscoord hgt;
|
||||
nscoord height;
|
||||
nscoord average = 0;
|
||||
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
|
||||
average = (char1Width + char2Width) / 2;
|
||||
width = maxCharWidth;
|
||||
hgt = ascent + descent;
|
||||
height = hgt + (hgt / 2);
|
||||
width += aSpec.mColDefaultSize * average;
|
||||
} else if (NS_FORM_TEXTAREA == type) {
|
||||
nscoord lines = 1;
|
||||
nscoord scrollbarWidth = 0;
|
||||
nscoord scrollbarHeight = 0;
|
||||
float scale;
|
||||
nsCOMPtr<nsIDeviceContext> dx;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dx));
|
||||
if (dx) {
|
||||
float sbWidth;
|
||||
float sbHeight;
|
||||
dx->GetCanonicalPixelScale(scale);
|
||||
dx->GetScrollBarDimensions(sbWidth, sbHeight);
|
||||
scrollbarWidth = PRInt32(sbWidth * scale);
|
||||
scrollbarHeight = PRInt32(sbHeight * scale);
|
||||
scrollbarWidth = NSToCoordRound(scrollbarWidth * t2p);
|
||||
scrollbarHeight = NSToCoordRound(scrollbarHeight * t2p);
|
||||
} else {
|
||||
NS_ASSERTION(0, "Couldn't get the device context");
|
||||
scrollbarWidth = 16;
|
||||
scrollbarHeight = 16;
|
||||
}
|
||||
nsIContent * content;
|
||||
aFrame->GetFormContent(content);
|
||||
nsCOMPtr<nsIHTMLContent> hContent(do_QueryInterface(content));
|
||||
|
||||
// determine the height
|
||||
nsHTMLValue rowAttr;
|
||||
nsresult rowStatus = NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (nsnull != aSpec.mRowSizeAttr) {
|
||||
rowStatus = hContent->GetHTMLAttribute(aSpec.mRowSizeAttr, rowAttr);
|
||||
}
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == rowStatus) { // row attr will provide height
|
||||
PRInt32 rowAttrInt = ((rowAttr.GetUnit() == eHTMLUnit_Pixel)
|
||||
? rowAttr.GetPixelValue() : rowAttr.GetIntValue());
|
||||
lines = (rowAttrInt > 0) ? rowAttrInt : 1;
|
||||
} else {
|
||||
lines = aSpec.mRowDefaultSize;
|
||||
}
|
||||
|
||||
average = (char1Width + char2Width) / 2;
|
||||
width = ((aSpec.mColDefaultSize + 1) * average) + scrollbarWidth;
|
||||
hgt = ascent + descent;
|
||||
height = (lines + 1) * hgt;
|
||||
|
||||
// then if not word wrapping
|
||||
nsHTMLTextWrap wrapProp;
|
||||
nsFormControlHelper::GetWrapPropertyEnum(content, wrapProp);
|
||||
if (wrapProp == eHTMLTextWrap_Off) {
|
||||
height += scrollbarHeight;
|
||||
}
|
||||
NS_RELEASE(content);
|
||||
} else if (NS_FORM_INPUT_BUTTON == type ||
|
||||
NS_FORM_INPUT_SUBMIT == type ||
|
||||
NS_FORM_INPUT_RESET == type) {
|
||||
GetTextSize(aPresContext, aFrame, *aSpec.mColDefaultValue, aSize, aRendContext);
|
||||
aSize.width = NSToCoordRound(aSize.width * t2p);
|
||||
aSize.height = NSToCoordRound(aSize.height * t2p);
|
||||
width = 3 * aSize.width / 2;
|
||||
height = 3 * aSize.height / 2;
|
||||
} else if (NS_FORM_INPUT_HIDDEN == type) {
|
||||
width = 0;
|
||||
height = 0;
|
||||
} else {
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_rodsXXXX
|
||||
printf("********* Nav Quirks: %d,%d max:%d average:%d ascent:%d descent:%d\n",
|
||||
width, height, maxCharWidth, average, ascent, descent);
|
||||
#endif
|
||||
|
||||
aSize.width = NSIntPixelsToTwips(width, p2t);
|
||||
aSize.height = NSIntPixelsToTwips(height, p2t);
|
||||
average = NSIntPixelsToTwips(average, p2t);
|
||||
|
||||
return average;
|
||||
|
||||
}
|
||||
|
||||
nscoord
|
||||
nscoord
|
||||
nsFormControlHelper::GetTextSize(nsIPresContext* aPresContext, nsIFormControlFrame* aFrame,
|
||||
const nsString& aString, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext)
|
||||
|
@ -379,138 +248,6 @@ nsFormControlHelper::GetTextSize(nsIPresContext* aPresContext, nsIFormControlFra
|
|||
return GetTextSize(aPresContext, aFrame, val, aSize, aRendContext);
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsFormControlHelper::CalculateSize (nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFormControlFrame* aFrame,
|
||||
const nsSize& aCSSSize,
|
||||
nsInputDimensionSpec& aSpec,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize,
|
||||
PRBool& aWidthExplicit,
|
||||
PRBool& aHeightExplicit,
|
||||
nscoord& aRowHeight)
|
||||
{
|
||||
nscoord charWidth = 0;
|
||||
PRInt32 numRows = ATTR_NOTSET;
|
||||
aWidthExplicit = PR_FALSE;
|
||||
aHeightExplicit = PR_FALSE;
|
||||
|
||||
aDesiredSize.width = CSS_NOTSET;
|
||||
aDesiredSize.height = CSS_NOTSET;
|
||||
|
||||
nsCOMPtr<nsIContent> iContent;
|
||||
aFrame->GetFormContent(*getter_AddRefs(iContent));
|
||||
|
||||
nsCOMPtr<nsIHTMLContent> hContent(do_QueryInterface(iContent));
|
||||
|
||||
if (!hContent) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsAutoString valAttr;
|
||||
nsresult valStatus = NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (nsnull != aSpec.mColValueAttr) {
|
||||
valStatus = hContent->GetAttr(kNameSpaceID_None, aSpec.mColValueAttr,
|
||||
valAttr);
|
||||
}
|
||||
nsHTMLValue colAttr;
|
||||
nsresult colStatus = NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (nsnull != aSpec.mColSizeAttr) {
|
||||
colStatus = hContent->GetHTMLAttribute(aSpec.mColSizeAttr, colAttr);
|
||||
}
|
||||
float p2t;
|
||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||
|
||||
#if 0
|
||||
// determine if it is percentage based width, height
|
||||
PRBool percentageWidth = PR_FALSE;
|
||||
PRBool percentageHeight = PR_FALSE;
|
||||
|
||||
const nsStylePosition* pos;
|
||||
nsIFrame* iFrame = nsnull;
|
||||
nsresult rv = aFrame->QueryInterface(NS_GET_IID(nsIFrame), (void**)&iFrame);
|
||||
if ((NS_OK == rv) && (nsnull != iFrame)) {
|
||||
iFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&)pos);
|
||||
if (eStyleUnit_Percent == pos->mWidth.GetUnit()) {
|
||||
percentageWidth = PR_TRUE;
|
||||
}
|
||||
if (eStyleUnit_Percent == pos->mWidth.GetUnit()) {
|
||||
percentageHeight = PR_TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// 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());
|
||||
if (aSpec.mColSizeAttrInPixels) {
|
||||
// need to set charWidth and aDesiredSize.height
|
||||
charWidth = GetTextSize(aPresContext, aFrame, 1, aDesiredSize, aRendContext);
|
||||
col = (col <= 0) ? 15 : col; // XXX why a default of 15 pixels, why hide it
|
||||
// XXX this conflicts with a default of 20 found in nsTextControlFrame.
|
||||
aDesiredSize.width = NSIntPixelsToTwips(col, p2t);
|
||||
} else {
|
||||
col = (col <= 0) ? 1 : col; // XXX why a default of 1 char, why hide it
|
||||
}
|
||||
if (aSpec.mColSizeAttrInPixels) {
|
||||
aWidthExplicit = PR_TRUE;
|
||||
}
|
||||
aMinSize.width = aDesiredSize.width;
|
||||
} else {
|
||||
// set aDesiredSize for height calculation below. CSS may override width
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == valStatus) { // use width of initial value
|
||||
charWidth = GetTextSize(aPresContext, aFrame, valAttr, aDesiredSize, aRendContext);
|
||||
} else if (aSpec.mColDefaultValue) { // use default value
|
||||
charWidth = GetTextSize(aPresContext, aFrame, *aSpec.mColDefaultValue, aDesiredSize, aRendContext);
|
||||
} else if (aSpec.mColDefaultSizeInPixels) { // use default width in pixels
|
||||
charWidth = GetTextSize(aPresContext, aFrame, 1, aDesiredSize, aRendContext);
|
||||
aDesiredSize.width = aSpec.mColDefaultSize;
|
||||
} else { // use default width in num characters
|
||||
charWidth = GetTextSize(aPresContext, aFrame, aSpec.mColDefaultSize, aDesiredSize, aRendContext);
|
||||
}
|
||||
aMinSize.width = aDesiredSize.width;
|
||||
if (CSS_NOTSET != aCSSSize.width) { // css provides width
|
||||
NS_ASSERTION(aCSSSize.width >= 0, "form control's computed width is < 0");
|
||||
if (NS_INTRINSICSIZE != aCSSSize.width) {
|
||||
aDesiredSize.width = PR_MAX(aDesiredSize.width,aCSSSize.width);
|
||||
aWidthExplicit = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
aRowHeight = aDesiredSize.height;
|
||||
aMinSize.height = aDesiredSize.height;
|
||||
|
||||
// determine the height
|
||||
nsHTMLValue rowAttr;
|
||||
nsresult rowStatus = NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (nsnull != aSpec.mRowSizeAttr) {
|
||||
rowStatus = hContent->GetHTMLAttribute(aSpec.mRowSizeAttr, rowAttr);
|
||||
}
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == rowStatus) { // row attr will provide height
|
||||
PRInt32 rowAttrInt = ((rowAttr.GetUnit() == eHTMLUnit_Pixel)
|
||||
? rowAttr.GetPixelValue() : rowAttr.GetIntValue());
|
||||
numRows = (rowAttrInt > 0) ? rowAttrInt : 1;
|
||||
aDesiredSize.height = aDesiredSize.height * numRows;
|
||||
} else {
|
||||
aDesiredSize.height = aDesiredSize.height * aSpec.mRowDefaultSize;
|
||||
if (CSS_NOTSET != aCSSSize.height) { // css provides height
|
||||
NS_ASSERTION(aCSSSize.height > 0, "form control's computed height is <= 0");
|
||||
if (NS_INTRINSICSIZE != aCSSSize.height) {
|
||||
aDesiredSize.height = PR_MAX(aDesiredSize.height,aCSSSize.height);
|
||||
aHeightExplicit = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ATTR_NOTSET == numRows) {
|
||||
numRows = (aRowHeight > 0) ? (aDesiredSize.height / aRowHeight) : 0;
|
||||
}
|
||||
|
||||
return numRows;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsFormControlHelper::GetFont(nsIFormControlFrame * aFormFrame,
|
||||
nsIPresContext* aPresContext,
|
||||
|
|
|
@ -73,33 +73,6 @@ enum nsMouseState {
|
|||
eMouseUp
|
||||
};
|
||||
|
||||
struct nsInputDimensionSpec
|
||||
{
|
||||
nsIAtom* mColSizeAttr; // attribute used to determine width
|
||||
PRBool mColSizeAttrInPixels; // is attribute value in pixels (otherwise num chars)
|
||||
nsIAtom* mColValueAttr; // attribute used to get value to determine size
|
||||
// if not determined above
|
||||
nsString* mColDefaultValue; // default value if not determined above
|
||||
nscoord mColDefaultSize; // default width if not determined above
|
||||
PRBool mColDefaultSizeInPixels; // is default width in pixels (otherswise num chars)
|
||||
nsIAtom* mRowSizeAttr; // attribute used to determine height
|
||||
nscoord mRowDefaultSize; // default height if not determined above
|
||||
|
||||
nsInputDimensionSpec(nsIAtom* aColSizeAttr, PRBool aColSizeAttrInPixels,
|
||||
nsIAtom* aColValueAttr, nsString* aColDefaultValue,
|
||||
nscoord aColDefaultSize, PRBool aColDefaultSizeInPixels,
|
||||
nsIAtom* aRowSizeAttr, nscoord aRowDefaultSize)
|
||||
: mColSizeAttr(aColSizeAttr), mColSizeAttrInPixels(aColSizeAttrInPixels),
|
||||
mColValueAttr(aColValueAttr),
|
||||
mColDefaultValue(aColDefaultValue), mColDefaultSize(aColDefaultSize),
|
||||
mColDefaultSizeInPixels(aColDefaultSizeInPixels),
|
||||
mRowSizeAttr(aRowSizeAttr), mRowDefaultSize(aRowDefaultSize)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* nsFormControlHelper is the base class for frames of form controls. It
|
||||
|
@ -112,17 +85,6 @@ class nsFormControlHelper
|
|||
public:
|
||||
|
||||
|
||||
static nscoord CalculateSize (nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFormControlFrame* aFrame,
|
||||
const nsSize& aCSSSize,
|
||||
nsInputDimensionSpec& aDimensionSpec,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize,
|
||||
PRBool& aWidthExplicit,
|
||||
PRBool& aHeightExplicit,
|
||||
nscoord& aRowSize);
|
||||
|
||||
static nscoord GetTextSize(nsIPresContext* aContext, nsIFormControlFrame* aFrame,
|
||||
const nsString& aString, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext);
|
||||
|
@ -142,13 +104,6 @@ public:
|
|||
nsIFormControlFrame * aFrame,
|
||||
nsIFontMetrics** aFontMet);
|
||||
|
||||
static nscoord CalcNavQuirkSizing(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFontMetrics* aFontMet,
|
||||
nsIFormControlFrame* aFrame,
|
||||
nsInputDimensionSpec& aSpec,
|
||||
nsSize& aSize);
|
||||
|
||||
static void ForceDrawFrame(nsIPresContext* aPresContext, nsIFrame * aFrame);
|
||||
|
||||
// Map platform line endings (CR, CRLF, LF) to DOM line endings (LF)
|
||||
|
|
|
@ -65,7 +65,6 @@ nsGfxButtonControlFrame::nsGfxButtonControlFrame()
|
|||
{
|
||||
mSuggestedWidth = kSuggestedNotSet;
|
||||
mSuggestedHeight = kSuggestedNotSet;
|
||||
mDefaultValueWasChanged = PR_FALSE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -92,26 +91,6 @@ nsGfxButtonControlFrame::GetFrameType(nsIAtom** aType) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsGfxButtonControlFrame::IsReset(PRInt32 type)
|
||||
{
|
||||
if (NS_FORM_INPUT_RESET == type) {
|
||||
return PR_TRUE;
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsGfxButtonControlFrame::IsSubmit(PRInt32 type)
|
||||
{
|
||||
if (NS_FORM_INPUT_SUBMIT == type) {
|
||||
return PR_TRUE;
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Special check for the browse button of a file input.
|
||||
//
|
||||
// Since this is actually type "NS_FORM_INPUT_BUTTON", we
|
||||
|
@ -120,7 +99,7 @@ nsGfxButtonControlFrame::IsSubmit(PRInt32 type)
|
|||
// (a) type is NS_FORM_BROWSE or
|
||||
// (b) type is NS_FORM_INPUT_BUTTON and our parent is a file input
|
||||
PRBool
|
||||
nsGfxButtonControlFrame::IsBrowse(PRInt32 type)
|
||||
nsGfxButtonControlFrame::IsFileBrowseButton(PRInt32 type)
|
||||
{
|
||||
PRBool rv = PR_FALSE;
|
||||
if (NS_FORM_BROWSE == type) {
|
||||
|
@ -192,7 +171,7 @@ nsGfxButtonControlFrame::AddComputedBorderPaddingToDesiredSize(nsHTMLReflowMetri
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsGfxButtonControlFrame::DoNavQuirksReflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
|
@ -233,12 +212,8 @@ nsGfxButtonControlFrame::DoNavQuirksReflow(nsIPresContext* aPresContext
|
|||
value.Assign(NS_LITERAL_STRING(" "));
|
||||
}
|
||||
|
||||
nsInputDimensionSpec btnSpec(NULL, PR_FALSE, nsnull,
|
||||
&value,0,
|
||||
PR_FALSE, NULL, 1);
|
||||
nsFormControlHelper::CalcNavQuirkSizing(aPresContext, aReflowState.rendContext,
|
||||
fontMet, (nsIFormControlFrame*)this,
|
||||
btnSpec, desiredSize);
|
||||
CalcNavQuirkSizing(aPresContext, aReflowState.rendContext, value,
|
||||
desiredSize);
|
||||
|
||||
// Note: The Quirks sizing includes a 2px border in its calculation of "desiredSize"
|
||||
// So we must subtract off the 2 pixel border.
|
||||
|
@ -481,20 +456,20 @@ else {
|
|||
// However, since html.css is not internationalized, we now grab the default
|
||||
// label from a string bundle as is done for all other UI strings.
|
||||
// See bug 16999 for further details.
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsGfxButtonControlFrame::GetDefaultLabel(nsString& aString)
|
||||
{
|
||||
const char * propname = nsFormControlHelper::GetHTMLPropertiesFileName();
|
||||
nsresult rv = NS_OK;
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
if (IsReset(type)) {
|
||||
if (type == NS_FORM_INPUT_RESET) {
|
||||
rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Reset").get(), aString);
|
||||
}
|
||||
else if (IsSubmit(type)) {
|
||||
else if (type == NS_FORM_INPUT_SUBMIT) {
|
||||
rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Submit").get(), aString);
|
||||
}
|
||||
else if (IsBrowse(type)) {
|
||||
else if (IsFileBrowseButton(type)) {
|
||||
rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Browse").get(), aString);
|
||||
}
|
||||
else {
|
||||
|
@ -525,7 +500,6 @@ nsGfxButtonControlFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|||
} else {
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
mDefaultValueWasChanged = PR_TRUE;
|
||||
|
||||
// defer to HTMLButtonControlFrame
|
||||
} else {
|
||||
|
@ -616,6 +590,29 @@ nsGfxButtonControlFrame::Reflow(nsIPresContext* aPresContext,
|
|||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
nsGfxButtonControlFrame::CalcNavQuirkSizing(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsString& aLabel,
|
||||
nsSize& aSize)
|
||||
{
|
||||
float p2t;
|
||||
float t2p;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
aPresContext->GetTwipsToPixels(&t2p);
|
||||
|
||||
// Get text size, round to nearest pixel, multiply by 3/2
|
||||
// XXX this algorithm seems suspect: rounding before multiply can't be good,
|
||||
// and 3/2 seems ... arbitrary
|
||||
nsFormControlHelper::GetTextSize(aPresContext, this,
|
||||
aLabel, aSize,
|
||||
aRendContext);
|
||||
aSize.width = NSToCoordRound(aSize.width * t2p);
|
||||
aSize.height = NSToCoordRound(aSize.height * t2p);
|
||||
aSize.width = NSIntPixelsToTwips(3 * aSize.width / 2, p2t);
|
||||
aSize.height = NSIntPixelsToTwips(3 * aSize.height / 2, p2t);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGfxButtonControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
|
|
|
@ -95,14 +95,6 @@ public:
|
|||
nsIContent * aContent,
|
||||
nsIFrame** aFrame);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD AddComputedBorderPaddingToDesiredSize(nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aSuggestedReflowState);
|
||||
NS_IMETHOD DoNavQuirksReflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus);
|
||||
NS_IMETHOD GetDefaultLabel(nsString& aLabel);
|
||||
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aNameSpaceID,
|
||||
|
@ -110,10 +102,21 @@ protected:
|
|||
PRInt32 aModType,
|
||||
PRInt32 aHint);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD AddComputedBorderPaddingToDesiredSize(nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aSuggestedReflowState);
|
||||
nsresult DoNavQuirksReflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus);
|
||||
void CalcNavQuirkSizing(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsString& aValue,
|
||||
nsSize& aSize);
|
||||
|
||||
virtual PRBool IsReset(PRInt32 type);
|
||||
virtual PRBool IsSubmit(PRInt32 type);
|
||||
virtual PRBool IsBrowse(PRInt32 type); // Browse button of file input
|
||||
nsresult GetDefaultLabel(nsString& aLabel);
|
||||
|
||||
PRBool IsFileBrowseButton(PRInt32 type); // Browse button of file input
|
||||
|
||||
private:
|
||||
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
|
||||
|
@ -122,8 +125,6 @@ private:
|
|||
nscoord mSuggestedWidth;
|
||||
nscoord mSuggestedHeight;
|
||||
nsCOMPtr<nsITextContent> mTextContent;
|
||||
|
||||
PRBool mDefaultValueWasChanged;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -204,23 +204,6 @@ NS_IMETHODIMP nsHTMLButtonControlFrame::GetAccessible(nsIAccessible** aAccessibl
|
|||
#endif
|
||||
|
||||
|
||||
void
|
||||
nsHTMLButtonControlFrame::GetDefaultLabel(nsString& aString)
|
||||
{
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
if (NS_FORM_BUTTON_BUTTON == type) {
|
||||
aString.Assign(NS_LITERAL_STRING("Button"));
|
||||
}
|
||||
else if (NS_FORM_BUTTON_RESET == type) {
|
||||
aString.Assign(NS_LITERAL_STRING("Reset"));
|
||||
}
|
||||
else if (NS_FORM_BUTTON_SUBMIT == type) {
|
||||
aString.Assign(NS_LITERAL_STRING("Submit"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLButtonControlFrame::GetType(PRInt32* aType) const
|
||||
{
|
||||
|
|
|
@ -147,9 +147,7 @@ public:
|
|||
nscoord aInnerWidth,
|
||||
nscoord aCharWidth) const;
|
||||
|
||||
void GetDefaultLabel(nsString& aLabel);
|
||||
|
||||
// nsIFormControlFrame
|
||||
// nsIFormControlFrame
|
||||
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAString& aValue);
|
||||
NS_IMETHOD GetProperty(nsIAtom* aName, nsAString& aValue);
|
||||
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
|
||||
|
|
|
@ -125,7 +125,8 @@
|
|||
#endif // IBMBIDI
|
||||
|
||||
#define DEFAULT_COLUMN_WIDTH 20
|
||||
#define GUESS_INPUT_SIZE 150 // 10 pixels wide
|
||||
// (10 pixels)
|
||||
#define GUESS_INPUT_SIZE 150
|
||||
|
||||
#include "nsContentCID.h"
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
@ -133,6 +134,10 @@ static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
|||
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
|
||||
static NS_DEFINE_CID(kFrameSelectionCID, NS_FRAMESELECTION_CID);
|
||||
|
||||
static const PRInt32 DEFAULT_COLS = 20;
|
||||
static const PRInt32 DEFAULT_ROWS = 1;
|
||||
static const PRInt32 DEFAULT_ROWS_TEXTAREA = 2;
|
||||
|
||||
static nsresult GetElementFactoryService(nsIElementFactory **aFactory)
|
||||
{
|
||||
nsresult rv(NS_OK);
|
||||
|
@ -1496,100 +1501,95 @@ PRBool nsTextControlFrame::IsPasswordTextControl() const
|
|||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextControlFrame::GetColRowSizeAttr(nsIFormControlFrame* aFrame,
|
||||
nsIAtom * aColSizeAttr,
|
||||
nsHTMLValue & aColSize,
|
||||
nsresult & aColStatus,
|
||||
nsIAtom * aRowSizeAttr,
|
||||
nsHTMLValue & aRowSize,
|
||||
nsresult & aRowStatus)
|
||||
PRInt32
|
||||
nsTextControlFrame::GetCols()
|
||||
{
|
||||
nsCOMPtr<nsIContent> iContent;
|
||||
aFrame->GetFormContent(*getter_AddRefs(iContent));
|
||||
nsCOMPtr<nsIHTMLContent> content = do_QueryInterface(mContent);
|
||||
NS_ASSERTION(content, "Content is not HTML content!");
|
||||
|
||||
nsCOMPtr<nsIHTMLContent> hContent(do_QueryInterface(iContent));
|
||||
|
||||
if (!hContent) {
|
||||
return NS_ERROR_FAILURE;
|
||||
if (IsTextArea()) {
|
||||
nsHTMLValue attr;
|
||||
nsresult rv = content->GetHTMLAttribute(nsHTMLAtoms::cols, attr);
|
||||
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
||||
PRInt32 cols = ((attr.GetUnit() == eHTMLUnit_Pixel)
|
||||
? attr.GetPixelValue() : attr.GetIntValue());
|
||||
// XXX why a default of 1 char, why hide it
|
||||
return (cols <= 0) ? 1 : cols;
|
||||
}
|
||||
} else {
|
||||
// Else we know (assume) it is an input with size attr
|
||||
nsHTMLValue attr;
|
||||
nsresult rv = content->GetHTMLAttribute(nsHTMLAtoms::size, attr);
|
||||
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
||||
PRInt32 cols = attr.GetIntValue();
|
||||
if (cols > 0) {
|
||||
return cols;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aColStatus = NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (aColSizeAttr) {
|
||||
aColStatus = hContent->GetHTMLAttribute(aColSizeAttr, aColSize);
|
||||
}
|
||||
|
||||
aRowStatus= NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (aRowSizeAttr) {
|
||||
aRowStatus = hContent->GetHTMLAttribute(aRowSizeAttr, aRowSize);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return DEFAULT_COLS;
|
||||
}
|
||||
|
||||
|
||||
PRInt32
|
||||
nsTextControlFrame::GetRows()
|
||||
{
|
||||
if (IsTextArea()) {
|
||||
nsCOMPtr<nsIHTMLContent> content = do_QueryInterface(mContent);
|
||||
NS_ASSERTION(content, "Content is not HTML content!");
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLValue attr;
|
||||
nsresult rv = content->GetHTMLAttribute(nsHTMLAtoms::rows, attr);
|
||||
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
||||
PRInt32 rows = attr.GetIntValue();
|
||||
return (rows <= 0) ? DEFAULT_ROWS_TEXTAREA : rows;
|
||||
}
|
||||
return DEFAULT_ROWS_TEXTAREA;
|
||||
}
|
||||
|
||||
return DEFAULT_ROWS;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsTextControlFrame::ReflowStandard(nsIPresContext* aPresContext,
|
||||
nsSize& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus,
|
||||
nsMargin& aBorder,
|
||||
nsMargin& aPadding)
|
||||
nsSize& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
{
|
||||
// get the css size and let the frame use or override it
|
||||
nsSize minSize;
|
||||
|
||||
PRBool usingDefaultSize = PR_FALSE;
|
||||
PRInt32 ignore;
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
|
||||
PRInt32 width = 0;
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE != GetSizeFromContent(&width)) {
|
||||
width = GetDefaultColumnWidth();
|
||||
usingDefaultSize = PR_TRUE;
|
||||
}
|
||||
nsInputDimensionSpec textSpec(nsnull, PR_FALSE, nsnull,
|
||||
nsnull, width,
|
||||
PR_FALSE, nsnull, 1);
|
||||
CalculateSizeStandard(aPresContext, aReflowState.rendContext, this,
|
||||
textSpec, aDesiredSize, minSize, ignore, aBorder, aPadding, usingDefaultSize);
|
||||
} else {
|
||||
nsInputDimensionSpec areaSpec(nsHTMLAtoms::cols, PR_FALSE, nsnull,
|
||||
nsnull, GetDefaultColumnWidth(),
|
||||
PR_FALSE, nsHTMLAtoms::rows, 1);
|
||||
CalculateSizeStandard(aPresContext, aReflowState.rendContext, this,
|
||||
areaSpec, aDesiredSize, minSize, ignore, aBorder, aPadding, usingDefaultSize);
|
||||
}
|
||||
CalculateSizeStandard(aPresContext, aReflowState.rendContext, aDesiredSize,
|
||||
minSize);
|
||||
|
||||
// CalculateSize makes calls in the nsFormControlHelper that figures
|
||||
// out the entire size of the control when in NavQuirks mode. For the
|
||||
// textarea, this means the scrollbar sizes hav already been added to
|
||||
// its overall size and do not need to be added here.
|
||||
if (NS_FORM_TEXTAREA == type) {
|
||||
float p2t;
|
||||
// Add in the size of the scrollbars for textarea
|
||||
if (IsTextArea()) {
|
||||
float p2t;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
|
||||
nscoord scrollbarWidth = 0;
|
||||
nscoord scrollbarHeight = 0;
|
||||
float scale;
|
||||
nsCOMPtr<nsIDeviceContext> dx;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dx));
|
||||
if (dx) {
|
||||
if (dx) {
|
||||
float scale;
|
||||
dx->GetCanonicalPixelScale(scale);
|
||||
|
||||
float sbWidth;
|
||||
float sbHeight;
|
||||
dx->GetCanonicalPixelScale(scale);
|
||||
dx->GetScrollBarDimensions(sbWidth, sbHeight);
|
||||
scrollbarWidth = PRInt32(sbWidth * scale);
|
||||
scrollbarHeight = PRInt32(sbHeight * scale);
|
||||
} else {
|
||||
NS_WARNING("Dude! No DeviceContext! Not cool!");
|
||||
scrollbarWidth = nsFormControlFrame::GetScrollbarWidth(p2t);
|
||||
scrollbarHeight = scrollbarWidth;
|
||||
}
|
||||
|
||||
aDesiredSize.height += scrollbarHeight;
|
||||
minSize.height += scrollbarHeight;
|
||||
|
||||
aDesiredSize.width += scrollbarWidth;
|
||||
minSize.width += scrollbarWidth;
|
||||
}
|
||||
|
@ -1597,51 +1597,29 @@ nsTextControlFrame::ReflowStandard(nsIPresContext* aPresContext,
|
|||
aDesiredSize.height += aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom;
|
||||
|
||||
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRInt32
|
||||
nsTextControlFrame::CalculateSizeStandard (nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFormControlFrame* aFrame,
|
||||
nsInputDimensionSpec& aSpec,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize,
|
||||
nscoord& aRowHeight,
|
||||
nsMargin& aBorder,
|
||||
nsMargin& aPadding,
|
||||
PRBool aIsUsingDefSize)
|
||||
void
|
||||
nsTextControlFrame::CalculateSizeStandard(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize)
|
||||
{
|
||||
nscoord charWidth = 0;
|
||||
aDesiredSize.width = CSS_NOTSET;
|
||||
aDesiredSize.height = CSS_NOTSET;
|
||||
|
||||
nsHTMLValue colAttr;
|
||||
nsresult colStatus;
|
||||
nsHTMLValue rowAttr;
|
||||
nsresult rowStatus;
|
||||
if (NS_ERROR_FAILURE == GetColRowSizeAttr(aFrame,
|
||||
aSpec.mColSizeAttr, colAttr, colStatus,
|
||||
aSpec.mRowSizeAttr, rowAttr, rowStatus)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float p2t;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
|
||||
nscoord fontHeight = 0;
|
||||
// get leading
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
nsresult res = nsFormControlHelper::GetFrameFontFM(aPresContext, aFrame, getter_AddRefs(fontMet));
|
||||
if (NS_SUCCEEDED(res) && fontMet) {
|
||||
nsresult rv = nsFormControlHelper::GetFrameFontFM(aPresContext, this, getter_AddRefs(fontMet));
|
||||
if (NS_SUCCEEDED(rv) && fontMet) {
|
||||
aRendContext->SetFont(fontMet);
|
||||
fontMet->GetHeight(fontHeight);
|
||||
aDesiredSize.height = fontHeight;
|
||||
} else {
|
||||
aDesiredSize.height = GUESS_INPUT_SIZE; // punt
|
||||
NS_WARNING("No font metrics found for textarea / input! Something is fishy.");
|
||||
fontHeight = GUESS_INPUT_SIZE;
|
||||
}
|
||||
|
||||
// Internal padding is necessary for better matching IE's width
|
||||
|
@ -1654,12 +1632,18 @@ nsTextControlFrame::CalculateSizeStandard (nsIPresContext* aPresContext,
|
|||
// 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.
|
||||
|
||||
float p2t;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
|
||||
nscoord charWidth = 0;
|
||||
|
||||
#if defined(_WIN32) || defined(XP_OS2)
|
||||
fontMet->GetAveCharWidth(charWidth);
|
||||
|
||||
// Get frame font
|
||||
const nsFont * font = nsnull;
|
||||
if (NS_SUCCEEDED(aFrame->GetFont(aPresContext, font))) {
|
||||
if (NS_SUCCEEDED(this->GetFont(aPresContext, font))) {
|
||||
// To better match IE, take the size (in twips) and remove 4 pixels
|
||||
// add this on as additional padding
|
||||
internalPadding = PR_MAX(font->size - NSToCoordRound(4 * p2t), 0);
|
||||
|
@ -1682,59 +1666,21 @@ nsTextControlFrame::CalculateSizeStandard (nsIPresContext* aPresContext,
|
|||
nscoord onePixel = NSIntPixelsToTwips(1, p2t); // get the rounding right
|
||||
charWidth = nscoord((float(charWidth) / float(onePixel)) + 0.5)*onePixel;
|
||||
#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 * charWidth;
|
||||
} else {
|
||||
aDesiredSize.width = aSpec.mColDefaultSize * charWidth;
|
||||
}
|
||||
|
||||
// Now add the extra internal padding on
|
||||
// Set the width equal to the width in characters
|
||||
aDesiredSize.width = GetCols() * charWidth;
|
||||
// Now add the extra padding on (so that small input sizes work well)
|
||||
aDesiredSize.width += internalPadding;
|
||||
|
||||
aRowHeight = aDesiredSize.height;
|
||||
// Set the height equal to total number of rows (times the height of each
|
||||
// line, of course)
|
||||
aDesiredSize.height = fontHeight * GetRows();
|
||||
|
||||
// Set minimum size equal to desired size. We are form controls. We are Gods
|
||||
// among elements. We do not yield for anybody, not even a table cell. None
|
||||
// shall pass.
|
||||
aMinSize.width = aDesiredSize.width;
|
||||
aMinSize.height = aDesiredSize.height;
|
||||
PRInt32 numRows = 0;
|
||||
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == rowStatus) { // row attr will provide height
|
||||
PRInt32 rowAttrInt = ((rowAttr.GetUnit() == eHTMLUnit_Pixel)
|
||||
? rowAttr.GetPixelValue() : rowAttr.GetIntValue());
|
||||
numRows = (rowAttrInt > 0) ? rowAttrInt : 1;
|
||||
aDesiredSize.height = aDesiredSize.height * numRows;
|
||||
} else {
|
||||
aDesiredSize.height = aDesiredSize.height * aSpec.mRowDefaultSize;
|
||||
}
|
||||
|
||||
numRows = (aRowHeight > 0) ? (aDesiredSize.height / aRowHeight) : 0;
|
||||
if (numRows == 1) {
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
if (NS_FORM_TEXTAREA == type) {
|
||||
aDesiredSize.height += fontHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// if we are not using the default size
|
||||
// then make the minimum size the size we want to be
|
||||
if (!aIsUsingDefSize) {
|
||||
aMinSize.width = aDesiredSize.width;
|
||||
aMinSize.height = aDesiredSize.height;
|
||||
}
|
||||
|
||||
return numRows;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2046,56 +1992,27 @@ nsTextControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize the plaintext editor
|
||||
nsCOMPtr<nsIPlaintextEditor> textEditor(do_QueryInterface(mEditor));
|
||||
if (textEditor)
|
||||
{
|
||||
nsHTMLValue colAttr;
|
||||
nsresult colStatus;
|
||||
nsHTMLValue rowAttr;
|
||||
nsresult rowStatus;
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
nsInputDimensionSpec *spec;
|
||||
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
|
||||
PRInt32 width = 0;
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE != GetSizeFromContent(&width)) {
|
||||
width = GetDefaultColumnWidth();
|
||||
if (textEditor) {
|
||||
// Set up wrapping
|
||||
if (IsTextArea()) {
|
||||
// wrap=off means -1 for wrap width no matter what cols is
|
||||
nsFormControlHelper::nsHTMLTextWrap wrapProp;
|
||||
nsFormControlHelper::GetWrapPropertyEnum(mContent, wrapProp);
|
||||
if (wrapProp == nsFormControlHelper::eHTMLTextWrap_Off) {
|
||||
// do not wrap when wrap=off
|
||||
textEditor->SetWrapWidth(-1);
|
||||
} else {
|
||||
// Set wrapping normally otherwise
|
||||
textEditor->SetWrapWidth(GetCols());
|
||||
}
|
||||
spec = new nsInputDimensionSpec(nsnull, PR_FALSE, nsnull,
|
||||
nsnull, width,
|
||||
PR_FALSE, nsnull, 1);
|
||||
} else {
|
||||
spec = new nsInputDimensionSpec(nsHTMLAtoms::cols, PR_FALSE, nsnull,
|
||||
nsnull, GetDefaultColumnWidth(),
|
||||
PR_FALSE, nsHTMLAtoms::rows, 1);
|
||||
}
|
||||
if (spec)
|
||||
{
|
||||
if (NS_FAILED(GetColRowSizeAttr(this,
|
||||
spec->mColSizeAttr, colAttr, colStatus,
|
||||
spec->mRowSizeAttr, rowAttr, rowStatus)))
|
||||
return NS_ERROR_FAILURE;
|
||||
PRInt32 col =-1;
|
||||
if (!(colAttr.GetUnit() == eHTMLUnit_Null))
|
||||
{
|
||||
col = ((colAttr.GetUnit() == eHTMLUnit_Pixel) ? colAttr.GetPixelValue() : colAttr.GetIntValue());
|
||||
col = (col <= 0) ? 1 : col; // XXX why a default of 1 char, why hide it
|
||||
}
|
||||
if (type == NS_FORM_TEXTAREA)
|
||||
{
|
||||
nsFormControlHelper::nsHTMLTextWrap wrapProp;
|
||||
nsresult rv = nsFormControlHelper::GetWrapPropertyEnum(mContent, wrapProp);
|
||||
// do not wrap at the cols attribute when wrap=off
|
||||
if ((rv != NS_CONTENT_ATTR_NOT_THERE) &&
|
||||
(wrapProp == nsFormControlHelper::eHTMLTextWrap_Off))
|
||||
{
|
||||
col = -1;
|
||||
}
|
||||
}
|
||||
textEditor->SetWrapWidth(col);
|
||||
delete spec;
|
||||
// Never wrap non-textareas
|
||||
textEditor->SetWrapWidth(-1);
|
||||
}
|
||||
|
||||
|
||||
// Set max text field length
|
||||
PRInt32 maxLength;
|
||||
rv = GetMaxLength(&maxLength);
|
||||
|
@ -2286,35 +2203,21 @@ nsTextControlFrame::GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize)
|
|||
if (collapsed)
|
||||
return NS_OK;
|
||||
|
||||
nsIPresContext* aPresContext = aState.GetPresContext();
|
||||
const nsHTMLReflowState* aReflowState = aState.GetReflowState();
|
||||
nsIPresContext* presContext = aState.GetPresContext();
|
||||
const nsHTMLReflowState* reflowState = aState.GetReflowState();
|
||||
nsSize styleSize(CSS_NOTSET,CSS_NOTSET);
|
||||
nsFormControlFrame::GetStyleSize(aPresContext, *aReflowState, styleSize);
|
||||
nsFormControlFrame::GetStyleSize(presContext, *reflowState, styleSize);
|
||||
|
||||
if (!aReflowState)
|
||||
if (!reflowState)
|
||||
return NS_OK;
|
||||
|
||||
InitEditor();
|
||||
|
||||
if (mState & NS_FRAME_FIRST_REFLOW)
|
||||
mNotifyOnInput = PR_TRUE;//its ok to notify now. all has been prepared.
|
||||
mNotifyOnInput = PR_TRUE; //its ok to notify now. all has been prepared.
|
||||
|
||||
nsReflowStatus aStatus;
|
||||
nsMargin border;
|
||||
border.SizeTo(0, 0, 0, 0);
|
||||
nsMargin padding;
|
||||
padding.SizeTo(0, 0, 0, 0);
|
||||
|
||||
// Get the CSS border
|
||||
const nsStyleBorder* borderStyle;
|
||||
const nsStylePadding* paddingStyle;
|
||||
GetStyleData(eStyleStruct_Border, (const nsStyleStruct *&)borderStyle);
|
||||
GetStyleData(eStyleStruct_Padding, (const nsStyleStruct *&)paddingStyle);
|
||||
borderStyle->CalcBorderFor(this, border);
|
||||
paddingStyle->CalcPaddingFor(this, padding);
|
||||
|
||||
nsresult rv;
|
||||
rv = ReflowStandard(aPresContext, aSize, *aReflowState, aStatus, border, padding);
|
||||
nsReflowStatus status;
|
||||
ReflowStandard(presContext, aSize, *reflowState, status);
|
||||
AddInset(aSize);
|
||||
|
||||
mPrefSize = aSize;
|
||||
|
@ -2376,39 +2279,6 @@ nsTextControlFrame::GetType(PRInt32* aType) const
|
|||
return nsFormControlHelper::GetType(mContent, aType);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextControlFrame::GetSizeFromContent(PRInt32* aSize) const
|
||||
{
|
||||
*aSize = -1;
|
||||
nsresult result = NS_CONTENT_ATTR_NOT_THERE;
|
||||
nsCOMPtr<nsIHTMLContent> content(do_QueryInterface(mContent));
|
||||
|
||||
if (content) {
|
||||
nsHTMLValue value;
|
||||
result = content->GetHTMLAttribute(nsHTMLAtoms::size, value);
|
||||
if (eHTMLUnit_Integer == value.GetUnit()) {
|
||||
*aSize = value.GetIntValue();
|
||||
}
|
||||
}
|
||||
if (*aSize < 1) {
|
||||
// This is part of bug 46224
|
||||
// when we can get a PresContent (may be cache it)
|
||||
// then we can check the compatibility mode
|
||||
#ifdef FUTURE_ADDITIONAL_FIX_FOR_46224
|
||||
nsCompatibility mode;
|
||||
nsFormControlHelper::GetFormCompatibilityMode(aPresContext, mode);
|
||||
if (eCompatibility_NavQuirks == mode) {
|
||||
*aSize = 1;
|
||||
} else {
|
||||
*aSize = 20;
|
||||
}
|
||||
#else
|
||||
*aSize = 20; // use '1' to be compatable with Nav 4.x, Use '20' to be compatable with IE
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void nsTextControlFrame::SetFocus(PRBool aOn , PRBool aRepaint){}
|
||||
|
||||
void nsTextControlFrame::ScrollIntoView(nsIPresContext* aPresContext)
|
||||
|
@ -2973,9 +2843,7 @@ NS_IMETHODIMP
|
|||
nsTextControlFrame::GetText(nsString* aText)
|
||||
{
|
||||
nsresult rv = NS_CONTENT_ATTR_NOT_THERE;
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
|
||||
if (IsSingleLineTextControl()) {
|
||||
// If we're going to remove newlines anyway, ignore the wrap property
|
||||
GetValue(*aText, PR_TRUE);
|
||||
RemoveNewlines(*aText);
|
||||
|
|
|
@ -66,9 +66,9 @@ class nsIAccessible;
|
|||
|
||||
|
||||
class nsTextControlFrame : public nsStackFrame,
|
||||
public nsIAnonymousContentCreator,
|
||||
public nsITextControlFrame,
|
||||
public nsIScrollableViewProvider
|
||||
public nsIAnonymousContentCreator,
|
||||
public nsITextControlFrame,
|
||||
public nsIScrollableViewProvider
|
||||
|
||||
{
|
||||
public:
|
||||
|
@ -249,33 +249,27 @@ protected:
|
|||
|
||||
//helper methods
|
||||
nsresult GetSizeFromContent(PRInt32* aSize) const;
|
||||
PRInt32 GetDefaultColumnWidth() const { return (PRInt32)(20); } // this was DEFAULT_PIXEL_WIDTH
|
||||
|
||||
nsresult GetColRowSizeAttr(nsIFormControlFrame* aFrame,
|
||||
nsIAtom * aColSizeAttr,
|
||||
nsHTMLValue & aColSize,
|
||||
nsresult & aColStatus,
|
||||
nsIAtom * aRowSizeAttr,
|
||||
nsHTMLValue & aRowSize,
|
||||
nsresult & aRowStatus);
|
||||
/**
|
||||
* Get the cols attribute (if textarea) or a default
|
||||
* @return the number of columns to use
|
||||
*/
|
||||
PRInt32 GetCols();
|
||||
/**
|
||||
* Get the rows attribute (if textarea) or a default
|
||||
* @return the number of rows to use
|
||||
*/
|
||||
PRInt32 GetRows();
|
||||
|
||||
NS_IMETHOD ReflowStandard(nsIPresContext* aPresContext,
|
||||
nsSize& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus,
|
||||
nsMargin& aBorder,
|
||||
nsMargin& aPadding);
|
||||
void ReflowStandard(nsIPresContext* aPresContext,
|
||||
nsSize& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus);
|
||||
|
||||
PRInt32 CalculateSizeStandard (nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFormControlFrame* aFrame,
|
||||
nsInputDimensionSpec& aSpec,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize,
|
||||
nscoord& aRowHeight,
|
||||
nsMargin& aBorder,
|
||||
nsMargin& aPadding,
|
||||
PRBool aIsUsingDefSize);
|
||||
void CalculateSizeStandard(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize);
|
||||
|
||||
NS_IMETHOD CreateFrameFor(nsIPresContext* aPresContext,
|
||||
nsIContent * aContent,
|
||||
|
|
|
@ -78,12 +78,9 @@ static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
|||
|
||||
|
||||
// For figuring out the "WRAP" property
|
||||
// See GetWrapPropertyEnum for details
|
||||
#define kTextControl_Wrap_Soft "SOFT"
|
||||
#define kTextControl_Wrap_Virtual "VIRTUAL" // "virtual" is a synonym for "soft"
|
||||
#define kTextControl_Wrap_Hard "HARD"
|
||||
#define kTextControl_Wrap_Physical "PHYSICAL" // "physical" should be a synonym
|
||||
// for "hard" but NS 4.x and IE make
|
||||
// it a synonym for "soft"
|
||||
#define kTextControl_Wrap_Off "OFF"
|
||||
|
||||
|
||||
|
@ -186,155 +183,27 @@ nsFormControlHelper::GetWrapProperty(nsIContent * aContent, nsString &aOutValue)
|
|||
nsresult
|
||||
nsFormControlHelper::GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap& aWrapProp)
|
||||
{
|
||||
nsString wrap;
|
||||
aWrapProp = eHTMLTextWrap_Off; // the default
|
||||
// soft is the default; "physical" defaults to soft as well because all other
|
||||
// browsers treat it that way and there is no real reason to maintain physical
|
||||
// and virtual as separate entities if no one else does. Only hard and off
|
||||
// do anything different.
|
||||
aWrapProp = eHTMLTextWrap_Soft; // the default
|
||||
|
||||
nsresult result = GetWrapProperty(aContent, wrap);
|
||||
nsAutoString wrap;
|
||||
nsresult rv = GetWrapProperty(aContent, wrap);
|
||||
|
||||
if (NS_CONTENT_ATTR_NOT_THERE != result) {
|
||||
if (rv != NS_CONTENT_ATTR_NOT_THERE) {
|
||||
|
||||
if (wrap.EqualsIgnoreCase(kTextControl_Wrap_Hard)) {
|
||||
aWrapProp = eHTMLTextWrap_Hard;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (wrap.EqualsIgnoreCase(kTextControl_Wrap_Soft) ||
|
||||
wrap.EqualsIgnoreCase(kTextControl_Wrap_Virtual) ||
|
||||
wrap.EqualsIgnoreCase(kTextControl_Wrap_Physical)) {
|
||||
aWrapProp = eHTMLTextWrap_Soft;
|
||||
return result;
|
||||
} else if (wrap.EqualsIgnoreCase(kTextControl_Wrap_Off)) {
|
||||
aWrapProp = eHTMLTextWrap_Off;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nscoord
|
||||
nsFormControlHelper::CalcNavQuirkSizing(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFontMetrics* aFontMet,
|
||||
nsIFormControlFrame* aFrame,
|
||||
nsInputDimensionSpec& aSpec,
|
||||
nsSize& aSize)
|
||||
{
|
||||
float p2t;
|
||||
float t2p;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
aPresContext->GetTwipsToPixels(&t2p);
|
||||
|
||||
nscoord ascent;
|
||||
nscoord descent;
|
||||
nscoord maxCharWidth;
|
||||
aFontMet->GetMaxAscent(ascent);
|
||||
aFontMet->GetMaxDescent(descent);
|
||||
aFontMet->GetMaxAdvance(maxCharWidth);
|
||||
|
||||
ascent = NSToCoordRound(ascent * t2p);
|
||||
descent = NSToCoordRound(descent * t2p);
|
||||
maxCharWidth = NSToCoordRound(maxCharWidth * t2p);
|
||||
|
||||
char char1, char2;
|
||||
GetRepChars(char1, char2);
|
||||
|
||||
nscoord char1Width, char2Width;
|
||||
aRendContext->GetWidth(char1, char1Width);
|
||||
aRendContext->GetWidth(char2, char2Width);
|
||||
char1Width = NSToCoordRound(char1Width * t2p);
|
||||
char2Width = NSToCoordRound(char2Width * t2p);
|
||||
|
||||
// Nav Quirk Calculation for TextField
|
||||
PRInt32 type;
|
||||
aFrame->GetType(&type);
|
||||
nscoord width;
|
||||
nscoord hgt;
|
||||
nscoord height;
|
||||
nscoord average = 0;
|
||||
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
|
||||
average = (char1Width + char2Width) / 2;
|
||||
width = maxCharWidth;
|
||||
hgt = ascent + descent;
|
||||
height = hgt + (hgt / 2);
|
||||
width += aSpec.mColDefaultSize * average;
|
||||
} else if (NS_FORM_TEXTAREA == type) {
|
||||
nscoord lines = 1;
|
||||
nscoord scrollbarWidth = 0;
|
||||
nscoord scrollbarHeight = 0;
|
||||
float scale;
|
||||
nsCOMPtr<nsIDeviceContext> dx;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dx));
|
||||
if (dx) {
|
||||
float sbWidth;
|
||||
float sbHeight;
|
||||
dx->GetCanonicalPixelScale(scale);
|
||||
dx->GetScrollBarDimensions(sbWidth, sbHeight);
|
||||
scrollbarWidth = PRInt32(sbWidth * scale);
|
||||
scrollbarHeight = PRInt32(sbHeight * scale);
|
||||
scrollbarWidth = NSToCoordRound(scrollbarWidth * t2p);
|
||||
scrollbarHeight = NSToCoordRound(scrollbarHeight * t2p);
|
||||
} else {
|
||||
NS_ASSERTION(0, "Couldn't get the device context");
|
||||
scrollbarWidth = 16;
|
||||
scrollbarHeight = 16;
|
||||
}
|
||||
nsIContent * content;
|
||||
aFrame->GetFormContent(content);
|
||||
nsCOMPtr<nsIHTMLContent> hContent(do_QueryInterface(content));
|
||||
|
||||
// determine the height
|
||||
nsHTMLValue rowAttr;
|
||||
nsresult rowStatus = NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (nsnull != aSpec.mRowSizeAttr) {
|
||||
rowStatus = hContent->GetHTMLAttribute(aSpec.mRowSizeAttr, rowAttr);
|
||||
}
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == rowStatus) { // row attr will provide height
|
||||
PRInt32 rowAttrInt = ((rowAttr.GetUnit() == eHTMLUnit_Pixel)
|
||||
? rowAttr.GetPixelValue() : rowAttr.GetIntValue());
|
||||
lines = (rowAttrInt > 0) ? rowAttrInt : 1;
|
||||
} else {
|
||||
lines = aSpec.mRowDefaultSize;
|
||||
}
|
||||
|
||||
average = (char1Width + char2Width) / 2;
|
||||
width = ((aSpec.mColDefaultSize + 1) * average) + scrollbarWidth;
|
||||
hgt = ascent + descent;
|
||||
height = (lines + 1) * hgt;
|
||||
|
||||
// then if not word wrapping
|
||||
nsHTMLTextWrap wrapProp;
|
||||
nsFormControlHelper::GetWrapPropertyEnum(content, wrapProp);
|
||||
if (wrapProp == eHTMLTextWrap_Off) {
|
||||
height += scrollbarHeight;
|
||||
}
|
||||
NS_RELEASE(content);
|
||||
} else if (NS_FORM_INPUT_BUTTON == type ||
|
||||
NS_FORM_INPUT_SUBMIT == type ||
|
||||
NS_FORM_INPUT_RESET == type) {
|
||||
GetTextSize(aPresContext, aFrame, *aSpec.mColDefaultValue, aSize, aRendContext);
|
||||
aSize.width = NSToCoordRound(aSize.width * t2p);
|
||||
aSize.height = NSToCoordRound(aSize.height * t2p);
|
||||
width = 3 * aSize.width / 2;
|
||||
height = 3 * aSize.height / 2;
|
||||
} else if (NS_FORM_INPUT_HIDDEN == type) {
|
||||
width = 0;
|
||||
height = 0;
|
||||
} else {
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_rodsXXXX
|
||||
printf("********* Nav Quirks: %d,%d max:%d average:%d ascent:%d descent:%d\n",
|
||||
width, height, maxCharWidth, average, ascent, descent);
|
||||
#endif
|
||||
|
||||
aSize.width = NSIntPixelsToTwips(width, p2t);
|
||||
aSize.height = NSIntPixelsToTwips(height, p2t);
|
||||
average = NSIntPixelsToTwips(average, p2t);
|
||||
|
||||
return average;
|
||||
|
||||
}
|
||||
|
||||
nscoord
|
||||
nscoord
|
||||
nsFormControlHelper::GetTextSize(nsIPresContext* aPresContext, nsIFormControlFrame* aFrame,
|
||||
const nsString& aString, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext)
|
||||
|
@ -379,138 +248,6 @@ nsFormControlHelper::GetTextSize(nsIPresContext* aPresContext, nsIFormControlFra
|
|||
return GetTextSize(aPresContext, aFrame, val, aSize, aRendContext);
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsFormControlHelper::CalculateSize (nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFormControlFrame* aFrame,
|
||||
const nsSize& aCSSSize,
|
||||
nsInputDimensionSpec& aSpec,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize,
|
||||
PRBool& aWidthExplicit,
|
||||
PRBool& aHeightExplicit,
|
||||
nscoord& aRowHeight)
|
||||
{
|
||||
nscoord charWidth = 0;
|
||||
PRInt32 numRows = ATTR_NOTSET;
|
||||
aWidthExplicit = PR_FALSE;
|
||||
aHeightExplicit = PR_FALSE;
|
||||
|
||||
aDesiredSize.width = CSS_NOTSET;
|
||||
aDesiredSize.height = CSS_NOTSET;
|
||||
|
||||
nsCOMPtr<nsIContent> iContent;
|
||||
aFrame->GetFormContent(*getter_AddRefs(iContent));
|
||||
|
||||
nsCOMPtr<nsIHTMLContent> hContent(do_QueryInterface(iContent));
|
||||
|
||||
if (!hContent) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsAutoString valAttr;
|
||||
nsresult valStatus = NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (nsnull != aSpec.mColValueAttr) {
|
||||
valStatus = hContent->GetAttr(kNameSpaceID_None, aSpec.mColValueAttr,
|
||||
valAttr);
|
||||
}
|
||||
nsHTMLValue colAttr;
|
||||
nsresult colStatus = NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (nsnull != aSpec.mColSizeAttr) {
|
||||
colStatus = hContent->GetHTMLAttribute(aSpec.mColSizeAttr, colAttr);
|
||||
}
|
||||
float p2t;
|
||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||
|
||||
#if 0
|
||||
// determine if it is percentage based width, height
|
||||
PRBool percentageWidth = PR_FALSE;
|
||||
PRBool percentageHeight = PR_FALSE;
|
||||
|
||||
const nsStylePosition* pos;
|
||||
nsIFrame* iFrame = nsnull;
|
||||
nsresult rv = aFrame->QueryInterface(NS_GET_IID(nsIFrame), (void**)&iFrame);
|
||||
if ((NS_OK == rv) && (nsnull != iFrame)) {
|
||||
iFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&)pos);
|
||||
if (eStyleUnit_Percent == pos->mWidth.GetUnit()) {
|
||||
percentageWidth = PR_TRUE;
|
||||
}
|
||||
if (eStyleUnit_Percent == pos->mWidth.GetUnit()) {
|
||||
percentageHeight = PR_TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// 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());
|
||||
if (aSpec.mColSizeAttrInPixels) {
|
||||
// need to set charWidth and aDesiredSize.height
|
||||
charWidth = GetTextSize(aPresContext, aFrame, 1, aDesiredSize, aRendContext);
|
||||
col = (col <= 0) ? 15 : col; // XXX why a default of 15 pixels, why hide it
|
||||
// XXX this conflicts with a default of 20 found in nsTextControlFrame.
|
||||
aDesiredSize.width = NSIntPixelsToTwips(col, p2t);
|
||||
} else {
|
||||
col = (col <= 0) ? 1 : col; // XXX why a default of 1 char, why hide it
|
||||
}
|
||||
if (aSpec.mColSizeAttrInPixels) {
|
||||
aWidthExplicit = PR_TRUE;
|
||||
}
|
||||
aMinSize.width = aDesiredSize.width;
|
||||
} else {
|
||||
// set aDesiredSize for height calculation below. CSS may override width
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == valStatus) { // use width of initial value
|
||||
charWidth = GetTextSize(aPresContext, aFrame, valAttr, aDesiredSize, aRendContext);
|
||||
} else if (aSpec.mColDefaultValue) { // use default value
|
||||
charWidth = GetTextSize(aPresContext, aFrame, *aSpec.mColDefaultValue, aDesiredSize, aRendContext);
|
||||
} else if (aSpec.mColDefaultSizeInPixels) { // use default width in pixels
|
||||
charWidth = GetTextSize(aPresContext, aFrame, 1, aDesiredSize, aRendContext);
|
||||
aDesiredSize.width = aSpec.mColDefaultSize;
|
||||
} else { // use default width in num characters
|
||||
charWidth = GetTextSize(aPresContext, aFrame, aSpec.mColDefaultSize, aDesiredSize, aRendContext);
|
||||
}
|
||||
aMinSize.width = aDesiredSize.width;
|
||||
if (CSS_NOTSET != aCSSSize.width) { // css provides width
|
||||
NS_ASSERTION(aCSSSize.width >= 0, "form control's computed width is < 0");
|
||||
if (NS_INTRINSICSIZE != aCSSSize.width) {
|
||||
aDesiredSize.width = PR_MAX(aDesiredSize.width,aCSSSize.width);
|
||||
aWidthExplicit = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
aRowHeight = aDesiredSize.height;
|
||||
aMinSize.height = aDesiredSize.height;
|
||||
|
||||
// determine the height
|
||||
nsHTMLValue rowAttr;
|
||||
nsresult rowStatus = NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (nsnull != aSpec.mRowSizeAttr) {
|
||||
rowStatus = hContent->GetHTMLAttribute(aSpec.mRowSizeAttr, rowAttr);
|
||||
}
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == rowStatus) { // row attr will provide height
|
||||
PRInt32 rowAttrInt = ((rowAttr.GetUnit() == eHTMLUnit_Pixel)
|
||||
? rowAttr.GetPixelValue() : rowAttr.GetIntValue());
|
||||
numRows = (rowAttrInt > 0) ? rowAttrInt : 1;
|
||||
aDesiredSize.height = aDesiredSize.height * numRows;
|
||||
} else {
|
||||
aDesiredSize.height = aDesiredSize.height * aSpec.mRowDefaultSize;
|
||||
if (CSS_NOTSET != aCSSSize.height) { // css provides height
|
||||
NS_ASSERTION(aCSSSize.height > 0, "form control's computed height is <= 0");
|
||||
if (NS_INTRINSICSIZE != aCSSSize.height) {
|
||||
aDesiredSize.height = PR_MAX(aDesiredSize.height,aCSSSize.height);
|
||||
aHeightExplicit = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ATTR_NOTSET == numRows) {
|
||||
numRows = (aRowHeight > 0) ? (aDesiredSize.height / aRowHeight) : 0;
|
||||
}
|
||||
|
||||
return numRows;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsFormControlHelper::GetFont(nsIFormControlFrame * aFormFrame,
|
||||
nsIPresContext* aPresContext,
|
||||
|
|
|
@ -73,33 +73,6 @@ enum nsMouseState {
|
|||
eMouseUp
|
||||
};
|
||||
|
||||
struct nsInputDimensionSpec
|
||||
{
|
||||
nsIAtom* mColSizeAttr; // attribute used to determine width
|
||||
PRBool mColSizeAttrInPixels; // is attribute value in pixels (otherwise num chars)
|
||||
nsIAtom* mColValueAttr; // attribute used to get value to determine size
|
||||
// if not determined above
|
||||
nsString* mColDefaultValue; // default value if not determined above
|
||||
nscoord mColDefaultSize; // default width if not determined above
|
||||
PRBool mColDefaultSizeInPixels; // is default width in pixels (otherswise num chars)
|
||||
nsIAtom* mRowSizeAttr; // attribute used to determine height
|
||||
nscoord mRowDefaultSize; // default height if not determined above
|
||||
|
||||
nsInputDimensionSpec(nsIAtom* aColSizeAttr, PRBool aColSizeAttrInPixels,
|
||||
nsIAtom* aColValueAttr, nsString* aColDefaultValue,
|
||||
nscoord aColDefaultSize, PRBool aColDefaultSizeInPixels,
|
||||
nsIAtom* aRowSizeAttr, nscoord aRowDefaultSize)
|
||||
: mColSizeAttr(aColSizeAttr), mColSizeAttrInPixels(aColSizeAttrInPixels),
|
||||
mColValueAttr(aColValueAttr),
|
||||
mColDefaultValue(aColDefaultValue), mColDefaultSize(aColDefaultSize),
|
||||
mColDefaultSizeInPixels(aColDefaultSizeInPixels),
|
||||
mRowSizeAttr(aRowSizeAttr), mRowDefaultSize(aRowDefaultSize)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* nsFormControlHelper is the base class for frames of form controls. It
|
||||
|
@ -112,17 +85,6 @@ class nsFormControlHelper
|
|||
public:
|
||||
|
||||
|
||||
static nscoord CalculateSize (nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFormControlFrame* aFrame,
|
||||
const nsSize& aCSSSize,
|
||||
nsInputDimensionSpec& aDimensionSpec,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize,
|
||||
PRBool& aWidthExplicit,
|
||||
PRBool& aHeightExplicit,
|
||||
nscoord& aRowSize);
|
||||
|
||||
static nscoord GetTextSize(nsIPresContext* aContext, nsIFormControlFrame* aFrame,
|
||||
const nsString& aString, nsSize& aSize,
|
||||
nsIRenderingContext *aRendContext);
|
||||
|
@ -142,13 +104,6 @@ public:
|
|||
nsIFormControlFrame * aFrame,
|
||||
nsIFontMetrics** aFontMet);
|
||||
|
||||
static nscoord CalcNavQuirkSizing(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFontMetrics* aFontMet,
|
||||
nsIFormControlFrame* aFrame,
|
||||
nsInputDimensionSpec& aSpec,
|
||||
nsSize& aSize);
|
||||
|
||||
static void ForceDrawFrame(nsIPresContext* aPresContext, nsIFrame * aFrame);
|
||||
|
||||
// Map platform line endings (CR, CRLF, LF) to DOM line endings (LF)
|
||||
|
|
|
@ -65,7 +65,6 @@ nsGfxButtonControlFrame::nsGfxButtonControlFrame()
|
|||
{
|
||||
mSuggestedWidth = kSuggestedNotSet;
|
||||
mSuggestedHeight = kSuggestedNotSet;
|
||||
mDefaultValueWasChanged = PR_FALSE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -92,26 +91,6 @@ nsGfxButtonControlFrame::GetFrameType(nsIAtom** aType) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsGfxButtonControlFrame::IsReset(PRInt32 type)
|
||||
{
|
||||
if (NS_FORM_INPUT_RESET == type) {
|
||||
return PR_TRUE;
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsGfxButtonControlFrame::IsSubmit(PRInt32 type)
|
||||
{
|
||||
if (NS_FORM_INPUT_SUBMIT == type) {
|
||||
return PR_TRUE;
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Special check for the browse button of a file input.
|
||||
//
|
||||
// Since this is actually type "NS_FORM_INPUT_BUTTON", we
|
||||
|
@ -120,7 +99,7 @@ nsGfxButtonControlFrame::IsSubmit(PRInt32 type)
|
|||
// (a) type is NS_FORM_BROWSE or
|
||||
// (b) type is NS_FORM_INPUT_BUTTON and our parent is a file input
|
||||
PRBool
|
||||
nsGfxButtonControlFrame::IsBrowse(PRInt32 type)
|
||||
nsGfxButtonControlFrame::IsFileBrowseButton(PRInt32 type)
|
||||
{
|
||||
PRBool rv = PR_FALSE;
|
||||
if (NS_FORM_BROWSE == type) {
|
||||
|
@ -192,7 +171,7 @@ nsGfxButtonControlFrame::AddComputedBorderPaddingToDesiredSize(nsHTMLReflowMetri
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsGfxButtonControlFrame::DoNavQuirksReflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
|
@ -233,12 +212,8 @@ nsGfxButtonControlFrame::DoNavQuirksReflow(nsIPresContext* aPresContext
|
|||
value.Assign(NS_LITERAL_STRING(" "));
|
||||
}
|
||||
|
||||
nsInputDimensionSpec btnSpec(NULL, PR_FALSE, nsnull,
|
||||
&value,0,
|
||||
PR_FALSE, NULL, 1);
|
||||
nsFormControlHelper::CalcNavQuirkSizing(aPresContext, aReflowState.rendContext,
|
||||
fontMet, (nsIFormControlFrame*)this,
|
||||
btnSpec, desiredSize);
|
||||
CalcNavQuirkSizing(aPresContext, aReflowState.rendContext, value,
|
||||
desiredSize);
|
||||
|
||||
// Note: The Quirks sizing includes a 2px border in its calculation of "desiredSize"
|
||||
// So we must subtract off the 2 pixel border.
|
||||
|
@ -481,20 +456,20 @@ else {
|
|||
// However, since html.css is not internationalized, we now grab the default
|
||||
// label from a string bundle as is done for all other UI strings.
|
||||
// See bug 16999 for further details.
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
nsGfxButtonControlFrame::GetDefaultLabel(nsString& aString)
|
||||
{
|
||||
const char * propname = nsFormControlHelper::GetHTMLPropertiesFileName();
|
||||
nsresult rv = NS_OK;
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
if (IsReset(type)) {
|
||||
if (type == NS_FORM_INPUT_RESET) {
|
||||
rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Reset").get(), aString);
|
||||
}
|
||||
else if (IsSubmit(type)) {
|
||||
else if (type == NS_FORM_INPUT_SUBMIT) {
|
||||
rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Submit").get(), aString);
|
||||
}
|
||||
else if (IsBrowse(type)) {
|
||||
else if (IsFileBrowseButton(type)) {
|
||||
rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Browse").get(), aString);
|
||||
}
|
||||
else {
|
||||
|
@ -525,7 +500,6 @@ nsGfxButtonControlFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|||
} else {
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
mDefaultValueWasChanged = PR_TRUE;
|
||||
|
||||
// defer to HTMLButtonControlFrame
|
||||
} else {
|
||||
|
@ -616,6 +590,29 @@ nsGfxButtonControlFrame::Reflow(nsIPresContext* aPresContext,
|
|||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
nsGfxButtonControlFrame::CalcNavQuirkSizing(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsString& aLabel,
|
||||
nsSize& aSize)
|
||||
{
|
||||
float p2t;
|
||||
float t2p;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
aPresContext->GetTwipsToPixels(&t2p);
|
||||
|
||||
// Get text size, round to nearest pixel, multiply by 3/2
|
||||
// XXX this algorithm seems suspect: rounding before multiply can't be good,
|
||||
// and 3/2 seems ... arbitrary
|
||||
nsFormControlHelper::GetTextSize(aPresContext, this,
|
||||
aLabel, aSize,
|
||||
aRendContext);
|
||||
aSize.width = NSToCoordRound(aSize.width * t2p);
|
||||
aSize.height = NSToCoordRound(aSize.height * t2p);
|
||||
aSize.width = NSIntPixelsToTwips(3 * aSize.width / 2, p2t);
|
||||
aSize.height = NSIntPixelsToTwips(3 * aSize.height / 2, p2t);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGfxButtonControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
|
|
|
@ -95,14 +95,6 @@ public:
|
|||
nsIContent * aContent,
|
||||
nsIFrame** aFrame);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD AddComputedBorderPaddingToDesiredSize(nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aSuggestedReflowState);
|
||||
NS_IMETHOD DoNavQuirksReflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus);
|
||||
NS_IMETHOD GetDefaultLabel(nsString& aLabel);
|
||||
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aNameSpaceID,
|
||||
|
@ -110,10 +102,21 @@ protected:
|
|||
PRInt32 aModType,
|
||||
PRInt32 aHint);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD AddComputedBorderPaddingToDesiredSize(nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aSuggestedReflowState);
|
||||
nsresult DoNavQuirksReflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus);
|
||||
void CalcNavQuirkSizing(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsString& aValue,
|
||||
nsSize& aSize);
|
||||
|
||||
virtual PRBool IsReset(PRInt32 type);
|
||||
virtual PRBool IsSubmit(PRInt32 type);
|
||||
virtual PRBool IsBrowse(PRInt32 type); // Browse button of file input
|
||||
nsresult GetDefaultLabel(nsString& aLabel);
|
||||
|
||||
PRBool IsFileBrowseButton(PRInt32 type); // Browse button of file input
|
||||
|
||||
private:
|
||||
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
|
||||
|
@ -122,8 +125,6 @@ private:
|
|||
nscoord mSuggestedWidth;
|
||||
nscoord mSuggestedHeight;
|
||||
nsCOMPtr<nsITextContent> mTextContent;
|
||||
|
||||
PRBool mDefaultValueWasChanged;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -204,23 +204,6 @@ NS_IMETHODIMP nsHTMLButtonControlFrame::GetAccessible(nsIAccessible** aAccessibl
|
|||
#endif
|
||||
|
||||
|
||||
void
|
||||
nsHTMLButtonControlFrame::GetDefaultLabel(nsString& aString)
|
||||
{
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
if (NS_FORM_BUTTON_BUTTON == type) {
|
||||
aString.Assign(NS_LITERAL_STRING("Button"));
|
||||
}
|
||||
else if (NS_FORM_BUTTON_RESET == type) {
|
||||
aString.Assign(NS_LITERAL_STRING("Reset"));
|
||||
}
|
||||
else if (NS_FORM_BUTTON_SUBMIT == type) {
|
||||
aString.Assign(NS_LITERAL_STRING("Submit"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLButtonControlFrame::GetType(PRInt32* aType) const
|
||||
{
|
||||
|
|
|
@ -147,9 +147,7 @@ public:
|
|||
nscoord aInnerWidth,
|
||||
nscoord aCharWidth) const;
|
||||
|
||||
void GetDefaultLabel(nsString& aLabel);
|
||||
|
||||
// nsIFormControlFrame
|
||||
// nsIFormControlFrame
|
||||
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAString& aValue);
|
||||
NS_IMETHOD GetProperty(nsIAtom* aName, nsAString& aValue);
|
||||
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
|
||||
|
|
|
@ -125,7 +125,8 @@
|
|||
#endif // IBMBIDI
|
||||
|
||||
#define DEFAULT_COLUMN_WIDTH 20
|
||||
#define GUESS_INPUT_SIZE 150 // 10 pixels wide
|
||||
// (10 pixels)
|
||||
#define GUESS_INPUT_SIZE 150
|
||||
|
||||
#include "nsContentCID.h"
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
@ -133,6 +134,10 @@ static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
|||
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
|
||||
static NS_DEFINE_CID(kFrameSelectionCID, NS_FRAMESELECTION_CID);
|
||||
|
||||
static const PRInt32 DEFAULT_COLS = 20;
|
||||
static const PRInt32 DEFAULT_ROWS = 1;
|
||||
static const PRInt32 DEFAULT_ROWS_TEXTAREA = 2;
|
||||
|
||||
static nsresult GetElementFactoryService(nsIElementFactory **aFactory)
|
||||
{
|
||||
nsresult rv(NS_OK);
|
||||
|
@ -1496,100 +1501,95 @@ PRBool nsTextControlFrame::IsPasswordTextControl() const
|
|||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextControlFrame::GetColRowSizeAttr(nsIFormControlFrame* aFrame,
|
||||
nsIAtom * aColSizeAttr,
|
||||
nsHTMLValue & aColSize,
|
||||
nsresult & aColStatus,
|
||||
nsIAtom * aRowSizeAttr,
|
||||
nsHTMLValue & aRowSize,
|
||||
nsresult & aRowStatus)
|
||||
PRInt32
|
||||
nsTextControlFrame::GetCols()
|
||||
{
|
||||
nsCOMPtr<nsIContent> iContent;
|
||||
aFrame->GetFormContent(*getter_AddRefs(iContent));
|
||||
nsCOMPtr<nsIHTMLContent> content = do_QueryInterface(mContent);
|
||||
NS_ASSERTION(content, "Content is not HTML content!");
|
||||
|
||||
nsCOMPtr<nsIHTMLContent> hContent(do_QueryInterface(iContent));
|
||||
|
||||
if (!hContent) {
|
||||
return NS_ERROR_FAILURE;
|
||||
if (IsTextArea()) {
|
||||
nsHTMLValue attr;
|
||||
nsresult rv = content->GetHTMLAttribute(nsHTMLAtoms::cols, attr);
|
||||
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
||||
PRInt32 cols = ((attr.GetUnit() == eHTMLUnit_Pixel)
|
||||
? attr.GetPixelValue() : attr.GetIntValue());
|
||||
// XXX why a default of 1 char, why hide it
|
||||
return (cols <= 0) ? 1 : cols;
|
||||
}
|
||||
} else {
|
||||
// Else we know (assume) it is an input with size attr
|
||||
nsHTMLValue attr;
|
||||
nsresult rv = content->GetHTMLAttribute(nsHTMLAtoms::size, attr);
|
||||
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
||||
PRInt32 cols = attr.GetIntValue();
|
||||
if (cols > 0) {
|
||||
return cols;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aColStatus = NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (aColSizeAttr) {
|
||||
aColStatus = hContent->GetHTMLAttribute(aColSizeAttr, aColSize);
|
||||
}
|
||||
|
||||
aRowStatus= NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (aRowSizeAttr) {
|
||||
aRowStatus = hContent->GetHTMLAttribute(aRowSizeAttr, aRowSize);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return DEFAULT_COLS;
|
||||
}
|
||||
|
||||
|
||||
PRInt32
|
||||
nsTextControlFrame::GetRows()
|
||||
{
|
||||
if (IsTextArea()) {
|
||||
nsCOMPtr<nsIHTMLContent> content = do_QueryInterface(mContent);
|
||||
NS_ASSERTION(content, "Content is not HTML content!");
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLValue attr;
|
||||
nsresult rv = content->GetHTMLAttribute(nsHTMLAtoms::rows, attr);
|
||||
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
||||
PRInt32 rows = attr.GetIntValue();
|
||||
return (rows <= 0) ? DEFAULT_ROWS_TEXTAREA : rows;
|
||||
}
|
||||
return DEFAULT_ROWS_TEXTAREA;
|
||||
}
|
||||
|
||||
return DEFAULT_ROWS;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsTextControlFrame::ReflowStandard(nsIPresContext* aPresContext,
|
||||
nsSize& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus,
|
||||
nsMargin& aBorder,
|
||||
nsMargin& aPadding)
|
||||
nsSize& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
{
|
||||
// get the css size and let the frame use or override it
|
||||
nsSize minSize;
|
||||
|
||||
PRBool usingDefaultSize = PR_FALSE;
|
||||
PRInt32 ignore;
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
|
||||
PRInt32 width = 0;
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE != GetSizeFromContent(&width)) {
|
||||
width = GetDefaultColumnWidth();
|
||||
usingDefaultSize = PR_TRUE;
|
||||
}
|
||||
nsInputDimensionSpec textSpec(nsnull, PR_FALSE, nsnull,
|
||||
nsnull, width,
|
||||
PR_FALSE, nsnull, 1);
|
||||
CalculateSizeStandard(aPresContext, aReflowState.rendContext, this,
|
||||
textSpec, aDesiredSize, minSize, ignore, aBorder, aPadding, usingDefaultSize);
|
||||
} else {
|
||||
nsInputDimensionSpec areaSpec(nsHTMLAtoms::cols, PR_FALSE, nsnull,
|
||||
nsnull, GetDefaultColumnWidth(),
|
||||
PR_FALSE, nsHTMLAtoms::rows, 1);
|
||||
CalculateSizeStandard(aPresContext, aReflowState.rendContext, this,
|
||||
areaSpec, aDesiredSize, minSize, ignore, aBorder, aPadding, usingDefaultSize);
|
||||
}
|
||||
CalculateSizeStandard(aPresContext, aReflowState.rendContext, aDesiredSize,
|
||||
minSize);
|
||||
|
||||
// CalculateSize makes calls in the nsFormControlHelper that figures
|
||||
// out the entire size of the control when in NavQuirks mode. For the
|
||||
// textarea, this means the scrollbar sizes hav already been added to
|
||||
// its overall size and do not need to be added here.
|
||||
if (NS_FORM_TEXTAREA == type) {
|
||||
float p2t;
|
||||
// Add in the size of the scrollbars for textarea
|
||||
if (IsTextArea()) {
|
||||
float p2t;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
|
||||
nscoord scrollbarWidth = 0;
|
||||
nscoord scrollbarHeight = 0;
|
||||
float scale;
|
||||
nsCOMPtr<nsIDeviceContext> dx;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dx));
|
||||
if (dx) {
|
||||
if (dx) {
|
||||
float scale;
|
||||
dx->GetCanonicalPixelScale(scale);
|
||||
|
||||
float sbWidth;
|
||||
float sbHeight;
|
||||
dx->GetCanonicalPixelScale(scale);
|
||||
dx->GetScrollBarDimensions(sbWidth, sbHeight);
|
||||
scrollbarWidth = PRInt32(sbWidth * scale);
|
||||
scrollbarHeight = PRInt32(sbHeight * scale);
|
||||
} else {
|
||||
NS_WARNING("Dude! No DeviceContext! Not cool!");
|
||||
scrollbarWidth = nsFormControlFrame::GetScrollbarWidth(p2t);
|
||||
scrollbarHeight = scrollbarWidth;
|
||||
}
|
||||
|
||||
aDesiredSize.height += scrollbarHeight;
|
||||
minSize.height += scrollbarHeight;
|
||||
|
||||
aDesiredSize.width += scrollbarWidth;
|
||||
minSize.width += scrollbarWidth;
|
||||
}
|
||||
|
@ -1597,51 +1597,29 @@ nsTextControlFrame::ReflowStandard(nsIPresContext* aPresContext,
|
|||
aDesiredSize.height += aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom;
|
||||
|
||||
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRInt32
|
||||
nsTextControlFrame::CalculateSizeStandard (nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFormControlFrame* aFrame,
|
||||
nsInputDimensionSpec& aSpec,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize,
|
||||
nscoord& aRowHeight,
|
||||
nsMargin& aBorder,
|
||||
nsMargin& aPadding,
|
||||
PRBool aIsUsingDefSize)
|
||||
void
|
||||
nsTextControlFrame::CalculateSizeStandard(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize)
|
||||
{
|
||||
nscoord charWidth = 0;
|
||||
aDesiredSize.width = CSS_NOTSET;
|
||||
aDesiredSize.height = CSS_NOTSET;
|
||||
|
||||
nsHTMLValue colAttr;
|
||||
nsresult colStatus;
|
||||
nsHTMLValue rowAttr;
|
||||
nsresult rowStatus;
|
||||
if (NS_ERROR_FAILURE == GetColRowSizeAttr(aFrame,
|
||||
aSpec.mColSizeAttr, colAttr, colStatus,
|
||||
aSpec.mRowSizeAttr, rowAttr, rowStatus)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float p2t;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
|
||||
nscoord fontHeight = 0;
|
||||
// get leading
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
nsresult res = nsFormControlHelper::GetFrameFontFM(aPresContext, aFrame, getter_AddRefs(fontMet));
|
||||
if (NS_SUCCEEDED(res) && fontMet) {
|
||||
nsresult rv = nsFormControlHelper::GetFrameFontFM(aPresContext, this, getter_AddRefs(fontMet));
|
||||
if (NS_SUCCEEDED(rv) && fontMet) {
|
||||
aRendContext->SetFont(fontMet);
|
||||
fontMet->GetHeight(fontHeight);
|
||||
aDesiredSize.height = fontHeight;
|
||||
} else {
|
||||
aDesiredSize.height = GUESS_INPUT_SIZE; // punt
|
||||
NS_WARNING("No font metrics found for textarea / input! Something is fishy.");
|
||||
fontHeight = GUESS_INPUT_SIZE;
|
||||
}
|
||||
|
||||
// Internal padding is necessary for better matching IE's width
|
||||
|
@ -1654,12 +1632,18 @@ nsTextControlFrame::CalculateSizeStandard (nsIPresContext* aPresContext,
|
|||
// 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.
|
||||
|
||||
float p2t;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
|
||||
nscoord charWidth = 0;
|
||||
|
||||
#if defined(_WIN32) || defined(XP_OS2)
|
||||
fontMet->GetAveCharWidth(charWidth);
|
||||
|
||||
// Get frame font
|
||||
const nsFont * font = nsnull;
|
||||
if (NS_SUCCEEDED(aFrame->GetFont(aPresContext, font))) {
|
||||
if (NS_SUCCEEDED(this->GetFont(aPresContext, font))) {
|
||||
// To better match IE, take the size (in twips) and remove 4 pixels
|
||||
// add this on as additional padding
|
||||
internalPadding = PR_MAX(font->size - NSToCoordRound(4 * p2t), 0);
|
||||
|
@ -1682,59 +1666,21 @@ nsTextControlFrame::CalculateSizeStandard (nsIPresContext* aPresContext,
|
|||
nscoord onePixel = NSIntPixelsToTwips(1, p2t); // get the rounding right
|
||||
charWidth = nscoord((float(charWidth) / float(onePixel)) + 0.5)*onePixel;
|
||||
#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 * charWidth;
|
||||
} else {
|
||||
aDesiredSize.width = aSpec.mColDefaultSize * charWidth;
|
||||
}
|
||||
|
||||
// Now add the extra internal padding on
|
||||
// Set the width equal to the width in characters
|
||||
aDesiredSize.width = GetCols() * charWidth;
|
||||
// Now add the extra padding on (so that small input sizes work well)
|
||||
aDesiredSize.width += internalPadding;
|
||||
|
||||
aRowHeight = aDesiredSize.height;
|
||||
// Set the height equal to total number of rows (times the height of each
|
||||
// line, of course)
|
||||
aDesiredSize.height = fontHeight * GetRows();
|
||||
|
||||
// Set minimum size equal to desired size. We are form controls. We are Gods
|
||||
// among elements. We do not yield for anybody, not even a table cell. None
|
||||
// shall pass.
|
||||
aMinSize.width = aDesiredSize.width;
|
||||
aMinSize.height = aDesiredSize.height;
|
||||
PRInt32 numRows = 0;
|
||||
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == rowStatus) { // row attr will provide height
|
||||
PRInt32 rowAttrInt = ((rowAttr.GetUnit() == eHTMLUnit_Pixel)
|
||||
? rowAttr.GetPixelValue() : rowAttr.GetIntValue());
|
||||
numRows = (rowAttrInt > 0) ? rowAttrInt : 1;
|
||||
aDesiredSize.height = aDesiredSize.height * numRows;
|
||||
} else {
|
||||
aDesiredSize.height = aDesiredSize.height * aSpec.mRowDefaultSize;
|
||||
}
|
||||
|
||||
numRows = (aRowHeight > 0) ? (aDesiredSize.height / aRowHeight) : 0;
|
||||
if (numRows == 1) {
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
if (NS_FORM_TEXTAREA == type) {
|
||||
aDesiredSize.height += fontHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// if we are not using the default size
|
||||
// then make the minimum size the size we want to be
|
||||
if (!aIsUsingDefSize) {
|
||||
aMinSize.width = aDesiredSize.width;
|
||||
aMinSize.height = aDesiredSize.height;
|
||||
}
|
||||
|
||||
return numRows;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2046,56 +1992,27 @@ nsTextControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize the plaintext editor
|
||||
nsCOMPtr<nsIPlaintextEditor> textEditor(do_QueryInterface(mEditor));
|
||||
if (textEditor)
|
||||
{
|
||||
nsHTMLValue colAttr;
|
||||
nsresult colStatus;
|
||||
nsHTMLValue rowAttr;
|
||||
nsresult rowStatus;
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
nsInputDimensionSpec *spec;
|
||||
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
|
||||
PRInt32 width = 0;
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE != GetSizeFromContent(&width)) {
|
||||
width = GetDefaultColumnWidth();
|
||||
if (textEditor) {
|
||||
// Set up wrapping
|
||||
if (IsTextArea()) {
|
||||
// wrap=off means -1 for wrap width no matter what cols is
|
||||
nsFormControlHelper::nsHTMLTextWrap wrapProp;
|
||||
nsFormControlHelper::GetWrapPropertyEnum(mContent, wrapProp);
|
||||
if (wrapProp == nsFormControlHelper::eHTMLTextWrap_Off) {
|
||||
// do not wrap when wrap=off
|
||||
textEditor->SetWrapWidth(-1);
|
||||
} else {
|
||||
// Set wrapping normally otherwise
|
||||
textEditor->SetWrapWidth(GetCols());
|
||||
}
|
||||
spec = new nsInputDimensionSpec(nsnull, PR_FALSE, nsnull,
|
||||
nsnull, width,
|
||||
PR_FALSE, nsnull, 1);
|
||||
} else {
|
||||
spec = new nsInputDimensionSpec(nsHTMLAtoms::cols, PR_FALSE, nsnull,
|
||||
nsnull, GetDefaultColumnWidth(),
|
||||
PR_FALSE, nsHTMLAtoms::rows, 1);
|
||||
}
|
||||
if (spec)
|
||||
{
|
||||
if (NS_FAILED(GetColRowSizeAttr(this,
|
||||
spec->mColSizeAttr, colAttr, colStatus,
|
||||
spec->mRowSizeAttr, rowAttr, rowStatus)))
|
||||
return NS_ERROR_FAILURE;
|
||||
PRInt32 col =-1;
|
||||
if (!(colAttr.GetUnit() == eHTMLUnit_Null))
|
||||
{
|
||||
col = ((colAttr.GetUnit() == eHTMLUnit_Pixel) ? colAttr.GetPixelValue() : colAttr.GetIntValue());
|
||||
col = (col <= 0) ? 1 : col; // XXX why a default of 1 char, why hide it
|
||||
}
|
||||
if (type == NS_FORM_TEXTAREA)
|
||||
{
|
||||
nsFormControlHelper::nsHTMLTextWrap wrapProp;
|
||||
nsresult rv = nsFormControlHelper::GetWrapPropertyEnum(mContent, wrapProp);
|
||||
// do not wrap at the cols attribute when wrap=off
|
||||
if ((rv != NS_CONTENT_ATTR_NOT_THERE) &&
|
||||
(wrapProp == nsFormControlHelper::eHTMLTextWrap_Off))
|
||||
{
|
||||
col = -1;
|
||||
}
|
||||
}
|
||||
textEditor->SetWrapWidth(col);
|
||||
delete spec;
|
||||
// Never wrap non-textareas
|
||||
textEditor->SetWrapWidth(-1);
|
||||
}
|
||||
|
||||
|
||||
// Set max text field length
|
||||
PRInt32 maxLength;
|
||||
rv = GetMaxLength(&maxLength);
|
||||
|
@ -2286,35 +2203,21 @@ nsTextControlFrame::GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize)
|
|||
if (collapsed)
|
||||
return NS_OK;
|
||||
|
||||
nsIPresContext* aPresContext = aState.GetPresContext();
|
||||
const nsHTMLReflowState* aReflowState = aState.GetReflowState();
|
||||
nsIPresContext* presContext = aState.GetPresContext();
|
||||
const nsHTMLReflowState* reflowState = aState.GetReflowState();
|
||||
nsSize styleSize(CSS_NOTSET,CSS_NOTSET);
|
||||
nsFormControlFrame::GetStyleSize(aPresContext, *aReflowState, styleSize);
|
||||
nsFormControlFrame::GetStyleSize(presContext, *reflowState, styleSize);
|
||||
|
||||
if (!aReflowState)
|
||||
if (!reflowState)
|
||||
return NS_OK;
|
||||
|
||||
InitEditor();
|
||||
|
||||
if (mState & NS_FRAME_FIRST_REFLOW)
|
||||
mNotifyOnInput = PR_TRUE;//its ok to notify now. all has been prepared.
|
||||
mNotifyOnInput = PR_TRUE; //its ok to notify now. all has been prepared.
|
||||
|
||||
nsReflowStatus aStatus;
|
||||
nsMargin border;
|
||||
border.SizeTo(0, 0, 0, 0);
|
||||
nsMargin padding;
|
||||
padding.SizeTo(0, 0, 0, 0);
|
||||
|
||||
// Get the CSS border
|
||||
const nsStyleBorder* borderStyle;
|
||||
const nsStylePadding* paddingStyle;
|
||||
GetStyleData(eStyleStruct_Border, (const nsStyleStruct *&)borderStyle);
|
||||
GetStyleData(eStyleStruct_Padding, (const nsStyleStruct *&)paddingStyle);
|
||||
borderStyle->CalcBorderFor(this, border);
|
||||
paddingStyle->CalcPaddingFor(this, padding);
|
||||
|
||||
nsresult rv;
|
||||
rv = ReflowStandard(aPresContext, aSize, *aReflowState, aStatus, border, padding);
|
||||
nsReflowStatus status;
|
||||
ReflowStandard(presContext, aSize, *reflowState, status);
|
||||
AddInset(aSize);
|
||||
|
||||
mPrefSize = aSize;
|
||||
|
@ -2376,39 +2279,6 @@ nsTextControlFrame::GetType(PRInt32* aType) const
|
|||
return nsFormControlHelper::GetType(mContent, aType);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextControlFrame::GetSizeFromContent(PRInt32* aSize) const
|
||||
{
|
||||
*aSize = -1;
|
||||
nsresult result = NS_CONTENT_ATTR_NOT_THERE;
|
||||
nsCOMPtr<nsIHTMLContent> content(do_QueryInterface(mContent));
|
||||
|
||||
if (content) {
|
||||
nsHTMLValue value;
|
||||
result = content->GetHTMLAttribute(nsHTMLAtoms::size, value);
|
||||
if (eHTMLUnit_Integer == value.GetUnit()) {
|
||||
*aSize = value.GetIntValue();
|
||||
}
|
||||
}
|
||||
if (*aSize < 1) {
|
||||
// This is part of bug 46224
|
||||
// when we can get a PresContent (may be cache it)
|
||||
// then we can check the compatibility mode
|
||||
#ifdef FUTURE_ADDITIONAL_FIX_FOR_46224
|
||||
nsCompatibility mode;
|
||||
nsFormControlHelper::GetFormCompatibilityMode(aPresContext, mode);
|
||||
if (eCompatibility_NavQuirks == mode) {
|
||||
*aSize = 1;
|
||||
} else {
|
||||
*aSize = 20;
|
||||
}
|
||||
#else
|
||||
*aSize = 20; // use '1' to be compatable with Nav 4.x, Use '20' to be compatable with IE
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void nsTextControlFrame::SetFocus(PRBool aOn , PRBool aRepaint){}
|
||||
|
||||
void nsTextControlFrame::ScrollIntoView(nsIPresContext* aPresContext)
|
||||
|
@ -2973,9 +2843,7 @@ NS_IMETHODIMP
|
|||
nsTextControlFrame::GetText(nsString* aText)
|
||||
{
|
||||
nsresult rv = NS_CONTENT_ATTR_NOT_THERE;
|
||||
PRInt32 type;
|
||||
GetType(&type);
|
||||
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
|
||||
if (IsSingleLineTextControl()) {
|
||||
// If we're going to remove newlines anyway, ignore the wrap property
|
||||
GetValue(*aText, PR_TRUE);
|
||||
RemoveNewlines(*aText);
|
||||
|
|
|
@ -66,9 +66,9 @@ class nsIAccessible;
|
|||
|
||||
|
||||
class nsTextControlFrame : public nsStackFrame,
|
||||
public nsIAnonymousContentCreator,
|
||||
public nsITextControlFrame,
|
||||
public nsIScrollableViewProvider
|
||||
public nsIAnonymousContentCreator,
|
||||
public nsITextControlFrame,
|
||||
public nsIScrollableViewProvider
|
||||
|
||||
{
|
||||
public:
|
||||
|
@ -249,33 +249,27 @@ protected:
|
|||
|
||||
//helper methods
|
||||
nsresult GetSizeFromContent(PRInt32* aSize) const;
|
||||
PRInt32 GetDefaultColumnWidth() const { return (PRInt32)(20); } // this was DEFAULT_PIXEL_WIDTH
|
||||
|
||||
nsresult GetColRowSizeAttr(nsIFormControlFrame* aFrame,
|
||||
nsIAtom * aColSizeAttr,
|
||||
nsHTMLValue & aColSize,
|
||||
nsresult & aColStatus,
|
||||
nsIAtom * aRowSizeAttr,
|
||||
nsHTMLValue & aRowSize,
|
||||
nsresult & aRowStatus);
|
||||
/**
|
||||
* Get the cols attribute (if textarea) or a default
|
||||
* @return the number of columns to use
|
||||
*/
|
||||
PRInt32 GetCols();
|
||||
/**
|
||||
* Get the rows attribute (if textarea) or a default
|
||||
* @return the number of rows to use
|
||||
*/
|
||||
PRInt32 GetRows();
|
||||
|
||||
NS_IMETHOD ReflowStandard(nsIPresContext* aPresContext,
|
||||
nsSize& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus,
|
||||
nsMargin& aBorder,
|
||||
nsMargin& aPadding);
|
||||
void ReflowStandard(nsIPresContext* aPresContext,
|
||||
nsSize& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus);
|
||||
|
||||
PRInt32 CalculateSizeStandard (nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsIFormControlFrame* aFrame,
|
||||
nsInputDimensionSpec& aSpec,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize,
|
||||
nscoord& aRowHeight,
|
||||
nsMargin& aBorder,
|
||||
nsMargin& aPadding,
|
||||
PRBool aIsUsingDefSize);
|
||||
void CalculateSizeStandard(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsSize& aDesiredSize,
|
||||
nsSize& aMinSize);
|
||||
|
||||
NS_IMETHOD CreateFrameFor(nsIPresContext* aPresContext,
|
||||
nsIContent * aContent,
|
||||
|
|
Загрузка…
Ссылка в новой задаче