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"
|
1998-10-14 01:31:26 +04:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2003-01-09 09:49:07 +03:00
|
|
|
#include "nsIPresShell.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"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIDOMEvent.h"
|
2000-09-08 05:46:00 +04:00
|
|
|
#include "nsIDocument.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"
|
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"
|
2006-11-28 06:17:03 +03:00
|
|
|
#include "nsPresState.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
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLButtonElement::HTMLButtonElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
|
2013-02-08 16:50:30 +04:00
|
|
|
FromParser aFromParser)
|
2017-04-01 05:49:00 +03:00
|
|
|
: nsGenericHTMLFormElementWithState(aNodeInfo, 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))
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
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
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLButtonElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLButtonElement, Element)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
// QueryInterface implementation for HTMLButtonElement
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLButtonElement)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(HTMLButtonElement,
|
|
|
|
nsIDOMHTMLButtonElement,
|
|
|
|
nsIConstraintValidation)
|
2013-08-08 00:23:08 +04:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLFormElementWithState)
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
// nsIConstraintValidation
|
2014-04-29 20:58:00 +04:00
|
|
|
NS_IMPL_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY(HTMLButtonElement)
|
2010-08-18 22:28:08 +04:00
|
|
|
|
2014-04-29 20:58:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLButtonElement::SetCustomValidity(const nsAString& aError)
|
|
|
|
{
|
|
|
|
nsIConstraintValidation::SetCustomValidity(aError);
|
|
|
|
|
|
|
|
UpdateState(true);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
UpdateBarredFromConstraintValidation();
|
|
|
|
|
|
|
|
nsGenericHTMLFormElementWithState::FieldSetDisabledChanged(aNotify);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMHTMLButtonElement
|
1999-07-28 09:26:55 +04:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLButtonElement)
|
1999-07-28 09:26:55 +04:00
|
|
|
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2002-08-07 03:50:08 +04:00
|
|
|
// nsIDOMHTMLButtonElement
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1998-09-03 05:03:33 +04:00
|
|
|
NS_IMETHODIMP
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2013-08-02 05:21:31 +04:00
|
|
|
return nsGenericHTMLFormElementWithState::GetForm(aForm);
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
NS_IMPL_BOOL_ATTR(HTMLButtonElement, Autofocus, autofocus)
|
|
|
|
NS_IMPL_BOOL_ATTR(HTMLButtonElement, Disabled, disabled)
|
|
|
|
NS_IMPL_ACTION_ATTR(HTMLButtonElement, FormAction, formaction)
|
2013-02-13 19:35:35 +04:00
|
|
|
NS_IMPL_ENUM_ATTR_DEFAULT_MISSING_INVALID_VALUES(HTMLButtonElement, FormEnctype, formenctype,
|
|
|
|
"", kFormDefaultEnctype->tag)
|
|
|
|
NS_IMPL_ENUM_ATTR_DEFAULT_MISSING_INVALID_VALUES(HTMLButtonElement, FormMethod, formmethod,
|
|
|
|
"", kFormDefaultMethod->tag)
|
2013-02-08 16:50:30 +04:00
|
|
|
NS_IMPL_BOOL_ATTR(HTMLButtonElement, FormNoValidate, formnovalidate)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLButtonElement, FormTarget, formtarget)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLButtonElement, Name, name)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLButtonElement, Value, value)
|
|
|
|
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(HTMLButtonElement, Type, type,
|
2010-04-15 15:03:00 +04:00
|
|
|
kButtonDefaultType->tag)
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2012-10-06 11:19:51 +04:00
|
|
|
int32_t
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::TabIndexDefault()
|
2012-10-06 11:19:51 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex)
|
2004-07-25 01:12:43 +04:00
|
|
|
{
|
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
|
|
|
|
|
|
|
*aIsFocusable =
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2010-08-20 21:47:30 +04:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::type) {
|
|
|
|
// XXX ARG!! This is major evilness. ParseAttribute
|
|
|
|
// shouldn't set members. Override SetAttr instead
|
2011-09-29 10:19:26 +04:00
|
|
|
bool success = aResult.ParseEnumValue(aValue, kButtonTypeTable, false);
|
2010-08-20 21:47:30 +04:00
|
|
|
if (success) {
|
|
|
|
mType = aResult.GetEnumValue();
|
|
|
|
} else {
|
|
|
|
mType = kButtonDefaultType->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
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,
|
|
|
|
aResult);
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 19:17:36 +04:00
|
|
|
bool
|
2015-08-26 15:56:59 +03:00
|
|
|
HTMLButtonElement::IsDisabledForEvents(EventMessage aMessage)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
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);
|
2013-01-03 19:17:36 +04:00
|
|
|
return IsElementDisabledForEvents(aMessage, formFrame);
|
|
|
|
}
|
2001-04-13 04:39:52 +04:00
|
|
|
|
2013-01-03 19:17:36 +04:00
|
|
|
nsresult
|
2016-10-21 05:11:07 +03:00
|
|
|
HTMLButtonElement::GetEventTargetParent(EventChainPreVisitor& aVisitor)
|
2013-01-03 19:17:36 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
aVisitor.mCanHandle = false;
|
2015-08-22 04:34:51 +03:00
|
|
|
if (IsDisabledForEvents(aVisitor.mEvent->mMessage)) {
|
2011-07-19 03:16:44 +04:00
|
|
|
return NS_OK;
|
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();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outerActivateEvent =
|
2013-10-28 13:03:19 +04:00
|
|
|
((mouseEvent && mouseEvent->IsLeftClickEvent()) ||
|
2015-09-02 09:08:01 +03:00
|
|
|
(aVisitor.mEvent->mMessage == eLegacyDOMActivate &&
|
2007-08-17 01:10:29 +04:00
|
|
|
!mInInternalActivate));
|
|
|
|
|
|
|
|
if (outerActivateEvent) {
|
|
|
|
aVisitor.mItemFlags |= NS_OUTER_ACTIVATE_EVENT;
|
|
|
|
if (mType == NS_FORM_BUTTON_SUBMIT && mForm) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-10-21 05:11:07 +03:00
|
|
|
return nsGenericHTMLElement::GetEventTargetParent(aVisitor);
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
nsresult
|
2014-03-18 08:48:20 +04:00
|
|
|
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
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell = aVisitor.mPresContext->GetPresShell();
|
|
|
|
if (shell) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
mInInternalActivate = true;
|
|
|
|
shell->HandleDOMEventWithTarget(this, &actEvent, &status);
|
|
|
|
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;
|
2002-03-10 04:09:14 +03:00
|
|
|
}
|
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(true,
|
2015-09-02 09:08:00 +03:00
|
|
|
(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;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell =
|
|
|
|
aVisitor.mPresContext->GetPresShell();
|
|
|
|
// If |nsIPresShell::Destroy| has been called due to
|
|
|
|
// 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
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
nsresult
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2011-06-01 05:46:57 +04:00
|
|
|
{
|
2013-08-02 05:21:31 +04:00
|
|
|
nsresult rv =
|
|
|
|
nsGenericHTMLFormElementWithState::BindToTree(aDocument, aParent, aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2011-06-01 05:46:57 +04:00
|
|
|
{
|
2013-08-02 05:21:31 +04:00
|
|
|
nsGenericHTMLFormElementWithState::UnbindFromTree(aDeep, 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()
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-16 10:24:16 +03:00
|
|
|
HTMLButtonElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission)
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
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;
|
2010-02-25 08:57:54 +03:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::name, name);
|
|
|
|
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;
|
2011-11-16 11:50:19 +04:00
|
|
|
nsresult rv = GetValue(value);
|
2002-02-16 04:19:24 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
void
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::DoneCreatingElement()
|
2006-11-28 06:17:03 +03:00
|
|
|
{
|
2011-06-01 01:57:16 +04:00
|
|
|
if (!mInhibitStateRestoration) {
|
2013-08-02 05:21:31 +04: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
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2017-03-16 21:50:41 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
2013-02-08 16:50:30 +04:00
|
|
|
bool aNotify)
|
2006-11-28 06:17:03 +03:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2010-04-15 15:03:00 +04:00
|
|
|
nsresult
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
2010-04-15 15:03:00 +04:00
|
|
|
{
|
2010-09-10 09:08:56 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aName == nsGkAtoms::type) {
|
|
|
|
if (!aValue) {
|
|
|
|
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) {
|
|
|
|
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(aNameSpaceID, aName,
|
|
|
|
aValue, 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;
|
|
|
|
}
|
|
|
|
|
2013-07-24 11:38:13 +04:00
|
|
|
nsPresState* 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.
|
|
|
|
state->SetDisabled(HasAttr(kNameSpaceID_None, nsGkAtoms::disabled));
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::RestoreState(nsPresState* aState)
|
2006-11-28 06:17:03 +03:00
|
|
|
{
|
2016-12-30 09:26:35 +03:00
|
|
|
if (aState && aState->IsDisabledSet() && !aState->GetDisabled()) {
|
|
|
|
SetDisabled(false);
|
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
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2013-02-08 16:50:30 +04:00
|
|
|
HTMLButtonElement::IntrinsicState() const
|
2010-08-19 04:03:20 +04:00
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsGenericHTMLFormElementWithState::IntrinsicState();
|
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
|
|
|
|
2013-02-08 16:50:30 +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
|
|
|
HTMLButtonElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
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
|
|
|
return HTMLButtonElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-08 16:50:30 +04:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|