From bf8234dd487818eb08a13046162158a26c1a7c12 Mon Sep 17 00:00:00 2001 From: karnaze Date: Wed, 13 May 1998 17:43:35 +0000 Subject: [PATCH] more select/option support git-svn-id: svn://10.0.0.236/trunk@1517 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLContentSink.cpp | 17 +++- .../layout/html/base/src/nsHTMLContainer.cpp | 2 +- .../html/document/src/nsHTMLContentSink.cpp | 17 +++- mozilla/layout/html/forms/src/nsForm.cpp | 1 - mozilla/layout/html/forms/src/nsInput.h | 1 + .../layout/html/forms/src/nsInputFrame.cpp | 5 +- mozilla/layout/html/forms/src/nsSelect.cpp | 96 ++++++++----------- .../tests/viewer/samples/test8-1.html | 36 ++++++- .../webshell/tests/viewer/samples/test8.html | 21 +++- 9 files changed, 121 insertions(+), 75 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 46ddeb94e6c..366ae34fd35 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -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); } diff --git a/mozilla/layout/html/base/src/nsHTMLContainer.cpp b/mozilla/layout/html/base/src/nsHTMLContainer.cpp index de695cfdf3a..d9dfb75fff0 100644 --- a/mozilla/layout/html/base/src/nsHTMLContainer.cpp +++ b/mozilla/layout/html/base/src/nsHTMLContainer.cpp @@ -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); diff --git a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp index 46ddeb94e6c..366ae34fd35 100644 --- a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp @@ -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); } diff --git a/mozilla/layout/html/forms/src/nsForm.cpp b/mozilla/layout/html/forms/src/nsForm.cpp index 5ae15b3f1e7..59a34a44e49 100644 --- a/mozilla/layout/html/forms/src/nsForm.cpp +++ b/mozilla/layout/html/forms/src/nsForm.cpp @@ -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); diff --git a/mozilla/layout/html/forms/src/nsInput.h b/mozilla/layout/html/forms/src/nsInput.h index 59962aee865..0fc4e3cba01 100644 --- a/mozilla/layout/html/forms/src/nsInput.h +++ b/mozilla/layout/html/forms/src/nsInput.h @@ -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); diff --git a/mozilla/layout/html/forms/src/nsInputFrame.cpp b/mozilla/layout/html/forms/src/nsInputFrame.cpp index 63ddd6e6a9f..06c52ad6817 100644 --- a/mozilla/layout/html/forms/src/nsInputFrame.cpp +++ b/mozilla/layout/html/forms/src/nsInputFrame.cpp @@ -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; } diff --git a/mozilla/layout/html/forms/src/nsSelect.cpp b/mozilla/layout/html/forms/src/nsSelect.cpp index 74e76f02a46..247078b4b74 100644 --- a/mozilla/layout/html/forms/src/nsSelect.cpp +++ b/mozilla/layout/html/forms/src/nsSelect.cpp @@ -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); } } diff --git a/mozilla/webshell/tests/viewer/samples/test8-1.html b/mozilla/webshell/tests/viewer/samples/test8-1.html index 1709d7d0b36..40e01e3ddb0 100644 --- a/mozilla/webshell/tests/viewer/samples/test8-1.html +++ b/mozilla/webshell/tests/viewer/samples/test8-1.html @@ -1,6 +1,6 @@ -Example 8a +Example 8-1 -

Example 8a: Forms

+

Example 8-1: Forms


@@ -26,10 +35,31 @@ INPUT#input100x50 {           
-
text size=8    text width=100 height=50 aligh=rigth
+
text size=8    text width=100 height=50 aligh=right
           +
+
select width=100 height=100  select width=100 height=50 font-size=large
+ +           + diff --git a/mozilla/webshell/tests/viewer/samples/test8.html b/mozilla/webshell/tests/viewer/samples/test8.html index 84c1233dafb..4719b494d0e 100644 --- a/mozilla/webshell/tests/viewer/samples/test8.html +++ b/mozilla/webshell/tests/viewer/samples/test8.html @@ -21,10 +21,23 @@ radio1 radio2
-

select/option hacks; why don't these line up

-   -   - +

select/option examples, the combo box alignment is waiting on a widget library modification

+ + +