LayoutTests:
authorharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Oct 2006 14:44:40 +0000 (14:44 +0000)
committerharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Oct 2006 14:44:40 +0000 (14:44 +0000)
        Reviewed by Maciej.

        <rdar://problem/4671286> Candidate Window isn't displayed and only first candidate is displayed at typing location.

        Updated test so that it actually shows the caret rect for the caret position.
        Before, it was showing the caret rect for the 9th character of the test description.

        * fast/text/justified-text-rect-expected.checksum:
        * fast/text/justified-text-rect-expected.png:
        * fast/text/justified-text-rect-expected.txt:
        * fast/text/justified-text-rect.html:

WebCore:

        Reviewed by Maciej.

        <rdar://problem/4671286> Candidate Window isn't displayed and only first candidate is displayed at typing location.

        Updated test:
        * fast/text/justified-text-rect.html

        * bridge/mac/WebCoreFrameBridge.mm:
        (-[WebCoreFrameBridge convertToNSRange:]):
        (-[WebCoreFrameBridge convertToDOMRange:]):
        Make the selection's root editable element (or the document itself) be
        the basis for NSRange conversions. This supports "shadow DOM" like
        that for text fields and text areas.

        * editing/CompositeEditCommand.cpp:
        (WebCore::CompositeEditCommand::moveParagraphs):
        Pass the document element as the scope.

        * editing/TextIterator.cpp:
        (WebCore::TextIterator::rangeFromLocationAndLength):
        Make the first parameter the scope.

        * editing/TextIterator.h:
        Make the first parameter of rangeFromLocationAndLength() the scope.

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

LayoutTests/ChangeLog
LayoutTests/fast/text/justified-text-rect-expected.checksum
LayoutTests/fast/text/justified-text-rect-expected.png
LayoutTests/fast/text/justified-text-rect-expected.txt
LayoutTests/fast/text/justified-text-rect.html
WebCore/ChangeLog
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/editing/CompositeEditCommand.cpp
WebCore/editing/TextIterator.cpp
WebCore/editing/TextIterator.h

index d49d3d6b74f5b3d9e3f12cf627c49c947eaa5e3b..5caf60f7783716d425ecf0ac52f2b13695df8aae 100644 (file)
@@ -1,3 +1,17 @@
+2006-10-03  David Harrison  <harrison@apple.com>
+
+        Reviewed by Maciej.
+        
+        <rdar://problem/4671286> Candidate Window isn't displayed and only first candidate is displayed at typing location.
+
+        Updated test so that it actually shows the caret rect for the caret position.
+        Before, it was showing the caret rect for the 9th character of the test description.
+        
+        * fast/text/justified-text-rect-expected.checksum:
+        * fast/text/justified-text-rect-expected.png:
+        * fast/text/justified-text-rect-expected.txt:
+        * fast/text/justified-text-rect.html:
+
 2006-10-02  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by john
index 423261bb82610a81b05b46068679d666d487bc37..4ce5a511cab831e5ff6dfd4bf87287b371d2d640 100644 (file)
@@ -1 +1 @@
-a29ef9f14534f7c1ec660153a7e26d2b
\ No newline at end of file
+913f637b065759f731e303b8e54a4007
\ No newline at end of file
index 6d5f14d0e5642f1667c01fe30471a49fcc96069d..8a915a115a46313a3769480739aac2156eac8f35 100644 (file)
Binary files a/LayoutTests/fast/text/justified-text-rect-expected.png and b/LayoutTests/fast/text/justified-text-rect-expected.png differ
index 9c9143f3535514581bf7d2924f40fa3ed6c41d96..59961c2046c26415ea9984fea51a4db868e4a835 100644 (file)
@@ -25,7 +25,7 @@ layer at (0,0) size 800x600
           text run at (0,18) width 50: "justified"
       RenderBlock (anonymous) at (0,136) size 800x18
         RenderText {#text} at (0,0) size 76x18
-          text run at (0,0) width 76: "53,582,4,18"
+          text run at (0,0) width 76: "38,512,4,18"
         RenderText {#text} at (0,0) size 0x0
         RenderText {#text} at (0,0) size 0x0
 caret: position 8 of child 0 {#text} of child 3 {P} of child 1 {BODY} of child 0 {HTML} of document
index 93248aae98ea5d5a160f8a07d094a3d1d7175787..a18c984a63f74fb8a1a04a4366ffa62434526fe5 100644 (file)
@@ -16,15 +16,15 @@ body { margin: 0; padding: 0 }
             var s = window.getSelection();
             var e = document.getElementById("testspan");
             s.setPosition(e, 0);
-            rect = textInputController.firstRectForCharacterRange(9, 1);
+            rect = textInputController.firstRectForCharacterRange(8, 1);
             document.write(rect);
 
-               } catch (ex) {
-                       document.write("Exception: " + ex.description);
-               }
-       } else {
-               document.write("(cannot run interactively)");
-       }
+        } catch (ex) {
+            document.write("Exception: " + ex.description);
+        }
+    } else {
+        document.write("(cannot run interactively)");
+    }
 </script>
 </body>
 </html>
