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: */
|
2013-02-12 14:10:44 +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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/HTMLOutputElement.h"
|
|
|
|
|
2013-08-14 10:55:11 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-08-14 10:55:11 +04:00
|
|
|
#include "mozilla/dom/HTMLFormElement.h"
|
2016-06-16 10:24:16 +03:00
|
|
|
#include "mozilla/dom/HTMLFormSubmission.h"
|
2013-02-12 14:11:01 +04:00
|
|
|
#include "mozilla/dom/HTMLOutputElementBinding.h"
|
2013-08-14 10:55:11 +04:00
|
|
|
#include "nsContentUtils.h"
|
2016-02-12 01:50:42 +03:00
|
|
|
#include "nsDOMTokenList.h"
|
2013-02-12 14:10:44 +04:00
|
|
|
|
2014-06-17 03:01:22 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Output)
|
2013-02-12 14:10:44 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLOutputElement::HTMLOutputElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
|
2014-06-17 03:01:22 +04:00
|
|
|
FromParser aFromParser)
|
2017-04-01 05:49:00 +03:00
|
|
|
: nsGenericHTMLFormElement(aNodeInfo, NS_FORM_OUTPUT)
|
2013-02-12 14:10:44 +04:00
|
|
|
, mValueModeFlag(eModeDefault)
|
2014-06-17 03:01:22 +04:00
|
|
|
, mIsDoneAddingChildren(!aFromParser)
|
2013-02-12 14:10:44 +04:00
|
|
|
{
|
|
|
|
AddMutationObserver(this);
|
|
|
|
|
|
|
|
// We start out valid and ui-valid (since we have no form).
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_VALID | NS_EVENT_STATE_MOZ_UI_VALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLOutputElement::~HTMLOutputElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLOutputElement)
|
|
|
|
|
2013-02-12 14:10:44 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLOutputElement,
|
|
|
|
nsGenericHTMLFormElement)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mValidity)
|
2014-03-28 18:36:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTokenList)
|
2013-02-12 14:10:44 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLOutputElement,
|
|
|
|
nsGenericHTMLFormElement)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mValidity)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTokenList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLOutputElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLOutputElement, Element)
|
|
|
|
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLOutputElement)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(HTMLOutputElement,
|
|
|
|
nsIMutationObserver,
|
|
|
|
nsIConstraintValidation)
|
2013-08-08 00:23:08 +04:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLFormElement)
|
2013-02-12 14:10:44 +04:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLOutputElement)
|
|
|
|
|
2013-08-02 02:24:23 +04:00
|
|
|
void
|
2013-02-12 14:10:44 +04:00
|
|
|
HTMLOutputElement::SetCustomValidity(const nsAString& aError)
|
|
|
|
{
|
|
|
|
nsIConstraintValidation::SetCustomValidity(aError);
|
|
|
|
|
|
|
|
UpdateState(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLOutputElement::Reset()
|
|
|
|
{
|
|
|
|
mValueModeFlag = eModeDefault;
|
|
|
|
return nsContentUtils::SetNodeTextContent(this, mDefaultValue, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-16 10:24:16 +03:00
|
|
|
HTMLOutputElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission)
|
2013-02-12 14:10:44 +04:00
|
|
|
{
|
|
|
|
// The output element is not submittable.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLOutputElement::ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue, nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::_for) {
|
|
|
|
aResult.ParseAtomArray(aValue);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLFormElement::ParseAttribute(aNamespaceID, aAttribute,
|
|
|
|
aValue, aResult);
|
|
|
|
}
|
|
|
|
|
2014-06-17 03:01:22 +04:00
|
|
|
void
|
|
|
|
HTMLOutputElement::DoneAddingChildren(bool aHaveNotified)
|
|
|
|
{
|
|
|
|
mIsDoneAddingChildren = true;
|
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2013-02-12 14:10:44 +04:00
|
|
|
HTMLOutputElement::IntrinsicState() const
|
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates states = nsGenericHTMLFormElement::IntrinsicState();
|
2013-02-12 14:10:44 +04:00
|
|
|
|
|
|
|
// We don't have to call IsCandidateForConstraintValidation()
|
|
|
|
// because <output> can't be barred from constraint validation.
|
|
|
|
if (IsValid()) {
|
|
|
|
states |= NS_EVENT_STATE_VALID;
|
|
|
|
if (!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) {
|
|
|
|
states |= NS_EVENT_STATE_MOZ_UI_VALID;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
states |= NS_EVENT_STATE_INVALID;
|
|
|
|
if (!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) {
|
|
|
|
states |= NS_EVENT_STATE_MOZ_UI_INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return states;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLOutputElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLFormElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Unfortunately, we can actually end up having to change our state
|
|
|
|
// as a result of being bound to a tree even from the parser: we
|
|
|
|
// might end up a in a novalidate form, and unlike other form
|
|
|
|
// controls that on its own is enough to make change ui-valid state.
|
|
|
|
// So just go ahead and update our state now.
|
|
|
|
UpdateState(false);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-08-14 10:55:11 +04:00
|
|
|
void
|
|
|
|
HTMLOutputElement::GetValue(nsAString& aValue)
|
|
|
|
{
|
2015-05-22 21:16:20 +03:00
|
|
|
nsContentUtils::GetNodeTextContent(this, true, aValue);
|
2013-08-14 10:55:11 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 02:24:23 +04:00
|
|
|
void
|
|
|
|
HTMLOutputElement::SetValue(const nsAString& aValue, ErrorResult& aRv)
|
2013-02-12 14:10:44 +04:00
|
|
|
{
|
|
|
|
mValueModeFlag = eModeValue;
|
2013-08-02 02:24:23 +04:00
|
|
|
aRv = nsContentUtils::SetNodeTextContent(this, aValue, true);
|
2013-02-12 14:10:44 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 02:24:23 +04:00
|
|
|
void
|
|
|
|
HTMLOutputElement::SetDefaultValue(const nsAString& aDefaultValue, ErrorResult& aRv)
|
2013-02-12 14:10:44 +04:00
|
|
|
{
|
|
|
|
mDefaultValue = aDefaultValue;
|
|
|
|
if (mValueModeFlag == eModeDefault) {
|
2013-08-02 02:24:23 +04:00
|
|
|
aRv = nsContentUtils::SetNodeTextContent(this, mDefaultValue, true);
|
2013-02-12 14:10:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:50:42 +03:00
|
|
|
nsDOMTokenList*
|
2013-02-12 14:11:01 +04:00
|
|
|
HTMLOutputElement::HtmlFor()
|
2013-02-12 14:10:44 +04:00
|
|
|
{
|
|
|
|
if (!mTokenList) {
|
2016-02-12 01:50:42 +03:00
|
|
|
mTokenList = new nsDOMTokenList(this, nsGkAtoms::_for);
|
2013-02-12 14:10:44 +04:00
|
|
|
}
|
2013-02-12 14:11:01 +04:00
|
|
|
return mTokenList;
|
|
|
|
}
|
2013-02-12 14:10:44 +04:00
|
|
|
|
|
|
|
void HTMLOutputElement::DescendantsChanged()
|
|
|
|
{
|
2014-06-17 03:01:22 +04:00
|
|
|
if (mIsDoneAddingChildren && mValueModeFlag == eModeDefault) {
|
2015-05-22 21:16:20 +03:00
|
|
|
nsContentUtils::GetNodeTextContent(this, true, mDefaultValue);
|
2013-02-12 14:10:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIMutationObserver
|
|
|
|
|
|
|
|
void HTMLOutputElement::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
DescendantsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLOutputElement::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
|
|
|
int32_t aNewIndexInContainer)
|
|
|
|
{
|
|
|
|
DescendantsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLOutputElement::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer)
|
|
|
|
{
|
|
|
|
DescendantsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLOutputElement::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer,
|
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
|
|
|
DescendantsChanged();
|
|
|
|
}
|
|
|
|
|
2013-02-12 14:11:01 +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
|
|
|
HTMLOutputElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-12 14:11:01 +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 HTMLOutputElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-12 14:11:01 +04:00
|
|
|
}
|
|
|
|
|
2013-02-12 14:10:44 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|