Bug 841488 - Part d: Move HTMLSelectElement to WebIDL bindings, remove CI and QS; r=khuey

This commit is contained in:
Ms2ger 2013-04-13 09:01:59 +02:00
parent ebd729fff1
commit 8f5d5c7049
11 changed files with 82 additions and 176 deletions

View File

@ -39,6 +39,8 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
// nsWrapperCache
using nsWrapperCache::GetWrapperPreserveColor;
virtual JSObject* WrapObject(JSContext* cx, JSObject* scope) MOZ_OVERRIDE;
// nsIDOMHTMLOptionsCollection interface

View File

@ -9,6 +9,7 @@
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLOptGroupElement.h"
#include "mozilla/dom/HTMLOptionElement.h"
#include "mozilla/dom/HTMLSelectElementBinding.h"
#include "mozilla/Util.h"
#include "nsContentCreatorFunctions.h"
#include "nsError.h"
@ -35,7 +36,6 @@
#include "nsTextNode.h"
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Select)
DOMCI_NODE_DATA(HTMLSelectElement, mozilla::dom::HTMLSelectElement)
namespace mozilla {
namespace dom {
@ -124,6 +124,8 @@ HTMLSelectElement::HTMLSelectElement(already_AddRefed<nsINodeInfo> aNodeInfo,
AddStatesSilently(NS_EVENT_STATE_ENABLED |
NS_EVENT_STATE_OPTIONAL |
NS_EVENT_STATE_VALID);
SetIsDOMBinding();
}
HTMLSelectElement::~HTMLSelectElement()
@ -154,7 +156,7 @@ NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLSelectElement)
nsIConstraintValidation)
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(HTMLSelectElement,
nsGenericHTMLFormElement)
NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLSelectElement)
NS_HTML_CONTENT_INTERFACE_MAP_END
// nsIDOMHTMLSelectElement
@ -1961,5 +1963,11 @@ HTMLSelectElement::SetSelectionChanged(bool aValue, bool aNotify)
}
}
JSObject*
HTMLSelectElement::WrapNode(JSContext* aCx, JSObject* aScope)
{
return HTMLSelectElementBinding::Wrap(aCx, aScope, this);
}
} // namespace dom
} // namespace mozilla

View File

@ -239,6 +239,10 @@ public:
// nsIConstraintValidation::SetCustomValidity() is fine.
// nsINode
virtual JSObject*
WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
// nsIContent
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
@ -373,13 +377,6 @@ public:
return mOptions;
}
static HTMLSelectElement* FromSupports(nsISupports* aSupports)
{
return static_cast<HTMLSelectElement*>(static_cast<nsINode*>(aSupports));
}
virtual nsXPCClassInfo* GetClassInfo();
virtual nsIDOMNode* AsDOMNode() { return this; }
// nsIConstraintValidation

View File

