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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp

Issue 1846913005: Newline characters in pasted text are not counted correctly for textarea[maxlength]. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) 7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 selectionLength = computeLengthForSubmission(document().frame()->selecti on().selectedText()); 326 selectionLength = computeLengthForSubmission(document().frame()->selecti on().selectedText());
327 } 327 }
328 ASSERT(currentLength >= selectionLength); 328 ASSERT(currentLength >= selectionLength);
329 unsigned baseLength = currentLength - selectionLength; 329 unsigned baseLength = currentLength - selectionLength;
330 unsigned appendableLength = unsignedMaxLength > baseLength ? unsignedMaxLeng th - baseLength : 0; 330 unsigned appendableLength = unsignedMaxLength > baseLength ? unsignedMaxLeng th - baseLength : 0;
331 event->setText(sanitizeUserInputValue(event->text(), appendableLength)); 331 event->setText(sanitizeUserInputValue(event->text(), appendableLength));
332 } 332 }
333 333
334 String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue, unsigned maxLength) 334 String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue, unsigned maxLength)
335 { 335 {
336 if (maxLength > 0 && U16_IS_LEAD(proposedValue[maxLength - 1])) 336 unsigned submissionLength = 0;
337 --maxLength; 337 unsigned i = 0;
338 return proposedValue.left(maxLength); 338 for (; i < proposedValue.length(); ++i) {
339 submissionLength += proposedValue[i] == '\n' ? 2 : 1;
340 if (submissionLength == maxLength) {
341 ++i;
342 break;
343 }
344 if (submissionLength > maxLength)
345 break;
346 }
347 if (i > 0 && U16_IS_LEAD(proposedValue[i - 1]))
348 --i;
349 return proposedValue.left(i);
339 } 350 }
340 351
341 void HTMLTextAreaElement::updateValue() const 352 void HTMLTextAreaElement::updateValue() const
342 { 353 {
343 if (m_valueIsUpToDate) 354 if (m_valueIsUpToDate)
344 return; 355 return;
345 356
346 m_value = innerEditorValue(); 357 m_value = innerEditorValue();
347 const_cast<HTMLTextAreaElement*>(this)->m_valueIsUpToDate = true; 358 const_cast<HTMLTextAreaElement*>(this)->m_valueIsUpToDate = true;
348 const_cast<HTMLTextAreaElement*>(this)->notifyFormStateChanged(); 359 const_cast<HTMLTextAreaElement*>(this)->notifyFormStateChanged();
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 673
663 void HTMLTextAreaElement::copyNonAttributePropertiesFromElement(const Element& s ource) 674 void HTMLTextAreaElement::copyNonAttributePropertiesFromElement(const Element& s ource)
664 { 675 {
665 const HTMLTextAreaElement& sourceElement = static_cast<const HTMLTextAreaEle ment&>(source); 676 const HTMLTextAreaElement& sourceElement = static_cast<const HTMLTextAreaEle ment&>(source);
666 setValueCommon(sourceElement.value(), DispatchNoEvent, SetSeletion); 677 setValueCommon(sourceElement.value(), DispatchNoEvent, SetSeletion);
667 m_isDirty = sourceElement.m_isDirty; 678 m_isDirty = sourceElement.m_isDirty;
668 HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(source); 679 HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(source);
669 } 680 }
670 681
671 } // namespace blink 682 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698