2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=2 et tw=80: */
|
2012-05-21 04:12:37 -07: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 00:52:24 -07:00
|
|
|
|
2013-02-18 13:18:40 -08:00
|
|
|
#include "mozilla/dom/HTMLTextAreaElement.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
|
|
|
|
#include "mozAutoDocUpdate.h"
|
2014-03-16 23:56:54 -07:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-02-18 21:54:23 -08:00
|
|
|
#include "mozilla/dom/HTMLTextAreaElementBinding.h"
|
2014-03-17 21:48:21 -07:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-02 21:18:36 -07:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsAttrValueInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsContentCID.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsFocusManager.h"
|
|
|
|
#include "nsFormSubmission.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIComponentManager.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsIConstraintValidation.h"
|
|
|
|
#include "nsIControllers.h"
|
|
|
|
#include "nsIDocument.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsIFormControlFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIForm.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsITextControlFrame.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsLinebreakConverter.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsMappedAttributes.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsPresContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPresState.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2014-10-28 10:33:15 -07:00
|
|
|
#include "nsRuleData.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsStyleConsts.h"
|
2010-04-21 13:17:41 -07:00
|
|
|
#include "nsTextEditorState.h"
|
2013-09-22 16:23:30 -07:00
|
|
|
#include "nsIController.h"
|
2010-04-21 13:17:41 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
|
|
|
|
|
|
|
|
#define NS_NO_CONTENT_DISPATCH (1 << 0)
|
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(TextArea)
|
|
|
|
|
2013-02-18 13:18:40 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
HTMLTextAreaElement::HTMLTextAreaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
|
2013-02-18 13:18:40 -08:00
|
|
|
FromParser aFromParser)
|
2013-08-01 18:21:31 -07:00
|
|
|
: nsGenericHTMLFormElementWithState(aNodeInfo),
|
2011-10-17 07:59:28 -07:00
|
|
|
mValueChanged(false),
|
|
|
|
mHandlingSelect(false),
|
2007-03-22 10:30:00 -07:00
|
|
|
mDoneAddingChildren(!aFromParser),
|
2010-10-25 05:17:38 -07:00
|
|
|
mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT)),
|
2011-10-17 07:59:28 -07:00
|
|
|
mDisabledChanged(false),
|
|
|
|
mCanShowInvalidUI(true),
|
|
|
|
mCanShowValidUI(true),
|
2013-07-10 02:56:47 -07:00
|
|
|
mState(MOZ_THIS_IN_INITIALIZER_LIST())
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
AddMutationObserver(this);
|
2011-05-31 18:46:57 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLTextAreaElement,
|
|
|
|
nsGenericHTMLFormElementWithState,
|
|
|
|
mValidity,
|
|
|
|
mControllers,
|
|
|
|
mState)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-18 13:18:40 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLTextAreaElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLTextAreaElement, Element)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2013-02-18 13:18:40 -08:00
|
|
|
// QueryInterface implementation for HTMLTextAreaElement
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLTextAreaElement)
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(HTMLTextAreaElement,
|
|
|
|
nsIDOMHTMLTextAreaElement,
|
|
|
|
nsITextControlElement,
|
|
|
|
nsIDOMNSEditableElement,
|
|
|
|
nsIMutationObserver,
|
|
|
|
nsIConstraintValidation)
|
2013-08-07 13:23:08 -07:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLFormElementWithState)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
// nsIDOMHTMLTextAreaElement
|
|
|
|
|
|
|
|
|
2013-02-18 13:18:40 -08:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLTextAreaElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-21 11:52:49 -07:00
|
|
|
// nsIConstraintValidation
|
2013-02-18 13:18:40 -08:00
|
|
|
NS_IMPL_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY(HTMLTextAreaElement)
|
2010-08-18 11:28:08 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-01 18:21:31 -07:00
|
|
|
return nsGenericHTMLFormElementWithState::GetForm(aForm);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsIContent
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::Select()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-07 11:53:23 -07:00
|
|
|
// XXX Bug? We have to give the input focus before contents can be
|
|
|
|
// selected
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-07 11:53:23 -07:00
|
|
|
FocusTristate state = FocusState();
|
|
|
|
if (state == eUnfocusable) {
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07: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 11:00:39 -07:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
|
2014-08-22 13:11:27 -07:00
|
|
|
nsRefPtr<nsPresContext> presContext = GetPresContext(eForComposedDoc);
|
2008-10-07 11:53:23 -07: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 11:00:39 -07:00
|
|
|
if (fm)
|
|
|
|
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
|
2008-10-07 11:53:23 -07:00
|
|
|
SelectAll(presContext);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent event(true, NS_FORM_SELECTED, nullptr);
|
2013-03-28 12:41:32 -07:00
|
|
|
// XXXbz HTMLInputElement guards against this reentering; shouldn't we?
|
2014-03-17 21:48:21 -07:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext,
|
|
|
|
&event, nullptr, &status);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If the DOM event was not canceled (e.g. by a JS event handler
|
|
|
|
// returning false)
|
|
|
|
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 11:00:39 -07: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);
|
2007-03-22 10:30:00 -07: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 11:00:39 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SelectAll(nsPresContext* aPresContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsIFormControlFrame* formControlFrame = GetFormControlFrame(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (formControlFrame) {
|
|
|
|
formControlFrame->SetFormProperty(nsGkAtoms::select, EmptyString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-02-18 13:18:40 -08: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 11:00:39 -07:00
|
|
|
{
|
2013-08-01 18:21:31 -07:00
|
|
|
if (nsGenericHTMLFormElementWithState::IsHTMLFocusable(aWithMouse, aIsFocusable,
|
|
|
|
aTabIndex))
|
|
|
|
{
|
2011-10-17 07:59:28 -07: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 11:00:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// disabled textareas are not focusable
|
2010-09-18 14:33:16 -07:00
|
|
|
*aIsFocusable = !IsDisabled();
|
2011-10-17 07:59:28 -07: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 11:00:39 -07:00
|
|
|
}
|
|
|
|
|
2013-02-18 13:18:40 -08: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)
|
|
|
|
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)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-06 00:19:51 -07:00
|
|
|
int32_t
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::TabIndexDefault()
|
2012-10-06 00:19:51 -07:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetType(nsAString& aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aType.AssignLiteral("textarea");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetValue(nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
GetValueInternal(aValue, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetValueInternal(nsAString& aValue, bool aIgnoreWrap) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
mState.GetValue(aValue, aIgnoreWrap);
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsIEditor*)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetTextEditor()
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2013-02-18 21:54:23 -08:00
|
|
|
return GetEditor();
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsISelectionController*)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetSelectionController()
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
return mState.GetSelectionController();
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsFrameSelection*)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetConstFrameSelection()
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
return mState.GetConstFrameSelection();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::BindToFrame(nsTextControlFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
return mState.BindToFrame(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-04-21 13:17:41 -07:00
|
|
|
NS_IMETHODIMP_(void)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::UnbindFromFrame(nsTextControlFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-21 17:59:25 -07:00
|
|
|
if (aFrame) {
|
2012-04-23 21:19:26 -07:00
|
|
|
mState.UnbindFromFrame(aFrame);
|
2010-07-21 17:59:25 -07:00
|
|
|
}
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-21 13:17:41 -07:00
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::CreateEditor()
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
return mState.PrepareEditor();
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-21 13:17:41 -07:00
|
|
|
NS_IMETHODIMP_(nsIContent*)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetRootEditorNode()
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
return mState.GetRootNode();
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-03 06:40:12 -08:00
|
|
|
NS_IMETHODIMP_(Element*)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::CreatePlaceholderNode()
|
2010-10-19 06:11:07 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(mState.CreatePlaceholderNode(), nullptr);
|
2012-04-23 21:19:26 -07:00
|
|
|
return mState.GetPlaceholderNode();
|
2010-10-19 06:11:07 -07:00
|
|
|
}
|
|
|
|
|
2013-12-03 06:40:12 -08:00
|
|
|
NS_IMETHODIMP_(Element*)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetPlaceholderNode()
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
return mState.GetPlaceholderNode();
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::UpdatePlaceholderVisibility(bool aNotify)
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2012-11-09 02:31:34 -08:00
|
|
|
mState.UpdatePlaceholderVisibility(aNotify);
|
2012-11-09 02:22:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetPlaceholderVisibility()
|
2012-11-09 02:22:29 -08:00
|
|
|
{
|
|
|
|
return mState.GetPlaceholderVisibility();
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SetValueInternal(const nsAString& aValue,
|
|
|
|
bool aUserInput)
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
|
|
|
// Need to set the value changed flag here, so that
|
|
|
|
// nsTextControlFrame::UpdateValueDisplay retrieves the correct value
|
|
|
|
// if needed.
|
2011-10-17 07:59:28 -07:00
|
|
|
SetValueChanged(true);
|
2012-05-31 09:01:30 -07:00
|
|
|
mState.SetValue(aValue, aUserInput, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SetValue(const nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-05 05:40:13 -07: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);
|
|
|
|
|
2012-05-07 09:27:24 -07:00
|
|
|
SetValueInternal(aValue, false);
|
2012-09-05 05:40:13 -07:00
|
|
|
|
|
|
|
if (mFocusedValue.Equals(currentValue)) {
|
|
|
|
GetValueInternal(mFocusedValue, true);
|
|
|
|
}
|
|
|
|
|
2012-05-07 09:27:24 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-10-02 09:56:07 -07:00
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SetUserInput(const nsAString& aValue)
|
2007-10-02 09:56:07 -07:00
|
|
|
{
|
2012-10-25 16:10:54 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2007-10-02 09:56:07 -07:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
SetValueInternal(aValue, true);
|
2007-10-02 09:56:07 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SetValueChanged(bool aValueChanged)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool previousValue = mValueChanged;
|
2010-11-23 15:46:49 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mValueChanged = aValueChanged;
|
2013-03-25 12:35:55 -07:00
|
|
|
if (!aValueChanged && !mState.IsEmpty()) {
|
|
|
|
mState.EmptyValue();
|
|
|
|
}
|
2010-08-24 21:39:10 -07:00
|
|
|
|
2010-11-23 15:49:50 -08:00
|
|
|
if (mValueChanged != previousValue) {
|
2011-05-31 18:46:57 -07:00
|
|
|
UpdateState(true);
|
2010-08-24 21:39:10 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetDefaultValue(nsAString& aDefaultValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-03-20 12:51:16 -07:00
|
|
|
if (!nsContentUtils::GetNodeTextContent(this, false, aDefaultValue)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SetDefaultValue(const nsAString& aDefaultValue)
|
2013-02-18 21:54:23 -08:00
|
|
|
{
|
|
|
|
ErrorResult error;
|
|
|
|
SetDefaultValue(aDefaultValue, error);
|
|
|
|
return error.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetDefaultValue(const nsAString& aDefaultValue, ErrorResult& aError)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsresult rv = nsContentUtils::SetNodeTextContent(this, aDefaultValue, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && !mValueChanged) {
|
|
|
|
Reset();
|
|
|
|
}
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2010-01-18 07:53:59 -08:00
|
|
|
if (aAttribute == nsGkAtoms::maxlength) {
|
2010-03-05 11:38:26 -08:00
|
|
|
return aResult.ParseNonNegativeIntValue(aValue);
|
2011-03-24 05:04:23 -07:00
|
|
|
} else if (aAttribute == nsGkAtoms::cols ||
|
|
|
|
aAttribute == nsGkAtoms::rows) {
|
|
|
|
return aResult.ParsePositiveIntValue(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
2013-11-19 11:21:29 -08:00
|
|
|
void
|
|
|
|
HTMLTextAreaElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|
|
|
nsRuleData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-10-28 10:33:15 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
|
|
|
|
// wrap=off
|
|
|
|
nsCSSValue* whiteSpace = aData->ValueForWhiteSpace();
|
|
|
|
if (whiteSpace->GetUnit() == eCSSUnit_Null) {
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::wrap);
|
|
|
|
if (value && value->Type() == nsAttrValue::eString &&
|
|
|
|
value->Equals(nsGkAtoms::OFF, eIgnoreCase)) {
|
|
|
|
whiteSpace->SetIntValue(NS_STYLE_WHITESPACE_PRE, eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-01 18:21:31 -07:00
|
|
|
nsGenericHTMLFormElementWithState::MapDivAlignAttributeInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLFormElementWithState::MapCommonAttributesInto(aAttributes, aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsChangeHint
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsChangeHint retval =
|
2013-08-01 18:21:31 -07:00
|
|
|
nsGenericHTMLFormElementWithState::GetAttributeChangeHint(aAttribute, aModType);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aAttribute == nsGkAtoms::rows ||
|
|
|
|
aAttribute == nsGkAtoms::cols) {
|
|
|
|
NS_UpdateHint(retval, NS_STYLE_HINT_REFLOW);
|
2010-02-06 00:51:10 -08:00
|
|
|
} else if (aAttribute == nsGkAtoms::wrap) {
|
|
|
|
NS_UpdateHint(retval, nsChangeHint_ReconstructFrame);
|
2010-10-19 06:11:07 -07:00
|
|
|
} else if (aAttribute == nsGkAtoms::placeholder) {
|
|
|
|
NS_UpdateHint(retval, NS_STYLE_HINT_FRAMECHANGE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-10-30 06:09:22 -07:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2014-10-28 10:33:15 -07:00
|
|
|
{ &nsGkAtoms::wrap },
|
|
|
|
{ nullptr }
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2014-10-28 10:33:15 -07:00
|
|
|
attributes,
|
2007-03-22 10:30:00 -07:00
|
|
|
sDivAlignAttributeMap,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 02:09:27 -08:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMapRuleToAttributesFunc
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetAttributeMappingFunction() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return &MapAttributesIntoRule;
|
|
|
|
}
|
|
|
|
|
2013-01-03 07:17:36 -08:00
|
|
|
bool
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsDisabledForEvents(uint32_t aMessage)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsIFormControlFrame* formControlFrame = GetFormControlFrame(false);
|
2014-03-25 08:36:49 -07:00
|
|
|
nsIFrame* formFrame = do_QueryFrame(formControlFrame);
|
2013-01-03 07:17:36 -08:00
|
|
|
return IsElementDisabledForEvents(aMessage, formFrame);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-03 07:17:36 -08:00
|
|
|
nsresult
|
2014-03-17 21:48:19 -07:00
|
|
|
HTMLTextAreaElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
2013-01-03 07:17:36 -08:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
aVisitor.mCanHandle = false;
|
2013-01-03 07:17:36 -08:00
|
|
|
if (IsDisabledForEvents(aVisitor.mEvent->message)) {
|
2011-07-18 16:16:44 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't dispatch a second select event if we are already handling
|
|
|
|
// one.
|
|
|
|
if (aVisitor.mEvent->message == NS_FORM_SELECTED) {
|
|
|
|
if (mHandlingSelect) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mHandlingSelect = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-15 17:26:05 -08:00
|
|
|
// If noContentDispatch is true we will not allow content to handle
|
2007-03-22 10:30:00 -07: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-15 17:26:05 -08:00
|
|
|
if (aVisitor.mEvent->mFlags.mNoContentDispatch) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aVisitor.mItemFlags |= NS_NO_CONTENT_DISPATCH;
|
2012-12-15 17:26:05 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aVisitor.mEvent->message == NS_MOUSE_CLICK &&
|
2013-10-22 01:55:20 -07:00
|
|
|
aVisitor.mEvent->AsMouseEvent()->button ==
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent::eMiddleButton) {
|
2012-12-15 17:26:05 -08:00
|
|
|
aVisitor.mEvent->mFlags.mNoContentDispatch = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fire onchange (if necessary), before we do the blur, bug 370521.
|
|
|
|
if (aVisitor.mEvent->message == NS_BLUR_CONTENT) {
|
2012-05-07 09:27:24 -07:00
|
|
|
FireChangeEventIfNeeded();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-01 18:21:31 -07:00
|
|
|
return nsGenericHTMLFormElementWithState::PreHandleEvent(aVisitor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-24 03:54:25 -07:00
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::FireChangeEventIfNeeded()
|
2012-05-24 03:54:25 -07: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 09:27:24 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2014-03-17 21:48:20 -07:00
|
|
|
HTMLTextAreaElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aVisitor.mEvent->message == NS_FORM_SELECTED) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHandlingSelect = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-11-23 15:50:53 -08:00
|
|
|
if (aVisitor.mEvent->message == NS_FOCUS_CONTENT ||
|
|
|
|
aVisitor.mEvent->message == NS_BLUR_CONTENT) {
|
|
|
|
if (aVisitor.mEvent->message == NS_FOCUS_CONTENT) {
|
|
|
|
// If the invalid UI is shown, we should show it while focusing (and
|
|
|
|
// update). Otherwise, we should not.
|
2012-05-07 09:27:24 -07:00
|
|
|
GetValueInternal(mFocusedValue, true);
|
2011-01-20 03:05:29 -08:00
|
|
|
mCanShowInvalidUI = !IsValid() && ShouldShowValidityUI();
|
2010-11-23 15:56:24 -08:00
|
|
|
|
|
|
|
// If neither invalid UI nor valid UI is shown, we shouldn't show the valid
|
|
|
|
// UI while typing.
|
2011-01-20 03:05:29 -08:00
|
|
|
mCanShowValidUI = ShouldShowValidityUI();
|
2010-11-23 15:50:53 -08:00
|
|
|
} else { // NS_BLUR_CONTENT
|
2011-10-17 07:59:28 -07:00
|
|
|
mCanShowInvalidUI = true;
|
|
|
|
mCanShowValidUI = true;
|
2010-11-23 15:50:53 -08:00
|
|
|
}
|
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
UpdateState(true);
|
2010-08-24 21:39:10 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Reset the flag for other content besides this text field
|
2012-12-15 17:26:05 -08:00
|
|
|
aVisitor.mEvent->mFlags.mNoContentDispatch =
|
|
|
|
((aVisitor.mItemFlags & NS_NO_CONTENT_DISPATCH) != 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-15 23:50:18 -08:00
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::DoneAddingChildren(bool aHaveNotified)
|
2007-03-22 10:30:00 -07: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-01 18:21:31 -07:00
|
|
|
|
2010-06-08 23:45:32 -07:00
|
|
|
if (!mInhibitStateRestoration) {
|
2013-08-01 18:21:31 -07:00
|
|
|
nsresult rv = GenerateStateKey();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
RestoreFormControlState();
|
|
|
|
}
|
2010-06-08 23:45:32 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mDoneAddingChildren = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsDoneAddingChildren()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mDoneAddingChildren;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Controllers Methods
|
|
|
|
|
2013-02-18 21:54:23 -08:00
|
|
|
nsIControllers*
|
|
|
|
HTMLTextAreaElement::GetControllers(ErrorResult& aError)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mControllers)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
mControllers = do_CreateInstance(kXULControllersCID, &rv);
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/editor/editorcontroller;1", &rv);
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mControllers->AppendController(controller);
|
2011-12-23 16:11:30 -08:00
|
|
|
|
|
|
|
controller = do_CreateInstance("@mozilla.org/editor/editingcontroller;1", &rv);
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-12-23 16:11:30 -08:00
|
|
|
|
|
|
|
mControllers->AppendController(controller);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-18 21:54:23 -08:00
|
|
|
return mControllers;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLTextAreaElement::GetControllers(nsIControllers** aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
|
|
|
ErrorResult error;
|
|
|
|
*aResult = GetControllers(error);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
|
2013-02-18 21:54:23 -08:00
|
|
|
return error.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
HTMLTextAreaElement::GetTextLength()
|
|
|
|
{
|
|
|
|
nsAutoString val;
|
|
|
|
GetValue(val);
|
|
|
|
return val.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetTextLength(int32_t *aTextLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aTextLength);
|
2013-02-18 21:54:23 -08:00
|
|
|
*aTextLength = GetTextLength();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-18 21:54:23 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetSelectionStart(int32_t *aSelectionStart)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aSelectionStart);
|
2011-07-29 14:31:57 -07:00
|
|
|
|
2013-02-18 21:54:23 -08:00
|
|
|
ErrorResult error;
|
|
|
|
*aSelectionStart = GetSelectionStart(error);
|
|
|
|
return error.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
HTMLTextAreaElement::GetSelectionStart(ErrorResult& aError)
|
|
|
|
{
|
|
|
|
int32_t selStart, selEnd;
|
|
|
|
nsresult rv = GetSelectionRange(&selStart, &selEnd);
|
2011-10-07 06:40:11 -07:00
|
|
|
|
2012-04-23 21:19:26 -07:00
|
|
|
if (NS_FAILED(rv) && mState.IsSelectionCached()) {
|
2013-02-18 21:54:23 -08:00
|
|
|
return mState.GetSelectionProperties().mStart;
|
2013-02-18 21:54:23 -08:00
|
|
|
}
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
|
|
|
return selStart;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SetSelectionStart(int32_t aSelectionStart)
|
2013-02-18 21:54:23 -08:00
|
|
|
{
|
|
|
|
ErrorResult error;
|
|
|
|
SetSelectionStart(aSelectionStart, error);
|
|
|
|
return error.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetSelectionStart(uint32_t aSelectionStart, ErrorResult& aError)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
if (mState.IsSelectionCached()) {
|
|
|
|
mState.GetSelectionProperties().mStart = aSelectionStart;
|
2013-02-18 21:54:23 -08:00
|
|
|
return;
|
2011-07-29 14:31:57 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 10:51:22 -07:00
|
|
|
nsAutoString direction;
|
|
|
|
nsresult rv = GetSelectionDirection(direction);
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t start, end;
|
2011-07-28 10:51:22 -07:00
|
|
|
rv = GetSelectionRange(&start, &end);
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2011-07-28 10:51:22 -07:00
|
|
|
start = aSelectionStart;
|
|
|
|
if (end < start) {
|
|
|
|
end = start;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-02-18 21:54:23 -08:00
|
|
|
rv = SetSelectionRange(start, end, direction);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetSelectionEnd(int32_t *aSelectionEnd)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aSelectionEnd);
|
2011-07-29 14:31:57 -07:00
|
|
|
|
2013-02-18 21:54:23 -08:00
|
|
|
ErrorResult error;
|
|
|
|
*aSelectionEnd = GetSelectionEnd(error);
|
|
|
|
return error.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
HTMLTextAreaElement::GetSelectionEnd(ErrorResult& aError)
|
|
|
|
{
|
|
|
|
int32_t selStart, selEnd;
|
|
|
|
nsresult rv = GetSelectionRange(&selStart, &selEnd);
|
2011-10-07 06:40:11 -07:00
|
|
|
|
2012-04-23 21:19:26 -07:00
|
|
|
if (NS_FAILED(rv) && mState.IsSelectionCached()) {
|
2013-02-18 21:54:23 -08:00
|
|
|
return mState.GetSelectionProperties().mEnd;
|
2013-02-18 21:54:23 -08:00
|
|
|
}
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
|
|
|
return selEnd;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SetSelectionEnd(int32_t aSelectionEnd)
|
2013-02-18 21:54:23 -08:00
|
|
|
{
|
|
|
|
ErrorResult error;
|
|
|
|
SetSelectionEnd(aSelectionEnd, error);
|
|
|
|
return error.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetSelectionEnd(uint32_t aSelectionEnd, ErrorResult& aError)
|
2011-07-28 10:51:22 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
if (mState.IsSelectionCached()) {
|
|
|
|
mState.GetSelectionProperties().mEnd = aSelectionEnd;
|
2013-02-18 21:54:23 -08:00
|
|
|
return;
|
2011-07-29 14:31:57 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 10:51:22 -07:00
|
|
|
nsAutoString direction;
|
|
|
|
nsresult rv = GetSelectionDirection(direction);
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t start, end;
|
2011-07-28 10:51:22 -07:00
|
|
|
rv = GetSelectionRange(&start, &end);
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2011-07-28 10:51:22 -07:00
|
|
|
end = aSelectionEnd;
|
|
|
|
if (start > end) {
|
|
|
|
start = end;
|
|
|
|
}
|
2013-02-18 21:54:23 -08:00
|
|
|
rv = SetSelectionRange(start, end, direction);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
2011-07-28 10:51:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetSelectionRange(int32_t* aSelectionStart,
|
|
|
|
int32_t* aSelectionEnd)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsIFormControlFrame* formControlFrame = GetFormControlFrame(true);
|
2014-03-25 08:36:49 -07:00
|
|
|
nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
|
|
|
|
if (textControlFrame) {
|
|
|
|
return textControlFrame->GetSelectionRange(aSelectionStart, aSelectionEnd);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-25 08:36:49 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-07-29 14:31:57 -07:00
|
|
|
static void
|
|
|
|
DirectionToName(nsITextControlFrame::SelectionDirection dir, nsAString& aDirection)
|
|
|
|
{
|
|
|
|
if (dir == nsITextControlFrame::eNone) {
|
|
|
|
aDirection.AssignLiteral("none");
|
|
|
|
} else if (dir == nsITextControlFrame::eForward) {
|
|
|
|
aDirection.AssignLiteral("forward");
|
|
|
|
} else if (dir == nsITextControlFrame::eBackward) {
|
|
|
|
aDirection.AssignLiteral("backward");
|
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("Invalid SelectionDirection value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetSelectionDirection(nsAString& aDirection)
|
2013-02-18 21:54:23 -08:00
|
|
|
{
|
|
|
|
ErrorResult error;
|
|
|
|
GetSelectionDirection(aDirection, error);
|
|
|
|
return error.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLTextAreaElement::GetSelectionDirection(nsAString& aDirection, ErrorResult& aError)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2011-10-17 07:59:28 -07:00
|
|
|
nsIFormControlFrame* formControlFrame = GetFormControlFrame(true);
|
2014-03-25 08:36:49 -07:00
|
|
|
nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
|
|
|
|
if (textControlFrame) {
|
|
|
|
nsITextControlFrame::SelectionDirection dir;
|
|
|
|
rv = textControlFrame->GetSelectionRange(nullptr, nullptr, &dir);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
DirectionToName(dir, aDirection);
|
2011-07-28 10:51:22 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-07 06:40:11 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-04-23 21:19:26 -07:00
|
|
|
if (mState.IsSelectionCached()) {
|
|
|
|
DirectionToName(mState.GetSelectionProperties().mDirection, aDirection);
|
2013-02-18 21:54:23 -08:00
|
|
|
return;
|
2011-10-07 06:40:11 -07:00
|
|
|
}
|
2013-02-18 21:54:23 -08:00
|
|
|
aError.Throw(rv);
|
2011-10-07 06:40:11 -07:00
|
|
|
}
|
2013-02-18 21:54:23 -08:00
|
|
|
}
|
|
|
|
|
2013-02-22 12:30:06 -08:00
|
|
|
NS_IMETHODIMP
|
2013-02-18 21:54:23 -08:00
|
|
|
HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection)
|
|
|
|
{
|
|
|
|
ErrorResult error;
|
|
|
|
SetSelectionDirection(aDirection, error);
|
|
|
|
return error.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection, ErrorResult& aError)
|
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
if (mState.IsSelectionCached()) {
|
2011-07-29 14:31:57 -07:00
|
|
|
nsITextControlFrame::SelectionDirection dir = nsITextControlFrame::eNone;
|
|
|
|
if (aDirection.EqualsLiteral("forward")) {
|
|
|
|
dir = nsITextControlFrame::eForward;
|
|
|
|
} else if (aDirection.EqualsLiteral("backward")) {
|
|
|
|
dir = nsITextControlFrame::eBackward;
|
|
|
|
}
|
2012-04-23 21:19:26 -07:00
|
|
|
mState.GetSelectionProperties().mDirection = dir;
|
2013-02-18 21:54:23 -08:00
|
|
|
return;
|
2011-07-29 14:31:57 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t start, end;
|
2011-07-28 10:51:22 -07:00
|
|
|
nsresult rv = GetSelectionRange(&start, &end);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = SetSelectionRange(start, end, aDirection);
|
|
|
|
}
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
2011-07-28 10:51:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SetSelectionRange(int32_t aSelectionStart,
|
|
|
|
int32_t aSelectionEnd,
|
|
|
|
const nsAString& aDirection)
|
2013-02-18 21:54:23 -08:00
|
|
|
{
|
|
|
|
ErrorResult error;
|
|
|
|
Optional<nsAString> dir;
|
|
|
|
dir = &aDirection;
|
|
|
|
SetSelectionRange(aSelectionStart, aSelectionEnd, dir, error);
|
|
|
|
return error.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetSelectionRange(uint32_t aSelectionStart,
|
|
|
|
uint32_t aSelectionEnd,
|
|
|
|
const Optional<nsAString>& aDirection,
|
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2011-10-17 07:59:28 -07:00
|
|
|
nsIFormControlFrame* formControlFrame = GetFormControlFrame(true);
|
2014-03-25 08:36:49 -07:00
|
|
|
nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
|
|
|
|
if (textControlFrame) {
|
|
|
|
// Default to forward, even if not specified.
|
|
|
|
// Note that we don't currently support directionless selections, so
|
|
|
|
// "none" is treated like "forward".
|
|
|
|
nsITextControlFrame::SelectionDirection dir = nsITextControlFrame::eForward;
|
|
|
|
if (aDirection.WasPassed() && aDirection.Value().EqualsLiteral("backward")) {
|
|
|
|
dir = nsITextControlFrame::eBackward;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-25 08:36:49 -07:00
|
|
|
rv = textControlFrame->SetSelectionRange(aSelectionStart, aSelectionEnd, dir);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = textControlFrame->ScrollSelectionIntoView();
|
|
|
|
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
|
|
|
|
new AsyncEventDispatcher(this, NS_LITERAL_STRING("select"),
|
|
|
|
true, false);
|
|
|
|
asyncDispatcher->PostDOMEvent();
|
2011-02-04 16:29:29 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-18 21:54:23 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-04 08:30:07 -07:00
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetRangeText(const nsAString& aReplacement,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
int32_t start, end;
|
|
|
|
aRv = GetSelectionRange(&start, &end);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
if (mState.IsSelectionCached()) {
|
|
|
|
start = mState.GetSelectionProperties().mStart;
|
|
|
|
end = mState.GetSelectionProperties().mEnd;
|
|
|
|
aRv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetRangeText(aReplacement, start, end, mozilla::dom::SelectionMode::Preserve,
|
|
|
|
aRv, start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLTextAreaElement::SetRangeText(const nsAString& aReplacement,
|
|
|
|
uint32_t aStart, uint32_t aEnd,
|
|
|
|
const SelectionMode& aSelectMode,
|
|
|
|
ErrorResult& aRv, int32_t aSelectionStart,
|
|
|
|
int32_t aSelectionEnd)
|
|
|
|
{
|
|
|
|
if (aStart > aEnd) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
GetValueInternal(value, false);
|
|
|
|
uint32_t inputValueLength = value.Length();
|
|
|
|
|
|
|
|
if (aStart > inputValueLength) {
|
|
|
|
aStart = inputValueLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEnd > inputValueLength) {
|
|
|
|
aEnd = inputValueLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSelectionStart == -1 && aSelectionEnd == -1) {
|
2013-12-17 05:30:24 -08:00
|
|
|
aRv = GetSelectionRange(&aSelectionStart, &aSelectionEnd);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
if (mState.IsSelectionCached()) {
|
|
|
|
aSelectionStart = mState.GetSelectionProperties().mStart;
|
|
|
|
aSelectionEnd = mState.GetSelectionProperties().mEnd;
|
|
|
|
aRv = NS_OK;
|
2013-10-04 08:30:07 -07:00
|
|
|
}
|
2013-12-17 05:30:24 -08:00
|
|
|
}
|
2013-10-04 08:30:07 -07:00
|
|
|
}
|
|
|
|
|
2013-12-17 05:30:24 -08:00
|
|
|
if (aStart <= aEnd) {
|
2013-10-04 08:30:07 -07:00
|
|
|
value.Replace(aStart, aEnd - aStart, aReplacement);
|
|
|
|
SetValueInternal(value, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t newEnd = aStart + aReplacement.Length();
|
|
|
|
int32_t delta = aReplacement.Length() - (aEnd - aStart);
|
|
|
|
|
|
|
|
switch (aSelectMode) {
|
|
|
|
case mozilla::dom::SelectionMode::Select:
|
|
|
|
{
|
|
|
|
aSelectionStart = aStart;
|
|
|
|
aSelectionEnd = newEnd;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case mozilla::dom::SelectionMode::Start:
|
|
|
|
{
|
|
|
|
aSelectionStart = aSelectionEnd = aStart;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case mozilla::dom::SelectionMode::End:
|
|
|
|
{
|
|
|
|
aSelectionStart = aSelectionEnd = newEnd;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case mozilla::dom::SelectionMode::Preserve:
|
|
|
|
{
|
2013-12-17 05:30:24 -08:00
|
|
|
if ((uint32_t)aSelectionStart > aEnd) {
|
2013-10-04 08:30:07 -07:00
|
|
|
aSelectionStart += delta;
|
2013-12-17 05:30:24 -08:00
|
|
|
} else if ((uint32_t)aSelectionStart > aStart) {
|
|
|
|
aSelectionStart = aStart;
|
|
|
|
}
|
2013-10-04 08:30:07 -07:00
|
|
|
|
2013-12-17 05:30:24 -08:00
|
|
|
if ((uint32_t)aSelectionEnd > aEnd) {
|
2013-10-04 08:30:07 -07:00
|
|
|
aSelectionEnd += delta;
|
2013-12-17 05:30:24 -08:00
|
|
|
} else if ((uint32_t)aSelectionEnd > aStart) {
|
2013-10-04 08:30:07 -07:00
|
|
|
aSelectionEnd = newEnd;
|
2013-12-17 05:30:24 -08:00
|
|
|
}
|
2013-10-04 08:30:07 -07:00
|
|
|
}
|
|
|
|
break;
|
2014-05-16 10:41:31 -07:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown mode!");
|
2013-10-04 08:30:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Optional<nsAString> direction;
|
|
|
|
SetSelectionRange(aSelectionStart, aSelectionEnd, direction, aRv);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::Reset()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2010-08-21 10:52:57 -07:00
|
|
|
|
|
|
|
// To get the initial spellchecking, reset value to
|
|
|
|
// empty string before setting the default value.
|
|
|
|
SetValue(EmptyString());
|
|
|
|
nsAutoString resetVal;
|
|
|
|
GetDefaultValue(resetVal);
|
|
|
|
rv = SetValue(resetVal);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
SetValueChanged(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SubmitNamesValues(nsFormSubmission* aFormSubmission)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Disabled elements don't submit
|
2010-09-18 14:33:16 -07:00
|
|
|
if (IsDisabled()) {
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the name (if no name, no submit)
|
|
|
|
//
|
|
|
|
nsAutoString name;
|
2010-11-23 00:50:55 -08:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::name, name);
|
|
|
|
if (name.IsEmpty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the value
|
|
|
|
//
|
|
|
|
nsAutoString value;
|
2011-10-17 07:59:28 -07:00
|
|
|
GetValueInternal(value, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// Submit
|
|
|
|
//
|
2011-11-15 23:50:19 -08:00
|
|
|
return aFormSubmission->AddNameValuePair(name, value);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SaveState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Only save if value != defaultValue (bug 62713)
|
2012-07-30 07:20:58 -07:00
|
|
|
nsPresState *state = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mValueChanged) {
|
2013-07-24 00:38:13 -07:00
|
|
|
state = GetPrimaryPresState();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (state) {
|
|
|
|
nsAutoString value;
|
2011-10-17 07:59:28 -07:00
|
|
|
GetValueInternal(value, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
rv = nsLinebreakConverter::ConvertStringLineBreaks(
|
|
|
|
value,
|
|
|
|
nsLinebreakConverter::eLinebreakPlatform,
|
|
|
|
nsLinebreakConverter::eLinebreakContent);
|
2007-10-09 20:39:16 -07:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!");
|
2008-12-12 11:25:22 -08:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsISupportsString> pState =
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
|
2008-12-12 11:25:22 -08:00
|
|
|
if (!pState) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
pState->SetData(value);
|
|
|
|
state->SetStateProperty(pState);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDisabledChanged) {
|
|
|
|
if (!state) {
|
2013-07-24 00:38:13 -07:00
|
|
|
state = GetPrimaryPresState();
|
|
|
|
rv = NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (state) {
|
2010-09-18 14:33:16 -07:00
|
|
|
// We do not want to save the real disabled state but the disabled
|
|
|
|
// attribute.
|
|
|
|
state->SetDisabled(HasAttr(kNameSpaceID_None, nsGkAtoms::disabled));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::RestoreState(nsPresState* aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-12-12 11:25:22 -08:00
|
|
|
nsCOMPtr<nsISupportsString> state
|
|
|
|
(do_QueryInterface(aState->GetStateProperty()));
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
nsAutoString data;
|
|
|
|
state->GetData(data);
|
|
|
|
SetValue(data);
|
2008-08-14 03:06:40 -07:00
|
|
|
}
|
2007-10-09 20:39:16 -07:00
|
|
|
|
2008-12-12 11:25:22 -08:00
|
|
|
if (aState->IsDisabledSet()) {
|
|
|
|
SetDisabled(aState->GetDisabled());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IntrinsicState() const
|
2010-08-18 17:03:20 -07:00
|
|
|
{
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates state = nsGenericHTMLFormElementWithState::IntrinsicState();
|
2008-12-12 11:25:22 -08:00
|
|
|
|
2010-08-18 17:03:20 -07:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::required)) {
|
|
|
|
state |= NS_EVENT_STATE_REQUIRED;
|
|
|
|
} else {
|
|
|
|
state |= NS_EVENT_STATE_OPTIONAL;
|
|
|
|
}
|
|
|
|
|
2010-08-21 11:51:38 -07:00
|
|
|
if (IsCandidateForConstraintValidation()) {
|
2010-11-23 15:49:50 -08:00
|
|
|
if (IsValid()) {
|
2010-11-23 15:55:22 -08:00
|
|
|
state |= NS_EVENT_STATE_VALID;
|
2010-11-23 15:49:50 -08:00
|
|
|
} else {
|
|
|
|
state |= NS_EVENT_STATE_INVALID;
|
2011-01-27 05:51:45 -08: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-17 22:00:47 -08:00
|
|
|
(mCanShowInvalidUI && ShouldShowValidityUI()))) {
|
2010-11-23 15:49:50 -08:00
|
|
|
state |= NS_EVENT_STATE_MOZ_UI_INVALID;
|
|
|
|
}
|
|
|
|
}
|
2010-11-23 15:56:24 -08: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 05:51:45 -08: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-23 15:56:24 -08:00
|
|
|
state |= NS_EVENT_STATE_MOZ_UI_VALID;
|
|
|
|
}
|
2010-08-21 10:52:57 -07:00
|
|
|
}
|
|
|
|
|
2010-08-18 17:03:20 -07:00
|
|
|
return state;
|
|
|
|
}
|
2008-12-12 11:25:22 -08:00
|
|
|
|
2010-09-18 14:33:16 -07:00
|
|
|
nsresult
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2010-09-18 14:33:16 -07:00
|
|
|
{
|
2013-08-01 18:21:31 -07:00
|
|
|
nsresult rv = nsGenericHTMLFormElementWithState::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2010-09-18 14:33:16 -07: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-05-31 18:46:57 -07:00
|
|
|
// And now make sure our state is up to date
|
|
|
|
UpdateState(false);
|
|
|
|
|
2010-09-18 14:33:16 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2010-09-18 14:33:16 -07:00
|
|
|
{
|
2013-08-01 18:21:31 -07:00
|
|
|
nsGenericHTMLFormElementWithState::UnbindFromTree(aDeep, aNullParent);
|
2010-09-18 14:33:16 -07:00
|
|
|
|
|
|
|
// We might be no longer disabled because of parent chain changed.
|
|
|
|
UpdateValueMissingValidityState();
|
|
|
|
UpdateBarredFromConstraintValidation();
|
2011-05-31 18:46:57 -07:00
|
|
|
|
|
|
|
// And now make sure our state is up to date
|
|
|
|
UpdateState(false);
|
2010-09-18 14:33:16 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValueOrString* aValue,
|
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aNotify && aName == nsGkAtoms::disabled &&
|
|
|
|
aNameSpaceID == kNameSpaceID_None) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mDisabledChanged = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-01 18:21:31 -07:00
|
|
|
return nsGenericHTMLFormElementWithState::BeforeSetAttr(aNameSpaceID, aName,
|
2007-03-22 10:30:00 -07:00
|
|
|
aValue, aNotify);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
ContentChanged(aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
|
|
|
int32_t /* unused */)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-28 11:04:37 -07:00
|
|
|
ContentChanged(aFirstNewContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t /* unused */)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer,
|
|
|
|
nsIContent* aPreviousSibling)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::ContentChanged(nsIContent* aContent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mValueChanged && mDoneAddingChildren &&
|
|
|
|
nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
|
2010-07-21 08:33:32 -07:00
|
|
|
// Hard to say what the reset can trigger, so be safe pending
|
|
|
|
// further auditing.
|
|
|
|
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
}
|
2007-06-27 19:48:16 -07:00
|
|
|
|
|
|
|
nsresult
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
2007-06-27 19:48:16 -07:00
|
|
|
{
|
2010-08-21 10:52:57 -07:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aName == nsGkAtoms::required || aName == nsGkAtoms::disabled ||
|
|
|
|
aName == nsGkAtoms::readonly) {
|
|
|
|
UpdateValueMissingValidityState();
|
2010-09-09 22:08:56 -07:00
|
|
|
|
|
|
|
// This *has* to be called *after* validity has changed.
|
|
|
|
if (aName == nsGkAtoms::readonly || aName == nsGkAtoms::disabled) {
|
|
|
|
UpdateBarredFromConstraintValidation();
|
|
|
|
}
|
2010-08-21 10:52:57 -07:00
|
|
|
} else if (aName == nsGkAtoms::maxlength) {
|
|
|
|
UpdateTooLongValidityState();
|
|
|
|
}
|
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
UpdateState(aNotify);
|
2007-06-27 19:48:16 -07:00
|
|
|
}
|
2010-08-21 10:52:57 -07:00
|
|
|
|
2013-08-01 18:21:31 -07:00
|
|
|
return nsGenericHTMLFormElementWithState::AfterSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
|
|
|
}
|
2009-12-10 20:02:13 -08:00
|
|
|
|
|
|
|
nsresult
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::CopyInnerTo(Element* aDest)
|
2009-12-10 20:02:13 -08:00
|
|
|
{
|
2013-08-01 18:21:31 -07:00
|
|
|
nsresult rv = nsGenericHTMLFormElementWithState::CopyInnerTo(aDest);
|
2009-12-10 20:02:13 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
if (aDest->OwnerDoc()->IsStaticDocument()) {
|
2009-12-10 20:02:13 -08:00
|
|
|
nsAutoString value;
|
2011-11-15 23:50:19 -08:00
|
|
|
GetValueInternal(value, true);
|
2013-02-18 13:18:40 -08:00
|
|
|
static_cast<HTMLTextAreaElement*>(aDest)->SetValue(value);
|
2009-12-10 20:02:13 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsMutable() const
|
2010-08-18 11:30:41 -07:00
|
|
|
{
|
2010-09-18 14:33:16 -07:00
|
|
|
return (!HasAttr(kNameSpaceID_None, nsGkAtoms::readonly) && !IsDisabled());
|
2010-08-18 11:30:41 -07:00
|
|
|
}
|
|
|
|
|
2011-04-12 23:33:01 -07:00
|
|
|
bool
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsValueEmpty() const
|
2011-04-12 23:33:01 -07:00
|
|
|
{
|
|
|
|
nsAutoString value;
|
2011-10-17 07:59:28 -07:00
|
|
|
GetValueInternal(value, true);
|
2011-04-12 23:33:01 -07:00
|
|
|
|
|
|
|
return value.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2010-08-21 11:52:49 -07:00
|
|
|
// nsIConstraintValidation
|
2010-08-18 11:28:08 -07:00
|
|
|
|
2010-08-21 10:52:57 -07:00
|
|
|
NS_IMETHODIMP
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::SetCustomValidity(const nsAString& aError)
|
2010-08-21 10:52:57 -07:00
|
|
|
{
|
2010-08-21 11:52:49 -07:00
|
|
|
nsIConstraintValidation::SetCustomValidity(aError);
|
2010-08-21 10:52:57 -07:00
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
UpdateState(true);
|
2010-08-21 10:52:57 -07:00
|
|
|
|
2010-08-21 11:51:38 -07:00
|
|
|
return NS_OK;
|
2010-08-21 10:52:57 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsTooLong()
|
2010-08-18 11:28:08 -07:00
|
|
|
{
|
2010-10-07 03:02:29 -07:00
|
|
|
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::maxlength) || !mValueChanged) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-18 11:29:20 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t maxLength = -1;
|
2010-08-18 11:28:08 -07:00
|
|
|
GetMaxLength(&maxLength);
|
2010-10-07 03:02:29 -07:00
|
|
|
|
|
|
|
// Maxlength of -1 means parsing error.
|
|
|
|
if (maxLength == -1) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-10-07 03:02:29 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t textLength = -1;
|
2010-08-18 11:28:08 -07:00
|
|
|
GetTextLength(&textLength);
|
|
|
|
|
2010-10-07 03:02:29 -07:00
|
|
|
return textLength > maxLength;
|
2010-08-18 11:28:08 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsValueMissing() const
|
2010-08-18 11:30:41 -07:00
|
|
|
{
|
|
|
|
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::required) || !IsMutable()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-18 11:30:41 -07:00
|
|
|
}
|
|
|
|
|
2011-04-12 23:33:01 -07:00
|
|
|
return IsValueEmpty();
|
2010-08-18 11:30:41 -07:00
|
|
|
}
|
|
|
|
|
2010-08-21 10:52:57 -07:00
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::UpdateTooLongValidityState()
|
2010-08-21 10:52:57 -07:00
|
|
|
{
|
2010-11-23 06:17:12 -08:00
|
|
|
// TODO: this code will be re-enabled with bug 613016 and bug 613019.
|
|
|
|
#if 0
|
2010-08-21 10:52:57 -07:00
|
|
|
SetValidityState(VALIDITY_STATE_TOO_LONG, IsTooLong());
|
2010-11-23 06:17:12 -08:00
|
|
|
#endif
|
2010-08-21 10:52:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::UpdateValueMissingValidityState()
|
2010-08-21 10:52:57 -07:00
|
|
|
{
|
|
|
|
SetValidityState(VALIDITY_STATE_VALUE_MISSING, IsValueMissing());
|
|
|
|
}
|
|
|
|
|
2010-09-09 22:08:56 -07:00
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::UpdateBarredFromConstraintValidation()
|
2010-08-18 11:28:08 -07:00
|
|
|
{
|
2010-09-09 22:08:56 -07:00
|
|
|
SetBarredFromConstraintValidation(HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::readonly) ||
|
2010-09-18 14:33:16 -07:00
|
|
|
IsDisabled());
|
2010-08-18 11:28:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetValidationMessage(nsAString& aValidationMessage,
|
|
|
|
ValidityStateType aType)
|
2010-08-18 11:28:08 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
switch (aType)
|
|
|
|
{
|
2010-08-21 10:52:57 -07:00
|
|
|
case VALIDITY_STATE_TOO_LONG:
|
2010-08-18 11:28:08 -07:00
|
|
|
{
|
|
|
|
nsXPIDLString message;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t maxLength = -1;
|
|
|
|
int32_t textLength = -1;
|
2010-08-18 11:28:08 -07:00
|
|
|
nsAutoString strMaxLength;
|
|
|
|
nsAutoString strTextLength;
|
|
|
|
|
|
|
|
GetMaxLength(&maxLength);
|
|
|
|
GetTextLength(&textLength);
|
|
|
|
|
|
|
|
strMaxLength.AppendInt(maxLength);
|
|
|
|
strTextLength.AppendInt(textLength);
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* params[] = { strMaxLength.get(), strTextLength.get() };
|
2010-08-18 11:28:08 -07:00
|
|
|
rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES,
|
2010-09-22 18:44:13 -07:00
|
|
|
"FormValidationTextTooLong",
|
2012-03-08 18:22:57 -08:00
|
|
|
params, message);
|
2010-08-18 11:28:08 -07:00
|
|
|
aValidationMessage = message;
|
|
|
|
}
|
|
|
|
break;
|
2010-08-21 10:52:57 -07:00
|
|
|
case VALIDITY_STATE_VALUE_MISSING:
|
2010-08-18 11:30:41 -07:00
|
|
|
{
|
|
|
|
nsXPIDLString message;
|
|
|
|
rv = nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES,
|
2010-09-22 18:44:13 -07:00
|
|
|
"FormValidationValueMissing",
|
2010-08-18 11:30:41 -07:00
|
|
|
message);
|
|
|
|
aValidationMessage = message;
|
|
|
|
}
|
|
|
|
break;
|
2010-08-18 11:28:08 -07:00
|
|
|
default:
|
2010-08-21 11:52:49 -07:00
|
|
|
rv = nsIConstraintValidation::GetValidationMessage(aValidationMessage, aType);
|
2010-08-18 11:28:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsSingleLineTextControl() const
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsTextArea() const
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsPlainTextControl() const
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
|
|
|
// need to check our HTML attribute and/or CSS.
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::IsPasswordTextControl() const
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP_(int32_t)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetCols()
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
|
|
|
const nsAttrValue* attr = GetParsedAttr(nsGkAtoms::cols);
|
|
|
|
if (attr) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t cols = attr->Type() == nsAttrValue::eInteger ?
|
2010-04-21 13:17:41 -07:00
|
|
|
attr->GetIntegerValue() : 0;
|
|
|
|
// XXX why a default of 1 char, why hide it
|
|
|
|
return (cols <= 0) ? 1 : cols;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DEFAULT_COLS;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP_(int32_t)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetWrapCols()
|
2010-04-21 13:17:41 -07: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
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise we just wrap at the given number of columns
|
|
|
|
return GetCols();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP_(int32_t)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetRows()
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
|
|
|
const nsAttrValue* attr = GetParsedAttr(nsGkAtoms::rows);
|
|
|
|
if (attr && attr->Type() == nsAttrValue::eInteger) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t rows = attr->GetIntegerValue();
|
2010-04-21 13:17:41 -07:00
|
|
|
return (rows <= 0) ? DEFAULT_ROWS_TEXTAREA : rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DEFAULT_ROWS_TEXTAREA;
|
|
|
|
}
|
|
|
|
|
2013-03-25 12:35:55 -07:00
|
|
|
NS_IMETHODIMP_(void)
|
2013-03-25 13:22:09 -07:00
|
|
|
HTMLTextAreaElement::GetDefaultValueFromContent(nsAString& aValue)
|
2013-03-25 12:35:55 -07:00
|
|
|
{
|
|
|
|
GetDefaultValue(aValue);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::ValueChanged() const
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
|
|
|
return mValueChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::GetTextEditorValue(nsAString& aValue,
|
|
|
|
bool aIgnoreWrap) const
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
mState.GetValue(aValue, aIgnoreWrap);
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::InitializeKeyboardEventListeners()
|
2010-04-21 13:17:41 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
mState.InitializeKeyboardEventListeners();
|
2010-04-21 13:17:41 -07:00
|
|
|
}
|
2010-08-21 10:52:57 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::OnValueChanged(bool aNotify)
|
2010-08-21 10:52:57 -07:00
|
|
|
{
|
|
|
|
// Update the validity state
|
2011-09-28 23:19:26 -07:00
|
|
|
bool validBefore = IsValid();
|
2010-08-21 10:52:57 -07:00
|
|
|
UpdateTooLongValidityState();
|
|
|
|
UpdateValueMissingValidityState();
|
|
|
|
|
2012-11-09 02:24:23 -08:00
|
|
|
if (validBefore != IsValid()) {
|
2011-05-31 18:46:57 -07:00
|
|
|
UpdateState(aNotify);
|
2010-08-21 10:52:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::HasCachedSelection()
|
2011-07-29 14:31:57 -07:00
|
|
|
{
|
2012-04-23 21:19:26 -07:00
|
|
|
return mState.IsSelectionCached();
|
2011-07-29 14:31:57 -07:00
|
|
|
}
|
|
|
|
|
2010-09-18 14:33:16 -07:00
|
|
|
void
|
2013-02-18 13:18:40 -08:00
|
|
|
HTMLTextAreaElement::FieldSetDisabledChanged(bool aNotify)
|
2010-09-18 14:33:16 -07:00
|
|
|
{
|
|
|
|
UpdateValueMissingValidityState();
|
|
|
|
UpdateBarredFromConstraintValidation();
|
|
|
|
|
2013-08-01 18:21:31 -07:00
|
|
|
nsGenericHTMLFormElementWithState::FieldSetDisabledChanged(aNotify);
|
2010-09-18 14:33:16 -07:00
|
|
|
}
|
2013-02-18 13:18:40 -08:00
|
|
|
|
2013-02-18 21:54:23 -08:00
|
|
|
JSObject*
|
2014-04-08 15:27:17 -07:00
|
|
|
HTMLTextAreaElement::WrapNode(JSContext* aCx)
|
2013-02-18 21:54:23 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return HTMLTextAreaElementBinding::Wrap(aCx, this);
|
2013-02-18 21:54:23 -08:00
|
|
|
}
|
|
|
|
|
2013-02-18 13:18:40 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|