better layout, sizing of select

This commit is contained in:
karnaze 1998-05-19 17:51:21 +00:00
Родитель 92661f8e27
Коммит d0ddd7fa42
6 изменённых файлов: 75 добавлений и 47 удалений

Просмотреть файл

@ -36,6 +36,7 @@
#include "nsRepository.h"
#include "nsIView.h"
PRInt32 nsInputFileFrame::gSpacing = 40;
nsInputFileFrame::nsInputFileFrame(nsIContent* aContent, nsIFrame* aParentFrame)
: nsInlineFrame(aContent, aParentFrame)
@ -107,7 +108,7 @@ void nsInputFileFrame::MouseClicked(nsIPresContext* aPresContext)
NS_IMETHODIMP
nsInputFileFrame::MoveTo(nscoord aX, nscoord aY)
{
if ((aX != mRect.x) || (aY != mRect.y)) {
if ( ((aX == 0) && (aY == 0)) || (aX != mRect.x) || (aY != mRect.y)) {
nsIFrame* childFrame = mFirstChild;
nscoord x = aX;
nscoord y = aY;
@ -115,7 +116,7 @@ nsInputFileFrame::MoveTo(nscoord aX, nscoord aY)
nsresult result = childFrame->MoveTo(x, y);
nsSize childSize;
((nsInputFrame *)childFrame)->GetWidgetSize(childSize);
x = x + childSize.width + 100;
x = x + childSize.width + gSpacing;
childFrame->GetNextSibling(childFrame);
}
}
@ -175,7 +176,7 @@ NS_IMETHODIMP nsInputFileFrame::ResizeReflow(nsIPresContext* aCX,
nsSize maxSize = aMaxSize;
nsReflowMetrics desiredSize = aDesiredSize;
aDesiredSize.width = 100; // padding
aDesiredSize.width = gSpacing;
aDesiredSize.height = 0;
childFrame = mFirstChild;
while (nsnull != childFrame) {

Просмотреть файл

@ -39,6 +39,7 @@ public:
virtual void MouseClicked(nsIPresContext* aPresContext);
NS_IMETHOD MoveTo(nscoord aX, nscoord aY);
NS_IMETHOD SizeTo(nscoord aWidth, nscoord aHeight);
static PRInt32 gSpacing;
protected:
virtual ~nsInputFileFrame();

Просмотреть файл

@ -81,7 +81,7 @@ NS_METHOD nsInputFrame::SetRect(const nsRect& aRect)
NS_METHOD
nsInputFrame::MoveTo(nscoord aX, nscoord aY)
{
if ((aX != mRect.x) || (aY != mRect.y)) {
if ( ((aX == 0) && (aY == 0)) || (aX != mRect.x) || (aY != mRect.y)) {
mRect.x = aX;
mRect.y = aY;
@ -114,12 +114,17 @@ nsInputFrame::SizeTo(nscoord aWidth, nscoord aHeight)
nsIView* view = nsnull;
GetView(view);
if (nsnull != view) {
// XXX combo boxes need revision, they cannot have their height altered
view->SetDimensions(aWidth, aHeight);
NS_RELEASE(view);
}
return NS_OK;
}
PRInt32 nsInputFrame::GetBorderSpacing(nsIPresContext& aPresContext)
{
return (int)(2 * (aPresContext.GetPixelsToTwips() + .5));
}
// XXX it would be cool if form element used our rendering sw, then
// they could be blended, and bordered, and so on...
@ -443,6 +448,8 @@ nsInputFrame::GetTextSize(nsIPresContext& aPresContext, nsIFrame* aFrame,
aSize.width = fontMet->GetWidth(aString);
aSize.height = fontMet->GetHeight() + fontMet->GetLeading();
aSize.height = (int)(((float)aSize.height) * .90); // XXX find out why this is necessary
nscoord charWidth = fontMet->GetWidth("W");
NS_RELEASE(fontMet);
@ -500,7 +507,7 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
else {
PRInt32 col = ((colAttr.GetUnit() == eHTMLUnit_Pixel) ? colAttr.GetPixelValue() : colAttr.GetIntValue());
charWidth = GetTextSize(*aPresContext, aFrame, col, aBounds);
aRowHeight = aBounds.height;
aRowHeight = aBounds.height; // XXX aBounds.height has CSS_NOTSET
}
if (aSpec.mColSizeAttrInPixels) {
aWidthExplicit = PR_TRUE;
@ -522,7 +529,7 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
else { // use default width in num characters
charWidth = GetTextSize(*aPresContext, aFrame, aSpec.mColDefaultSize, aBounds);
}
aRowHeight = aBounds.height;
aRowHeight = aBounds.height; // XXX aBounds.height has CSS_NOTSET
}
}
@ -574,6 +581,9 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
if (ATTR_NOTSET == numRows) {
numRows = aBounds.height / aRowHeight;
}
aBounds.height += (2 * aFrame->GetBorderSpacing(*aPresContext));
return numRows;
}

Просмотреть файл

@ -94,6 +94,8 @@ public:
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
virtual PRInt32 GetBorderSpacing(nsIPresContext& aPresContext);
NS_IMETHOD SetRect(const nsRect& aRect);
/**

Просмотреть файл

@ -56,8 +56,6 @@ public:
virtual const nsIID& GetIID();
NS_IMETHOD SizeTo(nscoord aWidth, nscoord aHeight);
protected:
virtual ~nsSelectFrame();
@ -214,31 +212,28 @@ nsSelectFrame::GetDesiredSize(nsIPresContext* aPresContext,
PRInt32 numRows = CalculateSize(aPresContext, this, styleSize, textSpec,
calcSize, widthExplicit, heightExplicit, rowHeight);
if (!heightExplicit) {
calcSize.height += 100;
}
// here it is determined whether we are a combo box
PRInt32 sizeAttr = select->GetSize();
if (!select->GetMultiple() && ((1 == sizeAttr) || ((ATTR_NOTSET == sizeAttr) && (1 >= numRows)))) {
mIsComboBox = PR_TRUE;
}
// account for vertical scrollbar, if present
if (heightExplicit) {
aDesiredLayoutSize.width = calcSize.width;
aDesiredLayoutSize.width = calcSize.width;
// account for vertical scrollbar, if present
if (!widthExplicit && ((numRows < select->ChildCount()) || mIsComboBox)) {
aDesiredLayoutSize.width += gScrollBarWidth;
}
else {
aDesiredLayoutSize.width = ((numRows < select->ChildCount()) || mIsComboBox)
? calcSize.width + gScrollBarWidth : calcSize.width + 100; // XXX why the 100 padding
}
aDesiredLayoutSize.height = calcSize.height;
// XXX put this in widget library, combo boxes are fixed height (visible part)
aDesiredLayoutSize.height = (mIsComboBox) ? 350 : calcSize.height;
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
aDesiredLayoutSize.descent = 0;
aDesiredWidgetSize.width = aDesiredLayoutSize.width;
aDesiredWidgetSize.height =
(mIsComboBox && !heightExplicit) ? aDesiredLayoutSize.height + (rowHeight * numChildren) + 100
: aDesiredLayoutSize.height;
aDesiredWidgetSize.height = aDesiredLayoutSize.height;
if (mIsComboBox) { // add in pull down size
aDesiredWidgetSize.height += (rowHeight * numChildren) + 100;
}
NS_RELEASE(select);
}
@ -265,13 +260,6 @@ nsSelectFrame::GetWidgetInitData(nsIPresContext& aPresContext)
}
}
NS_METHOD
nsSelectFrame::SizeTo(nscoord aWidth, nscoord aHeight)
{
nscoord height = (mIsComboBox) ? mWidgetSize.height : aHeight;
return nsInputFrame::SizeTo(aWidth, height);
}
void
nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
{
@ -283,7 +271,12 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
nsIListWidget* list;
nsresult stat = view->QueryInterface(kListWidgetIID, (void **) &list);
NS_ASSERTION((NS_OK == stat), "invalid widget");
if (NS_OK != stat) {
NS_ASSERTION((NS_OK == stat), "invalid widget");
return;
}
list->SetFont(GetFont(aPresContext));
PRInt32 numChildren = select->ChildCount();
for (int i = 0; i < numChildren; i++) {

Просмотреть файл

@ -1,5 +1,23 @@
<html>
<head>
<title>Example 8</title>
<style>
INPUT#input1 {
font-size: large;
}
INPUT#input2 {
font-size: medium;
}
TEXTAREA#textarea1 {
width: 300px;
height: 120px;
font-size: large;
}
SELECT#select1 {
font-size: large;
}
</style>
</head>
<body>
<H1>Example 8: Forms</H1>
@ -13,20 +31,20 @@
&nbsp;&nbsp;password:&nbsp;&nbsp;<INPUT TYPE="PASSWORD">
</FORM>
<BR>
<BR><BR>
<FORM METHOD="GET" ACTION="http://www.mcp.com/cgi-bin/post-query" NAME="echo">
<textarea name=a textarea rows=4 cols=20 value="a textarea">A TEXTAREA</textarea>
&nbsp;&nbsp; a checkbox: <input type=checkbox name=check1 checked>
&nbsp;&nbsp; radio buttons:
<textarea name=a rows=4 cols=10 value="a textarea">a textarea</textarea>
&nbsp;&nbsp;
<textarea name=a id=textarea1 value="a textarea">another textarea
size, font set by css</textarea>
<BR><BR>
a checkbox: <input type=checkbox name=check1 checked>
<BR><BR>
<input type=radio name=group1> radio1
<input type=radio name=group1 checked> radio2
<BR>
<P>select/option examples - the combo box is not aligned properly</P>
<select name=select1 size=2>
<option selected>option 1</option>
<option>option 2</option>
</select>
<select name=select2 size=4 multiple>
<input type=radio name=group1 checked> radio2
<BR><BR>
<select name=select2 id=select1 size=4 multiple>
<option>option 1</option>
<option>option 2</option>
<option selected>option 3</option>
@ -34,16 +52,19 @@
<option>option 5</option>
<option>option 6</option>
</select>
<select name=select1 size=2>
<option selected>option 1</option>
<option>option 2</option>
</select>
<select name=select3 size=1>
<option selected>option 1</option>
<option>option 2</option>
</select>
<BR><BR>
<input type=file size=20 name=file value=myfile>&nbsp;&nbsp;file content not being sent yet
<BR>
<P>input type=file - currently, file content is not being sent</P>
<input type=file size=20 name=file value=myfile>
<BR>
<input type=reset name=reset value="RESET">
<input type=submit name=submit value="SUBMIT">
<input type=reset name=reset id=input2 value="RESET">
<input type=submit id=input1 name=submit value="SUBMIT">
<input type=image src=raptor.jpg width=50 height=50 name=imageSubmit> an image submit. For now, click twice.
</form>