2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "visible_units.h"
31 #include "RenderBlock.h"
32 #include "TextBoundaries.h"
33 #include "htmlediting.h"
34 #include "HTMLNames.h"
35 #include "TextIterator.h"
39 using namespace HTMLNames;
41 static VisiblePosition previousBoundary(const VisiblePosition &c, unsigned (*searchFunction)(const UChar *, unsigned))
43 Position pos = c.deepEquivalent();
46 return VisiblePosition();
47 Document *d = n->document();
48 Node *de = d->documentElement();
50 return VisiblePosition();
51 Node *boundary = n->enclosingBlockFlowElement();
53 return VisiblePosition();
54 bool isContentEditable = boundary->isContentEditable();
55 while (boundary && boundary != de && boundary->parentNode() && isContentEditable == boundary->parentNode()->isContentEditable())
56 boundary = boundary->parentNode();
58 Position start = rangeCompliantEquivalent(Position(boundary, 0));
59 Position end = rangeCompliantEquivalent(pos);
60 RefPtr<Range> searchRange = new Range(d);
63 searchRange->setStart(start.node(), start.offset(), exception);
64 searchRange->setEnd(end.node(), end.offset(), exception);
68 return VisiblePosition();
70 SimplifiedBackwardsTextIterator it(searchRange.get());
71 DeprecatedString string;
73 bool inTextSecurityMode = start.node() && start.node()->renderer() && start.node()->renderer()->style()->textSecurity() != TSNONE;
74 while (!it.atEnd() && it.length() > 0) {
75 // iterate to get chunks until the searchFunction returns a non-zero value.
76 String iteratorString(it.characters(), it.length());
77 // Treat bullets used in the text security mode as regular characters when looking for boundaries
78 if (inTextSecurityMode)
79 iteratorString = iteratorString.impl()->secure('x');
80 string.prepend(iteratorString.deprecatedString());
81 next = searchFunction(reinterpret_cast<const UChar*>(string.unicode()), string.length());
87 if (it.atEnd() && next == 0) {
88 RefPtr<Range> range(it.range());
89 pos = Position(range->startContainer(exception), range->startOffset(exception));
90 } else if (!it.atEnd() && it.length() == 0) {
91 // Got a zero-length chunk.
92 // This means we have hit a replaced element.
93 // Make a check to see if the position should be before or after the replaced element
94 // by performing an additional check with a modified string which uses an "X"
95 // character to stand in for the replaced element.
96 DeprecatedChar chars[2];
99 string.prepend(chars, 2);
100 unsigned pastImage = searchFunction(reinterpret_cast<const UChar*>(string.unicode()), string.length());
101 RefPtr<Range> range(it.range());
103 pos = Position(range->startContainer(exception), range->startOffset(exception));
105 pos = Position(range->endContainer(exception), range->endOffset(exception));
106 } else if (next != 0) {
107 // The simpler iterator used in this function, as compared to the one used in
108 // nextWordPosition(), gives us results we can use directly without having to
109 // iterate again to translate the next value into a DOM position.
110 Node *node = it.range()->startContainer(exception);
111 if (node->isTextNode() || (node->renderer() && node->renderer()->isBR()))
112 // The next variable contains a usable index into a text node
113 pos = Position(node, next);
115 // If we are not in a text node, we ended on a node boundary, so the
116 // range start offset should be used.
117 pos = Position(node, it.range()->startOffset(exception));
120 return VisiblePosition(pos, DOWNSTREAM);
123 static VisiblePosition nextBoundary(const VisiblePosition &c, unsigned (*searchFunction)(const UChar *, unsigned))
125 Position pos = c.deepEquivalent();
126 Node *n = pos.node();
128 return VisiblePosition();
129 Document *d = n->document();
130 Node *de = d->documentElement();
132 return VisiblePosition();
133 Node *boundary = n->enclosingBlockFlowElement();
135 return VisiblePosition();
136 bool isContentEditable = boundary->isContentEditable();
137 while (boundary && boundary != de && boundary->parentNode() && isContentEditable == boundary->parentNode()->isContentEditable())
138 boundary = boundary->parentNode();
140 RefPtr<Range> searchRange(d->createRange());
141 Position start(rangeCompliantEquivalent(pos));
142 ExceptionCode ec = 0;
143 searchRange->selectNodeContents(boundary, ec);
144 searchRange->setStart(start.node(), start.offset(), ec);
145 TextIterator it(searchRange.get(), RUNFINDER);
146 DeprecatedString string;
148 bool inTextSecurityMode = start.node() && start.node()->renderer() && start.node()->renderer()->style()->textSecurity() != TSNONE;
149 while (!it.atEnd() && it.length() > 0) {
150 // Keep asking the iterator for chunks until the search function
151 // returns an end value not equal to the length of the string passed to it.
152 String iteratorString(it.characters(), it.length());
153 // Treat bullets used in the text security mode as regular characters when looking for boundaries
154 if (inTextSecurityMode)
155 iteratorString = iteratorString.impl()->secure('x');
156 string.append(iteratorString.deprecatedString());
157 next = searchFunction(reinterpret_cast<const UChar*>(string.unicode()), string.length());
158 if (next != string.length())
163 if (it.atEnd() && next == string.length()) {
164 RefPtr<Range> range(it.range());
166 pos = Position(range->startContainer(exception), range->startOffset(exception));
167 } else if (!it.atEnd() && it.length() == 0) {
168 // Got a zero-length chunk.
169 // This means we have hit a replaced element.
170 // Make a check to see if the position should be before or after the replaced element
171 // by performing an additional check with a modified string which uses an "X"
172 // character to stand in for the replaced element.
173 DeprecatedChar chars[2];
176 string.append(chars, 2);
177 unsigned pastImage = searchFunction(reinterpret_cast<const UChar*>(string.unicode()), string.length());
178 RefPtr<Range> range(it.range());
180 if (next != pastImage)
181 pos = Position(range->endContainer(exception), range->endOffset(exception));
183 pos = Position(range->startContainer(exception), range->startOffset(exception));
184 } else if (next != 0) {
185 // Use the character iterator to translate the next value into a DOM position.
186 CharacterIterator charIt(searchRange.get());
187 charIt.advance(next - 1);
188 pos = Position(charIt.range()->endContainer(ec), charIt.range()->endOffset(ec));
191 // generate VisiblePosition, use UPSTREAM affinity if possible
192 return VisiblePosition(pos, VP_UPSTREAM_IF_POSSIBLE);
197 static unsigned startWordBoundary(const UChar* characters, unsigned length)
200 findWordBoundary(characters, length, length, &start, &end);
204 VisiblePosition startOfWord(const VisiblePosition &c, EWordSide side)
206 // FIXME: This returns a null VP for c at the start of the document
207 // and side == LeftWordIfOnBoundary
208 VisiblePosition p = c;
209 if (side == RightWordIfOnBoundary) {
210 // at paragraph end, the startofWord is the current position
211 if (isEndOfParagraph(c))
218 return previousBoundary(p, startWordBoundary);
221 static unsigned endWordBoundary(const UChar* characters, unsigned length)
224 findWordBoundary(characters, length, 0, &start, &end);
228 VisiblePosition endOfWord(const VisiblePosition &c, EWordSide side)
230 VisiblePosition p = c;
231 if (side == LeftWordIfOnBoundary) {
232 if (isStartOfParagraph(c))
239 // at paragraph end, the endOfWord is the start of next paragraph
240 if (isEndOfParagraph(c)) {
242 return p.isNotNull() ? p : c;
246 return nextBoundary(p, endWordBoundary);
249 static unsigned previousWordPositionBoundary(const UChar* characters, unsigned length)
251 return findNextWordFromIndex(characters, length, length, false);
254 VisiblePosition previousWordPosition(const VisiblePosition &c)
256 return previousBoundary(c, previousWordPositionBoundary);
259 static unsigned nextWordPositionBoundary(const UChar* characters, unsigned length)
261 return findNextWordFromIndex(characters, length, 0, true);
264 VisiblePosition nextWordPosition(const VisiblePosition &c)
266 return nextBoundary(c, nextWordPositionBoundary);
271 static RootInlineBox *rootBoxForLine(const VisiblePosition &c)
273 Position p = c.deepEquivalent();
274 Node *node = p.node();
278 RenderObject *renderer = node->renderer();
282 InlineBox *box = renderer->inlineBox(p.offset(), c.affinity());
289 VisiblePosition startOfLine(const VisiblePosition &c)
291 RootInlineBox *rootBox = rootBoxForLine(c);
293 return VisiblePosition();
295 // Generated content (e.g. list markers and CSS :before and :after
296 // pseudoelements) have no corresponding DOM element, and so cannot be
297 // represented by a VisiblePosition. Use whatever follows instead.
298 InlineBox *startBox = rootBox->firstLeafChild();
302 return VisiblePosition();
304 RenderObject *startRenderer = startBox->object();
306 return VisiblePosition();
308 startNode = startRenderer->element();
312 startBox = startBox->nextLeafChild();
316 if (startBox->isInlineTextBox()) {
317 InlineTextBox *startTextBox = static_cast<InlineTextBox *>(startBox);
318 startOffset = startTextBox->m_start;
321 return VisiblePosition(startNode, startOffset, DOWNSTREAM);
324 VisiblePosition endOfLine(const VisiblePosition &c)
326 RootInlineBox *rootBox = rootBoxForLine(c);
328 return VisiblePosition();
330 // Generated content (e.g. list markers and CSS :before and :after
331 // pseudoelements) have no corresponding DOM element, and so cannot be
332 // represented by a VisiblePosition. Use whatever precedes instead.
334 InlineBox *endBox = rootBox->lastLeafChild();
337 return VisiblePosition();
339 RenderObject *endRenderer = endBox->object();
341 return VisiblePosition();
343 endNode = endRenderer->element();
347 endBox = endBox->prevLeafChild();
351 if (endNode->hasTagName(brTag)) {
353 } else if (endBox->isInlineTextBox()) {
354 InlineTextBox *endTextBox = static_cast<InlineTextBox *>(endBox);
355 endOffset = endTextBox->m_start + endTextBox->m_len;
358 return VisiblePosition(endNode, endOffset, VP_UPSTREAM_IF_POSSIBLE);
361 bool inSameLine(const VisiblePosition &a, const VisiblePosition &b)
363 return a.isNotNull() && startOfLine(a) == startOfLine(b);
366 bool isStartOfLine(const VisiblePosition &p)
368 return p.isNotNull() && p == startOfLine(p);
371 bool isEndOfLine(const VisiblePosition &p)
373 return p.isNotNull() && p == endOfLine(p);
376 VisiblePosition previousLinePosition(const VisiblePosition &visiblePosition, int x)
378 Position p = visiblePosition.deepEquivalent();
379 Node *node = p.node();
381 return VisiblePosition();
383 node->document()->updateLayoutIgnorePendingStylesheets();
385 RenderObject *renderer = node->renderer();
387 return VisiblePosition();
389 RenderBlock *containingBlock = 0;
390 RootInlineBox *root = 0;
391 InlineBox *box = renderer->inlineBox(p.offset(), visiblePosition.affinity());
393 root = box->root()->prevRootBox();
395 containingBlock = renderer->containingBlock();
399 // This containing editable block does not have a previous line.
400 // Need to move back to previous containing editable block in this root editable
401 // block and find the last root line box in that block.
402 Node *startBlock = node->enclosingBlockFlowElement();
403 Node *n = node->previousEditable();
404 while (n && startBlock == n->enclosingBlockFlowElement())
405 n = n->previousEditable();
407 if (!n->inSameRootEditableElement(node))
409 Position pos(n, n->caretMinOffset());
410 if (pos.inRenderedContent()) {
411 assert(n->renderer());
412 box = n->renderer()->inlineBox(n->caretMaxOffset());
414 // previous root line box found
416 containingBlock = n->renderer()->containingBlock();
420 return VisiblePosition(pos, DOWNSTREAM);
422 n = n->previousEditable();
428 containingBlock->absolutePositionForContent(absx, absy);
429 if (containingBlock->hasOverflowClip())
430 containingBlock->layer()->subtractScrollOffset(absx, absy);
431 RenderObject *renderer = root->closestLeafChildForXPos(x, absx)->object();
432 Node* node = renderer->element();
433 if (editingIgnoresContent(node))
434 return Position(node->parent(), node->nodeIndex());
435 return renderer->positionForCoordinates(x, absy + root->topOverflow());
438 // Could not find a previous line. This means we must already be on the first line.
439 // Move to the start of the content in this block, which effectively moves us
440 // to the start of the line we're on.
441 return VisiblePosition(node->rootEditableElement(), 0, DOWNSTREAM);
444 VisiblePosition nextLinePosition(const VisiblePosition &visiblePosition, int x)
446 Position p = visiblePosition.deepEquivalent();
447 Node *node = p.node();
449 return VisiblePosition();
451 node->document()->updateLayoutIgnorePendingStylesheets();
453 RenderObject *renderer = node->renderer();
455 return VisiblePosition();
457 RenderBlock *containingBlock = 0;
458 RootInlineBox *root = 0;
459 InlineBox *box = renderer->inlineBox(p.offset(), visiblePosition.affinity());
461 root = box->root()->nextRootBox();
463 containingBlock = renderer->containingBlock();
467 // This containing editable block does not have a next line.
468 // Need to move forward to next containing editable block in this root editable
469 // block and find the first root line box in that block.
470 Node *startBlock = node->enclosingBlockFlowElement();
471 Node *n = node->nextEditable(p.offset());
472 while (n && startBlock == n->enclosingBlockFlowElement())
473 n = n->nextEditable();
475 if (!n->inSameRootEditableElement(node))
477 Position pos(n, n->caretMinOffset());
478 if (pos.inRenderedContent()) {
479 assert(n->renderer());
480 box = n->renderer()->inlineBox(n->caretMinOffset());
482 // next root line box found
484 containingBlock = n->renderer()->containingBlock();
488 return VisiblePosition(pos, DOWNSTREAM);
490 n = n->nextEditable();
496 containingBlock->absolutePositionForContent(absx, absy);
497 if (containingBlock->hasOverflowClip())
498 containingBlock->layer()->subtractScrollOffset(absx, absy);
499 RenderObject *renderer = root->closestLeafChildForXPos(x, absx)->object();
500 Node* node = renderer->element();
501 if (editingIgnoresContent(node))
502 return Position(node->parent(), node->nodeIndex());
503 return renderer->positionForCoordinates(x, absy + root->topOverflow());
506 // Could not find a next line. This means we must already be on the last line.
507 // Move to the end of the content in this block, which effectively moves us
508 // to the end of the line we're on.
509 Element *rootElement = node->rootEditableElement();
510 return VisiblePosition(rootElement, rootElement ? rootElement->childNodeCount() : 0, DOWNSTREAM);
515 static unsigned startSentenceBoundary(const UChar* characters, unsigned length)
518 findSentenceBoundary(characters, length, length, &start, &end);
522 VisiblePosition startOfSentence(const VisiblePosition &c)
524 return previousBoundary(c, startSentenceBoundary);
527 static unsigned endSentenceBoundary(const UChar* characters, unsigned length)
530 findSentenceBoundary(characters, length, 0, &start, &end);
534 VisiblePosition endOfSentence(const VisiblePosition &c)
536 return nextBoundary(c, endSentenceBoundary);
539 static unsigned previousSentencePositionBoundary(const UChar* characters, unsigned length)
541 return findNextSentenceFromIndex(characters, length, length, false);
544 VisiblePosition previousSentencePosition(const VisiblePosition &c)
546 return previousBoundary(c, previousSentencePositionBoundary);
549 static unsigned nextSentencePositionBoundary(const UChar* characters, unsigned length)
551 return findNextSentenceFromIndex(characters, length, 0, true);
554 VisiblePosition nextSentencePosition(const VisiblePosition &c)
556 return nextBoundary(c, nextSentencePositionBoundary);
559 VisiblePosition startOfParagraph(const VisiblePosition &c)
561 Position p = c.deepEquivalent();
562 Node *startNode = p.node();
565 return VisiblePosition();
567 if (startNode->renderer()
568 && ((startNode->renderer()->isTable() && !startNode->renderer()->isInline())
569 || startNode->renderer()->isHR())
570 && p.offset() == maxDeepOffset(startNode))
571 return VisiblePosition(Position(startNode, 0));
573 Node *startBlock = startNode->enclosingBlockFlowElement();
575 Node *node = startNode;
576 int offset = p.offset();
580 if (n->isContentEditable() != startNode->isContentEditable())
582 RenderObject *r = n->renderer();
584 n = n->traversePreviousNodePostOrder(startBlock);
587 RenderStyle *style = r->style();
588 if (style->visibility() != VISIBLE) {
589 n = n->traversePreviousNodePostOrder(startBlock);
592 // FIXME: isBlockFlow should not exclude non-inline tables
593 if (r->isBR() || r->isBlockFlow() || (r->isTable() && !r->isInline()))
597 if (style->preserveNewline()) {
598 const UChar* text = static_cast<RenderText*>(r)->text();
599 int i = static_cast<RenderText*>(r)->length();
601 if (n == startNode && o < i)
605 return VisiblePosition(n, i + 1, DOWNSTREAM);
609 n = n->traversePreviousNodePostOrder(startBlock);
610 } else if (editingIgnoresContent(n) || isTableElement(n)) {
613 n = n->previousSibling() ? n->previousSibling() : n->traversePreviousNodePostOrder(startBlock);
615 n = n->traversePreviousNodePostOrder(startBlock);
618 return VisiblePosition(node, offset, DOWNSTREAM);
621 VisiblePosition endOfParagraph(const VisiblePosition &c)
624 return VisiblePosition();
626 Position p = c.deepEquivalent();
627 Node* startNode = p.node();
629 if (startNode->renderer()
630 && ((startNode->renderer()->isTable() && !startNode->renderer()->isInline())
631 || startNode->renderer()->isHR())
633 return VisiblePosition(Position(startNode, maxDeepOffset(startNode)));
635 Node *startBlock = startNode->enclosingBlockFlowElement();
636 Node *stayInsideBlock = startBlock;
638 Node *node = startNode;
639 int offset = p.offset();
643 if (n->isContentEditable() != startNode->isContentEditable())
645 RenderObject *r = n->renderer();
647 n = n->traverseNextNode(stayInsideBlock);
650 RenderStyle *style = r->style();
651 if (style->visibility() != VISIBLE) {
652 n = n->traverseNextNode(stayInsideBlock);
656 // FIXME: isBlockFlow should not exclude non-inline tables
657 if (r->isBR() || r->isBlockFlow() || (r->isTable() && !r->isInline()))
660 // FIXME: We avoid returning a position where the renderer can't accept the caret.
661 // We should probably do this in other cases such as startOfParagraph.
662 if (r->isText() && r->caretMaxRenderedOffset() > 0) {
663 int length = static_cast<RenderText *>(r)->length();
664 if (style->preserveNewline()) {
665 const UChar* text = static_cast<RenderText *>(r)->text();
666 int o = n == startNode ? offset : 0;
667 for (int i = o; i < length; ++i)
669 return VisiblePosition(n, i, DOWNSTREAM);
672 offset = r->caretMaxOffset();
673 n = n->traverseNextNode(stayInsideBlock);
674 } else if (editingIgnoresContent(n) || isTableElement(n)) {
676 offset = maxDeepOffset(n);
677 n = n->traverseNextSibling(stayInsideBlock);
679 n = n->traverseNextNode(stayInsideBlock);
682 return VisiblePosition(node, offset, DOWNSTREAM);
685 bool inSameParagraph(const VisiblePosition &a, const VisiblePosition &b)
687 return a.isNotNull() && startOfParagraph(a) == startOfParagraph(b);
690 bool isStartOfParagraph(const VisiblePosition &pos)
692 return pos.isNotNull() && pos == startOfParagraph(pos);
695 bool isEndOfParagraph(const VisiblePosition &pos)
697 return pos.isNotNull() && pos == endOfParagraph(pos);
700 VisiblePosition previousParagraphPosition(const VisiblePosition &p, int x)
702 VisiblePosition pos = p;
704 VisiblePosition n = previousLinePosition(pos, x);
705 if (n.isNull() || n == pos)
708 } while (inSameParagraph(p, pos));
712 VisiblePosition nextParagraphPosition(const VisiblePosition &p, int x)
714 VisiblePosition pos = p;
716 VisiblePosition n = nextLinePosition(pos, x);
717 if (n.isNull() || n == pos)
720 } while (inSameParagraph(p, pos));
726 VisiblePosition startOfBlock(const VisiblePosition &c)
728 Position p = c.deepEquivalent();
729 Node *startNode = p.node();
731 return VisiblePosition();
732 return VisiblePosition(Position(startNode->enclosingBlockFlowElement(), 0), DOWNSTREAM);
735 VisiblePosition endOfBlock(const VisiblePosition &c)
737 Position p = c.deepEquivalent();
739 Node *startNode = p.node();
741 return VisiblePosition();
743 Node *startBlock = startNode->enclosingBlockFlowElement();
745 return VisiblePosition(startBlock, startBlock->childNodeCount(), VP_DEFAULT_AFFINITY);
748 bool inSameBlock(const VisiblePosition &a, const VisiblePosition &b)
750 return !a.isNull() && enclosingBlockFlowElement(a) == enclosingBlockFlowElement(b);
753 bool isStartOfBlock(const VisiblePosition &pos)
755 return pos.isNotNull() && pos == startOfBlock(pos);
758 bool isEndOfBlock(const VisiblePosition &pos)
760 return pos.isNotNull() && pos == endOfBlock(pos);
765 VisiblePosition startOfDocument(const Node* node)
768 return VisiblePosition();
770 return VisiblePosition(node->document()->documentElement(), 0, DOWNSTREAM);
773 VisiblePosition startOfDocument(const VisiblePosition &c)
775 return startOfDocument(c.deepEquivalent().node());
778 VisiblePosition endOfDocument(const Node* node)
780 if (!node || !node->document())
781 return VisiblePosition();
783 Element* doc = node->document()->documentElement();
784 return VisiblePosition(doc, doc->childNodeCount(), DOWNSTREAM);
787 VisiblePosition endOfDocument(const VisiblePosition &c)
789 return endOfDocument(c.deepEquivalent().node());
792 bool inSameDocument(const VisiblePosition &a, const VisiblePosition &b)
794 Position ap = a.deepEquivalent();
795 Node *an = ap.node();
798 Position bp = b.deepEquivalent();
799 Node *bn = bp.node();
803 return an->document() == bn->document();
806 bool isStartOfDocument(const VisiblePosition &p)
808 return p.isNotNull() && p.previous().isNull();
811 bool isEndOfDocument(const VisiblePosition &p)
813 return p.isNotNull() && p.next().isNull();
818 VisiblePosition startOfEditableContent(const VisiblePosition &c)
820 Position p = c.deepEquivalent();
821 Node *node = p.node();
823 return VisiblePosition();
825 return VisiblePosition(node->rootEditableElement(), 0, DOWNSTREAM);
828 VisiblePosition endOfEditableContent(const VisiblePosition &c)
830 Position p = c.deepEquivalent();
831 Node *node = p.node();
833 return VisiblePosition();
835 node = node->rootEditableElement();
837 return VisiblePosition();
839 return VisiblePosition(node, node->childNodeCount(), DOWNSTREAM);
842 bool inSameEditableContent(const VisiblePosition &a, const VisiblePosition &b)
844 Position ap = a.deepEquivalent();
845 Node *an = ap.node();
849 Position bp = b.deepEquivalent();
850 Node *bn = bp.node();
854 if (!an->isContentEditable() || !bn->isContentEditable())
857 return an->rootEditableElement() == bn->rootEditableElement();
860 bool isStartOfEditableContent(const VisiblePosition &p)
862 return !inSameEditableContent(p, p.previous());
865 bool isEndOfEditableContent(const VisiblePosition &p)
867 return !inSameEditableContent(p, p.next());