Bug 839447 - Convert HTMLOptionElement to WebIDL, r=Ms2ger

This commit is contained in:
Andrea Marchesini 2013-02-18 13:26:57 +01:00
parent 60b0525214
commit dc2ed94e37
6 changed files with 113 additions and 12 deletions

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/HTMLOptionElement.h"
#include "mozilla/dom/HTMLOptionElementBinding.h"
#include "nsHTMLSelectElement.h"
#include "nsIDOMHTMLOptGroupElement.h"
#include "nsIDOMHTMLFormElement.h"
@ -66,6 +67,8 @@ HTMLOptionElement::HTMLOptionElement(already_AddRefed<nsINodeInfo> aNodeInfo)
mIsSelected(false),
mIsInSetDefaultSelected(false)
{
SetIsDOMBinding();
// We start off enabled
AddStatesSilently(NS_EVENT_STATE_ENABLED);
}
@ -98,17 +101,17 @@ NS_IMETHODIMP
HTMLOptionElement::GetForm(nsIDOMHTMLFormElement** aForm)
{
NS_ENSURE_ARG_POINTER(aForm);
*aForm = nullptr;
nsHTMLSelectElement* selectControl = GetSelect();
if (selectControl) {
selectControl->GetForm(aForm);
}
*aForm = GetForm();
return NS_OK;
}
nsHTMLFormElement*
HTMLOptionElement::GetForm()
{
nsHTMLSelectElement* selectControl = GetSelect();
return selectControl ? selectControl->GetForm() : nullptr;
}
void
HTMLOptionElement::SetSelectedInternal(bool aValue, bool aNotify)
{
@ -458,5 +461,11 @@ HTMLOptionElement::CopyInnerTo(Element* aDest)
return NS_OK;
}
JSObject*
HTMLOptionElement::WrapNode(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
{
return HTMLOptionElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
} // namespace dom
} // namespace mozilla

View File

@ -10,6 +10,7 @@
#include "nsGenericHTMLElement.h"
#include "nsIDOMHTMLOptionElement.h"
#include "nsIJSNativeInitializer.h"
#include "nsHTMLFormElement.h"
class nsHTMLSelectElement;
@ -48,7 +49,7 @@ public:
// nsIJSNativeInitializer
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
JSObject *aObj, uint32_t argc, jsval *argv);
JSObject* aObj, uint32_t argc, jsval* argv);
virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
int32_t aModType) const;
@ -68,7 +69,7 @@ public:
// nsIContent
virtual nsEventStates IntrinsicState() const;
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const;
nsresult CopyInnerTo(mozilla::dom::Element* aDest);
@ -79,7 +80,60 @@ public:
virtual bool IsDisabled() const {
return HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
}
bool Disabled() const
{
return GetBoolAttr(nsGkAtoms::disabled);
}
void SetDisabled(bool aValue, ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::disabled, aValue, aRv);
}
nsHTMLFormElement* GetForm();
// The XPCOM GetLabel is OK for us
void SetLabel(const nsAString& aLabel, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
}
// The XPCOM DefaultSelected is OK for us
void SetDefaultSelected(bool aValue, ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::selected, aValue, aRv);
}
// The XPCOM Selected is OK for us
void SetSelected(bool aValue, ErrorResult& aRv)
{
aRv = SetSelected(aValue);
}
// The XPCOM GetValue is OK for us
void SetValue(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
}
// The XPCOM GetText is OK for us
void SetText(const nsAString& aValue, ErrorResult& aRv)
{
aRv = SetText(aValue);
}
int32_t GetIndex(ErrorResult& aRv)
{
int32_t id = 0;
aRv = GetIndex(&id);
return id;
}
protected:
virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap) MOZ_OVERRIDE;
/**
* Get the select content element that contains this option, this
* intentionally does not return nsresult, all we care about is if

View File

@ -735,7 +735,7 @@ nsHTMLOptionCollection::Add(const HTMLOptionOrOptGroupElement& aElement,
{
nsGenericHTMLElement& element =
aElement.IsHTMLOptionElement() ?
static_cast<nsGenericHTMLElement&>(*aElement.GetAsHTMLOptionElement()) :
static_cast<nsGenericHTMLElement&>(aElement.GetAsHTMLOptionElement()) :
static_cast<nsGenericHTMLElement&>(aElement.GetAsHTMLOptGroupElement());
if (aBefore.IsNull()) {

View File

@ -1177,7 +1177,6 @@ def addExternalHTMLElement(element):
headerFile=nativeElement + '.h')
addExternalHTMLElement('HTMLFormElement')
addExternalIface('HTMLOptionElement', nativeType='mozilla::dom::HTMLOptionElement')
addExternalHTMLElement('HTMLVideoElement')
addExternalIface('Attr')
addExternalIface('CanvasGradient', headerFile='nsIDOMCanvasRenderingContext2D.h')

View File

@ -0,0 +1,38 @@
/* -*- 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/specs/web-apps/current-work/#the-option-element
*
* © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
* Opera Software ASA. You are granted a license to use, reproduce
* and create derivative works of this document.
*/
/* TODO: Bug 842276
* [NamedConstructor=Option(),
* NamedConstructor=Option(DOMString text),
* NamedConstructor=Option(DOMString text, DOMString value),
* NamedConstructor=Option(DOMString text, DOMString value, boolean defaultSelected),
* NamedConstructor=Option(DOMString text, DOMString value, boolean defaultSelected, boolean selected)]
*/
interface HTMLOptionElement : HTMLElement {
[SetterThrows]
attribute boolean disabled;
readonly attribute HTMLFormElement? form;
[SetterThrows]
attribute DOMString label;
[SetterThrows]
attribute boolean defaultSelected;
[SetterThrows]
attribute boolean selected;
[SetterThrows]
attribute DOMString value;
[SetterThrows]
attribute DOMString text;
[GetterThrows]
readonly attribute long index;
};

View File

@ -90,6 +90,7 @@ webidl_files = \
HTMLModElement.webidl \
HTMLOListElement.webidl \
HTMLOptGroupElement.webidl \
HTMLOptionElement.webidl \
HTMLOptionsCollection.webidl \
HTMLOutputElement.webidl \
HTMLParagraphElement.webidl \