Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderInline.h
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22
23 #ifndef RenderInline_h
24 #define RenderInline_h
25
26 #include "core/animation/ActiveAnimations.h"
27 #include "core/rendering/InlineFlowBox.h"
28 #include "core/rendering/RenderBoxModelObject.h"
29 #include "core/rendering/RenderLineBoxList.h"
30
31 namespace WebCore {
32
33 class Position;
34
35 class RenderInline : public RenderBoxModelObject {
36 public:
37     explicit RenderInline(Element*);
38
39     static RenderInline* createAnonymous(Document*);
40
41     RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); }
42     RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); }
43
44     virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0) OVERRIDE;
45
46     Element* node() const { return toElement(RenderBoxModelObject::node()); }
47
48     virtual LayoutUnit marginLeft() const OVERRIDE FINAL;
49     virtual LayoutUnit marginRight() const OVERRIDE FINAL;
50     virtual LayoutUnit marginTop() const OVERRIDE FINAL;
51     virtual LayoutUnit marginBottom() const OVERRIDE FINAL;
52     virtual LayoutUnit marginBefore(const RenderStyle* otherStyle = 0) const OVERRIDE FINAL;
53     virtual LayoutUnit marginAfter(const RenderStyle* otherStyle = 0) const OVERRIDE FINAL;
54     virtual LayoutUnit marginStart(const RenderStyle* otherStyle = 0) const OVERRIDE FINAL;
55     virtual LayoutUnit marginEnd(const RenderStyle* otherStyle = 0) const OVERRIDE FINAL;
56
57     virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE FINAL;
58     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
59
60     virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const OVERRIDE FINAL;
61
62     IntRect linesBoundingBox() const;
63     LayoutRect linesVisualOverflowBoundingBox() const;
64
65     InlineFlowBox* createAndAppendInlineFlowBox();
66
67     void dirtyLineBoxes(bool fullLayout);
68     void deleteLineBoxTree();
69
70     RenderLineBoxList* lineBoxes() { return &m_lineBoxes; }
71     const RenderLineBoxList* lineBoxes() const { return &m_lineBoxes; }
72
73     InlineFlowBox* firstLineBox() const { return m_lineBoxes.firstLineBox(); }
74     InlineFlowBox* lastLineBox() const { return m_lineBoxes.lastLineBox(); }
75     InlineBox* firstLineBoxIncludingCulling() const { return alwaysCreateLineBoxes() ? firstLineBox() : culledInlineFirstLineBox(); }
76     InlineBox* lastLineBoxIncludingCulling() const { return alwaysCreateLineBoxes() ? lastLineBox() : culledInlineLastLineBox(); }
77
78     virtual RenderBoxModelObject* virtualContinuation() const OVERRIDE FINAL { return continuation(); }
79     RenderInline* inlineElementContinuation() const;
80
81     virtual void updateDragState(bool dragOn) OVERRIDE FINAL;
82
83     LayoutSize offsetForInFlowPositionedInline(const RenderBox& child) const;
84
85     virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE FINAL;
86     void paintOutline(PaintInfo&, const LayoutPoint&);
87
88     using RenderBoxModelObject::continuation;
89     using RenderBoxModelObject::setContinuation;
90
91     bool alwaysCreateLineBoxes() const { return m_alwaysCreateLineBoxes; }
92     void setAlwaysCreateLineBoxes() { m_alwaysCreateLineBoxes = true; }
93     void updateAlwaysCreateLineBoxes(bool fullLayout);
94
95     virtual LayoutRect localCaretRect(InlineBox*, int, LayoutUnit* extraWidthToEndOfLine) OVERRIDE FINAL;
96
97     bool hitTestCulledInline(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset);
98
99 protected:
100     virtual void willBeDestroyed() OVERRIDE;
101
102     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
103
104     virtual void computeSelfHitTestRects(Vector<LayoutRect>& rects, const LayoutPoint& layerOffset) const OVERRIDE;
105
106 private:
107     virtual RenderObjectChildList* virtualChildren() OVERRIDE FINAL { return children(); }
108     virtual const RenderObjectChildList* virtualChildren() const OVERRIDE FINAL { return children(); }
109     const RenderObjectChildList* children() const { return &m_children; }
110     RenderObjectChildList* children() { return &m_children; }
111
112     virtual const char* renderName() const OVERRIDE;
113
114     virtual bool isRenderInline() const OVERRIDE FINAL { return true; }
115
116     LayoutRect culledInlineVisualOverflowBoundingBox() const;
117     InlineBox* culledInlineFirstLineBox() const;
118     InlineBox* culledInlineLastLineBox() const;
119
120     template<typename GeneratorContext>
121     void generateLineBoxRects(GeneratorContext& yield) const;
122     template<typename GeneratorContext>
123     void generateCulledLineBoxRects(GeneratorContext& yield, const RenderInline* container) const;
124
125     void addChildToContinuation(RenderObject* newChild, RenderObject* beforeChild);
126     virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = 0) OVERRIDE FINAL;
127
128     void splitInlines(RenderBlock* fromBlock, RenderBlock* toBlock, RenderBlock* middleBlock,
129                       RenderObject* beforeChild, RenderBoxModelObject* oldCont);
130     void splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox,
131                    RenderObject* newChild, RenderBoxModelObject* oldCont);
132
133     virtual void layout() OVERRIDE FINAL { ASSERT_NOT_REACHED(); } // Do nothing for layout()
134
135     virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE FINAL;
136
137     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE FINAL;
138
139     virtual LayerType layerTypeRequired() const OVERRIDE { return isInFlowPositioned() || createsGroup() || hasClipPath() || shouldCompositeForActiveAnimations(*this) ? NormalLayer : NoLayer; }
140
141     virtual LayoutUnit offsetLeft() const OVERRIDE FINAL;
142     virtual LayoutUnit offsetTop() const OVERRIDE FINAL;
143     virtual LayoutUnit offsetWidth() const OVERRIDE FINAL { return linesBoundingBox().width(); }
144     virtual LayoutUnit offsetHeight() const OVERRIDE FINAL { return linesBoundingBox().height(); }
145
146     virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
147     virtual LayoutRect rectWithOutlineForRepaint(const RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const OVERRIDE FINAL;
148     virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed) const OVERRIDE FINAL;
149
150     virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
151
152     virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE FINAL;
153
154     virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE FINAL { return linesBoundingBox(); }
155
156     virtual IntRect borderBoundingBox() const OVERRIDE FINAL
157     {
158         IntRect boundingBox = linesBoundingBox();
159         return IntRect(0, 0, boundingBox.width(), boundingBox.height());
160     }
161
162     virtual InlineFlowBox* createInlineFlowBox(); // Subclassed by SVG and Ruby
163
164     virtual void dirtyLinesFromChangedChild(RenderObject* child) OVERRIDE FINAL { m_lineBoxes.dirtyLinesFromChangedChild(this, child); }
165
166     virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE FINAL;
167     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE FINAL;
168
169     virtual void childBecameNonInline(RenderObject* child) OVERRIDE FINAL;
170
171     virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&) OVERRIDE FINAL;
172
173     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE FINAL;
174
175     virtual void addAnnotatedRegions(Vector<AnnotatedRegionValue>&) OVERRIDE FINAL;
176
177     virtual void updateFromStyle() OVERRIDE FINAL;
178
179     RenderInline* clone() const;
180
181     void paintOutlineForLine(GraphicsContext*, const LayoutPoint&, const LayoutRect& prevLine, const LayoutRect& thisLine,
182                              const LayoutRect& nextLine, const Color);
183     RenderBoxModelObject* continuationBefore(RenderObject* beforeChild);
184
185     RenderObjectChildList m_children;
186     RenderLineBoxList m_lineBoxes;   // All of the line boxes created for this inline flow.  For example, <i>Hello<br>world.</i> will have two <i> line boxes.
187
188     bool m_alwaysCreateLineBoxes : 1;
189 };
190
191 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderInline, isRenderInline());
192
193 } // namespace WebCore
194
195 #endif // RenderInline_h