Title: [146907] trunk
Revision
146907
Author
ser...@webkit.org
Date
2013-03-26 10:58:11 -0700 (Tue, 26 Mar 2013)

Log 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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (146906 => 146907)


--- trunk/LayoutTests/ChangeLog	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/LayoutTests/ChangeLog	2013-03-26 17:58:11 UTC (rev 146907)
@@ -1,3 +1,28 @@
+2013-03-26  Sergio Villar Senin  <svil...@igalia.com>
+
+        Implement overtype mode for editable content
+        https://bugs.webkit.org/show_bug.cgi?id=112126
+
+        Reviewed by Ryosuke Niwa.
+
+        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.
+
 2013-03-26  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r146901.

Modified: trunk/LayoutTests/editing/execCommand/enabling-and-selection-2-expected.txt (146906 => 146907)


--- trunk/LayoutTests/editing/execCommand/enabling-and-selection-2-expected.txt	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/LayoutTests/editing/execCommand/enabling-and-selection-2-expected.txt	2013-03-26 17:58:11 UTC (rev 146907)
@@ -83,6 +83,7 @@
 PASS whenEnabled('SelectSentence') is 'visible'
 PASS whenEnabled('SelectWord') is 'visible'
 PASS whenEnabled('SetMark') is 'visible'
+PASS whenEnabled('OverWrite') is 'richly editable'
 PASS successfullyParsed is true
 
 TEST COMPLETE

Added: trunk/LayoutTests/editing/execCommand/overtype-expected.txt (0 => 146907)


--- trunk/LayoutTests/editing/execCommand/overtype-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/execCommand/overtype-expected.txt	2013-03-26 17:58:11 UTC (rev 146907)
@@ -0,0 +1,108 @@
+This is a test for Overwrite mode
+
+These are the original contents:
+| "
+"
+| <b>
+|   "foo"
+| <a>
+|   href=""
+|   <div>
+|     id="linkText"
+|     "bar"
+| "
+"
+
+After overwritting the first two characters:
+| "
+"
+| <b>
+|   "FO<#selection-caret>o"
+| <a>
+|   href=""
+|   <div>
+|     id="linkText"
+|     "bar"
+| "
+"
+
+After inserting a blank:
+| "
+"
+| <b>
+|   "FO<#selection-caret> "
+| <a>
+|   href=""
+|   <div>
+|     id="linkText"
+|     "bar"
+| "
+"
+
+Overwrite at the end of a line performs as a normal Insert:
+| "
+"
+| <b>
+|   "FOO SOME MORE<#selection-caret>"
+| <a>
+|   href=""
+|   <div>
+|     id="linkText"
+|     "bar"
+| "
+"
+
+Overwritting works even if the inserted text is longer than the replaced text:
+| "
+"
+| <b>
+|   "FOO SOME MORE"
+| <a>
+|   href=""
+|   <div>
+|     id="linkText"
+|     "BAR.BAR<#selection-caret>"
+| "
+"
+
+Overwrite should create new text nodes on demand:
+| "
+"
+| <b>
+|   "FOO SOME MORE"
+| <div>
+|   id="linkText"
+|   <a>
+|     href=""
+|     "BAR.BAR"
+|   <br>
+|   "TEXT IN NEW NODE<#selection-caret>"
+| "
+"
+
+New plain text contents with an inner selection:
+| "we<#selection-anchor>bk<#selection-focus>it"
+
+Overwrite behaves like insert on range selections:
+| "weBK<#selection-caret>it"
+
+New CJK contents:
+| "丠両丢丣"
+
+Overwrite CJK text:
+| "且且<#selection-caret>丢丣"
+
+New RTL contents:
+| <div>
+|   dir="rtl"
+|   id="rtl-div"
+|   "ℵℶℷℸ"
+
+Overwrite RTL text:
+| <div>
+|   dir="rtl"
+|   id="rtl-div"
+|   "אא<#selection-caret>ℷℸ"
+
+console:
+| 