index b24c8e61c0a2844b137f6001d2d7f000b991f01f..09d50a37b377d634527e6b71e18212df68c48de2 100644 (file)
@@ -1,3 +1,30 @@
+2006-10-03  David Harrison  <harrison@apple.com>
+
+        Reviewed by Maciej.
+
+        <rdar://problem/4671286> Candidate Window isn't displayed and only first candidate is displayed at typing location.
+
+        Updated test:
+        * fast/text/justified-text-rect.html
+
+        * bridge/mac/WebCoreFrameBridge.mm:
+        (-[WebCoreFrameBridge convertToNSRange:]):
+        (-[WebCoreFrameBridge convertToDOMRange:]):
+        Make the selection's root editable element (or the document itself) be
+        the basis for NSRange conversions. This supports "shadow DOM" like
+        that for text fields and text areas.
+        
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::moveParagraphs):
+        Pass the document element as the scope.
+        
+        * editing/TextIterator.cpp:
+        (WebCore::TextIterator::rangeFromLocationAndLength):
+        Make the first parameter the scope.
+        
+        * editing/TextIterator.h:
+        Make the first parameter of rangeFromLocationAndLength() the scope.
+
 2006-10-03  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Eric.
index 17774f7d24d2988f16778433b5eb74435a08f8b5..63f881e5a628d01cace8754e9d52f50b74b104f2 100644 (file)
@@ -1706,18 +1706,26 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
 
 - (NSRange)convertToNSRange:(Range *)range
 {
-    if (!range || range->isDetached()) {
-        return NSMakeRange(NSNotFound, 0);
-    }
-
-    RefPtr<Range> fromStartRange(m_frame->document()->createRange());
     int exception = 0;
 
-    fromStartRange->setEnd(range->startContainer(exception), range->startOffset(exception), exception);
-    int startPosition = TextIterator::rangeLength(fromStartRange.get());
+    if (!range || range->isDetached())
+        return NSMakeRange(NSNotFound, 0);
+
+    Element* selectionRoot = m_frame->selectionController()->rootEditableElement();
+    Element* scope = selectionRoot ? selectionRoot : m_frame->document()->documentElement();
+    
+    // our critical assumption is that we are only called by input methods that
+    // concentrate on a given area containing the selection.  See comments in convertToDOMRange.
+    ASSERT(range->startContainer(exception) == scope || range->startContainer(exception)->isDescendantOf(scope));
+    ASSERT(range->endContainer(exception) == scope || range->endContainer(exception)->isDescendantOf(scope));
+    
+    RefPtr<Range> testRange = new Range(scope->document(), scope, 0, range->startContainer(exception), range->startOffset(exception));
+    ASSERT(testRange->startContainer(exception) == scope);
+    int startPosition = TextIterator::rangeLength(testRange.get());
 
-    fromStartRange->setEnd(range->endContainer(exception), range->endOffset(exception), exception);
-    int endPosition = TextIterator::rangeLength(fromStartRange.get());
+    testRange->setEnd(range->endContainer(exception), range->endOffset(exception), exception);
+    ASSERT(testRange->startContainer(exception) == scope);
+    int endPosition = TextIterator::rangeLength(testRange.get());
 
     return NSMakeRange(startPosition, endPosition - startPosition);
 }
