#ifndef InlineBox_h
#define InlineBox_h
#include "core/rendering/RenderBoxModelObject.h"
#include "platform/text/TextDirection.h"
namespace WebCore {
class HitTestRequest;
class HitTestResult;
class RootInlineBox;
class InlineBox {
WTF_MAKE_NONCOPYABLE(InlineBox);
public:
InlineBox(RenderObject& obj)
: m_next(0)
, m_prev(0)
, m_parent(0)
, m_renderer(obj)
, m_logicalWidth(0)
#ifndef NDEBUG
, m_hasBadParent(false)
#endif
{
}
InlineBox(RenderObject& obj, FloatPoint topLeft, float logicalWidth, bool firstLine, bool constructed,
bool dirty, bool extracted, bool isHorizontal, InlineBox* next, InlineBox* prev, InlineFlowBox* parent)
: m_next(next)
, m_prev(prev)
, m_parent(parent)
, m_renderer(obj)
, m_topLeft(topLeft)
, m_logicalWidth(logicalWidth)
, m_bitfields(firstLine, constructed, dirty, extracted, isHorizontal)
#ifndef NDEBUG
, m_hasBadParent(false)
#endif
{
}
virtual ~InlineBox();
virtual void destroy() { delete this; }
virtual void deleteLine();
virtual void extractLine();
virtual void attachLine();
virtual bool isLineBreak() const { return false; }
virtual void adjustPosition(float dx, float dy);
void adjustLogicalPosition(float deltaLogicalLeft, float deltaLogicalTop)
{
if (isHorizontal())
adjustPosition(deltaLogicalLeft, deltaLogicalTop);
else
adjustPosition(deltaLogicalTop, deltaLogicalLeft);
}
void adjustLineDirectionPosition(float delta)
{
if (isHorizontal())
adjustPosition(delta, 0);
else
adjustPosition(0, delta);
}
void adjustBlockDirectionPosition(float delta)
{
if (isHorizontal())
adjustPosition(0, delta);
else
adjustPosition(delta, 0);
}
virtual void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom);
virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom);
void* operator new(size_t);
void operator delete(void*);
#ifndef NDEBUG
void showTreeForThis() const;
void showLineTreeForThis() const;
virtual void showBox(int = 0) const;
virtual void showLineTreeAndMark(const InlineBox* = 0, const char* = 0, const InlineBox* = 0, const char* = 0, const RenderObject* = 0, int = 0) const;
virtual const char* boxName() const;
#endif
bool isText() const { return m_bitfields.isText(); }
void setIsText(bool isText) { m_bitfields.setIsText(isText); }
virtual bool isInlineFlowBox() const { return false; }
virtual bool isInlineTextBox() const { return false; }
virtual bool isRootInlineBox() const { return false; }
virtual bool isSVGInlineTextBox() const { return false; }
virtual bool isSVGInlineFlowBox() const { return false; }
virtual bool isSVGRootInlineBox() const { return false; }
bool hasVirtualLogicalHeight() const { return m_bitfields.hasVirtualLogicalHeight(); }
void setHasVirtualLogicalHeight() { m_bitfields.setHasVirtualLogicalHeight(true); }
virtual float virtualLogicalHeight() const
{
ASSERT_NOT_REACHED();
return 0;
}
bool isHorizontal() const { return m_bitfields.isHorizontal(); }
void setIsHorizontal(bool isHorizontal) { m_bitfields.setIsHorizontal(isHorizontal); }
virtual FloatRect calculateBoundaries() const
{
ASSERT_NOT_REACHED();
return FloatRect();
}
bool isConstructed() { return m_bitfields.constructed(); }
virtual void setConstructed() { m_bitfields.setConstructed(true); }
void setExtracted(bool extracted = true) { m_bitfields.setExtracted(extracted); }
void setFirstLineStyleBit(bool firstLine) { m_bitfields.setFirstLine(firstLine); }
bool isFirstLineStyle() const { return m_bitfields.firstLine(); }
void remove();
InlineBox* nextOnLine() const { return m_next; }
InlineBox* prevOnLine() const { return m_prev; }
void setNextOnLine(InlineBox* next)
{
ASSERT(m_parent || !next);
m_next = next;
}
void setPrevOnLine(InlineBox* prev)
{
ASSERT(m_parent || !prev);
m_prev = prev;
}
bool nextOnLineExists() const;
virtual bool isLeaf() const { return true; }
InlineBox* nextLeafChild() const;
InlineBox* prevLeafChild() const;
InlineBox* nextLeafChildIgnoringLineBreak() const;
InlineBox* prevLeafChildIgnoringLineBreak() const;
RenderObject& renderer() const { return m_renderer; }
InlineFlowBox* parent() const
{
ASSERT(!m_hasBadParent);
return m_parent;
}
void setParent(InlineFlowBox* par) { m_parent = par; }
const RootInlineBox& root() const;
RootInlineBox& root();
void setX(float x) { m_topLeft.setX(x); }
float x() const { return m_topLeft.x(); }
float left() const { return m_topLeft.x(); }
void setY(float y) { m_topLeft.setY(y); }
float y() const { return m_topLeft.y(); }
float top() const { return m_topLeft.y(); }
const FloatPoint& topLeft() const { return m_topLeft; }
float width() const { return isHorizontal() ? logicalWidth() : hasVirtualLogicalHeight() ? virtualLogicalHeight() : logicalHeight(); }
float height() const { return isHorizontal() ? hasVirtualLogicalHeight() ? virtualLogicalHeight() : logicalHeight() : logicalWidth(); }
FloatSize size() const { return FloatSize(width(), height()); }
float right() const { return left() + width(); }
float bottom() const { return top() + height(); }
float logicalLeft() const { return isHorizontal() ? m_topLeft.x() : m_topLeft.y(); }
float logicalRight() const { return logicalLeft() + logicalWidth(); }
void setLogicalLeft(float left)
{
if (isHorizontal())
setX(left);
else
setY(left);
}
int pixelSnappedLogicalLeft() const { return logicalLeft(); }
int pixelSnappedLogicalRight() const { return ceilf(logicalRight()); }
int pixelSnappedLogicalTop() const { return logicalTop(); }
int pixelSnappedLogicalBottom() const { return ceilf(logicalBottom()); }
float logicalTop() const { return isHorizontal() ? m_topLeft.y() : m_topLeft.x(); }
float logicalBottom() const { return logicalTop() + logicalHeight(); }
void setLogicalTop(float top)
{
if (isHorizontal())
setY(top);
else
setX(top);
}
void setLogicalWidth(float w) { m_logicalWidth = w; }
float logicalWidth() const { return m_logicalWidth; }
float logicalHeight() const;
FloatRect logicalFrameRect() const { return isHorizontal() ? FloatRect(m_topLeft.x(), m_topLeft.y(), m_logicalWidth, logicalHeight()) : FloatRect(m_topLeft.y(), m_topLeft.x(), m_logicalWidth, logicalHeight()); }
virtual int baselinePosition(FontBaseline baselineType) const;
virtual LayoutUnit lineHeight() const;
virtual int caretMinOffset() const;
virtual int caretMaxOffset() const;
unsigned char bidiLevel() const { return m_bitfields.bidiEmbeddingLevel(); }
void setBidiLevel(unsigned char level) { m_bitfields.setBidiEmbeddingLevel(level); }
TextDirection direction() const { return bidiLevel() % 2 ? RTL : LTR; }
bool isLeftToRightDirection() const { return direction() == LTR; }
int caretLeftmostOffset() const { return isLeftToRightDirection() ? caretMinOffset() : caretMaxOffset(); }
int caretRightmostOffset() const { return isLeftToRightDirection() ? caretMaxOffset() : caretMinOffset(); }
virtual void clearTruncation() { }
bool isDirty() const { return m_bitfields.dirty(); }
virtual void markDirty(bool dirty = true) { m_bitfields.setDirty(dirty); }
virtual void dirtyLineBoxes();
virtual RenderObject::SelectionState selectionState();
virtual bool canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth) const;
virtual float placeEllipsisBox(bool ltr, float visibleLeftEdge, float visibleRightEdge, float ellipsisWidth, float &truncatedWidth, bool&);
#ifndef NDEBUG
void setHasBadParent();
#endif
int expansion() const { return m_bitfields.expansion(); }
bool visibleForTouchAction() const { return false; }
bool visibleToHitTestRequest(const HitTestRequest& request) const
{
if (request.touchAction() && !visibleForTouchAction())
return false;
return renderer().visibleToHitTestRequest(request);
}
EVerticalAlign verticalAlign() const { return renderer().style(m_bitfields.firstLine())->verticalAlign(); }
RenderBoxModelObject* boxModelObject() const
{
if (!renderer().isText())
return toRenderBoxModelObject(&renderer());
return 0;
}
FloatPoint locationIncludingFlipping();
void flipForWritingMode(FloatRect&);
FloatPoint flipForWritingMode(const FloatPoint&);
void flipForWritingMode(LayoutRect&);
LayoutPoint flipForWritingMode(const LayoutPoint&);
bool knownToHaveNoOverflow() const { return m_bitfields.knownToHaveNoOverflow(); }
void clearKnownToHaveNoOverflow();
bool dirOverride() const { return m_bitfields.dirOverride(); }
void setDirOverride(bool dirOverride) { m_bitfields.setDirOverride(dirOverride); }
#define ADD_BOOLEAN_BITFIELD(name, Name) \
private:\
unsigned m_##name : 1;\
public:\
bool name() const { return m_##name; }\
void set##Name(bool name) { m_##name = name; }\
class InlineBoxBitfields {
public:
InlineBoxBitfields(bool firstLine = false, bool constructed = false, bool dirty = false, bool extracted = false, bool isHorizontal = true)
: m_firstLine(firstLine)
, m_constructed(constructed)
, m_bidiEmbeddingLevel(0)
, m_dirty(dirty)
, m_extracted(extracted)
, m_hasVirtualLogicalHeight(false)
, m_isHorizontal(isHorizontal)
, m_endsWithBreak(false)
, m_hasSelectedChildrenOrCanHaveLeadingExpansion(false)
, m_knownToHaveNoOverflow(true)
, m_hasEllipsisBoxOrHyphen(false)
, m_dirOverride(false)
, m_isText(false)
, m_determinedIfNextOnLineExists(false)
, m_nextOnLineExists(false)
, m_expansion(0)
{
}
ADD_BOOLEAN_BITFIELD(firstLine, FirstLine);
ADD_BOOLEAN_BITFIELD(constructed, Constructed);
private:
unsigned m_bidiEmbeddingLevel : 6;
public:
unsigned char bidiEmbeddingLevel() const { return m_bidiEmbeddingLevel; }
void setBidiEmbeddingLevel(unsigned char bidiEmbeddingLevel) { m_bidiEmbeddingLevel = bidiEmbeddingLevel; }
ADD_BOOLEAN_BITFIELD(dirty, Dirty);
ADD_BOOLEAN_BITFIELD(extracted, Extracted);
ADD_BOOLEAN_BITFIELD(hasVirtualLogicalHeight, HasVirtualLogicalHeight);
ADD_BOOLEAN_BITFIELD(isHorizontal, IsHorizontal);
ADD_BOOLEAN_BITFIELD(endsWithBreak, EndsWithBreak);
ADD_BOOLEAN_BITFIELD(hasSelectedChildrenOrCanHaveLeadingExpansion, HasSelectedChildrenOrCanHaveLeadingExpansion);
ADD_BOOLEAN_BITFIELD(knownToHaveNoOverflow, KnownToHaveNoOverflow);
ADD_BOOLEAN_BITFIELD(hasEllipsisBoxOrHyphen, HasEllipsisBoxOrHyphen);
ADD_BOOLEAN_BITFIELD(dirOverride, DirOverride);
ADD_BOOLEAN_BITFIELD(isText, IsText);
private:
mutable unsigned m_determinedIfNextOnLineExists : 1;
public:
bool determinedIfNextOnLineExists() const { return m_determinedIfNextOnLineExists; }
void setDeterminedIfNextOnLineExists(bool determinedIfNextOnLineExists) const { m_determinedIfNextOnLineExists = determinedIfNextOnLineExists; }
private:
mutable unsigned m_nextOnLineExists : 1;
public:
bool nextOnLineExists() const { return m_nextOnLineExists; }
void setNextOnLineExists(bool nextOnLineExists) const { m_nextOnLineExists = nextOnLineExists; }
private:
signed m_expansion : 12;
public:
signed expansion() const { return m_expansion; }
void setExpansion(signed expansion) { m_expansion = expansion; }
};
#undef ADD_BOOLEAN_BITFIELD
private:
InlineBox* m_next;
InlineBox* m_prev;
InlineFlowBox* m_parent;
RenderObject& m_renderer;
protected:
bool endsWithBreak() const { return m_bitfields.endsWithBreak(); }
void setEndsWithBreak(bool endsWithBreak) { m_bitfields.setEndsWithBreak(endsWithBreak); }
bool hasEllipsisBox() const { return m_bitfields.hasEllipsisBoxOrHyphen(); }
bool hasSelectedChildren() const { return m_bitfields.hasSelectedChildrenOrCanHaveLeadingExpansion(); }
void setHasSelectedChildren(bool hasSelectedChildren) { m_bitfields.setHasSelectedChildrenOrCanHaveLeadingExpansion(hasSelectedChildren); }
void setHasEllipsisBox(bool hasEllipsisBox) { m_bitfields.setHasEllipsisBoxOrHyphen(hasEllipsisBox); }
bool hasHyphen() const { return m_bitfields.hasEllipsisBoxOrHyphen(); }
void setHasHyphen(bool hasHyphen) { m_bitfields.setHasEllipsisBoxOrHyphen(hasHyphen); }
bool canHaveLeadingExpansion() const { return m_bitfields.hasSelectedChildrenOrCanHaveLeadingExpansion(); }
void setCanHaveLeadingExpansion(bool canHaveLeadingExpansion) { m_bitfields.setHasSelectedChildrenOrCanHaveLeadingExpansion(canHaveLeadingExpansion); }
signed expansion() { return m_bitfields.expansion(); }
void setExpansion(signed expansion) { m_bitfields.setExpansion(expansion); }
bool extracted() const { return m_bitfields.extracted(); }
FloatPoint m_topLeft;
float m_logicalWidth;
private:
InlineBoxBitfields m_bitfields;
#ifndef NDEBUG
bool m_hasBadParent;
#endif
};
#ifdef NDEBUG
inline InlineBox::~InlineBox()
{
}
#endif
#ifndef NDEBUG
inline void InlineBox::setHasBadParent()
{
m_hasBadParent = true;
}
#endif
#define DEFINE_INLINE_BOX_TYPE_CASTS(typeName) \
DEFINE_TYPE_CASTS(typeName, InlineBox, box, box->is##typeName(), box.is##typeName())
inline bool operator==(const InlineBox& a, const InlineBox& b) { return &a == &b; }
inline bool operator==(const InlineBox& a, const InlineBox* b) { return &a == b; }
inline bool operator==(const InlineBox* a, const InlineBox& b) { return a == &b; }
inline bool operator!=(const InlineBox& a, const InlineBox& b) { return !(a == b); }
inline bool operator!=(const InlineBox& a, const InlineBox* b) { return !(a == b); }
inline bool operator!=(const InlineBox* a, const InlineBox& b) { return !(a == b); }
}
#ifndef NDEBUG
void showTree(const WebCore::InlineBox*);
void showLineTree(const WebCore::InlineBox*);
#endif
#endif