Added: trunk/LayoutTests/editing/execCommand/overtype-support-expected.txt (0 => 146907)


--- trunk/LayoutTests/editing/execCommand/overtype-support-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/execCommand/overtype-support-expected.txt	2013-03-26 17:58:11 UTC (rev 146907)
@@ -0,0 +1,11 @@
+This test checks that the Overwrite mode is: 1) not exposed to _javascript_ 2) queryCommandState returns false.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.queryCommandSupported('OverWrite') is false
+PASS document.queryCommandState('OverWrite') is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/editing/execCommand/overtype-support.html (0 => 146907)


--- trunk/LayoutTests/editing/execCommand/overtype-support.html	                        (rev 0)
+++ trunk/LayoutTests/editing/execCommand/overtype-support.html	2013-03-26 17:58:11 UTC (rev 146907)
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+description('This test checks that the Overwrite mode is: 1) not exposed to _javascript_ 2) queryCommandState returns false.');
+
+shouldBeFalse("document.queryCommandSupported('OverWrite')");
+shouldBeFalse("document.queryCommandState('OverWrite')");
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/editing/execCommand/overtype.html (0 => 146907)


--- trunk/LayoutTests/editing/execCommand/overtype.html	                        (rev 0)
+++ trunk/LayoutTests/editing/execCommand/overtype.html	2013-03-26 17:58:11 UTC (rev 146907)
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+</head>
+<body>
+<script type="text/_javascript_" src=""
+<script src=""
+<div id="test" contenteditable="true">
+<b>foo</b><a href="" id="linkText">bar</div></a>
+</div>
+<pre id="console"></pre>
+<script>
+function log(message) {
+    var console = document.getElementById("console");
+    console.innerHTML += message + '\n';
+}
+
+if (!window.internals)
+    log("FAILED: this test requires the 'internals' object.");
+else {
+    Markup.description('This is a test for Overwrite mode');
+
+    var element = document.getElementById("test");
+    var selection = window.getSelection();
+
+    Markup.dump(element, 'These are the original contents');
+
+    selection.collapse(element, 0);
+    internals.toggleOverwriteModeEnabled(document);
+
+    document.execCommand("InsertText", false, 'FO');
+    Markup.dump(element, 'After overwritting the first two characters');
+
+    document.execCommand("InsertText", false, ' ');
+    Markup.dump(element, 'After inserting a blank');
+
+    document.execCommand("InsertText", false, 'O SOME MORE');
+    Markup.dump(element, 'Overwrite at the end of a line performs as a normal Insert');
+
+    selection.collapse(document.getElementById("linkText"), 0);
+    document.execCommand("InsertText", false, 'BAR.BAR');
+    Markup.dump(element, 'Overwritting works even if the inserted text is longer than the replaced text');
+
+    moveSelectionForwardByWordCommand();
+    document.execCommand("InsertLineBreak");
+    document.execCommand("InsertText", false, 'TEXT IN NEW NODE');
+    Markup.dump(element, 'Overwrite should create new text nodes on demand');
+
+    element.innerHTML = "webkit";
+    selection.collapse(element, 0);
+    for (i = 0; i < 2; i++)
+        moveSelectionForwardByCharacterCommand();
+    for (i = 0; i < 2; i++)
+        extendSelectionForwardByCharacterCommand();
+    Markup.dump(element, 'New plain text contents with an inner selection');
+
+    document.execCommand("InsertText", false, 'BK');
+    Markup.dump(element, 'Overwrite behaves like insert on range selections');
+
+    element.innerHTML = "&#x4E20;&#x4E21;&#x4E22;&#x4E23;";
+    selection.collapse();
+    Markup.dump(element, 'New CJK contents');
+
+    selection.collapse(element, 0);
+    document.execCommand("InsertText", false, '\u4E14\u4E14');
+    Markup.dump(element, 'Overwrite CJK text');
+
+    element.innerHTML="<div id=\"rtl-div\" dir=\"rtl\">&aleph;&beth;&gimel;&daleth;</div>"
+    selection.collapse();
+    Markup.dump(element, 'New RTL contents');
+
+    selection.collapse(element, 0);
+    document.execCommand("InsertText", false, '\u05d0\u05d0');
+    Markup.dump(element, 'Overwrite RTL text');
+}
+Markup.dump('console', 'console');
+
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/editing/execCommand/script-tests/enabling-and-selection-2.js (146906 => 146907)


