WebCore:
authoradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Sep 2007 23:53:52 +0000 (23:53 +0000)
committeradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Sep 2007 23:53:52 +0000 (23:53 +0000)
        Reviewed by Dave Harrison.

        Fix for <rdar://problem/5428427> Wrong characters are re-converted after doing reconversion with Kotoeri

        Revert change for<rdar://problem/5279521> and add nil checks for the result of TextIterator::rangeFromLocationAndLength
        TextIterator::exitNode shouldn't require the m_lastTextNode to be true, but we can't change that without making the logic in _web_attributedStringFromRange match.
        We'll get that for free when we switch to use TextIterator in _web_attributedStringFromRange.

        * editing/ApplyStyleCommand.cpp: (WebCore::ApplyStyleCommand::applyBlockStyle): Added nil checks.
        * editing/IndentOutdentCommand.cpp: (WebCore::IndentOutdentCommand::indentRegion): ditto.
        * editing/TextIterator.cpp: (WebCore::TextIterator::exitNode): Re-added check for m_lastTextNode before emitting newline.

LayoutTests:

        Reviewed by Dave Harrison.

        Tests for <rdar://problem/5428427> Wrong characters are re-converted after doing reconversion with Kotoeri

        * platform/mac/fast/text/attributed-substring-from-range-002-expected.txt: Added.
        * platform/mac/fast/text/attributed-substring-from-range-002.html: Added.
        * fast/forms/textarea-type-spaces-expected.txt: Revert back to old result.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@25429 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/textarea-type-spaces-expected.txt
LayoutTests/platform/mac/fast/text/attributed-substring-from-range-002-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/text/attributed-substring-from-range-002.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/ApplyStyleCommand.cpp
WebCore/editing/IndentOutdentCommand.cpp
WebCore/editing/TextIterator.cpp

index 136e8f7324743174525e89c1e23c63091b8d5f13..167e588da7a9f1cb542fd07f9ca97ab7ffb2faa3 100644 (file)
@@ -1,3 +1,13 @@
+2007-09-07  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Dave Harrison.
+
+        Tests for <rdar://problem/5428427> Wrong characters are re-converted after doing reconversion with Kotoeri
+
+        * platform/mac/fast/text/attributed-substring-from-range-002-expected.txt: Added.
+        * platform/mac/fast/text/attributed-substring-from-range-002.html: Added.
+        * fast/forms/textarea-type-spaces-expected.txt: Revert back to old result.
+
 2007-09-07  Sam Weinig  <sam@webkit.org>
 
         * platform/win/Skipped: fix typo
index b0dd03086077241ba344ad2c8a3156813f71af41..f4fda22d51b7a302c5e22ffd37ff2318224faf41 100644 (file)
@@ -1,3 +1,2 @@
 
-
 Hooray, test worked!
diff --git a/LayoutTests/platform/mac/fast/text/attributed-substring-from-range-002-expected.txt b/LayoutTests/platform/mac/fast/text/attributed-substring-from-range-002-expected.txt
new file mode 100644 (file)
index 0000000..c949541
--- /dev/null
@@ -0,0 +1,8 @@
+123456789
+-
+This tests a particular construction that screws up the text iterator.
+-
+actual text: \n123456789
+from innerText (TextIterator): 123456789
+from attributedSubstringFromRange: 123456789
+SUCCESS: Strings matched, although there is room for improvement because they were both wrong.
diff --git a/LayoutTests/platform/mac/fast/text/attributed-substring-from-range-002.html b/LayoutTests/platform/mac/fast/text/attributed-substring-from-range-002.html
new file mode 100644 (file)
index 0000000..fb1849b
--- /dev/null
@@ -0,0 +1,49 @@
+<html>
+<body contenteditable><div><object></object></div>123456789</body>
+<script>
+    var console_messages = document.createElement("ol");
+    function log(message)
+    {
+        var item = document.createElement("li");
+        item.appendChild(document.createTextNode(message));
+        console_messages.appendChild(item);
+    }
+    function createConsole()
+    {
+        var console = document.createElement("pre");
+        console.appendChild(console_messages);
+        document.body.appendChild(console);
+    }
+    
+    log("-");
+    log("This tests a particular construction that screws up the text iterator.");
+    log("-");
+
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+    
+        // Set selection, because attributedSubstringFromRange only works on the run of text that's
+        // currently selected.
+        window.getSelection().setPosition(document.body, 0);
+
+        var stringFromInnerText = document.body.innerText;
+        var stringFromAttributedSubstring = textInputController.attributedSubstringFromRange(0, 100).string();
+
+        log("actual text: \\n123456789");
+        log("from innerText (TextIterator): " + stringFromInnerText.replace("\n", "\\n"));
+        log("from attributedSubstringFromRange: " + stringFromAttributedSubstring.replace("\n", "\\n"));
+
+        if (stringFromInnerText != stringFromAttributedSubstring)
+            log("FAILED: Strings must match to keep input methods working.");
+        else if (stringFromInnerText == "\n123456789")
+            log("SUCCESS: Strings were correct.");
+        else
+            log("SUCCESS: Strings matched, although there is room for improvement because they were both wrong.");
+    } else {
+        log("DID NOT TEST: This test cannot run interactively.");
+    }
+    createConsole();
+    
+</script>
+</body>
+</html>
index cf62014ccd4ec675ff8c685ba20a0f16cb147406..e5e5807d1968848bf665b0181a0f4c2316be6b76 100644 (file)
@@ -1,3 +1,17 @@
+2007-09-07  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Dave Harrison.
+
+        Fix for <rdar://problem/5428427> Wrong characters are re-converted after doing reconversion with Kotoeri
+
+        Revert change for<rdar://problem/5279521> and add nil checks for the result of TextIterator::rangeFromLocationAndLength
+        TextIterator::exitNode shouldn't require the m_lastTextNode to be true, but we can't change that without making the logic in _web_attributedStringFromRange match.
+        We'll get that for free when we switch to use TextIterator in _web_attributedStringFromRange.
+
+        * editing/ApplyStyleCommand.cpp: (WebCore::ApplyStyleCommand::applyBlockStyle): Added nil checks.
+        * editing/IndentOutdentCommand.cpp: (WebCore::IndentOutdentCommand::indentRegion): ditto.
+        * editing/TextIterator.cpp: (WebCore::TextIterator::exitNode): Re-added check for m_lastTextNode before emitting newline.
+
 2007-09-07  Ada Chan  <adachan@apple.com>
 
         <rdar://problem/5395928> Need to be able to handle context menu item selection by index
