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 "RenderBox.h"
25 #include "TextDirection.h"
32 struct HitTestRequest
;
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
)
49 , m_constructed(false)
50 , m_bidiEmbeddingLevel(0)
53 , m_includeLeftEdge(false)
54 , m_includeRightEdge(false)
55 , m_hasTextChildren(true)
56 , m_endsWithBreak(false)
57 , m_hasSelectedChildren(false)
58 , m_hasEllipsisBox(false)
59 , m_dirOverride(false)
61 , m_determinedIfNextOnLineExists(false)
62 , m_determinedIfPrevOnLineExists(false)
63 , m_nextOnLineExists(false)
64 , m_prevOnLineExists(false)
67 , m_hasBadParent(false)
72 InlineBox(RenderObject
* obj
, int x
, int y
, int width
, int height
, int baseline
, bool firstLine
, bool constructed
,
73 bool dirty
, bool extracted
, InlineBox
* next
, InlineBox
* prev
, InlineFlowBox
* parent
)
79 , m_baseline(baseline
)
83 , m_firstLine(firstLine
)
84 , m_constructed(constructed
)
85 , m_bidiEmbeddingLevel(0)
87 , m_extracted(extracted
)
88 , m_includeLeftEdge(false)
89 , m_includeRightEdge(false)
90 , m_hasTextChildren(true)
91 , m_endsWithBreak(false)
92 , m_hasSelectedChildren(false)
93 , m_hasEllipsisBox(false)
94 , m_dirOverride(false)
96 , m_determinedIfNextOnLineExists(false)
97 , m_determinedIfPrevOnLineExists(false)
98 , m_nextOnLineExists(false)
99 , m_prevOnLineExists(false)
102 , m_hasBadParent(false)
107 virtual ~InlineBox();
109 virtual void destroy(RenderArena
*);
111 virtual void deleteLine(RenderArena
*);
112 virtual void extractLine();
113 virtual void attachLine();
115 virtual bool isLineBreak() const { return false; }
117 virtual void adjustPosition(int dx
, int dy
);
119 virtual void paint(RenderObject::PaintInfo
&, int tx
, int ty
);
120 virtual bool nodeAtPoint(const HitTestRequest
&, HitTestResult
&, int x
, int y
, int tx
, int ty
);
122 // Overloaded new operator.
123 void* operator new(size_t, RenderArena
*) throw();
125 // Overridden to prevent the normal delete from being called.
126 void operator delete(void*, size_t);
129 // The normal operator new is disallowed.
130 void* operator new(size_t) throw();
134 void showTreeForThis() const;
136 virtual bool isInlineBox() { return false; }
137 virtual bool isInlineFlowBox() { return false; }
138 virtual bool isContainer() { return false; }
139 virtual bool isInlineTextBox() { return false; }
140 virtual bool isRootInlineBox() { return false; }
142 virtual bool isSVGRootInlineBox() { return false; }
144 virtual bool isText() const { return false; }
146 bool isConstructed() { return m_constructed
; }
147 virtual void setConstructed()
149 m_constructed
= true;
151 m_next
->setConstructed();
154 void setExtracted(bool b
= true) { m_extracted
= b
; }
156 void setFirstLineStyleBit(bool f
) { m_firstLine
= f
; }
157 bool isFirstLineStyle() const { return m_firstLine
; }
161 InlineBox
* nextOnLine() const { return m_next
; }
162 InlineBox
* prevOnLine() const { return m_prev
; }
163 void setNextOnLine(InlineBox
* next
)
165 ASSERT(m_parent
|| !next
);
168 void setPrevOnLine(InlineBox
* prev
)
170 ASSERT(m_parent
|| !prev
);
173 bool nextOnLineExists() const;
174 bool prevOnLineExists() const;
176 virtual InlineBox
* firstLeafChild();
177 virtual InlineBox
* lastLeafChild();
178 InlineBox
* nextLeafChild();
179 InlineBox
* prevLeafChild();
181 RenderObject
* object() const { return m_object
; }
183 InlineFlowBox
* parent() const
185 ASSERT(!m_hasBadParent
);
188 void setParent(InlineFlowBox
* par
) { m_parent
= par
; }
190 RootInlineBox
* root();
192 void setWidth(int w
) { m_width
= w
; }
193 int width() const { return m_width
; }
195 void setXPos(int x
) { m_x
= x
; }
196 int xPos() const { return m_x
; }
198 void setYPos(int y
) { m_y
= y
; }
199 int yPos() const { return m_y
; }
201 void setHeight(int h
) { m_height
= h
; }
202 int height() const { return m_height
; }
204 void setBaseline(int b
) { m_baseline
= b
; }
205 int baseline() const { return m_baseline
; }
207 bool hasTextChildren() const { return m_hasTextChildren
; }
209 virtual int topOverflow() { return yPos(); }
210 virtual int bottomOverflow() { return yPos() + height(); }
211 virtual int leftOverflow() { return xPos(); }
212 virtual int rightOverflow() { return xPos() + width(); }
214 virtual int caretMinOffset() const;
215 virtual int caretMaxOffset() const;
216 virtual unsigned caretMaxRenderedOffset() const;
218 unsigned char bidiLevel() const { return m_bidiEmbeddingLevel
; }
219 void setBidiLevel(unsigned char level
) { m_bidiEmbeddingLevel
= level
; }
220 TextDirection
direction() const { return m_bidiEmbeddingLevel
% 2 ? RTL
: LTR
; }
221 int caretLeftmostOffset() const { return direction() == LTR
? caretMinOffset() : caretMaxOffset(); }
222 int caretRightmostOffset() const { return direction() == LTR
? caretMaxOffset() : caretMinOffset(); }
224 virtual void clearTruncation() { }
226 bool isDirty() const { return m_dirty
; }
227 void markDirty(bool dirty
= true) { m_dirty
= dirty
; }
229 void dirtyLineBoxes();
231 virtual RenderObject::SelectionState
selectionState();
233 virtual bool canAccommodateEllipsis(bool ltr
, int blockEdge
, int ellipsisWidth
);
234 virtual int placeEllipsisBox(bool ltr
, int blockEdge
, int ellipsisWidth
, bool&);
236 void setHasBadParent();
238 int toAdd() const { return m_toAdd
; }
240 bool visibleToHitTesting() const { return object()->style()->visibility() == VISIBLE
&& object()->style()->pointerEvents() != PE_NONE
; }
242 // Use with caution! The type is not checked!
243 RenderBox
* renderBox() const { return toRenderBox(m_object
); }
246 RenderObject
* m_object
;
255 InlineBox
* m_next
; // The next element on the same line as us.
256 InlineBox
* m_prev
; // The previous element on the same line as us.
258 InlineFlowBox
* m_parent
; // The box that contains us.
260 // Some of these bits are actually for subclasses and moved here to compact the structures.
264 bool m_firstLine
: 1;
266 bool m_constructed
: 1;
267 unsigned char m_bidiEmbeddingLevel
: 6;
270 bool m_extracted
: 1;
273 bool m_includeLeftEdge
: 1;
274 bool m_includeRightEdge
: 1;
275 bool m_hasTextChildren
: 1;
278 bool m_endsWithBreak
: 1; // Whether the line ends with a <br>.
279 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).
280 bool m_hasEllipsisBox
: 1;
284 bool m_dirOverride
: 1;
285 bool m_treatAsText
: 1; // Whether or not to treat a <br> as text for the purposes of line height.
287 mutable bool m_determinedIfNextOnLineExists
: 1;
288 mutable bool m_determinedIfPrevOnLineExists
: 1;
289 mutable bool m_nextOnLineExists
: 1;
290 mutable bool m_prevOnLineExists
: 1;
291 int m_toAdd
: 13; // for justified text
300 inline InlineBox::~InlineBox()
305 inline void InlineBox::setHasBadParent()
308 m_hasBadParent
= true;
312 } // namespace WebCore
315 // Outside the WebCore namespace for ease of invocation from gdb.
316 void showTree(const WebCore::InlineBox
*);
319 #endif // InlineBox_h