1 /*
2 * Copyright (C) 2003, 2006, 2007, 2008 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 RootInlineBox_h
22 #define RootInlineBox_h
23
24 #include "BidiContext.h"
25 #include "InlineFlowBox.h"
26
27 namespace WebCore {
28
29 class EllipsisBox;
30 class HitTestResult;
31
32 struct BidiStatus;
33 struct GapRects;
34
35 class RootInlineBox : public InlineFlowBox {
36 public:
37 RootInlineBox(RenderBlock* block);
38
39 virtual void destroy(RenderArena*);
40
isRootInlineBox()41 virtual bool isRootInlineBox() const { return true; }
42
43 void detachEllipsisBox(RenderArena*);
44
nextRootBox()45 RootInlineBox* nextRootBox() const { return static_cast<RootInlineBox*>(m_nextLineBox); }
prevRootBox()46 RootInlineBox* prevRootBox() const { return static_cast<RootInlineBox*>(m_prevLineBox); }
47
48 virtual void adjustPosition(float dx, float dy);
49
lineTop()50 int lineTop() const { return m_lineTop; }
lineBottom()51 int lineBottom() const { return m_lineBottom; }
52
paginationStrut()53 int paginationStrut() const { return m_paginationStrut; }
setPaginationStrut(int s)54 void setPaginationStrut(int s) { m_paginationStrut = s; }
55
isFirstAfterPageBreak()56 bool isFirstAfterPageBreak() const { return m_isFirstAfterPageBreak; }
setIsFirstAfterPageBreak(bool isFirstAfterPageBreak)57 void setIsFirstAfterPageBreak(bool isFirstAfterPageBreak) { m_isFirstAfterPageBreak = isFirstAfterPageBreak; }
58
59 int selectionTop() const;
60 int selectionBottom() const;
selectionHeight()61 int selectionHeight() const { return max(0, selectionBottom() - selectionTop()); }
62
63 int alignBoxesInBlockDirection(int heightOfBlock, GlyphOverflowAndFallbackFontsMap&, VerticalPositionCache&);
64 void setLineTopBottomPositions(int top, int bottom);
65
66 virtual RenderLineBoxList* rendererLineBoxes() const;
67
lineBreakObj()68 RenderObject* lineBreakObj() const { return m_lineBreakObj; }
69 BidiStatus lineBreakBidiStatus() const;
70 void setLineBreakInfo(RenderObject*, unsigned breakPos, const BidiStatus&);
71
lineBreakPos()72 unsigned lineBreakPos() const { return m_lineBreakPos; }
setLineBreakPos(unsigned p)73 void setLineBreakPos(unsigned p) { m_lineBreakPos = p; }
74
blockLogicalHeight()75 int blockLogicalHeight() const { return m_blockLogicalHeight; }
setBlockLogicalHeight(int h)76 void setBlockLogicalHeight(int h) { m_blockLogicalHeight = h; }
77
endsWithBreak()78 bool endsWithBreak() const { return m_endsWithBreak; }
setEndsWithBreak(bool b)79 void setEndsWithBreak(bool b) { m_endsWithBreak = b; }
80
81 void childRemoved(InlineBox* box);
82
83 bool lineCanAccommodateEllipsis(bool ltr, int blockEdge, int lineBoxEdge, int ellipsisWidth);
84 void placeEllipsis(const AtomicString& ellipsisStr, bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, InlineBox* markupBox = 0);
85 virtual float placeEllipsisBox(bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, bool& foundBox);
86
87 EllipsisBox* ellipsisBox() const;
88
89 void paintEllipsisBox(PaintInfo&, int tx, int ty, int lineTop, int lineBottom) const;
90
91 virtual void clearTruncation();
92
baselinePosition(FontBaseline baselineType)93 virtual int baselinePosition(FontBaseline baselineType) const { return boxModelObject()->baselinePosition(baselineType, m_firstLine, isHorizontal() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); }
lineHeight()94 virtual int lineHeight() const { return boxModelObject()->lineHeight(m_firstLine, isHorizontal() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); }
95
96 #if PLATFORM(MAC)
97 void addHighlightOverflow();
98 void paintCustomHighlight(PaintInfo&, int tx, int ty, const AtomicString& highlightType);
99 #endif
100
101 virtual void paint(PaintInfo&, int tx, int ty, int lineTop, int lineBottom);
102 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, int lineTop, int lineBottom);
103
hasSelectedChildren()104 bool hasSelectedChildren() const { return m_hasSelectedChildrenOrCanHaveLeadingExpansion; }
setHasSelectedChildren(bool hasSelectedChildren)105 void setHasSelectedChildren(bool hasSelectedChildren) { m_hasSelectedChildrenOrCanHaveLeadingExpansion = hasSelectedChildren; }
106
107 virtual RenderObject::SelectionState selectionState();
108 InlineBox* firstSelectedBox();
109 InlineBox* lastSelectedBox();
110
111 GapRects lineSelectionGap(RenderBlock* rootBlock, const IntPoint& rootBlockPhysicalPosition, const IntSize& offsetFromRootBlock, int selTop, int selHeight, const PaintInfo*);
112
113 RenderBlock* block() const;
114
115 InlineBox* closestLeafChildForLogicalLeftPosition(int, bool onlyEditableLeaves = false);
116
appendFloat(RenderBox * floatingBox)117 void appendFloat(RenderBox* floatingBox)
118 {
119 ASSERT(!isDirty());
120 if (m_floats)
121 m_floats->append(floatingBox);
122 else
123 m_floats= adoptPtr(new Vector<RenderBox*>(1, floatingBox));
124 }
125
floatsPtr()126 Vector<RenderBox*>* floatsPtr() { ASSERT(!isDirty()); return m_floats.get(); }
127
128 virtual void extractLineBoxFromRenderObject();
129 virtual void attachLineBoxToRenderObject();
130 virtual void removeLineBoxFromRenderObject();
131
baselineType()132 FontBaseline baselineType() const { return static_cast<FontBaseline>(m_baselineType); }
133
hasAnnotationsBefore()134 bool hasAnnotationsBefore() const { return m_hasAnnotationsBefore; }
hasAnnotationsAfter()135 bool hasAnnotationsAfter() const { return m_hasAnnotationsAfter; }
136
137 IntRect paddedLayoutOverflowRect(int endPadding) const;
138
139 void ascentAndDescentForBox(InlineBox*, GlyphOverflowAndFallbackFontsMap&, int& ascent, int& descent, bool& affectsAscent, bool& affectsDescent) const;
140 int verticalPositionForBox(InlineBox*, VerticalPositionCache&);
141 bool includeLeadingForBox(InlineBox*) const;
142 bool includeFontForBox(InlineBox*) const;
143 bool includeGlyphsForBox(InlineBox*) const;
144 bool includeMarginForBox(InlineBox*) const;
145 bool fitsToGlyphs() const;
146 bool includesRootLineBoxFontOrLeading() const;
147
logicalTopVisualOverflow()148 int logicalTopVisualOverflow() const
149 {
150 return InlineFlowBox::logicalTopVisualOverflow(lineTop());
151 }
logicalBottomVisualOverflow()152 int logicalBottomVisualOverflow() const
153 {
154 return InlineFlowBox::logicalBottomVisualOverflow(lineBottom());
155 }
logicalTopLayoutOverflow()156 int logicalTopLayoutOverflow() const
157 {
158 return InlineFlowBox::logicalTopLayoutOverflow(lineTop());
159 }
logicalBottomLayoutOverflow()160 int logicalBottomLayoutOverflow() const
161 {
162 return InlineFlowBox::logicalBottomLayoutOverflow(lineBottom());
163 }
164
165 Node* getLogicalStartBoxWithNode(InlineBox*&) const;
166 Node* getLogicalEndBoxWithNode(InlineBox*&) const;
167 #ifndef NDEBUG
168 virtual const char* boxName() const;
169 #endif
170 private:
hasEllipsisBox()171 bool hasEllipsisBox() const { return m_hasEllipsisBoxOrHyphen; }
setHasEllipsisBox(bool hasEllipsisBox)172 void setHasEllipsisBox(bool hasEllipsisBox) { m_hasEllipsisBoxOrHyphen = hasEllipsisBox; }
173
174 int beforeAnnotationsAdjustment() const;
175
176 // Where this line ended. The exact object and the position within that object are stored so that
177 // we can create an InlineIterator beginning just after the end of this line.
178 RenderObject* m_lineBreakObj;
179 unsigned m_lineBreakPos;
180 RefPtr<BidiContext> m_lineBreakContext;
181
182 int m_lineTop;
183 int m_lineBottom;
184
185 int m_paginationStrut;
186
187 // Floats hanging off the line are pushed into this vector during layout. It is only
188 // good for as long as the line has not been marked dirty.
189 OwnPtr<Vector<RenderBox*> > m_floats;
190
191 // The logical height of the block at the end of this line. This is where the next line starts.
192 int m_blockLogicalHeight;
193
194 // Whether or not this line uses alphabetic or ideographic baselines by default.
195 unsigned m_baselineType : 1; // FontBaseline
196
197 // If the line contains any ruby runs, then this will be true.
198 bool m_hasAnnotationsBefore : 1;
199 bool m_hasAnnotationsAfter : 1;
200
201 WTF::Unicode::Direction m_lineBreakBidiStatusEor : 5;
202 WTF::Unicode::Direction m_lineBreakBidiStatusLastStrong : 5;
203 WTF::Unicode::Direction m_lineBreakBidiStatusLast : 5;
204 };
205
setLineTopBottomPositions(int top,int bottom)206 inline void RootInlineBox::setLineTopBottomPositions(int top, int bottom)
207 {
208 m_lineTop = top;
209 m_lineBottom = bottom;
210 }
211
212 } // namespace WebCore
213
214 #endif // RootInlineBox_h
215