#ifndef VisiblePosition_h
#define VisiblePosition_h
#include "core/dom/Position.h"
#include "core/editing/EditingBoundary.h"
#include "platform/heap/Handle.h"
#include "platform/text/TextDirection.h"
namespace WebCore {
#define VP_DEFAULT_AFFINITY DOWNSTREAM
#define VP_UPSTREAM_IF_POSSIBLE UPSTREAM
class InlineBox;
class Node;
class VisiblePosition {
public:
VisiblePosition() : m_affinity(VP_DEFAULT_AFFINITY) { }
explicit VisiblePosition(const Position&, EAffinity = VP_DEFAULT_AFFINITY);
explicit VisiblePosition(const PositionWithAffinity&);
void clear() { m_deepPosition.clear(); }
bool isNull() const { return m_deepPosition.isNull(); }
bool isNotNull() const { return m_deepPosition.isNotNull(); }
bool isOrphan() const { return m_deepPosition.isOrphan(); }
Position deepEquivalent() const { return m_deepPosition; }
EAffinity affinity() const { ASSERT(m_affinity == UPSTREAM || m_affinity == DOWNSTREAM); return m_affinity; }
void setAffinity(EAffinity affinity) { m_affinity = affinity; }
VisiblePosition next(EditingBoundaryCrossingRule = CanCrossEditingBoundary) const;
VisiblePosition previous(EditingBoundaryCrossingRule = CanCrossEditingBoundary) const;
VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition&) const;
VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition&) const;
VisiblePosition skipToStartOfEditingBoundary(const VisiblePosition&) const;
VisiblePosition skipToEndOfEditingBoundary(const VisiblePosition&) const;
VisiblePosition left(bool stayInEditableContent = false) const;
VisiblePosition right(bool stayInEditableContent = false) const;
UChar32 characterAfter() const;
UChar32 characterBefore() const { return previous().characterAfter(); }
Element* rootEditableElement() const { return m_deepPosition.isNotNull() ? m_deepPosition.deprecatedNode()->rootEditableElement() : 0; }
void getInlineBoxAndOffset(InlineBox*& inlineBox, int& caretOffset) const
{
m_deepPosition.getInlineBoxAndOffset(m_affinity, inlineBox, caretOffset);
}
LayoutRect localCaretRect(RenderObject*&) const;
IntRect absoluteCaretBounds() const;
int lineDirectionPointForBlockDirectionNavigation() const;
#ifndef NDEBUG
void debugPosition(const char* msg = "") const;
void formatForDebugger(char* buffer, unsigned length) const;
void showTreeForThis() const;
#endif
private:
void init(const Position&, EAffinity);
Position canonicalPosition(const Position&);
Position leftVisuallyDistinctCandidate() const;
Position rightVisuallyDistinctCandidate() const;
Position m_deepPosition;
EAffinity m_affinity;
};
inline bool operator==(const VisiblePosition& a, const VisiblePosition& b)
{
return a.deepEquivalent() == b.deepEquivalent();
}
inline bool operator!=(const VisiblePosition& a, const VisiblePosition& b)
{
return !(a == b);
}
PassRefPtrWillBeRawPtr<Range> makeRange(const VisiblePosition&, const VisiblePosition&);
bool setStart(Range*, const VisiblePosition&);
bool setEnd(Range*, const VisiblePosition&);
VisiblePosition startVisiblePosition(const Range*, EAffinity);
Element* enclosingBlockFlowElement(const VisiblePosition&);
bool isFirstVisiblePositionInNode(const VisiblePosition&, const Node*);
bool isLastVisiblePositionInNode(const VisiblePosition&, const Node*);
}
#ifndef NDEBUG
void showTree(const WebCore::VisiblePosition*);
void showTree(const WebCore::VisiblePosition&);
#endif
#endif