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 "core/rendering/InlineBox.h"
25 #include "core/rendering/RenderOverflow.h"
26 #include "core/rendering/style/ShadowData.h"
33 class RenderLineBoxList;
35 class VerticalPositionCache;
39 typedef HashMap<const InlineTextBox*, pair<Vector<const SimpleFontData*>, GlyphOverflow> > GlyphOverflowAndFallbackFontsMap;
41 class InlineFlowBox : public InlineBox {
43 InlineFlowBox(RenderObject& obj)
49 , m_includeLogicalLeftEdge(false)
50 , m_includeLogicalRightEdge(false)
51 , m_descendantsHaveSameLineHeightAndBaseline(true)
52 , m_baselineType(AlphabeticBaseline)
53 , m_hasAnnotationsBefore(false)
54 , m_hasAnnotationsAfter(false)
55 , m_lineBreakBidiStatusEor(WTF::Unicode::LeftToRight)
56 , m_lineBreakBidiStatusLastStrong(WTF::Unicode::LeftToRight)
57 , m_lineBreakBidiStatusLast(WTF::Unicode::LeftToRight)
59 , m_hasBadChildList(false)
62 // 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
63 // 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
64 // an invisible marker exists. The side effect of having an invisible marker is that the quirks mode behavior of shrinking lines with no
65 // text children must not apply. This change also means that gaps will exist between image bullet list items. Even when the list bullet
66 // is an image, the line is still considered to be immune from the quirk.
67 m_hasTextChildren = obj.style()->display() == LIST_ITEM;
68 m_hasTextDescendants = m_hasTextChildren;
72 virtual ~InlineFlowBox();
74 virtual void showLineTreeAndMark(const InlineBox* = 0, const char* = 0, const InlineBox* = 0, const char* = 0, const RenderObject* = 0, int = 0) const OVERRIDE;
75 virtual const char* boxName() const OVERRIDE;
78 InlineFlowBox* prevLineBox() const { return m_prevLineBox; }
79 InlineFlowBox* nextLineBox() const { return m_nextLineBox; }
80 void setNextLineBox(InlineFlowBox* n) { m_nextLineBox = n; }
81 void setPreviousLineBox(InlineFlowBox* p) { m_prevLineBox = p; }
83 InlineBox* firstChild() const { checkConsistency(); return m_firstChild; }
84 InlineBox* lastChild() const { checkConsistency(); return m_lastChild; }
86 virtual bool isLeaf() const OVERRIDE FINAL { return false; }
88 InlineBox* firstLeafChild() const;
89 InlineBox* lastLeafChild() const;
91 typedef void (*CustomInlineBoxRangeReverse)(void* userData, Vector<InlineBox*>::iterator first, Vector<InlineBox*>::iterator last);
92 void collectLeafBoxesInLogicalOrder(Vector<InlineBox*>&, CustomInlineBoxRangeReverse customReverseImplementation = 0, void* userData = 0) const;
94 virtual void setConstructed() OVERRIDE FINAL
96 InlineBox::setConstructed();
97 for (InlineBox* child = firstChild(); child; child = child->nextOnLine())
98 child->setConstructed();
101 void addToLine(InlineBox* child);
102 virtual void deleteLine() OVERRIDE FINAL;
103 virtual void extractLine() OVERRIDE FINAL;
104 virtual void attachLine() OVERRIDE FINAL;
105 virtual void adjustPosition(float dx, float dy) OVERRIDE;
107 virtual void extractLineBoxFromRenderObject();
108 virtual void attachLineBoxToRenderObject();
109 virtual void removeLineBoxFromRenderObject();
111 virtual void clearTruncation() OVERRIDE;
113 IntRect roundedFrameRect() const;
115 void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
116 void paintMask(PaintInfo&, const LayoutPoint&);
117 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, CompositeOperator = CompositeSourceOver);
118 void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, CompositeOperator = CompositeSourceOver);
119 void paintBoxShadow(const PaintInfo&, RenderStyle*, ShadowStyle, const LayoutRect&);
120 virtual void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) OVERRIDE;
121 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom) OVERRIDE;
123 bool boxShadowCanBeAppliedToBackground(const FillLayer&) const;
125 virtual RenderLineBoxList* rendererLineBoxes() const;
127 // logicalLeft = left in a horizontal line and top in a vertical line.
128 LayoutUnit marginBorderPaddingLogicalLeft() const { return marginLogicalLeft() + borderLogicalLeft() + paddingLogicalLeft(); }
129 LayoutUnit marginBorderPaddingLogicalRight() const { return marginLogicalRight() + borderLogicalRight() + paddingLogicalRight(); }
130 LayoutUnit marginLogicalLeft() const
132 if (!includeLogicalLeftEdge())
134 return isHorizontal() ? boxModelObject()->marginLeft() : boxModelObject()->marginTop();
136 LayoutUnit marginLogicalRight() const
138 if (!includeLogicalRightEdge())
140 return isHorizontal() ? boxModelObject()->marginRight() : boxModelObject()->marginBottom();
142 int borderLogicalLeft() const
144 if (!includeLogicalLeftEdge())
146 return isHorizontal() ? renderer().style(isFirstLineStyle())->borderLeftWidth() : renderer().style(isFirstLineStyle())->borderTopWidth();
148 int borderLogicalRight() const
150 if (!includeLogicalRightEdge())
152 return isHorizontal() ? renderer().style(isFirstLineStyle())->borderRightWidth() : renderer().style(isFirstLineStyle())->borderBottomWidth();
154 int paddingLogicalLeft() const
156 if (!includeLogicalLeftEdge())
158 return isHorizontal() ? boxModelObject()->paddingLeft() : boxModelObject()->paddingTop();
160 int paddingLogicalRight() const
162 if (!includeLogicalRightEdge())
164 return isHorizontal() ? boxModelObject()->paddingRight() : boxModelObject()->paddingBottom();
167 bool includeLogicalLeftEdge() const { return m_includeLogicalLeftEdge; }
168 bool includeLogicalRightEdge() const { return m_includeLogicalRightEdge; }
169 void setEdges(bool includeLeft, bool includeRight)
171 m_includeLogicalLeftEdge = includeLeft;
172 m_includeLogicalRightEdge = includeRight;
175 // Helper functions used during line construction and placement.
176 void determineSpacingForFlowBoxes(bool lastLine, bool isLogicallyLastRunWrapped, RenderObject* logicallyLastRunRenderer);
177 LayoutUnit getFlowSpacingLogicalWidth();
178 float placeBoxesInInlineDirection(float logicalLeft, bool& needsWordSpacing, GlyphOverflowAndFallbackFontsMap&);
179 float placeBoxRangeInInlineDirection(InlineBox* firstChild, InlineBox* lastChild, float& logicalLeft, float& minLogicalLeft, float& maxLogicalRight, bool& needsWordSpacing, GlyphOverflowAndFallbackFontsMap&);
180 void beginPlacingBoxRangesInInlineDirection(float logicalLeft) { setLogicalLeft(logicalLeft); }
181 void endPlacingBoxRangesInInlineDirection(float logicalLeft, float logicalRight, float minLogicalLeft, float maxLogicalRight)
183 setLogicalWidth(logicalRight - logicalLeft);
184 if (knownToHaveNoOverflow() && (minLogicalLeft < logicalLeft || maxLogicalRight > logicalRight))
185 clearKnownToHaveNoOverflow();
188 void computeLogicalBoxHeights(RootInlineBox*, LayoutUnit& maxPositionTop, LayoutUnit& maxPositionBottom,
189 int& maxAscent, int& maxDescent, bool& setMaxAscent, bool& setMaxDescent,
190 bool strictMode, GlyphOverflowAndFallbackFontsMap&, FontBaseline, VerticalPositionCache&);
191 void adjustMaxAscentAndDescent(int& maxAscent, int& maxDescent,
192 int maxPositionTop, int maxPositionBottom);
193 void placeBoxesInBlockDirection(LayoutUnit logicalTop, LayoutUnit maxHeight, int maxAscent, bool strictMode, LayoutUnit& lineTop, LayoutUnit& lineBottom, bool& setLineTop,
194 LayoutUnit& lineTopIncludingMargins, LayoutUnit& lineBottomIncludingMargins, bool& hasAnnotationsBefore, bool& hasAnnotationsAfter, FontBaseline);
195 void flipLinesInBlockDirection(LayoutUnit lineTop, LayoutUnit lineBottom);
196 bool requiresIdeographicBaseline(const GlyphOverflowAndFallbackFontsMap&) const;
198 LayoutUnit computeOverAnnotationAdjustment(LayoutUnit allowedPosition) const;
199 LayoutUnit computeUnderAnnotationAdjustment(LayoutUnit allowedPosition) const;
201 void computeOverflow(LayoutUnit lineTop, LayoutUnit lineBottom, GlyphOverflowAndFallbackFontsMap&);
203 void removeChild(InlineBox* child, MarkLineBoxes);
205 virtual RenderObject::SelectionState selectionState() OVERRIDE;
207 virtual bool canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth) const OVERRIDE FINAL;
208 virtual float placeEllipsisBox(bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, float &truncatedWidth, bool&) OVERRIDE;
210 bool hasTextChildren() const { return m_hasTextChildren; }
211 bool hasTextDescendants() const { return m_hasTextDescendants; }
212 void setHasTextChildren() { m_hasTextChildren = true; setHasTextDescendants(); }
213 void setHasTextDescendants() { m_hasTextDescendants = true; }
215 void checkConsistency() const;
216 void setHasBadChildList();
218 // Line visual and layout overflow are in the coordinate space of the block. This means that they aren't purely physical directions.
219 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
220 // 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.
221 LayoutRect layoutOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
223 return m_overflow ? m_overflow->layoutOverflowRect() : enclosingLayoutRect(frameRectIncludingLineHeight(lineTop, lineBottom));
225 LayoutUnit logicalLeftLayoutOverflow() const
227 return m_overflow ? (isHorizontal() ? m_overflow->layoutOverflowRect().x() : m_overflow->layoutOverflowRect().y()) :
228 static_cast<LayoutUnit>(logicalLeft());
230 LayoutUnit logicalRightLayoutOverflow() const
232 return m_overflow ? (isHorizontal() ? m_overflow->layoutOverflowRect().maxX() : m_overflow->layoutOverflowRect().maxY()) :
233 static_cast<LayoutUnit>(ceilf(logicalRight()));
235 LayoutUnit logicalTopLayoutOverflow(LayoutUnit lineTop) const
238 return isHorizontal() ? m_overflow->layoutOverflowRect().y() : m_overflow->layoutOverflowRect().x();
241 LayoutUnit logicalBottomLayoutOverflow(LayoutUnit lineBottom) const
244 return isHorizontal() ? m_overflow->layoutOverflowRect().maxY() : m_overflow->layoutOverflowRect().maxX();
247 LayoutRect logicalLayoutOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
249 LayoutRect result = layoutOverflowRect(lineTop, lineBottom);
250 if (!renderer().isHorizontalWritingMode())
251 result = result.transposedRect();
255 LayoutRect visualOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
257 return m_overflow ? m_overflow->visualOverflowRect() : enclosingLayoutRect(frameRectIncludingLineHeight(lineTop, lineBottom));
259 LayoutUnit logicalLeftVisualOverflow() const { return m_overflow ? (isHorizontal() ? m_overflow->visualOverflowRect().x() : m_overflow->visualOverflowRect().y()) : static_cast<LayoutUnit>(logicalLeft()); }
260 LayoutUnit logicalRightVisualOverflow() const { return m_overflow ? (isHorizontal() ? m_overflow->visualOverflowRect().maxX() : m_overflow->visualOverflowRect().maxY()) : static_cast<LayoutUnit>(ceilf(logicalRight())); }
261 LayoutUnit logicalTopVisualOverflow(LayoutUnit lineTop) const
264 return isHorizontal() ? m_overflow->visualOverflowRect().y() : m_overflow->visualOverflowRect().x();
267 LayoutUnit logicalBottomVisualOverflow(LayoutUnit lineBottom) const
270 return isHorizontal() ? m_overflow->visualOverflowRect().maxY() : m_overflow->visualOverflowRect().maxX();
273 LayoutRect logicalVisualOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
275 LayoutRect result = visualOverflowRect(lineTop, lineBottom);
276 if (!renderer().isHorizontalWritingMode())
277 result = result.transposedRect();
281 void setOverflowFromLogicalRects(const LayoutRect& logicalLayoutOverflow, const LayoutRect& logicalVisualOverflow, LayoutUnit lineTop, LayoutUnit lineBottom);
283 FloatRect frameRectIncludingLineHeight(LayoutUnit lineTop, LayoutUnit lineBottom) const
286 return FloatRect(m_topLeft.x(), lineTop.toFloat(), width(), (lineBottom - lineTop).toFloat());
287 return FloatRect(lineTop.toFloat(), m_topLeft.y(), (lineBottom - lineTop).toFloat(), height());
290 FloatRect logicalFrameRectIncludingLineHeight(LayoutUnit lineTop, LayoutUnit lineBottom) const
292 return FloatRect(logicalLeft(), lineTop.toFloat(), logicalWidth(), (lineBottom - lineTop).toFloat());
295 bool descendantsHaveSameLineHeightAndBaseline() const { return m_descendantsHaveSameLineHeightAndBaseline; }
296 void clearDescendantsHaveSameLineHeightAndBaseline()
298 m_descendantsHaveSameLineHeightAndBaseline = false;
299 if (parent() && parent()->descendantsHaveSameLineHeightAndBaseline())
300 parent()->clearDescendantsHaveSameLineHeightAndBaseline();
304 void addBoxShadowVisualOverflow(LayoutRect& logicalVisualOverflow);
305 void addBorderOutsetVisualOverflow(LayoutRect& logicalVisualOverflow);
306 void addOutlineVisualOverflow(LayoutRect& logicalVisualOverflow);
307 void addTextBoxVisualOverflow(InlineTextBox*, GlyphOverflowAndFallbackFontsMap&, LayoutRect& logicalVisualOverflow);
308 void addReplacedChildOverflow(const InlineBox*, LayoutRect& logicalLayoutOverflow, LayoutRect& logicalVisualOverflow);
309 void constrainToLineTopAndBottomIfNeeded(LayoutRect&) const;
311 void setLayoutOverflow(const LayoutRect&, const LayoutRect&);
312 void setVisualOverflow(const LayoutRect&, const LayoutRect&);
315 OwnPtr<RenderOverflow> m_overflow;
317 virtual bool isInlineFlowBox() const OVERRIDE FINAL { return true; }
319 InlineBox* m_firstChild;
320 InlineBox* m_lastChild;
322 InlineFlowBox* m_prevLineBox; // The previous box that also uses our RenderObject
323 InlineFlowBox* m_nextLineBox; // The next box that also uses our RenderObject
325 // Maximum logicalTop among all children of an InlineFlowBox. Used to
326 // calculate the offset for TextUnderlinePositionUnder.
327 void computeMaxLogicalTop(float& maxLogicalTop) const;
330 unsigned m_includeLogicalLeftEdge : 1;
331 unsigned m_includeLogicalRightEdge : 1;
332 unsigned m_hasTextChildren : 1;
333 unsigned m_hasTextDescendants : 1;
334 unsigned m_descendantsHaveSameLineHeightAndBaseline : 1;
337 // The following members are only used by RootInlineBox but moved here to keep the bits packed.
339 // Whether or not this line uses alphabetic or ideographic baselines by default.
340 unsigned m_baselineType : 1; // FontBaseline
342 // If the line contains any ruby runs, then this will be true.
343 unsigned m_hasAnnotationsBefore : 1;
344 unsigned m_hasAnnotationsAfter : 1;
346 unsigned m_lineBreakBidiStatusEor : 5; // WTF::Unicode::Direction
347 unsigned m_lineBreakBidiStatusLastStrong : 5; // WTF::Unicode::Direction
348 unsigned m_lineBreakBidiStatusLast : 5; // WTF::Unicode::Direction
350 // End of RootInlineBox-specific members.
354 unsigned m_hasBadChildList : 1;
358 DEFINE_INLINE_BOX_TYPE_CASTS(InlineFlowBox);
361 inline void InlineFlowBox::checkConsistency() const
366 inline void InlineFlowBox::setHasBadChildList()
369 m_hasBadChildList = true;
373 } // namespace WebCore
376 // Outside the WebCore namespace for ease of invocation from gdb.
377 void showTree(const WebCore::InlineFlowBox*);
380 #endif // InlineFlowBox_h