, m_isDirty(false)
, m_valueIsUpToDate(true)
{
- ScriptWrappable::init(this);
}
PassRefPtrWillBeRawPtr<HTMLTextAreaElement> HTMLTextAreaElement::create(Document& document, HTMLFormElement* form)
// If the text field has no focus, we don't need to take account of the
// selection length. The selection is the source of text drag-and-drop in
// that case, and nothing in the text field will be removed.
- unsigned selectionLength = focused() ? computeLengthForSubmission(plainText(document().frame()->selection().selection().toNormalizedRange().get())) : 0;
+ unsigned selectionLength = 0;
+ if (focused()) {
+ Position start, end;
+ document().frame()->selection().selection().toNormalizedPositions(start, end);
+ selectionLength = computeLengthForSubmission(plainText(start, end));
+ }
ASSERT(currentLength >= selectionLength);
unsigned baseLength = currentLength - selectionLength;
unsigned appendableLength = unsignedMaxLength > baseLength ? unsignedMaxLength - baseLength : 0;
if (m_valueIsUpToDate)
return;
- ASSERT(renderer());
m_value = innerEditorValue();
const_cast<HTMLTextAreaElement*>(this)->m_valueIsUpToDate = true;
const_cast<HTMLTextAreaElement*>(this)->notifyFormStateChanged();
int HTMLTextAreaElement::maxLength() const
{
bool ok;
- int value = getAttribute(maxlengthAttr).string().toInt(&ok);
+ int value = getAttribute(maxlengthAttr).toInt(&ok);
return ok && value >= 0 ? value : -1;
}
bool HTMLTextAreaElement::valueMissing() const
{
- return willValidate() && valueMissing(value());
+ // We should not call value() for performance.
+ return willValidate() && valueMissing(0);
+}
+
+bool HTMLTextAreaElement::valueMissing(const String* value) const
+{
+ return isRequiredFormControl() && !isDisabledOrReadOnly() && (value ? *value : this->value()).isEmpty();
}
bool HTMLTextAreaElement::tooLong() const
{
- return willValidate() && tooLong(value(), CheckDirtyFlag);
+ // We should not call value() for performance.
+ return willValidate() && tooLong(0, CheckDirtyFlag);
}
-bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const
+bool HTMLTextAreaElement::tooLong(const String* value, NeedsToCheckDirtyFlag check) const
{
// Return false for the default value or value set by script even if it is
// longer than maxLength.
int max = maxLength();
if (max < 0)
return false;
- return computeLengthForSubmission(value) > static_cast<unsigned>(max);
+ return computeLengthForSubmission(value ? *value : this->value()) > static_cast<unsigned>(max);
}
bool HTMLTextAreaElement::isValidValue(const String& candidate) const
{
- return !valueMissing(candidate) && !tooLong(candidate, IgnoreDirtyFlag);
+ return !valueMissing(&candidate) && !tooLong(&candidate, IgnoreDirtyFlag);
}
void HTMLTextAreaElement::accessKeyAction(bool)