2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2006 Apple Computer, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
25 #include "FrameView.h"
26 #include "LayoutState.h"
27 #include "RenderBlock.h"
28 #include <wtf/OwnPtr.h>
34 #if USE(ACCELERATED_COMPOSITING)
35 class RenderLayerCompositor;
38 class RenderView : public RenderBlock {
40 RenderView(Node*, FrameView*);
41 virtual ~RenderView();
43 virtual const char* renderName() const { return "RenderView"; }
45 virtual bool isRenderView() const { return true; }
47 virtual void layout();
48 virtual void calcWidth();
49 virtual void calcHeight();
50 virtual void calcPrefWidths();
52 // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
53 int viewHeight() const;
54 int viewWidth() const;
56 float zoomFactor() const;
58 FrameView* frameView() const { return m_frameView; }
60 virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect&, bool fixed = false);
61 virtual void repaintViewRectangle(const IntRect&, bool immediate = false);
62 // Repaint the view, and all composited layers that intersect the given absolute rectangle.
63 // FIXME: ideally we'd never have to do this, if all repaints are container-relative.
64 virtual void repaintRectangleInViewAndCompositedLayers(const IntRect&, bool immediate = false);
66 virtual void paint(PaintInfo&, int tx, int ty);
67 virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
69 enum SelectionRepaintMode { RepaintNewXOROld, RepaintNewMinusOld };
70 void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode = RepaintNewXOROld);
71 void clearSelection();
72 virtual RenderObject* selectionStart() const { return m_selectionStart; }
73 virtual RenderObject* selectionEnd() const { return m_selectionEnd; }
75 bool printing() const;
76 void setPrintImages(bool enable) { m_printImages = enable; }
77 bool printImages() const { return m_printImages; }
78 void setTruncatedAt(int y) { m_truncatedAt = y; m_bestTruncatedAt = m_truncatorWidth = 0; m_minimumColumnHeight = 0; m_forcedPageBreak = false; }
79 void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false);
80 void setMinimumColumnHeight(int height) { m_minimumColumnHeight = height; }
81 int bestTruncatedAt() const { return m_bestTruncatedAt; }
82 int minimumColumnHeight() const { return m_minimumColumnHeight; }
84 int truncatedAt() const { return m_truncatedAt; }
86 virtual void absoluteRects(Vector<IntRect>&, int tx, int ty);
87 virtual void absoluteQuads(Vector<FloatQuad>&);
89 IntRect selectionBounds(bool clipToVisibleContent = true) const;
91 #if USE(ACCELERATED_COMPOSITING)
92 void setMaximalOutlineSize(int o);
94 void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
96 int maximalOutlineSize() const { return m_maximalOutlineSize; }
98 virtual IntRect viewRect() const;
100 void selectionStartEnd(int& startPos, int& endPos) const;
102 IntRect printRect() const { return m_printRect; }
103 void setPrintRect(const IntRect& r) { m_printRect = r; }
105 void updateWidgetPositions();
106 void addWidget(RenderWidget*);
107 void removeWidget(RenderWidget*);
109 // layoutDelta is used transiently during layout to store how far an object has moved from its
110 // last layout location, in order to repaint correctly.
111 // If we're doing a full repaint m_layoutState will be 0, but in that case layoutDelta doesn't matter.
112 IntSize layoutDelta() const
114 return m_layoutState ? m_layoutState->m_layoutDelta : IntSize();
116 void addLayoutDelta(const IntSize& delta)
119 m_layoutState->m_layoutDelta += delta;
122 bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
124 void pushLayoutState(RenderBox* renderer, const IntSize& offset)
126 if (doingFullRepaint())
128 // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
129 m_layoutState = new (renderArena()) LayoutState(m_layoutState, renderer, offset);
132 void pushLayoutState(RenderObject*);
134 void popLayoutState()
136 if (doingFullRepaint())
138 LayoutState* state = m_layoutState;
139 m_layoutState = state->m_next;
140 state->destroy(renderArena());
143 bool shouldDisableLayoutStateForSubtree(RenderObject*) const;
145 // Returns true if layoutState should be used for its cached offset and clip.
146 bool layoutStateEnabled() const { return m_layoutStateDisableCount == 0 && m_layoutState; }
147 LayoutState* layoutState() const { return m_layoutState; }
149 // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
150 // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
151 // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
152 // Note that even when disabled, LayoutState is still used to store layoutDelta.
153 void disableLayoutState() { m_layoutStateDisableCount++; }
154 void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
156 virtual void updateHitTestResult(HitTestResult&, const IntPoint&);
158 // Notifications that this view became visible in a window, or will be
159 // removed from the window.
160 void didMoveOnscreen();
161 void willMoveOffscreen();
163 #if USE(ACCELERATED_COMPOSITING)
164 RenderLayerCompositor* compositor();
165 bool usesCompositing() const;
169 virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&) const;
170 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
173 bool shouldRepaint(const IntRect& r) const;
175 #ifdef FLATTEN_FRAMESET
176 public: // used by layout function
178 int docHeight() const;
179 int docWidth() const;
182 FrameView* m_frameView;
184 RenderObject* m_selectionStart;
185 RenderObject* m_selectionEnd;
186 int m_selectionStartPos;
187 int m_selectionEndPos;
189 // used to ignore viewport width when printing to the printer
193 int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
194 IntRect m_printRect; // Used when printing.
196 typedef HashSet<RenderWidget*> RenderWidgetSet;
198 RenderWidgetSet m_widgets;
201 int m_bestTruncatedAt;
202 int m_truncatorWidth;
203 int m_minimumColumnHeight;
204 bool m_forcedPageBreak;
205 LayoutState* m_layoutState;
206 unsigned m_layoutStateDisableCount;
207 #if USE(ACCELERATED_COMPOSITING)
208 OwnPtr<RenderLayerCompositor> m_compositor;
212 inline RenderView* toRenderView(RenderObject* object)
214 ASSERT(!object || object->isRenderView());
215 return static_cast<RenderView*>(object);
218 inline const RenderView* toRenderView(const RenderObject* object)
220 ASSERT(!object || object->isRenderView());
221 return static_cast<const RenderView*>(object);
224 // This will catch anyone doing an unnecessary cast.
225 void toRenderView(const RenderView*);
228 // Stack-based class to assist with LayoutState push/pop
229 class LayoutStateMaintainer : public Noncopyable {
232 LayoutStateMaintainer(RenderView* view, RenderBox* root, IntSize offset, bool disableState = false)
234 , m_disabled(disableState)
241 // ctor to maybe push later
242 LayoutStateMaintainer(RenderView* view)
250 ~LayoutStateMaintainer()
252 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someone did a push(), but forgot to pop().
255 void push(RenderBox* root, IntSize offset)
258 // We push state even if disabled, because we still need to store layoutDelta
259 m_view->pushLayoutState(root, offset);
261 m_view->disableLayoutState();
269 m_view->popLayoutState();
271 m_view->enableLayoutState();
276 bool didPush() const { return m_didStart; }
280 bool m_disabled : 1; // true if the offset and clip part of layoutState is disabled
281 bool m_didStart : 1; // true if we did a push or disable
282 bool m_didEnd : 1; // true if we popped or re-enabled
285 } // namespace WebCore
287 #endif // RenderView_h