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