@ -12,7 +12,7 @@ test(function() {
assert_equals(select[0], option);
select[0] = null;
assert_equals(option.parentNode, null);
assert_equals(select[0], null);
assert_equals(select[0], undefined);
}, "Should be able to set select[n] to null.");
test(function() {
var select = document.createElement("select");

View File

@ -116,11 +116,6 @@
// Constraint Validation API helper includes
#include "nsIDOMValidityState.h"
// HTMLSelectElement helper includes
#include "nsIDOMHTMLSelectElement.h"
#include "nsIDOMHTMLOptionElement.h"
// Event related includes
#include "nsEventListenerManager.h"
#include "nsIDOMEventTarget.h"
@ -286,7 +281,6 @@
#include "nsIEventListenerService.h"
#include "nsIMessageManager.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLSelectElement.h"
#include "HTMLLegendElement.h"
#include "DOMSVGStringList.h"
@ -644,10 +638,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLInputElement, nsElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLSelectElement, nsHTMLSelectElementSH,
ELEMENT_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_SETPROPERTY |
nsIXPCScriptable::WANT_GETPROPERTY)
// Constraint Validation API classes
NS_DEFINE_CLASSINFO_DATA(ValidityState, nsDOMGenericSH,
@ -1936,11 +1926,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_GENERIC_HTML_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(HTMLSelectElement, nsIDOMHTMLSelectElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLSelectElement)
DOM_CLASSINFO_GENERIC_HTML_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(ValidityState, nsIDOMValidityState)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMValidityState)
DOM_CLASSINFO_MAP_END
@ -7215,110 +7200,6 @@ nsHTMLFormElementSH::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
}
// HTMLSelectElement helper
NS_IMETHODIMP
nsHTMLSelectElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, uint32_t flags,
JSObject **objp, bool *_retval)
{
int32_t n = GetArrayIndexFromId(cx, id);
if (n >= 0) {
HTMLSelectElement *s =
HTMLSelectElement::FromSupports(GetNative(wrapper, obj));
HTMLOptionsCollection *options = s->GetOptions();
if (options) {
nsISupports *node = options->GetElementAt(n);
if (node) {
*objp = obj;
*_retval = JS_DefineElement(cx, obj, uint32_t(n), JSVAL_VOID, nullptr, nullptr,
JSPROP_ENUMERATE | JSPROP_SHARED);
return NS_OK;
}
}
}
return nsElementSH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
}
NS_IMETHODIMP
nsHTMLSelectElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj, jsid id,
jsval *vp, bool *_retval)
{
int32_t n = GetArrayIndexFromId(cx, id);
nsresult rv = NS_OK;
if (n >= 0) {
HTMLSelectElement *s =
HTMLSelectElement::FromSupports(GetNative(wrapper, obj));
HTMLOptionsCollection *options = s->GetOptions();
if (options) {
nsISupports *node = options->GetElementAt(n);
rv = WrapNative(cx, JS_GetGlobalForScopeChain(cx), node,
&NS_GET_IID(nsIDOMNode), true, vp);
if (NS_SUCCEEDED(rv)) {
rv = NS_SUCCESS_I_DID_SOMETHING;
}
return rv;
}
}
return NS_OK;
}
// static
nsresult
nsHTMLSelectElementSH::SetOption(JSContext *cx, JS::Value *vp, uint32_t aIndex,
nsIDOMHTMLOptionsCollection *aOptCollection)
{
JSAutoRequest ar(cx);
// vp must refer to an object
if (!vp->isObjectOrNull()) {
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIDOMHTMLOptionElement> new_option;
if (JSObject* obj = vp->toObjectOrNull()) {
new_option = do_QueryWrapper(cx, obj);
if (!new_option) {
// Someone is trying to set an option to a non-option object.
return NS_ERROR_UNEXPECTED;
}
}
return aOptCollection->SetOption(aIndex, new_option);
}
NS_IMETHODIMP
nsHTMLSelectElementSH::SetProperty(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj, jsid id,
jsval *vp, bool *_retval)
{
int32_t n = GetArrayIndexFromId(cx, id);
if (n >= 0) {
nsCOMPtr<nsIDOMHTMLSelectElement> select =
do_QueryWrappedNative(wrapper, obj);
NS_ENSURE_TRUE(select, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIDOMHTMLOptionsCollection> options;
select->GetOptions(getter_AddRefs(options));
nsresult rv = SetOption(cx, vp, n, options);
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
}
return NS_OK;
}
// Plugin helper
nsISupports*

View File

@ -23,8 +23,6 @@
class nsContentList;
class nsGlobalWindow;
class nsICanvasRenderingContextInternal;
class nsIDOMHTMLOptionsCollection;
class nsIDOMWindow;
class nsIForm;
class nsIHTMLDocument;
@ -733,38 +731,6 @@ public:
};
// HTMLSelectElement helper
class nsHTMLSelectElementSH : public nsElementSH
{
protected:
nsHTMLSelectElementSH(nsDOMClassInfoData* aData) : nsElementSH(aData)
{
}
virtual ~nsHTMLSelectElementSH()
{
}
public:
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, uint32_t flags,
JSObject **objp, bool *_retval);
NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp,
bool *_retval);
NS_IMETHOD SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, bool *_retval);
static nsresult SetOption(JSContext *cx, jsval *vp, uint32_t aIndex,
nsIDOMHTMLOptionsCollection *aOptCollection);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsHTMLSelectElementSH(aData);
}
};
// Plugin helper
class nsPluginSH : public nsNamedArraySH

