2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
#ifndef mozilla_dom_HTMLOptionElement_h__
|
|
|
|
#define mozilla_dom_HTMLOptionElement_h__
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-07-15 18:07:21 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsIDOMHTMLOptionElement.h"
|
2013-06-19 14:24:37 +00:00
|
|
|
#include "mozilla/dom/HTMLFormElement.h"
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-04-04 07:03:33 +00:00
|
|
|
class HTMLSelectElement;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class HTMLOptionElement final : public nsGenericHTMLElement,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsIDOMHTMLOptionElement
|
2010-07-15 18:07:21 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit HTMLOptionElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2013-01-22 10:53:13 +00:00
|
|
|
static already_AddRefed<HTMLOptionElement>
|
2013-08-23 05:17:08 +00:00
|
|
|
Option(const GlobalObject& aGlobal,
|
|
|
|
const Optional<nsAString>& aText,
|
2013-01-22 10:53:13 +00:00
|
|
|
const Optional<nsAString>& aValue,
|
|
|
|
const Optional<bool>& aDefaultSelected,
|
|
|
|
const Optional<bool>& aSelected, ErrorResult& aError);
|
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLOptionElement, option)
|
2010-05-09 18:32:57 +00:00
|
|
|
|
2010-07-15 18:07:21 +00:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// nsIDOMHTMLOptionElement
|
2012-11-14 22:10:08 +00:00
|
|
|
using mozilla::dom::Element::SetText;
|
|
|
|
using mozilla::dom::Element::GetText;
|
2010-07-15 18:07:21 +00:00
|
|
|
NS_DECL_NSIDOMHTMLOPTIONELEMENT
|
|
|
|
|
2011-06-28 10:45:51 +00:00
|
|
|
bool Selected() const;
|
|
|
|
bool DefaultSelected() const;
|
|
|
|
|
2010-07-15 18:07:21 +00:00
|
|
|
virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
|
2015-03-21 16:28:04 +00:00
|
|
|
int32_t aModType) const override;
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
2015-08-01 05:14:06 +00:00
|
|
|
nsAttrValueOrString* aValue,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aNotify) override;
|
2014-05-06 17:19:00 +00:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2015-03-21 16:28:04 +00:00
|
|
|
const nsAttrValue* aValue, bool aNotify) override;
|
2012-02-14 02:00:56 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetSelectedInternal(bool aValue, bool aNotify);
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2012-06-01 09:46:43 +00:00
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aCompileEventHandlers) override;
|
2012-06-01 09:46:43 +00:00
|
|
|
virtual void UnbindFromTree(bool aDeep = true,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aNullParent = true) override;
|
2012-06-01 09:46:43 +00:00
|
|
|
|
2010-07-15 18:07:21 +00:00
|
|
|
// nsIContent
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual EventStates IntrinsicState() const override;
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const override;
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2012-11-14 22:10:08 +00:00
|
|
|
nsresult CopyInnerTo(mozilla::dom::Element* aDest);
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool IsDisabled() const override {
|
2012-03-10 10:57:19 +00:00
|
|
|
return HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
|
|
|
|
}
|
2013-02-18 12:26:57 +00:00
|
|
|
|
|
|
|
bool Disabled() const
|
|
|
|
{
|
|
|
|
return GetBoolAttr(nsGkAtoms::disabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDisabled(bool aValue, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::disabled, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
2013-06-19 14:24:37 +00:00
|
|
|
HTMLFormElement* GetForm();
|
2013-02-18 12:26:57 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2013-08-14 06:57:04 +00:00
|
|
|
int32_t Index();
|
2013-02-18 12:26:57 +00:00
|
|
|
|
2010-07-15 18:07:21 +00:00
|
|
|
protected:
|
2014-07-08 21:23:16 +00:00
|
|
|
virtual ~HTMLOptionElement();
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-02-18 12:26:57 +00:00
|
|
|
|
2010-07-15 18:07:21 +00:00
|
|
|
/**
|
|
|
|
* Get the select content element that contains this option, this
|
|
|
|
* intentionally does not return nsresult, all we care about is if
|
|
|
|
* there's a select associated with this option or not.
|
|
|
|
*/
|
2013-04-04 07:03:33 +00:00
|
|
|
HTMLSelectElement* GetSelect();
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mSelectedChanged;
|
|
|
|
bool mIsSelected;
|
2010-07-15 18:07:21 +00:00
|
|
|
|
|
|
|
// True only while we're under the SetOptionsSelectedByIndex call when our
|
|
|
|
// "selected" attribute is changing and mSelectedChanged is false.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mIsInSetDefaultSelected;
|
2010-07-15 18:07:21 +00:00
|
|
|
};
|
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_HTMLOptionElement_h__
|