2 * Copyright (C) 2003, 2004, 2005, 2006, 2007 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"
34 // InlineBox represents a rectangle that occurs on a line. It corresponds to
35 // some RenderObject (i.e., it represents a portion of that RenderObject).
38 InlineBox(RenderObject* obj)
47 , m_constructed(false)
48 , m_bidiEmbeddingLevel(0)
52 , m_hasVirtualHeight(false)
54 , m_endsWithBreak(false)
55 , m_hasSelectedChildren(false)
56 , m_hasEllipsisBox(false)
57 , m_dirOverride(false)
59 , m_determinedIfNextOnLineExists(false)
60 , m_determinedIfPrevOnLineExists(false)
61 , m_nextOnLineExists(false)
62 , m_prevOnLineExists(false)
65 , m_hasBadParent(false)
70 InlineBox(RenderObject* obj, int x, int y, int width, bool firstLine, bool constructed,
71 bool dirty, bool extracted, InlineBox* next, InlineBox* prev, InlineFlowBox* parent)
79 , m_firstLine(firstLine)
80 , m_constructed(constructed)
81 , m_bidiEmbeddingLevel(0)
83 , m_extracted(extracted)
85 , m_hasVirtualHeight(false)
87 , m_endsWithBreak(false)
88 , m_hasSelectedChildren(false)
89 , m_hasEllipsisBox(false)
90 , m_dirOverride(false)
92 , m_determinedIfNextOnLineExists(false)
93 , m_determinedIfPrevOnLineExists(false)
94 , m_nextOnLineExists(false)
95 , m_prevOnLineExists(false)
98 , m_hasBadParent(false)
103 virtual ~InlineBox();
105 virtual void destroy(RenderArena*);
107 virtual void deleteLine(RenderArena*);
108 virtual void extractLine();
109 virtual void attachLine();
111 virtual bool isLineBreak() const { return false; }
113 virtual void adjustPosition(int dx, int dy);
115 virtual void paint(RenderObject::PaintInfo&, int tx, int ty);
116 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty);
118 // Overloaded new operator.
119 void* operator new(size_t, RenderArena*) throw();
121 // Overridden to prevent the normal delete from being called.
122 void operator delete(void*, size_t);
125 // The normal operator new is disallowed.
126 void* operator new(size_t) throw();
130 void showTreeForThis() const;
133 bool isText() const { return m_isText; }
134 void setIsText(bool b) { m_isText = b; }
136 virtual bool isInlineBox() { return false; }
137 virtual bool isInlineFlowBox() const { return false; }
138 virtual bool isInlineTextBox() { return false; }
139 virtual bool isRootInlineBox() const { return false; }
141 virtual bool isSVGRootInlineBox() { return false; }
143 bool hasVirtualHeight() const { return m_hasVirtualHeight; }
144 void setHasVirtualHeight() { m_hasVirtualHeight = true; }
145 virtual int virtualHeight() const { ASSERT_NOT_REACHED(); return 0; }
148 bool isConstructed() { return m_constructed; }
149 virtual void setConstructed()
151 m_constructed = true;
153 m_next->setConstructed();
156 void setExtracted(bool b = true) { m_extracted = b; }
158 void setFirstLineStyleBit(bool f) { m_firstLine = f; }
159 bool isFirstLineStyle() const { return m_firstLine; }
163 InlineBox* nextOnLine() const { return m_next; }
164 InlineBox* prevOnLine() const { return m_prev; }
165 void setNextOnLine(InlineBox* next)
167 ASSERT(m_parent || !next);
170 void setPrevOnLine(InlineBox* prev)
172 ASSERT(m_parent || !prev);
175 bool nextOnLineExists() const;
176 bool prevOnLineExists() const;
178 virtual InlineBox* firstLeafChild();
179 virtual InlineBox* lastLeafChild();
180 InlineBox* nextLeafChild();
181 InlineBox* prevLeafChild();
183 RenderObject* renderer() const { return m_renderer; }
185 InlineFlowBox* parent() const
187 ASSERT(!m_hasBadParent);
190 void setParent(InlineFlowBox* par) { m_parent = par; }
192 const RootInlineBox* root() const;
193 RootInlineBox* root();
195 void setWidth(int w) { m_width = w; }
196 int width() const { return m_width; }
198 // x() is the left side of the box in the parent's coordinate system.
199 void setX(int x) { m_x = x; }
200 int x() const { return m_x; }
202 // y() is the top of the box in the parent's coordinate system.
203 void setY(int y) { m_y = y; }
204 int y() const { return m_y; }
208 inline int baselinePosition(bool isRootLineBox) const { return renderer()->baselinePosition(m_firstLine, isRootLineBox); }
209 inline int lineHeight(bool isRootLineBox) const { return renderer()->lineHeight(m_firstLine, isRootLineBox); }
211 virtual int topOverflow() const { return y(); }
212 virtual int bottomOverflow() const { return y() + height(); }
213 virtual int leftOverflow() const { return x(); }
214 virtual int rightOverflow() const { return x() + width(); }
216 virtual int caretMinOffset() const;
217 virtual int caretMaxOffset() const;
218 virtual unsigned caretMaxRenderedOffset() const;
220 unsigned char bidiLevel() const { return m_bidiEmbeddingLevel; }
221 void setBidiLevel(unsigned char level) { m_bidiEmbeddingLevel = level; }
222 TextDirection direction() const { return m_bidiEmbeddingLevel % 2 ? RTL : LTR; }
223 int caretLeftmostOffset() const { return direction() == LTR ? caretMinOffset() : caretMaxOffset(); }
224 int caretRightmostOffset() const { return direction() == LTR ? caretMaxOffset() : caretMinOffset(); }
226 virtual void clearTruncation() { }
228 bool isDirty() const { return m_dirty; }
229 void markDirty(bool dirty = true) { m_dirty = dirty; }
231 void dirtyLineBoxes();
233 virtual RenderObject::SelectionState selectionState();
235 virtual bool canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth);
236 // visibleLeftEdge, visibleRightEdge are in the parent's coordinate system.
237 virtual int placeEllipsisBox(bool ltr, int visibleLeftEdge, int visibleRightEdge, int ellipsisWidth, bool&);
239 void setHasBadParent();
241 int toAdd() const { return m_toAdd; }
243 bool visibleToHitTesting() const { return renderer()->style()->visibility() == VISIBLE && renderer()->style()->pointerEvents() != PE_NONE; }
245 // Use with caution! The type is not checked!
246 RenderBoxModelObject* boxModelObject() const
248 if (!m_renderer->isText())
249 return static_cast<RenderBoxModelObject*>(m_renderer);
254 InlineBox* m_next; // The next element on the same line as us.
255 InlineBox* m_prev; // The previous element on the same line as us.
257 InlineFlowBox* m_parent; // The box that contains us.
260 RenderObject* m_renderer;
266 // Some of these bits are actually for subclasses and moved here to compact the structures.
270 bool m_firstLine : 1;
272 bool m_constructed : 1;
273 unsigned char m_bidiEmbeddingLevel : 6;
276 bool m_extracted : 1;
277 bool m_hasVirtualHeight : 1;
280 bool m_endsWithBreak : 1; // Whether the line ends with a <br>.
281 bool m_hasSelectedChildren : 1; // Whether we have any children selected (this bit will also be set if the <br> that terminates our line is selected).
282 bool m_hasEllipsisBox : 1;
286 bool m_dirOverride : 1;
287 bool m_isText : 1; // Whether or not this object represents text with a non-zero height. Includes non-image list markers, text boxes.
289 mutable bool m_determinedIfNextOnLineExists : 1;
290 mutable bool m_determinedIfPrevOnLineExists : 1;
291 mutable bool m_nextOnLineExists : 1;
292 mutable bool m_prevOnLineExists : 1;
293 int m_toAdd : 12; // for justified text
302 inline InlineBox::~InlineBox()
307 inline void InlineBox::setHasBadParent()
310 m_hasBadParent = true;
314 } // namespace WebCore
317 // Outside the WebCore namespace for ease of invocation from gdb.
318 void showTree(const WebCore::InlineBox*);
321 #endif // InlineBox_h