more select/option support

This commit is contained in:
karnaze 1998-05-13 17:43:35 +00:00
parent 82f96bdfb7
commit 68b9679002
9 changed files with 121 additions and 75 deletions

View File

@ -594,20 +594,29 @@ PRBool HTMLContentSink::CloseContainer(const nsIParserNode& aNode)
mContainerStack[mStackPos] = nsnull;
nsIHTMLContent* parent = nsnull;
switch (aNode.GetNodeType()) {
case eHTMLTag_option:
ProcessCloseOPTIONTag(aNode);
eHTMLTags parentType;
parent = GetCurrentContainer(&parentType);
container->Compact();
if(parent) {
parent->AppendChild(container);
}
break;
case eHTMLTag_select:
ProcessCloseSELECTTag(aNode);
break;
ProcessCloseSELECTTag(aNode); // add fall through
default:
if (nsnull != container) {
// Now that this container is complete, append it to it's parent
eHTMLTags parentType;
nsIHTMLContent* parent = GetCurrentContainer(&parentType);
parent = GetCurrentContainer(&parentType);
container->Compact();
if(parent) {
@ -1225,7 +1234,7 @@ HTMLContentSink::ProcessOpenOPTIONTag(nsIHTMLContent** aInstancePtrResult,
if ((NS_OK == rv) && (nsnull != mCurrentSelect)) {
// Add remaining attributes from the tag
//rv = AddAttributes(aNode, mCurrentOption);
*aInstancePtrResult = mCurrentSelect;
*aInstancePtrResult = mCurrentOption;
}
NS_RELEASE(atom);
}

View File

@ -143,7 +143,7 @@ PRBool nsHTMLContainer::ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex)
PRBool nsHTMLContainer::AppendChild(nsIContent* aKid)
{
NS_PRECONDITION(nsnull != aKid, "null ptr");
NS_PRECONDITION((nsnull != aKid) && (aKid != this), "null ptr");
PRBool rv = mChildren.AppendElement(aKid);
if (rv) {
NS_ADDREF(aKid);

View File

@ -594,20 +594,29 @@ PRBool HTMLContentSink::CloseContainer(const nsIParserNode& aNode)
mContainerStack[mStackPos] = nsnull;
nsIHTMLContent* parent = nsnull;
switch (aNode.GetNodeType()) {
case eHTMLTag_option:
ProcessCloseOPTIONTag(aNode);
eHTMLTags parentType;
parent = GetCurrentContainer(&parentType);
container->Compact();
if(parent) {
parent->AppendChild(container);
}
break;
case eHTMLTag_select:
ProcessCloseSELECTTag(aNode);
break;
ProcessCloseSELECTTag(aNode); // add fall through
default:
if (nsnull != container) {
// Now that this container is complete, append it to it's parent
eHTMLTags parentType;
nsIHTMLContent* parent = GetCurrentContainer(&parentType);
parent = GetCurrentContainer(&parentType);
container->Compact();
if(parent) {
@ -1225,7 +1234,7 @@ HTMLContentSink::ProcessOpenOPTIONTag(nsIHTMLContent** aInstancePtrResult,
if ((NS_OK == rv) && (nsnull != mCurrentSelect)) {
// Add remaining attributes from the tag
//rv = AddAttributes(aNode, mCurrentOption);
*aInstancePtrResult = mCurrentSelect;
*aInstancePtrResult = mCurrentOption;
}
NS_RELEASE(atom);
}

View File

@ -516,7 +516,6 @@ nsForm::OnRadioChecked(nsIFormControl& aControl)
nsString groupName;
group->GetName(groupName);
nsIFormControl* checkedRadio = group->GetCheckedRadio();
printf("\n group name=%s radio name=%s", groupName.ToNewCString(), radioName.ToNewCString());
if (groupName.Equals(radioName) && (nsnull != checkedRadio) & (&aControl != checkedRadio)) {
checkedRadio->SetChecked(PR_FALSE, PR_FALSE);
group->SetCheckedRadio(&aControl);

View File

@ -154,6 +154,7 @@ public:
}
virtual void GetType(nsString& aResult) const = 0;
PRInt32 GetSize() const { return mSize; }
virtual PRBool GetChecked(PRBool aGetInitialValue) const;
virtual void SetChecked(PRBool aState, PRBool aSetInitialValue);
virtual void SetClickPoint(nscoord aX, nscoord aY);

View File

@ -469,7 +469,7 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
PRBool& aHeightExplicit, nscoord& aRowHeight)
{
nscoord charWidth = 0;
PRInt32 numRows = 1;
PRInt32 numRows = ATTR_NOTSET;
aWidthExplicit = PR_FALSE;
aHeightExplicit = PR_FALSE;
@ -570,6 +570,9 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
}
NS_RELEASE(content);
if (ATTR_NOTSET == numRows) {
numRows = aBounds.height / aRowHeight;
}
return numRows;
}

View File

@ -57,7 +57,6 @@ public:
virtual const nsIID& GetIID();
NS_IMETHOD SizeTo(nscoord aWidth, nscoord aHeight);
PRBool IsComboBox();
protected:
@ -67,6 +66,7 @@ protected:
const nsSize& aMaxSize,
nsReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize);
PRBool mIsComboBox;
};
class nsSelect : public nsInput
@ -92,7 +92,7 @@ public:
PRBool IsMultiple() { return mMultiple; }
PRBool IsComboBox();
PRBool GetMultiple() const { return mMultiple; }
virtual void Reset();
@ -126,9 +126,9 @@ public:
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames);
PRBool GetText(nsString& aString) const;
PRBool GetContent(nsString& aString) const;
void SetText(nsString& aString);
void SetContent(const nsString& aValue);
protected:
virtual ~nsOption();
@ -136,13 +136,13 @@ protected:
virtual void GetType(nsString& aResult) const;
PRBool mSelected;
nsString* mText;
nsString* mContent;
};
nsSelectFrame::nsSelectFrame(nsIContent* aContent,
nsIFrame* aParentFrame)
: nsInputFrame(aContent, aParentFrame)
: nsInputFrame(aContent, aParentFrame), mIsComboBox(PR_FALSE)
{
}
@ -150,17 +150,11 @@ nsSelectFrame::~nsSelectFrame()
{
}
PRBool
nsSelectFrame::IsComboBox()
{
nsSelect* content = (nsSelect *) mContent;
return content->IsComboBox();
}
const nsIID&
nsSelectFrame::GetIID()
{
if (IsComboBox()) {
if (mIsComboBox) {
return kComboBoxIID;
}
else {
@ -174,7 +168,7 @@ nsSelectFrame::GetCID()
static NS_DEFINE_IID(kComboCID, NS_COMBOBOX_CID);
static NS_DEFINE_IID(kListCID, NS_LISTBOX_CID);
if (IsComboBox()) {
if (mIsComboBox) {
return kComboCID;
}
else {
@ -201,7 +195,7 @@ nsSelectFrame::GetDesiredSize(nsIPresContext* aPresContext,
for (int i = 0; i < numChildren; i++) {
nsOption* option = (nsOption*) select->ChildAt(i); // YYY this had better be an option
nsString text;
if (PR_FALSE == option->GetText(text)) {
if (PR_FALSE == option->GetContent(text)) {
continue;
}
nsSize textSize;
@ -223,18 +217,27 @@ nsSelectFrame::GetDesiredSize(nsIPresContext* aPresContext,
calcSize.height += 100;
}
PRBool isCombo = IsComboBox();
// 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
aDesiredLayoutSize.width = ((numRows < select->ChildCount()) || isCombo)
? calcSize.width + 350 : calcSize.width + 100;
if (heightExplicit) {
aDesiredLayoutSize.width = calcSize.width;
}
else {
aDesiredLayoutSize.width = ((numRows < select->ChildCount()) || mIsComboBox)
? calcSize.width + gScrollBarWidth : calcSize.width + 100; // XXX why the 100 padding
}
aDesiredLayoutSize.height = calcSize.height;
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
aDesiredLayoutSize.descent = 0;
aDesiredWidgetSize.width = aDesiredLayoutSize.width;
aDesiredWidgetSize.height =
(isCombo && !heightExplicit) ? aDesiredLayoutSize.height + (rowHeight * numChildren) + 100
: aDesiredLayoutSize.height;
(mIsComboBox && !heightExplicit) ? aDesiredLayoutSize.height + (rowHeight * numChildren) + 100
: aDesiredLayoutSize.height;
NS_RELEASE(select);
}
@ -257,7 +260,7 @@ nsSelectFrame::GetWidgetInitData()
NS_METHOD
nsSelectFrame::SizeTo(nscoord aWidth, nscoord aHeight)
{
nscoord height = (IsComboBox()) ? mWidgetSize.height : aHeight;
nscoord height = (mIsComboBox) ? mWidgetSize.height : aHeight;
return nsInputFrame::SizeTo(aWidth, height);
}
@ -274,18 +277,13 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
nsresult stat = view->QueryInterface(kListWidgetIID, (void **) &list);
NS_ASSERTION((NS_OK == stat), "invalid widget");
PRBool isCombo = IsComboBox();
PRInt32 numChildren = select->ChildCount();
for (int i = 0; i < numChildren; i++) {
nsOption* option = (nsOption*) select->ChildAt(i); // YYY this had better be an option
nsString text;
if (PR_TRUE != option->GetText(text)) {
if (PR_TRUE != option->GetContent(text)) {
text = " ";
}
// if (isCombo) {
// printf("\n ** text = %s", text.ToNewCString());
// list->AddItemAt(text, 1);
// }
list->AddItemAt(text, i);
}
@ -349,25 +347,10 @@ nsContentAttr nsSelect::GetAttribute(nsIAtom* aAttribute,
}
}
PRBool
nsSelect::IsComboBox()
{
// PRBool multiple;
// PRInt32 size;
// GetAttribute(nsHTMLAtoms::size, size);
// GetAttribute(nsHTMLAtoms::multiple, multiple);
PRBool result = (!mMultiple && (mSize <= 1)) ? PR_TRUE : PR_FALSE;
return result;
}
PRInt32
nsSelect::GetMaxNumValues()
{
// PRBool isMultiple;
// GetAttribute(nsHTMLAtoms::multiple, isMultiple);
if (mMultiple) {
return ChildCount();
}
@ -463,14 +446,14 @@ nsSelect::Reset()
nsOption::nsOption(nsIAtom* aTag)
: nsInput(aTag, nsnull)
{
mText = nsnull;
mContent = nsnull;
mSelected = PR_FALSE;
}
nsOption::~nsOption()
{
if (nsnull != mText) {
delete mText;
if (nsnull != mContent) {
delete mContent;
}
}
@ -524,25 +507,24 @@ nsOption::GetMaxNumValues()
return 1;
}
PRBool nsOption::GetText(nsString& aString) const
PRBool nsOption::GetContent(nsString& aString) const
{
if (nsnull == mText) {
if (nsnull == mContent) {
aString.SetLength(0);
return PR_FALSE;
}
else {
aString = *mText;
aString = *mContent;
return PR_TRUE;
}
}
void nsOption::SetText(nsString& aString)
void nsOption::SetContent(const nsString& aString)
{
if (nsnull == mText) {
mText = new nsString(aString);
}
else {
*mText = aString;
if (nsnull == mContent) {
mContent = new nsString();
}
*mContent = aString;
}
PRBool
@ -561,8 +543,8 @@ nsOption::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
aNumValues = 1;
return PR_TRUE;
}
else if (nsnull != mText) {
aValues[0] = *mText;
else if (nsnull != mContent) {
aValues[0] = *mContent;
aNumValues = 1;
return PR_TRUE;
}
@ -645,7 +627,7 @@ void HACK(nsSelect* aSel, PRInt32 aIndex)
NS_NewHTMLOption((nsIHTMLContent**)&option, atom);
sprintf(&buf[0], "option %d", i);
nsString label(&buf[0]);
option->SetText(label);
option->SetContent(label);
aSel->AppendChild(option);
}
}

View File

@ -1,6 +1,6 @@
<html>
<head>
<title>Example 8a</title>
<title>Example 8-1</title>
<style>
TEXTAREA#textarea150x100 {
width: 150px;
@ -11,12 +11,21 @@ INPUT#input100x50 {
width: 100px;
height: 50px;
}
SELECT#select100x100 {
width: 100px;
height: 100px;
}
SELECT#select100x50 {
width: 100px;
height: 50px;
font-size: large;
}
</style>
</head>
<body>
<H1>Example 8a: Forms</H1>
<H1>Example 8-1: Forms</H1>
<BR>
@ -26,10 +35,31 @@ INPUT#input100x50 {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<textarea id=textarea150x100>textarea 2</textarea>
<BR>
<PRE>text size=8 text width=100 height=50 aligh=rigth</PRE>
<PRE>text size=8 text width=100 height=50 aligh=right</PRE>
<input type=text size=8 value=text>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type=text id=input100x50 value=text align=right>
<BR>
<PRE>select width=100 height=100 select width=100 height=50 font-size=large</PRE>
<select name=select1 id=select100x100>
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
<option>option 5</option>
<option>option 6</option>
<option>option 7</option>
<option>option 8</option>
</select>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name=select2 id=select100x50 multiple>
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
<option>option 5</option>
<option>option 6</option>
</select>
</form>
</body>

View File

@ -21,10 +21,23 @@
<input type=radio name=group1> radio1
<input type=radio name=group1 checked> radio2
<BR>
<P>select/option hacks; why don't these line up</P>
<input type=select1>&nbsp;&nbsp;
<input type=select2>&nbsp;&nbsp;
<input type=select3>
<P>select/option examples, the combo box alignment is waiting on a widget library modification</P>
<select name=select1 size=2>
<option selected>option 1</option>
<option>option 2</option>
</select>
<select name=select2 size=4 multiple>
<option>option 1</option>
<option>option 2</option>
<option selected>option 3</option>
<option>option 4</option>
<option>option 5</option>
<option>option 6</option>
</select>
<select name=select3 size=1>
<option selected>option 1</option>
<option>option 2</option>
</select>
<BR>
<input type=reset name=reset value="RESET">
<input type=submit name=submit value="SUBMIT">