--- trunk/LayoutTests/editing/execCommand/script-tests/enabling-and-selection-2.js	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/LayoutTests/editing/execCommand/script-tests/enabling-and-selection-2.js	2013-03-26 17:58:11 UTC (rev 146907)
@@ -164,6 +164,8 @@
 shouldBe("whenEnabled('SelectWord')", "'visible'");
 shouldBe("whenEnabled('SetMark')", "'visible'");
 
+shouldBe("whenEnabled('OverWrite')", "'richly editable'");
+
 document.body.removeChild(nonEditableParagraph);
 document.body.removeChild(editableParagraph);
 document.body.removeChild(editablePlainTextParagraph);

Modified: trunk/Source/WebCore/ChangeLog (146906 => 146907)


--- trunk/Source/WebCore/ChangeLog	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebCore/ChangeLog	2013-03-26 17:58:11 UTC (rev 146907)
@@ -1,3 +1,57 @@
+2013-03-26  Sergio Villar Senin  <svil...@igalia.com>
+
+        Implement overtype mode for editable content
+        https://bugs.webkit.org/show_bug.cgi?id=112126
+
+        Reviewed by Ryosuke Niwa.
+
+        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:
+
 2013-03-26  Arvid Nilsson  <anils...@rim.com>
 
         [BlackBerry] WebOverlay::pixelViewportRect() should return pixel viewport coordinates

Modified: trunk/Source/WebCore/editing/CompositeEditCommand.cpp (146906 => 146907)


--- trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2013-03-26 17:58:11 UTC (rev 146907)
@@ -500,9 +500,10 @@
     applyCommandToComposite(DeleteFromTextNodeCommand::create(node, offset, count));
 }
 
-void CompositeEditCommand::replaceTextInNode(PassRefPtr<Text> node, unsigned offset, unsigned count, const String& replacementText)
+void CompositeEditCommand::replaceTextInNode(PassRefPtr<Text> prpNode, unsigned offset, unsigned count, const String& replacementText)
 {
-    applyCommandToComposite(DeleteFromTextNodeCommand::create(node.get(), offset, count));
+    RefPtr<Text> node(prpNode);
+    applyCommandToComposite(DeleteFromTextNodeCommand::create(node, offset, count));
     if (!replacementText.isEmpty())
         applyCommandToComposite(InsertIntoTextNodeCommand::create(node, offset, replacementText));
 }

Modified: trunk/Source/WebCore/editing/Editor.cpp (146906 => 146907)


--- trunk/Source/WebCore/editing/Editor.cpp	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebCore/editing/Editor.cpp	2013-03-26 17:58:11 UTC (rev 146907)
@@ -905,6 +905,7 @@
     , m_alternativeTextController(adoptPtr(new AlternativeTextController(frame)))
     , m_areMarkedTextMatchesHighlighted(false)
     , m_defaultParagraphSeparator(EditorParagraphSeparatorIsDiv)
+    , m_overwriteModeEnabled(false)
 {
 #if ENABLE(DELETION_UI)
     m_deleteButtonController = adoptPtr(new DeleteButtonController(frame));

Modified: trunk/Source/WebCore/editing/Editor.h (146906 => 146907)


--- trunk/Source/WebCore/editing/Editor.h	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebCore/editing/Editor.h	2013-03-26 17:58:11 UTC (rev 146907)
@@ -245,6 +245,9 @@
     void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection);
     void markAndReplaceFor(PassRefPtr<SpellCheckRequest>, const Vector<TextCheckingResult>&);
 
