Changeset 81328 in webkit


Ignore:
Timestamp:
Mar 16, 2011 11:31:00 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-03-16 Naoki Takano <takano.naoki@gmail.com>

Reviewed by Ryosuke Niwa.

Textarea maxlength doesn't account for newlines
https://bugs.webkit.org/show_bug.cgi?id=54443

  • fast/forms/script-tests/textarea-maxlength.js: (createFocusedTextAreaWithMaxLength3): Added two tests to make sure consecutive insertbreaks work correctly for textarea maxlength.
  • fast/forms/textarea-maxlength-expected.txt: Added two test results.

2011-03-16 Naoki Takano <takano.naoki@gmail.com>

Reviewed by Ryosuke Niwa.

Textarea maxlength doesn't account for newlines
https://bugs.webkit.org/show_bug.cgi?id=54443

When a user presses a return key, TypingCommand::insertLineBreak() is called.
So before append a new line, check if we can add the new line.

  • editing/TypingCommand.cpp: (WebCore::canAppendNewLineFeed): Implement new helper function to check if we can add new line. (WebCore::TypingCommand::insertLineBreak): Added check logic before adding the new line. (WebCore::TypingCommand::insertParagraphSeparator): Added check logic before adding the new line.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r81324 r81328  
     12011-03-16  Naoki Takano  <takano.naoki@gmail.com>
     2
     3        Reviewed by Ryosuke Niwa.
     4
     5        Textarea maxlength doesn't account for newlines
     6        https://bugs.webkit.org/show_bug.cgi?id=54443
     7
     8        * fast/forms/script-tests/textarea-maxlength.js:
     9        (createFocusedTextAreaWithMaxLength3): Added two tests to make sure consecutive insertbreaks
     10        work correctly for textarea maxlength.
     11        * fast/forms/textarea-maxlength-expected.txt: Added two test results.
     12
    1132011-03-16  Alice Liu  <alice.liu@apple.com>
    214
  • trunk/LayoutTests/fast/forms/script-tests/textarea-maxlength.js

    r48903 r81328  
    8989shouldBe('textArea.value', '"A\\nB"');
    9090
     91// Confirms correct count for close linebreaks inputs.
     92createFocusedTextAreaWithMaxLength3();
     93textArea.innerHTML = 'a\n\n';
     94document.execCommand('insertLineBreak');
     95shouldBe('textArea.value', '"a\\n\\n"');
     96
     97// Confirms correct count for open consecutive linebreaks inputs.
     98createFocusedTextAreaWithMaxLength3();
     99document.execCommand('insertLineBreak');
     100document.execCommand('insertLineBreak');
     101document.execCommand('insertLineBreak');
     102document.execCommand('insertLineBreak');
     103shouldBe('textArea.value', '"\\n\\n\\n"');
     104
    91105// According to the HTML5 specification, maxLength is code-point length.
    92106// However WebKit handles it as grapheme length.
  • trunk/LayoutTests/fast/forms/textarea-maxlength-expected.txt

    r48903 r81328  
    2222PASS textArea.value is "abcde"
    2323PASS textArea.value is "A\nB"
     24PASS textArea.value is "a\n\n"
     25PASS textArea.value is "\n\n\n"
    2426PASS textArea.value is "AB" + fancyX
    2527PASS textArea.value.length is 5
  • trunk/Source/WebCore/ChangeLog

    r81326 r81328  
     12011-03-16  Naoki Takano  <takano.naoki@gmail.com>
     2
     3        Reviewed by Ryosuke Niwa.
     4
     5        Textarea maxlength doesn't account for newlines
     6        https://bugs.webkit.org/show_bug.cgi?id=54443
     7
     8        When a user presses a return key, TypingCommand::insertLineBreak() is called.
     9        So before append a new line, check if we can add the new line.
     10
     11        * editing/TypingCommand.cpp:
     12        (WebCore::canAppendNewLineFeed): Implement new helper function to check if we can add new line.
     13        (WebCore::TypingCommand::insertLineBreak): Added check logic before adding the new line.
     14        (WebCore::TypingCommand::insertParagraphSeparator): Added check logic before adding the new line.
     15
    1162011-03-16  Adam Barth  <abarth@webkit.org>
    217
  • trunk/Source/WebCore/editing/TypingCommand.cpp

    r81165 r81328  
    4848using namespace HTMLNames;
    4949
     50static bool canAppendNewLineFeed(const VisibleSelection& selection)
     51{
     52    ExceptionCode ec = 0;
     53    RefPtr<BeforeTextInsertedEvent> event = BeforeTextInsertedEvent::create(String("\n"));
     54    selection.rootEditableElement()->dispatchEvent(event, ec);
     55    return event->text().length();
     56}
     57
    5058TypingCommand::TypingCommand(Document *document, ETypingCommand commandType, const String &textToInsert, TypingCommandOptions options, TextGranularity granularity, TextCompositionType compositionType)
    5159    : CompositeEditCommand(document)
     
    404412void TypingCommand::insertLineBreak()
    405413{
     414    if (!canAppendNewLineFeed(endingSelection()))
     415        return;
     416
    406417    applyCommandToComposite(InsertLineBreakCommand::create(document()));
    407418    typingAddedToOpenCommand(InsertLineBreak);
     
    410421void TypingCommand::insertParagraphSeparator()
    411422{
     423    if (!canAppendNewLineFeed(endingSelection()))
     424        return;
     425
    412426    applyCommandToComposite(InsertParagraphSeparatorCommand::create(document()));
    413427    typingAddedToOpenCommand(InsertParagraphSeparator);
Note: See TracChangeset for help on using the changeset viewer.