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"
29 #include "LayoutState.h"
30 #include "RenderBlock.h"
31 #include <wtf/OwnPtr.h>
35 #if USE(ACCELERATED_COMPOSITING)
36 class RenderLayerCompositor
;
39 class RenderView
: public RenderBlock
{
41 RenderView(Node
*, FrameView
*);
42 virtual ~RenderView();
44 virtual const char* renderName() const { return "RenderView"; }
46 virtual bool isRenderView() const { return true; }
48 virtual void layout();
49 virtual void calcWidth();
50 virtual void calcHeight();
51 virtual void calcPrefWidths();
53 int docHeight() const;
56 // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
57 int viewHeight() const;
58 int viewWidth() const;
60 float zoomFactor() const { return m_frameView
->frame() && m_frameView
->frame()->shouldApplyPageZoom() ? m_frameView
->frame()->zoomFactor() : 1.0f
; }
62 FrameView
* frameView() const { return m_frameView
; }
64 virtual bool hasOverhangingFloats() { return false; }
66 virtual void computeRectForRepaint(RenderBox
* repaintContainer
, IntRect
&, bool fixed
= false);
67 virtual void repaintViewRectangle(const IntRect
&, bool immediate
= false);
68 // Repaint the view, and all composited layers that intersect the given absolute rectangle.
69 // FIXME: ideally we'd never have to do this, if all repaints are container-relative.
70 virtual void repaintRectangleInViewAndCompositedLayers(const IntRect
&, bool immediate
= false);
72 virtual void paint(PaintInfo
&, int tx
, int ty
);
73 virtual void paintBoxDecorations(PaintInfo
&, int tx
, int ty
);
75 void setSelection(RenderObject
* start
, int startPos
, RenderObject
* end
, int endPos
);
76 void clearSelection();
77 virtual RenderObject
* selectionStart() const { return m_selectionStart
; }
78 virtual RenderObject
* selectionEnd() const { return m_selectionEnd
; }
80 bool printing() const;
81 void setPrintImages(bool enable
) { m_printImages
= enable
; }
82 bool printImages() const { return m_printImages
; }
83 void setTruncatedAt(int y
) { m_truncatedAt
= y
; m_bestTruncatedAt
= m_truncatorWidth
= 0; m_forcedPageBreak
= false; }
84 void setBestTruncatedAt(int y
, RenderBox
* forRenderer
, bool forcedBreak
= false);
85 int bestTruncatedAt() const { return m_bestTruncatedAt
; }
87 int truncatedAt() const { return m_truncatedAt
; }
89 virtual void absoluteRects(Vector
<IntRect
>&, int tx
, int ty
, bool topLevel
= true);
90 virtual void absoluteQuads(Vector
<FloatQuad
>&, bool topLevel
= true);
92 IntRect
selectionBounds(bool clipToVisibleContent
= true) const;
94 #if USE(ACCELERATED_COMPOSITING)
95 void setMaximalOutlineSize(int o
);
97 void setMaximalOutlineSize(int o
) { m_maximalOutlineSize
= o
; }
99 int maximalOutlineSize() const { return m_maximalOutlineSize
; }
101 virtual IntRect
viewRect() const;
103 virtual void selectionStartEnd(int& startPos
, int& endPos
) const;
105 IntRect
printRect() const { return m_printRect
; }
106 void setPrintRect(const IntRect
& r
) { m_printRect
= r
; }
108 void updateWidgetPositions();
109 void addWidget(RenderObject
*);
110 void removeWidget(RenderObject
*);
112 // layoutDelta is used transiently during layout to store how far an object has moved from its
113 // last layout location, in order to repaint correctly.
114 // If we're doing a full repaint m_layoutState will be 0, but in that case layoutDelta doesn't matter.
115 IntSize
layoutDelta() const
117 return m_layoutState
? m_layoutState
->m_layoutDelta
: IntSize();
119 void addLayoutDelta(const IntSize
& delta
)
122 m_layoutState
->m_layoutDelta
+= delta
;
125 bool doingFullRepaint() const { return m_frameView
->needsFullRepaint(); }
127 void pushLayoutState(RenderBox
* renderer
, const IntSize
& offset
)
129 if (doingFullRepaint())
131 // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
132 m_layoutState
= new (renderArena()) LayoutState(m_layoutState
, renderer
, offset
);
135 void pushLayoutState(RenderObject
*);
137 void popLayoutState()
139 if (doingFullRepaint())
141 LayoutState
* state
= m_layoutState
;
142 m_layoutState
= state
->m_next
;
143 state
->destroy(renderArena());
146 // Returns true if layoutState should be used for its cached offset and clip.
147 bool layoutStateEnabled() const { return m_layoutStateDisableCount
== 0 && m_layoutState
; }
148 LayoutState
* layoutState() const { return m_layoutState
; }
150 // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
151 // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
152 // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
153 // Note that even when disabled, LayoutState is still used to store layoutDelta.
154 void disableLayoutState() { m_layoutStateDisableCount
++; }
155 void enableLayoutState() { ASSERT(m_layoutStateDisableCount
> 0); m_layoutStateDisableCount
--; }
157 virtual void updateHitTestResult(HitTestResult
&, const IntPoint
&);
159 // Notifications that this view became visible in a window, or will be
160 // removed from the window.
161 void didMoveOnscreen();
162 void willMoveOffscreen();
164 #if USE(ACCELERATED_COMPOSITING)
165 RenderLayerCompositor
* compositor();
166 bool usesCompositing() const;
170 virtual void mapLocalToContainer(RenderBox
* repaintContainer
, bool useTransforms
, bool fixed
, TransformState
&) const;
171 virtual void mapAbsoluteToLocalPoint(bool fixed
, bool useTransforms
, TransformState
&) const;
174 bool shouldRepaint(const IntRect
& r
) const;
177 FrameView
* m_frameView
;
179 RenderObject
* m_selectionStart
;
180 RenderObject
* m_selectionEnd
;
181 int m_selectionStartPos
;
182 int m_selectionEndPos
;
184 // used to ignore viewport width when printing to the printer
188 int m_maximalOutlineSize
; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
189 IntRect m_printRect
; // Used when printing.
191 typedef HashSet
<RenderObject
*> RenderObjectSet
;
193 RenderObjectSet m_widgets
;
196 int m_bestTruncatedAt
;
197 int m_truncatorWidth
;
198 bool m_forcedPageBreak
;
199 LayoutState
* m_layoutState
;
200 unsigned m_layoutStateDisableCount
;
201 #if USE(ACCELERATED_COMPOSITING)
202 OwnPtr
<RenderLayerCompositor
> m_compositor
;
206 // Stack-based class to assist with LayoutState push/pop
207 class LayoutStateMaintainer
: Noncopyable
{
210 LayoutStateMaintainer(RenderView
* view
, RenderBox
* root
, IntSize offset
, bool disableState
= false)
212 , m_disabled(disableState
)
219 // ctor to maybe push later
220 LayoutStateMaintainer(RenderView
* view
)
228 ~LayoutStateMaintainer()
230 ASSERT(m_didStart
== m_didEnd
); // if this fires, it means that someone did a push(), but forgot to pop().
233 void push(RenderBox
* root
, IntSize offset
)
236 // We push state even if disabled, because we still need to store layoutDelta
237 m_view
->pushLayoutState(root
, offset
);
239 m_view
->disableLayoutState();
247 m_view
->popLayoutState();
249 m_view
->enableLayoutState();
254 bool didPush() const { return m_didStart
; }
258 bool m_disabled
: 1; // true if the offset and clip part of layoutState is disabled
259 bool m_didStart
: 1; // true if we did a push or disable
260 bool m_didEnd
: 1; // true if we popped or re-enabled
263 } // namespace WebCore
265 #endif // RenderView_h