From 8995b83bcbfbb68245f779b64e5517627c6cc6ea Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 17 Oct 2012 16:21:14 +0200 Subject: Imported WebKit commit cf4f8fc6f19b0629f51860cb2d4b25e139d07e00 (http://svn.webkit.org/repository/webkit/trunk@131592) New snapshot that includes the build fixes for Mac OS X 10.6 and earlier as well as the previously cherry-picked changes --- Source/WebCore/html/HTMLTextAreaElement.cpp | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'Source/WebCore/html/HTMLTextAreaElement.cpp') diff --git a/Source/WebCore/html/HTMLTextAreaElement.cpp b/Source/WebCore/html/HTMLTextAreaElement.cpp index a42aa7831..db98ccc9f 100644 --- a/Source/WebCore/html/HTMLTextAreaElement.cpp +++ b/Source/WebCore/html/HTMLTextAreaElement.cpp @@ -56,10 +56,15 @@ static const int defaultCols = 20; // On submission, LF characters are converted into CRLF. // This function returns number of characters considering this. -static unsigned computeLengthForSubmission(const String& text) +static inline unsigned computeLengthForSubmission(const String& text, unsigned numberOfLineBreaks) +{ + return numGraphemeClusters(text) + numberOfLineBreaks; +} + +static unsigned numberOfLineBreaks(const String& text) { - unsigned count = numGraphemeClusters(text); unsigned length = text.length(); + unsigned count = 0; for (unsigned i = 0; i < length; i++) { if (text[i] == '\n') count++; @@ -67,6 +72,16 @@ static unsigned computeLengthForSubmission(const String& text) return count; } +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; +} + HTMLTextAreaElement::HTMLTextAreaElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) : HTMLTextFormControlElement(tagName, document, form) , m_rows(defaultRows) @@ -280,7 +295,13 @@ void HTMLTextAreaElement::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* return; unsigned unsignedMaxLength = static_cast(signedMaxLength); - unsigned currentLength = computeLengthForSubmission(innerTextValue()); + const String& currentValue = innerTextValue(); + unsigned numberOfLineBreaksInCurrentValue = numberOfLineBreaks(currentValue); + if (upperBoundForLengthForSubmission(currentValue, numberOfLineBreaksInCurrentValue) + + upperBoundForLengthForSubmission(event->text(), numberOfLineBreaks(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 @@ -466,7 +487,10 @@ bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag che int max = maxLength(); if (max < 0) return false; - return computeLengthForSubmission(value) > static_cast(max); + unsigned unsignedMax = static_cast(max); + unsigned numberOfLineBreaksInValue = numberOfLineBreaks(value); + return upperBoundForLengthForSubmission(value, numberOfLineBreaksInValue) > unsignedMax + && computeLengthForSubmission(value, numberOfLineBreaksInValue) > unsignedMax; } bool HTMLTextAreaElement::isValidValue(const String& candidate) const -- cgit v1.2.1