2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
24 #include "RenderBoxModelObject.h"
25 #include "TextDirection.h"
33 // InlineBox represents a rectangle that occurs on a line. It corresponds to
34 // some RenderObject (i.e., it represents a portion of that RenderObject).
37 InlineBox(RenderObject* obj)
44 , m_constructed(false)
45 , m_bidiEmbeddingLevel(0)
48 , m_hasVirtualLogicalHeight(false)
49 , m_isHorizontal(true)
50 , m_endsWithBreak(false)
51 , m_hasSelectedChildrenOrCanHaveLeadingExpansion(false)
52 , m_knownToHaveNoOverflow(true)
53 , m_hasEllipsisBoxOrHyphen(false)
54 , m_dirOverride(false)
56 , m_determinedIfNextOnLineExists(false)
57 , m_nextOnLineExists(false)
60 , m_hasBadParent(false)
65 InlineBox(RenderObject* obj, FloatPoint topLeft, float logicalWidth, bool firstLine, bool constructed,
66 bool dirty, bool extracted, bool isHorizontal, InlineBox* next, InlineBox* prev, InlineFlowBox* parent)
72 , m_logicalWidth(logicalWidth)
73 , m_firstLine(firstLine)
74 , m_constructed(constructed)
75 , m_bidiEmbeddingLevel(0)
77 , m_extracted(extracted)
78 , m_hasVirtualLogicalHeight(false)
79 , m_isHorizontal(isHorizontal)
80 , m_endsWithBreak(false)
81 , m_hasSelectedChildrenOrCanHaveLeadingExpansion(false)
82 , m_knownToHaveNoOverflow(true)
83 , m_hasEllipsisBoxOrHyphen(false)
84 , m_dirOverride(false)
86 , m_determinedIfNextOnLineExists(false)
87 , m_nextOnLineExists(false)
90 , m_hasBadParent(false)
97 virtual void destroy(RenderArena*);
99 virtual void deleteLine(RenderArena*);
100 virtual void extractLine();
101 virtual void attachLine();
103 virtual bool isLineBreak() const { return false; }
105 virtual void adjustPosition(float dx, float dy);
106 void adjustLineDirectionPosition(float delta)
109 adjustPosition(delta, 0);
111 adjustPosition(0, delta);
113 void adjustBlockDirectionPosition(float delta)
116 adjustPosition(0, delta);
118 adjustPosition(delta, 0);
121 virtual void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom);
122 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom);
124 InlineBox* next() const { return m_next; }
126 // Overloaded new operator.
127 void* operator new(size_t, RenderArena*) throw();
129 // Overridden to prevent the normal delete from being called.
130 void operator delete(void*, size_t);
133 // The normal operator new is disallowed.
134 void* operator new(size_t) throw();
138 void showTreeForThis() const;
139 void showLineTreeForThis() const;
141 virtual void showBox(int = 0) const;
142 virtual void showLineTreeAndMark(const InlineBox* = 0, const char* = 0, const InlineBox* = 0, const char* = 0, const RenderObject* = 0, int = 0) const;
143 virtual const char* boxName() const;
146 bool isText() const { return m_isText; }
147 void setIsText(bool b) { m_isText = b; }
149 virtual bool isInlineFlowBox() const { return false; }
150 virtual bool isInlineTextBox() const { return false; }
151 virtual bool isRootInlineBox() const { return false; }
153 virtual bool isSVGInlineTextBox() const { return false; }
154 virtual bool isSVGInlineFlowBox() const { return false; }
155 virtual bool isSVGRootInlineBox() const { return false; }
158 bool hasVirtualLogicalHeight() const { return m_hasVirtualLogicalHeight; }
159 void setHasVirtualLogicalHeight() { m_hasVirtualLogicalHeight = true; }
160 virtual float virtualLogicalHeight() const
162 ASSERT_NOT_REACHED();
166 bool isHorizontal() const { return m_isHorizontal; }
167 void setIsHorizontal(bool horizontal) { m_isHorizontal = horizontal; }
169 virtual FloatRect calculateBoundaries() const
171 ASSERT_NOT_REACHED();
175 bool isConstructed() { return m_constructed; }
176 virtual void setConstructed() { m_constructed = true; }
178 void setExtracted(bool b = true) { m_extracted = b; }
180 void setFirstLineStyleBit(bool f) { m_firstLine = f; }
181 bool isFirstLineStyle() const { return m_firstLine; }
185 InlineBox* nextOnLine() const { return m_next; }
186 InlineBox* prevOnLine() const { return m_prev; }
187 void setNextOnLine(InlineBox* next)
189 ASSERT(m_parent || !next);
192 void setPrevOnLine(InlineBox* prev)
194 ASSERT(m_parent || !prev);
197 bool nextOnLineExists() const;
199 virtual bool isLeaf() const { return true; }
201 InlineBox* nextLeafChild() const;
202 InlineBox* prevLeafChild() const;
204 RenderObject* renderer() const { return m_renderer; }
206 InlineFlowBox* parent() const
208 ASSERT(!m_hasBadParent);
211 void setParent(InlineFlowBox* par) { m_parent = par; }
213 const RootInlineBox* root() const;
214 RootInlineBox* root();
216 // x() is the left side of the box in the containing block's coordinate system.
217 void setX(float x) { m_topLeft.setX(x); }
218 float x() const { return m_topLeft.x(); }
219 float left() const { return m_topLeft.x(); }
221 // y() is the top side of the box in the containing block's coordinate system.
222 void setY(float y) { m_topLeft.setY(y); }
223 float y() const { return m_topLeft.y(); }
224 float top() const { return m_topLeft.y(); }
226 const FloatPoint& topLeft() const { return m_topLeft; }
228 float width() const { return isHorizontal() ? logicalWidth() : logicalHeight(); }
229 float height() const { return isHorizontal() ? logicalHeight() : logicalWidth(); }
230 FloatSize size() const { return IntSize(width(), height()); }
231 float right() const { return left() + width(); }
232 float bottom() const { return top() + height(); }
234 // The logicalLeft position is the left edge of the line box in a horizontal line and the top edge in a vertical line.
235 float logicalLeft() const { return isHorizontal() ? m_topLeft.x() : m_topLeft.y(); }
236 float logicalRight() const { return logicalLeft() + logicalWidth(); }
237 void setLogicalLeft(float left)
244 int pixelSnappedLogicalLeft() const { return logicalLeft(); }
245 int pixelSnappedLogicalRight() const { return ceilf(logicalRight()); }
246 int pixelSnappedLogicalTop() const { return logicalTop(); }
247 int pixelSnappedLogicalBottom() const { return ceilf(logicalBottom()); }
249 // The logicalTop[ position is the top edge of the line box in a horizontal line and the left edge in a vertical line.
250 float logicalTop() const { return isHorizontal() ? m_topLeft.y() : m_topLeft.x(); }
251 float logicalBottom() const { return logicalTop() + logicalHeight(); }
252 void setLogicalTop(float top)
260 // The logical width is our extent in the line's overall inline direction, i.e., width for horizontal text and height for vertical text.
261 void setLogicalWidth(float w) { m_logicalWidth = w; }
262 float logicalWidth() const { return m_logicalWidth; }
264 // The logical height is our extent in the block flow direction, i.e., height for horizontal text and width for vertical text.
265 float logicalHeight() const;
267 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()); }
269 virtual LayoutUnit baselinePosition(FontBaseline baselineType) const { return boxModelObject()->baselinePosition(baselineType, m_firstLine, isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine); }
270 virtual LayoutUnit lineHeight() const { return boxModelObject()->lineHeight(m_firstLine, isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine); }
272 virtual int caretMinOffset() const;
273 virtual int caretMaxOffset() const;
275 unsigned char bidiLevel() const { return m_bidiEmbeddingLevel; }
276 void setBidiLevel(unsigned char level) { m_bidiEmbeddingLevel = level; }
277 TextDirection direction() const { return m_bidiEmbeddingLevel % 2 ? RTL : LTR; }
278 bool isLeftToRightDirection() const { return direction() == LTR; }
279 int caretLeftmostOffset() const { return isLeftToRightDirection() ? caretMinOffset() : caretMaxOffset(); }
280 int caretRightmostOffset() const { return isLeftToRightDirection() ? caretMaxOffset() : caretMinOffset(); }
282 virtual void clearTruncation() { }
284 bool isDirty() const { return m_dirty; }
285 void markDirty(bool dirty = true) { m_dirty = dirty; }
287 void dirtyLineBoxes();
289 virtual RenderObject::SelectionState selectionState();
291 virtual bool canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth);
292 // visibleLeftEdge, visibleRightEdge are in the parent's coordinate system.
293 virtual float placeEllipsisBox(bool ltr, float visibleLeftEdge, float visibleRightEdge, float ellipsisWidth, bool&);
295 void setHasBadParent();
297 int expansion() const { return m_expansion; }
299 bool visibleToHitTesting() const { return renderer()->style()->visibility() == VISIBLE && renderer()->style()->pointerEvents() != PE_NONE; }
301 EVerticalAlign verticalAlign() const { return renderer()->style(m_firstLine)->verticalAlign(); }
303 // Use with caution! The type is not checked!
304 RenderBoxModelObject* boxModelObject() const
306 if (!m_renderer->isText())
307 return toRenderBoxModelObject(m_renderer);
311 FloatPoint locationIncludingFlipping();
312 void flipForWritingMode(FloatRect&);
313 FloatPoint flipForWritingMode(const FloatPoint&);
314 void flipForWritingMode(IntRect&);
315 IntPoint flipForWritingMode(const IntPoint&);
317 bool knownToHaveNoOverflow() const { return m_knownToHaveNoOverflow; }
318 void clearKnownToHaveNoOverflow();
321 InlineBox* m_next; // The next element on the same line as us.
322 InlineBox* m_prev; // The previous element on the same line as us.
324 InlineFlowBox* m_parent; // The box that contains us.
327 RenderObject* m_renderer;
329 FloatPoint m_topLeft;
330 float m_logicalWidth;
332 // Some of these bits are actually for subclasses and moved here to compact the structures.
336 bool m_firstLine : 1;
338 bool m_constructed : 1;
339 unsigned char m_bidiEmbeddingLevel : 6;
342 bool m_extracted : 1;
343 bool m_hasVirtualLogicalHeight : 1;
345 bool m_isHorizontal : 1;
348 bool m_endsWithBreak : 1; // Whether the line ends with a <br>.
349 // shared between RootInlineBox and InlineTextBox
350 bool m_hasSelectedChildrenOrCanHaveLeadingExpansion : 1; // Whether we have any children selected (this bit will also be set if the <br> that terminates our line is selected).
351 bool m_knownToHaveNoOverflow : 1;
352 bool m_hasEllipsisBoxOrHyphen : 1;
356 bool m_dirOverride : 1;
357 bool m_isText : 1; // Whether or not this object represents text with a non-zero height. Includes non-image list markers, text boxes.
359 mutable bool m_determinedIfNextOnLineExists : 1;
360 mutable bool m_nextOnLineExists : 1;
361 signed m_expansion : 11; // for justified text
370 inline InlineBox::~InlineBox()
375 inline void InlineBox::setHasBadParent()
378 m_hasBadParent = true;
382 } // namespace WebCore
385 // Outside the WebCore namespace for ease of invocation from gdb.
386 void showTree(const WebCore::InlineBox*);
387 void showLineTree(const WebCore::InlineBox*);
390 #endif // InlineBox_h