index 942b176e84936f8f082897117ccc43e08811ed2f..fb8a6c7fd1dc1ba9cb836d2966f6f1918d942339 100644 (file)
@@ -411,8 +411,10 @@ void ApplyStyleCommand::applyBlockStyle(CSSMutableStyleDeclaration *style)
         nextParagraphStart = endOfParagraph(paragraphStart).next();
     }
     
-    updateStartEnd(TextIterator::rangeFromLocationAndLength(static_cast<Element*>(scope), startIndex, 0, true)->startPosition(),
-                   TextIterator::rangeFromLocationAndLength(static_cast<Element*>(scope), endIndex, 0, true)->startPosition());
+    startRange = TextIterator::rangeFromLocationAndLength(static_cast<Element*>(scope), startIndex, 0, true);
+    endRange = TextIterator::rangeFromLocationAndLength(static_cast<Element*>(scope), endIndex, 0, true);
+    if (startRange && endRange)
+        updateStartEnd(startRange->startPosition(), endRange->startPosition());
 }
 
 #define NoFontDelta (0.0f)
index 5f4472a2da89eced75e3ec2713fddb7e513405f8..b6ed1f338f0d06ee029117b508548224314aba6b 100644 (file)
@@ -198,7 +198,8 @@ void IndentOutdentCommand::indentRegion()
     
     RefPtr<Range> startRange = TextIterator::rangeFromLocationAndLength(document()->documentElement(), 0, startIndex);
     RefPtr<Range> endRange = TextIterator::rangeFromLocationAndLength(document()->documentElement(), 0, endIndex);
-    setEndingSelection(Selection(startRange->endPosition(), endRange->endPosition(), DOWNSTREAM));
+    if (startRange && endRange)
+        setEndingSelection(Selection(startRange->endPosition(), endRange->endPosition(), DOWNSTREAM));
 }
 
 void IndentOutdentCommand::outdentParagraph()
index 2b24b3f5197d74dcea5ef95386e1334f5486521c..c5292f843776d42e8ceb5bed901d44f894980dda 100644 (file)
@@ -571,7 +571,10 @@ void TextIterator::exitNode()
     // case it is a block, because the run should start where the 
     // emitted character is positioned visually.
     Node* baseNode = m_node->lastChild() ? m_node->lastChild() : m_node;
-    if (shouldEmitNewlineAfterNode(m_node)) {
+    // FIXME: This shouldn't require the m_lastTextNode to be true, but we can't change that without making
+    // the logic in _web_attributedStringFromRange match.  We'll get that for free when we switch to use TextIterator in _web_attributedStringFromRange.
+    // See <rdar://problem/5428427> for an example of how this mismatch will cause problems.
+    if (m_lastTextNode && shouldEmitNewlineAfterNode(m_node)) {
         // use extra newline to represent margin bottom, as needed
         bool addNewline = shouldEmitExtraNewlineForNode(m_node);