2015-05-03 22:32:37 +03: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 15:12:37 +04: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 10:39:48 +04:00
|
|
|
|
2013-02-18 16:24:58 +04:00
|
|
|
#include "mozilla/dom/HTMLOptionElement.h"
|
2013-02-18 16:26:57 +04:00
|
|
|
#include "mozilla/dom/HTMLOptionElementBinding.h"
|
2013-04-04 11:03:33 +04:00
|
|
|
#include "mozilla/dom/HTMLSelectElement.h"
|
1999-03-02 06:26:29 +03:00
|
|
|
#include "nsIDOMHTMLOptGroupElement.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-02 04:56:01 +04:00
|
|
|
#include "nsStyleConsts.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIForm.h"
|
1999-04-09 03:47:49 +04:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMHTMLCollection.h"
|
2002-01-26 02:35:44 +03:00
|
|
|
#include "nsISelectControlFrame.h"
|
1998-09-02 04:56:01 +04:00
|
|
|
|
1999-01-30 04:02:28 +03:00
|
|
|
// Notify/query select frame for selected state
|
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMHTMLSelectElement.h"
|
2000-05-10 17:13:39 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2000-02-12 19:24:19 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2006-07-19 08:36:36 +04:00
|
|
|
#include "nsContentCreatorFunctions.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2013-04-04 16:01:08 +04:00
|
|
|
#include "nsTextNode.h"
|
1999-01-30 04:02:28 +03:00
|
|
|
|
2010-07-14 17:45:11 +04:00
|
|
|
/**
|
|
|
|
* Implementation of <option>
|
|
|
|
*/
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Option)
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2013-02-18 16:24:58 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLOptionElement::HTMLOptionElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2004-05-19 00:58:12 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo),
|
2011-10-17 18:59:28 +04:00
|
|
|
mSelectedChanged(false),
|
|
|
|
mIsSelected(false),
|
|
|
|
mIsInSetDefaultSelected(false)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2011-06-01 05:46:57 +04:00
|
|
|
// We start off enabled
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_ENABLED);
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::~HTMLOptionElement()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLOptionElement, nsGenericHTMLElement,
|
|
|
|
nsIDOMHTMLOptionElement)
|
1999-05-05 00:53:26 +04:00
|
|
|
|
2013-02-18 16:24:58 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLOptionElement)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1998-09-02 04:56:01 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2013-02-19 16:20:40 +04:00
|
|
|
NS_IF_ADDREF(*aForm = GetForm());
|
2013-02-18 16:26:57 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-02-06 05:11:30 +03:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
mozilla::dom::HTMLFormElement*
|
2013-02-18 16:26:57 +04:00
|
|
|
HTMLOptionElement::GetForm()
|
|
|
|
{
|
2013-04-04 11:03:33 +04:00
|
|
|
HTMLSelectElement* selectControl = GetSelect();
|
2013-02-18 16:26:57 +04:00
|
|
|
return selectControl ? selectControl->GetForm() : nullptr;
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2010-07-14 10:39:48 +04:00
|
|
|
void
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::SetSelectedInternal(bool aValue, bool aNotify)
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mSelectedChanged = true;
|
2002-03-07 06:34:29 +03:00
|
|
|
mIsSelected = aValue;
|
2001-11-05 09:15:14 +03:00
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
// When mIsInSetDefaultSelected is true, the state change will be handled by
|
2007-12-04 19:50:32 +03:00
|
|
|
// SetAttr/UnsetAttr.
|
2011-06-01 05:46:57 +04:00
|
|
|
if (!mIsInSetDefaultSelected) {
|
|
|
|
UpdateState(aNotify);
|
2004-01-21 07:28:57 +03:00
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-02-18 16:24:58 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLOptionElement::GetSelected(bool* aValue)
|
1999-08-27 07:59:49 +04:00
|
|
|
{
|
2001-11-02 10:40:01 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aValue);
|
2011-06-28 14:45:51 +04:00
|
|
|
*aValue = Selected();
|
2002-03-07 06:34:29 +03:00
|
|
|
return NS_OK;
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
NS_IMETHODIMP
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::SetSelected(bool aValue)
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
|
|
|
// Note: The select content obj maintains all the PresState
|
|
|
|
// so defer to it to get the answer
|
2013-04-04 11:03:33 +04:00
|
|
|
HTMLSelectElement* selectInt = GetSelect();
|
2001-11-02 10:40:01 +03:00
|
|
|
if (selectInt) {
|
2013-08-14 10:57:04 +04:00
|
|
|
int32_t index = Index();
|
2013-09-28 23:04:20 +04:00
|
|
|
uint32_t mask = HTMLSelectElement::SET_DISABLED | HTMLSelectElement::NOTIFY;
|
|
|
|
if (aValue) {
|
|
|
|
mask |= HTMLSelectElement::IS_SELECTED;
|
|
|
|
}
|
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
// This should end up calling SetSelectedInternal
|
2013-09-28 23:04:20 +04:00
|
|
|
selectInt->SetOptionsSelectedByIndex(index, index, mask);
|
2000-09-05 17:37:16 +04:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetSelectedInternal(aValue, true);
|
1999-08-27 07:59:49 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
return NS_OK;
|
1999-08-27 07:59:49 +04:00
|
|
|
}
|
|
|
|
|
2013-02-18 16:24:58 +04:00
|
|
|
NS_IMPL_BOOL_ATTR(HTMLOptionElement, DefaultSelected, selected)
|
2011-08-11 10:07:26 +04:00
|
|
|
// GetText returns a whitespace compressed .textContent value.
|
2013-02-18 16:24:58 +04: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 04:02:28 +03:00
|
|
|
|
2012-02-25 00:30:54 +04:00
|
|
|
NS_IMETHODIMP
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::GetIndex(int32_t* aIndex)
|
1999-04-09 03:47:49 +04:00
|
|
|
{
|
2013-08-14 10:57:04 +04:00
|
|
|
*aIndex = Index();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
HTMLOptionElement::Index()
|
|
|
|
{
|
|
|
|
static int32_t defaultIndex = 0;
|
1999-04-09 03:47:49 +04:00
|
|
|
|
2012-02-25 00:30:54 +04:00
|
|
|
// Only select elements can contain a list of options.
|
2013-04-04 11:03:33 +04:00
|
|
|
HTMLSelectElement* selectElement = GetSelect();
|
2012-02-25 00:30:54 +04:00
|
|
|
if (!selectElement) {
|
2013-08-14 10:57:04 +04:00
|
|
|
return defaultIndex;
|
2012-02-25 00:30:54 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
HTMLOptionsCollection* options = selectElement->GetOptions();
|
2012-02-25 00:30:54 +04:00
|
|
|
if (!options) {
|
2013-08-14 10:57:04 +04:00
|
|
|
return defaultIndex;
|
1999-04-09 03:47:49 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-08-14 10:57:04 +04:00
|
|
|
int32_t index = defaultIndex;
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(options->GetOptionIndex(this, 0, true, &index));
|
2013-08-14 10:57:04 +04:00
|
|
|
return index;
|
1999-04-09 03:47:49 +04:00
|
|
|
}
|
|
|
|
|
2011-06-28 14:45:51 +04:00
|
|
|
bool
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::Selected() const
|
2011-06-28 14:45:51 +04:00
|
|
|
{
|
|
|
|
// If we haven't been explictly selected or deselected, use our default value
|
|
|
|
if (!mSelectedChanged) {
|
|
|
|
return DefaultSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mIsSelected;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::DefaultSelected() const
|
2011-06-28 14:45:51 +04:00
|
|
|
{
|
|
|
|
return HasAttr(kNameSpaceID_None, nsGkAtoms::selected);
|
|
|
|
}
|
|
|
|
|
2004-10-24 21:10:32 +04:00
|
|
|
nsChangeHint
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) const
|
1999-07-07 05:24:40 +04:00
|
|
|
{
|
2004-10-24 21:10:32 +04:00
|
|
|
nsChangeHint retval =
|
|
|
|
nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType);
|
1999-07-07 05:24:40 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::label ||
|
|
|
|
aAttribute == nsGkAtoms::text) {
|
2016-05-23 06:26:03 +03:00
|
|
|
retval |= NS_STYLE_HINT_REFLOW;
|
2003-07-12 01:16:12 +04:00
|
|
|
}
|
2004-10-24 21:10:32 +04:00
|
|
|
return retval;
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
|
|
|
|
2007-12-04 19:50:32 +03:00
|
|
|
nsresult
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
2015-08-01 08:14:06 +03:00
|
|
|
nsAttrValueOrString* aValue,
|
2013-02-18 16:24:58 +04:00
|
|
|
bool aNotify)
|
2007-12-04 19:50:32 +03: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 16:24:58 +04:00
|
|
|
|
2013-12-04 17:02:00 +04: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 19:50:32 +03:00
|
|
|
// We just changed out selected state (since we look at the "selected"
|
2011-04-12 16:32:00 +04:00
|
|
|
// attribute when mSelectedChanged is false). Let's tell our select about
|
2007-12-04 19:50:32 +03:00
|
|
|
// it.
|
2013-04-04 11:03:33 +04:00
|
|
|
HTMLSelectElement* selectInt = GetSelect();
|
2007-12-04 19:50:32 +03:00
|
|
|
if (!selectInt) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mSelectedChanged, "Shouldn't be here");
|
2013-02-18 16:24:58 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool inSetDefaultSelected = mIsInSetDefaultSelected;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsInSetDefaultSelected = true;
|
2013-02-18 16:24:58 +04:00
|
|
|
|
2013-08-14 10:57:04 +04:00
|
|
|
int32_t index = Index();
|
2013-09-28 23:04:20 +04:00
|
|
|
uint32_t mask = HTMLSelectElement::SET_DISABLED;
|
2013-11-06 22:02:58 +04:00
|
|
|
if (defaultSelected) {
|
2013-09-28 23:04:20 +04:00
|
|
|
mask |= HTMLSelectElement::IS_SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aNotify) {
|
|
|
|
mask |= HTMLSelectElement::NOTIFY;
|
|
|
|
}
|
|
|
|
|
2013-12-04 17:02:00 +04: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 23:04:20 +04:00
|
|
|
selectInt->SetOptionsSelectedByIndex(index, index, mask);
|
2007-12-04 19:50:32 +03: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 17:02:00 +04:00
|
|
|
// mIsSelected might have been changed by SetOptionsSelectedByIndex. Possibly
|
|
|
|
// more than once; make sure our mSelectedChanged state is set correctly.
|
2013-11-06 22:02:58 +04:00
|
|
|
mSelectedChanged = mIsSelected != defaultSelected;
|
2007-12-04 19:50:32 +03:00
|
|
|
|
2013-07-24 11:37:14 +04:00
|
|
|
return NS_OK;
|
2007-12-04 19:50:32 +03:00
|
|
|
}
|
|
|
|
|
2014-05-06 21:19:00 +04: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 21:16:51 +04:00
|
|
|
NS_IMETHODIMP
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::GetText(nsAString& aText)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
2002-09-04 03:23:00 +04:00
|
|
|
nsAutoString text;
|
2012-10-21 11:38:40 +04: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 14:08:59 +03:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::script) ||
|
|
|
|
child->IsSVGElement(nsGkAtoms::script)) {
|
2012-10-21 11:38:40 +04:00
|
|
|
child = child->GetNextNonChildNode(this);
|
|
|
|
} else {
|
|
|
|
child = child->GetNextNode(this);
|
|
|
|
}
|
|
|
|
}
|
2000-02-12 19:24:19 +03:00
|
|
|
|
2002-09-26 12:21:26 +04:00
|
|
|
// XXX No CompressWhitespace for nsAString. Sad.
|
2011-10-17 18:59:28 +04:00
|
|
|
text.CompressWhitespace(true, true);
|
2002-09-26 12:21:26 +04:00
|
|
|
aText = text;
|
2002-09-04 03:23:00 +04:00
|
|
|
|
2000-02-12 19:24:19 +03:00
|
|
|
return NS_OK;
|
2000-01-15 04:42:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::SetText(const nsAString& aText)
|
2000-01-15 04:42:56 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return nsContentUtils::SetNodeTextContent(this, aText, true);
|
2002-03-31 13:48:38 +04:00
|
|
|
}
|
|
|
|
|
2012-06-01 13:46:43 +04:00
|
|
|
nsresult
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2012-06-01 13:46:43 +04: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 16:24:58 +04:00
|
|
|
HTMLOptionElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2012-06-01 13:46:43 +04:00
|
|
|
{
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
|
|
|
|
// Our previous parent could have been involved in :disabled/:enabled state.
|
|
|
|
UpdateState(false);
|
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::IntrinsicState() const
|
2005-06-03 06:02:45 +04:00
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsGenericHTMLElement::IntrinsicState();
|
2011-06-28 14:45:51 +04:00
|
|
|
if (Selected()) {
|
2005-06-03 06:02:45 +04:00
|
|
|
state |= NS_EVENT_STATE_CHECKED;
|
|
|
|
}
|
2011-06-28 14:45:51 +04:00
|
|
|
if (DefaultSelected()) {
|
2006-08-16 07:20:19 +04:00
|
|
|
state |= NS_EVENT_STATE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2012-06-01 13:46:43 +04:00
|
|
|
// An <option> is disabled if it has @disabled set or if it's <optgroup> has
|
|
|
|
// @disabled set.
|
2010-09-19 01:33:16 +04:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
|
2005-09-28 12:32:40 +04:00
|
|
|
state |= NS_EVENT_STATE_DISABLED;
|
|
|
|
state &= ~NS_EVENT_STATE_ENABLED;
|
|
|
|
} else {
|
2012-06-01 13:46:43 +04:00
|
|
|
nsIContent* parent = GetParent();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (parent && parent->IsHTMLElement(nsGkAtoms::optgroup) &&
|
2012-06-01 13:46:43 +04: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 12:32:40 +04:00
|
|
|
}
|
|
|
|
|
2005-06-03 06:02:45 +04:00
|
|
|
return state;
|
|
|
|
}
|
2002-03-31 13:48:38 +04:00
|
|
|
|
1999-04-09 03:47:49 +04:00
|
|
|
// Get the select content element that contains this option
|
2013-04-04 11:03:33 +04:00
|
|
|
HTMLSelectElement*
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::GetSelect()
|
1999-01-30 04:02:28 +03:00
|
|
|
{
|
2016-03-03 11:03:44 +03:00
|
|
|
nsIContent* parent = GetParent();
|
2016-03-03 11:47:36 +03:00
|
|
|
if (!parent) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLSelectElement* select = HTMLSelectElement::FromContent(parent);
|
2016-03-03 11:03:44 +03:00
|
|
|
if (select) {
|
|
|
|
return select;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parent->IsHTMLElement(nsGkAtoms::optgroup)) {
|
|
|
|
return nullptr;
|
1999-05-05 00:53:26 +04:00
|
|
|
}
|
2013-02-18 16:24:58 +04:00
|
|
|
|
2016-03-03 11:03:44 +03:00
|
|
|
return HTMLSelectElement::FromContentOrNull(parent->GetParent());
|
1999-05-05 00:53:26 +04:00
|
|
|
}
|
|
|
|
|
2013-01-22 14:53:13 +04: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-05 00:53:26 +04:00
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobal.GetAsSupports());
|
2013-01-22 14:53:13 +04:00
|
|
|
nsIDocument* doc;
|
|
|
|
if (!win || !(doc = win->GetExtantDoc())) {
|
|
|
|
aError.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
1999-05-05 00:53:26 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo> nodeInfo =
|
2013-01-22 14:53:13 +04:00
|
|
|
doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::option, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLOptionElement> option = new HTMLOptionElement(nodeInfo);
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-01-22 14:53:13 +04:00
|
|
|
if (aText.WasPassed()) {
|
2007-11-28 03:52:37 +03:00
|
|
|
// Create a new text node and append it to the option
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsTextNode> textContent =
|
2013-04-04 16:01:08 +04:00
|
|
|
new nsTextNode(option->NodeInfo()->NodeInfoManager());
|
2010-12-03 11:24:17 +03:00
|
|
|
|
2013-01-22 14:53:13 +04:00
|
|
|
textContent->SetText(aText.Value(), false);
|
2013-02-18 16:24:58 +04:00
|
|
|
|
2013-01-22 14:53:13 +04:00
|
|
|
aError = option->AppendChildTo(textContent, false);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
1999-03-02 06:26:29 +03:00
|
|
|
}
|
|
|
|
|
2013-01-22 14:53:13 +04: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 11:24:17 +03:00
|
|
|
}
|
|
|
|
|
2013-01-22 14:53:13 +04: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-05 00:53:26 +04:00
|
|
|
}
|
|
|
|
|
2013-01-22 14:53:13 +04:00
|
|
|
if (aSelected.WasPassed()) {
|
|
|
|
option->SetSelected(aSelected.Value(), aError);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
1999-05-05 00:53:26 +04:00
|
|
|
}
|
|
|
|
}
|
1999-01-30 04:02:28 +03:00
|
|
|
}
|
1999-05-05 00:53:26 +04:00
|
|
|
|
2013-01-22 14:53:13 +04:00
|
|
|
return option.forget();
|
1999-01-30 04:02:28 +03:00
|
|
|
}
|
2009-12-11 07:02:13 +03:00
|
|
|
|
|
|
|
nsresult
|
2013-02-18 16:24:58 +04:00
|
|
|
HTMLOptionElement::CopyInnerTo(Element* aDest)
|
2009-12-11 07:02:13 +03:00
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-18 14:53:36 +04:00
|
|
|
if (aDest->OwnerDoc()->IsStaticDocument()) {
|
2013-02-18 16:24:58 +04:00
|
|
|
static_cast<HTMLOptionElement*>(aDest)->SetSelected(Selected());
|
2009-12-11 07:02:13 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-18 16:26:57 +04: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 17:13:33 +03:00
|
|
|
HTMLOptionElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-18 16:26:57 +04: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 17:13:33 +03:00
|
|
|
return HTMLOptionElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-18 16:26:57 +04:00
|
|
|
}
|
|
|
|
|
2013-02-18 16:24:58 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|