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-14 06:39:48 +00:00
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
#include "mozilla/dom/HTMLOptionElement.h"
|
2013-02-18 12:26:57 +00:00
|
|
|
#include "mozilla/dom/HTMLOptionElementBinding.h"
|
2013-04-04 07:03:33 +00:00
|
|
|
#include "mozilla/dom/HTMLSelectElement.h"
|
1999-03-02 03:26:29 +00:00
|
|
|
#include "nsIDOMHTMLOptGroupElement.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-02 00:56:01 +00:00
|
|
|
#include "nsStyleConsts.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIForm.h"
|
1999-04-08 23:47:49 +00:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMHTMLCollection.h"
|
2002-01-25 23:35:44 +00:00
|
|
|
#include "nsISelectControlFrame.h"
|
1998-09-02 00:56:01 +00:00
|
|
|
|
1999-01-30 01:02:28 +00:00
|
|
|
// Notify/query select frame for selected state
|
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMHTMLSelectElement.h"
|
2000-05-10 13:13:39 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
2000-02-12 16:24:19 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2014-04-03 04:18:36 +00:00
|
|
|
#include "mozilla/EventStates.h"
|
2006-07-19 04:36:36 +00:00
|
|
|
#include "nsContentCreatorFunctions.h"
|
2008-04-11 17:29:06 +00:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2013-04-04 12:01:08 +00:00
|
|
|
#include "nsTextNode.h"
|
1999-01-30 01:02:28 +00:00
|
|
|
|
2010-07-14 13:45:11 +00:00
|
|
|
/**
|
|
|
|
* Implementation of <option>
|
|
|
|
*/
|
|
|
|
|
2013-06-19 14:24:37 +00:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Option)
|
1998-09-02 00:56:01 +00:00
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
HTMLOptionElement::HTMLOptionElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2004-05-18 20:58:12 +00:00
|
|
|
: nsGenericHTMLElement(aNodeInfo),
|
2011-10-17 14:59:28 +00:00
|
|
|
mSelectedChanged(false),
|
|
|
|
mIsSelected(false),
|
|
|
|
mIsInSetDefaultSelected(false)
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2011-06-01 01:46:57 +00:00
|
|
|
// We start off enabled
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_ENABLED);
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::~HTMLOptionElement()
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLOptionElement, nsGenericHTMLElement,
|
|
|
|
nsIDOMHTMLOptionElement)
|
1999-05-04 20:53:26 +00:00
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLOptionElement)
|
2000-12-23 10:56:31 +00:00
|
|
|
|
1998-09-02 00:56:01 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
1998-09-02 00:56:01 +00:00
|
|
|
{
|
2013-02-19 12:20:40 +00:00
|
|
|
NS_IF_ADDREF(*aForm = GetForm());
|
2013-02-18 12:26:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-02-06 02:11:30 +00:00
|
|
|
|
2013-06-19 14:24:37 +00:00
|
|
|
mozilla::dom::HTMLFormElement*
|
2013-02-18 12:26:57 +00:00
|
|
|
HTMLOptionElement::GetForm()
|
|
|
|
{
|
2013-04-04 07:03:33 +00:00
|
|
|
HTMLSelectElement* selectControl = GetSelect();
|
2013-02-18 12:26:57 +00:00
|
|
|
return selectControl ? selectControl->GetForm() : nullptr;
|
1998-09-02 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
2010-07-14 06:39:48 +00:00
|
|
|
void
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::SetSelectedInternal(bool aValue, bool aNotify)
|
2001-11-02 07:40:01 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mSelectedChanged = true;
|
2002-03-07 03:34:29 +00:00
|
|
|
mIsSelected = aValue;
|
2001-11-05 06:15:14 +00:00
|
|
|
|
2011-06-01 01:46:57 +00:00
|
|
|
// When mIsInSetDefaultSelected is true, the state change will be handled by
|
2007-12-04 16:50:32 +00:00
|
|
|
// SetAttr/UnsetAttr.
|
2011-06-01 01:46:57 +00:00
|
|
|
if (!mIsInSetDefaultSelected) {
|
|
|
|
UpdateState(aNotify);
|
2004-01-21 04:28:57 +00:00
|
|
|
}
|
2001-11-02 07:40:01 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLOptionElement::GetSelected(bool* aValue)
|
1999-08-27 03:59:49 +00:00
|
|
|
{
|
2001-11-02 07:40:01 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aValue);
|
2011-06-28 10:45:51 +00:00
|
|
|
*aValue = Selected();
|
2002-03-07 03:34:29 +00:00
|
|
|
return NS_OK;
|
2001-11-02 07:40:01 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2001-11-02 07:40:01 +00:00
|
|
|
NS_IMETHODIMP
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::SetSelected(bool aValue)
|
2001-11-02 07:40:01 +00:00
|
|
|
{
|
|
|
|
// Note: The select content obj maintains all the PresState
|
|
|
|
// so defer to it to get the answer
|
2013-04-04 07:03:33 +00:00
|
|
|
HTMLSelectElement* selectInt = GetSelect();
|
2001-11-02 07:40:01 +00:00
|
|
|
if (selectInt) {
|
2013-08-14 06:57:04 +00:00
|
|
|
int32_t index = Index();
|
2013-09-28 19:04:20 +00:00
|
|
|
uint32_t mask = HTMLSelectElement::SET_DISABLED | HTMLSelectElement::NOTIFY;
|
|
|
|
if (aValue) {
|
|
|
|
mask |= HTMLSelectElement::IS_SELECTED;
|
|
|
|
}
|
|
|
|
|
2001-11-02 07:40:01 +00:00
|
|
|
// This should end up calling SetSelectedInternal
|
2013-09-28 19:04:20 +00:00
|
|
|
selectInt->SetOptionsSelectedByIndex(index, index, mask);
|
2000-09-05 13:37:16 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
SetSelectedInternal(aValue, true);
|
1999-08-27 03:59:49 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2001-11-02 07:40:01 +00:00
|
|
|
return NS_OK;
|
1999-08-27 03:59:49 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
NS_IMPL_BOOL_ATTR(HTMLOptionElement, DefaultSelected, selected)
|
2011-08-11 06:07:26 +00:00
|
|
|
// GetText returns a whitespace compressed .textContent value.
|
2013-02-18 12:24:58 +00:00
|
|
|
NS_IMPL_STRING_ATTR_WITH_FALLBACK(HTMLOptionElement, Label, label, GetText)
|
|
|
|
NS_IMPL_STRING_ATTR_WITH_FALLBACK(HTMLOptionElement, Value, value, GetText)
|
|
|
|
NS_IMPL_BOOL_ATTR(HTMLOptionElement, Disabled, disabled)
|
1999-01-30 01:02:28 +00:00
|
|
|
|
2012-02-24 20:30:54 +00:00
|
|
|
NS_IMETHODIMP
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::GetIndex(int32_t* aIndex)
|
1999-04-08 23:47:49 +00:00
|
|
|
{
|
2013-08-14 06:57:04 +00:00
|
|
|
*aIndex = Index();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
HTMLOptionElement::Index()
|
|
|
|
{
|
|
|
|
static int32_t defaultIndex = 0;
|
1999-04-08 23:47:49 +00:00
|
|
|
|
2012-02-24 20:30:54 +00:00
|
|
|
// Only select elements can contain a list of options.
|
2013-04-04 07:03:33 +00:00
|
|
|
HTMLSelectElement* selectElement = GetSelect();
|
2012-02-24 20:30:54 +00:00
|
|
|
if (!selectElement) {
|
2013-08-14 06:57:04 +00:00
|
|
|
return defaultIndex;
|
2012-02-24 20:30:54 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
HTMLOptionsCollection* options = selectElement->GetOptions();
|
2012-02-24 20:30:54 +00:00
|
|
|
if (!options) {
|
2013-08-14 06:57:04 +00:00
|
|
|
return defaultIndex;
|
1999-04-08 23:47:49 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2013-08-14 06:57:04 +00:00
|
|
|
int32_t index = defaultIndex;
|
2016-03-28 17:28:15 +00:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(options->GetOptionIndex(this, 0, true, &index));
|
2013-08-14 06:57:04 +00:00
|
|
|
return index;
|
1999-04-08 23:47:49 +00:00
|
|
|
}
|
|
|
|
|
2011-06-28 10:45:51 +00:00
|
|
|
bool
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::Selected() const
|
2011-06-28 10:45:51 +00:00
|
|
|
{
|
|
|
|
// If we haven't been explictly selected or deselected, use our default value
|
|
|
|
if (!mSelectedChanged) {
|
|
|
|
return DefaultSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mIsSelected;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::DefaultSelected() const
|
2011-06-28 10:45:51 +00:00
|
|
|
{
|
|
|
|
return HasAttr(kNameSpaceID_None, nsGkAtoms::selected);
|
|
|
|
}
|
|
|
|
|
2004-10-24 17:10:32 +00:00
|
|
|
nsChangeHint
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) const
|
1999-07-07 01:24:40 +00:00
|
|
|
{
|
2004-10-24 17:10:32 +00:00
|
|
|
nsChangeHint retval =
|
|
|
|
nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType);
|
1999-07-07 01:24:40 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::label ||
|
|
|
|
aAttribute == nsGkAtoms::text) {
|
2016-05-23 03:26:03 +00:00
|
|
|
retval |= NS_STYLE_HINT_REFLOW;
|
2003-07-11 21:16:12 +00:00
|
|
|
}
|
2004-10-24 17:10:32 +00:00
|
|
|
return retval;
|
1999-07-07 01:24:40 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 16:50:32 +00:00
|
|
|
nsresult
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
2015-08-01 05:14:06 +00:00
|
|
|
nsAttrValueOrString* aValue,
|
2013-02-18 12:24:58 +00:00
|
|
|
bool aNotify)
|
2007-12-04 16:50:32 +00:00
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::BeforeSetAttr(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aNamespaceID != kNameSpaceID_None || aName != nsGkAtoms::selected ||
|
|
|
|
mSelectedChanged) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-02-18 12:24:58 +00:00
|
|
|
|
2013-12-04 13:02:00 +00:00
|
|
|
bool defaultSelected = aValue;
|
|
|
|
// First make sure we actually set our mIsSelected state to reflect our new
|
|
|
|
// defaultSelected state. If that turns out to be wrong,
|
|
|
|
// SetOptionsSelectedByIndex will fix it up. But otherwise we can end up in a
|
|
|
|
// situation where mIsSelected is still false, but mSelectedChanged becomes
|
|
|
|
// true (later in this method, when we compare mIsSelected to
|
|
|
|
// defaultSelected), and then we start returning false for Selected() even
|
|
|
|
// though we're actually selected.
|
|
|
|
mIsSelected = defaultSelected;
|
|
|
|
|
2007-12-04 16:50:32 +00:00
|
|
|
// We just changed out selected state (since we look at the "selected"
|
2011-04-12 12:32:00 +00:00
|
|
|
// attribute when mSelectedChanged is false). Let's tell our select about
|
2007-12-04 16:50:32 +00:00
|
|
|
// it.
|
2013-04-04 07:03:33 +00:00
|
|
|
HTMLSelectElement* selectInt = GetSelect();
|
2007-12-04 16:50:32 +00:00
|
|
|
if (!selectInt) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mSelectedChanged, "Shouldn't be here");
|
2013-02-18 12:24:58 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool inSetDefaultSelected = mIsInSetDefaultSelected;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsInSetDefaultSelected = true;
|
2013-02-18 12:24:58 +00:00
|
|
|
|
2013-08-14 06:57:04 +00:00
|
|
|
int32_t index = Index();
|
2013-09-28 19:04:20 +00:00
|
|
|
uint32_t mask = HTMLSelectElement::SET_DISABLED;
|
2013-11-06 18:02:58 +00:00
|
|
|
if (defaultSelected) {
|
2013-09-28 19:04:20 +00:00
|
|
|
mask |= HTMLSelectElement::IS_SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aNotify) {
|
|
|
|
mask |= HTMLSelectElement::NOTIFY;
|
|
|
|
}
|
|
|
|
|
2013-12-04 13:02:00 +00:00
|
|
|
// This can end up calling SetSelectedInternal if our selected state needs to
|
|
|
|
// change, which we will allow to take effect so that parts of
|
|
|
|
// SetOptionsSelectedByIndex that might depend on it working don't get
|
|
|
|
// confused.
|
2013-09-28 19:04:20 +00:00
|
|
|
selectInt->SetOptionsSelectedByIndex(index, index, mask);
|
2007-12-04 16:50:32 +00:00
|
|
|
|
|
|
|
// Now reset our members; when we finish the attr set we'll end up with the
|
|
|
|
// rigt selected state.
|
|
|
|
mIsInSetDefaultSelected = inSetDefaultSelected;
|
2013-12-04 13:02:00 +00:00
|
|
|
// mIsSelected might have been changed by SetOptionsSelectedByIndex. Possibly
|
|
|
|
// more than once; make sure our mSelectedChanged state is set correctly.
|
2013-11-06 18:02:58 +00:00
|
|
|
mSelectedChanged = mIsSelected != defaultSelected;
|
2007-12-04 16:50:32 +00:00
|
|
|
|
2013-07-24 07:37:14 +00:00
|
|
|
return NS_OK;
|
2007-12-04 16:50:32 +00:00
|
|
|
}
|
|
|
|
|
2014-05-06 17:19:00 +00:00
|
|
|
nsresult
|
|
|
|
HTMLOptionElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
aName == nsGkAtoms::value && Selected()) {
|
|
|
|
// Since this option is selected, changing value
|
|
|
|
// may have changed missing validity state of the
|
|
|
|
// Select element
|
|
|
|
HTMLSelectElement* select = GetSelect();
|
|
|
|
if (select) {
|
|
|
|
select->UpdateValueMissingValidityState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
|
|
|
|
aValue, aNotify);
|
|
|
|
}
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
NS_IMETHODIMP
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::GetText(nsAString& aText)
|
1998-09-23 17:16:51 +00:00
|
|
|
{
|
2002-09-03 23:23:00 +00:00
|
|
|
nsAutoString text;
|
2012-10-21 07:38:40 +00:00
|
|
|
|
|
|
|
nsIContent* child = nsINode::GetFirstChild();
|
|
|
|
while (child) {
|
|
|
|
if (child->NodeType() == nsIDOMNode::TEXT_NODE ||
|
|
|
|
child->NodeType() == nsIDOMNode::CDATA_SECTION_NODE) {
|
|
|
|
child->AppendTextTo(text);
|
|
|
|
}
|
2015-03-03 11:08:59 +00:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::script) ||
|
|
|
|
child->IsSVGElement(nsGkAtoms::script)) {
|
2012-10-21 07:38:40 +00:00
|
|
|
child = child->GetNextNonChildNode(this);
|
|
|
|
} else {
|
|
|
|
child = child->GetNextNode(this);
|
|
|
|
}
|
|
|
|
}
|
2000-02-12 16:24:19 +00:00
|
|
|
|
2002-09-26 08:21:26 +00:00
|
|
|
// XXX No CompressWhitespace for nsAString. Sad.
|
2011-10-17 14:59:28 +00:00
|
|
|
text.CompressWhitespace(true, true);
|
2002-09-26 08:21:26 +00:00
|
|
|
aText = text;
|
2002-09-03 23:23:00 +00:00
|
|
|
|
2000-02-12 16:24:19 +00:00
|
|
|
return NS_OK;
|
2000-01-15 01:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::SetText(const nsAString& aText)
|
2000-01-15 01:42:56 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return nsContentUtils::SetNodeTextContent(this, aText, true);
|
2002-03-31 09:48:38 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 09:46:43 +00:00
|
|
|
nsresult
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2012-06-01 09:46:43 +00:00
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Our new parent might change :disabled/:enabled state.
|
|
|
|
UpdateState(false);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2012-06-01 09:46:43 +00:00
|
|
|
{
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
|
|
|
|
// Our previous parent could have been involved in :disabled/:enabled state.
|
|
|
|
UpdateState(false);
|
|
|
|
}
|
|
|
|
|
2014-04-03 04:18:36 +00:00
|
|
|
EventStates
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::IntrinsicState() const
|
2005-06-03 02:02:45 +00:00
|
|
|
{
|
2014-04-03 04:18:36 +00:00
|
|
|
EventStates state = nsGenericHTMLElement::IntrinsicState();
|
2011-06-28 10:45:51 +00:00
|
|
|
if (Selected()) {
|
2005-06-03 02:02:45 +00:00
|
|
|
state |= NS_EVENT_STATE_CHECKED;
|
|
|
|
}
|
2011-06-28 10:45:51 +00:00
|
|
|
if (DefaultSelected()) {
|
2006-08-16 03:20:19 +00:00
|
|
|
state |= NS_EVENT_STATE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2012-06-01 09:46:43 +00:00
|
|
|
// An <option> is disabled if it has @disabled set or if it's <optgroup> has
|
|
|
|
// @disabled set.
|
2010-09-18 21:33:16 +00:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
|
2005-09-28 08:32:40 +00:00
|
|
|
state |= NS_EVENT_STATE_DISABLED;
|
|
|
|
state &= ~NS_EVENT_STATE_ENABLED;
|
|
|
|
} else {
|
2012-06-01 09:46:43 +00:00
|
|
|
nsIContent* parent = GetParent();
|
2015-03-03 11:08:59 +00:00
|
|
|
if (parent && parent->IsHTMLElement(nsGkAtoms::optgroup) &&
|
2012-06-01 09:46:43 +00:00
|
|
|
parent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
|
|
|
|
state |= NS_EVENT_STATE_DISABLED;
|
|
|
|
state &= ~NS_EVENT_STATE_ENABLED;
|
|
|
|
} else {
|
|
|
|
state &= ~NS_EVENT_STATE_DISABLED;
|
|
|
|
state |= NS_EVENT_STATE_ENABLED;
|
|
|
|
}
|
2005-09-28 08:32:40 +00:00
|
|
|
}
|
|
|
|
|
2005-06-03 02:02:45 +00:00
|
|
|
return state;
|
|
|
|
}
|
2002-03-31 09:48:38 +00:00
|
|
|
|
1999-04-08 23:47:49 +00:00
|
|
|
// Get the select content element that contains this option
|
2013-04-04 07:03:33 +00:00
|
|
|
HTMLSelectElement*
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::GetSelect()
|
1999-01-30 01:02:28 +00:00
|
|
|
{
|
2016-03-03 08:03:44 +00:00
|
|
|
nsIContent* parent = GetParent();
|
2016-03-03 08:47:36 +00:00
|
|
|
if (!parent) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLSelectElement* select = HTMLSelectElement::FromContent(parent);
|
2016-03-03 08:03:44 +00:00
|
|
|
if (select) {
|
|
|
|
return select;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parent->IsHTMLElement(nsGkAtoms::optgroup)) {
|
|
|
|
return nullptr;
|
1999-05-04 20:53:26 +00:00
|
|
|
}
|
2013-02-18 12:24:58 +00:00
|
|
|
|
2016-03-03 08:03:44 +00:00
|
|
|
return HTMLSelectElement::FromContentOrNull(parent->GetParent());
|
1999-05-04 20:53:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 10:53:13 +00:00
|
|
|
already_AddRefed<HTMLOptionElement>
|
|
|
|
HTMLOptionElement::Option(const GlobalObject& aGlobal,
|
|
|
|
const Optional<nsAString>& aText,
|
|
|
|
const Optional<nsAString>& aValue,
|
|
|
|
const Optional<bool>& aDefaultSelected,
|
|
|
|
const Optional<bool>& aSelected, ErrorResult& aError)
|
1999-05-04 20:53:26 +00:00
|
|
|
{
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobal.GetAsSupports());
|
2013-01-22 10:53:13 +00:00
|
|
|
nsIDocument* doc;
|
|
|
|
if (!win || !(doc = win->GetExtantDoc())) {
|
|
|
|
aError.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
1999-05-04 20:53:26 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo> nodeInfo =
|
2013-01-22 10:53:13 +00:00
|
|
|
doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::option, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<HTMLOptionElement> option = new HTMLOptionElement(nodeInfo);
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2013-01-22 10:53:13 +00:00
|
|
|
if (aText.WasPassed()) {
|
2007-11-28 00:52:37 +00:00
|
|
|
// Create a new text node and append it to the option
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsTextNode> textContent =
|
2013-04-04 12:01:08 +00:00
|
|
|
new nsTextNode(option->NodeInfo()->NodeInfoManager());
|
2010-12-03 08:24:17 +00:00
|
|
|
|
2013-01-22 10:53:13 +00:00
|
|
|
textContent->SetText(aText.Value(), false);
|
2013-02-18 12:24:58 +00:00
|
|
|
|
2013-01-22 10:53:13 +00:00
|
|
|
aError = option->AppendChildTo(textContent, false);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
1999-03-02 03:26:29 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 10:53:13 +00:00
|
|
|
if (aValue.WasPassed()) {
|
|
|
|
// Set the value attribute for this element. We're calling SetAttr
|
|
|
|
// directly because we want to pass aNotify == false.
|
|
|
|
aError = option->SetAttr(kNameSpaceID_None, nsGkAtoms::value,
|
|
|
|
aValue.Value(), false);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
2010-12-03 08:24:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 10:53:13 +00:00
|
|
|
if (aDefaultSelected.WasPassed()) {
|
|
|
|
if (aDefaultSelected.Value()) {
|
|
|
|
// We're calling SetAttr directly because we want to pass
|
|
|
|
// aNotify == false.
|
|
|
|
aError = option->SetAttr(kNameSpaceID_None, nsGkAtoms::selected,
|
|
|
|
EmptyString(), false);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
1999-05-04 20:53:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 10:53:13 +00:00
|
|
|
if (aSelected.WasPassed()) {
|
|
|
|
option->SetSelected(aSelected.Value(), aError);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2001-11-02 07:40:01 +00:00
|
|
|
}
|
1999-05-04 20:53:26 +00:00
|
|
|
}
|
|
|
|
}
|
1999-01-30 01:02:28 +00:00
|
|
|
}
|
1999-05-04 20:53:26 +00:00
|
|
|
|
2013-01-22 10:53:13 +00:00
|
|
|
return option.forget();
|
1999-01-30 01:02:28 +00:00
|
|
|
}
|
2009-12-11 04:02:13 +00:00
|
|
|
|
|
|
|
nsresult
|
2013-02-18 12:24:58 +00:00
|
|
|
HTMLOptionElement::CopyInnerTo(Element* aDest)
|
2009-12-11 04:02:13 +00:00
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-18 10:53:36 +00:00
|
|
|
if (aDest->OwnerDoc()->IsStaticDocument()) {
|
2013-02-18 12:24:58 +00:00
|
|
|
static_cast<HTMLOptionElement*>(aDest)->SetSelected(Selected());
|
2009-12-11 04:02:13 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-18 12:26:57 +00:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
HTMLOptionElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-18 12:26:57 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return HTMLOptionElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-18 12:26:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 12:24:58 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|