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.
21 #ifndef InlineFlowBox_h
22 #define InlineFlowBox_h
24 #include "InlineBox.h"
25 #include "RenderOverflow.h"
26 #include "ShadowData.h"
33 class RenderLineBoxList;
34 class VerticalPositionCache;
36 typedef HashMap<const InlineTextBox*, pair<Vector<const SimpleFontData*>, GlyphOverflow> > GlyphOverflowAndFallbackFontsMap;
38 class InlineFlowBox : public InlineBox {
40 InlineFlowBox(RenderObject* obj)
46 , m_includeLogicalLeftEdge(false)
47 , m_includeLogicalRightEdge(false)
48 , m_descendantsHaveSameLineHeightAndBaseline(true)
50 , m_hasBadChildList(false)
53 // Internet Explorer and Firefox always create a marker for list items, even when the list-style-type is none. We do not make a marker
54 // in the list-style-type: none case, since it is wasteful to do so. However, in order to match other browsers we have to pretend like
55 // an invisible marker exists. The side effect of having an invisible marker is that the quirks mode behavior of shrinking lines with no
56 // text children must not apply. This change also means that gaps will exist between image bullet list items. Even when the list bullet
57 // is an image, the line is still considered to be immune from the quirk.
58 m_hasTextChildren = obj->style()->display() == LIST_ITEM;
59 m_hasTextDescendants = m_hasTextChildren;
63 virtual ~InlineFlowBox();
65 virtual void showLineTreeAndMark(const InlineBox* = 0, const char* = 0, const InlineBox* = 0, const char* = 0, const RenderObject* = 0, int = 0) const;
66 virtual const char* boxName() const;
69 InlineFlowBox* prevLineBox() const { return m_prevLineBox; }
70 InlineFlowBox* nextLineBox() const { return m_nextLineBox; }
71 void setNextLineBox(InlineFlowBox* n) { m_nextLineBox = n; }
72 void setPreviousLineBox(InlineFlowBox* p) { m_prevLineBox = p; }
74 InlineBox* firstChild() const { checkConsistency(); return m_firstChild; }
75 InlineBox* lastChild() const { checkConsistency(); return m_lastChild; }
77 virtual bool isLeaf() const { return false; }
79 InlineBox* firstLeafChild() const;
80 InlineBox* lastLeafChild() const;
82 typedef void (*CustomInlineBoxRangeReverse)(void* userData, Vector<InlineBox*>::iterator first, Vector<InlineBox*>::iterator last);
83 void collectLeafBoxesInLogicalOrder(Vector<InlineBox*>&, CustomInlineBoxRangeReverse customReverseImplementation = 0, void* userData = 0) const;
85 virtual void setConstructed()
87 InlineBox::setConstructed();
88 for (InlineBox* child = firstChild(); child; child = child->next())
89 child->setConstructed();
92 void addToLine(InlineBox* child);
93 virtual void deleteLine(RenderArena*);
94 virtual void extractLine();
95 virtual void attachLine();
96 virtual void adjustPosition(float dx, float dy);
98 virtual void extractLineBoxFromRenderObject();
99 virtual void attachLineBoxToRenderObject();
100 virtual void removeLineBoxFromRenderObject();
102 virtual void clearTruncation();
104 IntRect roundedFrameRect() const;
106 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
107 virtual void paintMask(PaintInfo&, const LayoutPoint&);
108 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, CompositeOperator = CompositeSourceOver);
109 void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, CompositeOperator = CompositeSourceOver);
110 void paintBoxShadow(const PaintInfo&, RenderStyle*, ShadowStyle, const LayoutRect&);
111 virtual void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom);
112 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom);
114 virtual RenderLineBoxList* rendererLineBoxes() const;
116 // logicalLeft = left in a horizontal line and top in a vertical line.
117 int marginBorderPaddingLogicalLeft() const { return marginLogicalLeft() + borderLogicalLeft() + paddingLogicalLeft(); }
118 int marginBorderPaddingLogicalRight() const { return marginLogicalRight() + borderLogicalRight() + paddingLogicalRight(); }
119 LayoutUnit marginLogicalLeft() const
121 if (!includeLogicalLeftEdge())
123 return isHorizontal() ? boxModelObject()->marginLeft() : boxModelObject()->marginTop();
125 LayoutUnit marginLogicalRight() const
127 if (!includeLogicalRightEdge())
129 return isHorizontal() ? boxModelObject()->marginRight() : boxModelObject()->marginBottom();
131 int borderLogicalLeft() const
133 if (!includeLogicalLeftEdge())
135 return isHorizontal() ? renderer()->style()->borderLeftWidth() : renderer()->style()->borderTopWidth();
137 int borderLogicalRight() const
139 if (!includeLogicalRightEdge())
141 return isHorizontal() ? renderer()->style()->borderRightWidth() : renderer()->style()->borderBottomWidth();
143 int paddingLogicalLeft() const
145 if (!includeLogicalLeftEdge())
147 return isHorizontal() ? boxModelObject()->paddingLeft() : boxModelObject()->paddingTop();
149 int paddingLogicalRight() const
151 if (!includeLogicalRightEdge())
153 return isHorizontal() ? boxModelObject()->paddingRight() : boxModelObject()->paddingBottom();
156 bool includeLogicalLeftEdge() const { return m_includeLogicalLeftEdge; }
157 bool includeLogicalRightEdge() const { return m_includeLogicalRightEdge; }
158 void setEdges(bool includeLeft, bool includeRight)
160 m_includeLogicalLeftEdge = includeLeft;
161 m_includeLogicalRightEdge = includeRight;
164 // Helper functions used during line construction and placement.
165 void determineSpacingForFlowBoxes(bool lastLine, bool isLogicallyLastRunWrapped, RenderObject* logicallyLastRunRenderer);
166 int getFlowSpacingLogicalWidth();
167 float placeBoxesInInlineDirection(float logicalLeft, bool& needsWordSpacing, GlyphOverflowAndFallbackFontsMap&);
168 void computeLogicalBoxHeights(RootInlineBox*, LayoutUnit& maxPositionTop, LayoutUnit& maxPositionBottom,
169 LayoutUnit& maxAscent, LayoutUnit& maxDescent, bool& setMaxAscent, bool& setMaxDescent,
170 bool strictMode, GlyphOverflowAndFallbackFontsMap&, FontBaseline, VerticalPositionCache&);
171 void adjustMaxAscentAndDescent(LayoutUnit& maxAscent, LayoutUnit& maxDescent,
172 LayoutUnit maxPositionTop, LayoutUnit maxPositionBottom);
173 void placeBoxesInBlockDirection(LayoutUnit logicalTop, LayoutUnit maxHeight, LayoutUnit maxAscent, bool strictMode, LayoutUnit& lineTop, LayoutUnit& lineBottom, bool& setLineTop,
174 LayoutUnit& lineTopIncludingMargins, LayoutUnit& lineBottomIncludingMargins, bool& hasAnnotationsBefore, bool& hasAnnotationsAfter, FontBaseline);
175 void flipLinesInBlockDirection(LayoutUnit lineTop, LayoutUnit lineBottom);
176 bool requiresIdeographicBaseline(const GlyphOverflowAndFallbackFontsMap&) const;
178 LayoutUnit computeOverAnnotationAdjustment(LayoutUnit allowedPosition) const;
179 LayoutUnit computeUnderAnnotationAdjustment(LayoutUnit allowedPosition) const;
181 void computeOverflow(LayoutUnit lineTop, LayoutUnit lineBottom, GlyphOverflowAndFallbackFontsMap&);
183 void removeChild(InlineBox* child);
185 virtual RenderObject::SelectionState selectionState();
187 virtual bool canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth);
188 virtual float placeEllipsisBox(bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, bool&);
190 bool hasTextChildren() const { return m_hasTextChildren; }
191 bool hasTextDescendants() const { return m_hasTextDescendants; }
193 void checkConsistency() const;
194 void setHasBadChildList();
196 // Line visual and layout overflow are in the coordinate space of the block. This means that they aren't purely physical directions.
197 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
198 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr, but it is on the right in vertical-rl.
199 LayoutRect layoutOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
201 return m_overflow ? m_overflow->layoutOverflowRect() : enclosingLayoutRect(frameRectIncludingLineHeight(lineTop, lineBottom));
203 LayoutUnit logicalLeftLayoutOverflow() const { return m_overflow ? (isHorizontal() ? m_overflow->minXLayoutOverflow() : m_overflow->minYLayoutOverflow()) : logicalLeft(); }
204 LayoutUnit logicalRightLayoutOverflow() const { return m_overflow ? (isHorizontal() ? m_overflow->maxXLayoutOverflow() : m_overflow->maxYLayoutOverflow()) : ceilf(logicalRight()); }
205 LayoutUnit logicalTopLayoutOverflow(LayoutUnit lineTop) const
208 return isHorizontal() ? m_overflow->minYLayoutOverflow() : m_overflow->minXLayoutOverflow();
211 LayoutUnit logicalBottomLayoutOverflow(LayoutUnit lineBottom) const
214 return isHorizontal() ? m_overflow->maxYLayoutOverflow() : m_overflow->maxXLayoutOverflow();
217 LayoutRect logicalLayoutOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
219 LayoutRect result = layoutOverflowRect(lineTop, lineBottom);
220 if (!renderer()->isHorizontalWritingMode())
221 result = result.transposedRect();
225 LayoutRect visualOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
227 return m_overflow ? m_overflow->visualOverflowRect() : enclosingLayoutRect(frameRectIncludingLineHeight(lineTop, lineBottom));
229 LayoutUnit logicalLeftVisualOverflow() const { return m_overflow ? (isHorizontal() ? m_overflow->minXVisualOverflow() : m_overflow->minYVisualOverflow()) : logicalLeft(); }
230 LayoutUnit logicalRightVisualOverflow() const { return m_overflow ? (isHorizontal() ? m_overflow->maxXVisualOverflow() : m_overflow->maxYVisualOverflow()) : ceilf(logicalRight()); }
231 LayoutUnit logicalTopVisualOverflow(LayoutUnit lineTop) const
234 return isHorizontal() ? m_overflow->minYVisualOverflow() : m_overflow->minXVisualOverflow();
237 LayoutUnit logicalBottomVisualOverflow(LayoutUnit lineBottom) const
240 return isHorizontal() ? m_overflow->maxYVisualOverflow() : m_overflow->maxXVisualOverflow();
243 LayoutRect logicalVisualOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
245 LayoutRect result = visualOverflowRect(lineTop, lineBottom);
246 if (!renderer()->isHorizontalWritingMode())
247 result = result.transposedRect();
251 void setOverflowFromLogicalRects(const LayoutRect& logicalLayoutOverflow, const LayoutRect& logicalVisualOverflow, LayoutUnit lineTop, LayoutUnit lineBottom);
252 void setLayoutOverflow(const LayoutRect&, LayoutUnit lineTop, LayoutUnit lineBottom);
253 void setVisualOverflow(const LayoutRect&, LayoutUnit lineTop, LayoutUnit lineBottom);
255 FloatRect frameRectIncludingLineHeight(LayoutUnit lineTop, LayoutUnit lineBottom) const
258 return FloatRect(m_topLeft.x(), lineTop, width(), lineBottom - lineTop);
259 return FloatRect(lineTop, m_topLeft.y(), lineBottom - lineTop, height());
262 FloatRect logicalFrameRectIncludingLineHeight(LayoutUnit lineTop, LayoutUnit lineBottom) const
264 return FloatRect(logicalLeft(), lineTop, logicalWidth(), lineBottom - lineTop);
267 bool descendantsHaveSameLineHeightAndBaseline() const { return m_descendantsHaveSameLineHeightAndBaseline; }
268 void clearDescendantsHaveSameLineHeightAndBaseline()
270 m_descendantsHaveSameLineHeightAndBaseline = false;
271 if (parent() && parent()->descendantsHaveSameLineHeightAndBaseline())
272 parent()->clearDescendantsHaveSameLineHeightAndBaseline();
276 void addBoxShadowVisualOverflow(LayoutRect& logicalVisualOverflow);
277 void addBorderOutsetVisualOverflow(LayoutRect& logicalVisualOverflow);
278 void addTextBoxVisualOverflow(InlineTextBox*, GlyphOverflowAndFallbackFontsMap&, LayoutRect& logicalVisualOverflow);
279 void addReplacedChildOverflow(const InlineBox*, LayoutRect& logicalLayoutOverflow, LayoutRect& logicalVisualOverflow);
280 void constrainToLineTopAndBottomIfNeeded(LayoutRect&) const;
283 OwnPtr<RenderOverflow> m_overflow;
285 virtual bool isInlineFlowBox() const { return true; }
287 InlineBox* m_firstChild;
288 InlineBox* m_lastChild;
290 InlineFlowBox* m_prevLineBox; // The previous box that also uses our RenderObject
291 InlineFlowBox* m_nextLineBox; // The next box that also uses our RenderObject
293 bool m_includeLogicalLeftEdge : 1;
294 bool m_includeLogicalRightEdge : 1;
295 bool m_hasTextChildren : 1;
296 bool m_hasTextDescendants : 1;
297 bool m_descendantsHaveSameLineHeightAndBaseline : 1;
300 bool m_hasBadChildList;
304 inline InlineFlowBox* toInlineFlowBox(InlineBox* object)
306 ASSERT(!object || object->isInlineFlowBox());
307 return static_cast<InlineFlowBox*>(object);
310 inline const InlineFlowBox* toInlineFlowBox(const InlineBox* object)
312 ASSERT(!object || object->isInlineFlowBox());
313 return static_cast<const InlineFlowBox*>(object);
316 // This will catch anyone doing an unnecessary cast.
317 void toInlineFlowBox(const InlineFlowBox*);
320 inline void InlineFlowBox::checkConsistency() const
325 inline void InlineFlowBox::setHasBadChildList()
328 m_hasBadChildList = true;
332 } // namespace WebCore
335 // Outside the WebCore namespace for ease of invocation from gdb.
336 void showTree(const WebCore::InlineFlowBox*);
339 #endif // InlineFlowBox_h