From 0e7916f242eea495453f14e86f7dcc8c3603653b Mon Sep 17 00:00:00 2001 From: "pollmann%netscape.com" Date: Thu, 16 Sep 1999 20:13:41 +0000 Subject: [PATCH] Bug 12350: selected read/write --- dom/public/html/nsIDOMHTMLOptionElement.h | 3 +++ dom/public/idl/html/HTMLOptionElement.idl | 2 +- dom/src/html/nsJSHTMLOptionElement.cpp | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/dom/public/html/nsIDOMHTMLOptionElement.h b/dom/public/html/nsIDOMHTMLOptionElement.h index a448f8912e2f..0cd3af703f03 100644 --- a/dom/public/html/nsIDOMHTMLOptionElement.h +++ b/dom/public/html/nsIDOMHTMLOptionElement.h @@ -52,6 +52,7 @@ public: NS_IMETHOD SetLabel(const nsString& aLabel)=0; NS_IMETHOD GetSelected(PRBool* aSelected)=0; + NS_IMETHOD SetSelected(PRBool aSelected)=0; NS_IMETHOD GetValue(nsString& aValue)=0; NS_IMETHOD SetValue(const nsString& aValue)=0; @@ -70,6 +71,7 @@ public: NS_IMETHOD GetLabel(nsString& aLabel); \ NS_IMETHOD SetLabel(const nsString& aLabel); \ NS_IMETHOD GetSelected(PRBool* aSelected); \ + NS_IMETHOD SetSelected(PRBool aSelected); \ NS_IMETHOD GetValue(nsString& aValue); \ NS_IMETHOD SetValue(const nsString& aValue); \ @@ -87,6 +89,7 @@ public: NS_IMETHOD GetLabel(nsString& aLabel) { return _to GetLabel(aLabel); } \ NS_IMETHOD SetLabel(const nsString& aLabel) { return _to SetLabel(aLabel); } \ NS_IMETHOD GetSelected(PRBool* aSelected) { return _to GetSelected(aSelected); } \ + NS_IMETHOD SetSelected(PRBool aSelected) { return _to SetSelected(aSelected); } \ NS_IMETHOD GetValue(nsString& aValue) { return _to GetValue(aValue); } \ NS_IMETHOD SetValue(const nsString& aValue) { return _to SetValue(aValue); } \ diff --git a/dom/public/idl/html/HTMLOptionElement.idl b/dom/public/idl/html/HTMLOptionElement.idl index 8bf415e755f1..ff712cea97fa 100644 --- a/dom/public/idl/html/HTMLOptionElement.idl +++ b/dom/public/idl/html/HTMLOptionElement.idl @@ -10,7 +10,7 @@ attribute long index; attribute boolean disabled; attribute DOMString label; - readonly attribute boolean selected; + attribute boolean selected; attribute DOMString value; }; diff --git a/dom/src/html/nsJSHTMLOptionElement.cpp b/dom/src/html/nsJSHTMLOptionElement.cpp index a7b50c655d00..e41f4aaf1f3d 100644 --- a/dom/src/html/nsJSHTMLOptionElement.cpp +++ b/dom/src/html/nsJSHTMLOptionElement.cpp @@ -327,6 +327,22 @@ SetHTMLOptionElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) break; } + case HTMLOPTIONELEMENT_SELECTED: + { + PRBool ok = PR_FALSE; + secMan->CheckScriptAccess(scriptCX, obj, "htmloptionelement.selected", PR_TRUE, &ok); + if (!ok) { + return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR); + } + PRBool prop; + if (PR_FALSE == nsJSUtils::nsConvertJSValToBool(&prop, cx, *vp)) { + return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_BOOLEAN_ERR); + } + + a->SetSelected(prop); + + break; + } case HTMLOPTIONELEMENT_VALUE: { PRBool ok = PR_FALSE; @@ -412,7 +428,7 @@ static JSPropertySpec HTMLOptionElementProperties[] = {"index", HTMLOPTIONELEMENT_INDEX, JSPROP_ENUMERATE}, {"disabled", HTMLOPTIONELEMENT_DISABLED, JSPROP_ENUMERATE}, {"label", HTMLOPTIONELEMENT_LABEL, JSPROP_ENUMERATE}, - {"selected", HTMLOPTIONELEMENT_SELECTED, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"selected", HTMLOPTIONELEMENT_SELECTED, JSPROP_ENUMERATE}, {"value", HTMLOPTIONELEMENT_VALUE, JSPROP_ENUMERATE}, {0} };