| Index: Source/core/editing/FrameSelection.cpp
|
| diff --git a/Source/core/editing/FrameSelection.cpp b/Source/core/editing/FrameSelection.cpp
|
| index bd8ed462a8624d76bc6aa5a4b40fc00177d0adab..72a1e80c132dfe99c1bf189e7038ab170b92a95b 100644
|
| --- a/Source/core/editing/FrameSelection.cpp
|
| +++ b/Source/core/editing/FrameSelection.cpp
|
| @@ -176,19 +176,16 @@ void FrameSelection::moveTo(const Position &base, const Position &extent, EAffin
|
|
|
| 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 void adjustEndpointsAtBidiBoundary(VisiblePosition& visibleBase, VisiblePosition& visibleExtent)
|
| @@ -1204,7 +1201,7 @@ void FrameSelection::prepareForDestruction()
|
| view->clearSelection();
|
|
|
| setSelection(VisibleSelection(), CloseTyping | ClearTypingStyle | DoNotUpdateAppearance);
|
| - m_previousCaretNode.clear();
|
| + m_previousCaretPosition.clear();
|
| }
|
|
|
| void FrameSelection::setStart(const VisiblePosition &pos, EUserTriggered trigger)
|
| @@ -1257,20 +1254,21 @@ static inline bool caretRendersInsideNode(Node* node)
|
| return node && !isTableElement(node) && !editingIgnoresContent(node);
|
| }
|
|
|
| -static RenderObject* caretRenderer(Node* node)
|
| +static RenderObject* 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();
|
| }
|
|
|
| +static RenderObject* caretRenderer(const Position& position)
|
| +{
|
| + return caretRenderer(position.renderer());
|
| +}
|
| +
|
| bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caretPosition)
|
| {
|
| document->updateStyleIfNeeded();
|
| @@ -1281,7 +1279,7 @@ bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret
|
| if (caretPosition.isNull())
|
| return false;
|
|
|
| - ASSERT(caretPosition.deepEquivalent().deprecatedNode()->renderer());
|
| + ASSERT(caretPosition.deepEquivalent().renderer());
|
|
|
| // First compute a rect local to the renderer at the selection start.
|
| RenderObject* renderer;
|
| @@ -1289,7 +1287,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;
|
| @@ -1311,12 +1309,12 @@ bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret
|
|
|
| RenderObject* FrameSelection::caretRenderer() const
|
| {
|
| - return WebCore::caretRenderer(m_selection.start().deprecatedNode());
|
| + return WebCore::caretRenderer(m_selection.start());
|
| }
|
|
|
| RenderObject* DragCaretController::caretRenderer() const
|
| {
|
| - return WebCore::caretRenderer(m_position.deepEquivalent().deprecatedNode());
|
| + return WebCore::caretRenderer(m_position.deepEquivalent());
|
| }
|
|
|
| static bool isNonOrphanedCaret(const VisibleSelection& selection)
|
| @@ -1336,9 +1334,9 @@ LayoutRect FrameSelection::localCaretRect()
|
| return localCaretRectWithoutUpdate();
|
| }
|
|
|
| -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();
|
|
|
| @@ -1354,9 +1352,9 @@ IntRect FrameSelection::absoluteCaretBounds()
|
| return m_absCaretBounds;
|
| }
|
|
|
| -static void repaintCaretForLocalRect(Node* node, const LayoutRect& rect)
|
| +static void repaintCaretForLocalRect(const Position& position, const LayoutRect& rect)
|
| {
|
| - RenderObject* caretPainter = caretRenderer(node);
|
| + RenderObject* caretPainter = caretRenderer(position);
|
| if (!caretPainter)
|
| return;
|
|
|
| @@ -1386,19 +1384,18 @@ bool FrameSelection::recomputeCaretRect()
|
| return false;
|
|
|
| IntRect oldAbsCaretBounds = m_absCaretBounds;
|
| - m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start().deprecatedNode(), localCaretRectWithoutUpdate());
|
| + m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start(), localCaretRectWithoutUpdate());
|
| m_absCaretBoundsDirty = false;
|
|
|
| if (oldAbsCaretBounds == m_absCaretBounds)
|
| return false;
|
|
|
| if (RenderView* view = m_frame->document()->renderView()) {
|
| - Node* node = m_selection.start().deprecatedNode();
|
| - if (m_previousCaretNode)
|
| - repaintCaretForLocalRect(m_previousCaretNode.get(), oldRect);
|
| - m_previousCaretNode = node;
|
| + if (m_previousCaretPosition.isNotNull())
|
| + repaintCaretForLocalRect(m_previousCaretPosition, oldRect);
|
| + m_previousCaretPosition = m_selection.start();
|
| if (shouldRepaintCaret(view, isContentEditable()))
|
| - repaintCaretForLocalRect(node, newRect);
|
| + repaintCaretForLocalRect(m_previousCaretPosition, newRect);
|
| }
|
|
|
| return true;
|
| @@ -1417,10 +1414,10 @@ void FrameSelection::invalidateCaretRect()
|
| if (!isCaret())
|
| return;
|
|
|
| - CaretBase::invalidateCaretRect(m_selection.start().deprecatedNode(), recomputeCaretRect());
|
| + CaretBase::invalidateCaretRect(m_selection.start(), recomputeCaretRect());
|
| }
|
|
|
| -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
|
| @@ -1438,25 +1435,25 @@ 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 FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& paintOffset, const LayoutRect& clipRect)
|
| {
|
| if (m_selection.isCaret() && m_caretPaint)
|
| - CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, paintOffset, clipRect);
|
| + CaretBase::paintCaret(m_selection.start(), context, paintOffset, clipRect);
|
| }
|
|
|
| -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));
|
| @@ -1466,12 +1463,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);
|
|
|
| @@ -1556,11 +1548,11 @@ bool FrameSelection::contains(const LayoutPoint& point)
|
| HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent);
|
| HitTestResult result(point);
|
| document->renderView()->hitTest(request, result);
|
| - Node* innerNode = result.innerNode();
|
| - if (!innerNode || !innerNode->renderer())
|
| + RenderObject* renderer = result.renderer();
|
| + if (!renderer)
|
| return false;
|
|
|
| - VisiblePosition visiblePos(innerNode->renderer()->positionForPoint(result.localPoint()));
|
| + VisiblePosition visiblePos(renderer->positionForPoint(result.localPoint()));
|
| if (visiblePos.isNull())
|
| return false;
|
|
|
| @@ -1837,11 +1829,8 @@ void FrameSelection::updateAppearance()
|
|
|
| // We can get into a state where the selection endpoints map to the same VisiblePosition when a selection is deleted
|
| // because we don't yet notify the FrameSelection of text removal.
|
| - if (startPos.isNotNull() && endPos.isNotNull() && selection.visibleStart() != selection.visibleEnd()) {
|
| - RenderObject* startRenderer = startPos.deprecatedNode()->renderer();
|
| - RenderObject* endRenderer = endPos.deprecatedNode()->renderer();
|
| - view->setSelection(startRenderer, startPos.deprecatedEditingOffset(), endRenderer, endPos.deprecatedEditingOffset());
|
| - }
|
| + if (startPos.isNotNull() && endPos.isNotNull() && selection.visibleStart() != selection.visibleEnd())
|
| + view->setSelection(startPos.renderer(), startPos.offsetInRenderer(), endPos.renderer(), endPos.offsetInRenderer());
|
| }
|
|
|
| void FrameSelection::setCaretVisibility(CaretVisibility visibility)
|
| @@ -1945,7 +1934,7 @@ void FrameSelection::setFocusedNodeIfNeeded()
|
| 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);
|
| }
|
|
|
| PassRefPtr<MutableStylePropertySet> FrameSelection::copyTypingStyle() const
|
| @@ -2048,11 +2037,11 @@ void FrameSelection::revealSelection(const ScrollAlignment& alignment, RevealExt
|
|
|
| Position start = this->start();
|
| ASSERT(start.deprecatedNode());
|
| - if (start.deprecatedNode() && start.deprecatedNode()->renderer()) {
|
| + if (start.renderer()) {
|
| // FIXME: This code only handles scrolling the startContainer's layer, but
|
| // the selection rect could intersect more than just that.
|
| // See <rdar://problem/4799899>.
|
| - if (start.deprecatedNode()->renderer()->scrollRectToVisible(rect, alignment, alignment))
|
| + if (start.renderer()->scrollRectToVisible(rect, alignment, alignment))
|
| updateAppearance();
|
| }
|
| }
|
|
|