2 * This file is part of the HTML widget for KDE.
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * Copyright (C) 2006 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
27 #include "FrameView.h"
28 #include "LayoutState.h"
29 #include "RenderBlock.h"
30 #include <wtf/OwnPtr.h>
36 #if USE(ACCELERATED_COMPOSITING)
37 class RenderLayerCompositor;
40 class RenderView : public RenderBlock {
42 RenderView(Node*, FrameView*);
43 virtual ~RenderView();
45 virtual const char* renderName() const { return "RenderView"; }
47 virtual bool isRenderView() const { return true; }
49 virtual void layout();
50 virtual void calcWidth();
51 virtual void calcHeight();
52 virtual void calcPrefWidths();
54 int docHeight() const;
57 // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
58 int viewHeight() const;
59 int viewWidth() const;
61 float zoomFactor() const;
63 FrameView* frameView() const { return m_frameView; }
65 virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect&, bool fixed = false);
66 virtual void repaintViewRectangle(const IntRect&, bool immediate = false);
67 // Repaint the view, and all composited layers that intersect the given absolute rectangle.
68 // FIXME: ideally we'd never have to do this, if all repaints are container-relative.
69 virtual void repaintRectangleInViewAndCompositedLayers(const IntRect&, bool immediate = false);
71 virtual void paint(PaintInfo&, int tx, int ty);
72 virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
74 void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos);
75 void clearSelection();
76 virtual RenderObject* selectionStart() const { return m_selectionStart; }
77 virtual RenderObject* selectionEnd() const { return m_selectionEnd; }
79 bool printing() const;
80 void setPrintImages(bool enable) { m_printImages = enable; }
81 bool printImages() const { return m_printImages; }
82 void setTruncatedAt(int y) { m_truncatedAt = y; m_bestTruncatedAt = m_truncatorWidth = 0; m_forcedPageBreak = false; }
83 void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false);
84 int bestTruncatedAt() const { return m_bestTruncatedAt; }
86 int truncatedAt() const { return m_truncatedAt; }
88 virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true);
89 virtual void absoluteQuads(Vector<FloatQuad>&, bool topLevel = true);
91 IntRect selectionBounds(bool clipToVisibleContent = true) const;
93 #if USE(ACCELERATED_COMPOSITING)
94 void setMaximalOutlineSize(int o);
96 void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
98 int maximalOutlineSize() const { return m_maximalOutlineSize; }
100 virtual IntRect viewRect() const;
102 void selectionStartEnd(int& startPos, int& endPos) const;
104 IntRect printRect() const { return m_printRect; }
105 void setPrintRect(const IntRect& r) { m_printRect = r; }
107 void updateWidgetPositions();
108 void addWidget(RenderWidget*);
109 void removeWidget(RenderWidget*);
111 // layoutDelta is used transiently during layout to store how far an object has moved from its
112 // last layout location, in order to repaint correctly.
113 // If we're doing a full repaint m_layoutState will be 0, but in that case layoutDelta doesn't matter.
114 IntSize layoutDelta() const
116 return m_layoutState ? m_layoutState->m_layoutDelta : IntSize();
118 void addLayoutDelta(const IntSize& delta)
121 m_layoutState->m_layoutDelta += delta;
124 bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
126 void pushLayoutState(RenderBox* renderer, const IntSize& offset)
128 if (doingFullRepaint())
130 // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
131 m_layoutState = new (renderArena()) LayoutState(m_layoutState, renderer, offset);
134 void pushLayoutState(RenderObject*);
136 void popLayoutState()
138 if (doingFullRepaint())
140 LayoutState* state = m_layoutState;
141 m_layoutState = state->m_next;
142 state->destroy(renderArena());
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;
176 FrameView* m_frameView;
178 RenderObject* m_selectionStart;
179 RenderObject* m_selectionEnd;
180 int m_selectionStartPos;
181 int m_selectionEndPos;
183 // used to ignore viewport width when printing to the printer
187 int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
188 IntRect m_printRect; // Used when printing.
190 typedef HashSet<RenderWidget*> RenderWidgetSet;
192 RenderWidgetSet m_widgets;
195 int m_bestTruncatedAt;
196 int m_truncatorWidth;
197 bool m_forcedPageBreak;
198 LayoutState* m_layoutState;
199 unsigned m_layoutStateDisableCount;
200 #if USE(ACCELERATED_COMPOSITING)
201 OwnPtr<RenderLayerCompositor> m_compositor;
205 inline RenderView* toRenderView(RenderObject* o)
207 ASSERT(!o || o->isRenderView());
208 return static_cast<RenderView*>(o);
211 inline const RenderView* toRenderView(const RenderObject* o)
213 ASSERT(!o || o->isRenderView());
214 return static_cast<const RenderView*>(o);
217 // This will catch anyone doing an unnecessary cast.
218 void toRenderView(const RenderView*);
221 // Stack-based class to assist with LayoutState push/pop
222 class LayoutStateMaintainer : Noncopyable {
225 LayoutStateMaintainer(RenderView* view, RenderBox* root, IntSize offset, bool disableState = false)
227 , m_disabled(disableState)
234 // ctor to maybe push later
235 LayoutStateMaintainer(RenderView* view)
243 ~LayoutStateMaintainer()
245 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someone did a push(), but forgot to pop().
248 void push(RenderBox* root, IntSize offset)
251 // We push state even if disabled, because we still need to store layoutDelta
252 m_view->pushLayoutState(root, offset);
254 m_view->disableLayoutState();
262 m_view->popLayoutState();
264 m_view->enableLayoutState();
269 bool didPush() const { return m_didStart; }
273 bool m_disabled : 1; // true if the offset and clip part of layoutState is disabled
274 bool m_didStart : 1; // true if we did a push or disable
275 bool m_didEnd : 1; // true if we popped or re-enabled
278 } // namespace WebCore
280 #endif // RenderView_h