textarea sizing improvement; use nsCSSLayout::GetStyleSize; fix combo box SizeTo
git-svn-id: svn://10.0.0.236/trunk@1449 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include "nsHTMLForms.h"
|
||||
#include "nsStyleConsts.h"
|
||||
|
||||
#define ALIGN_UNSET PRUint8(-1);
|
||||
static NS_DEFINE_IID(kStyleDisplaySID, NS_STYLEDISPLAY_SID);
|
||||
static NS_DEFINE_IID(kStyleTextSID, NS_STYLETEXT_SID);
|
||||
|
||||
@@ -49,7 +50,7 @@ nsInput::nsInput(nsIAtom* aTag, nsIFormManager* aManager)
|
||||
mFormMan->AddFormControl(&mControl);
|
||||
}
|
||||
mSize = ATTR_NOTSET;
|
||||
mAlign = nsnull;
|
||||
mAlign = ALIGN_UNSET;
|
||||
mWidth = ATTR_NOTSET;
|
||||
mHeight= ATTR_NOTSET;
|
||||
mLastClickPoint.x = -1;
|
||||
@@ -88,11 +89,10 @@ void nsInput::SetContent(const nsString& aValue)
|
||||
}
|
||||
|
||||
void nsInput::MapAttributesInto(nsIStyleContext* aContext,
|
||||
nsIPresContext* aPresContext)
|
||||
nsIPresContext* aPresContext)
|
||||
{
|
||||
#if 0
|
||||
XXX
|
||||
if (ATTR_NOTSET != mAlign) {
|
||||
// if (ALIGN_UNSET != mAlign) { XXX why won't this compile
|
||||
if (-1 != mAlign) {
|
||||
nsStyleDisplay* display = (nsStyleDisplay*)
|
||||
aContext->GetData(kStyleDisplaySID);
|
||||
nsStyleText* text = (nsStyleText*)
|
||||
@@ -104,16 +104,15 @@ void nsInput::MapAttributesInto(nsIStyleContext* aContext,
|
||||
case NS_STYLE_TEXT_ALIGN_RIGHT:
|
||||
display->mFloats = NS_STYLE_FLOAT_RIGHT;
|
||||
break;
|
||||
#if 0
|
||||
default:
|
||||
text->mVerticalAlignFlags = mAlign;
|
||||
text->mVerticalAlign.SetIntValue(mAlign, eStyleUnit_Enumerated);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
MapImagePropertiesInto(aContext, aPresContext);
|
||||
}
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
|
||||
|
||||
nsresult nsInput::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
@@ -290,16 +289,26 @@ void nsInput::SetAttribute(nsIAtom* aAttribute, const nsString& aValue)
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::width) {
|
||||
CacheAttribute(aValue, ATTR_NOTSET, mWidth);
|
||||
nsInputSuper::SetAttribute(aAttribute, aValue); // is this needed?
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::height) {
|
||||
CacheAttribute(aValue, ATTR_NOTSET, mHeight);
|
||||
nsInputSuper::SetAttribute(aAttribute, aValue); // is this needed?
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::value) {
|
||||
CacheAttribute(aValue, mValue);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::align) {
|
||||
CacheAttribute(aValue, ATTR_NOTSET, mAlign);
|
||||
}
|
||||
nsHTMLValue val;
|
||||
if (ParseAlignParam(aValue, val)) {
|
||||
mAlign = val.GetIntValue();
|
||||
// Reflect the attribute into the syle system
|
||||
nsHTMLTagContent::SetAttribute(aAttribute, val); // is this needed?
|
||||
} else {
|
||||
mAlign = ALIGN_UNSET;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else {
|
||||
nsInputSuper::SetAttribute(aAttribute, aValue);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ protected:
|
||||
nsString* mName;
|
||||
nsString* mValue;
|
||||
PRInt32 mSize;
|
||||
PRInt32 mAlign;
|
||||
PRUint8 mAlign;
|
||||
PRInt32 mWidth;
|
||||
PRInt32 mHeight;
|
||||
|
||||
|
||||
@@ -424,7 +424,7 @@ nsInputButtonFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
||||
}
|
||||
else {
|
||||
nsSize styleSize;
|
||||
GetStyleSize(*aPresContext, aMaxSize, styleSize);
|
||||
GetStyleSize(*aPresContext, styleSize);
|
||||
|
||||
if (kButton_Image == GetButtonType()) { // there is an image
|
||||
float p2t = aPresContext->GetPixelsToTwips();
|
||||
@@ -432,8 +432,8 @@ nsInputButtonFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
||||
GetImage(*aPresContext, PR_FALSE);
|
||||
|
||||
// Use dimensions from style attributes
|
||||
aDesiredLayoutSize.width = nscoord(styleSize.width * p2t);
|
||||
aDesiredLayoutSize.height = nscoord(styleSize.height * p2t);
|
||||
aDesiredLayoutSize.width = nscoord(styleSize.width);
|
||||
aDesiredLayoutSize.height = nscoord(styleSize.height);
|
||||
} else {
|
||||
nsIImage* image = GetImage(*aPresContext, PR_TRUE);
|
||||
if (nsnull == image) {
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include "nsHTMLForms.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsUnitConversion.h"
|
||||
|
||||
#include "nsCSSLayout.h"
|
||||
static NS_DEFINE_IID(kStyleFontSID, NS_STYLEFONT_SID);
|
||||
static NS_DEFINE_IID(kStylePositionSID, NS_STYLEPOSITION_SID);
|
||||
static NS_DEFINE_IID(kStyleSpacingSID, NS_STYLESPACING_SID);
|
||||
@@ -71,6 +71,8 @@ nsInputFrame::~nsInputFrame()
|
||||
{
|
||||
}
|
||||
|
||||
PRInt32 nsInputFrame::gScrollBarWidth = 360;
|
||||
|
||||
NS_METHOD nsInputFrame::SetRect(const nsRect& aRect)
|
||||
{
|
||||
return nsInputFrameSuper::SetRect(aRect);
|
||||
@@ -188,7 +190,7 @@ nsInputFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
||||
{
|
||||
// get the css size and let the frame use or override it
|
||||
nsSize styleSize;
|
||||
GetStyleSize(*aPresContext, aMaxSize, styleSize);
|
||||
GetStyleSize(*aPresContext, styleSize);
|
||||
|
||||
// subclasses should always override this method, but if not and no css, make it small
|
||||
aDesiredLayoutSize.width = (styleSize.width > CSS_NOTSET) ? styleSize.width : 144;
|
||||
@@ -236,10 +238,9 @@ nsInputFrame::ResizeReflow(nsIPresContext* aPresContext,
|
||||
nsIPresShell *presShell = aPresContext->GetShell(); // need to release
|
||||
nsIViewManager *viewMan = presShell->GetViewManager(); // need to release
|
||||
|
||||
nsSize widgetSize;
|
||||
GetDesiredSize(aPresContext, aMaxSize, aDesiredSize, widgetSize);
|
||||
GetDesiredSize(aPresContext, aMaxSize, aDesiredSize, mWidgetSize);
|
||||
|
||||
nsRect boundBox(0, 0, widgetSize.width, widgetSize.height);
|
||||
nsRect boundBox(0, 0, mWidgetSize.width, mWidgetSize.height);
|
||||
|
||||
nsIFrame* parWithView;
|
||||
nsIView *parView;
|
||||
@@ -283,8 +284,7 @@ nsInputFrame::ResizeReflow(nsIPresContext* aPresContext,
|
||||
NS_IF_RELEASE(presShell);
|
||||
}
|
||||
else {
|
||||
nsSize widgetSize;
|
||||
GetDesiredSize(aPresContext, aMaxSize, aDesiredSize, widgetSize);
|
||||
GetDesiredSize(aPresContext, aMaxSize, aDesiredSize, mWidgetSize);
|
||||
|
||||
// If we are being reflowed and have a view, hide the view until
|
||||
// we are told to paint (which is when our location will have
|
||||
@@ -414,6 +414,19 @@ NS_METHOD nsInputFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
return nsEventStatus_eConsumeDoDefault;
|
||||
}
|
||||
|
||||
void nsInputFrame::GetStyleSize(nsIPresContext& aPresContext,
|
||||
nsSize& aSize)
|
||||
{
|
||||
PRIntn ss = nsCSSLayout::GetStyleSize(&aPresContext, this, aSize);
|
||||
if (0 == (ss & NS_SIZE_HAS_WIDTH)) {
|
||||
aSize.width = CSS_NOTSET;
|
||||
}
|
||||
if (0 == (ss & NS_SIZE_HAS_HEIGHT)) {
|
||||
aSize.height = CSS_NOTSET;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
void nsInputFrame::GetStyleSize(nsIPresContext& aPresContext,
|
||||
const nsSize& aMaxSize, nsSize& aSize)
|
||||
{
|
||||
@@ -455,6 +468,7 @@ nsInputFrame::GetStyleDim(nsIPresContext& aPresContext, nscoord aMaxDim,
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
nscoord
|
||||
nsInputFrame::GetTextSize(nsIPresContext& aPresContext, nsIFrame* aFrame,
|
||||
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
// nsLeafFrame overrides
|
||||
|
||||
NS_IMETHOD MoveTo(nscoord aX, nscoord aY);
|
||||
NS_METHOD SizeTo(nscoord aWidth, nscoord aHeight);
|
||||
NS_IMETHOD SizeTo(nscoord aWidth, nscoord aHeight);
|
||||
|
||||
/**
|
||||
* Respond to a gui event
|
||||
@@ -172,6 +172,8 @@ public:
|
||||
static nscoord GetTextSize(nsIPresContext& aContext, nsIFrame* aFrame,
|
||||
PRInt32 aNumChars, nsSize& aSize);
|
||||
|
||||
static PRInt32 gScrollBarWidth;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~nsInputFrame();
|
||||
@@ -203,16 +205,16 @@ protected:
|
||||
/**
|
||||
* Get the width and height of this control based on CSS
|
||||
* @param aPresContext the presentation context
|
||||
* @param aMaxSize the maximum size that this frame can have
|
||||
* @param aSize the size that this frame wants, set by this method. values of -1
|
||||
* for aSize.width or aSize.height indicate unset values.
|
||||
*/
|
||||
void GetStyleSize(nsIPresContext& aContext, const nsSize& aMaxSize, nsSize& aSize);
|
||||
void GetStyleSize(nsIPresContext& aContext, nsSize& aSize);
|
||||
|
||||
nscoord GetStyleDim(nsIPresContext& aPresContext, nscoord aMaxDim,
|
||||
nscoord aMaxWidth, const nsStyleCoord& aCoord);
|
||||
|
||||
nsMouseState mLastMouseState;
|
||||
nsSize mWidgetSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -113,15 +113,16 @@ nsInputTextFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
||||
nsReflowMetrics& aDesiredLayoutSize,
|
||||
nsSize& aDesiredWidgetSize)
|
||||
{
|
||||
nsInputTextType textType = GetTextType();
|
||||
// get the css size and let the frame use or override it
|
||||
nsSize styleSize;
|
||||
GetStyleSize(*aPresContext, aMaxSize, styleSize);
|
||||
GetStyleSize(*aPresContext, styleSize);
|
||||
|
||||
nsSize size;
|
||||
|
||||
PRBool widthExplicit, heightExplicit;
|
||||
PRInt32 ignore;
|
||||
if ((kInputTextText == GetTextType()) || (kInputTextPassword == GetTextType())) {
|
||||
if ((kInputTextText == textType) || (kInputTextPassword == textType)) {
|
||||
nsInputDimensionSpec textSpec(nsHTMLAtoms::size, PR_FALSE, nsHTMLAtoms::value,
|
||||
20, PR_FALSE, nsnull, 1);
|
||||
CalculateSize(aPresContext, this, styleSize, textSpec, size,
|
||||
@@ -133,8 +134,17 @@ nsInputTextFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
||||
CalculateSize(aPresContext, this, styleSize, areaSpec, size,
|
||||
widthExplicit, heightExplicit, ignore);
|
||||
}
|
||||
if (!heightExplicit && (kInputTextArea != GetTextType())) {
|
||||
size.height += 100;
|
||||
if (!heightExplicit) {
|
||||
if (kInputTextArea == textType) {
|
||||
size.height += gScrollBarWidth;
|
||||
}
|
||||
else {
|
||||
size.height += 100;
|
||||
}
|
||||
}
|
||||
|
||||
if (!widthExplicit && (kInputTextArea == textType)) {
|
||||
size.width += gScrollBarWidth;
|
||||
}
|
||||
|
||||
aDesiredLayoutSize.width = size.width;
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
|
||||
virtual const nsIID& GetIID();
|
||||
|
||||
NS_IMETHOD SizeTo(nscoord aWidth, nscoord aHeight);
|
||||
PRBool IsComboBox();
|
||||
|
||||
protected:
|
||||
@@ -192,7 +193,7 @@ nsSelectFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
||||
|
||||
// get the css size
|
||||
nsSize styleSize;
|
||||
GetStyleSize(*aPresContext, aMaxSize, styleSize);
|
||||
GetStyleSize(*aPresContext, styleSize);
|
||||
|
||||
// get the size of the longest child
|
||||
PRInt32 maxWidth = 1;
|
||||
@@ -253,6 +254,13 @@ nsSelectFrame::GetWidgetInitData()
|
||||
return data;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsSelectFrame::SizeTo(nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
nscoord height = (IsComboBox()) ? mWidgetSize.height : aHeight;
|
||||
return nsInputFrame::SizeTo(aWidth, height);
|
||||
}
|
||||
|
||||
void
|
||||
nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
|
||||
{
|
||||
|
||||
36
mozilla/webshell/tests/viewer/samples/test8-1.html
Normal file
36
mozilla/webshell/tests/viewer/samples/test8-1.html
Normal file
@@ -0,0 +1,36 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Example 8a</title>
|
||||
<style>
|
||||
TEXTAREA#textarea150x100 {
|
||||
width: 150px;
|
||||
height: 100px;
|
||||
font-size: large;
|
||||
}
|
||||
INPUT#input100x50 {
|
||||
width: 100px;
|
||||
height: 50px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<H1>Example 8a: Forms</H1>
|
||||
|
||||
<BR>
|
||||
|
||||
<FORM METHOD="GET" ACTION="http://www.mcp.com/cgi-bin/post-query" NAME="echo">
|
||||
<PRE>textarea rows=4 cols=20 textarea width=150 height=100 font-size=large</PRE>
|
||||
<textarea rows=4 cols=20>textarea 1</textarea>
|
||||
|
||||
<textarea id=textarea150x100>textarea 2</textarea>
|
||||
<BR>
|
||||
<PRE>text size=8 text width=100 height=50 aligh=rigth</PRE>
|
||||
<input type=text size=8 value=text>
|
||||
|
||||
<input type=text id=input100x50 value=text align=right>
|
||||
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -30,11 +30,6 @@
|
||||
<input type=submit name=submit value="SUBMIT">
|
||||
<input type=image src=raptor.jpg width=50 height=50 name=imageSubmit> an image submit. For now, click twice.
|
||||
|
||||
<SELECT name=foo>
|
||||
<OPTION>option 1</OPTION>
|
||||
<OPTION>option 2</OPTION>
|
||||
</SELECT>
|
||||
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user