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-08 16:50:30 +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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_HTMLButtonElement_h
|
|
|
|
#define mozilla_dom_HTMLButtonElement_h
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-02-08 16:50:30 +04:00
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsIConstraintValidation.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2014-03-18 08:48:20 +04:00
|
|
|
class EventChainPostVisitor;
|
2014-03-18 08:48:19 +04:00
|
|
|
class EventChainPreVisitor;
|
2013-02-08 16:50:30 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class HTMLButtonElement final : public nsGenericHTMLFormElementWithState,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIConstraintValidation {
|
2013-02-08 16:50:30 +04:00
|
|
|
public:
|
|
|
|
using nsIConstraintValidation::GetValidationMessage;
|
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
explicit HTMLButtonElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2014-09-02 04:49:25 +04:00
|
|
|
FromParser aFromParser = NOT_FROM_PARSER);
|
2013-02-08 16:50:30 +04:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLButtonElement,
|
2013-08-02 05:21:31 +04:00
|
|
|
nsGenericHTMLFormElementWithState)
|
2013-02-08 16:50:30 +04:00
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual int32_t TabIndexDefault() override;
|
2013-02-08 16:50:30 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLButtonElement, button)
|
2013-08-08 00:23:08 +04:00
|
|
|
|
2015-01-20 23:39:28 +03:00
|
|
|
// Element
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override {
|
2015-01-20 23:39:28 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
// overriden nsIFormControl methods
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Reset() override;
|
2016-06-16 10:24:16 +03:00
|
|
|
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD SaveState() override;
|
2018-03-02 21:18:35 +03:00
|
|
|
bool RestoreState(PresState* aState) override;
|
2018-10-31 11:55:33 +03:00
|
|
|
virtual bool IsDisabledForEvents(WidgetEvent* aEvent) override;
|
2013-02-08 16:50:30 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void FieldSetDisabledChanged(bool aNotify) override;
|
2014-04-29 20:58:00 +04:00
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
// EventTarget
|
|
|
|
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
2019-05-09 23:21:28 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
|
2013-02-08 16:50:30 +04:00
|
|
|
|
|
|
|
// nsINode
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-02-08 16:50:30 +04:00
|
|
|
|
|
|
|
// nsIContent
|
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
|
|
|
virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
|
2019-05-29 01:47:08 +03:00
|
|
|
virtual void UnbindFromTree(bool aNullParent = true) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DoneCreatingElement() override;
|
2013-02-08 16:50:30 +04:00
|
|
|
|
2014-04-29 20:58:00 +04:00
|
|
|
void UpdateBarredFromConstraintValidation();
|
2013-02-08 16:50:30 +04:00
|
|
|
// Element
|
2015-03-21 19:28:04 +03:00
|
|
|
EventStates IntrinsicState() const override;
|
2013-02-08 16:50:30 +04:00
|
|
|
/**
|
|
|
|
* Called when an attribute is about to be changed
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-03-16 21:50:41 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aNotify) override;
|
2013-02-08 16:50:30 +04:00
|
|
|
/**
|
|
|
|
* Called when an attribute has just been changed
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
2017-05-19 00:09:01 +03:00
|
|
|
bool aNotify) override;
|
2013-02-08 16:50:30 +04:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAttrValue& aResult) override;
|
2013-02-08 16:50:30 +04:00
|
|
|
|
|
|
|
// nsGenericHTMLElement
|
|
|
|
virtual bool IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t* aTabIndex) override;
|
2013-02-08 16:50:30 +04:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
// WebIDL
|
|
|
|
bool Autofocus() const { return GetBoolAttr(nsGkAtoms::autofocus); }
|
|
|
|
void SetAutofocus(bool aAutofocus, ErrorResult& aError) {
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::autofocus, aAutofocus, aError);
|
|
|
|
}
|
|
|
|
bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled); }
|
|
|
|
void SetDisabled(bool aDisabled, ErrorResult& aError) {
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::disabled, aDisabled, aError);
|
|
|
|
}
|
|
|
|
// nsGenericHTMLFormElement::GetForm is fine.
|
|
|
|
using nsGenericHTMLFormElement::GetForm;
|
2017-09-28 07:03:58 +03:00
|
|
|
// GetFormAction implemented in superclass
|
2013-02-08 16:50:30 +04:00
|
|
|
void SetFormAction(const nsAString& aFormAction, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::formaction, aFormAction, aRv);
|
|
|
|
}
|
2017-09-28 07:03:58 +03:00
|
|
|
void GetFormEnctype(nsAString& aFormEncType);
|
2013-02-08 16:50:30 +04:00
|
|
|
void SetFormEnctype(const nsAString& aFormEnctype, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::formenctype, aFormEnctype, aRv);
|
|
|
|
}
|
2017-09-28 07:03:58 +03:00
|
|
|
void GetFormMethod(nsAString& aFormMethod);
|
2013-02-08 16:50:30 +04:00
|
|
|
void SetFormMethod(const nsAString& aFormMethod, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::formmethod, aFormMethod, aRv);
|
|
|
|
}
|
|
|
|
bool FormNoValidate() const { return GetBoolAttr(nsGkAtoms::formnovalidate); }
|
|
|
|
void SetFormNoValidate(bool aFormNoValidate, ErrorResult& aError) {
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::formnovalidate, aFormNoValidate, aError);
|
|
|
|
}
|
2017-09-28 07:03:58 +03:00
|
|
|
void GetFormTarget(DOMString& aFormTarget) {
|
|
|
|
GetHTMLAttr(nsGkAtoms::formtarget, aFormTarget);
|
|
|
|
}
|
2013-02-08 16:50:30 +04:00
|
|
|
void SetFormTarget(const nsAString& aFormTarget, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::formtarget, aFormTarget, aRv);
|
|
|
|
}
|
2017-09-28 07:03:58 +03:00
|
|
|
void GetName(DOMString& aName) { GetHTMLAttr(nsGkAtoms::name, aName); }
|
2013-02-08 16:50:30 +04:00
|
|
|
void SetName(const nsAString& aName, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::name, aName, aRv);
|
|
|
|
}
|
2017-09-28 07:03:58 +03:00
|
|
|
void GetType(nsAString& aType);
|
2013-02-08 16:50:30 +04:00
|
|
|
void SetType(const nsAString& aType, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::type, aType, aRv);
|
|
|
|
}
|
2017-09-28 07:03:58 +03:00
|
|
|
void GetValue(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::value, aValue); }
|
2013-02-08 16:50:30 +04:00
|
|
|
void SetValue(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
2017-07-14 06:46:28 +03:00
|
|
|
// Override SetCustomValidity so we update our state properly when it's called
|
|
|
|
// via bindings.
|
|
|
|
void SetCustomValidity(const nsAString& aError);
|
2013-02-08 16:50:30 +04:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~HTMLButtonElement();
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
bool mDisabledChanged;
|
|
|
|
bool mInInternalActivate;
|
|
|
|
bool mInhibitStateRestoration;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_HTMLButtonElement_h
|