@@ -1729,7 +1737,15 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
     if (nsrange.length > INT_MAX || nsrange.location + nsrange.length > INT_MAX)
         nsrange.length = INT_MAX - nsrange.location;
 
-    return TextIterator::rangeFromLocationAndLength(m_frame->document(), nsrange.location, nsrange.length);
+    // our critical assumption is that we are only called by input methods that
+    // concentrate on a given area containing the selection
+    // We have to do this because of text fields and textareas. The DOM for those is not
+    // directly in the document DOM, so serialization is problematic. Our solution is
+    // to use the root editable element of the selection start as the positional base.
+    // That fits with AppKit's idea of an input context.
+    Element* selectionRoot = m_frame->selectionController()->rootEditableElement();
+    Element* scope = selectionRoot ? selectionRoot : m_frame->document()->documentElement();
+    return TextIterator::rangeFromLocationAndLength(scope, nsrange.location, nsrange.length);
 }
 
 - (DOMRange *)convertNSRangeToDOMRange:(NSRange)nsrange
index 2e3ed9a2d31fec4cf41148e3919b4c53f694b574..ebf5725ad5abf76a4f9e62e164dcc8c62955cf5a 100644 (file)
@@ -690,8 +690,8 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
     applyCommandToComposite(new ReplaceSelectionCommand(document(), fragment.get(), true, false, !preserveStyle, false));
     
     if (preserveSelection && startIndex != -1) {
-        setEndingSelection(Selection(TextIterator::rangeFromLocationAndLength(document(), destinationIndex + startIndex, 0)->startPosition(), 
-                                     TextIterator::rangeFromLocationAndLength(document(), destinationIndex + endIndex, 0)->startPosition(), 
+        setEndingSelection(Selection(TextIterator::rangeFromLocationAndLength(document()->documentElement(), destinationIndex + startIndex, 0)->startPosition(), 
+                                     TextIterator::rangeFromLocationAndLength(document()->documentElement(), destinationIndex + endIndex, 0)->startPosition(), 
                                      DOWNSTREAM));
     }
 }
index 642a6190b41055ac7496ce1ae98ede6f94884b83..b073a2c59e930eb102139e9b24d7507f36f34071 100644 (file)
@@ -1019,9 +1019,9 @@ int TextIterator::rangeLength(const Range *r)
     return length;
 }
 
-PassRefPtr<Range> TextIterator::rangeFromLocationAndLength(Document *doc, int rangeLocation, int rangeLength)
+PassRefPtr<Range> TextIterator::rangeFromLocationAndLength(Element *scope, int rangeLocation, int rangeLength)
 {
-    RefPtr<Range> resultRange = doc->createRange();
+    RefPtr<Range> resultRange = scope->document()->createRange();
 
     int docTextPosition = 0;
     int rangeEnd = rangeLocation + rangeLength;
@@ -1029,7 +1029,7 @@ PassRefPtr<Range> TextIterator::rangeFromLocationAndLength(Document *doc, int ra
 
     RefPtr<Range> textRunRange;
 
-    TextIterator it(rangeOfContents(doc).get());
+    TextIterator it(rangeOfContents(scope).get());
     
     // FIXME: the atEnd() check shouldn't be necessary, workaround for <http://bugzilla.opendarwin.org/show_bug.cgi?id=6289>.
     if (rangeLocation == 0 && rangeLength == 0 && it.atEnd()) {
index ab012560b1d046b53e90093fb06927cf715db65f..f11cc0cedabee1295b8c922b80f935f5c1545d8f 100644 (file)
@@ -71,7 +71,7 @@ public:
     PassRefPtr<Range> range() const;
      
     static int rangeLength(const Range *r);
-    static PassRefPtr<Range> rangeFromLocationAndLength(Document *doc, int rangeLocation, int rangeLength);
+    static PassRefPtr<Range> rangeFromLocationAndLength(Element *scope, int rangeLocation, int rangeLength);
     
 private:
     void exitNode();