Index: Source/core/editing/Caret.cpp |
diff --git a/Source/core/editing/Caret.cpp b/Source/core/editing/Caret.cpp |
index d1cb06150b209d2d71c388e1b95298d0042c9d26..613e2f8bc568b9c6f0df6adc931c2ff638b57713 100644 |
--- a/Source/core/editing/Caret.cpp |
+++ b/Source/core/editing/Caret.cpp |
@@ -63,19 +63,16 @@ bool DragCaretController::isContentRichlyEditable() const |
void DragCaretController::setCaretPosition(const VisiblePosition& position) |
{ |
- if (Node* node = m_position.deepEquivalent().deprecatedNode()) |
- invalidateCaretRect(node); |
+ if (m_position.isNotNull()) |
+ invalidateCaretRect(m_position.deepEquivalent()); |
m_position = position; |
setCaretRectNeedsUpdate(); |
- Document* document = 0; |
- if (Node* node = m_position.deepEquivalent().deprecatedNode()) { |
- invalidateCaretRect(node); |
- document = &node->document(); |
- } |
+ if (m_position.isNotNull()) |
+ invalidateCaretRect(m_position.deepEquivalent()); |
if (m_position.isNull() || m_position.isOrphan()) |
clearCaretRect(); |
else |
- updateCaretRect(document, m_position); |
+ updateCaretRect(m_position.deepEquivalent().document(), m_position); |
} |
static bool removingNodeRemovesPosition(Node* node, const Position& position) |
@@ -123,20 +120,21 @@ static inline bool caretRendersInsideNode(Node* node) |
return node && !isTableElement(node) && !editingIgnoresContent(node); |
} |
-RenderObject* CaretBase::caretRenderer(Node* node) |
+RenderObject* CaretBase::caretRenderer(RenderObject* renderer) |
ojan
2013/09/23 23:01:45
This function looks to me like it's only used in t
|
{ |
- if (!node) |
- return 0; |
- |
- RenderObject* renderer = node->renderer(); |
if (!renderer) |
return 0; |
// if caretNode is a block and caret is inside it then caret should be painted by that block |
- bool paintedByBlock = renderer->isRenderBlock() && caretRendersInsideNode(node); |
+ bool paintedByBlock = renderer->isRenderBlock() && caretRendersInsideNode(renderer->node()); |
return paintedByBlock ? renderer : renderer->containingBlock(); |
} |
+RenderObject* CaretBase::caretRenderer(const Position& position) |
+{ |
+ return caretRenderer(position.rendererOfAnchorNode()); |
+} |
+ |
bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caretPosition) |
{ |
document->updateStyleIfNeeded(); |
@@ -155,7 +153,7 @@ bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret |
// Get the renderer that will be responsible for painting the caret |
// (which is either the renderer we just found, or one of its containers). |
- RenderObject* caretPainter = caretRenderer(caretPosition.deepEquivalent().deprecatedNode()); |
+ RenderObject* caretPainter = caretRenderer(caretPosition.deepEquivalent()); |
// Compute an offset between the renderer and the caretPainter. |
bool unrooted = false; |
@@ -177,12 +175,12 @@ bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret |
RenderObject* DragCaretController::caretRenderer() const |
{ |
- return CaretBase::caretRenderer(m_position.deepEquivalent().deprecatedNode()); |
+ return CaretBase::caretRenderer(m_position.deepEquivalent()); |
} |
-IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect) const |
+IntRect CaretBase::absoluteBoundsForLocalRect(const Position& position, const LayoutRect& rect) const |
{ |
- RenderObject* caretPainter = caretRenderer(node); |
+ RenderObject* caretPainter = caretRenderer(position); |
if (!caretPainter) |
return IntRect(); |
@@ -192,9 +190,9 @@ IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect |
return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoundingBox(); |
} |
-void CaretBase::repaintCaretForLocalRect(Node* node, const LayoutRect& rect) |
+void CaretBase::repaintCaretForLocalRect(const Position& position, const LayoutRect& rect) |
{ |
- RenderObject* caretPainter = caretRenderer(node); |
+ RenderObject* caretPainter = caretRenderer(position); |
if (!caretPainter) |
return; |
@@ -217,7 +215,7 @@ bool CaretBase::shouldRepaintCaret(const RenderView* view, bool isContentEditabl |
return (caretBrowsing || isContentEditable); |
} |
-void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged) |
+void CaretBase::invalidateCaretRect(const Position& position, bool caretRectChanged) |
{ |
// EDIT FIXME: This is an unfortunate hack. |
// Basically, we can't trust this layout position since we |
@@ -235,19 +233,19 @@ void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged) |
if (caretRectChanged) |
return; |
- if (RenderView* view = node->document().renderView()) { |
- if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable))) |
- repaintCaretForLocalRect(node, localCaretRectWithoutUpdate()); |
+ if (RenderView* view = position.document()->renderView()) { |
+ if (shouldRepaintCaret(view, position.anchorNode()->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable))) |
+ repaintCaretForLocalRect(position, localCaretRectWithoutUpdate()); |
} |
} |
-void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
+void CaretBase::paintCaret(const Position& position, GraphicsContext* context, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
{ |
if (m_caretVisibility == Hidden) |
return; |
LayoutRect drawingRect = localCaretRectWithoutUpdate(); |
- RenderObject* renderer = caretRenderer(node); |
+ RenderObject* renderer = caretRenderer(position); |
if (renderer && renderer->isBox()) |
toRenderBox(renderer)->flipForWritingMode(drawingRect); |
drawingRect.moveBy(roundedIntPoint(paintOffset)); |
@@ -257,12 +255,7 @@ void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi |
Color caretColor = Color::black; |
- Element* element; |
- if (node->isElementNode()) |
- element = toElement(node); |
- else |
- element = node->parentElement(); |
- |
+ Element* element = position.element(); |
if (element && element->renderer()) |
caretColor = element->renderer()->resolveColor(CSSPropertyColor); |
@@ -272,7 +265,7 @@ void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi |
void DragCaretController::paintDragCaret(Frame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
{ |
if (m_position.deepEquivalent().deprecatedNode()->document().frame() == frame) |
- paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset, clipRect); |
+ paintCaret(m_position.deepEquivalent(), p, paintOffset, clipRect); |
} |
} |