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)
56 , m_hasBadChildList(false)
59 // 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
60 // 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
61 // an invisible marker exists. The side effect of having an invisible marker is that the quirks mode behavior of shrinking lines with no
62 // text children must not apply. This change also means that gaps will exist between image bullet list items. Even when the list bullet
63 // is an image, the line is still considered to be immune from the quirk.
64 m_hasTextChildren = obj.style()->display() == LIST_ITEM;
65 m_hasTextDescendants = m_hasTextChildren;
69 virtual ~InlineFlowBox();
71 virtual void showLineTreeAndMark(const InlineBox* = 0, const char* = 0, const InlineBox* = 0, const char* = 0, const RenderObject* = 0, int = 0) const OVERRIDE;
72 virtual const char* boxName() const OVERRIDE;
75 InlineFlowBox* prevLineBox() const { return m_prevLineBox; }
76 InlineFlowBox* nextLineBox() const { return m_nextLineBox; }
77 void setNextLineBox(InlineFlowBox* n) { m_nextLineBox = n; }
78 void setPreviousLineBox(InlineFlowBox* p) { m_prevLineBox = p; }
80 InlineBox* firstChild() const { checkConsistency(); return m_firstChild; }
81 InlineBox* lastChild() const { checkConsistency(); return m_lastChild; }
83 virtual bool isLeaf() const OVERRIDE FINAL { return false; }
85 InlineBox* firstLeafChild() const;
86 InlineBox* lastLeafChild() const;
88 typedef void (*CustomInlineBoxRangeReverse)(void* userData, Vector<InlineBox*>::iterator first, Vector<InlineBox*>::iterator last);
89 void collectLeafBoxesInLogicalOrder(Vector<InlineBox*>&, CustomInlineBoxRangeReverse customReverseImplementation = 0, void* userData = 0) const;
91 virtual void setConstructed() OVERRIDE FINAL
93 InlineBox::setConstructed();
94 for (InlineBox* child = firstChild(); child; child = child->nextOnLine())
95 child->setConstructed();
98 void addToLine(InlineBox* child);
99 virtual void deleteLine() OVERRIDE FINAL;
100 virtual void extractLine() OVERRIDE FINAL;
101 virtual void attachLine() OVERRIDE FINAL;
102 virtual void adjustPosition(float dx, float dy) OVERRIDE;
104 virtual void extractLineBoxFromRenderObject();
105 virtual void attachLineBoxToRenderObject();
106 virtual void removeLineBoxFromRenderObject();
108 virtual void clearTruncation() OVERRIDE;
110 IntRect roundedFrameRect() const;
112 void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
113 void paintMask(PaintInfo&, const LayoutPoint&);
114 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, CompositeOperator = CompositeSourceOver);
115 void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, CompositeOperator = CompositeSourceOver);
116 void paintBoxShadow(const PaintInfo&, RenderStyle*, ShadowStyle, const LayoutRect&);
117 virtual void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) OVERRIDE;
118 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom) OVERRIDE;
120 bool boxShadowCanBeAppliedToBackground(const FillLayer&) const;
122 virtual RenderLineBoxList* rendererLineBoxes() const;
124 // logicalLeft = left in a horizontal line and top in a vertical line.
125 LayoutUnit marginBorderPaddingLogicalLeft() const { return marginLogicalLeft() + borderLogicalLeft() + paddingLogicalLeft(); }
126 LayoutUnit marginBorderPaddingLogicalRight() const { return marginLogicalRight() + borderLogicalRight() + paddingLogicalRight(); }
127 LayoutUnit marginLogicalLeft() const
129 if (!includeLogicalLeftEdge())
131 return isHorizontal() ? boxModelObject()->marginLeft() : boxModelObject()->marginTop();
133 LayoutUnit marginLogicalRight() const
135 if (!includeLogicalRightEdge())
137 return isHorizontal() ? boxModelObject()->marginRight() : boxModelObject()->marginBottom();
139 int borderLogicalLeft() const
141 if (!includeLogicalLeftEdge())
143 return isHorizontal() ? renderer().style(isFirstLineStyle())->borderLeftWidth() : renderer().style(isFirstLineStyle())->borderTopWidth();
145 int borderLogicalRight() const
147 if (!includeLogicalRightEdge())
149 return isHorizontal() ? renderer().style(isFirstLineStyle())->borderRightWidth() : renderer().style(isFirstLineStyle())->borderBottomWidth();
151 int paddingLogicalLeft() const
153 if (!includeLogicalLeftEdge())
155 return isHorizontal() ? boxModelObject()->paddingLeft() : boxModelObject()->paddingTop();
157 int paddingLogicalRight() const
159 if (!includeLogicalRightEdge())
161 return isHorizontal() ? boxModelObject()->paddingRight() : boxModelObject()->paddingBottom();
164 bool includeLogicalLeftEdge() const { return m_includeLogicalLeftEdge; }
165 bool includeLogicalRightEdge() const { return m_includeLogicalRightEdge; }
166 void setEdges(bool includeLeft, bool includeRight)
168 m_includeLogicalLeftEdge = includeLeft;
169 m_includeLogicalRightEdge = includeRight;
172 // Helper functions used during line construction and placement.
173 void determineSpacingForFlowBoxes(bool lastLine, bool isLogicallyLastRunWrapped, RenderObject* logicallyLastRunRenderer);
174 LayoutUnit getFlowSpacingLogicalWidth();
175 float placeBoxesInInlineDirection(float logicalLeft, bool& needsWordSpacing, GlyphOverflowAndFallbackFontsMap&);
176 float placeBoxRangeInInlineDirection(InlineBox* firstChild, InlineBox* lastChild, float& logicalLeft, float& minLogicalLeft, float& maxLogicalRight, bool& needsWordSpacing, GlyphOverflowAndFallbackFontsMap&);
177 void beginPlacingBoxRangesInInlineDirection(float logicalLeft) { setLogicalLeft(logicalLeft); }
178 void endPlacingBoxRangesInInlineDirection(float logicalLeft, float logicalRight, float minLogicalLeft, float maxLogicalRight)
180 setLogicalWidth(logicalRight - logicalLeft);
181 if (knownToHaveNoOverflow() && (minLogicalLeft < logicalLeft || maxLogicalRight > logicalRight))
182 clearKnownToHaveNoOverflow();
185 void computeLogicalBoxHeights(RootInlineBox*, LayoutUnit& maxPositionTop, LayoutUnit& maxPositionBottom,
186 int& maxAscent, int& maxDescent, bool& setMaxAscent, bool& setMaxDescent,
187 bool strictMode, GlyphOverflowAndFallbackFontsMap&, FontBaseline, VerticalPositionCache&);
188 void adjustMaxAscentAndDescent(int& maxAscent, int& maxDescent,
189 int maxPositionTop, int maxPositionBottom);
190 void placeBoxesInBlockDirection(LayoutUnit logicalTop, LayoutUnit maxHeight, int maxAscent, bool strictMode, LayoutUnit& lineTop, LayoutUnit& lineBottom, bool& setLineTop,
191 LayoutUnit& lineTopIncludingMargins, LayoutUnit& lineBottomIncludingMargins, bool& hasAnnotationsBefore, bool& hasAnnotationsAfter, FontBaseline);
192 void flipLinesInBlockDirection(LayoutUnit lineTop, LayoutUnit lineBottom);
193 bool requiresIdeographicBaseline(const GlyphOverflowAndFallbackFontsMap&) const;
195 LayoutUnit computeOverAnnotationAdjustment(LayoutUnit allowedPosition) const;
196 LayoutUnit computeUnderAnnotationAdjustment(LayoutUnit allowedPosition) const;
198 void computeOverflow(LayoutUnit lineTop, LayoutUnit lineBottom, GlyphOverflowAndFallbackFontsMap&);
200 void removeChild(InlineBox* child);
202 virtual RenderObject::SelectionState selectionState() OVERRIDE;
204 virtual bool canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth) const OVERRIDE FINAL;
205 virtual float placeEllipsisBox(bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, float &truncatedWidth, bool&) OVERRIDE;
207 bool hasTextChildren() const { return m_hasTextChildren; }
208 bool hasTextDescendants() const { return m_hasTextDescendants; }
209 void setHasTextChildren() { m_hasTextChildren = true; setHasTextDescendants(); }
210 void setHasTextDescendants() { m_hasTextDescendants = true; }
212 void checkConsistency() const;
213 void setHasBadChildList();
215 // Line visual and layout overflow are in the coordinate space of the block. This means that they aren't purely physical directions.
216 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
217 // 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.
218 LayoutRect layoutOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
220 return m_overflow ? m_overflow->layoutOverflowRect() : enclosingLayoutRect(frameRectIncludingLineHeight(lineTop, lineBottom));
222 LayoutUnit logicalLeftLayoutOverflow() const
224 return m_overflow ? (isHorizontal() ? m_overflow->layoutOverflowRect().x() : m_overflow->layoutOverflowRect().y()) :
225 static_cast<LayoutUnit>(logicalLeft());
227 LayoutUnit logicalRightLayoutOverflow() const
229 return m_overflow ? (isHorizontal() ? m_overflow->layoutOverflowRect().maxX() : m_overflow->layoutOverflowRect().maxY()) :
230 static_cast<LayoutUnit>(ceilf(logicalRight()));
232 LayoutUnit logicalTopLayoutOverflow(LayoutUnit lineTop) const
235 return isHorizontal() ? m_overflow->layoutOverflowRect().y() : m_overflow->layoutOverflowRect().x();
238 LayoutUnit logicalBottomLayoutOverflow(LayoutUnit lineBottom) const
241 return isHorizontal() ? m_overflow->layoutOverflowRect().maxY() : m_overflow->layoutOverflowRect().maxX();
244 LayoutRect logicalLayoutOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
246 LayoutRect result = layoutOverflowRect(lineTop, lineBottom);
247 if (!renderer().isHorizontalWritingMode())
248 result = result.transposedRect();
252 LayoutRect visualOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
254 return m_overflow ? m_overflow->visualOverflowRect() : enclosingLayoutRect(frameRectIncludingLineHeight(lineTop, lineBottom));
256 LayoutUnit logicalLeftVisualOverflow() const { return m_overflow ? (isHorizontal() ? m_overflow->visualOverflowRect().x() : m_overflow->visualOverflowRect().y()) : static_cast<LayoutUnit>(logicalLeft()); }
257 LayoutUnit logicalRightVisualOverflow() const { return m_overflow ? (isHorizontal() ? m_overflow->visualOverflowRect().maxX() : m_overflow->visualOverflowRect().maxY()) : static_cast<LayoutUnit>(ceilf(logicalRight())); }
258 LayoutUnit logicalTopVisualOverflow(LayoutUnit lineTop) const
261 return isHorizontal() ? m_overflow->visualOverflowRect().y() : m_overflow->visualOverflowRect().x();
264 LayoutUnit logicalBottomVisualOverflow(LayoutUnit lineBottom) const
267 return isHorizontal() ? m_overflow->visualOverflowRect().maxY() : m_overflow->visualOverflowRect().maxX();
270 LayoutRect logicalVisualOverflowRect(LayoutUnit lineTop, LayoutUnit lineBottom) const
272 LayoutRect result = visualOverflowRect(lineTop, lineBottom);
273 if (!renderer().isHorizontalWritingMode())
274 result = result.transposedRect();
278 void setOverflowFromLogicalRects(const LayoutRect& logicalLayoutOverflow, const LayoutRect& logicalVisualOverflow, LayoutUnit lineTop, LayoutUnit lineBottom);
280 FloatRect frameRectIncludingLineHeight(LayoutUnit lineTop, LayoutUnit lineBottom) const
283 return FloatRect(m_topLeft.x(), lineTop.toFloat(), width(), (lineBottom - lineTop).toFloat());
284 return FloatRect(lineTop.toFloat(), m_topLeft.y(), (lineBottom - lineTop).toFloat(), height());
287 FloatRect logicalFrameRectIncludingLineHeight(LayoutUnit lineTop, LayoutUnit lineBottom) const
289 return FloatRect(logicalLeft(), lineTop.toFloat(), logicalWidth(), (lineBottom - lineTop).toFloat());
292 bool descendantsHaveSameLineHeightAndBaseline() const { return m_descendantsHaveSameLineHeightAndBaseline; }
293 void clearDescendantsHaveSameLineHeightAndBaseline()
295 m_descendantsHaveSameLineHeightAndBaseline = false;
296 if (parent() && parent()->descendantsHaveSameLineHeightAndBaseline())
297 parent()->clearDescendantsHaveSameLineHeightAndBaseline();
301 void addBoxShadowVisualOverflow(LayoutRect& logicalVisualOverflow);
302 void addBorderOutsetVisualOverflow(LayoutRect& logicalVisualOverflow);
303 void addOutlineVisualOverflow(LayoutRect& logicalVisualOverflow);
304 void addTextBoxVisualOverflow(InlineTextBox*, GlyphOverflowAndFallbackFontsMap&, LayoutRect& logicalVisualOverflow);
305 void addReplacedChildOverflow(const InlineBox*, LayoutRect& logicalLayoutOverflow, LayoutRect& logicalVisualOverflow);
306 void constrainToLineTopAndBottomIfNeeded(LayoutRect&) const;
308 void setLayoutOverflow(const LayoutRect&, const LayoutRect&);
309 void setVisualOverflow(const LayoutRect&, const LayoutRect&);
312 OwnPtr<RenderOverflow> m_overflow;
314 virtual bool isInlineFlowBox() const OVERRIDE FINAL { return true; }
316 InlineBox* m_firstChild;
317 InlineBox* m_lastChild;
319 InlineFlowBox* m_prevLineBox; // The previous box that also uses our RenderObject
320 InlineFlowBox* m_nextLineBox; // The next box that also uses our RenderObject
322 // Maximum logicalTop among all children of an InlineFlowBox. Used to
323 // calculate the offset for TextUnderlinePositionUnder.
324 void computeMaxLogicalTop(float& maxLogicalTop) const;
327 unsigned m_includeLogicalLeftEdge : 1;
328 unsigned m_includeLogicalRightEdge : 1;
329 unsigned m_hasTextChildren : 1;
330 unsigned m_hasTextDescendants : 1;
331 unsigned m_descendantsHaveSameLineHeightAndBaseline : 1;
334 // The following members are only used by RootInlineBox but moved here to keep the bits packed.
336 // Whether or not this line uses alphabetic or ideographic baselines by default.
337 unsigned m_baselineType : 1; // FontBaseline
339 // If the line contains any ruby runs, then this will be true.
340 unsigned m_hasAnnotationsBefore : 1;
341 unsigned m_hasAnnotationsAfter : 1;
343 unsigned m_lineBreakBidiStatusEor : 5; // WTF::Unicode::Direction
344 unsigned m_lineBreakBidiStatusLastStrong : 5; // WTF::Unicode::Direction
345 unsigned m_lineBreakBidiStatusLast : 5; // WTF::Unicode::Direction
347 // End of RootInlineBox-specific members.
351 unsigned m_hasBadChildList : 1;
355 DEFINE_INLINE_BOX_TYPE_CASTS(InlineFlowBox);
358 inline void InlineFlowBox::checkConsistency() const
363 inline void InlineFlowBox::setHasBadChildList()
366 m_hasBadChildList = true;
370 } // namespace WebCore
373 // Outside the WebCore namespace for ease of invocation from gdb.
374 void showTree(const WebCore::InlineFlowBox*);
377 #endif // InlineFlowBox_h