Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RootInlineBox.h
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 "core/rendering/InlineFlowBox.h"
25 #include "platform/text/BidiContext.h"
26
27 namespace blink {
28
29 class EllipsisBox;
30 class HitTestResult;
31 class RenderBlockFlow;
32
33 struct BidiStatus;
34 struct GapRects;
35
36 class RootInlineBox : public InlineFlowBox {
37 public:
38     explicit RootInlineBox(RenderBlockFlow&);
39
40     virtual void destroy() override final;
41
42     virtual bool isRootInlineBox() const override final { return true; }
43
44     void detachEllipsisBox();
45
46     RootInlineBox* nextRootBox() const { return static_cast<RootInlineBox*>(m_nextLineBox); }
47     RootInlineBox* prevRootBox() const { return static_cast<RootInlineBox*>(m_prevLineBox); }
48
49     virtual void adjustPosition(float dx, float dy) override final;
50
51     LayoutUnit lineTop() const { return m_lineTop; }
52     LayoutUnit lineBottom() const { return m_lineBottom; }
53
54     LayoutUnit lineTopWithLeading() const { return m_lineTopWithLeading; }
55     LayoutUnit lineBottomWithLeading() const { return m_lineBottomWithLeading; }
56
57     LayoutUnit paginationStrut() const { return m_fragmentationData ? m_fragmentationData->m_paginationStrut : LayoutUnit(0); }
58     void setPaginationStrut(LayoutUnit strut) { ensureLineFragmentationData()->m_paginationStrut = strut; }
59
60     bool isFirstAfterPageBreak() const { return m_fragmentationData ? m_fragmentationData->m_isFirstAfterPageBreak : false; }
61     void setIsFirstAfterPageBreak(bool isFirstAfterPageBreak) { ensureLineFragmentationData()->m_isFirstAfterPageBreak = isFirstAfterPageBreak; }
62
63     void setPaginatedLineWidth(LayoutUnit width) { ensureLineFragmentationData()->m_paginatedLineWidth = width; }
64
65     LayoutUnit selectionTop() const;
66     LayoutUnit selectionBottom() const;
67     LayoutUnit selectionHeight() const { return max<LayoutUnit>(0, selectionBottom() - selectionTop()); }
68
69     LayoutUnit selectionTopAdjustedForPrecedingBlock() const;
70     LayoutUnit selectionHeightAdjustedForPrecedingBlock() const { return max<LayoutUnit>(0, selectionBottom() - selectionTopAdjustedForPrecedingBlock()); }
71
72     int blockDirectionPointInLine() const;
73
74     LayoutUnit alignBoxesInBlockDirection(LayoutUnit heightOfBlock, GlyphOverflowAndFallbackFontsMap&, VerticalPositionCache&);
75     void setLineTopBottomPositions(LayoutUnit top, LayoutUnit bottom, LayoutUnit topWithLeading, LayoutUnit bottomWithLeading, LayoutUnit selectionBottom = LayoutUnit::min())
76     {
77         m_lineTop = top;
78         m_lineBottom = bottom;
79         m_lineTopWithLeading = topWithLeading;
80         m_lineBottomWithLeading = bottomWithLeading;
81         m_selectionBottom = selectionBottom == LayoutUnit::min() ? bottom : selectionBottom;
82     }
83
84     virtual RenderLineBoxList* rendererLineBoxes() const override final;
85
86     RenderObject* lineBreakObj() const { return m_lineBreakObj; }
87     BidiStatus lineBreakBidiStatus() const;
88     void setLineBreakInfo(RenderObject*, unsigned breakPos, const BidiStatus&);
89
90     unsigned lineBreakPos() const { return m_lineBreakPos; }
91     void setLineBreakPos(unsigned p) { m_lineBreakPos = p; }
92
93     using InlineBox::endsWithBreak;
94     using InlineBox::setEndsWithBreak;
95
96     void childRemoved(InlineBox* box);
97
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;
103
104     using InlineBox::hasEllipsisBox;
105     EllipsisBox* ellipsisBox() const;
106
107     virtual void clearTruncation() override final;
108
109     virtual int baselinePosition(FontBaseline baselineType) const override final;
110     virtual LayoutUnit lineHeight() const override final;
111
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;
114
115     using InlineBox::hasSelectedChildren;
116     using InlineBox::setHasSelectedChildren;
117
118     virtual RenderObject::SelectionState selectionState() const override final;
119     InlineBox* firstSelectedBox() const;
120     InlineBox* lastSelectedBox() const;
121
122     GapRects lineSelectionGap(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock, LayoutUnit selTop, LayoutUnit selHeight, const PaintInfo*) const;
123
124     RenderBlockFlow& block() const;
125
126     InlineBox* closestLeafChildForPoint(const IntPoint&, bool onlyEditableLeaves);
127     InlineBox* closestLeafChildForLogicalLeftPosition(int, bool onlyEditableLeaves = false);
128
129     void appendFloat(RenderBox* floatingBox)
130     {
131         ASSERT(!isDirty());
132         if (m_floats)
133             m_floats->append(floatingBox);
134         else
135             m_floats= adoptPtr(new Vector<RenderBox*>(1, floatingBox));
136     }
137
138     Vector<RenderBox*>* floatsPtr() { ASSERT(!isDirty()); return m_floats.get(); }
139
140     virtual void extractLineBoxFromRenderObject() override final;
141     virtual void attachLineBoxToRenderObject() override final;
142     virtual void removeLineBoxFromRenderObject() override final;
143
144     FontBaseline baselineType() const { return static_cast<FontBaseline>(m_baselineType); }
145
146     bool hasAnnotationsBefore() const { return m_hasAnnotationsBefore; }
147     bool hasAnnotationsAfter() const { return m_hasAnnotationsAfter; }
148
149     LayoutRect paddedLayoutOverflowRect(LayoutUnit endPadding) const;
150
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;
159
160     LayoutUnit logicalTopVisualOverflow() const
161     {
162         return InlineFlowBox::logicalTopVisualOverflow(lineTop());
163     }
164     LayoutUnit logicalBottomVisualOverflow() const
165     {
166         return InlineFlowBox::logicalBottomVisualOverflow(lineBottom());
167     }
168     LayoutUnit logicalTopLayoutOverflow() const
169     {
170         return InlineFlowBox::logicalTopLayoutOverflow(lineTop());
171     }
172     LayoutUnit logicalBottomLayoutOverflow() const
173     {
174         return InlineFlowBox::logicalBottomLayoutOverflow(lineBottom());
175     }
176
177     // Used to calculate the underline offset for TextUnderlinePositionUnder.
178     float maxLogicalTop() const;
179
180     Node* getLogicalStartBoxWithNode(InlineBox*&) const;
181     Node* getLogicalEndBoxWithNode(InlineBox*&) const;
182
183 #ifndef NDEBUG
184     virtual const char* boxName() const override;
185 #endif
186 private:
187     LayoutUnit beforeAnnotationsAdjustment() const;
188
189     struct LineFragmentationData;
190     LineFragmentationData* ensureLineFragmentationData()
191     {
192         if (!m_fragmentationData)
193             m_fragmentationData = adoptPtr(new LineFragmentationData());
194
195         return m_fragmentationData.get();
196     }
197
198     // This folds into the padding at the end of InlineFlowBox on 64-bit.
199     unsigned m_lineBreakPos;
200
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;
205
206     struct LineFragmentationData {
207         WTF_MAKE_NONCOPYABLE(LineFragmentationData); WTF_MAKE_FAST_ALLOCATED;
208     public:
209         LineFragmentationData()
210             : m_paginationStrut(0)
211             , m_paginatedLineWidth(0)
212             , m_isFirstAfterPageBreak(false)
213         {
214
215         }
216
217         LayoutUnit m_paginationStrut;
218         LayoutUnit m_paginatedLineWidth;
219         bool m_isFirstAfterPageBreak;
220     };
221
222     OwnPtr<LineFragmentationData> m_fragmentationData;
223
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;
227
228     LayoutUnit m_lineTop;
229     LayoutUnit m_lineBottom;
230     LayoutUnit m_lineTopWithLeading;
231     LayoutUnit m_lineBottomWithLeading;
232     LayoutUnit m_selectionBottom;
233 };
234
235 } // namespace blink
236
237 #endif // RootInlineBox_h