#ifndef Caret_h
#define Caret_h
#include "core/editing/VisiblePosition.h"
#include "platform/geometry/IntRect.h"
#include "platform/geometry/LayoutRect.h"
#include "wtf/Noncopyable.h"
namespace WebCore {
class LocalFrame;
class GraphicsContext;
class RenderObject;
class RenderView;
class CaretBase {
WTF_MAKE_NONCOPYABLE(CaretBase);
WTF_MAKE_FAST_ALLOCATED;
protected:
enum CaretVisibility { Visible, Hidden };
explicit CaretBase(CaretVisibility = Hidden);
void invalidateCaretRect(Node*, bool caretRectChanged = false);
void clearCaretRect();
bool updateCaretRect(Document*, const VisiblePosition& caretPosition);
IntRect absoluteBoundsForLocalRect(Node*, const LayoutRect&) const;
bool shouldRepaintCaret(const RenderView*, bool isContentEditable) const;
void paintCaret(Node*, GraphicsContext*, const LayoutPoint&, const LayoutRect& clipRect) const;
const LayoutRect& localCaretRectWithoutUpdate() const { return m_caretLocalRect; }
bool shouldUpdateCaretRect() const { return m_caretRectNeedsUpdate; }
void setCaretRectNeedsUpdate() { m_caretRectNeedsUpdate = true; }
void setCaretVisibility(CaretVisibility visibility) { m_caretVisibility = visibility; }
bool caretIsVisible() const { return m_caretVisibility == Visible; }
CaretVisibility caretVisibility() const { return m_caretVisibility; }
protected:
static RenderObject* caretRenderer(Node*);
static void repaintCaretForLocalRect(Node*, const LayoutRect&);
private:
LayoutRect m_caretLocalRect;
bool m_caretRectNeedsUpdate;
CaretVisibility m_caretVisibility;
};
class DragCaretController : private CaretBase {
WTF_MAKE_NONCOPYABLE(DragCaretController);
WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<DragCaretController> create();
RenderObject* caretRenderer() const;
void paintDragCaret(LocalFrame*, GraphicsContext*, const LayoutPoint&, const LayoutRect& clipRect) const;
bool isContentEditable() const { return m_position.rootEditableElement(); }
bool isContentRichlyEditable() const;
bool hasCaret() const { return m_position.isNotNull(); }
const VisiblePosition& caretPosition() { return m_position; }
void setCaretPosition(const VisiblePosition&);
void clear() { setCaretPosition(VisiblePosition()); }
void nodeWillBeRemoved(Node&);
private:
DragCaretController();
VisiblePosition m_position;
};
}
#endif