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/. */
|
2012-09-30 20:40:24 +04:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
#include "mozilla/dom/HTMLButtonElement.h"
|
|
|
|
|
2016-06-16 10:24:16 +03:00
|
|
|
#include "HTMLFormSubmissionConstants.h"
|
2013-02-08 16:50:30 +04:00
|
|
|
#include "mozilla/dom/HTMLButtonElementBinding.h"
|
2016-06-16 10:24:16 +03:00
|
|
|
#include "mozilla/dom/HTMLFormSubmission.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-03 05:03:33 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-10-14 01:31:26 +04:00
|
|
|
#include "nsIFormControl.h"
|
1999-01-15 05:07:46 +03:00
|
|
|
#include "nsIURL.h"
|
2001-10-24 04:01:09 +04:00
|
|
|
#include "nsIFrame.h"
|
1999-08-21 04:19:34 +04:00
|
|
|
#include "nsIFormControlFrame.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2013-09-25 15:21:20 +04:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2019-04-03 15:40:26 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2001-12-16 14:58:03 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
2005-12-13 02:53:06 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2018-03-02 21:18:35 +03:00
|
|
|
#include "mozilla/PresState.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
2013-06-19 18:24:37 +04:00
|
|
|
#include "mozilla/dom/HTMLFormElement.h"
|
2010-09-08 21:43:28 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2006-03-07 20:08:51 +03:00
|
|
|
|
2007-08-17 01:10:29 +04:00
|
|
|
#define NS_IN_SUBMIT_CLICK (1 << 0)
|
|
|
|
#define NS_OUTER_ACTIVATE_EVENT (1 << 1)
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Button)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2010-04-15 15:03:00 +04:00
|
|
|
static const nsAttrValue::EnumTable kButtonTypeTable[] = {
|
|
|
|
{"button", NS_FORM_BUTTON_BUTTON},
|
|
|
|
{"reset", NS_FORM_BUTTON_RESET},
|
|
|
|
{"submit", NS_FORM_BUTTON_SUBMIT},
|
2016-09-07 05:20:17 +03:00
|
|
|
{nullptr, 0}};
|
2010-04-15 15:03:00 +04:00
|
|
|
|
|
|
|
// Default type is 'submit'.
|
|
|
|
static const nsAttrValue::EnumTable* kButtonDefaultType = &kButtonTypeTable[2];
|
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
// Construction, destruction
|
2018-09-21 23:45:49 +03:00
|
|
|
HTMLButtonElement::HTMLButtonElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2013-02-08 16:50:30 +04:00
|
|
|
FromParser aFromParser)
|
2019-06-29 02:39:01 +03:00
|
|
|
: nsGenericHTMLFormElementWithState(std::move(aNodeInfo),
|
2018-09-21 23:45:49 +03:00
|
|
|
kButtonDefaultType->value),
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisabledChanged(false),
|
|
|
|
mInInternalActivate(false),
|
2011-06-01 01:57:16 +04:00
|
|
|
mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT)) {
|
2011-06-01 05:46:57 +04:00
|
|
|
// Set up our default state: enabled
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_ENABLED);
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::~HTMLButtonElement() {}
|
1998-09-03 05:03:33 +04:00
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
// nsISupports
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLButtonElement,
|
|
|
|
nsGenericHTMLFormElementWithState, mValidity)
|
2013-01-16 22:01:01 +04:00
|
|
|
|
2017-08-16 23:14:11 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLButtonElement,
|
|
|
|
nsGenericHTMLFormElementWithState,
|
|
|
|
nsIConstraintValidation)
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
void HTMLButtonElement::SetCustomValidity(const nsAString& aError) {
|
2014-04-29 20:58:00 +04:00
|
|
|
nsIConstraintValidation::SetCustomValidity(aError);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2014-04-29 20:58:00 +04:00
|
|
|
UpdateState(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLButtonElement::UpdateBarredFromConstraintValidation() {
|
|
|
|
SetBarredFromConstraintValidation(mType == NS_FORM_BUTTON_BUTTON ||
|
|
|
|
mType == NS_FORM_BUTTON_RESET ||
|
|
|
|
IsDisabled());
|
|
|
|
}
|
1998-10-14 01:31:26 +04:00
|
|
|
|
2014-04-29 20:58:00 +04:00
|
|
|
void HTMLButtonElement::FieldSetDisabledChanged(bool aNotify) {
|
Bug 1375599 - Change IsDisabled() to look at NS_EVENT_STATE_DISABLED instead of the "disabled" attribute. r=bz
In order to speed up IsDisabled(), instead of querying for the @disabled
attribute, we're now using the NS_EVENT_STATE_DISABLED flag to know whether an
element is disabled.
It is safe to use the NS_EVENT_STATE_DISABLED flag for the following reasons:
- For form elements, nsGenericHTMLFormElement::IsDisabled() is only called on
form elements that can be disabled; form elements that can't be disabled
overrides IsDisabled() to return false directly.
And, before this patch, NS_EVENT_STATE_DISABLED flag is set by
nsGenericHTMLFormElement::IntrinsicState() if and only if IsDisabled() in all
cases when CanBeDisabled() is true, and when CanBeDisabled() is false then
IsDisabled() is always false and the flag is not set.
- For non form elements, optgroup and option have the flag matching
IsDisabled(). Note that option's IsDisabled() should also refer to optgroup's
(if it exists) disabled state, which was not done before this patch.
For this to work correctly, we need to set NS_EVENT_STATE_DISABLED earlier,
that is, in AfterSetAttr(), before any consumer of IsDisabled().
We also need to update the flag whenever the element's parent (e.g. fieldset or
optgroup) disabled state changes and when moving into/out of a parent
container.
Note that NS_EVENT_STATE_DISABLED/ENABLED is now part of the
EXTERNALLY_MANAGED_STATES.
MozReview-Commit-ID: KSceikeqvvU
2017-07-20 09:15:00 +03:00
|
|
|
// FieldSetDisabledChanged *has* to be called *before*
|
|
|
|
// UpdateBarredFromConstraintValidation, because the latter depends on our
|
|
|
|
// disabled state.
|
2014-04-29 20:58:00 +04:00
|
|
|
nsGenericHTMLFormElementWithState::FieldSetDisabledChanged(aNotify);
|
Bug 1375599 - Change IsDisabled() to look at NS_EVENT_STATE_DISABLED instead of the "disabled" attribute. r=bz
In order to speed up IsDisabled(), instead of querying for the @disabled
attribute, we're now using the NS_EVENT_STATE_DISABLED flag to know whether an
element is disabled.
It is safe to use the NS_EVENT_STATE_DISABLED flag for the following reasons:
- For form elements, nsGenericHTMLFormElement::IsDisabled() is only called on
form elements that can be disabled; form elements that can't be disabled
overrides IsDisabled() to return false directly.
And, before this patch, NS_EVENT_STATE_DISABLED flag is set by
nsGenericHTMLFormElement::IntrinsicState() if and only if IsDisabled() in all
cases when CanBeDisabled() is true, and when CanBeDisabled() is false then
IsDisabled() is always false and the flag is not set.
- For non form elements, optgroup and option have the flag matching
IsDisabled(). Note that option's IsDisabled() should also refer to optgroup's
(if it exists) disabled state, which was not done before this patch.
For this to work correctly, we need to set NS_EVENT_STATE_DISABLED earlier,
that is, in AfterSetAttr(), before any consumer of IsDisabled().
We also need to update the flag whenever the element's parent (e.g. fieldset or
optgroup) disabled state changes and when moving into/out of a parent
container.
Note that NS_EVENT_STATE_DISABLED/ENABLED is now part of the
EXTERNALLY_MANAGED_STATES.
MozReview-Commit-ID: KSceikeqvvU
2017-07-20 09:15:00 +03:00
|
|
|
|
|
|
|
UpdateBarredFromConstraintValidation();
|
|
|
|
UpdateState(aNotify);
|
2014-04-29 20:58:00 +04:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLButtonElement)
|
1999-07-28 09:26:55 +04:00
|
|
|
|
2017-09-28 07:03:58 +03:00
|
|
|
void HTMLButtonElement::GetFormEnctype(nsAString& aFormEncType) {
|
|
|
|
GetEnumAttr(nsGkAtoms::formenctype, "", kFormDefaultEnctype->tag,
|
|
|
|
aFormEncType);
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2017-09-28 07:03:58 +03:00
|
|
|
void HTMLButtonElement::GetFormMethod(nsAString& aFormMethod) {
|
|
|
|
GetEnumAttr(nsGkAtoms::formmethod, "", kFormDefaultMethod->tag, aFormMethod);
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2017-09-28 07:03:58 +03:00
|
|
|
void HTMLButtonElement::GetType(nsAString& aType) {
|
|
|
|
GetEnumAttr(nsGkAtoms::type, kButtonDefaultType->tag, aType);
|
|
|
|
}
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
int32_t HTMLButtonElement::TabIndexDefault() { return 0; }
|
2012-10-06 11:19:51 +04:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
bool HTMLButtonElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
|
|
|
|
int32_t* aTabIndex) {
|
2013-08-02 05:21:31 +04:00
|
|
|
if (nsGenericHTMLFormElementWithState::IsHTMLFocusable(
|
|
|
|
aWithMouse, aIsFocusable, aTabIndex)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2004-07-25 01:12:43 +04:00
|
|
|
}
|
2010-06-21 16:37:34 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
*aIsFocusable =
|
2010-06-21 16:37:34 +04:00
|
|
|
#ifdef XP_MACOSX
|
2010-08-09 20:15:47 +04:00
|
|
|
(!aWithMouse || nsFocusManager::sMouseFocusesFormControl) &&
|
2010-06-21 16:37:34 +04:00
|
|
|
#endif
|
2010-09-19 01:33:16 +04:00
|
|
|
!IsDisabled();
|
2008-04-15 22:40:38 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2004-07-25 01:12:43 +04:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
bool HTMLButtonElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-02-08 16:50:30 +04:00
|
|
|
nsAttrValue& aResult) {
|
2010-08-20 21:47:30 +04:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::type) {
|
2017-04-20 07:35:19 +03:00
|
|
|
return aResult.ParseEnumValue(aValue, kButtonTypeTable, false,
|
|
|
|
kButtonDefaultType);
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
2010-04-15 15:03:00 +04:00
|
|
|
|
2010-08-20 21:47:30 +04:00
|
|
|
if (aAttribute == nsGkAtoms::formmethod) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aValue, kFormMethodTable, false);
|
2010-08-20 21:47:30 +04:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::formenctype) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aValue, kFormEnctypeTable, false);
|
2010-08-20 21:47:30 +04:00
|
|
|
}
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2005-11-29 19:37:15 +03:00
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
|
|
|
|
2018-10-31 11:55:33 +03:00
|
|
|
bool HTMLButtonElement::IsDisabledForEvents(WidgetEvent* aEvent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFormControlFrame* formControlFrame = GetFormControlFrame(false);
|
2014-03-25 19:36:49 +04:00
|
|
|
nsIFrame* formFrame = do_QueryFrame(formControlFrame);
|
2018-10-31 11:55:33 +03:00
|
|
|
return IsElementDisabledForEvents(aEvent, formFrame);
|
2013-01-03 19:17:36 +04:00
|
|
|
}
|
2001-04-13 04:39:52 +04:00
|
|
|
|
2016-10-21 05:11:07 +03:00
|
|
|
void HTMLButtonElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aVisitor.mCanHandle = false;
|
2018-10-31 11:55:33 +03:00
|
|
|
|
|
|
|
if (IsDisabledForEvents(aVisitor.mEvent)) {
|
2018-04-05 20:42:41 +03:00
|
|
|
return;
|
2001-04-13 04:39:52 +04:00
|
|
|
}
|
2002-11-30 03:01:21 +03:00
|
|
|
|
2007-08-17 01:10:29 +04:00
|
|
|
// Track whether we're in the outermost Dispatch invocation that will
|
|
|
|
// cause activation of the input. That is, if we're a click event, or a
|
|
|
|
// DOMActivate that was dispatched directly, this will be set, but if we're
|
|
|
|
// a DOMActivate dispatched from click handling, it will not be set.
|
2013-10-28 13:03:19 +04:00
|
|
|
WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
|
|
|
|
bool outerActivateEvent =
|
|
|
|
((mouseEvent && mouseEvent->IsLeftClickEvent()) ||
|
2015-09-02 09:08:01 +03:00
|
|
|
(aVisitor.mEvent->mMessage == eLegacyDOMActivate &&
|
2018-12-12 00:35:40 +03:00
|
|
|
!mInInternalActivate && aVisitor.mEvent->mOriginalTarget == this));
|
2007-08-17 01:10:29 +04:00
|
|
|
|
|
|
|
if (outerActivateEvent) {
|
|
|
|
aVisitor.mItemFlags |= NS_OUTER_ACTIVATE_EVENT;
|
2018-12-12 00:35:40 +03:00
|
|
|
if (mType == NS_FORM_BUTTON_SUBMIT && mForm &&
|
|
|
|
!aVisitor.mEvent->mFlags.mMultiplePreActionsPrevented) {
|
|
|
|
aVisitor.mEvent->mFlags.mMultiplePreActionsPrevented = true;
|
2007-08-17 01:10:29 +04:00
|
|
|
aVisitor.mItemFlags |= NS_IN_SUBMIT_CLICK;
|
|
|
|
// tell the form that we are about to enter a click handler.
|
|
|
|
// that means that if there are scripted submissions, the
|
|
|
|
// latest one will be deferred until after the exit point of the handler.
|
2010-08-20 03:23:59 +04:00
|
|
|
mForm->OnSubmitClickBegin(this);
|
2007-08-17 01:10:29 +04:00
|
|
|
}
|
2002-11-30 03:01:21 +03:00
|
|
|
}
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
nsGenericHTMLElement::GetEventTargetParent(aVisitor);
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2014-03-18 08:48:20 +04:00
|
|
|
nsresult HTMLButtonElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
2006-03-07 20:08:51 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (!aVisitor.mPresContext) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-08-17 01:10:29 +04:00
|
|
|
|
2013-10-28 13:03:19 +04:00
|
|
|
if (aVisitor.mEventStatus != nsEventStatus_eConsumeNoDefault) {
|
|
|
|
WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
|
|
|
|
if (mouseEvent && mouseEvent->IsLeftClickEvent()) {
|
2015-08-22 07:02:39 +03:00
|
|
|
// DOMActive event should be trusted since the activation is actually
|
|
|
|
// occurred even if the cause is an untrusted click event.
|
2015-09-02 09:08:01 +03:00
|
|
|
InternalUIEvent actEvent(true, eLegacyDOMActivate, mouseEvent);
|
2016-03-26 10:22:27 +03:00
|
|
|
actEvent.mDetail = 1;
|
2013-10-28 13:03:19 +04:00
|
|
|
|
2019-04-03 15:40:26 +03:00
|
|
|
if (RefPtr<PresShell> presShell = aVisitor.mPresContext->GetPresShell()) {
|
2013-10-28 13:03:19 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
mInInternalActivate = true;
|
2019-04-03 15:40:26 +03:00
|
|
|
presShell->HandleDOMEventWithTarget(this, &actEvent, &status);
|
2013-10-28 13:03:19 +04:00
|
|
|
mInInternalActivate = false;
|
|
|
|
|
|
|
|
// If activate is cancelled, we must do the same as when click is
|
|
|
|
// cancelled (revert the checkbox to its original value).
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
aVisitor.mEventStatus = status;
|
|
|
|
}
|
|
|
|
}
|
2007-08-17 01:10:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-30 02:59:37 +04:00
|
|
|
// mForm is null if the event handler removed us from the document (bug
|
|
|
|
// 194582).
|
2006-03-07 20:08:51 +03:00
|
|
|
if ((aVisitor.mItemFlags & NS_IN_SUBMIT_CLICK) && mForm) {
|
2002-11-30 03:01:21 +03:00
|
|
|
// tell the form that we are about to exit a click handler
|
|
|
|
// so the form knows not to defer subsequent submissions
|
|
|
|
// the pending ones that were created during the handler
|
|
|
|
// will be flushed or forgoten.
|
|
|
|
mForm->OnSubmitClickEnd();
|
|
|
|
}
|
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
if (nsEventStatus_eIgnore == aVisitor.mEventStatus) {
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (aVisitor.mEvent->mMessage) {
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyPress:
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyUp: {
|
2002-11-30 03:01:21 +03:00
|
|
|
// For backwards compat, trigger buttons with space or enter
|
|
|
|
// (bug 25300)
|
2013-10-18 10:10:24 +04:00
|
|
|
WidgetKeyboardEvent* keyEvent = aVisitor.mEvent->AsKeyboardEvent();
|
2016-05-12 11:13:49 +03:00
|
|
|
if ((keyEvent->mKeyCode == NS_VK_RETURN &&
|
2015-08-29 02:58:27 +03:00
|
|
|
eKeyPress == aVisitor.mEvent->mMessage) ||
|
2016-05-12 11:13:49 +03:00
|
|
|
(keyEvent->mKeyCode == NS_VK_SPACE &&
|
2015-08-29 02:58:27 +03:00
|
|
|
eKeyUp == aVisitor.mEvent->mMessage)) {
|
2016-03-17 10:01:30 +03:00
|
|
|
DispatchSimulatedClick(this, aVisitor.mEvent->IsTrusted(),
|
2016-03-19 15:37:09 +03:00
|
|
|
aVisitor.mPresContext);
|
2010-12-27 23:42:10 +03:00
|
|
|
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
|
2000-06-21 04:40:11 +04:00
|
|
|
}
|
2015-08-29 02:58:27 +03:00
|
|
|
} break;
|
2002-11-30 03:01:21 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
2007-08-17 01:10:29 +04:00
|
|
|
if (aVisitor.mItemFlags & NS_OUTER_ACTIVATE_EVENT) {
|
|
|
|
if (mForm &&
|
|
|
|
(mType == NS_FORM_BUTTON_SUBMIT || mType == NS_FORM_BUTTON_RESET)) {
|
2013-09-27 10:20:55 +04:00
|
|
|
InternalFormEvent event(
|
2015-09-02 09:08:00 +03:00
|
|
|
true, (mType == NS_FORM_BUTTON_RESET) ? eFormReset : eFormSubmit);
|
2016-08-03 11:06:10 +03:00
|
|
|
event.mOriginator = this;
|
2007-08-17 01:10:29 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
|
2019-04-03 15:40:26 +03:00
|
|
|
RefPtr<PresShell> presShell = aVisitor.mPresContext->GetPresShell();
|
2019-04-30 04:35:30 +03:00
|
|
|
// If |PresShell::Destroy| has been called due to
|
2007-08-17 01:10:29 +04:00
|
|
|
// handling the event, the pres context will return
|
|
|
|
// a null pres shell. See bug 125624.
|
|
|
|
//
|
|
|
|
// Using presShell to dispatch the event. It makes sure that
|
|
|
|
// event is not handled if the window is being destroyed.
|
2015-09-02 09:08:00 +03:00
|
|
|
if (presShell && (event.mMessage != eFormSubmit ||
|
2016-08-02 21:05:36 +03:00
|
|
|
mForm->SubmissionCanProceed(this))) {
|
2010-09-11 08:07:41 +04:00
|
|
|
// TODO: removing this code and have the submit event sent by the form
|
|
|
|
// see bug 592124.
|
2009-10-30 04:49:11 +03:00
|
|
|
// Hold a strong ref while dispatching
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLFormElement> form(mForm);
|
2016-08-24 21:12:09 +03:00
|
|
|
presShell->HandleDOMEventWithTarget(form, &event, &status);
|
2010-12-27 23:42:10 +03:00
|
|
|
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
|
2002-11-30 03:01:21 +03:00
|
|
|
}
|
2007-08-17 01:10:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ((aVisitor.mItemFlags & NS_IN_SUBMIT_CLICK) && mForm) {
|
|
|
|
// Tell the form to flush a possible pending submission.
|
|
|
|
// the reason is that the script returned false (the event was
|
|
|
|
// not ignored) so if there is a stored submission, it needs to
|
|
|
|
// be submitted immediatelly.
|
|
|
|
// Note, NS_IN_SUBMIT_CLICK is set only when we're in outer activate event.
|
|
|
|
mForm->FlushPendingSubmission();
|
2002-11-30 03:01:21 +03:00
|
|
|
} // if
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
return rv;
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
1998-10-14 01:31:26 +04:00
|
|
|
|
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 HTMLButtonElement::BindToTree(BindContext& aContext,
|
|
|
|
nsINode& aParent) {
|
|
|
|
nsresult rv =
|
|
|
|
nsGenericHTMLFormElementWithState::BindToTree(aContext, aParent);
|
2011-06-01 05:46:57 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Update our state; we may now be the default submit element
|
|
|
|
UpdateState(false);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
void HTMLButtonElement::UnbindFromTree(bool aNullParent) {
|
|
|
|
nsGenericHTMLFormElementWithState::UnbindFromTree(aNullParent);
|
2011-06-01 05:46:57 +04:00
|
|
|
|
|
|
|
// Update our state; we may no longer be the default submit element
|
|
|
|
UpdateState(false);
|
|
|
|
}
|
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
NS_IMETHODIMP
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::Reset() { return NS_OK; }
|
2001-11-02 10:40:01 +03:00
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-16 10:24:16 +03:00
|
|
|
HTMLButtonElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission) {
|
2002-02-16 04:19:24 +03:00
|
|
|
//
|
|
|
|
// We only submit if we were the button pressed
|
|
|
|
//
|
2010-08-20 01:58:20 +04:00
|
|
|
if (aFormSubmission->GetOriginatingElement() != this) {
|
2001-11-02 10:40:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
// Disabled elements don't submit
|
2010-09-19 01:33:16 +04:00
|
|
|
if (IsDisabled()) {
|
|
|
|
return NS_OK;
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
//
|
|
|
|
// Get the name (if no name, no submit)
|
|
|
|
//
|
2001-11-02 10:40:01 +03:00
|
|
|
nsAutoString name;
|
2017-09-28 07:03:58 +03:00
|
|
|
GetHTMLAttr(nsGkAtoms::name, name);
|
2010-02-25 08:57:54 +03:00
|
|
|
if (name.IsEmpty()) {
|
2005-10-28 15:25:24 +04:00
|
|
|
return NS_OK;
|
2002-02-16 04:19:24 +03:00
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
//
|
|
|
|
// Get the value
|
|
|
|
//
|
2001-11-02 10:40:01 +03:00
|
|
|
nsAutoString value;
|
2017-09-28 07:03:58 +03:00
|
|
|
GetHTMLAttr(nsGkAtoms::value, value);
|
2001-11-02 10:40:01 +03:00
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
//
|
|
|
|
// Submit
|
|
|
|
//
|
2011-11-16 11:50:19 +04:00
|
|
|
return aFormSubmission->AddNameValuePair(name, value);
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
2006-11-28 06:17:03 +03:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
void HTMLButtonElement::DoneCreatingElement() {
|
2011-06-01 01:57:16 +04:00
|
|
|
if (!mInhibitStateRestoration) {
|
2019-06-29 02:39:01 +03:00
|
|
|
nsresult rv = GenerateStateKey();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
RestoreFormControlState();
|
|
|
|
}
|
2011-06-01 01:57:16 +04:00
|
|
|
}
|
2006-11-28 06:17:03 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult HTMLButtonElement::BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-03-16 21:50:41 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
2013-02-08 16:50:30 +04:00
|
|
|
bool aNotify) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aNotify && aName == nsGkAtoms::disabled &&
|
2006-11-28 06:17:03 +03:00
|
|
|
aNameSpaceID == kNameSpaceID_None) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisabledChanged = true;
|
2006-11-28 06:17:03 +03:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:21:31 +04:00
|
|
|
return nsGenericHTMLFormElementWithState::BeforeSetAttr(aNameSpaceID, aName,
|
|
|
|
aValue, aNotify);
|
2006-11-28 06:17:03 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult HTMLButtonElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
bool aNotify) {
|
2010-09-10 09:08:56 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aName == nsGkAtoms::type) {
|
2017-04-20 07:35:19 +03:00
|
|
|
if (aValue) {
|
|
|
|
mType = aValue->GetEnumValue();
|
|
|
|
} else {
|
2010-09-10 09:08:56 +04:00
|
|
|
mType = kButtonDefaultType->value;
|
|
|
|
}
|
2014-04-29 20:58:00 +04:00
|
|
|
}
|
2010-09-10 09:08:56 +04:00
|
|
|
|
2014-04-29 20:58:00 +04:00
|
|
|
if (aName == nsGkAtoms::type || aName == nsGkAtoms::disabled) {
|
Bug 1375599 - Change IsDisabled() to look at NS_EVENT_STATE_DISABLED instead of the "disabled" attribute. r=bz
In order to speed up IsDisabled(), instead of querying for the @disabled
attribute, we're now using the NS_EVENT_STATE_DISABLED flag to know whether an
element is disabled.
It is safe to use the NS_EVENT_STATE_DISABLED flag for the following reasons:
- For form elements, nsGenericHTMLFormElement::IsDisabled() is only called on
form elements that can be disabled; form elements that can't be disabled
overrides IsDisabled() to return false directly.
And, before this patch, NS_EVENT_STATE_DISABLED flag is set by
nsGenericHTMLFormElement::IntrinsicState() if and only if IsDisabled() in all
cases when CanBeDisabled() is true, and when CanBeDisabled() is false then
IsDisabled() is always false and the flag is not set.
- For non form elements, optgroup and option have the flag matching
IsDisabled(). Note that option's IsDisabled() should also refer to optgroup's
(if it exists) disabled state, which was not done before this patch.
For this to work correctly, we need to set NS_EVENT_STATE_DISABLED earlier,
that is, in AfterSetAttr(), before any consumer of IsDisabled().
We also need to update the flag whenever the element's parent (e.g. fieldset or
optgroup) disabled state changes and when moving into/out of a parent
container.
Note that NS_EVENT_STATE_DISABLED/ENABLED is now part of the
EXTERNALLY_MANAGED_STATES.
MozReview-Commit-ID: KSceikeqvvU
2017-07-20 09:15:00 +03:00
|
|
|
if (aName == nsGkAtoms::disabled) {
|
|
|
|
// This *has* to be called *before* validity state check because
|
|
|
|
// UpdateBarredFromConstraintValidation depends on our disabled state.
|
|
|
|
UpdateDisabledState(aNotify);
|
|
|
|
}
|
|
|
|
|
2014-04-29 20:58:00 +04:00
|
|
|
UpdateBarredFromConstraintValidation();
|
2010-08-21 21:52:57 +04:00
|
|
|
}
|
2010-04-15 15:03:00 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:21:31 +04:00
|
|
|
return nsGenericHTMLFormElementWithState::AfterSetAttr(
|
2017-10-10 00:33:38 +03:00
|
|
|
aNameSpaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
|
2010-04-15 15:03:00 +04:00
|
|
|
}
|
|
|
|
|
2006-11-28 06:17:03 +03:00
|
|
|
NS_IMETHODIMP
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::SaveState() {
|
2006-11-28 06:17:03 +03:00
|
|
|
if (!mDisabledChanged) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-03-02 21:18:35 +03:00
|
|
|
PresState* state = GetPrimaryPresState();
|
2006-11-28 06:17:03 +03:00
|
|
|
if (state) {
|
2010-09-19 01:33:16 +04:00
|
|
|
// We do not want to save the real disabled state but the disabled
|
|
|
|
// attribute.
|
2018-03-02 21:18:35 +03:00
|
|
|
state->disabled() = HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
|
|
|
|
state->disabledSet() = true;
|
2006-11-28 06:17:03 +03:00
|
|
|
}
|
|
|
|
|
2013-07-24 11:38:13 +04:00
|
|
|
return NS_OK;
|
2006-11-28 06:17:03 +03:00
|
|
|
}
|
|
|
|
|
2018-03-02 21:18:35 +03:00
|
|
|
bool HTMLButtonElement::RestoreState(PresState* aState) {
|
|
|
|
if (aState && aState->disabledSet() && !aState->disabled()) {
|
2018-02-01 22:21:14 +03:00
|
|
|
SetDisabled(false, IgnoreErrors());
|
2007-10-10 07:39:16 +04:00
|
|
|
}
|
2006-11-28 06:17:03 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-11-28 06:17:03 +03:00
|
|
|
}
|
2010-08-18 22:28:08 +04:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
EventStates HTMLButtonElement::IntrinsicState() const {
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsGenericHTMLFormElementWithState::IntrinsicState();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2014-04-29 20:58:00 +04:00
|
|
|
if (IsCandidateForConstraintValidation()) {
|
|
|
|
if (IsValid()) {
|
|
|
|
state |= NS_EVENT_STATE_VALID;
|
|
|
|
if (!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) {
|
|
|
|
state |= NS_EVENT_STATE_MOZ_UI_VALID;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
state |= NS_EVENT_STATE_INVALID;
|
|
|
|
if (!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) {
|
|
|
|
state |= NS_EVENT_STATE_MOZ_UI_INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-21 21:52:57 +04:00
|
|
|
|
2010-09-10 09:08:56 +04:00
|
|
|
if (mForm && !mForm->GetValidity() && IsSubmitControl()) {
|
|
|
|
state |= NS_EVENT_STATE_MOZ_SUBMITINVALID;
|
|
|
|
}
|
|
|
|
|
2010-10-08 01:09:31 +04:00
|
|
|
return state;
|
2010-08-19 04:03:20 +04:00
|
|
|
}
|
2013-02-08 16:50:30 +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
|
|
|
JSObject* HTMLButtonElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLButtonElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-08 16:50:30 +04:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|