View File

@ -48,7 +48,6 @@ DOMCI_CLASS(HTMLDocument)
DOMCI_CLASS(HTMLFormElement)
DOMCI_CLASS(HTMLIFrameElement)
DOMCI_CLASS(HTMLInputElement)
DOMCI_CLASS(HTMLSelectElement)
DOMCI_CLASS(ValidityState)
// CSS classes

View File

@ -501,6 +501,15 @@ DOMInterfaces = {
}
},
'HTMLSelectElement': {
'resultNotAddRefed': [
'form',
'item',
'options',
'IndexedGetter',
]
},
'HTMLStyleElement': {
'resultNotAddRefed': [
'sheet'

View File

@ -0,0 +1,55 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* http://www.whatwg.org/html/#the-select-element
*/
interface HTMLSelectElement : HTMLElement {
[SetterThrows, Pure]
attribute boolean autofocus;
[SetterThrows, Pure]
attribute boolean disabled;
[Pure]
readonly attribute HTMLFormElement? form;
[SetterThrows, Pure]
attribute boolean multiple;
[SetterThrows, Pure]
attribute DOMString name;
[SetterThrows, Pure]
attribute boolean required;
[SetterThrows, Pure]
attribute unsigned long size;
[Pure]
readonly attribute DOMString type;
[Constant]
readonly attribute HTMLOptionsCollection options;
[SetterThrows, Pure]
attribute unsigned long length;
getter Element item(unsigned long index);
[Throws]
object namedItem(DOMString name);
[Throws]
void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
void remove(long index);
[Throws]
setter creator void (unsigned long index, HTMLOptionElement? option);
// NYI: readonly attribute HTMLCollection selectedOptions;
[SetterThrows, Pure]
attribute long selectedIndex;
[Pure]
attribute DOMString value;
readonly attribute boolean willValidate;
readonly attribute ValidityState validity;
readonly attribute DOMString validationMessage;
boolean checkValidity();
void setCustomValidity(DOMString error);
// NYI: readonly attribute NodeList labels;
};

View File

@ -125,6 +125,7 @@ webidl_files = \
HTMLPropertiesCollection.webidl \
HTMLQuoteElement.webidl \
HTMLScriptElement.webidl \
HTMLSelectElement.webidl \
HTMLSourceElement.webidl \
HTMLSpanElement.webidl \
HTMLStyleElement.webidl \

View File

@ -94,18 +94,6 @@ members = [
'nsIDOMHTMLFormElement.length',
'nsIDOMHTMLFormElement.target',
'nsIDOMHTMLFormElement.action',
'nsIDOMHTMLSelectElement.name',
'nsIDOMHTMLSelectElement.form',
'nsIDOMHTMLSelectElement.add',
'nsIDOMHTMLSelectElement.value',
'nsIDOMHTMLSelectElement.disabled',
'nsIDOMHTMLSelectElement.length',
'nsIDOMHTMLSelectElement.remove',
'nsIDOMHTMLSelectElement.selectedIndex',
'nsIDOMHTMLSelectElement.item',
'nsIDOMHTMLSelectElement.type',
'nsIDOMHTMLSelectElement.options',
'nsIDOMHTMLSelectElement.size',
'nsIDOMHTMLCanvasElement.width',
'nsIDOMHTMLCanvasElement.height',
'nsIDOMHTMLCanvasElement.getContext',