Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1193)

Unified Diff: Source/core/html/HTMLTextAreaElement.cpp

Issue 22590003: input/textarea: Count value length with the standard way. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: comment in a test Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/forms/textarea-maxlength-expected.txt ('k') | Source/core/html/TextFieldInputType.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLTextAreaElement.cpp
diff --git a/Source/core/html/HTMLTextAreaElement.cpp b/Source/core/html/HTMLTextAreaElement.cpp
index fae5d5d370c47604da4285e4c5681e6002bbdf07..81f888f6bae56340f3279e37d4173736bc592ea2 100644
--- a/Source/core/html/HTMLTextAreaElement.cpp
+++ b/Source/core/html/HTMLTextAreaElement.cpp
@@ -59,7 +59,7 @@ static const int defaultCols = 20;
// This function returns number of characters considering this.
static inline unsigned computeLengthForSubmission(const String& text, unsigned numberOfLineBreaks)
{
- return numGraphemeClusters(text) + numberOfLineBreaks;
+ return text.length() + numberOfLineBreaks;
}
static unsigned numberOfLineBreaks(const String& text)
@@ -75,12 +75,7 @@ static unsigned numberOfLineBreaks(const String& text)
static inline unsigned computeLengthForSubmission(const String& text)
{
- return numGraphemeClusters(text) + numberOfLineBreaks(text);
-}
-
-static inline unsigned upperBoundForLengthForSubmission(const String& text, unsigned numberOfLineBreaks)
-{
- return text.length() + numberOfLineBreaks;
+ return text.length() + numberOfLineBreaks(text);
}
HTMLTextAreaElement::HTMLTextAreaElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
@@ -294,12 +289,10 @@ void HTMLTextAreaElement::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*
unsigned unsignedMaxLength = static_cast<unsigned>(signedMaxLength);
const String& currentValue = innerTextValue();
- unsigned numberOfLineBreaksInCurrentValue = numberOfLineBreaks(currentValue);
- if (upperBoundForLengthForSubmission(currentValue, numberOfLineBreaksInCurrentValue)
- + upperBoundForLengthForSubmission(event->text(), numberOfLineBreaks(event->text())) < unsignedMaxLength)
+ unsigned currentLength = computeLengthForSubmission(currentValue);
+ if (currentLength + computeLengthForSubmission(event->text()) < unsignedMaxLength)
return;
- unsigned currentLength = computeLengthForSubmission(currentValue, numberOfLineBreaksInCurrentValue);
// selectionLength represents the selection length of this text field to be
// removed by this insertion.
// If the text field has no focus, we don't need to take account of the
@@ -314,7 +307,9 @@ void HTMLTextAreaElement::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*
String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue, unsigned maxLength)
{
- return proposedValue.left(numCharactersInGraphemeClusters(proposedValue, maxLength));
+ if (maxLength > 0 && U16_IS_LEAD(proposedValue[maxLength - 1]))
+ --maxLength;
+ return proposedValue.left(maxLength);
}
HTMLElement* HTMLTextAreaElement::innerTextElement() const
@@ -484,10 +479,7 @@ bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag che
int max = maxLength();
if (max < 0)
return false;
- unsigned unsignedMax = static_cast<unsigned>(max);
- unsigned numberOfLineBreaksInValue = numberOfLineBreaks(value);
- return upperBoundForLengthForSubmission(value, numberOfLineBreaksInValue) > unsignedMax
- && computeLengthForSubmission(value, numberOfLineBreaksInValue) > unsignedMax;
+ return computeLengthForSubmission(value) > static_cast<unsigned>(max);
}
bool HTMLTextAreaElement::isValidValue(const String& candidate) const
« no previous file with comments | « LayoutTests/fast/forms/textarea-maxlength-expected.txt ('k') | Source/core/html/TextFieldInputType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698