+    bool isOverwriteModeEnabled() const { return m_overwriteModeEnabled; }
+    void toggleOverwriteModeEnabled() { m_overwriteModeEnabled = !m_overwriteModeEnabled; }
+
 #if USE(APPKIT)
     void uppercaseWord();
     void lowercaseWord();
@@ -433,6 +436,7 @@
     VisibleSelection m_mark;
     bool m_areMarkedTextMatchesHighlighted;
     EditorParagraphSeparator m_defaultParagraphSeparator;
+    bool m_overwriteModeEnabled;
 
     bool canDeleteRange(Range*) const;
     bool canSmartReplaceWithPasteboard(Pasteboard*);

Modified: trunk/Source/WebCore/editing/EditorCommand.cpp (146906 => 146907)


--- trunk/Source/WebCore/editing/EditorCommand.cpp	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebCore/editing/EditorCommand.cpp	2013-03-26 17:58:11 UTC (rev 146907)
@@ -902,6 +902,12 @@
     return true;
 }
 
+static bool executeToggleOverwrite(Frame* frame, Event*, EditorCommandSource, const String&)
+{
+    frame->editor()->toggleOverwriteModeEnabled();
+    return true;
+}
+
 static bool executePaste(Frame* frame, Event*, EditorCommandSource source, const String&)
 {
     if (source == CommandFromMenuOrKeyBinding) {
@@ -1551,6 +1557,7 @@
         { "MoveWordRight", { executeMoveWordRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "MoveWordRightAndModifySelection", { executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "Outdent", { executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
+        { "OverWrite", { executeToggleOverwrite, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "Paste", { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
         { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
         { "PasteAsPlainText", { executePasteAsPlainText, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
@@ -1629,7 +1636,6 @@
     // LiveResize (not supported)
     // MultipleSelection (not supported)
     // Open (not supported)
-    // Overwrite (not supported)
     // PlayImage (not supported)
     // Refresh (not supported)
     // RemoveParaFormat (not supported)

Modified: trunk/Source/WebCore/editing/InsertTextCommand.cpp (146906 => 146907)


--- trunk/Source/WebCore/editing/InsertTextCommand.cpp	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebCore/editing/InsertTextCommand.cpp	2013-03-26 17:58:11 UTC (rev 146907)
@@ -75,13 +75,27 @@
     return pos;
 }
 
+void InsertTextCommand::setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition, bool selectInsertedText)
+{
+    // We could have inserted a part of composed character sequence,
+    // so we are basically treating ending selection as a range to avoid validation.
+    // <http://bugs.webkit.org/show_bug.cgi?id=15781>
+    VisibleSelection forcedEndingSelection;
+    forcedEndingSelection.setWithoutValidation(startPosition, endPosition);
+    forcedEndingSelection.setIsDirectional(endingSelection().isDirectional());
+    setEndingSelection(forcedEndingSelection);
+
+    if (!selectInsertedText)
+        setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
+}
+
 // This avoids the expense of a full fledged delete operation, and avoids a layout that typically results
 // from text removal.
 bool InsertTextCommand::performTrivialReplace(const String& text, bool selectInsertedText)
 {
     if (!endingSelection().isRange())
         return false;
-    
+
     if (text.contains('\t') || text.contains(' ') || text.contains('\n'))
         return false;
 
@@ -90,20 +104,27 @@
     if (endPosition.isNull())
         return false;
 
-    // We could have inserted a part of composed character sequence,
-    // so we are basically treating ending selection as a range to avoid validation.
-    // <http://bugs.webkit.org/show_bug.cgi?id=15781>
-    VisibleSelection forcedEndingSelection;
-    forcedEndingSelection.setWithoutValidation(start, endPosition);
-    forcedEndingSelection.setIsDirectional(endingSelection().isDirectional());
-    setEndingSelection(forcedEndingSelection);
+    setEndingSelectionWithoutValidation(start, endPosition, selectInsertedText);
 
-    if (!selectInsertedText)
-        setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
-    
     return true;
 }
 
+bool InsertTextCommand::performOverwrite(const String& text, bool selectInsertedText)
+{
+    Position start = endingSelection().start();
+    RefPtr<Text> textNode = start.containerText();
+    if (!textNode)
+        return false;
+
+    unsigned count = std::min(text.length(), textNode->length() - start.offsetInContainerNode());
+    replaceTextInNode(textNode, start.offsetInContainerNode(), count, text);
+
+    Position endPosition = Position(textNode.release(), start.offsetInContainerNode() + text.length());
+    setEndingSelectionWithoutValidation(start, endPosition, selectInsertedText);
+
+    return true;
+}
+
 void InsertTextCommand::doApply()
 {
     ASSERT(m_text.find('\n') == notFound);
@@ -122,6 +143,9 @@
         // anything other than NoSelection. The rest of this function requires a real endingSelection, so bail out.
         if (endingSelection().isNone())
             return;
+    } else if (document()->frame()->editor()->isOverwriteModeEnabled()) {
+        if (performOverwrite(m_text, m_selectInsertedText))
+            return;
     }
 
     Position startPosition(endingSelection().start());

Modified: trunk/Source/WebCore/editing/InsertTextCommand.h (146906 => 146907)


--- trunk/Source/WebCore/editing/InsertTextCommand.h	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebCore/editing/InsertTextCommand.h	2013-03-26 17:58:11 UTC (rev 146907)
@@ -72,6 +72,8 @@
     Position insertTab(const Position&);
     
     bool performTrivialReplace(const String&, bool selectInsertedText);
+    bool performOverwrite(const String&, bool selectInsertedText);
+    void setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition, bool selectInsertedText);
 
     friend class TypingCommand;
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (146906 => 146907)


--- trunk/Source/WebCore/testing/Internals.cpp	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebCore/testing/Internals.cpp	2013-03-26 17:58:11 UTC (rev 146907)
@@ -274,6 +274,8 @@
 #endif
     if (!page->mainFrame()->editor()->isContinuousSpellCheckingEnabled())
         page->mainFrame()->editor()->toggleContinuousSpellChecking();
+    if (page->mainFrame()->editor()->isOverwriteModeEnabled())
+        page->mainFrame()->editor()->toggleOverwriteModeEnabled();
 }
 
 Internals::Internals(Document* document)
@@ -1513,6 +1515,22 @@
         contextDocument()->frame()->editor()->toggleContinuousSpellChecking();
 }
 
+bool Internals::isOverwriteModeEnabled(Document* document, ExceptionCode&)
+{
+    if (!document || !document->frame())
+        return 0;
+
+    return document->frame()->editor()->isOverwriteModeEnabled();
+}
+
+void Internals::toggleOverwriteModeEnabled(Document* document, ExceptionCode&)
+{
+    if (!document || !document->frame())
+        return;
+
+    document->frame()->editor()->toggleOverwriteModeEnabled();
+}
+
 #if ENABLE(INSPECTOR)
 unsigned Internals::numberOfLiveNodes() const
 {

Modified: trunk/Source/WebCore/testing/Internals.h (146906 => 146907)


--- trunk/Source/WebCore/testing/Internals.h	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebCore/testing/Internals.h	2013-03-26 17:58:11 UTC (rev 146907)
@@ -202,6 +202,9 @@
     bool hasAutocorrectedMarker(Document*, int from, int length, ExceptionCode&);
     void setContinuousSpellCheckingEnabled(bool enabled, ExceptionCode&);
 
+    bool isOverwriteModeEnabled(Document*, ExceptionCode&);
+    void toggleOverwriteModeEnabled(Document*, ExceptionCode&);
+
     unsigned numberOfScrollableAreas(Document*, ExceptionCode&);
 
     bool isPageBoxVisible(Document*, int pageNumber, ExceptionCode&);

Modified: trunk/Source/WebCore/testing/Internals.idl (146906 => 146907)


--- trunk/Source/WebCore/testing/Internals.idl	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebCore/testing/Internals.idl	2013-03-26 17:58:11 UTC (rev 146907)
@@ -169,6 +169,9 @@
     boolean hasAutocorrectedMarker(in Document document, in long from, in long length) raises (DOMException);
     void setContinuousSpellCheckingEnabled(in boolean enabled) raises (DOMException);
 
+    boolean isOverwriteModeEnabled(in Document document) raises (DOMException);
+    void toggleOverwriteModeEnabled(in Document document) raises (DOMException);
+
     unsigned long numberOfScrollableAreas(in Document document) raises (DOMException);
 
     boolean isPageBoxVisible(in Document document, in long pageNumber) raises (DOMException);

Modified: trunk/Source/WebKit/mac/ChangeLog (146906 => 146907)


--- trunk/Source/WebKit/mac/ChangeLog	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebKit/mac/ChangeLog	2013-03-26 17:58:11 UTC (rev 146907)
@@ -1,3 +1,17 @@
+2013-03-26  Sergio Villar Senin  <svil...@igalia.com>
+
+        Implement overtype mode for editable content
+        https://bugs.webkit.org/show_bug.cgi?id=112126
+
+        Reviewed by Ryosuke Niwa.
+
+        Added the OverWrite editing command to the WebCore editing
+        commands lists.
+
+        * WebView/WebHTMLView.mm:
+        * WebView/WebView.h:
+        * WebView/WebView.mm:
+
 2013-03-25  Kent Tamura  <tk...@chromium.org>
 
         Rename ENABLE_INPUT_TYPE_DATETIME

Modified: trunk/Source/WebKit/mac/WebView/WebHTMLView.mm (146906 => 146907)


--- trunk/Source/WebKit/mac/WebView/WebHTMLView.mm	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebKit/mac/WebView/WebHTMLView.mm	2013-03-26 17:58:11 UTC (rev 146907)
@@ -2502,6 +2502,7 @@
 WEBCORE_COMMAND(moveWordRight)
 WEBCORE_COMMAND(moveWordRightAndModifySelection)
 WEBCORE_COMMAND(outdent)
+WEBCORE_COMMAND(overWrite)
 WEBCORE_COMMAND(pageDown)
 WEBCORE_COMMAND(pageDownAndModifySelection)
 WEBCORE_COMMAND(pageUp)

Modified: trunk/Source/WebKit/mac/WebView/WebView.h (146906 => 146907)


--- trunk/Source/WebKit/mac/WebView/WebView.h	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebKit/mac/WebView/WebView.h	2013-03-26 17:58:11 UTC (rev 146907)
@@ -756,6 +756,8 @@
 - (void)moveToEndOfSentenceAndModifySelection:(id)sender;
 - (void)selectSentence:(id)sender;
 
+- (void)overWrite:(id)sender;
+
 /* 
 The following methods are declared in NSResponder.h.
 WebView overrides each method in this list, providing

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (146906 => 146907)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2013-03-26 17:44:19 UTC (rev 146906)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2013-03-26 17:58:11 UTC (rev 146907)
@@ -320,8 +320,9 @@
 macro(moveWordLeftAndModifySelection) \
 macro(moveWordRight) \
 macro(moveWordRightAndModifySelection) \
+macro(orderFrontSubstitutionsPanel) \
 macro(outdent) \
-macro(orderFrontSubstitutionsPanel) \
+macro(overWrite) \
 macro(pageDown) \
 macro(pageDownAndModifySelection) \
 macro(pageUp) \
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to