• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
3  *
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.
8  *
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.
13  *
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.
18  *
19  */
20 
21 #ifndef InlineBox_h
22 #define InlineBox_h
23 
24 #include "RenderBox.h"
25 #include "TextDirection.h"
26 
27 namespace WebCore {
28 
29 class HitTestResult;
30 class RootInlineBox;
31 
32 struct HitTestRequest;
33 
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).
36 class InlineBox {
37 public:
InlineBox(RenderObject * obj)38     InlineBox(RenderObject* obj)
39         : m_object(obj)
40         , m_x(0)
41         , m_y(0)
42         , m_width(0)
43         , m_height(0)
44         , m_baseline(0)
45         , m_next(0)
46         , m_prev(0)
47         , m_parent(0)
48         , m_firstLine(false)
49         , m_constructed(false)
50         , m_bidiEmbeddingLevel(0)
51         , m_dirty(false)
52         , m_extracted(false)
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)
60         , m_treatAsText(true)
61         , m_determinedIfNextOnLineExists(false)
62         , m_determinedIfPrevOnLineExists(false)
63         , m_nextOnLineExists(false)
64         , m_prevOnLineExists(false)
65         , m_toAdd(0)
66 #ifndef NDEBUG
67         , m_hasBadParent(false)
68 #endif
69     {
70     }
71 
InlineBox(RenderObject * obj,int x,int y,int width,int height,int baseline,bool firstLine,bool constructed,bool dirty,bool extracted,InlineBox * next,InlineBox * prev,InlineFlowBox * parent)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)
74         : m_object(obj)
75         , m_x(x)
76         , m_y(y)
77         , m_width(width)
78         , m_height(height)
79         , m_baseline(baseline)
80         , m_next(next)
81         , m_prev(prev)
82         , m_parent(parent)
83         , m_firstLine(firstLine)
84         , m_constructed(constructed)
85         , m_bidiEmbeddingLevel(0)
86         , m_dirty(dirty)
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)
95         , m_treatAsText(true)
96         , m_determinedIfNextOnLineExists(false)
97         , m_determinedIfPrevOnLineExists(false)
98         , m_nextOnLineExists(false)
99         , m_prevOnLineExists(false)
100         , m_toAdd(0)
101 #ifndef NDEBUG
102         , m_hasBadParent(false)
103 #endif
104     {
105     }
106 
107     virtual ~InlineBox();
108 
109     virtual void destroy(RenderArena*);
110 
111     virtual void deleteLine(RenderArena*);
112     virtual void extractLine();
113     virtual void attachLine();
114 
isLineBreak()115     virtual bool isLineBreak() const { return false; }
116 
117     virtual void adjustPosition(int dx, int dy);
118 
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);
121 
122     // Overloaded new operator.
123     void* operator new(size_t, RenderArena*) throw();
124 
125     // Overridden to prevent the normal delete from being called.
126     void operator delete(void*, size_t);
127 
128 private:
129     // The normal operator new is disallowed.
130     void* operator new(size_t) throw();
131 
132 public:
133 #ifndef NDEBUG
134     void showTreeForThis() const;
135 #endif
isInlineBox()136     virtual bool isInlineBox() { return false; }
isInlineFlowBox()137     virtual bool isInlineFlowBox() { return false; }
isContainer()138     virtual bool isContainer() { return false; }
isInlineTextBox()139     virtual bool isInlineTextBox() { return false; }
isRootInlineBox()140     virtual bool isRootInlineBox() { return false; }
141 #if ENABLE(SVG)
isSVGRootInlineBox()142     virtual bool isSVGRootInlineBox() { return false; }
143 #endif
isText()144     virtual bool isText() const { return false; }
145 
isConstructed()146     bool isConstructed() { return m_constructed; }
setConstructed()147     virtual void setConstructed()
148     {
149         m_constructed = true;
150         if (m_next)
151             m_next->setConstructed();
152     }
153 
154     void setExtracted(bool b = true) { m_extracted = b; }
155 
setFirstLineStyleBit(bool f)156     void setFirstLineStyleBit(bool f) { m_firstLine = f; }
isFirstLineStyle()157     bool isFirstLineStyle() const { return m_firstLine; }
158 
159     void remove();
160 
nextOnLine()161     InlineBox* nextOnLine() const { return m_next; }
prevOnLine()162     InlineBox* prevOnLine() const { return m_prev; }
setNextOnLine(InlineBox * next)163     void setNextOnLine(InlineBox* next)
164     {
165         ASSERT(m_parent || !next);
166         m_next = next;
167     }
setPrevOnLine(InlineBox * prev)168     void setPrevOnLine(InlineBox* prev)
169     {
170         ASSERT(m_parent || !prev);
171         m_prev = prev;
172     }
173     bool nextOnLineExists() const;
174     bool prevOnLineExists() const;
175 
176     virtual InlineBox* firstLeafChild();
177     virtual InlineBox* lastLeafChild();
178     InlineBox* nextLeafChild();
179     InlineBox* prevLeafChild();
180 
object()181     RenderObject* object() const { return m_object; }
182 
parent()183     InlineFlowBox* parent() const
184     {
185         ASSERT(!m_hasBadParent);
186         return m_parent;
187     }
setParent(InlineFlowBox * par)188     void setParent(InlineFlowBox* par) { m_parent = par; }
189 
190     RootInlineBox* root();
191 
setWidth(int w)192     void setWidth(int w) { m_width = w; }
width()193     int width() const { return m_width; }
194 
setXPos(int x)195     void setXPos(int x) { m_x = x; }
xPos()196     int xPos() const { return m_x; }
197 
setYPos(int y)198     void setYPos(int y) { m_y = y; }
yPos()199     int yPos() const { return m_y; }
200 
setHeight(int h)201     void setHeight(int h) { m_height = h; }
height()202     int height() const { return m_height; }
203 
setBaseline(int b)204     void setBaseline(int b) { m_baseline = b; }
baseline()205     int baseline() const { return m_baseline; }
206 
hasTextChildren()207     bool hasTextChildren() const { return m_hasTextChildren; }
208 
topOverflow()209     virtual int topOverflow() { return yPos(); }
bottomOverflow()210     virtual int bottomOverflow() { return yPos() + height(); }
leftOverflow()211     virtual int leftOverflow() { return xPos(); }
rightOverflow()212     virtual int rightOverflow() { return xPos() + width(); }
213 
214     virtual int caretMinOffset() const;
215     virtual int caretMaxOffset() const;
216     virtual unsigned caretMaxRenderedOffset() const;
217 
bidiLevel()218     unsigned char bidiLevel() const { return m_bidiEmbeddingLevel; }
setBidiLevel(unsigned char level)219     void setBidiLevel(unsigned char level) { m_bidiEmbeddingLevel = level; }
direction()220     TextDirection direction() const { return m_bidiEmbeddingLevel % 2 ? RTL : LTR; }
caretLeftmostOffset()221     int caretLeftmostOffset() const { return direction() == LTR ? caretMinOffset() : caretMaxOffset(); }
caretRightmostOffset()222     int caretRightmostOffset() const { return direction() == LTR ? caretMaxOffset() : caretMinOffset(); }
223 
clearTruncation()224     virtual void clearTruncation() { }
225 
isDirty()226     bool isDirty() const { return m_dirty; }
227     void markDirty(bool dirty = true) { m_dirty = dirty; }
228 
229     void dirtyLineBoxes();
230 
231     virtual RenderObject::SelectionState selectionState();
232 
233     virtual bool canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth);
234     virtual int placeEllipsisBox(bool ltr, int blockEdge, int ellipsisWidth, bool&);
235 
236     void setHasBadParent();
237 
toAdd()238     int toAdd() const { return m_toAdd; }
239 
visibleToHitTesting()240     bool visibleToHitTesting() const { return object()->style()->visibility() == VISIBLE && object()->style()->pointerEvents() != PE_NONE; }
241 
242     // Use with caution! The type is not checked!
renderBox()243     RenderBox* renderBox() const { return toRenderBox(m_object); }
244 
245 public:
246     RenderObject* m_object;
247 
248     int m_x;
249     int m_y;
250     int m_width;
251     int m_height;
252     int m_baseline;
253 
254 private:
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.
257 
258     InlineFlowBox* m_parent; // The box that contains us.
259 
260     // Some of these bits are actually for subclasses and moved here to compact the structures.
261 
262     // for this class
263 protected:
264     bool m_firstLine : 1;
265 private:
266     bool m_constructed : 1;
267     unsigned char m_bidiEmbeddingLevel : 6;
268 protected:
269     bool m_dirty : 1;
270     bool m_extracted : 1;
271 
272     // for InlineFlowBox
273     bool m_includeLeftEdge : 1;
274     bool m_includeRightEdge : 1;
275     bool m_hasTextChildren : 1;
276 
277     // for RootInlineBox
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;
281 
282     // for InlineTextBox
283 public:
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.
286 protected:
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
292 
293 #ifndef NDEBUG
294 private:
295     bool m_hasBadParent;
296 #endif
297 };
298 
299 #ifdef NDEBUG
~InlineBox()300 inline InlineBox::~InlineBox()
301 {
302 }
303 #endif
304 
setHasBadParent()305 inline void InlineBox::setHasBadParent()
306 {
307 #ifndef NDEBUG
308     m_hasBadParent = true;
309 #endif
310 }
311 
312 } // namespace WebCore
313 
314 #ifndef NDEBUG
315 // Outside the WebCore namespace for ease of invocation from gdb.
316 void showTree(const WebCore::InlineBox*);
317 #endif
318 
319 #endif // InlineBox_h
320