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 {
|
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
HTMLOutputElement::HTMLOutputElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2014-06-17 03:01:22 +04:00
|
|
|
FromParser aFromParser)
|
2018-09-21 23:45:49 +03:00
|
|
|
: nsGenericHTMLFormElement(std::move(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);
|
|
|
|
}
|
|
|
|
|
2020-02-20 19:19:15 +03:00
|
|
|
HTMLOutputElement::~HTMLOutputElement() = default;
|
2013-02-12 14:10:44 +04:00
|
|
|
|
2017-10-03 02:21:17 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLOutputElement, nsGenericHTMLFormElement,
|
|
|
|
mValidity, mTokenList)
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLOutputElement,
|
|
|
|
nsGenericHTMLFormElement,
|
|
|
|
nsIMutationObserver,
|
|
|
|
nsIConstraintValidation)
|
2013-02-12 14:10:44 +04:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLOutputElement)
|
|
|
|
|
|
|
|
void 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;
|
|
|
|
}
|
|
|
|
|
2017-11-02 06:35:52 +03:00
|
|
|
bool HTMLOutputElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
nsAttrValue& aResult) {
|
2013-02-12 14:10:44 +04:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::_for) {
|
|
|
|
aResult.ParseAtomArray(aValue);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLFormElement::ParseAttribute(
|
2017-11-02 06:35:52 +03:00
|
|
|
aNamespaceID, aAttribute, aValue, aMaybeScriptedPrincipal, aResult);
|
2013-02-12 14:10:44 +04:00
|
|
|
}
|
|
|
|
|
2014-06-17 03:01:22 +04:00
|
|
|
void HTMLOutputElement::DoneAddingChildren(bool aHaveNotified) {
|
|
|
|
mIsDoneAddingChildren = true;
|
|
|
|
}
|
|
|
|
|
2013-02-12 14:10:44 +04:00
|
|
|
EventStates 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;
|
|
|
|
}
|
|
|
|
|
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 07:27:04 +03:00
|
|
|
nsresult HTMLOutputElement::BindToTree(BindContext& aContext,
|
|
|
|
nsINode& aParent) {
|
|
|
|
nsresult rv = nsGenericHTMLFormElement::BindToTree(aContext, aParent);
|
2013-02-12 14:10:44 +04:00
|
|
|
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) {
|
2017-12-01 04:37:00 +03:00
|
|
|
// We can't pass mDefaultValue, because it'll be truncated when
|
|
|
|
// the element's descendants are changed.
|
|
|
|
aRv = nsContentUtils::SetNodeTextContent(this, aDefaultValue, true);
|
2013-02-12 14:10:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-12 14:11:01 +04:00
|
|
|
nsDOMTokenList* 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
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void HTMLOutputElement::CharacterDataChanged(nsIContent* aContent,
|
2018-02-27 17:30:27 +03:00
|
|
|
const CharacterDataChangeInfo&) {
|
2013-02-12 14:10:44 +04:00
|
|
|
DescendantsChanged();
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void HTMLOutputElement::ContentAppended(nsIContent* aFirstNewContent) {
|
2013-02-12 14:10:44 +04:00
|
|
|
DescendantsChanged();
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void HTMLOutputElement::ContentInserted(nsIContent* aChild) {
|
2013-02-12 14:10:44 +04:00
|
|
|
DescendantsChanged();
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void HTMLOutputElement::ContentRemoved(nsIContent* aChild,
|
2013-02-12 14:10:44 +04:00
|
|
|
nsIContent* aPreviousSibling) {
|
|
|
|
DescendantsChanged();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
JSObject* HTMLOutputElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLOutputElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-12 14:11:01 +04:00
|
|
|
}
|
|
|
|
|
2013-02-12 14:10:44 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|