1 | /* |
2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 | * Copyright (C) 2006, 2015-2016 Apple Inc. |
4 | * |
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. |
9 | * |
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. |
14 | * |
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. |
19 | * |
20 | */ |
21 | |
22 | #pragma once |
23 | |
24 | #include "FrameView.h" |
25 | #include "Region.h" |
26 | #include "RenderBlockFlow.h" |
27 | #include "RenderWidget.h" |
28 | #include "SelectionRangeData.h" |
29 | #include <memory> |
30 | #include <wtf/HashSet.h> |
31 | #include <wtf/ListHashSet.h> |
32 | |
33 | namespace WebCore { |
34 | |
35 | class ImageQualityController; |
36 | class RenderLayerCompositor; |
37 | class RenderLayoutState; |
38 | class RenderQuote; |
39 | |
40 | class RenderView final : public RenderBlockFlow { |
41 | WTF_MAKE_ISO_ALLOCATED(RenderView); |
42 | public: |
43 | RenderView(Document&, RenderStyle&&); |
44 | virtual ~RenderView(); |
45 | |
46 | WEBCORE_EXPORT bool hitTest(const HitTestRequest&, HitTestResult&); |
47 | bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&); |
48 | |
49 | const char* renderName() const override { return "RenderView" ; } |
50 | |
51 | bool requiresLayer() const override { return true; } |
52 | |
53 | bool isChildAllowed(const RenderObject&, const RenderStyle&) const override; |
54 | |
55 | void layout() override; |
56 | void updateLogicalWidth() override; |
57 | LogicalExtentComputedValues computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop) const override; |
58 | |
59 | LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const override; |
60 | |
61 | // The same as the FrameView's layoutHeight/layoutWidth but with null check guards. |
62 | int viewHeight() const; |
63 | int viewWidth() const; |
64 | int viewLogicalWidth() const { return style().isHorizontalWritingMode() ? viewWidth() : viewHeight(); } |
65 | int viewLogicalHeight() const; |
66 | |
67 | LayoutUnit clientLogicalWidthForFixedPosition() const; |
68 | LayoutUnit clientLogicalHeightForFixedPosition() const; |
69 | |
70 | float zoomFactor() const; |
71 | |
72 | FrameView& frameView() const { return m_frameView; } |
73 | |
74 | LayoutRect visualOverflowRect() const override; |
75 | Optional<LayoutRect> computeVisibleRectInContainer(const LayoutRect&, const RenderLayerModelObject* container, VisibleRectContext) const override; |
76 | void repaintRootContents(); |
77 | void repaintViewRectangle(const LayoutRect&) const; |
78 | void repaintViewAndCompositedLayers(); |
79 | |
80 | void paint(PaintInfo&, const LayoutPoint&) override; |
81 | void paintBoxDecorations(PaintInfo&, const LayoutPoint&) override; |
82 | // Return the renderer whose background style is used to paint the root background. |
83 | RenderElement* rendererForRootBackground() const; |
84 | |
85 | SelectionRangeData& selection() { return m_selection; } |
86 | |
87 | bool printing() const; |
88 | |
89 | void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const override; |
90 | void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const override; |
91 | |
92 | LayoutRect viewRect() const; |
93 | |
94 | void updateHitTestResult(HitTestResult&, const LayoutPoint&) override; |
95 | |
96 | void setPageLogicalSize(LayoutSize); |
97 | LayoutUnit pageOrViewLogicalHeight() const; |
98 | |
99 | // This method is used to assign a page number only when pagination modes have |
100 | // a block progression. This happens with vertical-rl books for example, but it |
101 | // doesn't happen for normal horizontal-tb books. This is a very specialized |
102 | // function and should not be mistaken for a general page number API. |
103 | unsigned pageNumberForBlockProgressionOffset(int offset) const; |
104 | |
105 | unsigned pageCount() const; |
106 | |
107 | // FIXME: These functions are deprecated. No code should be added that uses these. |
108 | int bestTruncatedAt() const { return m_legacyPrinting.m_bestTruncatedAt; } |
109 | void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false); |
110 | int truncatedAt() const { return m_legacyPrinting.m_truncatedAt; } |
111 | void setTruncatedAt(int y) |
112 | { |
113 | m_legacyPrinting.m_truncatedAt = y; |
114 | m_legacyPrinting.m_bestTruncatedAt = 0; |
115 | m_legacyPrinting.m_truncatorWidth = 0; |
116 | m_legacyPrinting.m_forcedPageBreak = false; |
117 | } |
118 | const IntRect& printRect() const { return m_legacyPrinting.m_printRect; } |
119 | void setPrintRect(const IntRect& r) { m_legacyPrinting.m_printRect = r; } |
120 | // End deprecated functions. |
121 | |
122 | // Notification that this view moved into or out of a native window. |
123 | void setIsInWindow(bool); |
124 | |
125 | WEBCORE_EXPORT RenderLayerCompositor& compositor(); |
126 | WEBCORE_EXPORT bool usesCompositing() const; |
127 | |
128 | bool usesFirstLineRules() const { return m_usesFirstLineRules; } |
129 | bool usesFirstLetterRules() const { return m_usesFirstLetterRules; } |
130 | void setUsesFirstLineRules(bool value) { m_usesFirstLineRules = value; } |
131 | void setUsesFirstLetterRules(bool value) { m_usesFirstLetterRules = value; } |
132 | |
133 | WEBCORE_EXPORT IntRect unscaledDocumentRect() const; |
134 | LayoutRect unextendedBackgroundRect() const; |
135 | LayoutRect backgroundRect() const; |
136 | |
137 | WEBCORE_EXPORT IntRect documentRect() const; |
138 | |
139 | // Renderer that paints the root background has background-images which all have background-attachment: fixed. |
140 | bool rootBackgroundIsEntirelyFixed() const; |
141 | |
142 | void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override; |
143 | |
144 | IntSize viewportSizeForCSSViewportUnits() const; |
145 | |
146 | bool hasQuotesNeedingUpdate() const { return m_hasQuotesNeedingUpdate; } |
147 | void setHasQuotesNeedingUpdate(bool b) { m_hasQuotesNeedingUpdate = b; } |
148 | |
149 | // FIXME: This is a work around because the current implementation of counters |
150 | // requires walking the entire tree repeatedly and most pages don't actually use either |
151 | // feature so we shouldn't take the performance hit when not needed. Long term we should |
152 | // rewrite the counter code. |
153 | void addRenderCounter() { m_renderCounterCount++; } |
154 | void removeRenderCounter() { ASSERT(m_renderCounterCount > 0); m_renderCounterCount--; } |
155 | bool hasRenderCounters() { return m_renderCounterCount; } |
156 | |
157 | ImageQualityController& imageQualityController(); |
158 | |
159 | void setHasSoftwareFilters(bool hasSoftwareFilters) { m_hasSoftwareFilters = hasSoftwareFilters; } |
160 | bool hasSoftwareFilters() const { return m_hasSoftwareFilters; } |
161 | |
162 | uint64_t rendererCount() const { return m_rendererCount; } |
163 | void didCreateRenderer() { ++m_rendererCount; } |
164 | void didDestroyRenderer() { --m_rendererCount; } |
165 | |
166 | void updateVisibleViewportRect(const IntRect&); |
167 | void registerForVisibleInViewportCallback(RenderElement&); |
168 | void unregisterForVisibleInViewportCallback(RenderElement&); |
169 | void resumePausedImageAnimationsIfNeeded(const IntRect& visibleRect); |
170 | void addRendererWithPausedImageAnimations(RenderElement&, CachedImage&); |
171 | void removeRendererWithPausedImageAnimations(RenderElement&); |
172 | void removeRendererWithPausedImageAnimations(RenderElement&, CachedImage&); |
173 | |
174 | class RepaintRegionAccumulator { |
175 | WTF_MAKE_NONCOPYABLE(RepaintRegionAccumulator); |
176 | public: |
177 | RepaintRegionAccumulator(RenderView*); |
178 | ~RepaintRegionAccumulator(); |
179 | |
180 | private: |
181 | WeakPtr<RenderView> m_rootView; |
182 | bool m_wasAccumulatingRepaintRegion; |
183 | }; |
184 | |
185 | void scheduleLazyRepaint(RenderBox&); |
186 | void unscheduleLazyRepaint(RenderBox&); |
187 | |
188 | void protectRenderWidgetUntilLayoutIsDone(RenderWidget& widget) { m_protectedRenderWidgets.append(&widget); } |
189 | void releaseProtectedRenderWidgets() { m_protectedRenderWidgets.clear(); } |
190 | |
191 | #if ENABLE(CSS_SCROLL_SNAP) |
192 | void registerBoxWithScrollSnapPositions(const RenderBox&); |
193 | void unregisterBoxWithScrollSnapPositions(const RenderBox&); |
194 | const HashSet<const RenderBox*>& boxesWithScrollSnapPositions() { return m_boxesWithScrollSnapPositions; } |
195 | #endif |
196 | |
197 | #if !ASSERT_DISABLED |
198 | bool inHitTesting() const { return m_inHitTesting; } |
199 | #endif |
200 | |
201 | protected: |
202 | void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags, bool* wasFixed) const override; |
203 | const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const override; |
204 | void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const override; |
205 | bool requiresColumns(int desiredColumnCount) const override; |
206 | |
207 | private: |
208 | void computeColumnCountAndWidth() override; |
209 | |
210 | bool shouldRepaint(const LayoutRect&) const; |
211 | void flushAccumulatedRepaintRegion() const; |
212 | |
213 | void layoutContent(const RenderLayoutState&); |
214 | |
215 | bool isScrollableOrRubberbandableBox() const override; |
216 | |
217 | private: |
218 | FrameView& m_frameView; |
219 | |
220 | // Include this RenderView. |
221 | uint64_t m_rendererCount { 1 }; |
222 | |
223 | mutable std::unique_ptr<Region> m_accumulatedRepaintRegion; |
224 | SelectionRangeData m_selection; |
225 | |
226 | // FIXME: Only used by embedded WebViews inside AppKit NSViews. Find a way to remove. |
227 | struct LegacyPrinting { |
228 | int m_bestTruncatedAt { 0 }; |
229 | int m_truncatedAt { 0 }; |
230 | int m_truncatorWidth { 0 }; |
231 | IntRect m_printRect; |
232 | bool m_forcedPageBreak { false }; |
233 | }; |
234 | LegacyPrinting m_legacyPrinting; |
235 | // End deprecated members. |
236 | |
237 | bool shouldUsePrintingLayout() const; |
238 | |
239 | void lazyRepaintTimerFired(); |
240 | |
241 | Timer m_lazyRepaintTimer; |
242 | HashSet<RenderBox*> m_renderersNeedingLazyRepaint; |
243 | |
244 | std::unique_ptr<ImageQualityController> m_imageQualityController; |
245 | Optional<LayoutSize> m_pageLogicalSize; |
246 | bool m_pageLogicalHeightChanged { false }; |
247 | std::unique_ptr<RenderLayerCompositor> m_compositor; |
248 | |
249 | bool m_hasQuotesNeedingUpdate { false }; |
250 | |
251 | unsigned m_renderCounterCount { 0 }; |
252 | |
253 | bool m_hasSoftwareFilters { false }; |
254 | bool m_usesFirstLineRules { false }; |
255 | bool m_usesFirstLetterRules { false }; |
256 | #if !ASSERT_DISABLED |
257 | bool m_inHitTesting { false }; |
258 | #endif |
259 | |
260 | HashMap<RenderElement*, Vector<CachedImage*>> m_renderersWithPausedImageAnimation; |
261 | HashSet<RenderElement*> m_visibleInViewportRenderers; |
262 | Vector<RefPtr<RenderWidget>> m_protectedRenderWidgets; |
263 | |
264 | #if ENABLE(CSS_SCROLL_SNAP) |
265 | HashSet<const RenderBox*> m_boxesWithScrollSnapPositions; |
266 | #endif |
267 | }; |
268 | |
269 | } // namespace WebCore |
270 | |
271 | SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderView, isRenderView()) |
272 | |