summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/core/editing/VisiblePosition.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/editing/VisiblePosition.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/core/editing/VisiblePosition.cpp73
1 files changed, 36 insertions, 37 deletions
diff --git a/chromium/third_party/WebKit/Source/core/editing/VisiblePosition.cpp b/chromium/third_party/WebKit/Source/core/editing/VisiblePosition.cpp
index b158125184c..7c380bf591d 100644
--- a/chromium/third_party/WebKit/Source/core/editing/VisiblePosition.cpp
+++ b/chromium/third_party/WebKit/Source/core/editing/VisiblePosition.cpp
@@ -27,15 +27,14 @@
#include "config.h"
#include "core/editing/VisiblePosition.h"
-#include "HTMLNames.h"
#include "bindings/v8/ExceptionState.h"
+#include "core/HTMLNames.h"
#include "core/dom/Document.h"
#include "core/dom/Range.h"
#include "core/dom/Text.h"
#include "core/editing/VisibleUnits.h"
#include "core/editing/htmlediting.h"
#include "core/html/HTMLElement.h"
-#include "core/html/HTMLHtmlElement.h"
#include "core/rendering/RenderBlock.h"
#include "core/rendering/RootInlineBox.h"
#include "platform/geometry/FloatQuad.h"
@@ -136,7 +135,7 @@ Position VisiblePosition::leftVisuallyDistinctCandidate() const
if (!box)
return primaryDirection == LTR ? previousVisuallyDistinctCandidate(m_deepPosition) : nextVisuallyDistinctCandidate(m_deepPosition);
- RenderObject* renderer = box->renderer();
+ RenderObject* renderer = &box->renderer();
while (true) {
if ((renderer->isReplaced() || renderer->isBR()) && offset == box->caretRightmostOffset())
@@ -146,7 +145,7 @@ Position VisiblePosition::leftVisuallyDistinctCandidate() const
box = box->prevLeafChild();
if (!box)
return primaryDirection == LTR ? previousVisuallyDistinctCandidate(m_deepPosition) : nextVisuallyDistinctCandidate(m_deepPosition);
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = box->caretRightmostOffset();
continue;
}
@@ -177,7 +176,7 @@ Position VisiblePosition::leftVisuallyDistinctCandidate() const
// Reposition at the other logical position corresponding to our edge's visual position and go for another round.
box = prevBox;
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = prevBox->caretRightmostOffset();
continue;
}
@@ -190,9 +189,9 @@ Position VisiblePosition::leftVisuallyDistinctCandidate() const
if (box->direction() == primaryDirection) {
if (!prevBox) {
InlineBox* logicalStart = 0;
- if (primaryDirection == LTR ? box->root()->getLogicalStartBoxWithNode(logicalStart) : box->root()->getLogicalEndBoxWithNode(logicalStart)) {
+ if (primaryDirection == LTR ? box->root().getLogicalStartBoxWithNode(logicalStart) : box->root().getLogicalEndBoxWithNode(logicalStart)) {
box = logicalStart;
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = primaryDirection == LTR ? box->caretMinOffset() : box->caretMaxOffset();
}
break;
@@ -211,19 +210,19 @@ Position VisiblePosition::leftVisuallyDistinctCandidate() const
break;
box = prevBox;
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = box->caretRightmostOffset();
if (box->direction() == primaryDirection)
break;
continue;
}
- while (prevBox && !prevBox->renderer()->node())
+ while (prevBox && !prevBox->renderer().node())
prevBox = prevBox->prevLeafChild();
if (prevBox) {
box = prevBox;
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = box->caretRightmostOffset();
if (box->bidiLevel() > level) {
do {
@@ -253,7 +252,7 @@ Position VisiblePosition::leftVisuallyDistinctCandidate() const
break;
level = box->bidiLevel();
}
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = primaryDirection == LTR ? box->caretMinOffset() : box->caretMaxOffset();
}
break;
@@ -301,7 +300,7 @@ Position VisiblePosition::rightVisuallyDistinctCandidate() const
if (!box)
return primaryDirection == LTR ? nextVisuallyDistinctCandidate(m_deepPosition) : previousVisuallyDistinctCandidate(m_deepPosition);
- RenderObject* renderer = box->renderer();
+ RenderObject* renderer = &box->renderer();
while (true) {
if ((renderer->isReplaced() || renderer->isBR()) && offset == box->caretLeftmostOffset())
@@ -311,7 +310,7 @@ Position VisiblePosition::rightVisuallyDistinctCandidate() const
box = box->nextLeafChild();
if (!box)
return primaryDirection == LTR ? nextVisuallyDistinctCandidate(m_deepPosition) : previousVisuallyDistinctCandidate(m_deepPosition);
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = box->caretLeftmostOffset();
continue;
}
@@ -342,7 +341,7 @@ Position VisiblePosition::rightVisuallyDistinctCandidate() const
// Reposition at the other logical position corresponding to our edge's visual position and go for another round.
box = nextBox;
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = nextBox->caretLeftmostOffset();
continue;
}
@@ -355,9 +354,9 @@ Position VisiblePosition::rightVisuallyDistinctCandidate() const
if (box->direction() == primaryDirection) {
if (!nextBox) {
InlineBox* logicalEnd = 0;
- if (primaryDirection == LTR ? box->root()->getLogicalEndBoxWithNode(logicalEnd) : box->root()->getLogicalStartBoxWithNode(logicalEnd)) {
+ if (primaryDirection == LTR ? box->root().getLogicalEndBoxWithNode(logicalEnd) : box->root().getLogicalStartBoxWithNode(logicalEnd)) {
box = logicalEnd;
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = primaryDirection == LTR ? box->caretMaxOffset() : box->caretMinOffset();
}
break;
@@ -378,19 +377,19 @@ Position VisiblePosition::rightVisuallyDistinctCandidate() const
// For example, abc 123 ^ CBA or 123 ^ CBA abc
box = nextBox;
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = box->caretLeftmostOffset();
if (box->direction() == primaryDirection)
break;
continue;
}
- while (nextBox && !nextBox->renderer()->node())
+ while (nextBox && !nextBox->renderer().node())
nextBox = nextBox->nextLeafChild();
if (nextBox) {
box = nextBox;
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = box->caretLeftmostOffset();
if (box->bidiLevel() > level) {
@@ -421,7 +420,7 @@ Position VisiblePosition::rightVisuallyDistinctCandidate() const
break;
level = box->bidiLevel();
}
- renderer = box->renderer();
+ renderer = &box->renderer();
offset = primaryDirection == LTR ? box->caretMaxOffset() : box->caretMinOffset();
}
break;
@@ -476,7 +475,7 @@ VisiblePosition VisiblePosition::honorEditingBoundaryAtOrBefore(const VisiblePos
return VisiblePosition();
// Return the last position before pos that is in the same editable region as this position
- return lastEditablePositionBeforePositionInRoot(pos.deepEquivalent(), highestRoot);
+ return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(), highestRoot);
}
VisiblePosition VisiblePosition::honorEditingBoundaryAtOrAfter(const VisiblePosition &pos) const
@@ -502,7 +501,7 @@ VisiblePosition VisiblePosition::honorEditingBoundaryAtOrAfter(const VisiblePosi
return VisiblePosition();
// Return the next position after pos that is in the same editable region as this position
- return firstEditablePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot);
+ return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot);
}
VisiblePosition VisiblePosition::skipToStartOfEditingBoundary(const VisiblePosition &pos) const
@@ -519,10 +518,10 @@ VisiblePosition VisiblePosition::skipToStartOfEditingBoundary(const VisiblePosit
// If |pos| has an editable root, skip to the start
if (highestRootOfPos)
- return previousVisuallyDistinctCandidate(Position(highestRootOfPos, Position::PositionIsBeforeAnchor).parentAnchoredEquivalent());
+ return VisiblePosition(previousVisuallyDistinctCandidate(Position(highestRootOfPos, Position::PositionIsBeforeAnchor).parentAnchoredEquivalent()));
// That must mean that |pos| is not editable. Return the last position before pos that is in the same editable region as this position
- return lastEditablePositionBeforePositionInRoot(pos.deepEquivalent(), highestRoot);
+ return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(), highestRoot);
}
VisiblePosition VisiblePosition::skipToEndOfEditingBoundary(const VisiblePosition &pos) const
@@ -539,10 +538,10 @@ VisiblePosition VisiblePosition::skipToEndOfEditingBoundary(const VisiblePositio
// If |pos| has an editable root, skip to the end
if (highestRootOfPos)
- return Position(highestRootOfPos, Position::PositionIsAfterAnchor).parentAnchoredEquivalent();
+ return VisiblePosition(Position(highestRootOfPos, Position::PositionIsAfterAnchor).parentAnchoredEquivalent());
// That must mean that |pos| is not editable. Return the next position after pos that is in the same editable region as this position
- return firstEditablePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot);
+ return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot);
}
static Position canonicalizeCandidate(const Position& candidate)
@@ -592,14 +591,14 @@ Position VisiblePosition::canonicalPosition(const Position& passedPosition)
// The new position must be in the same editable element. Enforce that first.
// Unless the descent is from a non-editable html element to an editable body.
- if (node && isHTMLHtmlElement(node) && !node->rendererIsEditable() && node->document().body() && node->document().body()->rendererIsEditable())
+ if (isHTMLHtmlElement(node) && !node->rendererIsEditable() && node->document().body() && node->document().body()->rendererIsEditable())
return next.isNotNull() ? next : prev;
Node* editingRoot = editableRootForPosition(position);
// If the html element is editable, descending into its body will look like a descent
// from non-editable to editable content since rootEditableElement() always stops at the body.
- if ((editingRoot && isHTMLHtmlElement(editingRoot)) || position.deprecatedNode()->isDocumentNode())
+ if (isHTMLHtmlElement(editingRoot) || position.deprecatedNode()->isDocumentNode())
return next.isNotNull() ? next : prev;
bool prevIsInSameEditableElement = prevNode && editableRootForPosition(prev) == editingRoot;
@@ -665,7 +664,7 @@ LayoutRect VisiblePosition::localCaretRect(RenderObject*& renderer) const
getInlineBoxAndOffset(inlineBox, caretOffset);
if (inlineBox)
- renderer = inlineBox->renderer();
+ renderer = &inlineBox->renderer();
return renderer->localCaretRect(inlineBox, caretOffset);
}
@@ -721,15 +720,15 @@ void VisiblePosition::showTreeForThis() const
#endif
-PassRefPtr<Range> makeRange(const VisiblePosition &start, const VisiblePosition &end)
+PassRefPtrWillBeRawPtr<Range> makeRange(const VisiblePosition &start, const VisiblePosition &end)
{
if (start.isNull() || end.isNull())
- return 0;
+ return nullptr;
Position s = start.deepEquivalent().parentAnchoredEquivalent();
Position e = end.deepEquivalent().parentAnchoredEquivalent();
if (s.isNull() || e.isNull())
- return 0;
+ return nullptr;
return Range::create(s.containerNode()->document(), s.containerNode(), s.offsetInContainerNode(), e.containerNode(), e.offsetInContainerNode());
}
@@ -739,11 +738,6 @@ VisiblePosition startVisiblePosition(const Range *r, EAffinity affinity)
return VisiblePosition(r->startPosition(), affinity);
}
-VisiblePosition endVisiblePosition(const Range *r, EAffinity affinity)
-{
- return VisiblePosition(r->endPosition(), affinity);
-}
-
bool setStart(Range *r, const VisiblePosition &visiblePosition)
{
if (!r)
@@ -796,6 +790,11 @@ bool isLastVisiblePositionInNode(const VisiblePosition &visiblePosition, const N
return next.isNull() || !next.deepEquivalent().deprecatedNode()->isDescendantOf(node);
}
+void VisiblePosition::trace(Visitor* visitor)
+{
+ visitor->trace(m_deepPosition);
+}
+
} // namespace WebCore
#ifndef NDEBUG