2 * Copyright (C) 2003, 2006, 2007, 2008 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 RootInlineBox_h
22 #define RootInlineBox_h
24 #include "core/rendering/InlineFlowBox.h"
25 #include "platform/text/BidiContext.h"
31 class RenderBlockFlow;
36 class RootInlineBox : public InlineFlowBox {
38 explicit RootInlineBox(RenderBlockFlow&);
40 virtual void destroy() override final;
42 virtual bool isRootInlineBox() const override final { return true; }
44 void detachEllipsisBox();
46 RootInlineBox* nextRootBox() const { return static_cast<RootInlineBox*>(m_nextLineBox); }
47 RootInlineBox* prevRootBox() const { return static_cast<RootInlineBox*>(m_prevLineBox); }
49 virtual void adjustPosition(float dx, float dy) override final;
51 LayoutUnit lineTop() const { return m_lineTop; }
52 LayoutUnit lineBottom() const { return m_lineBottom; }
54 LayoutUnit lineTopWithLeading() const { return m_lineTopWithLeading; }
55 LayoutUnit lineBottomWithLeading() const { return m_lineBottomWithLeading; }
57 LayoutUnit paginationStrut() const { return m_fragmentationData ? m_fragmentationData->m_paginationStrut : LayoutUnit(0); }
58 void setPaginationStrut(LayoutUnit strut) { ensureLineFragmentationData()->m_paginationStrut = strut; }
60 bool isFirstAfterPageBreak() const { return m_fragmentationData ? m_fragmentationData->m_isFirstAfterPageBreak : false; }
61 void setIsFirstAfterPageBreak(bool isFirstAfterPageBreak) { ensureLineFragmentationData()->m_isFirstAfterPageBreak = isFirstAfterPageBreak; }
63 void setPaginatedLineWidth(LayoutUnit width) { ensureLineFragmentationData()->m_paginatedLineWidth = width; }
65 LayoutUnit selectionTop() const;
66 LayoutUnit selectionBottom() const;
67 LayoutUnit selectionHeight() const { return max<LayoutUnit>(0, selectionBottom() - selectionTop()); }
69 LayoutUnit selectionTopAdjustedForPrecedingBlock() const;
70 LayoutUnit selectionHeightAdjustedForPrecedingBlock() const { return max<LayoutUnit>(0, selectionBottom() - selectionTopAdjustedForPrecedingBlock()); }
72 int blockDirectionPointInLine() const;
74 LayoutUnit alignBoxesInBlockDirection(LayoutUnit heightOfBlock, GlyphOverflowAndFallbackFontsMap&, VerticalPositionCache&);
75 void setLineTopBottomPositions(LayoutUnit top, LayoutUnit bottom, LayoutUnit topWithLeading, LayoutUnit bottomWithLeading, LayoutUnit selectionBottom = LayoutUnit::min())
78 m_lineBottom = bottom;
79 m_lineTopWithLeading = topWithLeading;
80 m_lineBottomWithLeading = bottomWithLeading;
81 m_selectionBottom = selectionBottom == LayoutUnit::min() ? bottom : selectionBottom;
84 virtual RenderLineBoxList* rendererLineBoxes() const override final;
86 RenderObject* lineBreakObj() const { return m_lineBreakObj; }
87 BidiStatus lineBreakBidiStatus() const;
88 void setLineBreakInfo(RenderObject*, unsigned breakPos, const BidiStatus&);
90 unsigned lineBreakPos() const { return m_lineBreakPos; }
91 void setLineBreakPos(unsigned p) { m_lineBreakPos = p; }
93 using InlineBox::endsWithBreak;
94 using InlineBox::setEndsWithBreak;
96 void childRemoved(InlineBox* box);
98 bool lineCanAccommodateEllipsis(bool ltr, int blockEdge, int lineBoxEdge, int ellipsisWidth);
99 // Return the truncatedWidth, the width of the truncated text + ellipsis.
100 float placeEllipsis(const AtomicString& ellipsisStr, bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, InlineBox* markupBox = 0);
101 // Return the position of the EllipsisBox or -1.
102 virtual float placeEllipsisBox(bool ltr, float blockLeftEdge, float blockRightEdge, float ellipsisWidth, float &truncatedWidth, bool& foundBox) override final;
104 using InlineBox::hasEllipsisBox;
105 EllipsisBox* ellipsisBox() const;
107 virtual void clearTruncation() override final;
109 virtual int baselinePosition(FontBaseline baselineType) const override final;
110 virtual LayoutUnit lineHeight() const override final;
112 virtual void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) override;
113 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom) override final;
115 using InlineBox::hasSelectedChildren;
116 using InlineBox::setHasSelectedChildren;
118 virtual RenderObject::SelectionState selectionState() const override final;
119 InlineBox* firstSelectedBox() const;
120 InlineBox* lastSelectedBox() const;
122 GapRects lineSelectionGap(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock, LayoutUnit selTop, LayoutUnit selHeight, const PaintInfo*) const;
124 RenderBlockFlow& block() const;
126 InlineBox* closestLeafChildForPoint(const IntPoint&, bool onlyEditableLeaves);
127 InlineBox* closestLeafChildForLogicalLeftPosition(int, bool onlyEditableLeaves = false);
129 void appendFloat(RenderBox* floatingBox)
133 m_floats->append(floatingBox);
135 m_floats= adoptPtr(new Vector<RenderBox*>(1, floatingBox));
138 Vector<RenderBox*>* floatsPtr() { ASSERT(!isDirty()); return m_floats.get(); }
140 virtual void extractLineBoxFromRenderObject() override final;
141 virtual void attachLineBoxToRenderObject() override final;
142 virtual void removeLineBoxFromRenderObject() override final;
144 FontBaseline baselineType() const { return static_cast<FontBaseline>(m_baselineType); }
146 bool hasAnnotationsBefore() const { return m_hasAnnotationsBefore; }
147 bool hasAnnotationsAfter() const { return m_hasAnnotationsAfter; }
149 LayoutRect paddedLayoutOverflowRect(LayoutUnit endPadding) const;
151 void ascentAndDescentForBox(InlineBox*, GlyphOverflowAndFallbackFontsMap&, int& ascent, int& descent, bool& affectsAscent, bool& affectsDescent) const;
152 LayoutUnit verticalPositionForBox(InlineBox*, VerticalPositionCache&);
153 bool includeLeadingForBox(InlineBox*) const;
154 bool includeFontForBox(InlineBox*) const;
155 bool includeGlyphsForBox(InlineBox*) const;
156 bool includeMarginForBox(InlineBox*) const;
157 bool fitsToGlyphs() const;
158 bool includesRootLineBoxFontOrLeading() const;
160 LayoutUnit logicalTopVisualOverflow() const
162 return InlineFlowBox::logicalTopVisualOverflow(lineTop());
164 LayoutUnit logicalBottomVisualOverflow() const
166 return InlineFlowBox::logicalBottomVisualOverflow(lineBottom());
168 LayoutUnit logicalTopLayoutOverflow() const
170 return InlineFlowBox::logicalTopLayoutOverflow(lineTop());
172 LayoutUnit logicalBottomLayoutOverflow() const
174 return InlineFlowBox::logicalBottomLayoutOverflow(lineBottom());
177 // Used to calculate the underline offset for TextUnderlinePositionUnder.
178 float maxLogicalTop() const;
180 Node* getLogicalStartBoxWithNode(InlineBox*&) const;
181 Node* getLogicalEndBoxWithNode(InlineBox*&) const;
184 virtual const char* boxName() const override;
187 LayoutUnit beforeAnnotationsAdjustment() const;
189 struct LineFragmentationData;
190 LineFragmentationData* ensureLineFragmentationData()
192 if (!m_fragmentationData)
193 m_fragmentationData = adoptPtr(new LineFragmentationData());
195 return m_fragmentationData.get();
198 // This folds into the padding at the end of InlineFlowBox on 64-bit.
199 unsigned m_lineBreakPos;
201 // Where this line ended. The exact object and the position within that object are stored so that
202 // we can create an InlineIterator beginning just after the end of this line.
203 RenderObject* m_lineBreakObj;
204 RefPtr<BidiContext> m_lineBreakContext;
206 struct LineFragmentationData {
207 WTF_MAKE_NONCOPYABLE(LineFragmentationData); WTF_MAKE_FAST_ALLOCATED;
209 LineFragmentationData()
210 : m_paginationStrut(0)
211 , m_paginatedLineWidth(0)
212 , m_isFirstAfterPageBreak(false)
217 LayoutUnit m_paginationStrut;
218 LayoutUnit m_paginatedLineWidth;
219 bool m_isFirstAfterPageBreak;
222 OwnPtr<LineFragmentationData> m_fragmentationData;
224 // Floats hanging off the line are pushed into this vector during layout. It is only
225 // good for as long as the line has not been marked dirty.
226 OwnPtr<Vector<RenderBox*> > m_floats;
228 LayoutUnit m_lineTop;
229 LayoutUnit m_lineBottom;
230 LayoutUnit m_lineTopWithLeading;
231 LayoutUnit m_lineBottomWithLeading;
232 LayoutUnit m_selectionBottom;
237 #endif // RootInlineBox_h