Changeset 146907 in webkit


Ignore:
Timestamp:
Mar 26, 2013 10:58:11 AM (11 years ago)
Author:
sergio@webkit.org
Message:

Implement overtype mode for editable content
https://bugs.webkit.org/show_bug.cgi?id=112126

Reviewed by Ryosuke Niwa.

Source/WebCore:

Tests: editing/execCommand/overtype-support.html

editing/execCommand/overtype.html

Add a new Overwrite command to the editor. This command will
perform overtype operations when enabled instead of "normal" text
insertions. As IE does, we maintain a single toggle state in the
editor (enabled/disabled) for all the editable content in the
page.

This new command will be only available for richly editable
content via keybindings or the context menu. For testing purposes
it is also accessible via internals.

  • editing/CompositeEditCommand.cpp:

(WebCore::CompositeEditCommand::replaceTextInNode): Use RefPtr for
local variables.

  • editing/Editor.cpp:

(WebCore::Editor::Editor):

  • editing/Editor.h:

(WebCore::Editor::isOverwriteModeEnabled):
(WebCore::Editor::toggleOverwriteModeEnabled):
(Editor): Added two new functions and a new attribute.

  • editing/EditorCommand.cpp:

(WebCore::executeToggleOverwrite): Enables/disables overwrite mode.
(WebCore):
(WebCore::createCommandMap): New OverWrite command.

  • editing/InsertTextCommand.cpp:

(WebCore::InsertTextCommand::setEndingSelectionWithoutValidation):
Refactored from performTrivialReplace(), shared by
performOverwrite().
(WebCore):
(WebCore::InsertTextCommand::performTrivialReplace):
(WebCore::InsertTextCommand::performOverwrite):
(WebCore::InsertTextCommand::doApply): Perform overwrite if enabled.

  • editing/InsertTextCommand.h:

(InsertTextCommand):

  • testing/Internals.cpp:

(WebCore::Internals::resetToConsistentState): Reset OverWrite mode
to false.
(WebCore::Internals::isOverwriteModeEnabled):
(WebCore):
(WebCore::Internals::toggleOverwriteModeEnabled): Provide access
to overwrite functionality in Editor for testing purposes.

  • testing/Internals.h:

(Internals):

  • testing/Internals.idl:

Source/WebKit/mac:

Added the OverWrite editing command to the WebCore editing
commands lists.

  • WebView/WebHTMLView.mm:
  • WebView/WebView.h:
  • WebView/WebView.mm:

LayoutTests:

Two new layout tests for the new overtype mode. We use
overtype-support.html to check that the Overwrite command is not
exported to JavaScript but accessible through Internals. The
overtype.html one is used to test the actual behaviour of the
command.

The new command was also added to enabling-and-selection-2.js to
check that it is only available for richly editable content.

  • editing/execCommand/enabling-and-selection-2-expected.txt:

Updated expectations for OverWrite command.

  • editing/execCommand/overtype-expected.txt: Added.
  • editing/execCommand/overtype-support-expected.txt: Added.
  • editing/execCommand/overtype-support.html: Added.
  • editing/execCommand/overtype.html: Added.
  • editing/execCommand/script-tests/enabling-and-selection-2.js:

Added a check for OverWrite command.

