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/. */
|
2011-06-11 11:52:24 +04:00
|
|
|
|
2013-02-19 01:18:40 +04:00
|
|
|
#include "mozilla/dom/HTMLTextAreaElement.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
|
|
|
|
#include "mozAutoDocUpdate.h"
|
2014-03-17 10:56:54 +04:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2016-06-16 10:24:16 +03:00
|
|
|
#include "mozilla/dom/HTMLFormSubmission.h"
|
2013-02-19 09:54:23 +04:00
|
|
|
#include "mozilla/dom/HTMLTextAreaElementBinding.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2017-01-27 03:51:01 +03:00
|
|
|
#include "mozilla/GenericSpecifiedValuesInlines.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2001-02-22 06:01:34 +03:00
|
|
|
#include "nsContentCID.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsFocusManager.h"
|
1999-11-19 11:30:02 +03:00
|
|
|
#include "nsIComponentManager.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
#include "nsIConstraintValidation.h"
|
|
|
|
#include "nsIControllers.h"
|
|
|
|
#include "nsIDocument.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
#include "nsIFormControlFrame.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIForm.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2002-07-27 00:57:24 +04:00
|
|
|
#include "nsITextControlFrame.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
1999-12-02 02:05:58 +03:00
|
|
|
#include "nsLinebreakConverter.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
#include "nsMappedAttributes.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsPresContext.h"
|
2005-01-28 01:52:53 +03:00
|
|
|
#include "nsPresState.h"
|
2001-12-23 19:06:13 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2010-04-22 00:17:41 +04:00
|
|
|
#include "nsTextEditorState.h"
|
2013-09-23 03:23:30 +04:00
|
|
|
#include "nsIController.h"
|
2010-04-22 00:17:41 +04:00
|
|
|
|
1999-11-19 10:24:15 +03:00
|
|
|
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
#define NS_NO_CONTENT_DISPATCH (1 << 0)
|
2000-09-09 09:46:14 +04:00
|
|
|
|
2004-06-02 04:25:00 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(TextArea)
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2013-02-19 01:18:40 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLTextAreaElement::HTMLTextAreaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
|
2013-02-19 01:18:40 +04:00
|
|
|
FromParser aFromParser)
|
2017-04-01 05:49:00 +03:00
|
|
|
: nsGenericHTMLFormElementWithState(aNodeInfo, NS_FORM_TEXTAREA),
|
2011-10-17 18:59:28 +04:00
|
|
|
mValueChanged(false),
|
2016-08-06 18:59:08 +03:00
|
|
|
mLastValueChangeWasInteractive(false),
|
2011-10-17 18:59:28 +04:00
|
|
|
mHandlingSelect(false),
|
2006-11-28 06:17:03 +03:00
|
|
|
mDoneAddingChildren(!aFromParser),
|
2010-10-25 16:17:38 +04:00
|
|
|
mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT)),
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisabledChanged(false),
|
|
|
|
mCanShowInvalidUI(true),
|
|
|
|
mCanShowValidUI(true),
|
2017-03-22 11:55:56 +03:00
|
|
|
mIsPreviewEnabled(false),
|
2015-01-07 08:39:46 +03:00
|
|
|
mState(this)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2007-01-30 08:48:22 +03:00
|
|
|
AddMutationObserver(this);
|
2011-06-01 05:46:57 +04:00
|
|
|
|
|
|
|
// Set up our default state. By default we're enabled (since we're
|
|
|
|
// a control type that can be disabled but not actually disabled
|
|
|
|
// right now), optional, and valid. We are NOT readwrite by default
|
|
|
|
// until someone calls UpdateEditableState on us, apparently! Also
|
|
|
|
// by default we don't have to show validity UI and so forth.
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_ENABLED |
|
|
|
|
NS_EVENT_STATE_OPTIONAL |
|
|
|
|
NS_EVENT_STATE_VALID);
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLTextAreaElement,
|
|
|
|
nsGenericHTMLFormElementWithState,
|
|
|
|
mValidity,
|
|
|
|
mControllers,
|
|
|
|
mState)
|
2007-03-08 14:17:16 +03:00
|
|
|
|
2013-02-19 01:18:40 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLTextAreaElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLTextAreaElement, 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-19 01:18:40 +04:00
|
|
|
// QueryInterface implementation for HTMLTextAreaElement
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLTextAreaElement)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(HTMLTextAreaElement,
|
|
|
|
nsIDOMHTMLTextAreaElement,
|
|
|
|
nsITextControlElement,
|
|
|
|
nsIDOMNSEditableElement,
|
|
|
|
nsIMutationObserver,
|
|
|
|
nsIConstraintValidation)
|
2013-08-08 00:23:08 +04:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLFormElementWithState)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1998-09-03 05:03:33 +04:00
|
|
|
|
1998-09-23 21:16:51 +04:00
|
|
|
// nsIDOMHTMLTextAreaElement
|
|
|
|
|
2016-09-15 20:52:37 +03:00
|
|
|
nsresult
|
2017-04-20 22:57:48 +03:00
|
|
|
HTMLTextAreaElement::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
|
|
|
|
bool aPreallocateChildren) const
|
2016-09-15 20:52:37 +03:00
|
|
|
{
|
|
|
|
*aResult = nullptr;
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo> ni =
|
|
|
|
RefPtr<mozilla::dom::NodeInfo>(aNodeInfo).forget();
|
|
|
|
RefPtr<HTMLTextAreaElement> it = new HTMLTextAreaElement(ni);
|
|
|
|
|
2017-04-20 22:57:48 +03:00
|
|
|
nsresult rv = const_cast<HTMLTextAreaElement*>(this)->CopyInnerTo(it, aPreallocateChildren);
|
2016-09-15 20:52:37 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (mValueChanged) {
|
|
|
|
// Set our value on the clone.
|
|
|
|
nsAutoString value;
|
|
|
|
GetValueInternal(value, true);
|
|
|
|
|
|
|
|
// SetValueInternal handles setting mValueChanged for us
|
|
|
|
rv = it->SetValueInternal(value, nsTextEditorState::eSetValue_Notify);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
it->mLastValueChangeWasInteractive = mLastValueChangeWasInteractive;
|
|
|
|
it.forget(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-28 09:26:55 +04:00
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
// nsIConstraintValidation
|
2013-02-19 01:18:40 +04:00
|
|
|
NS_IMPL_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY(HTMLTextAreaElement)
|
2010-08-18 22:28:08 +04:00
|
|
|
|
1999-07-28 09:26:55 +04:00
|
|
|
|
1998-09-03 05:03:33 +04:00
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::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
|
|
|
// nsIContent
|
|
|
|
|
1998-09-03 05:03:33 +04:00
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::Select()
|
2000-05-30 06:45:55 +04:00
|
|
|
{
|
2008-10-07 22:53:23 +04:00
|
|
|
// XXX Bug? We have to give the input focus before contents can be
|
|
|
|
// selected
|
2000-05-30 06:45:55 +04:00
|
|
|
|
2008-10-07 22:53:23 +04:00
|
|
|
FocusTristate state = FocusState();
|
|
|
|
if (state == eUnfocusable) {
|
|
|
|
return NS_OK;
|
2006-07-13 13:14:56 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPresContext> presContext = GetPresContext(eForComposedDoc);
|
2008-10-07 22:53:23 +04:00
|
|
|
if (state == eInactiveWindow) {
|
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
|
|
|
if (fm)
|
|
|
|
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
|
2008-10-07 22:53:23 +04:00
|
|
|
SelectAll(presContext);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-09-09 05:22:01 +04:00
|
|
|
|
2000-09-08 05:46:00 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-02 09:08:00 +03:00
|
|
|
WidgetGUIEvent event(true, eFormSelect, nullptr);
|
2013-03-28 23:41:32 +04:00
|
|
|
// XXXbz HTMLInputElement guards against this reentering; shouldn't we?
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext,
|
|
|
|
&event, nullptr, &status);
|
2000-05-30 06:45:55 +04:00
|
|
|
|
2000-12-23 13:56:31 +03:00
|
|
|
// If the DOM event was not canceled (e.g. by a JS event handler
|
|
|
|
// returning false)
|
2000-09-09 05:22:01 +04:00
|
|
|
if (status == nsEventStatus_eIgnore) {
|
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
|
|
|
if (fm) {
|
|
|
|
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
|
|
|
|
|
|
|
|
// ensure that the element is actually focused
|
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
|
|
|
fm->GetFocusedElement(getter_AddRefs(focusedElement));
|
|
|
|
if (SameCOMIdentity(static_cast<nsIDOMNode*>(this), focusedElement)) {
|
|
|
|
// Now Select all the text!
|
|
|
|
SelectAll(presContext);
|
2004-11-04 04:32:40 +03:00
|
|
|
}
|
2000-09-09 05:22:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
return NS_OK;
|
2000-05-30 06:45:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::SelectAll(nsPresContext* aPresContext)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFormControlFrame* formControlFrame = GetFormControlFrame(true);
|
2000-12-23 13:56:31 +03:00
|
|
|
|
|
|
|
if (formControlFrame) {
|
2006-12-26 20:47:52 +03:00
|
|
|
formControlFrame->SetFormProperty(nsGkAtoms::select, EmptyString());
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
return NS_OK;
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsHTMLFocusable(bool aWithMouse,
|
|
|
|
bool *aIsFocusable, int32_t *aTabIndex)
|
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
|
|
|
{
|
2013-08-02 05:21:31 +04:00
|
|
|
if (nsGenericHTMLFormElementWithState::IsHTMLFocusable(aWithMouse, aIsFocusable,
|
|
|
|
aTabIndex))
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// disabled textareas are not focusable
|
2010-09-19 01:33:16 +04:00
|
|
|
*aIsFocusable = !IsDisabled();
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
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
|
|
|
}
|
|
|
|
|
2013-02-19 01:18:40 +04:00
|
|
|
NS_IMPL_BOOL_ATTR(HTMLTextAreaElement, Autofocus, autofocus)
|
|
|
|
NS_IMPL_UINT_ATTR_NON_ZERO_DEFAULT_VALUE(HTMLTextAreaElement, Cols, cols, DEFAULT_COLS)
|
|
|
|
NS_IMPL_BOOL_ATTR(HTMLTextAreaElement, Disabled, disabled)
|
|
|
|
NS_IMPL_NON_NEGATIVE_INT_ATTR(HTMLTextAreaElement, MaxLength, maxlength)
|
2016-08-17 07:11:24 +03:00
|
|
|
NS_IMPL_NON_NEGATIVE_INT_ATTR(HTMLTextAreaElement, MinLength, minlength)
|
2013-02-19 01:18:40 +04:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLTextAreaElement, Name, name)
|
|
|
|
NS_IMPL_BOOL_ATTR(HTMLTextAreaElement, ReadOnly, readonly)
|
|
|
|
NS_IMPL_BOOL_ATTR(HTMLTextAreaElement, Required, required)
|
|
|
|
NS_IMPL_UINT_ATTR_NON_ZERO_DEFAULT_VALUE(HTMLTextAreaElement, Rows, rows, DEFAULT_ROWS_TEXTAREA)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLTextAreaElement, Wrap, wrap)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLTextAreaElement, Placeholder, placeholder)
|
1998-10-20 21:07:23 +04:00
|
|
|
|
2012-10-06 11:19:51 +04:00
|
|
|
int32_t
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::TabIndexDefault()
|
2012-10-06 11:19:51 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
1998-10-20 21:07:23 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetType(nsAString& aType)
|
1998-10-20 21:07:23 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aType.AssignLiteral("textarea");
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1998-10-20 21:07:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetValue(nsAString& aValue)
|
1998-10-20 21:07:23 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
GetValueInternal(aValue, true);
|
2002-05-16 22:26:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetValueInternal(nsAString& aValue, bool aIgnoreWrap) const
|
2002-05-16 22:26:05 +04:00
|
|
|
{
|
2012-04-24 08:19:26 +04:00
|
|
|
mState.GetValue(aValue, aIgnoreWrap);
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsIEditor*)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetTextEditor()
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2013-02-19 09:54:23 +04:00
|
|
|
return GetEditor();
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsISelectionController*)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetSelectionController()
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2012-04-24 08:19:26 +04:00
|
|
|
return mState.GetSelectionController();
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsFrameSelection*)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetConstFrameSelection()
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2012-04-24 08:19:26 +04:00
|
|
|
return mState.GetConstFrameSelection();
|
1998-10-20 21:07:23 +04:00
|
|
|
}
|
|
|
|
|
2002-12-09 09:15:33 +03:00
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::BindToFrame(nsTextControlFrame* aFrame)
|
2002-12-17 02:49:16 +03:00
|
|
|
{
|
2012-04-24 08:19:26 +04:00
|
|
|
return mState.BindToFrame(aFrame);
|
2002-12-17 02:49:16 +03:00
|
|
|
}
|
|
|
|
|
2010-04-22 00:17:41 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::UnbindFromFrame(nsTextControlFrame* aFrame)
|
2001-11-19 13:35:52 +03:00
|
|
|
{
|
2010-07-22 04:59:25 +04:00
|
|
|
if (aFrame) {
|
2012-04-24 08:19:26 +04:00
|
|
|
mState.UnbindFromFrame(aFrame);
|
2010-07-22 04:59:25 +04:00
|
|
|
}
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
2001-11-19 13:35:52 +03:00
|
|
|
|
2010-04-22 00:17:41 +04:00
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::CreateEditor()
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2012-04-24 08:19:26 +04:00
|
|
|
return mState.PrepareEditor();
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
2001-11-16 05:38:10 +03:00
|
|
|
|
2017-02-28 20:41:37 +03:00
|
|
|
NS_IMETHODIMP_(Element*)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetRootEditorNode()
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2012-04-24 08:19:26 +04:00
|
|
|
return mState.GetRootNode();
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-12-03 18:40:12 +04:00
|
|
|
NS_IMETHODIMP_(Element*)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::CreatePlaceholderNode()
|
2010-10-19 17:11:07 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_SUCCESS(mState.CreatePlaceholderNode(), nullptr);
|
2012-04-24 08:19:26 +04:00
|
|
|
return mState.GetPlaceholderNode();
|
2010-10-19 17:11:07 +04:00
|
|
|
}
|
|
|
|
|
2013-12-03 18:40:12 +04:00
|
|
|
NS_IMETHODIMP_(Element*)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetPlaceholderNode()
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2012-04-24 08:19:26 +04:00
|
|
|
return mState.GetPlaceholderNode();
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
2017-03-30 12:38:59 +03:00
|
|
|
HTMLTextAreaElement::UpdateOverlayTextVisibility(bool aNotify)
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2017-03-30 12:38:59 +03:00
|
|
|
mState.UpdateOverlayTextVisibility(aNotify);
|
2012-11-09 14:22:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetPlaceholderVisibility()
|
2012-11-09 14:22:29 +04:00
|
|
|
{
|
|
|
|
return mState.GetPlaceholderVisibility();
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
2017-03-20 06:53:40 +03:00
|
|
|
NS_IMETHODIMP_(Element*)
|
|
|
|
HTMLTextAreaElement::CreatePreviewNode()
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mState.CreatePreviewNode(), nullptr);
|
|
|
|
return mState.GetPreviewNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(Element*)
|
|
|
|
HTMLTextAreaElement::GetPreviewNode()
|
|
|
|
{
|
|
|
|
return mState.GetPreviewNode();
|
|
|
|
}
|
|
|
|
|
2017-03-20 19:08:01 +03:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
HTMLTextAreaElement::SetPreviewValue(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
mState.SetPreviewText(aValue, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
HTMLTextAreaElement::GetPreviewValue(nsAString& aValue)
|
|
|
|
{
|
|
|
|
mState.GetPreviewText(aValue);
|
|
|
|
}
|
2017-03-20 06:53:40 +03:00
|
|
|
|
2017-03-22 11:55:56 +03:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
HTMLTextAreaElement::EnablePreview()
|
|
|
|
{
|
|
|
|
if (mIsPreviewEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mIsPreviewEnabled = true;
|
|
|
|
// Reconstruct the frame to append an anonymous preview node
|
|
|
|
nsLayoutUtils::PostRestyleEvent(this, nsRestyleHint(0), nsChangeHint_ReconstructFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
HTMLTextAreaElement::IsPreviewEnabled()
|
|
|
|
{
|
|
|
|
return mIsPreviewEnabled;
|
|
|
|
}
|
|
|
|
|
2017-03-30 12:38:59 +03:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
HTMLTextAreaElement::GetPreviewVisibility()
|
|
|
|
{
|
|
|
|
return mState.GetPreviewVisibility();
|
|
|
|
}
|
|
|
|
|
2010-04-22 00:17:41 +04:00
|
|
|
nsresult
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::SetValueInternal(const nsAString& aValue,
|
2015-06-18 17:56:20 +03:00
|
|
|
uint32_t aFlags)
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2017-03-09 22:44:04 +03:00
|
|
|
// Need to set the value changed flag here if our value has in fact changed
|
|
|
|
// (i.e. if eSetValue_Notify is in aFlags), so that
|
|
|
|
// nsTextControlFrame::UpdateValueDisplay retrieves the correct value if
|
|
|
|
// needed.
|
|
|
|
if (aFlags & nsTextEditorState::eSetValue_Notify) {
|
|
|
|
SetValueChanged(true);
|
|
|
|
}
|
|
|
|
|
2015-06-18 17:56:20 +03:00
|
|
|
if (!mState.SetValue(aValue, aFlags)) {
|
2015-01-08 04:14:01 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1999-02-01 21:44:59 +03:00
|
|
|
return NS_OK;
|
1998-10-20 21:07:23 +04:00
|
|
|
}
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2001-12-11 08:39:36 +03:00
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::SetValue(const nsAString& aValue)
|
2001-12-11 08:39:36 +03:00
|
|
|
{
|
2012-09-05 16:40:13 +04:00
|
|
|
// If the value has been set by a script, we basically want to keep the
|
|
|
|
// current change event state. If the element is ready to fire a change
|
|
|
|
// event, we should keep it that way. Otherwise, we should make sure the
|
|
|
|
// element will not fire any event because of the script interaction.
|
|
|
|
//
|
|
|
|
// NOTE: this is currently quite expensive work (too much string
|
|
|
|
// manipulation). We should probably optimize that.
|
|
|
|
nsAutoString currentValue;
|
|
|
|
GetValueInternal(currentValue, true);
|
|
|
|
|
2015-06-18 17:56:20 +03:00
|
|
|
nsresult rv =
|
2017-03-09 22:44:04 +03:00
|
|
|
SetValueInternal(aValue, nsTextEditorState::eSetValue_ByContent |
|
2017-03-09 22:44:04 +03:00
|
|
|
nsTextEditorState::eSetValue_Notify |
|
|
|
|
nsTextEditorState::eSetValue_MoveCursorToEnd);
|
2015-01-08 04:14:01 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-09-05 16:40:13 +04:00
|
|
|
|
|
|
|
if (mFocusedValue.Equals(currentValue)) {
|
|
|
|
GetValueInternal(mFocusedValue, true);
|
|
|
|
}
|
|
|
|
|
2012-05-07 20:27:24 +04:00
|
|
|
return NS_OK;
|
2001-12-11 08:39:36 +03:00
|
|
|
}
|
|
|
|
|
2007-10-02 20:56:07 +04:00
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::SetUserInput(const nsAString& aValue)
|
2007-10-02 20:56:07 +04:00
|
|
|
{
|
2017-03-09 22:44:04 +03:00
|
|
|
return SetValueInternal(aValue,
|
|
|
|
nsTextEditorState::eSetValue_BySetUserInput |
|
2017-03-09 22:44:04 +03:00
|
|
|
nsTextEditorState::eSetValue_Notify|
|
|
|
|
nsTextEditorState::eSetValue_MoveCursorToEnd);
|
2007-10-02 20:56:07 +04:00
|
|
|
}
|
2001-11-05 09:50:21 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::SetValueChanged(bool aValueChanged)
|
2001-11-05 09:50:21 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool previousValue = mValueChanged;
|
2010-11-24 02:46:49 +03:00
|
|
|
|
2001-12-23 19:06:13 +03:00
|
|
|
mValueChanged = aValueChanged;
|
2013-03-25 23:35:55 +04:00
|
|
|
if (!aValueChanged && !mState.IsEmpty()) {
|
|
|
|
mState.EmptyValue();
|
|
|
|
}
|
2010-08-25 08:39:10 +04:00
|
|
|
|
2010-11-24 02:49:50 +03:00
|
|
|
if (mValueChanged != previousValue) {
|
2011-06-01 05:46:57 +04:00
|
|
|
UpdateState(true);
|
2010-08-25 08:39:10 +04:00
|
|
|
}
|
|
|
|
|
2001-11-05 09:50:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-20 00:37:40 +04:00
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetDefaultValue(nsAString& aDefaultValue)
|
1998-10-20 00:37:40 +04:00
|
|
|
{
|
2015-05-22 21:16:20 +03:00
|
|
|
if (!nsContentUtils::GetNodeTextContent(this, false, aDefaultValue, fallible)) {
|
2014-03-20 23:51:16 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2004-07-07 02:52:03 +04:00
|
|
|
return NS_OK;
|
1998-10-20 00:37:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::SetDefaultValue(const nsAString& aDefaultValue)
|
2013-02-19 09:54:23 +04:00
|
|
|
{
|
|
|
|
ErrorResult error;
|
|
|
|
SetDefaultValue(aDefaultValue, error);
|
2015-04-27 16:18:51 +03:00
|
|
|
return error.StealNSResult();
|
2013-02-19 09:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetDefaultValue(const nsAString& aDefaultValue, ErrorResult& aError)
|
1998-10-20 00:37:40 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsresult rv = nsContentUtils::SetNodeTextContent(this, aDefaultValue, true);
|
2005-06-02 06:30:09 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && !mValueChanged) {
|
|
|
|
Reset();
|
|
|
|
}
|
2013-02-19 09:54:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
2001-12-23 19:06:13 +03:00
|
|
|
}
|
1999-12-02 02:05:58 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2005-11-29 19:37:15 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2016-08-17 07:11:24 +03:00
|
|
|
if (aAttribute == nsGkAtoms::maxlength ||
|
|
|
|
aAttribute == nsGkAtoms::minlength) {
|
2010-03-05 22:38:26 +03:00
|
|
|
return aResult.ParseNonNegativeIntValue(aValue);
|
2016-08-21 18:09:20 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::cols) {
|
|
|
|
aResult.ParseIntWithFallback(aValue, DEFAULT_COLS);
|
|
|
|
return true;
|
|
|
|
} else if (aAttribute == nsGkAtoms::rows) {
|
|
|
|
aResult.ParseIntWithFallback(aValue, DEFAULT_ROWS_TEXTAREA);
|
|
|
|
return true;
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
1998-09-23 21:16:51 +04: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-11-19 23:21:29 +04:00
|
|
|
void
|
|
|
|
HTMLTextAreaElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Text))) {
|
2014-10-28 20:33:15 +03:00
|
|
|
// wrap=off
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_white_space)) {
|
2014-10-28 20:33:15 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::wrap);
|
|
|
|
if (value && value->Type() == nsAttrValue::eString &&
|
|
|
|
value->Equals(nsGkAtoms::OFF, eIgnoreCase)) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValue(eCSSProperty_white_space, NS_STYLE_WHITESPACE_PRE);
|
2014-10-28 20:33:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
nsGenericHTMLFormElementWithState::MapDivAlignAttributeInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLFormElementWithState::MapCommonAttributesInto(aAttributes, aData);
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
|
|
|
|
2004-10-24 21:10:32 +04:00
|
|
|
nsChangeHint
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) const
|
1999-07-07 05:24:40 +04:00
|
|
|
{
|
2004-10-24 21:10:32 +04:00
|
|
|
nsChangeHint retval =
|
2013-08-02 05:21:31 +04:00
|
|
|
nsGenericHTMLFormElementWithState::GetAttributeChangeHint(aAttribute, aModType);
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::rows ||
|
|
|
|
aAttribute == nsGkAtoms::cols) {
|
2016-05-23 06:26:03 +03:00
|
|
|
retval |= NS_STYLE_HINT_REFLOW;
|
2010-02-06 11:51:10 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::wrap) {
|
2016-05-23 06:26:03 +03:00
|
|
|
retval |= nsChangeHint_ReconstructFrame;
|
2010-10-19 17:11:07 +04:00
|
|
|
} else if (aAttribute == nsGkAtoms::placeholder) {
|
2016-07-06 08:06:14 +03:00
|
|
|
retval |= nsChangeHint_ReconstructFrame;
|
2003-07-12 01:16:12 +04:00
|
|
|
}
|
2004-10-24 21:10:32 +04:00
|
|
|
return retval;
|
2003-07-12 01:16:12 +04:00
|
|
|
}
|
2003-04-17 00:54:20 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
2003-07-12 01:16:12 +04:00
|
|
|
{
|
2014-10-30 16:09:22 +03:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2014-10-28 20:33:15 +03:00
|
|
|
{ &nsGkAtoms::wrap },
|
|
|
|
{ nullptr }
|
|
|
|
};
|
|
|
|
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2014-10-28 20:33:15 +03:00
|
|
|
attributes,
|
2003-07-12 01:16:12 +04:00
|
|
|
sDivAlignAttributeMap,
|
2003-04-17 00:54:20 +04:00
|
|
|
sCommonAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsMapRuleToAttributesFunc
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetAttributeMappingFunction() const
|
1998-09-05 08:00:06 +04:00
|
|
|
{
|
2005-01-12 22:45:38 +03:00
|
|
|
return &MapAttributesIntoRule;
|
1998-09-05 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 19:17:36 +04:00
|
|
|
bool
|
2015-08-26 15:56:59 +03:00
|
|
|
HTMLTextAreaElement::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);
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-01-03 19:17:36 +04:00
|
|
|
nsresult
|
2016-10-21 05:11:07 +03:00
|
|
|
HTMLTextAreaElement::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;
|
2000-08-09 03:38:00 +04:00
|
|
|
}
|
|
|
|
|
2003-04-22 07:27:24 +04:00
|
|
|
// Don't dispatch a second select event if we are already handling
|
|
|
|
// one.
|
2015-09-02 09:08:00 +03:00
|
|
|
if (aVisitor.mEvent->mMessage == eFormSelect) {
|
2006-03-07 20:08:51 +03:00
|
|
|
if (mHandlingSelect) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mHandlingSelect = true;
|
2003-04-22 07:27:24 +04:00
|
|
|
}
|
|
|
|
|
2012-12-16 05:26:05 +04:00
|
|
|
// If noContentDispatch is true we will not allow content to handle
|
2001-11-07 09:29:29 +03:00
|
|
|
// this event. But to allow middle mouse button paste to work we must allow
|
|
|
|
// middle clicks to go to text fields anyway.
|
2012-12-16 05:26:05 +04:00
|
|
|
if (aVisitor.mEvent->mFlags.mNoContentDispatch) {
|
2006-03-07 20:08:51 +03:00
|
|
|
aVisitor.mItemFlags |= NS_NO_CONTENT_DISPATCH;
|
2012-12-16 05:26:05 +04:00
|
|
|
}
|
2015-08-29 02:58:32 +03:00
|
|
|
if (aVisitor.mEvent->mMessage == eMouseClick &&
|
2013-10-22 12:55:20 +04:00
|
|
|
aVisitor.mEvent->AsMouseEvent()->button ==
|
2013-10-02 10:38:27 +04:00
|
|
|
WidgetMouseEvent::eMiddleButton) {
|
2012-12-16 05:26:05 +04:00
|
|
|
aVisitor.mEvent->mFlags.mNoContentDispatch = false;
|
2003-04-22 07:27:24 +04:00
|
|
|
}
|
|
|
|
|
2015-09-02 09:08:00 +03:00
|
|
|
if (aVisitor.mEvent->mMessage == eBlur) {
|
2016-10-21 12:33:41 +03:00
|
|
|
// Set mWantsPreHandleEvent and fire change event in PreHandleEvent to
|
|
|
|
// prevent it breaks event target chain creation.
|
|
|
|
aVisitor.mWantsPreHandleEvent = true;
|
2007-02-16 19:19:28 +03:00
|
|
|
}
|
|
|
|
|
2016-10-21 05:11:07 +03:00
|
|
|
return nsGenericHTMLFormElementWithState::GetEventTargetParent(aVisitor);
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
2000-09-02 08:59:44 +04:00
|
|
|
|
2016-10-21 12:33:41 +03:00
|
|
|
nsresult
|
|
|
|
HTMLTextAreaElement::PreHandleEvent(EventChainVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
if (aVisitor.mEvent->mMessage == eBlur) {
|
|
|
|
// Fire onchange (if necessary), before we do the blur, bug 370521.
|
|
|
|
FireChangeEventIfNeeded();
|
|
|
|
}
|
|
|
|
return nsGenericHTMLFormElementWithState::PreHandleEvent(aVisitor);
|
|
|
|
}
|
|
|
|
|
2012-05-24 14:54:25 +04:00
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::FireChangeEventIfNeeded()
|
2012-05-24 14:54:25 +04:00
|
|
|
{
|
|
|
|
nsString value;
|
|
|
|
GetValueInternal(value, true);
|
|
|
|
|
|
|
|
if (mFocusedValue.Equals(value)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dispatch the change event.
|
|
|
|
mFocusedValue = value;
|
|
|
|
nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
|
|
|
|
static_cast<nsIContent*>(this),
|
|
|
|
NS_LITERAL_STRING("change"), true,
|
|
|
|
false);
|
2012-05-07 20:27:24 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
nsresult
|
2014-03-18 08:48:20 +04:00
|
|
|
HTMLTextAreaElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
2006-03-07 20:08:51 +03:00
|
|
|
{
|
2015-09-02 09:08:00 +03:00
|
|
|
if (aVisitor.mEvent->mMessage == eFormSelect) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mHandlingSelect = false;
|
2003-04-22 07:27:24 +04:00
|
|
|
}
|
|
|
|
|
2015-09-02 09:08:00 +03:00
|
|
|
if (aVisitor.mEvent->mMessage == eFocus ||
|
2015-09-02 09:08:00 +03:00
|
|
|
aVisitor.mEvent->mMessage == eBlur) {
|
2015-09-02 09:08:00 +03:00
|
|
|
if (aVisitor.mEvent->mMessage == eFocus) {
|
2010-11-24 02:50:53 +03:00
|
|
|
// If the invalid UI is shown, we should show it while focusing (and
|
|
|
|
// update). Otherwise, we should not.
|
2012-05-07 20:27:24 +04:00
|
|
|
GetValueInternal(mFocusedValue, true);
|
2011-01-20 14:05:29 +03:00
|
|
|
mCanShowInvalidUI = !IsValid() && ShouldShowValidityUI();
|
2010-11-24 02:56:24 +03:00
|
|
|
|
|
|
|
// If neither invalid UI nor valid UI is shown, we shouldn't show the valid
|
|
|
|
// UI while typing.
|
2011-01-20 14:05:29 +03:00
|
|
|
mCanShowValidUI = ShouldShowValidityUI();
|
2015-09-02 09:08:00 +03:00
|
|
|
} else { // eBlur
|
2011-10-17 18:59:28 +04:00
|
|
|
mCanShowInvalidUI = true;
|
|
|
|
mCanShowValidUI = true;
|
2010-11-24 02:50:53 +03:00
|
|
|
}
|
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
UpdateState(true);
|
2010-08-25 08:39:10 +04:00
|
|
|
}
|
|
|
|
|
2001-11-07 09:29:29 +03:00
|
|
|
// Reset the flag for other content besides this text field
|
2012-12-16 05:26:05 +04:00
|
|
|
aVisitor.mEvent->mFlags.mNoContentDispatch =
|
|
|
|
((aVisitor.mItemFlags & NS_NO_CONTENT_DISPATCH) != 0);
|
2001-11-07 09:29:29 +03:00
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
return NS_OK;
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2011-11-16 11:50:18 +04:00
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::DoneAddingChildren(bool aHaveNotified)
|
2002-03-31 14:14:01 +04:00
|
|
|
{
|
2005-06-16 04:41:50 +04:00
|
|
|
if (!mValueChanged) {
|
|
|
|
if (!mDoneAddingChildren) {
|
|
|
|
// Reset now that we're done adding children if the content sink tried to
|
|
|
|
// sneak some text in without calling AppendChildTo.
|
|
|
|
Reset();
|
|
|
|
}
|
2013-08-02 05:21:31 +04:00
|
|
|
|
2010-06-09 10:45:32 +04:00
|
|
|
if (!mInhibitStateRestoration) {
|
2013-08-02 05:21:31 +04:00
|
|
|
nsresult rv = GenerateStateKey();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
RestoreFormControlState();
|
|
|
|
}
|
2010-06-09 10:45:32 +04:00
|
|
|
}
|
2005-06-16 04:41:50 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mDoneAddingChildren = true;
|
2002-03-31 14:14:01 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsDoneAddingChildren()
|
2004-06-02 04:25:00 +04:00
|
|
|
{
|
|
|
|
return mDoneAddingChildren;
|
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
1999-11-19 10:24:15 +03:00
|
|
|
// Controllers Methods
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-02-19 09:54:23 +04:00
|
|
|
nsIControllers*
|
|
|
|
HTMLTextAreaElement::GetControllers(ErrorResult& aError)
|
1999-11-19 10:24:15 +03:00
|
|
|
{
|
|
|
|
if (!mControllers)
|
|
|
|
{
|
2000-02-16 04:41:17 +03:00
|
|
|
nsresult rv;
|
2002-12-11 17:24:49 +03:00
|
|
|
mControllers = do_CreateInstance(kXULControllersCID, &rv);
|
2013-02-19 09:54:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2002-12-11 17:24:49 +03:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/editor/editorcontroller;1", &rv);
|
2013-02-19 09:54:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1999-12-15 06:54:52 +03:00
|
|
|
mControllers->AppendController(controller);
|
2011-12-24 04:11:30 +04:00
|
|
|
|
|
|
|
controller = do_CreateInstance("@mozilla.org/editor/editingcontroller;1", &rv);
|
2013-02-19 09:54:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-12-24 04:11:30 +04:00
|
|
|
|
|
|
|
mControllers->AppendController(controller);
|
1999-11-19 10:24:15 +03:00
|
|
|
}
|
|
|
|
|
2013-02-19 09:54:23 +04:00
|
|
|
return mControllers;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLTextAreaElement::GetControllers(nsIControllers** aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
|
|
|
ErrorResult error;
|
|
|
|
*aResult = GetControllers(error);
|
1999-11-19 10:24:15 +03:00
|
|
|
NS_IF_ADDREF(*aResult);
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2015-04-27 16:18:51 +03:00
|
|
|
return error.StealNSResult();
|
2013-02-19 09:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
HTMLTextAreaElement::GetTextLength()
|
|
|
|
{
|
|
|
|
nsAutoString val;
|
|
|
|
GetValue(val);
|
|
|
|
return val.Length();
|
1999-11-19 10:24:15 +03:00
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
|
2002-06-28 00:22:28 +04:00
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetTextLength(int32_t *aTextLength)
|
2002-06-28 00:22:28 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aTextLength);
|
2013-02-19 09:54:23 +04:00
|
|
|
*aTextLength = GetTextLength();
|
2002-06-28 00:22:28 +04:00
|
|
|
|
2013-02-19 09:54:23 +04:00
|
|
|
return NS_OK;
|
2002-06-28 00:22:28 +04:00
|
|
|
}
|
|
|
|
|
2016-08-09 00:19:00 +03:00
|
|
|
Nullable<uint32_t>
|
2013-02-19 09:54:23 +04:00
|
|
|
HTMLTextAreaElement::GetSelectionStart(ErrorResult& aError)
|
|
|
|
{
|
2017-03-09 22:44:45 +03:00
|
|
|
uint32_t selStart, selEnd;
|
2017-03-09 22:44:04 +03:00
|
|
|
GetSelectionRange(&selStart, &selEnd, aError);
|
2016-08-09 00:19:00 +03:00
|
|
|
return Nullable<uint32_t>(selStart);
|
2002-06-28 00:22:28 +04:00
|
|
|
}
|
|
|
|
|
2013-02-19 09:54:23 +04:00
|
|
|
void
|
2016-08-09 00:19:00 +03:00
|
|
|
HTMLTextAreaElement::SetSelectionStart(const Nullable<uint32_t>& aSelectionStart,
|
|
|
|
ErrorResult& aError)
|
2002-06-28 00:22:28 +04:00
|
|
|
{
|
2017-03-09 22:44:05 +03:00
|
|
|
mState.SetSelectionStart(aSelectionStart, aError);
|
2002-06-28 00:22:28 +04:00
|
|
|
}
|
|
|
|
|
2016-08-09 00:19:00 +03:00
|
|
|
Nullable<uint32_t>
|
2013-02-19 09:54:23 +04:00
|
|
|
HTMLTextAreaElement::GetSelectionEnd(ErrorResult& aError)
|
|
|
|
{
|
2017-03-09 22:44:45 +03:00
|
|
|
uint32_t selStart, selEnd;
|
2017-03-09 22:44:04 +03:00
|
|
|
GetSelectionRange(&selStart, &selEnd, aError);
|
2016-08-09 00:19:00 +03:00
|
|
|
return Nullable<uint32_t>(selEnd);
|
2003-01-09 09:06:17 +03:00
|
|
|
}
|
2002-06-28 00:22:28 +04:00
|
|
|
|
2013-02-19 09:54:23 +04:00
|
|
|
void
|
2016-08-09 00:19:00 +03:00
|
|
|
HTMLTextAreaElement::SetSelectionEnd(const Nullable<uint32_t>& aSelectionEnd,
|
|
|
|
ErrorResult& aError)
|
2011-07-28 21:51:22 +04:00
|
|
|
{
|
2017-03-09 22:44:05 +03:00
|
|
|
mState.SetSelectionEnd(aSelectionEnd, aError);
|
2011-07-28 21:51:22 +04:00
|
|
|
}
|
|
|
|
|
2017-03-09 22:44:04 +03:00
|
|
|
void
|
2017-03-09 22:44:45 +03:00
|
|
|
HTMLTextAreaElement::GetSelectionRange(uint32_t* aSelectionStart,
|
|
|
|
uint32_t* aSelectionEnd,
|
2017-03-09 22:44:04 +03:00
|
|
|
ErrorResult& aRv)
|
2003-01-09 09:06:17 +03:00
|
|
|
{
|
2017-03-09 22:44:04 +03:00
|
|
|
return mState.GetSelectionRange(aSelectionStart, aSelectionEnd, aRv);
|
2002-06-28 00:22:28 +04:00
|
|
|
}
|
|
|
|
|
2013-02-19 09:54:23 +04:00
|
|
|
void
|
|
|
|
HTMLTextAreaElement::GetSelectionDirection(nsAString& aDirection, ErrorResult& aError)
|
2002-06-28 00:22:28 +04:00
|
|
|
{
|
2017-03-09 22:44:06 +03:00
|
|
|
mState.GetSelectionDirectionString(aDirection, aError);
|
2013-02-19 09:54:23 +04:00
|
|
|
}
|
|
|
|
|
2013-02-19 09:54:23 +04:00
|
|
|
void
|
2016-08-09 00:19:00 +03:00
|
|
|
HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection,
|
|
|
|
ErrorResult& aError)
|
2013-02-19 09:54:23 +04:00
|
|
|
{
|
2017-03-09 22:44:06 +03:00
|
|
|
mState.SetSelectionDirection(aDirection, aError);
|
2011-07-28 21:51:22 +04:00
|
|
|
}
|
|
|
|
|
2013-02-19 09:54:23 +04:00
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetSelectionRange(uint32_t aSelectionStart,
|
|
|
|
uint32_t aSelectionEnd,
|
|
|
|
const Optional<nsAString>& aDirection,
|
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
2017-03-09 22:44:06 +03:00
|
|
|
mState.SetSelectionRange(aSelectionStart, aSelectionEnd,
|
|
|
|
aDirection, aError);
|
2013-02-19 09:54:23 +04:00
|
|
|
}
|
2003-01-09 09:06:17 +03:00
|
|
|
|
2013-10-04 19:30:07 +04:00
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetRangeText(const nsAString& aReplacement,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2017-03-09 22:44:06 +03:00
|
|
|
mState.SetRangeText(aReplacement, aRv);
|
2013-10-04 19:30:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetRangeText(const nsAString& aReplacement,
|
|
|
|
uint32_t aStart, uint32_t aEnd,
|
2017-03-09 22:44:06 +03:00
|
|
|
SelectionMode aSelectMode,
|
|
|
|
ErrorResult& aRv)
|
2013-10-04 19:30:07 +04:00
|
|
|
{
|
2017-03-09 22:44:06 +03:00
|
|
|
mState.SetRangeText(aReplacement, aStart, aEnd, aSelectMode, aRv);
|
|
|
|
}
|
2013-10-04 19:30:07 +04:00
|
|
|
|
2017-03-09 22:44:06 +03:00
|
|
|
void
|
|
|
|
HTMLTextAreaElement::GetValueFromSetRangeText(nsAString& aValue)
|
|
|
|
{
|
|
|
|
GetValueInternal(aValue, false);
|
|
|
|
}
|
2013-10-04 19:30:07 +04:00
|
|
|
|
2017-03-09 22:44:06 +03:00
|
|
|
nsresult
|
|
|
|
HTMLTextAreaElement::SetValueFromSetRangeText(const nsAString& aValue)
|
|
|
|
{
|
2017-03-09 22:44:36 +03:00
|
|
|
return SetValueInternal(aValue,
|
|
|
|
nsTextEditorState::eSetValue_ByContent |
|
|
|
|
nsTextEditorState::eSetValue_Notify);
|
2013-10-04 19:30:07 +04:00
|
|
|
}
|
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
nsresult
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::Reset()
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
2010-08-21 21:52:57 +04:00
|
|
|
nsAutoString resetVal;
|
|
|
|
GetDefaultValue(resetVal);
|
2017-03-09 22:44:04 +03:00
|
|
|
SetValueChanged(false);
|
|
|
|
|
2017-03-09 22:44:04 +03:00
|
|
|
nsresult rv = SetValueInternal(resetVal,
|
|
|
|
nsTextEditorState::eSetValue_Internal);
|
2010-08-21 21:52:57 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
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
|
|
|
HTMLTextAreaElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission)
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
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-11-23 11:50:55 +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-10-17 18:59:28 +04:00
|
|
|
GetValueInternal(value, false);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::SaveState()
|
2002-03-31 14:14:01 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Only save if value != defaultValue (bug 62713)
|
2012-07-30 18:20:58 +04:00
|
|
|
nsPresState *state = nullptr;
|
2002-03-31 14:14:01 +04:00
|
|
|
if (mValueChanged) {
|
2013-07-24 11:38:13 +04:00
|
|
|
state = GetPrimaryPresState();
|
2002-03-31 14:14:01 +04:00
|
|
|
if (state) {
|
|
|
|
nsAutoString value;
|
2011-10-17 18:59:28 +04:00
|
|
|
GetValueInternal(value, true);
|
2002-03-31 14:14:01 +04:00
|
|
|
|
|
|
|
rv = nsLinebreakConverter::ConvertStringLineBreaks(
|
|
|
|
value,
|
|
|
|
nsLinebreakConverter::eLinebreakPlatform,
|
|
|
|
nsLinebreakConverter::eLinebreakContent);
|
2016-05-06 01:50:35 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("Converting linebreaks failed!");
|
|
|
|
return rv;
|
|
|
|
}
|
2008-12-12 22:25:22 +03:00
|
|
|
|
2011-11-16 11:50:19 +04:00
|
|
|
nsCOMPtr<nsISupportsString> pState =
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
|
2008-12-12 22:25:22 +03:00
|
|
|
if (!pState) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
pState->SetData(value);
|
|
|
|
state->SetStateProperty(pState);
|
2002-03-31 14:14:01 +04:00
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
|
|
|
|
2006-11-28 06:17:03 +03:00
|
|
|
if (mDisabledChanged) {
|
|
|
|
if (!state) {
|
2013-07-24 11:38:13 +04:00
|
|
|
state = GetPrimaryPresState();
|
|
|
|
rv = NS_OK;
|
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
|
|
|
}
|
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::RestoreState(nsPresState* aState)
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
2008-12-12 22:25:22 +03:00
|
|
|
nsCOMPtr<nsISupportsString> state
|
|
|
|
(do_QueryInterface(aState->GetStateProperty()));
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
nsAutoString data;
|
|
|
|
state->GetData(data);
|
2015-01-08 04:14:01 +03:00
|
|
|
nsresult rv = SetValue(data);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2008-08-14 14:06:40 +04:00
|
|
|
}
|
2007-10-10 07:39:16 +04:00
|
|
|
|
2016-12-30 09:26:35 +03:00
|
|
|
if (aState->IsDisabledSet() && !aState->GetDisabled()) {
|
|
|
|
SetDisabled(false);
|
2006-11-28 06:17:03 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
2006-11-28 06:17:03 +03:00
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IntrinsicState() const
|
2010-08-19 04:03:20 +04:00
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsGenericHTMLFormElementWithState::IntrinsicState();
|
2008-12-12 22:25:22 +03:00
|
|
|
|
2010-08-19 04:03:20 +04:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::required)) {
|
|
|
|
state |= NS_EVENT_STATE_REQUIRED;
|
|
|
|
} else {
|
|
|
|
state |= NS_EVENT_STATE_OPTIONAL;
|
|
|
|
}
|
|
|
|
|
2010-08-21 22:51:38 +04:00
|
|
|
if (IsCandidateForConstraintValidation()) {
|
2010-11-24 02:49:50 +03:00
|
|
|
if (IsValid()) {
|
2010-11-24 02:55:22 +03:00
|
|
|
state |= NS_EVENT_STATE_VALID;
|
2010-11-24 02:49:50 +03:00
|
|
|
} else {
|
|
|
|
state |= NS_EVENT_STATE_INVALID;
|
2011-01-27 16:51:45 +03:00
|
|
|
// :-moz-ui-invalid always apply if the element suffers from a custom
|
|
|
|
// error and never applies if novalidate is set on the form owner.
|
|
|
|
if ((!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) &&
|
|
|
|
(GetValidityState(VALIDITY_STATE_CUSTOM_ERROR) ||
|
2011-12-18 10:00:47 +04:00
|
|
|
(mCanShowInvalidUI && ShouldShowValidityUI()))) {
|
2010-11-24 02:49:50 +03:00
|
|
|
state |= NS_EVENT_STATE_MOZ_UI_INVALID;
|
|
|
|
}
|
|
|
|
}
|
2010-11-24 02:56:24 +03:00
|
|
|
|
|
|
|
// :-moz-ui-valid applies if all the following are true:
|
|
|
|
// 1. The element is not focused, or had either :-moz-ui-valid or
|
|
|
|
// :-moz-ui-invalid applying before it was focused ;
|
|
|
|
// 2. The element is either valid or isn't allowed to have
|
|
|
|
// :-moz-ui-invalid applying ;
|
2011-01-27 16:51:45 +03:00
|
|
|
// 3. The element has no form owner or its form owner doesn't have the
|
|
|
|
// novalidate attribute set ;
|
|
|
|
// 4. The element has already been modified or the user tried to submit the
|
|
|
|
// form owner while invalid.
|
|
|
|
if ((!mForm || !mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate)) &&
|
|
|
|
(mCanShowValidUI && ShouldShowValidityUI() &&
|
|
|
|
(IsValid() || (state.HasState(NS_EVENT_STATE_MOZ_UI_INVALID) &&
|
|
|
|
!mCanShowInvalidUI)))) {
|
2010-11-24 02:56:24 +03:00
|
|
|
state |= NS_EVENT_STATE_MOZ_UI_VALID;
|
|
|
|
}
|
2010-08-21 21:52:57 +04:00
|
|
|
}
|
|
|
|
|
2016-08-31 21:21:44 +03:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder) &&
|
|
|
|
IsValueEmpty()) {
|
|
|
|
state |= NS_EVENT_STATE_PLACEHOLDERSHOWN;
|
|
|
|
}
|
|
|
|
|
2010-08-19 04:03:20 +04:00
|
|
|
return state;
|
|
|
|
}
|
2008-12-12 22:25:22 +03:00
|
|
|
|
2010-09-19 01:33:16 +04:00
|
|
|
nsresult
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2010-09-19 01:33:16 +04:00
|
|
|
{
|
2013-08-02 05:21:31 +04:00
|
|
|
nsresult rv = nsGenericHTMLFormElementWithState::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2010-09-19 01:33:16 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// If there is a disabled fieldset in the parent chain, the element is now
|
|
|
|
// barred from constraint validation and can't suffer from value missing.
|
|
|
|
UpdateValueMissingValidityState();
|
|
|
|
UpdateBarredFromConstraintValidation();
|
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
// And now make sure our state is up to date
|
|
|
|
UpdateState(false);
|
|
|
|
|
2010-09-19 01:33:16 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2010-09-19 01:33:16 +04:00
|
|
|
{
|
2013-08-02 05:21:31 +04:00
|
|
|
nsGenericHTMLFormElementWithState::UnbindFromTree(aDeep, aNullParent);
|
2010-09-19 01:33:16 +04:00
|
|
|
|
|
|
|
// We might be no longer disabled because of parent chain changed.
|
|
|
|
UpdateValueMissingValidityState();
|
|
|
|
UpdateBarredFromConstraintValidation();
|
2011-06-01 05:46:57 +04:00
|
|
|
|
|
|
|
// And now make sure our state is up to date
|
|
|
|
UpdateState(false);
|
2010-09-19 01:33:16 +04:00
|
|
|
}
|
|
|
|
|
2006-11-28 06:17:03 +03:00
|
|
|
nsresult
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2017-03-16 21:50:41 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
2013-02-19 01:18:40 +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,
|
2006-11-28 06:17:03 +03:00
|
|
|
aValue, aNotify);
|
|
|
|
}
|
2007-01-30 08:48:22 +03:00
|
|
|
|
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
2007-01-30 08:48:22 +03:00
|
|
|
{
|
|
|
|
ContentChanged(aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
|
|
|
int32_t /* unused */)
|
2007-01-30 08:48:22 +03:00
|
|
|
{
|
2010-06-28 22:04:37 +04:00
|
|
|
ContentChanged(aFirstNewContent);
|
2007-01-30 08:48:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t /* unused */)
|
2007-01-30 08:48:22 +03:00
|
|
|
{
|
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer,
|
|
|
|
nsIContent* aPreviousSibling)
|
2007-01-30 08:48:22 +03:00
|
|
|
{
|
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::ContentChanged(nsIContent* aContent)
|
2007-01-30 08:48:22 +03:00
|
|
|
{
|
|
|
|
if (!mValueChanged && mDoneAddingChildren &&
|
|
|
|
nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
|
2010-07-21 19:33:32 +04:00
|
|
|
// Hard to say what the reset can trigger, so be safe pending
|
|
|
|
// further auditing.
|
|
|
|
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
|
2007-01-30 08:48:22 +03:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
|
|
|
|
nsresult
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
2007-06-28 06:48:16 +04:00
|
|
|
{
|
2010-08-21 21:52:57 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aName == nsGkAtoms::required || aName == nsGkAtoms::disabled ||
|
|
|
|
aName == nsGkAtoms::readonly) {
|
|
|
|
UpdateValueMissingValidityState();
|
2010-09-10 09:08:56 +04:00
|
|
|
|
|
|
|
// This *has* to be called *after* validity has changed.
|
|
|
|
if (aName == nsGkAtoms::readonly || aName == nsGkAtoms::disabled) {
|
|
|
|
UpdateBarredFromConstraintValidation();
|
|
|
|
}
|
2010-08-21 21:52:57 +04:00
|
|
|
} else if (aName == nsGkAtoms::maxlength) {
|
|
|
|
UpdateTooLongValidityState();
|
2016-08-17 07:11:24 +03:00
|
|
|
} else if (aName == nsGkAtoms::minlength) {
|
|
|
|
UpdateTooShortValidityState();
|
2010-08-21 21:52:57 +04:00
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2010-08-21 21:52:57 +04:00
|
|
|
|
2013-08-02 05:21:31 +04:00
|
|
|
return nsGenericHTMLFormElementWithState::AfterSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
|
|
|
}
|
2009-12-11 07:02:13 +03:00
|
|
|
|
|
|
|
nsresult
|
2017-04-20 22:57:48 +03:00
|
|
|
HTMLTextAreaElement::CopyInnerTo(Element* aDest, bool aPreallocateChildren)
|
2009-12-11 07:02:13 +03:00
|
|
|
{
|
2017-04-20 22:57:48 +03:00
|
|
|
nsresult rv = nsGenericHTMLFormElementWithState::CopyInnerTo(aDest,
|
|
|
|
aPreallocateChildren);
|
2009-12-11 07:02:13 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-18 14:53:36 +04:00
|
|
|
if (aDest->OwnerDoc()->IsStaticDocument()) {
|
2009-12-11 07:02:13 +03:00
|
|
|
nsAutoString value;
|
2011-11-16 11:50:19 +04:00
|
|
|
GetValueInternal(value, true);
|
2015-01-08 04:14:01 +03:00
|
|
|
return static_cast<HTMLTextAreaElement*>(aDest)->SetValue(value);
|
2009-12-11 07:02:13 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsMutable() const
|
2010-08-18 22:30:41 +04:00
|
|
|
{
|
2010-09-19 01:33:16 +04:00
|
|
|
return (!HasAttr(kNameSpaceID_None, nsGkAtoms::readonly) && !IsDisabled());
|
2010-08-18 22:30:41 +04:00
|
|
|
}
|
|
|
|
|
2011-04-13 10:33:01 +04:00
|
|
|
bool
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsValueEmpty() const
|
2011-04-13 10:33:01 +04:00
|
|
|
{
|
|
|
|
nsAutoString value;
|
2011-10-17 18:59:28 +04:00
|
|
|
GetValueInternal(value, true);
|
2011-04-13 10:33:01 +04:00
|
|
|
|
|
|
|
return value.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
// nsIConstraintValidation
|
2010-08-18 22:28:08 +04:00
|
|
|
|
2010-08-21 21:52:57 +04:00
|
|
|
NS_IMETHODIMP
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::SetCustomValidity(const nsAString& aError)
|
2010-08-21 21:52:57 +04:00
|
|
|
{
|
2010-08-21 22:52:49 +04:00
|
|
|
nsIConstraintValidation::SetCustomValidity(aError);
|
2010-08-21 21:52:57 +04:00
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
UpdateState(true);
|
2010-08-21 21:52:57 +04:00
|
|
|
|
2010-08-21 22:51:38 +04:00
|
|
|
return NS_OK;
|
2010-08-21 21:52:57 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsTooLong()
|
2010-08-18 22:28:08 +04:00
|
|
|
{
|
2016-08-06 18:59:08 +03:00
|
|
|
if (!mValueChanged ||
|
|
|
|
!mLastValueChangeWasInteractive ||
|
|
|
|
!HasAttr(kNameSpaceID_None, nsGkAtoms::maxlength)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-08-18 22:29:20 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t maxLength = -1;
|
2010-08-18 22:28:08 +04:00
|
|
|
GetMaxLength(&maxLength);
|
2010-10-07 14:02:29 +04:00
|
|
|
|
|
|
|
// Maxlength of -1 means parsing error.
|
|
|
|
if (maxLength == -1) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-10-07 14:02:29 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t textLength = -1;
|
2010-08-18 22:28:08 +04:00
|
|
|
GetTextLength(&textLength);
|
|
|
|
|
2010-10-07 14:02:29 +04:00
|
|
|
return textLength > maxLength;
|
2010-08-18 22:28:08 +04:00
|
|
|
}
|
|
|
|
|
2016-08-17 07:11:24 +03:00
|
|
|
bool
|
|
|
|
HTMLTextAreaElement::IsTooShort()
|
|
|
|
{
|
|
|
|
if (!mValueChanged ||
|
|
|
|
!mLastValueChangeWasInteractive ||
|
|
|
|
!HasAttr(kNameSpaceID_None, nsGkAtoms::minlength)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t minLength = -1;
|
|
|
|
GetMinLength(&minLength);
|
|
|
|
|
|
|
|
// Minlength of -1 means parsing error.
|
|
|
|
if (minLength == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t textLength = -1;
|
|
|
|
GetTextLength(&textLength);
|
|
|
|
|
|
|
|
return textLength && textLength < minLength;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsValueMissing() const
|
2010-08-18 22:30:41 +04:00
|
|
|
{
|
|
|
|
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::required) || !IsMutable()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-08-18 22:30:41 +04:00
|
|
|
}
|
|
|
|
|
2011-04-13 10:33:01 +04:00
|
|
|
return IsValueEmpty();
|
2010-08-18 22:30:41 +04:00
|
|
|
}
|
|
|
|
|
2010-08-21 21:52:57 +04:00
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::UpdateTooLongValidityState()
|
2010-08-21 21:52:57 +04:00
|
|
|
{
|
|
|
|
SetValidityState(VALIDITY_STATE_TOO_LONG, IsTooLong());
|
|
|
|
}
|
|
|
|
|
2016-08-17 07:11:24 +03:00
|
|
|
void
|
|
|
|
HTMLTextAreaElement::UpdateTooShortValidityState()
|
|
|
|
{
|
|
|
|
SetValidityState(VALIDITY_STATE_TOO_SHORT, IsTooShort());
|
|
|
|
}
|
|
|
|
|
2010-08-21 21:52:57 +04:00
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::UpdateValueMissingValidityState()
|
2010-08-21 21:52:57 +04:00
|
|
|
{
|
|
|
|
SetValidityState(VALIDITY_STATE_VALUE_MISSING, IsValueMissing());
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:08:56 +04:00
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::UpdateBarredFromConstraintValidation()
|
2010-08-18 22:28:08 +04:00
|
|
|
{
|
2010-09-10 09:08:56 +04:00
|
|
|
SetBarredFromConstraintValidation(HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::readonly) ||
|
2010-09-19 01:33:16 +04:00
|
|
|
IsDisabled());
|
2010-08-18 22:28:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetValidationMessage(nsAString& aValidationMessage,
|
|
|
|
ValidityStateType aType)
|
2010-08-18 22:28:08 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
switch (aType)
|
|
|
|
{
|
2010-08-21 21:52:57 +04:00
|
|
|
case VALIDITY_STATE_TOO_LONG:
|
2010-08-18 22:28:08 +04:00
|
|
|
{
|
|
|
|
nsXPIDLString message;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t maxLength = -1;
|
|
|
|
int32_t textLength = -1;
|
2010-08-18 22:28:08 +04:00
|
|
|
nsAutoString strMaxLength;
|
|
|
|
nsAutoString strTextLength;
|
|
|
|
|
|
|
|
GetMaxLength(&maxLength);
|
|
|
|
GetTextLength(&textLength);
|
|
|
|
|
|
|
|
strMaxLength.AppendInt(maxLength);
|
|
|
|
strTextLength.AppendInt(textLength);
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* params[] = { strMaxLength.get(), strTextLength.get() };
|
2010-08-18 22:28:08 +04:00
|
|
|
rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES,
|
2010-09-23 05:44:13 +04:00
|
|
|
"FormValidationTextTooLong",
|
2012-03-09 06:22:57 +04:00
|
|
|
params, message);
|
2010-08-18 22:28:08 +04:00
|
|
|
aValidationMessage = message;
|
|
|
|
}
|
|
|
|
break;
|
2016-08-17 07:11:24 +03:00
|
|
|
case VALIDITY_STATE_TOO_SHORT:
|
|
|
|
{
|
|
|
|
nsXPIDLString message;
|
|
|
|
int32_t minLength = -1;
|
|
|
|
int32_t textLength = -1;
|
|
|
|
nsAutoString strMinLength;
|
|
|
|
nsAutoString strTextLength;
|
|
|
|
|
|
|
|
GetMinLength(&minLength);
|
|
|
|
GetTextLength(&textLength);
|
|
|
|
|
|
|
|
strMinLength.AppendInt(minLength);
|
|
|
|
strTextLength.AppendInt(textLength);
|
|
|
|
|
|
|
|
const char16_t* params[] = { strMinLength.get(), strTextLength.get() };
|
|
|
|
rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"FormValidationTextTooShort",
|
|
|
|
params, message);
|
|
|
|
aValidationMessage = message;
|
|
|
|
}
|
|
|
|
break;
|
2010-08-21 21:52:57 +04:00
|
|
|
case VALIDITY_STATE_VALUE_MISSING:
|
2010-08-18 22:30:41 +04:00
|
|
|
{
|
|
|
|
nsXPIDLString message;
|
|
|
|
rv = nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES,
|
2010-09-23 05:44:13 +04:00
|
|
|
"FormValidationValueMissing",
|
2010-08-18 22:30:41 +04:00
|
|
|
message);
|
|
|
|
aValidationMessage = message;
|
|
|
|
}
|
|
|
|
break;
|
2010-08-18 22:28:08 +04:00
|
|
|
default:
|
2010-08-21 22:52:49 +04:00
|
|
|
rv = nsIConstraintValidation::GetValidationMessage(aValidationMessage, aType);
|
2010-08-18 22:28:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsSingleLineTextControl() const
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsTextArea() const
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsPlainTextControl() const
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
|
|
|
// need to check our HTML attribute and/or CSS.
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::IsPasswordTextControl() const
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP_(int32_t)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetCols()
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2015-04-20 23:54:46 +03:00
|
|
|
return Cols();
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP_(int32_t)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetWrapCols()
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
|
|
|
// wrap=off means -1 for wrap width no matter what cols is
|
|
|
|
nsHTMLTextWrap wrapProp;
|
|
|
|
nsITextControlElement::GetWrapPropertyEnum(this, wrapProp);
|
|
|
|
if (wrapProp == nsITextControlElement::eHTMLTextWrap_Off) {
|
|
|
|
// do not wrap when wrap=off
|
2015-02-26 23:26:12 +03:00
|
|
|
return 0;
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise we just wrap at the given number of columns
|
|
|
|
return GetCols();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP_(int32_t)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetRows()
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
|
|
|
const nsAttrValue* attr = GetParsedAttr(nsGkAtoms::rows);
|
|
|
|
if (attr && attr->Type() == nsAttrValue::eInteger) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rows = attr->GetIntegerValue();
|
2010-04-22 00:17:41 +04:00
|
|
|
return (rows <= 0) ? DEFAULT_ROWS_TEXTAREA : rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DEFAULT_ROWS_TEXTAREA;
|
|
|
|
}
|
|
|
|
|
2013-03-25 23:35:55 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2013-03-26 00:22:09 +04:00
|
|
|
HTMLTextAreaElement::GetDefaultValueFromContent(nsAString& aValue)
|
2013-03-25 23:35:55 +04:00
|
|
|
{
|
|
|
|
GetDefaultValue(aValue);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::ValueChanged() const
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
|
|
|
return mValueChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::GetTextEditorValue(nsAString& aValue,
|
|
|
|
bool aIgnoreWrap) const
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2012-04-24 08:19:26 +04:00
|
|
|
mState.GetValue(aValue, aIgnoreWrap);
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::InitializeKeyboardEventListeners()
|
2010-04-22 00:17:41 +04:00
|
|
|
{
|
2012-04-24 08:19:26 +04:00
|
|
|
mState.InitializeKeyboardEventListeners();
|
2010-04-22 00:17:41 +04:00
|
|
|
}
|
2010-08-21 21:52:57 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
2016-08-06 18:59:08 +03:00
|
|
|
HTMLTextAreaElement::OnValueChanged(bool aNotify, bool aWasInteractiveUserChange)
|
2010-08-21 21:52:57 +04:00
|
|
|
{
|
2016-08-06 18:59:08 +03:00
|
|
|
mLastValueChangeWasInteractive = aWasInteractiveUserChange;
|
|
|
|
|
2010-08-21 21:52:57 +04:00
|
|
|
// Update the validity state
|
2011-09-29 10:19:26 +04:00
|
|
|
bool validBefore = IsValid();
|
2010-08-21 21:52:57 +04:00
|
|
|
UpdateTooLongValidityState();
|
2016-08-17 07:11:24 +03:00
|
|
|
UpdateTooShortValidityState();
|
2010-08-21 21:52:57 +04:00
|
|
|
UpdateValueMissingValidityState();
|
|
|
|
|
2016-08-31 21:21:44 +03:00
|
|
|
if (validBefore != IsValid() ||
|
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder)) {
|
2011-06-01 05:46:57 +04:00
|
|
|
UpdateState(aNotify);
|
2010-08-21 21:52:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::HasCachedSelection()
|
2011-07-30 01:31:57 +04:00
|
|
|
{
|
2012-04-24 08:19:26 +04:00
|
|
|
return mState.IsSelectionCached();
|
2011-07-30 01:31:57 +04:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:33:16 +04:00
|
|
|
void
|
2013-02-19 01:18:40 +04:00
|
|
|
HTMLTextAreaElement::FieldSetDisabledChanged(bool aNotify)
|
2010-09-19 01:33:16 +04:00
|
|
|
{
|
|
|
|
UpdateValueMissingValidityState();
|
|
|
|
UpdateBarredFromConstraintValidation();
|
|
|
|
|
2013-08-02 05:21:31 +04:00
|
|
|
nsGenericHTMLFormElementWithState::FieldSetDisabledChanged(aNotify);
|
2010-09-19 01:33:16 +04:00
|
|
|
}
|
2013-02-19 01:18:40 +04:00
|
|
|
|
2013-02-19 09:54:23 +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
|
|
|
HTMLTextAreaElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-19 09:54:23 +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 HTMLTextAreaElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-19 09:54:23 +04:00
|
|
|
}
|
|
|
|
|
2013-02-19 01:18:40 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|