2 Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 (C) 1998 Waldo Bastian (bastian@kde.org)
4 (C) 1998, 1999 Torben Weis (weis@kde.org)
5 (C) 1999 Lars Knoll (knoll@kde.org)
6 (C) 1999 Antti Koivisto (koivisto@kde.org)
7 Copyright (C) 2004-2017 Apple Inc. All rights reserved.
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
27 #include "AdjustViewSizeOrNot.h"
29 #include "ContainerNode.h"
30 #include "LayoutContext.h"
31 #include "LayoutMilestones.h"
32 #include "LayoutRect.h"
33 #include "Pagination.h"
34 #include "PaintPhase.h"
35 #include "RenderPtr.h"
36 #include "ScrollView.h"
37 #include "TiledBacking.h"
39 #include <wtf/Forward.h>
40 #include <wtf/Function.h>
41 #include <wtf/HashSet.h>
42 #include <wtf/IsoMalloc.h>
43 #include <wtf/ListHashSet.h>
44 #include <wtf/text/WTFString.h>
52 class HTMLFrameOwnerElement;
58 class RenderEmbeddedObject;
61 class RenderScrollbarPart;
66 enum class FrameFlattening;
67 enum class SelectionRevealMode;
69 Pagination::Mode paginationModeForRenderStyle(const RenderStyle&);
71 class FrameView final : public ScrollView {
72 WTF_MAKE_ISO_ALLOCATED(FrameView);
74 friend class RenderView;
75 friend class Internals;
76 friend class LayoutContext;
78 WEBCORE_EXPORT static Ref<FrameView> create(Frame&);
79 static Ref<FrameView> create(Frame&, const IntSize& initialSize);
83 HostWindow* hostWindow() const final;
85 WEBCORE_EXPORT void invalidateRect(const IntRect&) final;
86 void setFrameRect(const IntRect&) final;
88 bool scheduleAnimation() final;
90 Frame& frame() const { return m_frame; }
92 WEBCORE_EXPORT RenderView* renderView() const;
94 int mapFromLayoutToCSSUnits(LayoutUnit) const;
95 LayoutUnit mapFromCSSToLayoutUnits(int) const;
97 LayoutUnit marginWidth() const { return m_margins.width(); } // -1 means default
98 LayoutUnit marginHeight() const { return m_margins.height(); } // -1 means default
99 void setMarginWidth(LayoutUnit);
100 void setMarginHeight(LayoutUnit);
102 WEBCORE_EXPORT void setCanHaveScrollbars(bool) final;
103 WEBCORE_EXPORT void updateCanHaveScrollbars();
105 Ref<Scrollbar> createScrollbar(ScrollbarOrientation) final;
107 bool avoidScrollbarCreation() const final;
109 void setContentsSize(const IntSize&) final;
110 void updateContentsSize() final;
112 const LayoutContext& layoutContext() const { return m_layoutContext; }
113 LayoutContext& layoutContext() { return m_layoutContext; }
115 WEBCORE_EXPORT bool didFirstLayout() const;
116 void queuePostLayoutCallback(WTF::Function<void ()>&&);
118 WEBCORE_EXPORT bool needsLayout() const;
119 WEBCORE_EXPORT void setNeedsLayout();
120 void setViewportConstrainedObjectsNeedLayout();
122 WEBCORE_EXPORT bool renderedCharactersExceed(unsigned threshold);
124 void scheduleSelectionUpdate();
127 bool useCustomFixedPositionLayoutRect() const;
128 IntRect customFixedPositionLayoutRect() const { return m_customFixedPositionLayoutRect; }
129 WEBCORE_EXPORT void setCustomFixedPositionLayoutRect(const IntRect&);
130 bool updateFixedPositionLayoutRect();
132 IntSize customSizeForResizeEvent() const { return m_customSizeForResizeEvent; }
133 WEBCORE_EXPORT void setCustomSizeForResizeEvent(IntSize);
135 WEBCORE_EXPORT void setScrollVelocity(double horizontalVelocity, double verticalVelocity, double scaleChangeRate, MonotonicTime timestamp);
137 bool useCustomFixedPositionLayoutRect() const { return false; }
140 void willRecalcStyle();
141 bool updateCompositingLayersAfterStyleChange();
142 void updateCompositingLayersAfterLayout();
144 void clearBackingStores();
146 // Called when changes to the GraphicsLayer hierarchy have to be synchronized with
147 // content rendered via the normal painting path.
148 void setNeedsOneShotDrawingSynchronization();
150 WEBCORE_EXPORT GraphicsLayer* graphicsLayerForPlatformWidget(PlatformWidget);
151 WEBCORE_EXPORT void scheduleLayerFlushAllowingThrottling();
153 WEBCORE_EXPORT TiledBacking* tiledBacking() const final;
155 // In the future when any ScrollableArea can have a node in th ScrollingTree, this should
156 // become a virtual function on ScrollableArea.
157 uint64_t scrollLayerID() const;
158 ScrollableArea* scrollableAreaForScrollLayerID(uint64_t) const;
160 bool hasCompositedContent() const;
161 WEBCORE_EXPORT void enterCompositingMode();
162 WEBCORE_EXPORT bool isEnclosedInCompositingLayer() const;
164 // Only used with accelerated compositing, but outside the #ifdef to make linkage easier.
165 // Returns true if the flush was completed.
166 WEBCORE_EXPORT bool flushCompositingStateIncludingSubframes();
168 // Returns true when a paint with the PaintBehaviorFlattenCompositingLayers flag set gives
169 // a faithful representation of the content.
170 WEBCORE_EXPORT bool isSoftwareRenderable() const;
172 void setIsInWindow(bool);
174 void resetScrollbars();
175 void resetScrollbarsAndClearContentsSize();
176 void prepareForDetach();
177 void detachCustomScrollbars();
178 WEBCORE_EXPORT void recalculateScrollbarOverlayStyle();
182 WEBCORE_EXPORT bool isTransparent() const;
183 WEBCORE_EXPORT void setTransparent(bool isTransparent);
185 // True if the FrameView is not transparent, and the base background color is opaque.
186 bool hasOpaqueBackground() const;
188 WEBCORE_EXPORT Color baseBackgroundColor() const;
189 WEBCORE_EXPORT void setBaseBackgroundColor(const Color&);
190 void updateBackgroundRecursively(const Color&, bool);
192 enum ExtendedBackgroundModeFlags {
193 ExtendedBackgroundModeNone = 0,
194 ExtendedBackgroundModeVertical = 1 << 0,
195 ExtendedBackgroundModeHorizontal = 1 << 1,
196 ExtendedBackgroundModeAll = ExtendedBackgroundModeVertical | ExtendedBackgroundModeHorizontal,
198 typedef unsigned ExtendedBackgroundMode;
200 void updateExtendBackgroundIfNecessary();
201 void updateTilesForExtendedBackgroundMode(ExtendedBackgroundMode);
202 ExtendedBackgroundMode calculateExtendedBackgroundMode() const;
204 bool hasExtendedBackgroundRectForPainting() const;
205 IntRect extendedBackgroundRectForPainting() const;
207 bool shouldUpdateWhileOffscreen() const;
208 WEBCORE_EXPORT void setShouldUpdateWhileOffscreen(bool);
209 bool shouldUpdate() const;
211 WEBCORE_EXPORT void adjustViewSize();
213 WEBCORE_EXPORT void setViewportSizeForCSSViewportUnits(IntSize);
214 IntSize viewportSizeForCSSViewportUnits() const;
216 IntRect windowClipRect() const final;
217 WEBCORE_EXPORT IntRect windowClipRectForFrameOwner(const HTMLFrameOwnerElement*, bool clipToLayerContents) const;
219 float visibleContentScaleFactor() const final;
221 #if USE(COORDINATED_GRAPHICS)
222 WEBCORE_EXPORT void setFixedVisibleContentRect(const IntRect&) final;
224 WEBCORE_EXPORT void setScrollPosition(const ScrollPosition&) final;
225 void restoreScrollbar();
226 void scheduleScrollToFocusedElement(SelectionRevealMode);
227 void scrollToFocusedElementImmediatelyIfNeeded();
228 void updateLayerPositionsAfterScrolling() final;
229 void updateCompositingLayersAfterScrolling() final;
230 bool requestScrollPositionUpdate(const ScrollPosition&) final;
231 bool isRubberBandInProgress() const final;
232 WEBCORE_EXPORT ScrollPosition minimumScrollPosition() const final;
233 WEBCORE_EXPORT ScrollPosition maximumScrollPosition() const final;
235 // The scrollOrigin, scrollPosition, minimumScrollPosition and maximumScrollPosition are all affected by frame scale,
236 // but layoutViewport computations require unscaled scroll positions.
237 ScrollPosition unscaledMinimumScrollPosition() const;
238 ScrollPosition unscaledMaximumScrollPosition() const;
240 IntPoint unscaledScrollOrigin() const;
242 WEBCORE_EXPORT LayoutPoint minStableLayoutViewportOrigin() const;
243 WEBCORE_EXPORT LayoutPoint maxStableLayoutViewportOrigin() const;
245 enum class TriggerLayoutOrNot {
249 // This origin can be overridden by setLayoutViewportOverrideRect.
250 void setBaseLayoutViewportOrigin(LayoutPoint, TriggerLayoutOrNot = TriggerLayoutOrNot::Yes);
251 // This size can be overridden by setLayoutViewportOverrideRect.
252 WEBCORE_EXPORT LayoutSize baseLayoutViewportSize() const;
254 // If set, overrides the default "m_layoutViewportOrigin, size of initial containing block" rect.
255 // Used with delegated scrolling (i.e. iOS).
256 WEBCORE_EXPORT void setLayoutViewportOverrideRect(std::optional<LayoutRect>, TriggerLayoutOrNot = TriggerLayoutOrNot::Yes);
258 WEBCORE_EXPORT void setVisualViewportOverrideRect(std::optional<LayoutRect>);
260 // These are in document coordinates, unaffected by page scale (but affected by zooming).
261 WEBCORE_EXPORT LayoutRect layoutViewportRect() const;
262 WEBCORE_EXPORT LayoutRect visualViewportRect() const;
264 static LayoutRect visibleDocumentRect(const FloatRect& visibleContentRect, float headerHeight, float footerHeight, const FloatSize& totalContentsSize, float pageScaleFactor);
266 // This is different than visibleContentRect() in that it ignores negative (or overly positive)
267 // offsets from rubber-banding, and it takes zooming into account.
268 LayoutRect viewportConstrainedVisibleContentRect() const;
270 LayoutRect rectForFixedPositionLayout() const;
272 void viewportContentsChanged();
273 WEBCORE_EXPORT void resumeVisibleImageAnimationsIncludingSubframes();
275 String mediaType() const;
276 WEBCORE_EXPORT void setMediaType(const String&);
277 void adjustMediaTypeForPrinting(bool printing);
279 void setCannotBlitToWindow();
280 void setIsOverlapped(bool);
281 void setContentIsOpaque(bool);
283 void addSlowRepaintObject(RenderElement&);
284 void removeSlowRepaintObject(RenderElement&);
285 bool hasSlowRepaintObject(const RenderElement& renderer) const { return m_slowRepaintObjects && m_slowRepaintObjects->contains(&renderer); }
286 bool hasSlowRepaintObjects() const { return m_slowRepaintObjects && m_slowRepaintObjects->size(); }
288 // Includes fixed- and sticky-position objects.
289 typedef HashSet<RenderElement*> ViewportConstrainedObjectSet;
290 void addViewportConstrainedObject(RenderElement*);
291 void removeViewportConstrainedObject(RenderElement*);
292 const ViewportConstrainedObjectSet* viewportConstrainedObjects() const { return m_viewportConstrainedObjects.get(); }
293 bool hasViewportConstrainedObjects() const { return m_viewportConstrainedObjects && m_viewportConstrainedObjects->size() > 0; }
295 float frameScaleFactor() const;
297 // Functions for querying the current scrolled position, negating the effects of overhang
298 // and adjusting for page scale.
299 LayoutPoint scrollPositionForFixedPosition() const;
301 // Static function can be called from another thread.
302 static LayoutPoint scrollPositionForFixedPosition(const LayoutRect& visibleContentRect, const LayoutSize& totalContentsSize, const LayoutPoint& scrollPosition, const LayoutPoint& scrollOrigin, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame, ScrollBehaviorForFixedElements, int headerHeight, int footerHeight);
304 WEBCORE_EXPORT static LayoutSize expandedLayoutViewportSize(const LayoutSize& baseLayoutViewportSize, const LayoutSize& documentSize, double heightExpansionFactor);
306 enum class LayoutViewportConstraint { ConstrainedToDocumentRect, Unconstrained };
307 WEBCORE_EXPORT static LayoutRect computeUpdatedLayoutViewportRect(const LayoutRect& layoutViewport, const LayoutRect& documentRect, const LayoutSize& unobscuredContentSize, const LayoutRect& unobscuredContentRect, const LayoutSize& baseLayoutViewportSize, const LayoutPoint& stableLayoutViewportOriginMin, const LayoutPoint& stableLayoutViewportOriginMax, LayoutViewportConstraint);
309 WEBCORE_EXPORT static LayoutPoint computeLayoutViewportOrigin(const LayoutRect& visualViewport, const LayoutPoint& stableLayoutViewportOriginMin, const LayoutPoint& stableLayoutViewportOriginMax, const LayoutRect& layoutViewport, ScrollBehaviorForFixedElements);
311 // These layers are positioned differently when there is a topContentInset, a header, or a footer. These value need to be computed
312 // on both the main thread and the scrolling thread.
313 static float yPositionForInsetClipLayer(const FloatPoint& scrollPosition, float topContentInset);
314 WEBCORE_EXPORT static FloatPoint positionForRootContentLayer(const FloatPoint& scrollPosition, const FloatPoint& scrollOrigin, float topContentInset, float headerHeight);
315 WEBCORE_EXPORT FloatPoint positionForRootContentLayer() const;
317 static float yPositionForHeaderLayer(const FloatPoint& scrollPosition, float topContentInset);
318 static float yPositionForFooterLayer(const FloatPoint& scrollPosition, float topContentInset, float totalContentsHeight, float footerHeight);
321 WEBCORE_EXPORT LayoutRect viewportConstrainedObjectsRect() const;
322 // Static function can be called from another thread.
323 WEBCORE_EXPORT static LayoutRect rectForViewportConstrainedObjects(const LayoutRect& visibleContentRect, const LayoutSize& totalContentsSize, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame, ScrollBehaviorForFixedElements);
326 bool fixedElementsLayoutRelativeToFrame() const;
328 WEBCORE_EXPORT void disableLayerFlushThrottlingTemporarilyForInteraction();
329 bool speculativeTilingEnabled() const { return m_speculativeTilingEnabled; }
330 void loadProgressingStatusChanged();
332 #if ENABLE(DASHBOARD_SUPPORT)
333 void updateAnnotatedRegions();
335 WEBCORE_EXPORT void updateControlTints();
337 WEBCORE_EXPORT bool wasScrolledByUser() const;
338 WEBCORE_EXPORT void setWasScrolledByUser(bool);
340 bool safeToPropagateScrollToParent() const { return m_safeToPropagateScrollToParent; }
341 void setSafeToPropagateScrollToParent(bool isSafe) { m_safeToPropagateScrollToParent = isSafe; }
343 void addEmbeddedObjectToUpdate(RenderEmbeddedObject&);
344 void removeEmbeddedObjectToUpdate(RenderEmbeddedObject&);
346 WEBCORE_EXPORT void paintContents(GraphicsContext&, const IntRect& dirtyRect, SecurityOriginPaintPolicy = SecurityOriginPaintPolicy::AnyOrigin) final;
348 struct PaintingState {
349 PaintBehavior paintBehavior;
350 bool isTopLevelPainter;
351 bool isFlatteningPaintOfRootFrame;
354 , isTopLevelPainter(false)
355 , isFlatteningPaintOfRootFrame(false)
360 void willPaintContents(GraphicsContext&, const IntRect& dirtyRect, PaintingState&);
361 void didPaintContents(GraphicsContext&, const IntRect& dirtyRect, PaintingState&);
364 WEBCORE_EXPORT void didReplaceMultipartContent();
367 WEBCORE_EXPORT void setPaintBehavior(PaintBehavior);
368 WEBCORE_EXPORT PaintBehavior paintBehavior() const;
369 bool isPainting() const;
370 bool hasEverPainted() const { return !!m_lastPaintTime; }
371 void setLastPaintTime(MonotonicTime lastPaintTime) { m_lastPaintTime = lastPaintTime; }
372 WEBCORE_EXPORT void setNodeToDraw(Node*);
374 enum SelectionInSnapshot { IncludeSelection, ExcludeSelection };
375 enum CoordinateSpaceForSnapshot { DocumentCoordinates, ViewCoordinates };
376 WEBCORE_EXPORT void paintContentsForSnapshot(GraphicsContext&, const IntRect& imageRect, SelectionInSnapshot shouldPaintSelection, CoordinateSpaceForSnapshot);
378 void paintOverhangAreas(GraphicsContext&, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect) final;
379 void paintScrollCorner(GraphicsContext&, const IntRect& cornerRect) final;
380 void paintScrollbar(GraphicsContext&, Scrollbar&, const IntRect&) final;
382 WEBCORE_EXPORT Color documentBackgroundColor() const;
384 bool isInChildFrameWithFrameFlattening() const;
386 void startDisallowingLayout() { layoutContext().startDisallowingLayout(); }
387 void endDisallowingLayout() { layoutContext().endDisallowingLayout(); }
389 static MonotonicTime currentPaintTimeStamp() { return sCurrentPaintTimeStamp; } // returns 0 if not painting
391 WEBCORE_EXPORT void updateLayoutAndStyleIfNeededRecursive();
393 void incrementVisuallyNonEmptyCharacterCount(unsigned);
394 void incrementVisuallyNonEmptyPixelCount(const IntSize&);
395 void updateIsVisuallyNonEmpty();
396 bool isVisuallyNonEmpty() const { return m_isVisuallyNonEmpty; }
397 WEBCORE_EXPORT void enableAutoSizeMode(bool enable, const IntSize& minSize, const IntSize& maxSize);
398 WEBCORE_EXPORT void setAutoSizeFixedMinimumHeight(int);
399 IntSize autoSizingIntrinsicContentSize() const { return m_autoSizeContentSize; }
401 WEBCORE_EXPORT void forceLayout(bool allowSubtreeLayout = false);
402 WEBCORE_EXPORT void forceLayoutForPagination(const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkFactor, AdjustViewSizeOrNot);
404 // FIXME: This method is retained because of embedded WebViews in AppKit. When a WebView is embedded inside
405 // some enclosing view with auto-pagination, no call happens to resize the view. The new pagination model
406 // needs the view to resize as a result of the breaks, but that means that the enclosing view has to potentially
407 // resize around that view. Auto-pagination uses the bounds of the actual view that's being printed to determine
408 // the edges of the print operation, so the resize is necessary if the enclosing view's bounds depend on the
409 // web document's bounds.
411 // This is already a problem if the view needs to be a different size because of printer fonts or because of print stylesheets.
412 // Mail/Dictionary work around this problem by using the _layoutForPrinting SPI
413 // to at least get print stylesheets and printer fonts into play, but since WebKit doesn't know about the page offset or
414 // page size, it can't actually paginate correctly during _layoutForPrinting.
416 // We can eventually move Mail to a newer SPI that would let them opt in to the layout-time pagination model,
417 // but that doesn't solve the general problem of how other AppKit views could opt in to the better model.
419 // NO OTHER PLATFORM BESIDES MAC SHOULD USE THIS METHOD.
420 WEBCORE_EXPORT void adjustPageHeightDeprecated(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
422 bool scrollToFragment(const URL&);
423 bool scrollToAnchor(const String&);
424 void maintainScrollPositionAtAnchor(ContainerNode*);
425 WEBCORE_EXPORT void scrollElementToRect(const Element&, const IntRect&);
427 // Coordinate systems:
430 // Top left is top left of the FrameView/ScrollView/Widget. Size is Widget::boundsRect().size().
433 // Relative to ScrollView's scrolled contents, including headers and footers. Size is totalContentsSize().
436 // Relative to ScrollView's scrolled contents, excluding headers and footers, so top left is top left of the scroll view's
437 // document, and size is contentsSize().
440 // Relative to the document's scroll origin (non-zero for RTL documents), but affected by page zoom and page scale. Mostly used
441 // in rendering code.
444 // Relative to the document's scroll origin, but not affected by page zoom or page scale. Size is equivalent to CSS pixel dimensions.
445 // FIXME: some uses are affected by page zoom (e.g. layout and visual viewports).
448 // Relative to the visible part of the document (or, more strictly, the layout viewport rect), and with the same scaling
449 // as Document coordinates, i.e. matching CSS pixels. Affected by scroll origin.
452 // Similar to client coordinates, but affected by page zoom (but not page scale).
455 // Methods to convert points and rects between the coordinate space of the renderer, and this view.
456 WEBCORE_EXPORT IntRect convertFromRendererToContainingView(const RenderElement*, const IntRect&) const;
457 WEBCORE_EXPORT IntRect convertFromContainingViewToRenderer(const RenderElement*, const IntRect&) const;
458 WEBCORE_EXPORT IntPoint convertFromRendererToContainingView(const RenderElement*, const IntPoint&) const;
459 WEBCORE_EXPORT IntPoint convertFromContainingViewToRenderer(const RenderElement*, const IntPoint&) const;
461 // Override ScrollView methods to do point conversion via renderers, in order to take transforms into account.
462 IntRect convertToContainingView(const IntRect&) const final;
463 IntRect convertFromContainingView(const IntRect&) const final;
464 IntPoint convertToContainingView(const IntPoint&) const final;
465 IntPoint convertFromContainingView(const IntPoint&) const final;
467 float documentToAbsoluteScaleFactor(std::optional<float> effectiveZoom = std::nullopt) const;
468 float absoluteToDocumentScaleFactor(std::optional<float> effectiveZoom = std::nullopt) const;
470 FloatRect absoluteToDocumentRect(FloatRect, std::optional<float> effectiveZoom = std::nullopt) const;
471 FloatPoint absoluteToDocumentPoint(FloatPoint, std::optional<float> effectiveZoom = std::nullopt) const;
473 FloatSize documentToClientOffset() const;
474 FloatRect documentToClientRect(FloatRect) const;
475 FloatPoint documentToClientPoint(FloatPoint) const;
476 WEBCORE_EXPORT FloatRect clientToDocumentRect(FloatRect) const;
477 WEBCORE_EXPORT FloatPoint clientToDocumentPoint(FloatPoint) const;
479 FloatPoint layoutViewportToAbsolutePoint(FloatPoint) const;
481 // Unlike client coordinates, layout viewport coordinates are affected by page zoom.
482 FloatPoint clientToLayoutViewportPoint(FloatPoint) const;
484 bool isFrameViewScrollCorner(const RenderScrollbarPart& scrollCorner) const { return m_scrollCorner.get() == &scrollCorner; }
486 // isScrollable() takes an optional Scrollability parameter that allows the caller to define what they mean by 'scrollable.'
487 // Most callers are interested in the default value, Scrollability::Scrollable, which means that there is actually content
488 // to scroll to, and a scrollbar that will allow you to access it. In some cases, callers want to know if the FrameView is allowed
489 // to rubber-band, which the main frame might be allowed to do even if there is no content to scroll to. In that case,
490 // callers use Scrollability::ScrollableOrRubberbandable.
491 enum class Scrollability { Scrollable, ScrollableOrRubberbandable };
492 WEBCORE_EXPORT bool isScrollable(Scrollability definitionOfScrollable = Scrollability::Scrollable);
494 bool isScrollableOrRubberbandable() final;
495 bool hasScrollableOrRubberbandableAncestor() final;
497 enum ScrollbarModesCalculationStrategy { RulesFromWebContentOnly, AnyRule };
498 void calculateScrollbarModesForLayout(ScrollbarMode& hMode, ScrollbarMode& vMode, ScrollbarModesCalculationStrategy = AnyRule);
500 IntPoint lastKnownMousePosition() const final;
501 bool isHandlingWheelEvent() const final;
502 bool shouldSetCursor() const;
504 // FIXME: Remove this method once plugin loading is decoupled from layout.
505 void flushAnyPendingPostLayoutTasks();
507 bool shouldSuspendScrollAnimations() const final;
508 void scrollbarStyleChanged(ScrollbarStyle, bool forceUpdate) override;
510 RenderBox* embeddedContentBox() const;
512 WEBCORE_EXPORT void setTracksRepaints(bool);
513 bool isTrackingRepaints() const { return m_isTrackingRepaints; }
514 WEBCORE_EXPORT void resetTrackedRepaints();
515 const Vector<FloatRect>& trackedRepaintRects() const { return m_trackedRepaintRects; }
516 String trackedRepaintRectsAsText() const;
518 typedef HashSet<ScrollableArea*> ScrollableAreaSet;
519 // Returns whether the scrollable area has just been newly added.
520 WEBCORE_EXPORT bool addScrollableArea(ScrollableArea*);
521 // Returns whether the scrollable area has just been removed.
522 WEBCORE_EXPORT bool removeScrollableArea(ScrollableArea*);
523 bool containsScrollableArea(ScrollableArea*) const;
524 const ScrollableAreaSet* scrollableAreas() const { return m_scrollableAreas.get(); }
526 WEBCORE_EXPORT void addChild(Widget&) final;
527 WEBCORE_EXPORT void removeChild(Widget&) final;
529 // This function exists for ports that need to handle wheel events manually.
530 // On Mac WebKit1 the underlying NSScrollView just does the scrolling, but on most other platforms
531 // we need this function in order to do the scroll ourselves.
532 bool wheelEvent(const PlatformWheelEvent&);
534 WEBCORE_EXPORT void setScrollingPerformanceLoggingEnabled(bool);
536 // Page and FrameView both store a Pagination value. Page::pagination() is set only by API,
537 // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all
538 // FrameViews in the page cache, but FrameView::pagination() only affects the current
539 // FrameView. FrameView::pagination() will return m_pagination if it has been set. Otherwise,
540 // it will return Page::pagination() since currently there are no callers that need to
541 // distinguish between the two.
542 const Pagination& pagination() const;
543 void setPagination(const Pagination&);
545 bool inProgrammaticScroll() const final { return m_inProgrammaticScroll; }
546 void setInProgrammaticScroll(bool programmaticScroll) { m_inProgrammaticScroll = programmaticScroll; }
548 #if ENABLE(CSS_DEVICE_ADAPTATION)
549 IntSize initialViewportSize() const { return m_initialViewportSize; }
550 void setInitialViewportSize(const IntSize& size) { m_initialViewportSize = size; }
553 bool isActive() const final;
554 bool forceUpdateScrollbarsOnMainThreadForPerformanceTesting() const final;
556 #if ENABLE(RUBBER_BANDING)
557 WEBCORE_EXPORT GraphicsLayer* setWantsLayerForTopOverHangArea(bool) const;
558 WEBCORE_EXPORT GraphicsLayer* setWantsLayerForBottomOverHangArea(bool) const;
561 // This function "smears" the "position:fixed" uninflatedBounds for scrolling, returning a rect that is the union of
562 // all possible locations of the given rect under page scrolling.
563 LayoutRect fixedScrollableAreaBoundsInflatedForScrolling(const LayoutRect& uninflatedBounds) const;
565 LayoutPoint scrollPositionRespectingCustomFixedPosition() const;
567 int headerHeight() const final { return m_headerHeight; }
568 WEBCORE_EXPORT void setHeaderHeight(int);
569 int footerHeight() const final { return m_footerHeight; }
570 WEBCORE_EXPORT void setFooterHeight(int);
572 WEBCORE_EXPORT float topContentInset(TopContentInsetType = TopContentInsetType::WebCoreContentInset) const final;
573 void topContentInsetDidChange(float newTopContentInset);
575 void topContentDirectionDidChange();
577 WEBCORE_EXPORT void willStartLiveResize() final;
578 WEBCORE_EXPORT void willEndLiveResize() final;
580 WEBCORE_EXPORT void availableContentSizeChanged(AvailableSizeChangeReason) final;
582 void updateTiledBackingAdaptiveSizing();
583 TiledBacking::Scrollability computeScrollability() const;
585 void addPaintPendingMilestones(LayoutMilestones);
586 void firePaintRelatedMilestonesIfNeeded();
587 void fireLayoutRelatedMilestonesIfNeeded();
588 LayoutMilestones milestonesPendingPaint() const { return m_milestonesPendingPaint; }
590 bool visualUpdatesAllowedByClient() const { return m_visualUpdatesAllowedByClient; }
591 WEBCORE_EXPORT void setVisualUpdatesAllowedByClient(bool);
593 WEBCORE_EXPORT void setScrollPinningBehavior(ScrollPinningBehavior);
595 ScrollBehaviorForFixedElements scrollBehaviorForFixedElements() const;
597 bool hasFlippedBlockRenderers() const { return m_hasFlippedBlockRenderers; }
598 void setHasFlippedBlockRenderers(bool b) { m_hasFlippedBlockRenderers = b; }
600 void updateWidgetPositions();
601 void scheduleUpdateWidgetPositions();
603 void didAddWidgetToRenderTree(Widget&);
604 void willRemoveWidgetFromRenderTree(Widget&);
606 const HashSet<Widget*>& widgetsInRenderTree() const { return m_widgetsInRenderTree; }
608 void addTrackedRepaintRect(const FloatRect&);
610 // exposedRect represents WebKit's understanding of what part
611 // of the view is actually exposed on screen (taking into account
612 // clipping by other UI elements), whereas visibleContentRect is
613 // internal to WebCore and doesn't respect those things.
614 WEBCORE_EXPORT void setViewExposedRect(std::optional<FloatRect>);
615 std::optional<FloatRect> viewExposedRect() const { return m_viewExposedRect; }
617 #if ENABLE(CSS_SCROLL_SNAP)
618 void updateSnapOffsets() final;
619 bool isScrollSnapInProgress() const final;
620 void updateScrollingCoordinatorScrollSnapProperties() const;
623 float adjustScrollStepForFixedContent(float step, ScrollbarOrientation, ScrollGranularity) final;
625 void didChangeScrollOffset();
630 bool shouldPlaceBlockDirectionScrollbarOnLeft() const final;
632 void didRestoreFromPageCache();
634 void willDestroyRenderTree();
635 void didDestroyRenderTree();
637 void setSpeculativeTilingDelayDisabledForTesting(bool disabled) { m_speculativeTilingDelayDisabledForTesting = disabled; }
639 WEBCORE_EXPORT FrameFlattening effectiveFrameFlattening() const;
642 bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) final;
643 void scrollContentsSlowPath(const IntRect& updateRect) final;
645 void repaintSlowRepaintObjects();
647 bool isVerticalDocument() const final;
648 bool isFlippedDocument() const final;
651 explicit FrameView(Frame&);
664 bool isFrameView() const final { return true; }
666 friend class RenderWidget;
667 bool useSlowRepaints(bool considerOverlap = true) const;
668 bool useSlowRepaintsIfNotOverlapped() const;
669 void updateCanBlitOnScrollRecursively();
670 bool shouldLayoutAfterContentsResized() const;
672 bool shouldUpdateCompositingLayersAfterScrolling() const;
673 bool flushCompositingStateForThisFrame(const Frame& rootFrameForFlush);
675 bool shouldDeferScrollUpdateAfterContentSizeChange() final;
677 void scrollOffsetChangedViaPlatformWidgetImpl(const ScrollOffset& oldOffset, const ScrollOffset& newOffset) final;
679 void applyOverflowToViewport(const RenderElement&, ScrollbarMode& hMode, ScrollbarMode& vMode);
680 void applyPaginationToViewport();
682 void updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow);
684 WEBCORE_EXPORT void paintControlTints();
686 void forceLayoutParentViewIfNeeded();
687 void flushPostLayoutTasksQueue();
688 void performPostLayoutTasks();
689 void autoSizeIfEnabled();
691 void applyRecursivelyWithVisibleRect(const WTF::Function<void (FrameView& frameView, const IntRect& visibleRect)>&);
692 void resumeVisibleImageAnimations(const IntRect& visibleRect);
693 void updateScriptedAnimationsAndTimersThrottlingState(const IntRect& visibleRect);
695 void updateLayerFlushThrottling();
696 WEBCORE_EXPORT void adjustTiledBackingCoverage();
698 void repaintContentRectangle(const IntRect&) final;
699 void addedOrRemovedScrollbar() final;
701 void scrollToFocusedElementTimerFired();
702 void scrollToFocusedElementInternal();
704 void delegatesScrollingDidChange() final;
706 // ScrollableArea interface
707 void invalidateScrollbarRect(Scrollbar&, const IntRect&) final;
708 void scrollTo(const ScrollPosition&) final;
709 void setVisibleScrollerThumbRect(const IntRect&) final;
710 ScrollableArea* enclosingScrollableArea() const final;
711 IntRect scrollableAreaBoundingBox(bool* = nullptr) const final;
712 bool scrollAnimatorEnabled() const final;
713 GraphicsLayer* layerForScrolling() const final;
714 GraphicsLayer* layerForHorizontalScrollbar() const final;
715 GraphicsLayer* layerForVerticalScrollbar() const final;
716 GraphicsLayer* layerForScrollCorner() const final;
717 #if ENABLE(RUBBER_BANDING)
718 GraphicsLayer* layerForOverhangAreas() const final;
720 void contentsResized() final;
723 void unobscuredContentSizeChanged() final;
726 bool usesCompositedScrolling() const final;
727 bool usesAsyncScrolling() const final;
728 bool usesMockScrollAnimator() const final;
729 void logMockScrollAnimatorMessage(const String&) const final;
731 // Override scrollbar notifications to update the AXObject cache.
732 void didAddScrollbar(Scrollbar*, ScrollbarOrientation) final;
733 void willRemoveScrollbar(Scrollbar*, ScrollbarOrientation) final;
735 IntSize sizeForResizeEvent() const;
736 void sendResizeEventIfNeeded();
738 void adjustScrollbarsForLayout(bool firstLayout);
740 void handleDeferredScrollbarsUpdateAfterDirectionChange();
742 void updateScrollableAreaSet();
743 void updateLayoutViewport();
745 void notifyPageThatContentAreaWillPaint() const final;
747 void enableSpeculativeTilingIfNeeded();
748 void speculativeTilingEnableTimerFired();
750 void updateEmbeddedObjectsTimerFired();
751 bool updateEmbeddedObjects();
752 void updateEmbeddedObject(RenderEmbeddedObject&);
754 void updateWidgetPositionsTimerFired();
756 void scrollToAnchor();
757 void scrollPositionChanged(const ScrollPosition& oldPosition, const ScrollPosition& newPosition);
758 void scrollableAreaSetChanged();
759 void sendScrollEvent();
760 void resetScrollAnchor();
762 bool hasCustomScrollbars() const;
764 void updateScrollCorner() final;
766 FrameView* parentFrameView() const;
768 bool frameFlatteningEnabled() const;
769 bool isFrameFlatteningValidForThisFrame() const;
771 void markRootOrBodyRendererDirty() const;
773 bool qualifiesAsVisuallyNonEmpty() const;
774 bool isViewForDocumentInFrame() const;
776 AXObjectCache* axObjectCache() const;
777 void notifyWidgetsInAllFrames(WidgetNotification);
778 void removeFromAXObjectCache();
779 void notifyWidgets(WidgetNotification);
781 RenderElement* viewportRenderer() const;
783 void willDoLayout(WeakPtr<RenderElement> layoutRoot);
784 void didLayout(WeakPtr<RenderElement> layoutRoot);
786 HashSet<Widget*> m_widgetsInRenderTree;
788 static MonotonicTime sCurrentPaintTimeStamp; // used for detecting decoded resource thrash in the cache
791 LayoutSize m_margins;
793 std::unique_ptr<ListHashSet<RenderEmbeddedObject*>> m_embeddedObjectsToUpdate;
794 const Ref<Frame> m_frame;
796 std::unique_ptr<HashSet<const RenderElement*>> m_slowRepaintObjects;
798 bool m_canHaveScrollbars;
799 bool m_cannotBlitToWindow;
800 bool m_isOverlapped { false };
801 bool m_contentIsOpaque;
803 Timer m_updateEmbeddedObjectsTimer;
804 Timer m_updateWidgetPositionsTimer;
806 bool m_firstLayoutCallbackPending;
808 bool m_isTransparent;
809 Color m_baseBackgroundColor;
810 IntSize m_lastViewportSize;
811 float m_lastZoomFactor;
814 String m_mediaTypeWhenNotPrinting;
816 bool m_overflowStatusDirty;
817 bool m_horizontalOverflow;
818 bool m_verticalOverflow;
819 enum class ViewportRendererType { None, Document, Body };
820 ViewportRendererType m_viewportRendererType { ViewportRendererType::None };
822 Pagination m_pagination;
824 bool m_wasScrolledByUser;
825 bool m_inProgrammaticScroll;
826 bool m_safeToPropagateScrollToParent;
827 Timer m_delayedScrollEventTimer;
828 bool m_shouldScrollToFocusedElement { false };
829 SelectionRevealMode m_selectionRevealModeForFocusedElement;
830 Timer m_delayedScrollToFocusedElementTimer;
832 MonotonicTime m_lastPaintTime;
834 bool m_isTrackingRepaints; // Used for testing.
835 Vector<FloatRect> m_trackedRepaintRects;
837 bool m_shouldUpdateWhileOffscreen;
839 std::optional<FloatRect> m_viewExposedRect;
841 LayoutPoint m_layoutViewportOrigin;
842 std::optional<LayoutRect> m_layoutViewportOverrideRect;
843 std::optional<LayoutRect> m_visualViewportOverrideRect; // Used when the iOS keyboard is showing.
845 RefPtr<Node> m_nodeToDraw;
846 PaintBehavior m_paintBehavior;
849 unsigned m_visuallyNonEmptyCharacterCount;
850 unsigned m_visuallyNonEmptyPixelCount;
851 bool m_isVisuallyNonEmpty;
852 bool m_firstVisuallyNonEmptyLayoutCallbackPending;
854 bool m_needsDeferredScrollbarsUpdate { false };
856 RefPtr<ContainerNode> m_maintainScrollPositionAnchor;
858 // Renderer to hold our custom scroll corner.
859 RenderPtr<RenderScrollbarPart> m_scrollCorner;
861 bool m_speculativeTilingEnabled;
862 Timer m_speculativeTilingEnableTimer;
865 bool m_useCustomFixedPositionLayoutRect;
866 IntRect m_customFixedPositionLayoutRect;
868 bool m_useCustomSizeForResizeEvent;
869 IntSize m_customSizeForResizeEvent;
872 IntSize m_overrideViewportSize;
873 bool m_hasOverrideViewportSize;
875 // If true, automatically resize the frame view around its content.
876 bool m_shouldAutoSize;
878 // True if autosize has been run since m_shouldAutoSize was set.
879 bool m_didRunAutosize;
880 // The lower bound on the size when autosizing.
881 IntSize m_minAutoSize;
882 // The upper bound on the size when autosizing.
883 IntSize m_maxAutoSize;
884 // The fixed height to resize the view to after autosizing is complete.
885 int m_autoSizeFixedMinimumHeight;
886 // The intrinsic content size decided by autosizing.
887 IntSize m_autoSizeContentSize;
889 std::unique_ptr<ScrollableAreaSet> m_scrollableAreas;
890 std::unique_ptr<ViewportConstrainedObjectSet> m_viewportConstrainedObjects;
895 LayoutMilestones m_milestonesPendingPaint;
897 static const unsigned visualCharacterThreshold = 200;
898 static const unsigned visualPixelThreshold = 32 * 32;
900 #if ENABLE(CSS_DEVICE_ADAPTATION)
901 // Size of viewport before any UA or author styles have overridden
902 // the viewport given by the window or viewing area of the UA.
903 IntSize m_initialViewportSize;
906 bool m_visualUpdatesAllowedByClient;
907 bool m_hasFlippedBlockRenderers;
908 bool m_speculativeTilingDelayDisabledForTesting { false };
910 ScrollPinningBehavior m_scrollPinningBehavior;
912 IntRect* m_cachedWindowClipRect { nullptr };
913 Vector<WTF::Function<void ()>> m_postLayoutCallbackQueue;
915 LayoutContext m_layoutContext;
918 inline void FrameView::incrementVisuallyNonEmptyCharacterCount(unsigned count)
920 if (m_isVisuallyNonEmpty)
922 m_visuallyNonEmptyCharacterCount += count;
923 if (m_visuallyNonEmptyCharacterCount <= visualCharacterThreshold)
925 updateIsVisuallyNonEmpty();
928 inline void FrameView::incrementVisuallyNonEmptyPixelCount(const IntSize& size)
930 if (m_isVisuallyNonEmpty)
932 m_visuallyNonEmptyPixelCount += size.width() * size.height();
933 if (m_visuallyNonEmptyPixelCount <= visualPixelThreshold)
935 updateIsVisuallyNonEmpty();
938 } // namespace WebCore
940 SPECIALIZE_TYPE_TRAITS_WIDGET(FrameView, isFrameView())