From b6fa9960a151dbfc62bef899d72779395aed147d Mon Sep 17 00:00:00 2001 From: "pollmann%netscape.com" Date: Wed, 19 May 1999 03:46:25 +0000 Subject: [PATCH] Bug 3187: Add frame notification on option creation and destruction. git-svn-id: svn://10.0.0.236/trunk@32252 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/content/src/nsHTMLSelectElement.cpp | 26 +++++++++++++++++-- .../html/content/src/nsHTMLSelectElement.cpp | 26 +++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp index b118ff015f4..b9be860fa29 100644 --- a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp @@ -542,17 +542,39 @@ nsHTMLSelectElement::AddOption(nsIContent* aContent) mOptions->AddOption(aContent); } + // Update the widget + nsIFormControlFrame* selectFrame = nsnull; + nsresult result = nsGenericHTMLElement::GetPrimaryFrame(this, selectFrame); + if (NS_SUCCEEDED(result) && (nsnull != selectFrame)) { + nsString action("a"); + action.Append(mOptions->IndexOf(aContent),10); + selectFrame->SetProperty(nsHTMLAtoms::option, action); + } + + // When first populating, GetPrimaryFrame will fail but it's ok return NS_OK; } NS_IMETHODIMP nsHTMLSelectElement::RemoveOption(nsIContent* aContent) { + // We can't get our index if we've already been replaced in the OptionList. + // If we couldn't get our index, pass -1, remove all options and recreate + PRInt32 index = mOptions->IndexOf(aContent); if (nsnull != mOptions) { mOptions->RemoveOption(aContent); } - return NS_OK; + // Update the widget + nsIFormControlFrame* selectFrame = nsnull; + nsresult result = nsGenericHTMLElement::GetPrimaryFrame(this, selectFrame); + if (NS_SUCCEEDED(result) && (nsnull != selectFrame)) { + nsString action("r"); + action.Append(index,10); + selectFrame->SetProperty(nsHTMLAtoms::option, action); + } + + return result; } NS_IMETHODIMP @@ -902,7 +924,7 @@ nsOptionList::SetProperty(JSContext *aContext, PRInt32 length = mElements.Count(); // If the index is within range - if ((index > 0) && (index <= length)) { + if ((index >= 0) && (index <= length)) { // if the value is null, remove this option if (JSVAL_IS_NULL(*aVp)) { diff --git a/mozilla/layout/html/content/src/nsHTMLSelectElement.cpp b/mozilla/layout/html/content/src/nsHTMLSelectElement.cpp index b118ff015f4..b9be860fa29 100644 --- a/mozilla/layout/html/content/src/nsHTMLSelectElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLSelectElement.cpp @@ -542,17 +542,39 @@ nsHTMLSelectElement::AddOption(nsIContent* aContent) mOptions->AddOption(aContent); } + // Update the widget + nsIFormControlFrame* selectFrame = nsnull; + nsresult result = nsGenericHTMLElement::GetPrimaryFrame(this, selectFrame); + if (NS_SUCCEEDED(result) && (nsnull != selectFrame)) { + nsString action("a"); + action.Append(mOptions->IndexOf(aContent),10); + selectFrame->SetProperty(nsHTMLAtoms::option, action); + } + + // When first populating, GetPrimaryFrame will fail but it's ok return NS_OK; } NS_IMETHODIMP nsHTMLSelectElement::RemoveOption(nsIContent* aContent) { + // We can't get our index if we've already been replaced in the OptionList. + // If we couldn't get our index, pass -1, remove all options and recreate + PRInt32 index = mOptions->IndexOf(aContent); if (nsnull != mOptions) { mOptions->RemoveOption(aContent); } - return NS_OK; + // Update the widget + nsIFormControlFrame* selectFrame = nsnull; + nsresult result = nsGenericHTMLElement::GetPrimaryFrame(this, selectFrame); + if (NS_SUCCEEDED(result) && (nsnull != selectFrame)) { + nsString action("r"); + action.Append(index,10); + selectFrame->SetProperty(nsHTMLAtoms::option, action); + } + + return result; } NS_IMETHODIMP @@ -902,7 +924,7 @@ nsOptionList::SetProperty(JSContext *aContext, PRInt32 length = mElements.Count(); // If the index is within range - if ((index > 0) && (index <= length)) { + if ((index >= 0) && (index <= length)) { // if the value is null, remove this option if (JSVAL_IS_NULL(*aVp)) {