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 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 RenderFlow_h
24 #define RenderFlow_h
25
26 #include "RenderContainer.h"
27
28 namespace WebCore {
29
30 /**
31 * all geometry managing stuff is only in the block elements.
32 *
33 * Inline elements don't layout themselves, but the whole paragraph
34 * gets flowed by the surrounding block element. This is, because
35 * one needs to know the whole paragraph to calculate bidirectional
36 * behaviour of text, so putting the layouting routines in the inline
37 * elements is impossible.
38 */
39 class RenderFlow : public RenderContainer {
40 public:
RenderFlow(Node * node)41 RenderFlow(Node* node)
42 : RenderContainer(node)
43 , m_continuation(0)
44 , m_firstLineBox(0)
45 , m_lastLineBox(0)
46 , m_lineHeight(-1)
47 , m_childrenInline(true)
48 , m_firstLine(false)
49 , m_topMarginQuirk(false)
50 , m_bottomMarginQuirk(false)
51 , m_hasMarkupTruncation(false)
52 , m_selectionState(SelectionNone)
53 , m_hasColumns(false)
54 , m_isContinuation(false)
55 , m_cellWidthChanged(false)
56 {
57 }
58 #ifndef NDEBUG
59 virtual ~RenderFlow();
60 #endif
61
virtualContinuation()62 virtual RenderFlow* virtualContinuation() const { return continuation(); }
continuation()63 RenderFlow* continuation() const { return m_continuation; }
setContinuation(RenderFlow * c)64 void setContinuation(RenderFlow* c) { m_continuation = c; }
65 RenderFlow* continuationBefore(RenderObject* beforeChild);
66
67 void addChildWithContinuation(RenderObject* newChild, RenderObject* beforeChild);
68 virtual void addChildToFlow(RenderObject* newChild, RenderObject* beforeChild) = 0;
69 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
70
71 static RenderFlow* createAnonymousFlow(Document*, PassRefPtr<RenderStyle>);
72
73 void extractLineBox(InlineFlowBox*);
74 void attachLineBox(InlineFlowBox*);
75 void removeLineBox(InlineFlowBox*);
76 void deleteLineBoxes();
77 virtual void destroy();
78
79 virtual void dirtyLinesFromChangedChild(RenderObject* child);
80
81 virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const;
82
firstLineBox()83 InlineFlowBox* firstLineBox() const { return m_firstLineBox; }
lastLineBox()84 InlineFlowBox* lastLineBox() const { return m_lastLineBox; }
85
86 virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun=false);
87 virtual void dirtyLineBoxes(bool fullLayout, bool isRootLineBox = false);
88
89 void paintLines(PaintInfo&, int tx, int ty);
90 bool hitTestLines(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
91
92 virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0);
93
94 virtual void addFocusRingRects(GraphicsContext*, int tx, int ty);
95 void paintOutlineForLine(GraphicsContext*, int tx, int ty, const IntRect& prevLine, const IntRect& thisLine, const IntRect& nextLine);
96 void paintOutline(GraphicsContext*, int tx, int ty);
97
hasColumns()98 virtual bool hasColumns() const { return m_hasColumns; }
99
100 void calcMargins(int containerWidth);
101
102 void checkConsistency() const;
103
104 private:
105 // An inline can be split with blocks occurring in between the inline content.
106 // When this occurs we need a pointer to our next object. We can basically be
107 // split into a sequence of inlines and blocks. The continuation will either be
108 // an anonymous block (that houses other blocks) or it will be an inline flow.
109 RenderFlow* m_continuation;
110
111 protected:
112 // For block flows, each box represents the root inline box for a line in the
113 // paragraph.
114 // For inline flows, each box represents a portion of that inline.
115 InlineFlowBox* m_firstLineBox;
116 InlineFlowBox* m_lastLineBox;
117
118 mutable int m_lineHeight;
119
120 // These bitfields are moved here from subclasses to pack them together
121 // from RenderBlock
122 bool m_childrenInline : 1;
123 bool m_firstLine : 1;
124 bool m_topMarginQuirk : 1;
125 bool m_bottomMarginQuirk : 1;
126 bool m_hasMarkupTruncation : 1;
127 unsigned m_selectionState : 3; // SelectionState
128 bool m_hasColumns : 1;
129
130 // from RenderInline
131 bool m_isContinuation : 1; // Whether or not we're a continuation of an inline.
132
133 // from RenderTableCell
134 bool m_cellWidthChanged : 1;
135 };
136
137 #ifdef NDEBUG
checkConsistency()138 inline void RenderFlow::checkConsistency() const
139 {
140 }
141 #endif
142
143 } // namespace WebCore
144
145 #endif // RenderFlow_h
146