| Index: Source/core/editing/Caret.cpp
|
| diff --git a/Source/core/editing/Caret.cpp b/Source/core/editing/Caret.cpp
|
| index c8b2f6090c678accee43e40b8201e89abc324077..50543f4cfbcd3a12f584c4e317a124fc061f5e7b 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)
|
| {
|
| - 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->isBlockFlow() && caretRendersInsideNode(node);
|
| + bool paintedByBlock = renderer->isBlockFlow() && caretRendersInsideNode(renderer->node());
|
| return paintedByBlock ? renderer : renderer->containingBlock();
|
| }
|
|
|
| +RenderObject* CaretBase::caretRenderer(const Position& position)
|
| +{
|
| + return caretRenderer(position.renderer());
|
| +}
|
| +
|
| 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;
|
|
|
| @@ -214,7 +212,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
|
| @@ -232,19 +230,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));
|
| @@ -254,12 +252,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);
|
|
|
| @@ -269,7 +262,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);
|
| }
|
|
|
| }
|
|
|