1/*
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, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
8
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.
13
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.
18
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.
23*/
24
25#ifndef FrameView_h
26#define FrameView_h
27
28#include "AdjustViewSizeOrNot.h"
29#include "Color.h"
30#include "LayoutMilestones.h"
31#include "LayoutRect.h"
32#include "Pagination.h"
33#include "PaintPhase.h"
34#include "RenderPtr.h"
35#include "ScrollView.h"
36#include <memory>
37#include <wtf/Forward.h>
38#include <wtf/ListHashSet.h>
39#include <wtf/text/WTFString.h>
40
41namespace WebCore {
42
43class AXObjectCache;
44class Element;
45class FloatSize;
46class Frame;
47class HTMLFrameOwnerElement;
48class URL;
49class Node;
50class Page;
51class RenderBox;
52class RenderElement;
53class RenderEmbeddedObject;
54class RenderLayer;
55class RenderObject;
56class RenderScrollbarPart;
57class RenderStyle;
58class RenderView;
59class RenderWidget;
60
61Pagination::Mode paginationModeForRenderStyle(const RenderStyle&);
62
63typedef unsigned long long DOMTimeStamp;
64
65class FrameView final : public ScrollView {
66public:
67    friend class RenderView;
68    friend class Internals;
69
70    static PassRefPtr<FrameView> create(Frame&);
71    static PassRefPtr<FrameView> create(Frame&, const IntSize& initialSize);
72
73    virtual ~FrameView();
74
75    virtual HostWindow* hostWindow() const override;
76
77    virtual void invalidateRect(const IntRect&) override;
78    virtual void setFrameRect(const IntRect&) override;
79
80#if ENABLE(REQUEST_ANIMATION_FRAME)
81    virtual bool scheduleAnimation() override;
82#endif
83
84    Frame& frame() const { return *m_frame; }
85
86    RenderView* renderView() const;
87
88    int mapFromLayoutToCSSUnits(LayoutUnit) const;
89    LayoutUnit mapFromCSSToLayoutUnits(int) const;
90
91    LayoutUnit marginWidth() const { return m_margins.width(); } // -1 means default
92    LayoutUnit marginHeight() const { return m_margins.height(); } // -1 means default
93    void setMarginWidth(LayoutUnit);
94    void setMarginHeight(LayoutUnit);
95
96    virtual void setCanHaveScrollbars(bool) override;
97    void updateCanHaveScrollbars();
98
99    virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation) override;
100
101    virtual bool avoidScrollbarCreation() const override;
102
103    virtual void setContentsSize(const IntSize&) override;
104
105    void layout(bool allowSubtree = true);
106    bool didFirstLayout() const;
107    void layoutTimerFired(Timer<FrameView>&);
108    void scheduleRelayout();
109    void scheduleRelayoutOfSubtree(RenderElement&);
110    void unscheduleRelayout();
111    bool layoutPending() const;
112    bool isInLayout() const { return m_layoutPhase == InLayout; }
113
114    RenderObject* layoutRoot(bool onlyDuringLayout = false) const;
115    void clearLayoutRoot() { m_layoutRoot = nullptr; }
116    int layoutCount() const { return m_layoutCount; }
117
118    bool needsLayout() const;
119    void setNeedsLayout();
120    void setViewportConstrainedObjectsNeedLayout();
121
122    bool needsFullRepaint() const { return m_needsFullRepaint; }
123
124    bool renderedCharactersExceed(unsigned threshold);
125
126#if PLATFORM(IOS)
127    bool useCustomFixedPositionLayoutRect() const { return m_useCustomFixedPositionLayoutRect; }
128    IntRect customFixedPositionLayoutRect() const { return m_customFixedPositionLayoutRect; }
129    void setCustomFixedPositionLayoutRect(const IntRect&);
130    bool updateFixedPositionLayoutRect();
131
132    IntSize customSizeForResizeEvent() const { return m_customSizeForResizeEvent; }
133    void setCustomSizeForResizeEvent(IntSize);
134
135    void setScrollVelocity(double horizontalVelocity, double verticalVelocity, double scaleChangeRate, double timestamp);
136    FloatRect computeCoverageRect(double horizontalMargin, double verticalMargin) const;
137#else
138    bool useCustomFixedPositionLayoutRect() const { return false; }
139#endif
140
141#if ENABLE(REQUEST_ANIMATION_FRAME)
142    void serviceScriptedAnimations(double monotonicAnimationStartTime);
143#endif
144
145    void updateCompositingLayersAfterStyleChange();
146    void updateCompositingLayersAfterLayout();
147    bool flushCompositingStateForThisFrame(Frame* rootFrameForFlush);
148
149    void clearBackingStores();
150    void restoreBackingStores();
151
152    // Called when changes to the GraphicsLayer hierarchy have to be synchronized with
153    // content rendered via the normal painting path.
154    void setNeedsOneShotDrawingSynchronization();
155
156    GraphicsLayer* graphicsLayerForPlatformWidget(PlatformWidget);
157    void scheduleLayerFlushAllowingThrottling();
158
159    virtual TiledBacking* tiledBacking() const override;
160
161    // In the future when any ScrollableArea can have a node in th ScrollingTree, this should
162    // become a virtual function on ScrollableArea.
163    uint64_t scrollLayerID() const;
164    ScrollableArea* scrollableAreaForScrollLayerID(uint64_t) const;
165
166    bool hasCompositedContent() const;
167    bool hasCompositedContentIncludingDescendants() const;
168    bool hasCompositingAncestor() const;
169    void enterCompositingMode();
170    bool isEnclosedInCompositingLayer() const;
171
172    // Only used with accelerated compositing, but outside the #ifdef to make linkage easier.
173    // Returns true if the flush was completed.
174    bool flushCompositingStateIncludingSubframes();
175
176    // Returns true when a paint with the PaintBehaviorFlattenCompositingLayers flag set gives
177    // a faithful representation of the content.
178    bool isSoftwareRenderable() const;
179
180    void setIsInWindow(bool);
181
182    void resetScrollbars();
183    void resetScrollbarsAndClearContentsSize();
184    void prepareForDetach();
185    void detachCustomScrollbars();
186    void recalculateScrollbarOverlayStyle();
187
188    void clear();
189
190    bool isTransparent() const;
191    void setTransparent(bool isTransparent);
192
193    // True if the FrameView is not transparent, and the base background color is opaque.
194    bool hasOpaqueBackground() const;
195
196    Color baseBackgroundColor() const;
197    void setBaseBackgroundColor(const Color&);
198    void updateBackgroundRecursively(const Color&, bool);
199
200    enum ExtendedBackgroundModeFlags {
201        ExtendedBackgroundModeNone          = 0,
202        ExtendedBackgroundModeVertical      = 1 << 0,
203        ExtendedBackgroundModeHorizontal    = 1 << 1,
204        ExtendedBackgroundModeAll           = ExtendedBackgroundModeVertical | ExtendedBackgroundModeHorizontal,
205    };
206    typedef unsigned ExtendedBackgroundMode;
207
208    void updateExtendBackgroundIfNecessary();
209    void updateTilesForExtendedBackgroundMode(ExtendedBackgroundMode);
210    ExtendedBackgroundMode calculateExtendedBackgroundMode() const;
211
212    bool hasExtendedBackgroundRectForPainting() const;
213    IntRect extendedBackgroundRectForPainting() const;
214
215    bool shouldUpdateWhileOffscreen() const;
216    void setShouldUpdateWhileOffscreen(bool);
217    bool shouldUpdate() const;
218
219    void adjustViewSize();
220
221    void setViewportSizeForCSSViewportUnits(IntSize);
222    IntSize viewportSizeForCSSViewportUnits() const;
223
224    virtual IntRect windowClipRect(bool clipToContents = true) const override;
225    IntRect windowClipRectForFrameOwner(const HTMLFrameOwnerElement*, bool clipToLayerContents) const;
226
227    virtual IntRect windowResizerRect() const override;
228
229    virtual float visibleContentScaleFactor() const override;
230
231#if USE(TILED_BACKING_STORE)
232    virtual void setFixedVisibleContentRect(const IntRect&) override;
233#endif
234    virtual void setScrollPosition(const IntPoint&) override;
235    void scrollPositionChangedViaPlatformWidget(const IntPoint& oldPosition, const IntPoint& newPosition);
236    virtual void updateLayerPositionsAfterScrolling() override;
237    virtual void updateCompositingLayersAfterScrolling() override;
238    virtual bool requestScrollPositionUpdate(const IntPoint&) override;
239    virtual bool isRubberBandInProgress() const override;
240    virtual IntPoint minimumScrollPosition() const override;
241    virtual IntPoint maximumScrollPosition() const override;
242    void delayedScrollEventTimerFired(Timer<FrameView>&);
243
244    void resumeVisibleImageAnimationsIncludingSubframes();
245
246    // This is different than visibleContentRect() in that it ignores negative (or overly positive)
247    // offsets from rubber-banding, and it takes zooming into account.
248    LayoutRect viewportConstrainedVisibleContentRect() const;
249
250    String mediaType() const;
251    void setMediaType(const String&);
252    void adjustMediaTypeForPrinting(bool printing);
253
254    void setCannotBlitToWindow();
255    void setIsOverlapped(bool);
256    bool isOverlapped() const { return m_isOverlapped; }
257    bool isOverlappedIncludingAncestors() const;
258    void setContentIsOpaque(bool);
259
260    void addSlowRepaintObject(RenderElement*);
261    void removeSlowRepaintObject(RenderElement*);
262    bool hasSlowRepaintObject(RenderElement* o) const { return m_slowRepaintObjects && m_slowRepaintObjects->contains(o); }
263    bool hasSlowRepaintObjects() const { return m_slowRepaintObjects && m_slowRepaintObjects->size(); }
264
265    // Includes fixed- and sticky-position objects.
266    typedef HashSet<RenderElement*> ViewportConstrainedObjectSet;
267    void addViewportConstrainedObject(RenderElement*);
268    void removeViewportConstrainedObject(RenderElement*);
269    const ViewportConstrainedObjectSet* viewportConstrainedObjects() const { return m_viewportConstrainedObjects.get(); }
270    bool hasViewportConstrainedObjects() const { return m_viewportConstrainedObjects && m_viewportConstrainedObjects->size() > 0; }
271
272    // Functions for querying the current scrolled position, negating the effects of overhang
273    // and adjusting for page scale.
274    LayoutSize scrollOffsetForFixedPosition() const;
275    // Static function can be called from another thread.
276    static LayoutSize scrollOffsetForFixedPosition(const LayoutRect& visibleContentRect, const LayoutSize& totalContentsSize, const LayoutPoint& scrollPosition, const LayoutPoint& scrollOrigin, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame, ScrollBehaviorForFixedElements, int headerHeight, int footerHeight);
277
278    // These layers are positioned differently when there is a topContentInset, a header, or a footer. These value need to be computed
279    // on both the main thread and the scrolling thread.
280    static float yPositionForInsetClipLayer(const FloatPoint& scrollPosition, float topContentInset);
281    static float yPositionForRootContentLayer(const FloatPoint& scrollPosition, float topContentInset, float headerHeight);
282    static float yPositionForHeaderLayer(const FloatPoint& scrollPosition, float topContentInset);
283    static float yPositionForFooterLayer(const FloatPoint& scrollPosition, float topContentInset, float totalContentsHeight, float footerHeight);
284
285#if PLATFORM(IOS)
286    LayoutRect viewportConstrainedObjectsRect() const;
287    // Static function can be called from another thread.
288    static LayoutRect rectForViewportConstrainedObjects(const LayoutRect& visibleContentRect, const LayoutSize& totalContentsSize, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame, ScrollBehaviorForFixedElements);
289#endif
290
291    bool fixedElementsLayoutRelativeToFrame() const;
292
293    void disableLayerFlushThrottlingTemporarilyForInteraction();
294    bool speculativeTilingEnabled() const { return m_speculativeTilingEnabled; }
295    void loadProgressingStatusChanged();
296
297#if ENABLE(DASHBOARD_SUPPORT)
298    void updateAnnotatedRegions();
299#endif
300    void updateControlTints();
301
302    void restoreScrollbar();
303
304    void postLayoutTimerFired(Timer<FrameView>&);
305
306    bool wasScrolledByUser() const;
307    void setWasScrolledByUser(bool);
308
309    bool safeToPropagateScrollToParent() const { return m_safeToPropagateScrollToParent; }
310    void setSafeToPropagateScrollToParent(bool isSafe) { m_safeToPropagateScrollToParent = isSafe; }
311
312    void addEmbeddedObjectToUpdate(RenderEmbeddedObject&);
313    void removeEmbeddedObjectToUpdate(RenderEmbeddedObject&);
314
315    virtual void paintContents(GraphicsContext*, const IntRect& dirtyRect) override;
316
317    struct PaintingState {
318        PaintBehavior paintBehavior;
319        bool isTopLevelPainter;
320        bool isFlatteningPaintOfRootFrame;
321        PaintingState()
322            : paintBehavior()
323            , isTopLevelPainter(false)
324            , isFlatteningPaintOfRootFrame(false)
325        {
326        }
327    };
328
329    void willPaintContents(GraphicsContext*, const IntRect& dirtyRect, PaintingState&);
330    void didPaintContents(GraphicsContext*, const IntRect& dirtyRect, PaintingState&);
331
332    void setPaintBehavior(PaintBehavior);
333    PaintBehavior paintBehavior() const;
334    bool isPainting() const;
335    bool hasEverPainted() const { return m_lastPaintTime; }
336    void setLastPaintTime(double lastPaintTime) { m_lastPaintTime = lastPaintTime; }
337    void setNodeToDraw(Node*);
338
339    enum SelectionInSnapshot { IncludeSelection, ExcludeSelection };
340    enum CoordinateSpaceForSnapshot { DocumentCoordinates, ViewCoordinates };
341    void paintContentsForSnapshot(GraphicsContext*, const IntRect& imageRect, SelectionInSnapshot shouldPaintSelection, CoordinateSpaceForSnapshot);
342
343    virtual void paintOverhangAreas(GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect) override;
344    virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect) override;
345    virtual void paintScrollbar(GraphicsContext*, Scrollbar*, const IntRect&) override;
346
347    Color documentBackgroundColor() const;
348
349    bool isInChildFrameWithFrameFlattening() const;
350
351    static double currentPaintTimeStamp() { return sCurrentPaintTimeStamp; } // returns 0 if not painting
352
353    void updateLayoutAndStyleIfNeededRecursive();
354
355    void incrementVisuallyNonEmptyCharacterCount(unsigned);
356    void incrementVisuallyNonEmptyPixelCount(const IntSize&);
357    void updateIsVisuallyNonEmpty();
358    bool isVisuallyNonEmpty() const { return m_isVisuallyNonEmpty; }
359    void enableAutoSizeMode(bool enable, const IntSize& minSize, const IntSize& maxSize);
360    void setAutoSizeFixedMinimumHeight(int fixedMinimumHeight);
361    IntSize autoSizingIntrinsicContentSize() const { return m_autoSizeContentSize; }
362
363    void forceLayout(bool allowSubtree = false);
364    void forceLayoutForPagination(const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkFactor, AdjustViewSizeOrNot);
365
366    // FIXME: This method is retained because of embedded WebViews in AppKit.  When a WebView is embedded inside
367    // some enclosing view with auto-pagination, no call happens to resize the view.  The new pagination model
368    // needs the view to resize as a result of the breaks, but that means that the enclosing view has to potentially
369    // resize around that view.  Auto-pagination uses the bounds of the actual view that's being printed to determine
370    // the edges of the print operation, so the resize is necessary if the enclosing view's bounds depend on the
371    // web document's bounds.
372    //
373    // This is already a problem if the view needs to be a different size because of printer fonts or because of print stylesheets.
374    // Mail/Dictionary work around this problem by using the _layoutForPrinting SPI
375    // to at least get print stylesheets and printer fonts into play, but since WebKit doesn't know about the page offset or
376    // page size, it can't actually paginate correctly during _layoutForPrinting.
377    //
378    // We can eventually move Mail to a newer SPI that would let them opt in to the layout-time pagination model,
379    // but that doesn't solve the general problem of how other AppKit views could opt in to the better model.
380    //
381    // NO OTHER PLATFORM BESIDES MAC SHOULD USE THIS METHOD.
382    void adjustPageHeightDeprecated(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
383
384    bool scrollToFragment(const URL&);
385    bool scrollToAnchor(const String&);
386    void maintainScrollPositionAtAnchor(Node*);
387    void scrollElementToRect(Element*, const IntRect&);
388
389    // Methods to convert points and rects between the coordinate space of the renderer, and this view.
390    IntRect convertFromRendererToContainingView(const RenderElement*, const IntRect&) const;
391    IntRect convertFromContainingViewToRenderer(const RenderElement*, const IntRect&) const;
392    IntPoint convertFromRendererToContainingView(const RenderElement*, const IntPoint&) const;
393    IntPoint convertFromContainingViewToRenderer(const RenderElement*, const IntPoint&) const;
394
395    bool isFrameViewScrollCorner(RenderScrollbarPart* scrollCorner) const { return m_scrollCorner == scrollCorner; }
396
397    bool isScrollable();
398
399    enum ScrollbarModesCalculationStrategy { RulesFromWebContentOnly, AnyRule };
400    void calculateScrollbarModesForLayout(ScrollbarMode& hMode, ScrollbarMode& vMode, ScrollbarModesCalculationStrategy = AnyRule);
401
402    virtual IntPoint lastKnownMousePosition() const override;
403    virtual bool isHandlingWheelEvent() const override;
404    bool shouldSetCursor() const;
405
406    // FIXME: Remove this method once plugin loading is decoupled from layout.
407    void flushAnyPendingPostLayoutTasks();
408
409    virtual bool shouldSuspendScrollAnimations() const override;
410    virtual void scrollbarStyleChanged(int newStyle, bool forceUpdate) override;
411
412    RenderBox* embeddedContentBox() const;
413
414    void setTracksRepaints(bool);
415    bool isTrackingRepaints() const { return m_isTrackingRepaints; }
416    void resetTrackedRepaints();
417    const Vector<FloatRect>& trackedRepaintRects() const { return m_trackedRepaintRects; }
418    String trackedRepaintRectsAsText() const;
419
420    typedef HashSet<ScrollableArea*> ScrollableAreaSet;
421    // Returns whether the scrollable area has just been newly added.
422    bool addScrollableArea(ScrollableArea*);
423    // Returns whether the scrollable area has just been removed.
424    bool removeScrollableArea(ScrollableArea*);
425    bool containsScrollableArea(ScrollableArea*) const;
426    const ScrollableAreaSet* scrollableAreas() const { return m_scrollableAreas.get(); }
427
428    virtual void removeChild(Widget*) override;
429
430    // This function exists for ports that need to handle wheel events manually.
431    // On Mac WebKit1 the underlying NSScrollView just does the scrolling, but on most other platforms
432    // we need this function in order to do the scroll ourselves.
433    bool wheelEvent(const PlatformWheelEvent&);
434
435    void setScrollingPerformanceLoggingEnabled(bool);
436
437    // Page and FrameView both store a Pagination value. Page::pagination() is set only by API,
438    // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all
439    // FrameViews in the page cache, but FrameView::pagination() only affects the current
440    // FrameView. FrameView::pagination() will return m_pagination if it has been set. Otherwise,
441    // it will return Page::pagination() since currently there are no callers that need to
442    // distinguish between the two.
443    const Pagination& pagination() const;
444    void setPagination(const Pagination&);
445
446    bool inProgrammaticScroll() const override { return m_inProgrammaticScroll; }
447    void setInProgrammaticScroll(bool programmaticScroll) { m_inProgrammaticScroll = programmaticScroll; }
448
449#if ENABLE(CSS_DEVICE_ADAPTATION)
450    IntSize initialViewportSize() const { return m_initialViewportSize; }
451    void setInitialViewportSize(const IntSize& size) { m_initialViewportSize = size; }
452#endif
453
454    virtual bool isActive() const override;
455    virtual bool updatesScrollLayerPositionOnMainThread() const override;
456    virtual bool forceUpdateScrollbarsOnMainThreadForPerformanceTesting() const override;
457
458#if ENABLE(RUBBER_BANDING)
459    GraphicsLayer* setWantsLayerForTopOverHangArea(bool) const;
460    GraphicsLayer* setWantsLayerForBottomOverHangArea(bool) const;
461#endif
462
463    virtual int headerHeight() const override { return m_headerHeight; }
464    void setHeaderHeight(int);
465    virtual int footerHeight() const override { return m_footerHeight; }
466    void setFooterHeight(int);
467
468    virtual float topContentInset(TopContentInsetType = TopContentInsetType::WebCoreContentInset) const override;
469    void topContentInsetDidChange(float newTopContentInset);
470
471    virtual void willStartLiveResize() override;
472    virtual void willEndLiveResize() override;
473
474    void addPaintPendingMilestones(LayoutMilestones);
475    void firePaintRelatedMilestonesIfNeeded();
476    void fireLayoutRelatedMilestonesIfNeeded();
477    LayoutMilestones milestonesPendingPaint() const { return m_milestonesPendingPaint; }
478
479    bool visualUpdatesAllowedByClient() const { return m_visualUpdatesAllowedByClient; }
480    void setVisualUpdatesAllowedByClient(bool);
481
482    void setScrollPinningBehavior(ScrollPinningBehavior);
483
484    ScrollBehaviorForFixedElements scrollBehaviorForFixedElements() const;
485
486    void updateWidgetPositions();
487    void didAddWidgetToRenderTree(Widget&);
488    void willRemoveWidgetFromRenderTree(Widget&);
489
490    void addTrackedRepaintRect(const FloatRect&);
491
492    // exposedRect represents WebKit's understanding of what part
493    // of the view is actually exposed on screen (taking into account
494    // clipping by other UI elements), whereas visibleContentRect is
495    // internal to WebCore and doesn't respect those things.
496    void setExposedRect(FloatRect);
497    FloatRect exposedRect() const { return m_exposedRect; }
498
499protected:
500    virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) override;
501    virtual void scrollContentsSlowPath(const IntRect& updateRect) override;
502
503    void repaintSlowRepaintObjects();
504
505    virtual bool isVerticalDocument() const override;
506    virtual bool isFlippedDocument() const override;
507
508private:
509    explicit FrameView(Frame&);
510
511    void reset();
512    void init();
513
514    enum LayoutPhase {
515        OutsideLayout,
516        InPreLayout,
517        InPreLayoutStyleUpdate,
518        InLayout,
519        InViewSizeAdjust,
520        InPostLayout,
521    };
522    LayoutPhase layoutPhase() const { return m_layoutPhase; }
523
524    bool inPreLayoutStyleUpdate() const { return m_layoutPhase == InPreLayoutStyleUpdate; }
525
526    virtual bool isFrameView() const override { return true; }
527
528    friend class RenderWidget;
529    bool useSlowRepaints(bool considerOverlap = true) const;
530    bool useSlowRepaintsIfNotOverlapped() const;
531    void updateCanBlitOnScrollRecursively();
532    bool contentsInCompositedLayer() const;
533    bool shouldLayoutAfterContentsResized() const;
534
535    bool shouldUpdateCompositingLayersAfterScrolling() const;
536
537    void applyOverflowToViewport(RenderElement*, ScrollbarMode& hMode, ScrollbarMode& vMode);
538    void applyPaginationToViewport();
539
540    void updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow);
541
542    void paintControlTints();
543
544    void forceLayoutParentViewIfNeeded();
545    void performPostLayoutTasks();
546    void autoSizeIfEnabled();
547
548    void updateLayerFlushThrottling();
549    void adjustTiledBackingCoverage();
550
551    virtual void repaintContentRectangle(const IntRect&) override;
552    virtual void contentsResized() override;
553    virtual void visibleContentsResized() override;
554    virtual void addedOrRemovedScrollbar() override;
555    virtual void fixedLayoutSizeChanged() override;
556
557    virtual void delegatesScrollingDidChange() override;
558
559    // Override ScrollView methods to do point conversion via renderers, in order to
560    // take transforms into account.
561    virtual IntRect convertToContainingView(const IntRect&) const override;
562    virtual IntRect convertFromContainingView(const IntRect&) const override;
563    virtual IntPoint convertToContainingView(const IntPoint&) const override;
564    virtual IntPoint convertFromContainingView(const IntPoint&) const override;
565
566    // ScrollableArea interface
567    virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) override;
568    virtual void scrollTo(const IntSize&) override;
569    virtual void setVisibleScrollerThumbRect(const IntRect&) override;
570    virtual ScrollableArea* enclosingScrollableArea() const override;
571    virtual IntRect scrollableAreaBoundingBox() const override;
572    virtual bool scrollAnimatorEnabled() const override;
573    virtual GraphicsLayer* layerForScrolling() const override;
574    virtual GraphicsLayer* layerForHorizontalScrollbar() const override;
575    virtual GraphicsLayer* layerForVerticalScrollbar() const override;
576    virtual GraphicsLayer* layerForScrollCorner() const override;
577#if ENABLE(RUBBER_BANDING)
578    virtual GraphicsLayer* layerForOverhangAreas() const override;
579#endif
580
581    // Override scrollbar notifications to update the AXObject cache.
582    virtual void didAddScrollbar(Scrollbar*, ScrollbarOrientation) override;
583    virtual void willRemoveScrollbar(Scrollbar*, ScrollbarOrientation) override;
584
585    IntSize sizeForResizeEvent() const;
586    void sendResizeEventIfNeeded();
587
588    void updateScrollableAreaSet();
589
590    virtual void notifyPageThatContentAreaWillPaint() const override;
591
592    void enableSpeculativeTilingIfNeeded();
593    void speculativeTilingEnableTimerFired(Timer<FrameView>&);
594
595    void updateEmbeddedObjectsTimerFired(Timer<FrameView>*);
596    bool updateEmbeddedObjects();
597    void updateEmbeddedObject(RenderEmbeddedObject&);
598    void scrollToAnchor();
599    void scrollPositionChanged(const IntPoint& oldPosition, const IntPoint& newPosition);
600    void scrollableAreaSetChanged();
601    void sendScrollEvent();
602
603    bool hasCustomScrollbars() const;
604
605    virtual void updateScrollCorner() override;
606
607    FrameView* parentFrameView() const;
608
609    void startLayoutAtMainFrameViewIfNeeded(bool allowSubtree);
610    bool frameFlatteningEnabled() const;
611    bool isFrameFlatteningValidForThisFrame() const;
612
613    bool qualifiesAsVisuallyNonEmpty() const;
614
615    AXObjectCache* axObjectCache() const;
616    void notifyWidgetsInAllFrames(WidgetNotification);
617    void removeFromAXObjectCache();
618    void notifyWidgets(WidgetNotification);
619
620    HashSet<Widget*> m_widgetsInRenderTree;
621
622    static double sCurrentPaintTimeStamp; // used for detecting decoded resource thrash in the cache
623
624    LayoutSize m_size;
625    LayoutSize m_margins;
626
627    std::unique_ptr<ListHashSet<RenderEmbeddedObject*>> m_embeddedObjectsToUpdate;
628    const RefPtr<Frame> m_frame;
629
630    std::unique_ptr<HashSet<RenderElement*>> m_slowRepaintObjects;
631
632    bool m_needsFullRepaint;
633
634    bool m_canHaveScrollbars;
635    bool m_cannotBlitToWindow;
636    bool m_isOverlapped;
637    bool m_contentIsOpaque;
638
639    Timer<FrameView> m_layoutTimer;
640    bool m_delayedLayout;
641    RenderElement* m_layoutRoot;
642
643    LayoutPhase m_layoutPhase;
644    bool m_layoutSchedulingEnabled;
645    bool m_inSynchronousPostLayout;
646    int m_layoutCount;
647    unsigned m_nestedLayoutCount;
648    Timer<FrameView> m_postLayoutTasksTimer;
649    Timer<FrameView> m_updateEmbeddedObjectsTimer;
650    bool m_firstLayoutCallbackPending;
651
652    bool m_firstLayout;
653    bool m_isTransparent;
654    Color m_baseBackgroundColor;
655    IntSize m_lastViewportSize;
656    float m_lastZoomFactor;
657
658    String m_mediaType;
659    String m_mediaTypeWhenNotPrinting;
660
661    bool m_overflowStatusDirty;
662    bool m_horizontalOverflow;
663    bool m_verticalOverflow;
664    RenderElement* m_viewportRenderer;
665
666    Pagination m_pagination;
667
668    bool m_wasScrolledByUser;
669    bool m_inProgrammaticScroll;
670    bool m_safeToPropagateScrollToParent;
671    Timer<FrameView> m_delayedScrollEventTimer;
672
673    double m_lastPaintTime;
674
675    bool m_isTrackingRepaints; // Used for testing.
676    Vector<FloatRect> m_trackedRepaintRects;
677
678    bool m_shouldUpdateWhileOffscreen;
679
680    FloatRect m_exposedRect;
681
682    unsigned m_deferSetNeedsLayouts;
683    bool m_setNeedsLayoutWasDeferred;
684
685    RefPtr<Node> m_nodeToDraw;
686    PaintBehavior m_paintBehavior;
687    bool m_isPainting;
688
689    unsigned m_visuallyNonEmptyCharacterCount;
690    unsigned m_visuallyNonEmptyPixelCount;
691    bool m_isVisuallyNonEmpty;
692    bool m_firstVisuallyNonEmptyLayoutCallbackPending;
693
694    RefPtr<Node> m_maintainScrollPositionAnchor;
695
696    // Renderer to hold our custom scroll corner.
697    RenderPtr<RenderScrollbarPart> m_scrollCorner;
698
699    bool m_speculativeTilingEnabled;
700    Timer<FrameView> m_speculativeTilingEnableTimer;
701
702#if PLATFORM(IOS)
703    bool m_useCustomFixedPositionLayoutRect;
704    IntRect m_customFixedPositionLayoutRect;
705
706    bool m_useCustomSizeForResizeEvent;
707    IntSize m_customSizeForResizeEvent;
708
709    double m_horizontalVelocity;
710    double m_verticalVelocity;
711    double m_scaleChangeRate;
712    double m_lastVelocityUpdateTime;
713#endif
714
715    IntSize m_overrideViewportSize;
716    bool m_hasOverrideViewportSize;
717
718    // If true, automatically resize the frame view around its content.
719    bool m_shouldAutoSize;
720    bool m_inAutoSize;
721    // True if autosize has been run since m_shouldAutoSize was set.
722    bool m_didRunAutosize;
723    // The lower bound on the size when autosizing.
724    IntSize m_minAutoSize;
725    // The upper bound on the size when autosizing.
726    IntSize m_maxAutoSize;
727    // The fixed height to resize the view to after autosizing is complete.
728    int m_autoSizeFixedMinimumHeight;
729    // The intrinsic content size decided by autosizing.
730    IntSize m_autoSizeContentSize;
731
732    std::unique_ptr<ScrollableAreaSet> m_scrollableAreas;
733    std::unique_ptr<ViewportConstrainedObjectSet> m_viewportConstrainedObjects;
734
735    int m_headerHeight;
736    int m_footerHeight;
737
738    LayoutMilestones m_milestonesPendingPaint;
739
740    static const unsigned visualCharacterThreshold = 200;
741    static const unsigned visualPixelThreshold = 32 * 32;
742
743#if ENABLE(CSS_DEVICE_ADAPTATION)
744    // Size of viewport before any UA or author styles have overridden
745    // the viewport given by the window or viewing area of the UA.
746    IntSize m_initialViewportSize;
747#endif
748
749    bool m_visualUpdatesAllowedByClient;
750
751    ScrollPinningBehavior m_scrollPinningBehavior;
752};
753
754inline void FrameView::incrementVisuallyNonEmptyCharacterCount(unsigned count)
755{
756    if (m_isVisuallyNonEmpty)
757        return;
758    m_visuallyNonEmptyCharacterCount += count;
759    if (m_visuallyNonEmptyCharacterCount <= visualCharacterThreshold)
760        return;
761    updateIsVisuallyNonEmpty();
762}
763
764inline void FrameView::incrementVisuallyNonEmptyPixelCount(const IntSize& size)
765{
766    if (m_isVisuallyNonEmpty)
767        return;
768    m_visuallyNonEmptyPixelCount += size.width() * size.height();
769    if (m_visuallyNonEmptyPixelCount <= visualPixelThreshold)
770        return;
771    updateIsVisuallyNonEmpty();
772}
773
774WIDGET_TYPE_CASTS(FrameView, isFrameView());
775
776} // namespace WebCore
777
778#endif // FrameView_h
779