Location:
trunk
Files:
4 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r146905 r146907  
     12013-03-26  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        Implement overtype mode for editable content
     4        https://bugs.webkit.org/show_bug.cgi?id=112126
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Two new layout tests for the new overtype mode. We use
     9        overtype-support.html to check that the Overwrite command is not
     10        exported to JavaScript but accessible through Internals. The
     11        overtype.html one is used to test the actual behaviour of the
     12        command.
     13
     14        The new command was also added to enabling-and-selection-2.js to
     15        check that it is only available for richly editable content.
     16
     17        * editing/execCommand/enabling-and-selection-2-expected.txt:
     18        Updated expectations for OverWrite command.
     19        * editing/execCommand/overtype-expected.txt: Added.
     20        * editing/execCommand/overtype-support-expected.txt: Added.
     21        * editing/execCommand/overtype-support.html: Added.
     22        * editing/execCommand/overtype.html: Added.
     23        * editing/execCommand/script-tests/enabling-and-selection-2.js:
     24        Added a check for OverWrite command.
     25
    1262013-03-26  Sheriff Bot  <webkit.review.bot@gmail.com>
    227
  • trunk/LayoutTests/editing/execCommand/enabling-and-selection-2-expected.txt

    r39114 r146907  
    8484PASS whenEnabled('SelectWord') is 'visible'
    8585PASS whenEnabled('SetMark') is 'visible'
     86PASS whenEnabled('OverWrite') is 'richly editable'
    8687PASS successfullyParsed is true
    8788
  • trunk/LayoutTests/editing/execCommand/script-tests/enabling-and-selection-2.js

    r120173 r146907  
    165165shouldBe("whenEnabled('SetMark')", "'visible'");
    166166
     167shouldBe("whenEnabled('OverWrite')", "'richly editable'");
     168
    167169document.body.removeChild(nonEditableParagraph);
    168170document.body.removeChild(editableParagraph);
  • trunk/Source/WebCore/ChangeLog

    r146906 r146907  
     12013-03-26  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        Implement overtype mode for editable content
     4        https://bugs.webkit.org/show_bug.cgi?id=112126
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Tests: editing/execCommand/overtype-support.html
     9               editing/execCommand/overtype.html
     10
     11        Add a new Overwrite command to the editor. This command will
     12        perform overtype operations when enabled instead of "normal" text
     13        insertions. As IE does, we maintain a single toggle state in the
     14        editor (enabled/disabled) for all the editable content in the
     15        page.
     16
     17        This new command will be only available for richly editable
     18        content via keybindings or the context menu. For testing purposes
     19        it is also accessible via internals.
     20
     21        * editing/CompositeEditCommand.cpp:
     22        (WebCore::CompositeEditCommand::replaceTextInNode): Use RefPtr for
     23        local variables.
     24        * editing/Editor.cpp:
     25        (WebCore::Editor::Editor):
     26        * editing/Editor.h:
     27        (WebCore::Editor::isOverwriteModeEnabled):
     28        (WebCore::Editor::toggleOverwriteModeEnabled):
     29        (Editor): Added two new functions and a new attribute.
     30        * editing/EditorCommand.cpp:
     31        (WebCore::executeToggleOverwrite): Enables/disables overwrite mode.
     32        (WebCore):
     33        (WebCore::createCommandMap): New OverWrite command.
     34        * editing/InsertTextCommand.cpp:
     35        (WebCore::InsertTextCommand::setEndingSelectionWithoutValidation):
     36        Refactored from performTrivialReplace(), shared by
     37        performOverwrite().
     38        (WebCore):
     39        (WebCore::InsertTextCommand::performTrivialReplace):
     40        (WebCore::InsertTextCommand::performOverwrite):
     41        (WebCore::InsertTextCommand::doApply): Perform overwrite if enabled.
     42        * editing/InsertTextCommand.h:
     43        (InsertTextCommand):
     44        * testing/Internals.cpp:
     45        (WebCore::Internals::resetToConsistentState): Reset OverWrite mode
     46        to false.
     47        (WebCore::Internals::isOverwriteModeEnabled):
     48        (WebCore):
     49        (WebCore::Internals::toggleOverwriteModeEnabled): Provide access
     50        to overwrite functionality in Editor for testing purposes.
     51        * testing/Internals.h:
     52        (Internals):
     53        * testing/Internals.idl:
     54
    1552013-03-26  Arvid Nilsson  <anilsson@rim.com>
    256
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r145754 r146907  
    501501}
    502502
    503 void CompositeEditCommand::replaceTextInNode(PassRefPtr<Text> node, unsigned offset, unsigned count, const String& replacementText)
    504 {
    505     applyCommandToComposite(DeleteFromTextNodeCommand::create(node.get(), offset, count));
     503void CompositeEditCommand::replaceTextInNode(PassRefPtr<Text> prpNode, unsigned offset, unsigned count, const String& replacementText)
     504{
     505    RefPtr<Text> node(prpNode);
     506    applyCommandToComposite(DeleteFromTextNodeCommand::create(node, offset, count));
    506507    if (!replacementText.isEmpty())
    507508        applyCommandToComposite(InsertIntoTextNodeCommand::create(node, offset, replacementText));
  • trunk/Source/WebCore/editing/Editor.cpp

    r146835 r146907  
    906906    , m_areMarkedTextMatchesHighlighted(false)
    907907    , m_defaultParagraphSeparator(EditorParagraphSeparatorIsDiv)
     908    , m_overwriteModeEnabled(false)
    908909{
    909910#if ENABLE(DELETION_UI)
  • trunk/Source/WebCore/editing/Editor.h

    r146835 r146907  
    246246    void markAndReplaceFor(PassRefPtr<SpellCheckRequest>, const Vector<TextCheckingResult>&);
    247247
     248    bool isOverwriteModeEnabled() const { return m_overwriteModeEnabled; }
     249    void toggleOverwriteModeEnabled() { m_overwriteModeEnabled = !m_overwriteModeEnabled; }
     250
    248251#if USE(APPKIT)
    249252    void uppercaseWord();
     
    434437    bool m_areMarkedTextMatchesHighlighted;
    435438    EditorParagraphSeparator m_defaultParagraphSeparator;
     439    bool m_overwriteModeEnabled;
    436440
    437441    bool canDeleteRange(Range*) const;
  • trunk/Source/WebCore/editing/EditorCommand.cpp

    r143398 r146907  
    900900{
    901901    applyCommand(IndentOutdentCommand::create(frame->document(), IndentOutdentCommand::Outdent));
     902    return true;
     903}
     904
     905static bool executeToggleOverwrite(Frame* frame, Event*, EditorCommandSource, const String&)
     906{
     907    frame->editor()->toggleOverwriteModeEnabled();
    902908    return true;
    903909}
     
    15521558        { "MoveWordRightAndModifySelection", { executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
    15531559        { "Outdent", { executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
     1560        { "OverWrite", { executeToggleOverwrite, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
    15541561        { "Paste", { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
    15551562        { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
     
    16301637    // MultipleSelection (not supported)
    16311638    // Open (not supported)
    1632     // Overwrite (not supported)
    16331639    // PlayImage (not supported)
    16341640    // Refresh (not supported)
  • trunk/Source/WebCore/editing/InsertTextCommand.cpp

    r144911 r146907  
    7676}
    7777
    78 // This avoids the expense of a full fledged delete operation, and avoids a layout that typically results
    79 // from text removal.
    80 bool InsertTextCommand::performTrivialReplace(const String& text, bool selectInsertedText)
    81 {
    82     if (!endingSelection().isRange())
    83         return false;
    84    
    85     if (text.contains('\t') || text.contains(' ') || text.contains('\n'))
    86         return false;
    87 
    88     Position start = endingSelection().start();
    89     Position endPosition = replaceSelectedTextInNode(text);
    90     if (endPosition.isNull())
    91         return false;
    92 
     78void InsertTextCommand::setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition, bool selectInsertedText)
     79{
    9380    // We could have inserted a part of composed character sequence,
    9481    // so we are basically treating ending selection as a range to avoid validation.
    9582    // <http://bugs.webkit.org/show_bug.cgi?id=15781>
    9683    VisibleSelection forcedEndingSelection;
    97     forcedEndingSelection.setWithoutValidation(start, endPosition);
     84    forcedEndingSelection.setWithoutValidation(startPosition, endPosition);
    9885    forcedEndingSelection.setIsDirectional(endingSelection().isDirectional());
    9986    setEndingSelection(forcedEndingSelection);
     
    10188    if (!selectInsertedText)
    10289        setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
    103    
     90}
     91
     92// This avoids the expense of a full fledged delete operation, and avoids a layout that typically results
     93// from text removal.
     94bool InsertTextCommand::performTrivialReplace(const String& text, bool selectInsertedText)
     95{
     96    if (!endingSelection().isRange())
     97        return false;
     98
     99    if (text.contains('\t') || text.contains(' ') || text.contains('\n'))
     100        return false;
     101
     102    Position start = endingSelection().start();
     103    Position endPosition = replaceSelectedTextInNode(text);
     104    if (endPosition.isNull())
     105        return false;
     106
     107    setEndingSelectionWithoutValidation(start, endPosition, selectInsertedText);
     108
     109    return true;
     110}
     111
     112bool InsertTextCommand::performOverwrite(const String& text, bool selectInsertedText)
     113{
     114    Position start = endingSelection().start();
     115    RefPtr<Text> textNode = start.containerText();
     116    if (!textNode)
     117        return false;
     118
     119    unsigned count = std::min(text.length(), textNode->length() - start.offsetInContainerNode());
     120    replaceTextInNode(textNode, start.offsetInContainerNode(), count, text);
     121
     122    Position endPosition = Position(textNode.release(), start.offsetInContainerNode() + text.length());
     123    setEndingSelectionWithoutValidation(start, endPosition, selectInsertedText);
     124
    104125    return true;
    105126}
     
    122143        // anything other than NoSelection. The rest of this function requires a real endingSelection, so bail out.
    123144        if (endingSelection().isNone())
     145            return;
     146    } else if (document()->frame()->editor()->isOverwriteModeEnabled()) {
     147        if (performOverwrite(m_text, m_selectInsertedText))
    124148            return;
    125149    }
  • trunk/Source/WebCore/editing/InsertTextCommand.h

    r114220 r146907  
    7373   
    7474    bool performTrivialReplace(const String&, bool selectInsertedText);
     75    bool performOverwrite(const String&, bool selectInsertedText);
     76    void setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition, bool selectInsertedText);
    7577
    7678    friend class TypingCommand;
  • trunk/Source/WebCore/testing/Internals.cpp

    r146361 r146907  
    275275    if (!page->mainFrame()->editor()->isContinuousSpellCheckingEnabled())
    276276        page->mainFrame()->editor()->toggleContinuousSpellChecking();
     277    if (page->mainFrame()->editor()->isOverwriteModeEnabled())
     278        page->mainFrame()->editor()->toggleOverwriteModeEnabled();
    277279}
    278280
     
    15121514    if (enabled != contextDocument()->frame()->editor()->isContinuousSpellCheckingEnabled())
    15131515        contextDocument()->frame()->editor()->toggleContinuousSpellChecking();
     1516}
     1517
     1518bool Internals::isOverwriteModeEnabled(Document* document, ExceptionCode&)
     1519{
     1520    if (!document || !document->frame())
     1521        return 0;
     1522
     1523    return document->frame()->editor()->isOverwriteModeEnabled();
     1524}
     1525
     1526void Internals::toggleOverwriteModeEnabled(Document* document, ExceptionCode&)
     1527{
     1528    if (!document || !document->frame())
     1529        return;
     1530
     1531    document->frame()->editor()->toggleOverwriteModeEnabled();
    15141532}
    15151533
  • trunk/Source/WebCore/testing/Internals.h

    r146361 r146907  
    203203    void setContinuousSpellCheckingEnabled(bool enabled, ExceptionCode&);
    204204
     205    bool isOverwriteModeEnabled(Document*, ExceptionCode&);
     206    void toggleOverwriteModeEnabled(Document*, ExceptionCode&);
     207
    205208    unsigned numberOfScrollableAreas(Document*, ExceptionCode&);
    206209
  • trunk/Source/WebCore/testing/Internals.idl

    r146361 r146907  
    170170    void setContinuousSpellCheckingEnabled(in boolean enabled) raises (DOMException);
    171171
     172    boolean isOverwriteModeEnabled(in Document document) raises (DOMException);
     173    void toggleOverwriteModeEnabled(in Document document) raises (DOMException);
     174
    172175    unsigned long numberOfScrollableAreas(in Document document) raises (DOMException);
    173176
  • trunk/Source/WebKit/mac/ChangeLog

    r146847 r146907  
     12013-03-26  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        Implement overtype mode for editable content
     4        https://bugs.webkit.org/show_bug.cgi?id=112126
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Added the OverWrite editing command to the WebCore editing
     9        commands lists.
     10
     11        * WebView/WebHTMLView.mm:
     12        * WebView/WebView.h:
     13        * WebView/WebView.mm:
     14
    1152013-03-25  Kent Tamura  <tkent@chromium.org>
    216
  • trunk/Source/WebKit/mac/WebView/WebHTMLView.mm

    r143863 r146907  
    25032503WEBCORE_COMMAND(moveWordRightAndModifySelection)
    25042504WEBCORE_COMMAND(outdent)
     2505WEBCORE_COMMAND(overWrite)
    25052506WEBCORE_COMMAND(pageDown)
    25062507WEBCORE_COMMAND(pageDownAndModifySelection)
  • trunk/Source/WebKit/mac/WebView/WebView.h

    r93258 r146907  
    756756- (void)moveToEndOfSentenceAndModifySelection:(id)sender;
    757757- (void)selectSentence:(id)sender;
     758
     759- (void)overWrite:(id)sender;
    758760
    759761/*
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r146704 r146907  
    321321macro(moveWordRight) \
    322322macro(moveWordRightAndModifySelection) \
     323macro(orderFrontSubstitutionsPanel) \
    323324macro(outdent) \
    324 macro(orderFrontSubstitutionsPanel) \
     325macro(overWrite) \
    325326macro(pageDown) \
    326327macro(pageDownAndModifySelection) \
Note: See TracChangeset for help on using the changeset viewer.