summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/HTMLTextAreaElement.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/WebCore/html/HTMLTextAreaElement.cpp
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/WebCore/html/HTMLTextAreaElement.cpp')
-rw-r--r--Source/WebCore/html/HTMLTextAreaElement.cpp97
1 files changed, 54 insertions, 43 deletions
diff --git a/Source/WebCore/html/HTMLTextAreaElement.cpp b/Source/WebCore/html/HTMLTextAreaElement.cpp
index 838747433..d40d4e810 100644
--- a/Source/WebCore/html/HTMLTextAreaElement.cpp
+++ b/Source/WebCore/html/HTMLTextAreaElement.cpp
@@ -2,7 +2,7 @@
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
* (C) 2006 Alexey Proskuryakov (ap@nypop.com)
* Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
*
@@ -26,6 +26,7 @@
#include "config.h"
#include "HTMLTextAreaElement.h"
+#include "Attribute.h"
#include "BeforeTextInsertedEvent.h"
#include "CSSValueKeywords.h"
#include "Document.h"
@@ -40,7 +41,6 @@
#include "Frame.h"
#include "FrameSelection.h"
#include "HTMLNames.h"
-#include "HTMLParserIdioms.h"
#include "LocalizedStrings.h"
#include "RenderTextControlMultiLine.h"
#include "ShadowRoot.h"
@@ -101,22 +101,21 @@ HTMLTextAreaElement::HTMLTextAreaElement(const QualifiedName& tagName, Document&
setFormControlValueMatchesRenderer(true);
}
-Ref<HTMLTextAreaElement> HTMLTextAreaElement::create(const QualifiedName& tagName, Document& document, HTMLFormElement* form)
+PassRefPtr<HTMLTextAreaElement> HTMLTextAreaElement::create(const QualifiedName& tagName, Document& document, HTMLFormElement* form)
{
- Ref<HTMLTextAreaElement> textArea = adoptRef(*new HTMLTextAreaElement(tagName, document, form));
+ RefPtr<HTMLTextAreaElement> textArea = adoptRef(new HTMLTextAreaElement(tagName, document, form));
textArea->ensureUserAgentShadowRoot();
- return textArea;
+ return textArea.release();
}
void HTMLTextAreaElement::didAddUserAgentShadowRoot(ShadowRoot* root)
{
root->appendChild(TextControlInnerTextElement::create(document()), ASSERT_NO_EXCEPTION);
- updateInnerTextElementEditability();
}
const AtomicString& HTMLTextAreaElement::formControlType() const
{
- static NeverDestroyed<const AtomicString> textarea("textarea", AtomicString::ConstructFromLiteral);
+ DEFINE_STATIC_LOCAL(const AtomicString, textarea, ("textarea", AtomicString::ConstructFromLiteral));
return textarea;
}
@@ -170,14 +169,18 @@ void HTMLTextAreaElement::collectStyleForPresentationAttribute(const QualifiedNa
void HTMLTextAreaElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (name == rowsAttr) {
- unsigned rows = limitToOnlyNonNegativeNumbersGreaterThanZero(value.string().toUInt(), defaultRows);
+ int rows = value.toInt();
+ if (rows <= 0)
+ rows = defaultRows;
if (m_rows != rows) {
m_rows = rows;
if (renderer())
renderer()->setNeedsLayoutAndPrefWidthsRecalc();
}
} else if (name == colsAttr) {
- unsigned cols = limitToOnlyNonNegativeNumbersGreaterThanZero(value.string().toUInt(), defaultCols);
+ int cols = value.toInt();
+ if (cols <= 0)
+ cols = defaultCols;
if (m_cols != cols) {
m_cols = cols;
if (renderer())
@@ -187,9 +190,9 @@ void HTMLTextAreaElement::parseAttribute(const QualifiedName& name, const Atomic
// The virtual/physical values were a Netscape extension of HTML 3.0, now deprecated.
// The soft/hard /off values are a recommendation for HTML 4 extension by IE and NS 4.
WrapMethod wrap;
- if (equalLettersIgnoringASCIICase(value, "physical") || equalLettersIgnoringASCIICase(value, "hard") || equalLettersIgnoringASCIICase(value, "on"))
+ if (equalIgnoringCase(value, "physical") || equalIgnoringCase(value, "hard") || equalIgnoringCase(value, "on"))
wrap = HardWrap;
- else if (equalLettersIgnoringASCIICase(value, "off"))
+ else if (equalIgnoringCase(value, "off"))
wrap = NoWrap;
else
wrap = SoftWrap;
@@ -201,14 +204,14 @@ void HTMLTextAreaElement::parseAttribute(const QualifiedName& name, const Atomic
} else if (name == accesskeyAttr) {
// ignore for the moment
} else if (name == maxlengthAttr)
- updateValidity();
+ setNeedsValidityCheck();
else
HTMLTextFormControlElement::parseAttribute(name, value);
}
-RenderPtr<RenderElement> HTMLTextAreaElement::createElementRenderer(Ref<RenderStyle>&& style, const RenderTreePosition&)
+RenderPtr<RenderElement> HTMLTextAreaElement::createElementRenderer(PassRef<RenderStyle> style)
{
- return createRenderer<RenderTextControlMultiLine>(*this, WTFMove(style));
+ return createRenderer<RenderTextControlMultiLine>(*this, std::move(style));
}
bool HTMLTextAreaElement::appendFormData(FormDataList& encoding, bool)
@@ -248,26 +251,26 @@ bool HTMLTextAreaElement::isMouseFocusable() const
return isFocusable();
}
-void HTMLTextAreaElement::updateFocusAppearance(SelectionRestorationMode restorationMode, SelectionRevealMode revealMode)
+void HTMLTextAreaElement::updateFocusAppearance(bool restorePreviousSelection)
{
- if (restorationMode == SelectionRestorationMode::SetDefault || !hasCachedSelection()) {
+ if (!restorePreviousSelection || !hasCachedSelection()) {
// If this is the first focus, set a caret at the beginning of the text.
// This matches some browsers' behavior; see bug 11746 Comment #15.
// http://bugs.webkit.org/show_bug.cgi?id=11746#c15
- setSelectionRange(0, 0, SelectionHasNoDirection, Element::defaultFocusTextStateChangeIntent());
+ setSelectionRange(0, 0);
} else
- restoreCachedSelection(Element::defaultFocusTextStateChangeIntent());
+ restoreCachedSelection();
- if (document().frame() && revealMode == SelectionRevealMode::Reveal)
+ if (document().frame())
document().frame()->selection().revealSelection();
}
void HTMLTextAreaElement::defaultEventHandler(Event* event)
{
- if (renderer() && (event->isMouseEvent() || event->type() == eventNames().blurEvent))
+ if (renderer() && (event->isMouseEvent() || event->isDragEvent() || event->eventInterface() == WheelEventInterfaceType || event->type() == eventNames().blurEvent))
forwardEvent(event);
- else if (renderer() && is<BeforeTextInsertedEvent>(*event))
- handleBeforeTextInsertedEvent(downcast<BeforeTextInsertedEvent>(event));
+ else if (renderer() && event->isBeforeTextInsertedEvent())
+ handleBeforeTextInsertedEvent(static_cast<BeforeTextInsertedEvent*>(event));
HTMLTextFormControlElement::defaultEventHandler(event);
}
@@ -276,7 +279,7 @@ void HTMLTextAreaElement::subtreeHasChanged()
{
setChangedSinceLastFormControlChangeEvent(true);
setFormControlValueMatchesRenderer(false);
- updateValidity();
+ setNeedsValidityCheck();
if (!focused())
return;
@@ -322,7 +325,8 @@ String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue,
TextControlInnerTextElement* HTMLTextAreaElement::innerTextElement() const
{
- return downcast<TextControlInnerTextElement>(userAgentShadowRoot()->firstChild());
+ Node* node = userAgentShadowRoot()->firstChild();
+ return toTextControlInnerTextElement(node);
}
void HTMLTextAreaElement::rendererWillBeDestroyed()
@@ -338,9 +342,10 @@ void HTMLTextAreaElement::updateValue() const
ASSERT(renderer());
m_value = innerTextValue();
const_cast<HTMLTextAreaElement*>(this)->setFormControlValueMatchesRenderer(true);
+ const_cast<HTMLTextAreaElement*>(this)->notifyFormStateChanged();
m_isDirty = true;
m_wasModifiedByUser = true;
- const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility();
+ const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(false);
}
String HTMLTextAreaElement::value() const
@@ -353,14 +358,14 @@ void HTMLTextAreaElement::setValue(const String& value)
{
setValueCommon(value);
m_isDirty = true;
- updateValidity();
+ setNeedsValidityCheck();
}
void HTMLTextAreaElement::setNonDirtyValue(const String& value)
{
setValueCommon(value);
m_isDirty = false;
- updateValidity();
+ setNeedsValidityCheck();
}
void HTMLTextAreaElement::setValueCommon(const String& newValue)
@@ -380,7 +385,7 @@ void HTMLTextAreaElement::setValueCommon(const String& newValue)
m_value = normalizedValue;
setInnerTextValue(m_value);
setLastChangeWasNotUserEdit();
- updatePlaceholderVisibility();
+ updatePlaceholderVisibility(false);
setNeedsStyleRecalc();
setFormControlValueMatchesRenderer(true);
@@ -390,12 +395,13 @@ void HTMLTextAreaElement::setValueCommon(const String& newValue)
setSelectionRange(endOfString, endOfString);
}
+ notifyFormStateChanged();
setTextAsOfLastFormControlChangeEvent(normalizedValue);
}
String HTMLTextAreaElement::defaultValue() const
{
- return TextNodeTraversal::contentsAsString(*this);
+ return TextNodeTraversal::contentsAsString(this);
}
void HTMLTextAreaElement::setDefaultValue(const String& defaultValue)
@@ -403,12 +409,13 @@ void HTMLTextAreaElement::setDefaultValue(const String& defaultValue)
Ref<HTMLTextAreaElement> protectFromMutationEvents(*this);
// To preserve comments, remove only the text nodes, then add a single text node.
- Vector<Ref<Text>> textNodes;
- for (Text* textNode = TextNodeTraversal::firstChild(*this); textNode; textNode = TextNodeTraversal::nextSibling(*textNode))
- textNodes.append(*textNode);
+ Vector<RefPtr<Text>> textNodes;
+ for (Text* textNode = TextNodeTraversal::firstChild(this); textNode; textNode = TextNodeTraversal::nextSibling(textNode))
+ textNodes.append(textNode);
- for (auto& textNode : textNodes)
- removeChild(textNode.get(), IGNORE_EXCEPTION);
+ size_t size = textNodes.size();
+ for (size_t i = 0; i < size; ++i)
+ removeChild(textNodes[i].get(), IGNORE_EXCEPTION);
// Normalize line endings.
String value = defaultValue;
@@ -424,7 +431,7 @@ void HTMLTextAreaElement::setDefaultValue(const String& defaultValue)
int HTMLTextAreaElement::maxLength() const
{
bool ok;
- int value = fastGetAttribute(maxlengthAttr).string().toInt(&ok);
+ int value = getAttribute(maxlengthAttr).string().toInt(&ok);
return ok && value >= 0 ? value : -1;
}
@@ -489,14 +496,14 @@ void HTMLTextAreaElement::accessKeyAction(bool)
focus();
}
-void HTMLTextAreaElement::setCols(unsigned cols)
+void HTMLTextAreaElement::setCols(int cols)
{
- setUnsignedIntegralAttribute(colsAttr, limitToOnlyNonNegativeNumbersGreaterThanZero(cols, defaultCols));
+ setIntegralAttribute(colsAttr, cols);
}
-void HTMLTextAreaElement::setRows(unsigned rows)
+void HTMLTextAreaElement::setRows(int rows)
{
- setUnsignedIntegralAttribute(rowsAttr, limitToOnlyNonNegativeNumbersGreaterThanZero(rows, defaultRows));
+ setIntegralAttribute(rowsAttr, rows);
}
bool HTMLTextAreaElement::shouldUseInputMethod()
@@ -509,6 +516,11 @@ HTMLElement* HTMLTextAreaElement::placeholderElement() const
return m_placeholder;
}
+bool HTMLTextAreaElement::matchesReadOnlyPseudoClass() const
+{
+ return isReadOnly();
+}
+
bool HTMLTextAreaElement::matchesReadWritePseudoClass() const
{
return !isDisabledOrReadOnly();
@@ -519,8 +531,8 @@ void HTMLTextAreaElement::updatePlaceholderText()
String placeholderText = strippedPlaceholder();
if (placeholderText.isEmpty()) {
if (m_placeholder) {
- userAgentShadowRoot()->removeChild(*m_placeholder, ASSERT_NO_EXCEPTION);
- m_placeholder = nullptr;
+ userAgentShadowRoot()->removeChild(m_placeholder, ASSERT_NO_EXCEPTION);
+ m_placeholder = 0;
}
return;
}
@@ -528,8 +540,7 @@ void HTMLTextAreaElement::updatePlaceholderText()
RefPtr<HTMLDivElement> placeholder = HTMLDivElement::create(document());
m_placeholder = placeholder.get();
m_placeholder->setPseudo(AtomicString("-webkit-input-placeholder", AtomicString::ConstructFromLiteral));
- m_placeholder->setInlineStyleProperty(CSSPropertyDisplay, isPlaceholderVisible() ? CSSValueBlock : CSSValueNone, true);
- userAgentShadowRoot()->insertBefore(*m_placeholder, innerTextElement()->nextSibling());
+ userAgentShadowRoot()->insertBefore(m_placeholder, innerTextElement()->nextSibling());
}
m_placeholder->setInnerText(placeholderText, ASSERT_NO_EXCEPTION);
}