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

Unified Diff: Source/core/html/TextFieldInputType.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 | « Source/core/html/HTMLTextAreaElement.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/TextFieldInputType.cpp
diff --git a/Source/core/html/TextFieldInputType.cpp b/Source/core/html/TextFieldInputType.cpp
index 6c51162e357af26914bd3ba96cb3ca8eb2897964..e0987833e48549b430c695e91130b15c9ae3c2f6 100644
--- a/Source/core/html/TextFieldInputType.cpp
+++ b/Source/core/html/TextFieldInputType.cpp
@@ -357,7 +357,9 @@ static bool isASCIILineBreak(UChar c)
static String limitLength(const String& string, int maxLength)
{
- unsigned newLength = numCharactersInGraphemeClusters(string, maxLength);
+ unsigned newLength = maxLength;
+ // FIXME: We should not truncate the string at a control character. It's not
+ // compatible with IE and Firefox.
for (unsigned i = 0; i < newLength; ++i) {
const UChar current = string[i];
if (current < ' ' && current != '\t') {
@@ -365,6 +367,8 @@ static String limitLength(const String& string, int maxLength)
break;
}
}
+ if (newLength > 0 && U16_IS_LEAD(string[newLength - 1]))
+ --newLength;
return string.left(newLength);
}
@@ -377,17 +381,17 @@ void TextFieldInputType::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*
{
// Make sure that the text to be inserted will not violate the maxLength.
- // We use RenderTextControlSingleLine::text() instead of InputElement::value()
- // because they can be mismatched by sanitizeValue() in
- // HTMLInputElement::subtreeHasChanged() in some cases.
- unsigned oldLength = numGraphemeClusters(element()->innerTextValue());
+ // We use HTMLInputElement::innerTextValue() instead of
+ // HTMLInputElement::value() because they can be mismatched by
+ // sanitizeValue() in HTMLInputElement::subtreeHasChanged() in some cases.
+ unsigned oldLength = element()->innerTextValue().length();
// 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
// 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 = element()->focused() ? numGraphemeClusters(plainText(element()->document()->frame()->selection()->selection().toNormalizedRange().get())) : 0;
+ unsigned selectionLength = element()->focused() ? plainText(element()->document()->frame()->selection()->selection().toNormalizedRange().get()).length() : 0;
ASSERT(oldLength >= selectionLength);
// Selected characters will be removed by the next text event.
« no previous file with comments | « Source/core/html/HTMLTextAreaElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698