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"
|
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;
|
|
|
|
|
2017-11-09 01:43:09 +00:00
|
|
|
class HTMLOptionElement final : public nsGenericHTMLElement {
|
2010-07-15 18:07:21 +00:00
|
|
|
public:
|
2018-09-21 20:45:49 +00:00
|
|
|
explicit HTMLOptionElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2013-01-22 10:53:13 +00:00
|
|
|
static already_AddRefed<HTMLOptionElement> Option(
|
2013-08-23 05:17:08 +00:00
|
|
|
const GlobalObject& aGlobal, const nsAString& aText,
|
2013-01-22 10:53:13 +00:00
|
|
|
const Optional<nsAString>& aValue, bool aDefaultSelected, bool aSelected,
|
2017-05-18 09:56:27 +00:00
|
|
|
ErrorResult& aError);
|
2013-01-22 10:53:13 +00:00
|
|
|
|
2018-03-21 21:39:04 +00:00
|
|
|
NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLOptionElement, option)
|
2010-05-09 18:32:57 +00:00
|
|
|
|
2010-07-15 18:07:21 +00:00
|
|
|
// nsISupports
|
2018-02-12 20:44:40 +00:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLOptionElement, nsGenericHTMLElement)
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2012-11-14 22:10:08 +00:00
|
|
|
using mozilla::dom::Element::GetText;
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2017-11-09 01:43:09 +00:00
|
|
|
bool Selected() const { return mIsSelected; }
|
|
|
|
void SetSelected(bool aValue);
|
|
|
|
|
2017-05-18 06:44:00 +00:00
|
|
|
void SetSelectedChanged(bool aValue) { mSelectedChanged = aValue; }
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
virtual nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute,
|
2015-03-21 16:28:04 +00:00
|
|
|
int32_t aModType) const override;
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-03-16 18:50:41 +00:00
|
|
|
const nsAttrValueOrString* aValue,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aNotify) override;
|
2017-10-02 22:05:19 +00:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-05-18 21:09:01 +00:00
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
2017-10-09 21:33:38 +00:00
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
2017-05-18 21:09:01 +00:00
|
|
|
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
|
|
|
|
Bug 1375599 - Change IsDisabled() to look at NS_EVENT_STATE_DISABLED instead of the "disabled" attribute. r=bz
In order to speed up IsDisabled(), instead of querying for the @disabled
attribute, we're now using the NS_EVENT_STATE_DISABLED flag to know whether an
element is disabled.
It is safe to use the NS_EVENT_STATE_DISABLED flag for the following reasons:
- For form elements, nsGenericHTMLFormElement::IsDisabled() is only called on
form elements that can be disabled; form elements that can't be disabled
overrides IsDisabled() to return false directly.
And, before this patch, NS_EVENT_STATE_DISABLED flag is set by
nsGenericHTMLFormElement::IntrinsicState() if and only if IsDisabled() in all
cases when CanBeDisabled() is true, and when CanBeDisabled() is false then
IsDisabled() is always false and the flag is not set.
- For non form elements, optgroup and option have the flag matching
IsDisabled(). Note that option's IsDisabled() should also refer to optgroup's
(if it exists) disabled state, which was not done before this patch.
For this to work correctly, we need to set NS_EVENT_STATE_DISABLED earlier,
that is, in AfterSetAttr(), before any consumer of IsDisabled().
We also need to update the flag whenever the element's parent (e.g. fieldset or
optgroup) disabled state changes and when moving into/out of a parent
container.
Note that NS_EVENT_STATE_DISABLED/ENABLED is now part of the
EXTERNALLY_MANAGED_STATES.
MozReview-Commit-ID: KSceikeqvvU
2017-07-20 06:15:00 +00:00
|
|
|
/**
|
|
|
|
* This callback is called by an optgroup on all its option elements whenever
|
|
|
|
* its disabled state is changed so that option elements can know their
|
|
|
|
* disabled state might have changed.
|
|
|
|
*/
|
|
|
|
void OptGroupDisabledChanged(bool aNotify);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check our disabled content attribute and optgroup's (if it exists) disabled
|
|
|
|
* state to decide whether our disabled flag should be toggled.
|
|
|
|
*/
|
|
|
|
void UpdateDisabledState(bool aNotify);
|
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 04:27:04 +00:00
|
|
|
virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
|
2019-05-28 22:47:08 +00:00
|
|
|
virtual void UnbindFromTree(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
|
|
|
|
2018-08-08 23:58:44 +00:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
2010-07-15 18:07:21 +00:00
|
|
|
|
2018-08-08 23:58:44 +00:00
|
|
|
nsresult CopyInnerTo(mozilla::dom::Element* aDest);
|
2010-07-15 18:07:21 +00:00
|
|
|
|
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
|
|
|
|
2017-11-09 01:43:09 +00:00
|
|
|
void GetLabel(DOMString& aLabel) {
|
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::label, aLabel)) {
|
|
|
|
GetText(aLabel);
|
|
|
|
}
|
|
|
|
}
|
2013-02-18 12:26:57 +00:00
|
|
|
void SetLabel(const nsAString& aLabel, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:43:09 +00:00
|
|
|
bool DefaultSelected() const {
|
|
|
|
return HasAttr(kNameSpaceID_None, nsGkAtoms::selected);
|
|
|
|
}
|
2013-02-18 12:26:57 +00:00
|
|
|
void SetDefaultSelected(bool aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::selected, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:43:09 +00:00
|
|
|
void GetValue(nsAString& aValue) {
|
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::value, aValue)) {
|
|
|
|
GetText(aValue);
|
|
|
|
}
|
2013-02-18 12:26:57 +00:00
|
|
|
}
|
|
|
|
void SetValue(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:43:09 +00:00
|
|
|
void GetText(nsAString& aText);
|
|
|
|
void SetText(const nsAString& aText, ErrorResult& aRv);
|
2013-02-18 12:26:57 +00:00
|
|
|
|
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__
|