RenderSelectionInfo.h [plain text]
#ifndef RenderSelectionInfo_h
#define RenderSelectionInfo_h
#include "IntRect.h"
#include "RenderBox.h"
#include "RenderText.h"
namespace WebCore {
class RenderSelectionInfoBase {
WTF_MAKE_NONCOPYABLE(RenderSelectionInfoBase); WTF_MAKE_FAST_ALLOCATED;
public:
RenderSelectionInfoBase()
: m_object(0)
, m_repaintContainer(0)
, m_state(RenderObject::SelectionNone)
{
}
explicit RenderSelectionInfoBase(RenderObject* o)
: m_object(o)
, m_repaintContainer(o->containerForRepaint())
, m_state(o->selectionState())
{
}
RenderObject* object() const { return m_object; }
RenderLayerModelObject* repaintContainer() const { return m_repaintContainer; }
RenderObject::SelectionState state() const { return m_state; }
protected:
RenderObject* m_object;
RenderLayerModelObject* m_repaintContainer;
RenderObject::SelectionState m_state;
};
class RenderSelectionInfo : public RenderSelectionInfoBase {
public:
RenderSelectionInfo(RenderObject* o, bool clipToVisibleContent)
: RenderSelectionInfoBase(o)
{
ASSERT(o);
if (o->canUpdateSelectionOnRootLineBoxes()) {
if (o->isText())
m_rect = toRenderText(*o).collectSelectionRectsForLineBoxes(m_repaintContainer, clipToVisibleContent, m_rects);
else
m_rect = o->selectionRectForRepaint(m_repaintContainer, clipToVisibleContent);
}
}
void repaint()
{
m_object->repaintUsingContainer(m_repaintContainer, enclosingIntRect(m_rect));
}
const Vector<LayoutRect>& rects() const { return m_rects; }
LayoutRect rect() const { return m_rect; }
private:
Vector<LayoutRect> m_rects;
LayoutRect m_rect; };
class RenderBlockSelectionInfo : public RenderSelectionInfoBase {
public:
explicit RenderBlockSelectionInfo(RenderBlock* b)
: RenderSelectionInfoBase(b)
, m_rects(b->canUpdateSelectionOnRootLineBoxes() ? block()->selectionGapRectsForRepaint(m_repaintContainer) : GapRects())
{
}
void repaint()
{
m_object->repaintUsingContainer(m_repaintContainer, enclosingIntRect(m_rects));
}
RenderBlock* block() const { return toRenderBlock(m_object); }
GapRects rects() const { return m_rects; }
private:
GapRects m_rects; };
}
#endif // RenderSelectionInfo_h