* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
#include "core/editing/Caret.h"
#include "core/dom/Document.h"
+#include "core/editing/VisibleUnits.h"
#include "core/editing/htmlediting.h"
-#include "core/frame/Frame.h"
-#include "core/page/Settings.h"
+#include "core/frame/LocalFrame.h"
+#include "core/frame/Settings.h"
+#include "core/html/HTMLTextFormControlElement.h"
#include "core/rendering/RenderBlock.h"
+#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderView.h"
+#include "platform/graphics/GraphicsContext.h"
-namespace WebCore {
-
-static inline LayoutUnit NoXPosForVerticalArrowNavigation()
-{
- return LayoutUnit::min();
-}
+namespace blink {
CaretBase::CaretBase(CaretVisibility visibility)
: m_caretRectNeedsUpdate(true)
{
}
-PassOwnPtr<DragCaretController> DragCaretController::create()
+PassOwnPtrWillBeRawPtr<DragCaretController> DragCaretController::create()
{
- return adoptPtr(new DragCaretController);
+ return adoptPtrWillBeNoop(new DragCaretController);
}
bool DragCaretController::isContentRichlyEditable() const
void DragCaretController::setCaretPosition(const VisiblePosition& position)
{
+ // for querying RenderLayer::compositingState()
+ // This code is probably correct, since it doesn't occur in a stack that involves updating compositing state.
+ DisableCompositingQueryAsserts disabler;
+
if (Node* node = m_position.deepEquivalent().deprecatedNode())
invalidateCaretRect(node);
m_position = position;
invalidateCaretRect(node);
document = &node->document();
}
- if (m_position.isNull() || m_position.isOrphan())
+ if (m_position.isNull() || m_position.isOrphan()) {
clearCaretRect();
- else
+ } else {
+ document->updateRenderTreeIfNeeded();
updateCaretRect(document, m_position);
+ }
}
static bool removingNodeRemovesPosition(Node& node, const Position& position)
return element.containsIncludingShadowDOM(position.anchorNode());
}
-static void clearRenderViewSelection(const Position& position)
-{
- RefPtr<Document> document = position.document();
- document->updateStyleIfNeeded();
- if (RenderView* view = document->renderView())
- view->clearSelection();
-}
-
void DragCaretController::nodeWillBeRemoved(Node& node)
{
- if (!hasCaret() || !node.inDocument())
+ if (!hasCaret() || !node.inActiveDocument())
return;
if (!removingNodeRemovesPosition(node, m_position.deepEquivalent()))
return;
- clearRenderViewSelection(m_position.deepEquivalent());
+ m_position.deepEquivalent().document()->renderView()->clearSelection();
clear();
}
+void DragCaretController::trace(Visitor* visitor)
+{
+ visitor->trace(m_position);
+}
+
void CaretBase::clearCaretRect()
{
m_caretLocalRect = LayoutRect();
static inline bool caretRendersInsideNode(Node* node)
{
- return node && !isTableElement(node) && !editingIgnoresContent(node);
+ return node && !isRenderedTableElement(node) && !editingIgnoresContent(node);
}
-RenderObject* CaretBase::caretRenderer(Node* node)
+RenderBlock* CaretBase::caretRenderer(Node* node)
{
if (!node)
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);
- return paintedByBlock ? renderer : renderer->containingBlock();
+ return paintedByBlock ? toRenderBlock(renderer) : renderer->containingBlock();
}
-bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caretPosition)
+bool CaretBase::updateCaretRect(Document* document, const PositionWithAffinity& caretPosition)
{
- document->updateStyleIfNeeded();
m_caretLocalRect = LayoutRect();
m_caretRectNeedsUpdate = false;
- if (caretPosition.isNull())
+ if (caretPosition.position().isNull())
return false;
- ASSERT(caretPosition.deepEquivalent().deprecatedNode()->renderer());
+ ASSERT(caretPosition.position().deprecatedNode()->renderer());
// First compute a rect local to the renderer at the selection start.
RenderObject* renderer;
- LayoutRect localRect = caretPosition.localCaretRect(renderer);
+ LayoutRect localRect = localCaretRectOfPosition(caretPosition, renderer);
// 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());
+ RenderBlock* caretPainter = caretRenderer(caretPosition.position().deprecatedNode());
// Compute an offset between the renderer and the caretPainter.
bool unrooted = false;
return true;
}
-RenderObject* DragCaretController::caretRenderer() const
+bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caretPosition)
+{
+ return updateCaretRect(document, PositionWithAffinity(caretPosition.deepEquivalent(), caretPosition.affinity()));
+}
+
+RenderBlock* DragCaretController::caretRenderer() const
{
return CaretBase::caretRenderer(m_position.deepEquivalent().deprecatedNode());
}
IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect) const
{
- RenderObject* caretPainter = caretRenderer(node);
+ RenderBlock* caretPainter = caretRenderer(node);
if (!caretPainter)
return IntRect();
LayoutRect localRect(rect);
- if (caretPainter->isBox())
- toRenderBox(caretPainter)->flipForWritingMode(localRect);
+ caretPainter->flipForWritingMode(localRect);
return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoundingBox();
}
-void CaretBase::repaintCaretForLocalRect(Node* node, const LayoutRect& rect)
+void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect)
{
- RenderObject* caretPainter = caretRenderer(node);
+ RenderBlock* caretPainter = caretRenderer(node);
if (!caretPainter)
return;
LayoutRect inflatedRect = rect;
inflatedRect.inflate(1);
- caretPainter->repaintRectangle(inflatedRect);
+ caretPainter->invalidatePaintRectangle(inflatedRect);
}
bool CaretBase::shouldRepaintCaret(const RenderView* view, bool isContentEditable) const
ASSERT(view);
bool caretBrowsing = false;
if (FrameView* frameView = view->frameView()) {
- Frame& frame = frameView->frame(); // The frame where the selection started
+ LocalFrame& frame = frameView->frame(); // The frame where the selection started
caretBrowsing = frame.settings() && frame.settings()->caretBrowsingEnabled();
}
return (caretBrowsing || isContentEditable);
if (RenderView* view = node->document().renderView()) {
if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)))
- repaintCaretForLocalRect(node, localCaretRectWithoutUpdate());
+ invalidateLocalCaretRect(node, localCaretRectWithoutUpdate());
}
}
return;
LayoutRect drawingRect = localCaretRectWithoutUpdate();
- RenderObject* renderer = caretRenderer(node);
- if (renderer && renderer->isBox())
- toRenderBox(renderer)->flipForWritingMode(drawingRect);
+ if (RenderBlock* renderer = caretRenderer(node))
+ renderer->flipForWritingMode(drawingRect);
drawingRect.moveBy(roundedIntPoint(paintOffset));
LayoutRect caret = intersection(drawingRect, clipRect);
if (caret.isEmpty())
context->fillRect(caret, caretColor);
}
-void DragCaretController::paintDragCaret(Frame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const
+void DragCaretController::paintDragCaret(LocalFrame* 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);