Commit 01ad47aa authored by harrison's avatar harrison

LayoutTests:

        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: http://svn.webkit.org/repository/webkit/trunk@16737 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 54b6b95a
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> 2006-10-02 Justin Garcia <justin.garcia@apple.com>
Reviewed by john Reviewed by john
a29ef9f14534f7c1ec660153a7e26d2b 913f637b065759f731e303b8e54a4007
\ No newline at end of file \ No newline at end of file
...@@ -25,7 +25,7 @@ layer at (0,0) size 800x600 ...@@ -25,7 +25,7 @@ layer at (0,0) size 800x600
text run at (0,18) width 50: "justified" text run at (0,18) width 50: "justified"
RenderBlock (anonymous) at (0,136) size 800x18 RenderBlock (anonymous) at (0,136) size 800x18
RenderText {#text} at (0,0) size 76x18 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
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 caret: position 8 of child 0 {#text} of child 3 {P} of child 1 {BODY} of child 0 {HTML} of document
...@@ -16,15 +16,15 @@ body { margin: 0; padding: 0 } ...@@ -16,15 +16,15 @@ body { margin: 0; padding: 0 }
var s = window.getSelection(); var s = window.getSelection();
var e = document.getElementById("testspan"); var e = document.getElementById("testspan");
s.setPosition(e, 0); s.setPosition(e, 0);
rect = textInputController.firstRectForCharacterRange(9, 1); rect = textInputController.firstRectForCharacterRange(8, 1);
document.write(rect); document.write(rect);
} catch (ex) { } catch (ex) {
document.write("Exception: " + ex.description); document.write("Exception: " + ex.description);
} }
} else { } else {
document.write("(cannot run interactively)"); document.write("(cannot run interactively)");
} }
</script> </script>
</body> </body>
</html> </html>
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> 2006-10-03 Nikolas Zimmermann <zimmermann@kde.org>
Reviewed by Eric. Reviewed by Eric.
...@@ -1706,18 +1706,26 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element) ...@@ -1706,18 +1706,26 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
- (NSRange)convertToNSRange:(Range *)range - (NSRange)convertToNSRange:(Range *)range
{ {
if (!range || range->isDetached()) {
return NSMakeRange(NSNotFound, 0);
}
RefPtr<Range> fromStartRange(m_frame->document()->createRange());
int exception = 0; int exception = 0;
fromStartRange->setEnd(range->startContainer(exception), range->startOffset(exception), exception); if (!range || range->isDetached())
int startPosition = TextIterator::rangeLength(fromStartRange.get()); 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); testRange->setEnd(range->endContainer(exception), range->endOffset(exception), exception);
int endPosition = TextIterator::rangeLength(fromStartRange.get()); ASSERT(testRange->startContainer(exception) == scope);
int endPosition = TextIterator::rangeLength(testRange.get());
return NSMakeRange(startPosition, endPosition - startPosition); return NSMakeRange(startPosition, endPosition - startPosition);
} }
...@@ -1729,7 +1737,15 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element) ...@@ -1729,7 +1737,15 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
if (nsrange.length > INT_MAX || nsrange.location + nsrange.length > INT_MAX) if (nsrange.length > INT_MAX || nsrange.location + nsrange.length > INT_MAX)
nsrange.length = INT_MAX - nsrange.location; 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 - (DOMRange *)convertNSRangeToDOMRange:(NSRange)nsrange
......
...@@ -690,8 +690,8 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap ...@@ -690,8 +690,8 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
applyCommandToComposite(new ReplaceSelectionCommand(document(), fragment.get(), true, false, !preserveStyle, false)); applyCommandToComposite(new ReplaceSelectionCommand(document(), fragment.get(), true, false, !preserveStyle, false));
if (preserveSelection && startIndex != -1) { if (preserveSelection && startIndex != -1) {
setEndingSelection(Selection(TextIterator::rangeFromLocationAndLength(document(), destinationIndex + startIndex, 0)->startPosition(), setEndingSelection(Selection(TextIterator::rangeFromLocationAndLength(document()->documentElement(), destinationIndex + startIndex, 0)->startPosition(),
TextIterator::rangeFromLocationAndLength(document(), destinationIndex + endIndex, 0)->startPosition(), TextIterator::rangeFromLocationAndLength(document()->documentElement(), destinationIndex + endIndex, 0)->startPosition(),
DOWNSTREAM)); DOWNSTREAM));
} }
} }
......
...@@ -1019,9 +1019,9 @@ int TextIterator::rangeLength(const Range *r) ...@@ -1019,9 +1019,9 @@ int TextIterator::rangeLength(const Range *r)
return length; 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 docTextPosition = 0;
int rangeEnd = rangeLocation + rangeLength; int rangeEnd = rangeLocation + rangeLength;
...@@ -1029,7 +1029,7 @@ PassRefPtr<Range> TextIterator::rangeFromLocationAndLength(Document *doc, int ra ...@@ -1029,7 +1029,7 @@ PassRefPtr<Range> TextIterator::rangeFromLocationAndLength(Document *doc, int ra
RefPtr<Range> textRunRange; 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>. // 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()) { if (rangeLocation == 0 && rangeLength == 0 && it.atEnd()) {
......
...@@ -71,7 +71,7 @@ public: ...@@ -71,7 +71,7 @@ public:
PassRefPtr<Range> range() const; PassRefPtr<Range> range() const;
static int rangeLength(const Range *r); 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: private:
void exitNode(); void exitNode();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment