2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Dirk Mueller <mueller@kde.org>
6 * Copyright (C) 2004-2008, 2013, 2014 Apple Inc. All rights reserved.
7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
9 * Copyright (C) 2009 Google Inc. All rights reserved.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
28 #include "FrameView.h"
30 #include "AXObjectCache.h"
31 #include "AnimationController.h"
32 #include "BackForwardController.h"
33 #include "CachedImage.h"
34 #include "CachedResourceLoader.h"
36 #include "ChromeClient.h"
37 #include "DOMWindow.h"
38 #include "DebugPageOverlays.h"
39 #include "DocumentMarkerController.h"
40 #include "EventHandler.h"
41 #include "FloatRect.h"
42 #include "FocusController.h"
43 #include "FontCache.h"
44 #include "FontLoader.h"
45 #include "FrameLoader.h"
46 #include "FrameLoaderClient.h"
47 #include "FrameSelection.h"
48 #include "FrameTree.h"
49 #include "GraphicsContext.h"
50 #include "HTMLDocument.h"
51 #include "HTMLFrameElement.h"
52 #include "HTMLFrameSetElement.h"
53 #include "HTMLNames.h"
54 #include "HTMLPlugInImageElement.h"
55 #include "ImageDocument.h"
56 #include "InspectorClient.h"
57 #include "InspectorController.h"
58 #include "InspectorInstrumentation.h"
60 #include "MainFrame.h"
61 #include "MemoryCache.h"
62 #include "MemoryPressureHandler.h"
63 #include "OverflowEvent.h"
64 #include "PageOverlayController.h"
65 #include "ProgressTracker.h"
66 #include "RenderEmbeddedObject.h"
67 #include "RenderFullScreen.h"
68 #include "RenderIFrame.h"
69 #include "RenderInline.h"
70 #include "RenderLayer.h"
71 #include "RenderLayerBacking.h"
72 #include "RenderLayerCompositor.h"
73 #include "RenderSVGRoot.h"
74 #include "RenderScrollbar.h"
75 #include "RenderScrollbarPart.h"
76 #include "RenderStyle.h"
77 #include "RenderText.h"
78 #include "RenderTheme.h"
79 #include "RenderView.h"
80 #include "RenderWidget.h"
81 #include "SVGDocument.h"
82 #include "SVGSVGElement.h"
83 #include "ScrollAnimator.h"
84 #include "ScrollingCoordinator.h"
86 #include "StyleResolver.h"
87 #include "TextResourceDecoder.h"
88 #include "TextStream.h"
89 #include "TiledBacking.h"
91 #include <wtf/CurrentTime.h>
93 #include <wtf/TemporaryChange.h>
95 #if USE(TILED_BACKING_STORE)
96 #include "TiledBackingStore.h"
99 #if ENABLE(TEXT_AUTOSIZING)
100 #include "TextAutosizer.h"
103 #if ENABLE(CSS_SCROLL_SNAP)
104 #include "AxisScrollSnapOffsets.h"
108 #include "DocumentLoader.h"
109 #include "LegacyTileCache.h"
110 #include "MemoryCache.h"
111 #include "MemoryPressureHandler.h"
112 #include "SystemMemory.h"
117 using namespace HTMLNames;
119 double FrameView::sCurrentPaintTimeStamp = 0.0;
121 // The maximum number of updateEmbeddedObjects iterations that should be done before returning.
122 static const unsigned maxUpdateEmbeddedObjectsIterations = 2;
124 static RenderLayer::UpdateLayerPositionsFlags updateLayerPositionFlags(RenderLayer* layer, bool isRelayoutingSubtree, bool didFullRepaint)
126 RenderLayer::UpdateLayerPositionsFlags flags = RenderLayer::defaultFlags;
127 if (didFullRepaint) {
128 flags &= ~RenderLayer::CheckForRepaint;
129 flags |= RenderLayer::NeedsFullRepaintInBacking;
131 if (isRelayoutingSubtree && layer->enclosingPaginationLayer(RenderLayer::IncludeCompositedPaginatedLayers))
132 flags |= RenderLayer::UpdatePagination;
136 Pagination::Mode paginationModeForRenderStyle(const RenderStyle& style)
138 EOverflow overflow = style.overflowY();
139 if (overflow != OPAGEDX && overflow != OPAGEDY)
140 return Pagination::Unpaginated;
142 bool isHorizontalWritingMode = style.isHorizontalWritingMode();
143 TextDirection textDirection = style.direction();
144 WritingMode writingMode = style.writingMode();
146 // paged-x always corresponds to LeftToRightPaginated or RightToLeftPaginated. If the WritingMode
147 // is horizontal, then we use TextDirection to choose between those options. If the WritingMode
148 // is vertical, then the direction of the verticality dictates the choice.
149 if (overflow == OPAGEDX) {
150 if ((isHorizontalWritingMode && textDirection == LTR) || writingMode == LeftToRightWritingMode)
151 return Pagination::LeftToRightPaginated;
152 return Pagination::RightToLeftPaginated;
155 // paged-y always corresponds to TopToBottomPaginated or BottomToTopPaginated. If the WritingMode
156 // is horizontal, then the direction of the horizontality dictates the choice. If the WritingMode
157 // is vertical, then we use TextDirection to choose between those options.
158 if (writingMode == TopToBottomWritingMode || (!isHorizontalWritingMode && textDirection == RTL))
159 return Pagination::TopToBottomPaginated;
160 return Pagination::BottomToTopPaginated;
163 FrameView::FrameView(Frame& frame)
165 , m_canHaveScrollbars(true)
166 , m_layoutTimer(*this, &FrameView::layoutTimerFired)
168 , m_layoutPhase(OutsideLayout)
169 , m_inSynchronousPostLayout(false)
170 , m_postLayoutTasksTimer(*this, &FrameView::postLayoutTimerFired)
171 , m_updateEmbeddedObjectsTimer(*this, &FrameView::updateEmbeddedObjectsTimerFired)
172 , m_isTransparent(false)
173 , m_baseBackgroundColor(Color::white)
174 , m_mediaType("screen")
175 , m_overflowStatusDirty(true)
176 , m_viewportRenderer(0)
177 , m_wasScrolledByUser(false)
178 , m_inProgrammaticScroll(false)
179 , m_safeToPropagateScrollToParent(true)
180 , m_delayedScrollEventTimer(*this, &FrameView::delayedScrollEventTimerFired)
181 , m_isTrackingRepaints(false)
182 , m_shouldUpdateWhileOffscreen(true)
183 , m_exposedRect(FloatRect::infiniteRect())
184 , m_deferSetNeedsLayouts(0)
185 , m_setNeedsLayoutWasDeferred(false)
186 , m_speculativeTilingEnabled(false)
187 , m_speculativeTilingEnableTimer(*this, &FrameView::speculativeTilingEnableTimerFired)
189 , m_useCustomFixedPositionLayoutRect(false)
190 , m_useCustomSizeForResizeEvent(false)
191 , m_horizontalVelocity(0)
192 , m_verticalVelocity(0)
193 , m_scaleChangeRate(0)
194 , m_lastVelocityUpdateTime(0)
196 , m_hasOverrideViewportSize(false)
197 , m_shouldAutoSize(false)
198 , m_inAutoSize(false)
199 , m_didRunAutosize(false)
200 , m_autoSizeFixedMinimumHeight(0)
203 , m_milestonesPendingPaint(0)
204 , m_visualUpdatesAllowedByClient(true)
205 , m_scrollPinningBehavior(DoNotPin)
209 #if ENABLE(RUBBER_BANDING)
210 ScrollElasticity verticalElasticity = ScrollElasticityNone;
211 ScrollElasticity horizontalElasticity = ScrollElasticityNone;
212 if (m_frame->isMainFrame()) {
213 verticalElasticity = m_frame->page() ? m_frame->page()->verticalScrollElasticity() : ScrollElasticityAllowed;
214 horizontalElasticity = m_frame->page() ? m_frame->page()->horizontalScrollElasticity() : ScrollElasticityAllowed;
215 } else if (m_frame->settings().rubberBandingForSubScrollableRegionsEnabled()) {
216 verticalElasticity = ScrollElasticityAutomatic;
217 horizontalElasticity = ScrollElasticityAutomatic;
220 ScrollableArea::setVerticalScrollElasticity(verticalElasticity);
221 ScrollableArea::setHorizontalScrollElasticity(horizontalElasticity);
225 PassRefPtr<FrameView> FrameView::create(Frame& frame)
227 RefPtr<FrameView> view = adoptRef(new FrameView(frame));
229 return view.release();
232 PassRefPtr<FrameView> FrameView::create(Frame& frame, const IntSize& initialSize)
234 RefPtr<FrameView> view = adoptRef(new FrameView(frame));
235 view->Widget::setFrameRect(IntRect(view->location(), initialSize));
237 return view.release();
240 FrameView::~FrameView()
242 if (m_postLayoutTasksTimer.isActive())
243 m_postLayoutTasksTimer.stop();
245 removeFromAXObjectCache();
248 // Custom scrollbars should already be destroyed at this point
249 ASSERT(!horizontalScrollbar() || !horizontalScrollbar()->isCustomScrollbar());
250 ASSERT(!verticalScrollbar() || !verticalScrollbar()->isCustomScrollbar());
252 setHasHorizontalScrollbar(false); // Remove native scrollbars now before we lose the connection to the HostWindow.
253 setHasVerticalScrollbar(false);
255 ASSERT(!m_scrollCorner);
257 ASSERT(frame().view() != this || !frame().contentRenderer());
260 void FrameView::reset()
262 m_cannotBlitToWindow = false;
263 m_isOverlapped = false;
264 m_contentIsOpaque = false;
265 m_layoutTimer.stop();
267 m_delayedLayout = false;
268 m_needsFullRepaint = true;
269 m_layoutSchedulingEnabled = true;
270 m_layoutPhase = OutsideLayout;
271 m_inSynchronousPostLayout = false;
273 m_nestedLayoutCount = 0;
274 m_postLayoutTasksTimer.stop();
275 m_updateEmbeddedObjectsTimer.stop();
276 m_firstLayout = true;
277 m_firstLayoutCallbackPending = false;
278 m_wasScrolledByUser = false;
279 m_safeToPropagateScrollToParent = true;
280 m_delayedScrollEventTimer.stop();
281 m_lastViewportSize = IntSize();
282 m_lastZoomFactor = 1.0f;
283 m_isTrackingRepaints = false;
284 m_trackedRepaintRects.clear();
286 m_paintBehavior = PaintBehaviorNormal;
287 m_isPainting = false;
288 m_visuallyNonEmptyCharacterCount = 0;
289 m_visuallyNonEmptyPixelCount = 0;
290 m_isVisuallyNonEmpty = false;
291 m_firstVisuallyNonEmptyLayoutCallbackPending = true;
292 m_maintainScrollPositionAnchor = nullptr;
293 m_throttledTimers.clear();
296 void FrameView::removeFromAXObjectCache()
298 if (AXObjectCache* cache = axObjectCache())
302 void FrameView::resetScrollbars()
304 // Reset the document's scrollbars back to our defaults before we yield the floor.
305 m_firstLayout = true;
306 setScrollbarsSuppressed(true);
307 if (m_canHaveScrollbars)
308 setScrollbarModes(ScrollbarAuto, ScrollbarAuto);
310 setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff);
311 setScrollbarsSuppressed(false);
314 void FrameView::resetScrollbarsAndClearContentsSize()
318 setScrollbarsSuppressed(true);
319 setContentsSize(IntSize());
320 setScrollbarsSuppressed(false);
323 void FrameView::init()
327 m_margins = LayoutSize(-1, -1); // undefined
328 m_size = LayoutSize();
330 // Propagate the marginwidth/height and scrolling modes to the view.
331 Element* ownerElement = frame().ownerElement();
332 if (is<HTMLFrameElementBase>(ownerElement)) {
333 HTMLFrameElementBase& frameElement = downcast<HTMLFrameElementBase>(*ownerElement);
334 if (frameElement.scrollingMode() == ScrollbarAlwaysOff)
335 setCanHaveScrollbars(false);
336 LayoutUnit marginWidth = frameElement.marginWidth();
337 LayoutUnit marginHeight = frameElement.marginHeight();
338 if (marginWidth != -1)
339 setMarginWidth(marginWidth);
340 if (marginHeight != -1)
341 setMarginHeight(marginHeight);
344 Page* page = frame().page();
345 if (page && page->chrome().client().shouldPaintEntireContents())
346 setPaintsEntireContents(true);
349 void FrameView::prepareForDetach()
351 detachCustomScrollbars();
352 // When the view is no longer associated with a frame, it needs to be removed from the ax object cache
353 // right now, otherwise it won't be able to reach the topDocument()'s axObject cache later.
354 removeFromAXObjectCache();
356 if (frame().page()) {
357 if (ScrollingCoordinator* scrollingCoordinator = frame().page()->scrollingCoordinator())
358 scrollingCoordinator->willDestroyScrollableArea(this);
362 void FrameView::detachCustomScrollbars()
364 Scrollbar* horizontalBar = horizontalScrollbar();
365 if (horizontalBar && horizontalBar->isCustomScrollbar())
366 setHasHorizontalScrollbar(false);
368 Scrollbar* verticalBar = verticalScrollbar();
369 if (verticalBar && verticalBar->isCustomScrollbar())
370 setHasVerticalScrollbar(false);
372 m_scrollCorner = nullptr;
375 void FrameView::recalculateScrollbarOverlayStyle()
377 ScrollbarOverlayStyle oldOverlayStyle = scrollbarOverlayStyle();
378 ScrollbarOverlayStyle overlayStyle = ScrollbarOverlayStyleDefault;
380 Color backgroundColor = documentBackgroundColor();
381 if (backgroundColor.isValid()) {
382 // Reduce the background color from RGB to a lightness value
383 // and determine which scrollbar style to use based on a lightness
385 double hue, saturation, lightness;
386 backgroundColor.getHSL(hue, saturation, lightness);
387 if (lightness <= .5 && backgroundColor.alpha() > 0)
388 overlayStyle = ScrollbarOverlayStyleLight;
391 if (oldOverlayStyle != overlayStyle)
392 setScrollbarOverlayStyle(overlayStyle);
395 void FrameView::clear()
397 setCanBlitOnScroll(true);
401 setScrollbarsSuppressed(true);
404 // To avoid flashes of white, disable tile updates immediately when view is cleared at the beginning of a page load.
405 // Tiling will be re-enabled from UIKit via [WAKWindow setTilingMode:] when we have content to draw.
406 if (LegacyTileCache* tileCache = legacyTileCache())
407 tileCache->setTilingMode(LegacyTileCache::Disabled);
411 bool FrameView::didFirstLayout() const
413 return !m_firstLayout;
416 void FrameView::invalidateRect(const IntRect& rect)
419 if (HostWindow* window = hostWindow())
420 window->invalidateContentsAndRootView(rect);
424 RenderWidget* renderer = frame().ownerRenderer();
428 IntRect repaintRect = rect;
429 repaintRect.move(renderer->borderLeft() + renderer->paddingLeft(),
430 renderer->borderTop() + renderer->paddingTop());
431 renderer->repaintRectangle(repaintRect);
434 void FrameView::setFrameRect(const IntRect& newRect)
436 IntRect oldRect = frameRect();
437 if (newRect == oldRect)
440 #if ENABLE(TEXT_AUTOSIZING)
441 // Autosized font sizes depend on the width of the viewing area.
442 if (newRect.width() != oldRect.width()) {
443 if (frame().isMainFrame() && page->settings().textAutosizingEnabled()) {
444 for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext())
445 frame().document()->textAutosizer()->recalculateMultipliers();
450 ScrollView::setFrameRect(newRect);
452 updateScrollableAreaSet();
454 if (RenderView* renderView = this->renderView()) {
455 if (renderView->usesCompositing())
456 renderView->compositor().frameViewDidChangeSize();
459 if (frame().isMainFrame())
460 frame().mainFrame().pageOverlayController().didChangeViewSize();
463 #if ENABLE(REQUEST_ANIMATION_FRAME)
464 bool FrameView::scheduleAnimation()
466 if (HostWindow* window = hostWindow()) {
467 window->scheduleAnimation();
474 void FrameView::setMarginWidth(LayoutUnit w)
476 // make it update the rendering area when set
477 m_margins.setWidth(w);
480 void FrameView::setMarginHeight(LayoutUnit h)
482 // make it update the rendering area when set
483 m_margins.setHeight(h);
486 bool FrameView::frameFlatteningEnabled() const
488 return frame().settings().frameFlatteningEnabled();
491 bool FrameView::isFrameFlatteningValidForThisFrame() const
493 if (!frameFlatteningEnabled())
496 HTMLFrameOwnerElement* owner = frame().ownerElement();
500 // Frame flattening is valid only for <frame> and <iframe>.
501 return owner->hasTagName(frameTag) || owner->hasTagName(iframeTag);
504 bool FrameView::avoidScrollbarCreation() const
506 // with frame flattening no subframe can have scrollbars
507 // but we also cannot turn scrollbars off as we determine
508 // our flattening policy using that.
509 return isFrameFlatteningValidForThisFrame();
512 void FrameView::setCanHaveScrollbars(bool canHaveScrollbars)
514 m_canHaveScrollbars = canHaveScrollbars;
515 ScrollView::setCanHaveScrollbars(canHaveScrollbars);
518 void FrameView::updateCanHaveScrollbars()
522 scrollbarModes(hMode, vMode);
523 if (hMode == ScrollbarAlwaysOff && vMode == ScrollbarAlwaysOff)
524 setCanHaveScrollbars(false);
526 setCanHaveScrollbars(true);
529 PassRefPtr<Scrollbar> FrameView::createScrollbar(ScrollbarOrientation orientation)
531 if (!frame().settings().allowCustomScrollbarInMainFrame() && frame().isMainFrame())
532 return ScrollView::createScrollbar(orientation);
534 // FIXME: We need to update the scrollbar dynamically as documents change (or as doc elements and bodies get discovered that have custom styles).
535 Document* doc = frame().document();
537 // Try the <body> element first as a scrollbar source.
538 Element* body = doc ? doc->body() : 0;
539 if (body && body->renderer() && body->renderer()->style().hasPseudoStyle(SCROLLBAR))
540 return RenderScrollbar::createCustomScrollbar(this, orientation, body);
542 // If the <body> didn't have a custom style, then the root element might.
543 Element* docElement = doc ? doc->documentElement() : 0;
544 if (docElement && docElement->renderer() && docElement->renderer()->style().hasPseudoStyle(SCROLLBAR))
545 return RenderScrollbar::createCustomScrollbar(this, orientation, docElement);
547 // If we have an owning iframe/frame element, then it can set the custom scrollbar also.
548 RenderWidget* frameRenderer = frame().ownerRenderer();
549 if (frameRenderer && frameRenderer->style().hasPseudoStyle(SCROLLBAR))
550 return RenderScrollbar::createCustomScrollbar(this, orientation, 0, &frame());
552 // Nobody set a custom style, so we just use a native scrollbar.
553 return ScrollView::createScrollbar(orientation);
556 void FrameView::setContentsSize(const IntSize& size)
558 if (size == contentsSize())
561 m_deferSetNeedsLayouts++;
563 ScrollView::setContentsSize(size);
564 ScrollView::contentsResized();
566 Page* page = frame().page();
570 updateScrollableAreaSet();
572 page->chrome().contentsSizeChanged(&frame(), size); // Notify only.
574 if (frame().isMainFrame())
575 frame().mainFrame().pageOverlayController().didChangeDocumentSize();
577 ASSERT(m_deferSetNeedsLayouts);
578 m_deferSetNeedsLayouts--;
580 if (!m_deferSetNeedsLayouts)
581 m_setNeedsLayoutWasDeferred = false; // FIXME: Find a way to make the deferred layout actually happen.
584 void FrameView::adjustViewSize()
586 RenderView* renderView = this->renderView();
590 ASSERT(frame().view() == this);
592 const IntRect rect = renderView->documentRect();
593 const IntSize& size = rect.size();
594 ScrollView::setScrollOrigin(IntPoint(-rect.x(), -rect.y()), !frame().document()->printing(), size == contentsSize());
596 setContentsSize(size);
599 void FrameView::applyOverflowToViewport(RenderElement* renderer, ScrollbarMode& hMode, ScrollbarMode& vMode)
601 // Handle the overflow:hidden/scroll case for the body/html elements. WinIE treats
602 // overflow:hidden and overflow:scroll on <body> as applying to the document's
603 // scrollbars. The CSS2.1 draft states that HTML UAs should use the <html> or <body> element and XML/XHTML UAs should
604 // use the root element.
606 // To combat the inability to scroll on a page with overflow:hidden on the root when scaled, disregard hidden when
607 // there is a frameScaleFactor that is greater than one on the main frame. Also disregard hidden if there is a
610 bool overrideHidden = frame().isMainFrame() && ((frame().frameScaleFactor() > 1) || headerHeight() || footerHeight());
612 EOverflow overflowX = renderer->style().overflowX();
613 EOverflow overflowY = renderer->style().overflowY();
615 if (is<RenderSVGRoot>(*renderer)) {
616 // FIXME: evaluate if we can allow overflow for these cases too.
617 // Overflow is always hidden when stand-alone SVG documents are embedded.
618 if (downcast<RenderSVGRoot>(*renderer).isEmbeddedThroughFrameContainingSVGDocument()) {
627 hMode = ScrollbarAuto;
629 hMode = ScrollbarAlwaysOff;
632 hMode = ScrollbarAlwaysOn;
635 hMode = ScrollbarAuto;
638 // Don't set it at all.
645 vMode = ScrollbarAuto;
647 vMode = ScrollbarAlwaysOff;
650 vMode = ScrollbarAlwaysOn;
653 vMode = ScrollbarAuto;
656 // Don't set it at all. Values of OPAGEDX and OPAGEDY are handled by applyPaginationToViewPort().
660 m_viewportRenderer = renderer;
663 void FrameView::applyPaginationToViewport()
665 Document* document = frame().document();
666 auto documentElement = document->documentElement();
667 RenderElement* documentRenderer = documentElement ? documentElement->renderer() : nullptr;
668 RenderElement* documentOrBodyRenderer = documentRenderer;
669 auto body = document->body();
670 if (body && body->renderer()) {
671 if (body->hasTagName(bodyTag))
672 documentOrBodyRenderer = documentRenderer->style().overflowX() == OVISIBLE && documentElement->hasTagName(htmlTag) ? body->renderer() : documentRenderer;
675 Pagination pagination;
677 if (!documentOrBodyRenderer) {
678 setPagination(pagination);
682 EOverflow overflowY = documentOrBodyRenderer->style().overflowY();
683 if (overflowY == OPAGEDX || overflowY == OPAGEDY) {
684 pagination.mode = WebCore::paginationModeForRenderStyle(documentOrBodyRenderer->style());
685 pagination.gap = static_cast<unsigned>(documentOrBodyRenderer->style().columnGap());
688 setPagination(pagination);
691 void FrameView::calculateScrollbarModesForLayout(ScrollbarMode& hMode, ScrollbarMode& vMode, ScrollbarModesCalculationStrategy strategy)
693 m_viewportRenderer = 0;
695 const HTMLFrameOwnerElement* owner = frame().ownerElement();
696 if (owner && (owner->scrollingMode() == ScrollbarAlwaysOff)) {
697 hMode = ScrollbarAlwaysOff;
698 vMode = ScrollbarAlwaysOff;
702 if (m_canHaveScrollbars || strategy == RulesFromWebContentOnly) {
703 hMode = ScrollbarAuto;
704 vMode = ScrollbarAuto;
706 hMode = ScrollbarAlwaysOff;
707 vMode = ScrollbarAlwaysOff;
711 Document* document = frame().document();
712 auto documentElement = document->documentElement();
713 RenderElement* rootRenderer = documentElement ? documentElement->renderer() : nullptr;
714 auto body = document->body();
715 if (body && body->renderer()) {
716 if (body->hasTagName(framesetTag) && !frameFlatteningEnabled()) {
717 vMode = ScrollbarAlwaysOff;
718 hMode = ScrollbarAlwaysOff;
719 } else if (body->hasTagName(bodyTag)) {
720 // It's sufficient to just check the X overflow,
721 // since it's illegal to have visible in only one direction.
722 RenderElement* o = rootRenderer->style().overflowX() == OVISIBLE && document->documentElement()->hasTagName(htmlTag) ? body->renderer() : rootRenderer;
723 applyOverflowToViewport(o, hMode, vMode);
725 } else if (rootRenderer)
726 applyOverflowToViewport(rootRenderer, hMode, vMode);
730 void FrameView::updateCompositingLayersAfterStyleChange()
732 RenderView* renderView = this->renderView();
736 // If we expect to update compositing after an incipient layout, don't do so here.
737 if (inPreLayoutStyleUpdate() || layoutPending() || renderView->needsLayout())
740 RenderLayerCompositor& compositor = renderView->compositor();
741 // This call will make sure the cached hasAcceleratedCompositing is updated from the pref
742 compositor.cacheAcceleratedCompositingFlags();
743 compositor.updateCompositingLayers(CompositingUpdateAfterStyleChange);
746 void FrameView::updateCompositingLayersAfterLayout()
748 RenderView* renderView = this->renderView();
752 // This call will make sure the cached hasAcceleratedCompositing is updated from the pref
753 renderView->compositor().cacheAcceleratedCompositingFlags();
754 renderView->compositor().updateCompositingLayers(CompositingUpdateAfterLayout);
757 void FrameView::clearBackingStores()
759 RenderView* renderView = this->renderView();
763 RenderLayerCompositor& compositor = renderView->compositor();
764 ASSERT(compositor.inCompositingMode());
765 compositor.enableCompositingMode(false);
766 compositor.clearBackingForAllLayers();
769 void FrameView::restoreBackingStores()
771 RenderView* renderView = this->renderView();
775 RenderLayerCompositor& compositor = renderView->compositor();
776 compositor.enableCompositingMode(true);
777 compositor.updateCompositingLayers(CompositingUpdateAfterLayout);
780 GraphicsLayer* FrameView::layerForScrolling() const
782 RenderView* renderView = this->renderView();
785 return renderView->compositor().scrollLayer();
788 GraphicsLayer* FrameView::layerForHorizontalScrollbar() const
790 RenderView* renderView = this->renderView();
793 return renderView->compositor().layerForHorizontalScrollbar();
796 GraphicsLayer* FrameView::layerForVerticalScrollbar() const
798 RenderView* renderView = this->renderView();
801 return renderView->compositor().layerForVerticalScrollbar();
804 GraphicsLayer* FrameView::layerForScrollCorner() const
806 RenderView* renderView = this->renderView();
809 return renderView->compositor().layerForScrollCorner();
812 TiledBacking* FrameView::tiledBacking() const
814 RenderView* renderView = this->renderView();
818 RenderLayerBacking* backing = renderView->layer()->backing();
822 return backing->graphicsLayer()->tiledBacking();
825 uint64_t FrameView::scrollLayerID() const
827 RenderView* renderView = this->renderView();
831 RenderLayerBacking* backing = renderView->layer()->backing();
835 return backing->scrollingNodeIDForRole(FrameScrollingNode);
838 ScrollableArea* FrameView::scrollableAreaForScrollLayerID(uint64_t nodeID) const
840 RenderView* renderView = this->renderView();
844 return renderView->compositor().scrollableAreaForScrollLayerID(nodeID);
847 #if ENABLE(RUBBER_BANDING)
848 GraphicsLayer* FrameView::layerForOverhangAreas() const
850 RenderView* renderView = this->renderView();
853 return renderView->compositor().layerForOverhangAreas();
856 GraphicsLayer* FrameView::setWantsLayerForTopOverHangArea(bool wantsLayer) const
858 RenderView* renderView = this->renderView();
862 return renderView->compositor().updateLayerForTopOverhangArea(wantsLayer);
865 GraphicsLayer* FrameView::setWantsLayerForBottomOverHangArea(bool wantsLayer) const
867 RenderView* renderView = this->renderView();
871 return renderView->compositor().updateLayerForBottomOverhangArea(wantsLayer);
874 #endif // ENABLE(RUBBER_BANDING)
876 #if ENABLE(CSS_SCROLL_SNAP)
877 void FrameView::updateSnapOffsets()
879 if (!frame().document())
882 // FIXME: Should we allow specifying snap points through <html> tags too?
883 HTMLElement* body = frame().document()->body();
884 if (!renderView() || !body || !body->renderer())
887 updateSnapOffsetsForScrollableArea(*this, *body, *renderView(), body->renderer()->style());
891 bool FrameView::flushCompositingStateForThisFrame(Frame* rootFrameForFlush)
893 RenderView* renderView = this->renderView();
895 return true; // We don't want to keep trying to update layers if we have no renderer.
897 ASSERT(frame().view() == this);
899 // If we sync compositing layers when a layout is pending, we may cause painting of compositing
900 // layer content to occur before layout has happened, which will cause paintContents() to bail.
905 if (LegacyTileCache* tileCache = legacyTileCache())
906 tileCache->doPendingRepaints();
909 renderView->compositor().flushPendingLayerChanges(rootFrameForFlush == &frame());
914 void FrameView::setNeedsOneShotDrawingSynchronization()
916 if (Page* page = frame().page())
917 page->chrome().client().setNeedsOneShotDrawingSynchronization();
920 GraphicsLayer* FrameView::graphicsLayerForPlatformWidget(PlatformWidget platformWidget)
922 // To find the Widget that corresponds with platformWidget we have to do a linear
923 // search of our child widgets.
924 Widget* foundWidget = nullptr;
925 for (auto& widget : children()) {
926 if (widget->platformWidget() != platformWidget)
928 foundWidget = widget.get();
935 auto* renderWidget = RenderWidget::find(foundWidget);
939 RenderLayer* widgetLayer = renderWidget->layer();
940 if (!widgetLayer || !widgetLayer->isComposited())
943 return widgetLayer->backing()->parentForSublayers();
946 void FrameView::scheduleLayerFlushAllowingThrottling()
948 RenderView* view = this->renderView();
951 view->compositor().scheduleLayerFlush(true /* canThrottle */);
954 void FrameView::setHeaderHeight(int headerHeight)
957 ASSERT(frame().isMainFrame());
958 m_headerHeight = headerHeight;
960 if (RenderView* renderView = this->renderView())
961 renderView->setNeedsLayout();
964 void FrameView::setFooterHeight(int footerHeight)
967 ASSERT(frame().isMainFrame());
968 m_footerHeight = footerHeight;
970 if (RenderView* renderView = this->renderView())
971 renderView->setNeedsLayout();
974 float FrameView::topContentInset(TopContentInsetType contentInsetTypeToReturn) const
976 if (platformWidget() && contentInsetTypeToReturn == TopContentInsetType::WebCoreOrPlatformContentInset)
977 return platformTopContentInset();
979 if (!frame().isMainFrame())
982 Page* page = frame().page();
983 return page ? page->topContentInset() : 0;
986 void FrameView::topContentInsetDidChange(float newTopContentInset)
988 RenderView* renderView = this->renderView();
992 if (platformWidget())
993 platformSetTopContentInset(newTopContentInset);
997 updateScrollbars(scrollOffset());
998 if (renderView->usesCompositing())
999 renderView->compositor().frameViewDidChangeSize();
1001 if (TiledBacking* tiledBacking = this->tiledBacking())
1002 tiledBacking->setTopContentInset(newTopContentInset);
1005 bool FrameView::hasCompositedContent() const
1007 if (RenderView* renderView = this->renderView())
1008 return renderView->compositor().inCompositingMode();
1012 bool FrameView::hasCompositedContentIncludingDescendants() const
1014 for (Frame* frame = m_frame.get(); frame; frame = frame->tree().traverseNext(m_frame.get())) {
1015 RenderView* renderView = frame->contentRenderer();
1016 if (RenderLayerCompositor* compositor = renderView ? &renderView->compositor() : 0) {
1017 if (compositor->inCompositingMode())
1020 if (!RenderLayerCompositor::allowsIndependentlyCompositedFrames(this))
1027 bool FrameView::hasCompositingAncestor() const
1029 for (Frame* frame = this->frame().tree().parent(); frame; frame = frame->tree().parent()) {
1030 if (FrameView* view = frame->view()) {
1031 if (view->hasCompositedContent())
1038 // Sometimes (for plug-ins) we need to eagerly go into compositing mode.
1039 void FrameView::enterCompositingMode()
1041 if (RenderView* renderView = this->renderView()) {
1042 renderView->compositor().enableCompositingMode();
1044 renderView->compositor().scheduleCompositingLayerUpdate();
1048 bool FrameView::isEnclosedInCompositingLayer() const
1050 auto frameOwnerRenderer = frame().ownerRenderer();
1051 if (frameOwnerRenderer && frameOwnerRenderer->containerForRepaint())
1054 if (FrameView* parentView = parentFrameView())
1055 return parentView->isEnclosedInCompositingLayer();
1059 bool FrameView::flushCompositingStateIncludingSubframes()
1061 bool allFramesFlushed = flushCompositingStateForThisFrame(&frame());
1063 for (Frame* child = frame().tree().firstChild(); child; child = child->tree().traverseNext(&frame())) {
1064 bool flushed = child->view()->flushCompositingStateForThisFrame(&frame());
1065 allFramesFlushed &= flushed;
1067 return allFramesFlushed;
1070 bool FrameView::isSoftwareRenderable() const
1072 RenderView* renderView = this->renderView();
1073 return !renderView || !renderView->compositor().has3DContent();
1076 void FrameView::setIsInWindow(bool isInWindow)
1078 if (RenderView* renderView = this->renderView())
1079 renderView->setIsInWindow(isInWindow);
1082 RenderObject* FrameView::layoutRoot(bool onlyDuringLayout) const
1084 return onlyDuringLayout && layoutPending() ? 0 : m_layoutRoot;
1087 inline void FrameView::forceLayoutParentViewIfNeeded()
1089 RenderWidget* ownerRenderer = frame().ownerRenderer();
1093 RenderBox* contentBox = embeddedContentBox();
1097 auto& svgRoot = downcast<RenderSVGRoot>(*contentBox);
1098 if (svgRoot.everHadLayout() && !svgRoot.needsLayout())
1101 // If the embedded SVG document appears the first time, the ownerRenderer has already finished
1102 // layout without knowing about the existence of the embedded SVG document, because RenderReplaced
1103 // embeddedContentBox() returns 0, as long as the embedded document isn't loaded yet. Before
1104 // bothering to lay out the SVG document, mark the ownerRenderer needing layout and ask its
1105 // FrameView for a layout. After that the RenderEmbeddedObject (ownerRenderer) carries the
1106 // correct size, which RenderSVGRoot::computeReplacedLogicalWidth/Height rely on, when laying
1107 // out for the first time, or when the RenderSVGRoot size has changed dynamically (eg. via <script>).
1108 Ref<FrameView> frameView(ownerRenderer->view().frameView());
1110 // Mark the owner renderer as needing layout.
1111 ownerRenderer->setNeedsLayoutAndPrefWidthsRecalc();
1113 // Synchronously enter layout, to layout the view containing the host object/embed/iframe.
1114 frameView->layout();
1117 void FrameView::layout(bool allowSubtree)
1122 // Protect the view from being deleted during layout (in recalcStyle).
1123 Ref<FrameView> protect(*this);
1125 // Many of the tasks performed during layout can cause this function to be re-entered,
1126 // so save the layout phase now and restore it on exit.
1127 TemporaryChange<LayoutPhase> layoutPhaseRestorer(m_layoutPhase, InPreLayout);
1129 // Every scroll that happens during layout is programmatic.
1130 TemporaryChange<bool> changeInProgrammaticScroll(m_inProgrammaticScroll, true);
1132 bool inChildFrameLayoutWithFrameFlattening = isInChildFrameWithFrameFlattening();
1134 if (inChildFrameLayoutWithFrameFlattening) {
1135 startLayoutAtMainFrameViewIfNeeded(allowSubtree);
1136 RenderElement* root = m_layoutRoot ? m_layoutRoot : frame().document()->renderView();
1137 if (!root || !root->needsLayout())
1142 if (updateFixedPositionLayoutRect())
1143 allowSubtree = false;
1146 m_layoutTimer.stop();
1147 m_delayedLayout = false;
1148 m_setNeedsLayoutWasDeferred = false;
1150 // we shouldn't enter layout() while painting
1151 ASSERT(!isPainting());
1155 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willLayout(&frame());
1157 if (!allowSubtree && m_layoutRoot) {
1158 m_layoutRoot->markContainingBlocksForLayout(false);
1162 ASSERT(frame().view() == this);
1163 ASSERT(frame().document());
1165 Document& document = *frame().document();
1166 ASSERT(!document.inPageCache());
1169 RenderElement* root;
1172 TemporaryChange<bool> changeSchedulingEnabled(m_layoutSchedulingEnabled, false);
1174 if (!m_nestedLayoutCount && !m_inSynchronousPostLayout && m_postLayoutTasksTimer.isActive() && !inChildFrameLayoutWithFrameFlattening) {
1175 // This is a new top-level layout. If there are any remaining tasks from the previous
1176 // layout, finish them now.
1177 TemporaryChange<bool> inSynchronousPostLayoutChange(m_inSynchronousPostLayout, true);
1178 performPostLayoutTasks();
1181 m_layoutPhase = InPreLayoutStyleUpdate;
1183 // Viewport-dependent media queries may cause us to need completely different style information.
1184 StyleResolver* styleResolver = document.styleResolverIfExists();
1185 if (!styleResolver || styleResolver->hasMediaQueriesAffectedByViewportChange()) {
1186 document.styleResolverChanged(DeferRecalcStyle);
1187 // FIXME: This instrumentation event is not strictly accurate since cached media query results do not persist across StyleResolver rebuilds.
1188 InspectorInstrumentation::mediaQueryResultChanged(&document);
1190 document.evaluateMediaQueryList();
1192 // If there is any pagination to apply, it will affect the RenderView's style, so we should
1193 // take care of that now.
1194 applyPaginationToViewport();
1196 // Always ensure our style info is up-to-date. This can happen in situations where
1197 // the layout beats any sort of style recalc update that needs to occur.
1198 document.updateStyleIfNeeded();
1199 m_layoutPhase = InPreLayout;
1201 subtree = m_layoutRoot;
1203 // If there is only one ref to this view left, then its going to be destroyed as soon as we exit,
1204 // so there's no point to continuing to layout
1208 root = subtree ? m_layoutRoot : document.renderView();
1210 // FIXME: Do we need to set m_size here?
1214 // Close block here so we can set up the font cache purge preventer, which we will still
1215 // want in scope even after we want m_layoutSchedulingEnabled to be restored again.
1216 // The next block sets m_layoutSchedulingEnabled back to false once again.
1219 FontCachePurgePreventer fontCachePurgePreventer;
1222 ++m_nestedLayoutCount;
1225 TemporaryChange<bool> changeSchedulingEnabled(m_layoutSchedulingEnabled, false);
1227 if (!m_layoutRoot) {
1228 HTMLElement* body = document.body();
1229 if (body && body->renderer()) {
1230 if (body->hasTagName(framesetTag) && !frameFlatteningEnabled()) {
1231 body->renderer()->setChildNeedsLayout();
1232 } else if (body->hasTagName(bodyTag)) {
1233 if (!m_firstLayout && m_size.height() != layoutHeight() && body->renderer()->enclosingBox().stretchesToViewport())
1234 body->renderer()->setChildNeedsLayout();
1238 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
1239 if (m_firstLayout && !frame().ownerElement())
1240 printf("Elapsed time before first layout: %lld\n", document.elapsedTime().count());
1244 autoSizeIfEnabled();
1246 m_needsFullRepaint = !subtree && (m_firstLayout || downcast<RenderView>(*root).printing());
1249 ScrollbarMode hMode;
1250 ScrollbarMode vMode;
1251 calculateScrollbarModesForLayout(hMode, vMode);
1253 if (m_firstLayout || (hMode != horizontalScrollbarMode() || vMode != verticalScrollbarMode())) {
1254 if (m_firstLayout) {
1255 setScrollbarsSuppressed(true);
1257 m_firstLayout = false;
1258 m_firstLayoutCallbackPending = true;
1259 m_lastViewportSize = sizeForResizeEvent();
1260 m_lastZoomFactor = root->style().zoom();
1262 // Set the initial vMode to AlwaysOn if we're auto.
1263 if (vMode == ScrollbarAuto)
1264 setVerticalScrollbarMode(ScrollbarAlwaysOn); // This causes a vertical scrollbar to appear.
1265 // Set the initial hMode to AlwaysOff if we're auto.
1266 if (hMode == ScrollbarAuto)
1267 setHorizontalScrollbarMode(ScrollbarAlwaysOff); // This causes a horizontal scrollbar to disappear.
1269 setScrollbarModes(hMode, vMode);
1270 setScrollbarsSuppressed(false, true);
1272 setScrollbarModes(hMode, vMode);
1275 LayoutSize oldSize = m_size;
1277 m_size = layoutSize();
1279 if (oldSize != m_size) {
1280 m_needsFullRepaint = true;
1281 if (!m_firstLayout) {
1282 RenderBox* rootRenderer = document.documentElement() ? document.documentElement()->renderBox() : 0;
1283 RenderBox* bodyRenderer = rootRenderer && document.body() ? document.body()->renderBox() : 0;
1284 if (bodyRenderer && bodyRenderer->stretchesToViewport())
1285 bodyRenderer->setChildNeedsLayout();
1286 else if (rootRenderer && rootRenderer->stretchesToViewport())
1287 rootRenderer->setChildNeedsLayout();
1289 document.updateViewportUnitsOnResize();
1293 m_layoutPhase = InPreLayout;
1296 layer = root->enclosingLayer();
1298 bool disableLayoutState = false;
1300 disableLayoutState = root->view().shouldDisableLayoutStateForSubtree(root);
1301 root->view().pushLayoutState(*root);
1303 LayoutStateDisabler layoutStateDisabler(disableLayoutState ? &root->view() : 0);
1304 RenderView::RepaintRegionAccumulator repaintRegionAccumulator(&root->view());
1306 ASSERT(m_layoutPhase == InPreLayout);
1307 m_layoutPhase = InLayout;
1309 forceLayoutParentViewIfNeeded();
1311 ASSERT(m_layoutPhase == InLayout);
1314 #if ENABLE(IOS_TEXT_AUTOSIZING)
1315 float minZoomFontSize = frame().settings().minimumZoomFontSize();
1316 float visWidth = frame().page()->textAutosizingWidth();
1317 if (minZoomFontSize && visWidth && !root->view().printing()) {
1318 root->adjustComputedFontSizesOnBlocks(minZoomFontSize, visWidth);
1319 bool needsLayout = root->needsLayout();
1324 #if ENABLE(TEXT_AUTOSIZING)
1325 if (document.textAutosizer()->processSubtree(root) && root->needsLayout())
1329 ASSERT(m_layoutPhase == InLayout);
1332 root->view().popLayoutState(*root);
1334 m_layoutRoot = nullptr;
1336 // Close block here to end the scope of changeSchedulingEnabled and layoutStateDisabler.
1339 m_layoutPhase = InViewSizeAdjust;
1341 bool neededFullRepaint = m_needsFullRepaint;
1343 if (!subtree && !downcast<RenderView>(*root).printing())
1346 m_layoutPhase = InPostLayout;
1348 m_needsFullRepaint = neededFullRepaint;
1350 // Now update the positions of all layers.
1351 if (m_needsFullRepaint)
1352 root->view().repaintRootContents();
1354 layer->updateLayerPositionsAfterLayout(renderView()->layer(), updateLayerPositionFlags(layer, subtree, m_needsFullRepaint));
1356 updateCompositingLayersAfterLayout();
1360 #if PLATFORM(COCOA) || PLATFORM(WIN) || PLATFORM(GTK) || PLATFORM(EFL)
1361 if (AXObjectCache* cache = root->document().existingAXObjectCache())
1362 cache->postNotification(root, AXObjectCache::AXLayoutComplete);
1365 #if ENABLE(DASHBOARD_SUPPORT)
1366 updateAnnotatedRegions();
1369 #if ENABLE(IOS_TOUCH_EVENTS)
1370 document.dirtyTouchEventRects();
1373 ASSERT(!root->needsLayout());
1375 updateCanBlitOnScrollRecursively();
1377 if (document.hasListenerType(Document::OVERFLOWCHANGED_LISTENER))
1378 updateOverflowStatus(layoutWidth() < contentsWidth(), layoutHeight() < contentsHeight());
1380 if (!m_postLayoutTasksTimer.isActive()) {
1381 if (!m_inSynchronousPostLayout) {
1382 if (inChildFrameLayoutWithFrameFlattening)
1383 updateWidgetPositions();
1385 TemporaryChange<bool> inSynchronousPostLayoutChange(m_inSynchronousPostLayout, true);
1386 performPostLayoutTasks(); // Calls resumeScheduledEvents().
1390 if (!m_postLayoutTasksTimer.isActive() && (needsLayout() || m_inSynchronousPostLayout || inChildFrameLayoutWithFrameFlattening)) {
1391 // If we need layout or are already in a synchronous call to postLayoutTasks(),
1392 // defer widget updates and event dispatch until after we return. postLayoutTasks()
1393 // can make us need to update again, and we can get stuck in a nasty cycle unless
1394 // we call it through the timer here.
1395 m_postLayoutTasksTimer.startOneShot(0);
1401 InspectorInstrumentation::didLayout(cookie, root);
1402 if (frame().isMainFrame())
1403 DebugPageOverlays::didLayout(frame().mainFrame());
1405 --m_nestedLayoutCount;
1408 RenderBox* FrameView::embeddedContentBox() const
1410 RenderView* renderView = this->renderView();
1414 RenderObject* firstChild = renderView->firstChild();
1416 // Curently only embedded SVG documents participate in the size-negotiation logic.
1417 if (is<RenderSVGRoot>(firstChild))
1418 return downcast<RenderSVGRoot>(firstChild);
1423 void FrameView::addEmbeddedObjectToUpdate(RenderEmbeddedObject& embeddedObject)
1425 if (!m_embeddedObjectsToUpdate)
1426 m_embeddedObjectsToUpdate = std::make_unique<ListHashSet<RenderEmbeddedObject*>>();
1428 HTMLFrameOwnerElement& element = embeddedObject.frameOwnerElement();
1429 if (is<HTMLObjectElement>(element) || is<HTMLEmbedElement>(element)) {
1430 // Tell the DOM element that it needs a widget update.
1431 HTMLPlugInImageElement& pluginElement = downcast<HTMLPlugInImageElement>(element);
1432 if (!pluginElement.needsCheckForSizeChange())
1433 pluginElement.setNeedsWidgetUpdate(true);
1436 m_embeddedObjectsToUpdate->add(&embeddedObject);
1439 void FrameView::removeEmbeddedObjectToUpdate(RenderEmbeddedObject& embeddedObject)
1441 if (!m_embeddedObjectsToUpdate)
1444 m_embeddedObjectsToUpdate->remove(&embeddedObject);
1447 void FrameView::setMediaType(const String& mediaType)
1449 m_mediaType = mediaType;
1452 String FrameView::mediaType() const
1454 // See if we have an override type.
1455 String overrideType = frame().loader().client().overrideMediaType();
1456 InspectorInstrumentation::applyEmulatedMedia(&frame(), &overrideType);
1457 if (!overrideType.isNull())
1458 return overrideType;
1462 void FrameView::adjustMediaTypeForPrinting(bool printing)
1465 if (m_mediaTypeWhenNotPrinting.isNull())
1466 m_mediaTypeWhenNotPrinting = mediaType();
1467 setMediaType("print");
1469 if (!m_mediaTypeWhenNotPrinting.isNull())
1470 setMediaType(m_mediaTypeWhenNotPrinting);
1471 m_mediaTypeWhenNotPrinting = String();
1475 bool FrameView::useSlowRepaints(bool considerOverlap) const
1477 bool mustBeSlow = hasSlowRepaintObjects() || (platformWidget() && hasViewportConstrainedObjects());
1479 // FIXME: WidgetMac.mm makes the assumption that useSlowRepaints ==
1480 // m_contentIsOpaque, so don't take the fast path for composited layers
1481 // if they are a platform widget in order to get painting correctness
1482 // for transparent layers. See the comment in WidgetMac::paint.
1483 if (contentsInCompositedLayer() && !platformWidget())
1486 bool isOverlapped = m_isOverlapped && considerOverlap;
1488 if (mustBeSlow || m_cannotBlitToWindow || isOverlapped || !m_contentIsOpaque)
1491 if (FrameView* parentView = parentFrameView())
1492 return parentView->useSlowRepaints(considerOverlap);
1497 bool FrameView::useSlowRepaintsIfNotOverlapped() const
1499 return useSlowRepaints(false);
1502 void FrameView::updateCanBlitOnScrollRecursively()
1504 for (Frame* frame = m_frame.get(); frame; frame = frame->tree().traverseNext(m_frame.get())) {
1505 if (FrameView* view = frame->view())
1506 view->setCanBlitOnScroll(!view->useSlowRepaints());
1510 bool FrameView::contentsInCompositedLayer() const
1512 RenderView* renderView = this->renderView();
1513 if (renderView && renderView->isComposited()) {
1514 GraphicsLayer* layer = renderView->layer()->backing()->graphicsLayer();
1515 if (layer && layer->drawsContent())
1522 void FrameView::setCannotBlitToWindow()
1524 m_cannotBlitToWindow = true;
1525 updateCanBlitOnScrollRecursively();
1528 void FrameView::addSlowRepaintObject(RenderElement* o)
1530 bool hadSlowRepaintObjects = hasSlowRepaintObjects();
1532 if (!m_slowRepaintObjects)
1533 m_slowRepaintObjects = std::make_unique<HashSet<RenderElement*>>();
1535 m_slowRepaintObjects->add(o);
1537 if (!hadSlowRepaintObjects) {
1538 updateCanBlitOnScrollRecursively();
1540 if (Page* page = frame().page()) {
1541 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
1542 scrollingCoordinator->frameViewHasSlowRepaintObjectsDidChange(this);
1547 void FrameView::removeSlowRepaintObject(RenderElement* o)
1549 if (!m_slowRepaintObjects)
1552 m_slowRepaintObjects->remove(o);
1553 if (m_slowRepaintObjects->isEmpty()) {
1554 m_slowRepaintObjects = nullptr;
1555 updateCanBlitOnScrollRecursively();
1557 if (Page* page = frame().page()) {
1558 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
1559 scrollingCoordinator->frameViewHasSlowRepaintObjectsDidChange(this);
1564 void FrameView::addViewportConstrainedObject(RenderElement* object)
1566 if (!m_viewportConstrainedObjects)
1567 m_viewportConstrainedObjects = std::make_unique<ViewportConstrainedObjectSet>();
1569 if (!m_viewportConstrainedObjects->contains(object)) {
1570 m_viewportConstrainedObjects->add(object);
1571 if (platformWidget())
1572 updateCanBlitOnScrollRecursively();
1574 if (Page* page = frame().page()) {
1575 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
1576 scrollingCoordinator->frameViewFixedObjectsDidChange(this);
1581 void FrameView::removeViewportConstrainedObject(RenderElement* object)
1583 if (m_viewportConstrainedObjects && m_viewportConstrainedObjects->remove(object)) {
1584 if (Page* page = frame().page()) {
1585 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
1586 scrollingCoordinator->frameViewFixedObjectsDidChange(this);
1589 // FIXME: In addFixedObject() we only call this if there's a platform widget,
1590 // why isn't the same check being made here?
1591 updateCanBlitOnScrollRecursively();
1595 LayoutRect FrameView::viewportConstrainedVisibleContentRect() const
1598 if (useCustomFixedPositionLayoutRect())
1599 return customFixedPositionLayoutRect();
1601 LayoutRect viewportRect = visibleContentRect();
1603 viewportRect.setLocation(toLayoutPoint(scrollOffsetForFixedPosition()));
1604 return viewportRect;
1607 LayoutSize FrameView::scrollOffsetForFixedPosition(const LayoutRect& visibleContentRect, const LayoutSize& totalContentsSize, const LayoutPoint& scrollPosition, const LayoutPoint& scrollOrigin, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame, ScrollBehaviorForFixedElements behaviorForFixed, int headerHeight, int footerHeight)
1609 LayoutPoint position;
1610 if (behaviorForFixed == StickToDocumentBounds)
1611 position = ScrollableArea::constrainScrollPositionForOverhang(visibleContentRect, totalContentsSize, scrollPosition, scrollOrigin, headerHeight, footerHeight);
1613 position = scrollPosition;
1614 position.setY(position.y() - headerHeight);
1617 LayoutSize maxSize = totalContentsSize - visibleContentRect.size();
1619 float dragFactorX = (fixedElementsLayoutRelativeToFrame || !maxSize.width()) ? 1 : (totalContentsSize.width() - visibleContentRect.width() * frameScaleFactor) / maxSize.width();
1620 float dragFactorY = (fixedElementsLayoutRelativeToFrame || !maxSize.height()) ? 1 : (totalContentsSize.height() - visibleContentRect.height() * frameScaleFactor) / maxSize.height();
1622 return LayoutSize(position.x() * dragFactorX / frameScaleFactor, position.y() * dragFactorY / frameScaleFactor);
1625 LayoutSize FrameView::scrollOffsetForFixedPosition() const
1627 IntRect visibleContentRect = this->visibleContentRect();
1628 IntSize totalContentsSize = this->totalContentsSize();
1629 IntPoint scrollPosition = this->scrollPosition();
1630 IntPoint scrollOrigin = this->scrollOrigin();
1631 float frameScaleFactor = frame().frameScaleFactor();
1632 ScrollBehaviorForFixedElements behaviorForFixed = scrollBehaviorForFixedElements();
1633 return scrollOffsetForFixedPosition(visibleContentRect, totalContentsSize, scrollPosition, scrollOrigin, frameScaleFactor, fixedElementsLayoutRelativeToFrame(), behaviorForFixed, headerHeight(), footerHeight());
1636 float FrameView::yPositionForInsetClipLayer(const FloatPoint& scrollPosition, float topContentInset)
1638 if (!topContentInset)
1641 // The insetClipLayer should not move for negative scroll values.
1642 float scrollY = std::max<float>(0, scrollPosition.y());
1644 if (scrollY >= topContentInset)
1647 return topContentInset - scrollY;
1650 float FrameView::yPositionForHeaderLayer(const FloatPoint& scrollPosition, float topContentInset)
1652 if (!topContentInset)
1655 float scrollY = std::max<float>(0, scrollPosition.y());
1657 if (scrollY >= topContentInset)
1658 return topContentInset;
1663 float FrameView::yPositionForRootContentLayer(const FloatPoint& scrollPosition, float topContentInset, float headerHeight)
1665 return yPositionForHeaderLayer(scrollPosition, topContentInset) + headerHeight;
1668 float FrameView::yPositionForFooterLayer(const FloatPoint& scrollPosition, float topContentInset, float totalContentsHeight, float footerHeight)
1670 return yPositionForHeaderLayer(scrollPosition, topContentInset) + totalContentsHeight - footerHeight;
1674 LayoutRect FrameView::rectForViewportConstrainedObjects(const LayoutRect& visibleContentRect, const LayoutSize& totalContentsSize, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame, ScrollBehaviorForFixedElements scrollBehavior)
1676 if (fixedElementsLayoutRelativeToFrame)
1677 return visibleContentRect;
1679 if (totalContentsSize.isEmpty())
1680 return visibleContentRect;
1682 // We impose an lower limit on the size (so an upper limit on the scale) of
1683 // the rect used to position fixed objects so that they don't crowd into the
1684 // center of the screen at larger scales.
1685 const LayoutUnit maxContentWidthForZoomThreshold = LayoutUnit::fromPixel(1024);
1686 float zoomedOutScale = frameScaleFactor * visibleContentRect.width() / std::min(maxContentWidthForZoomThreshold, totalContentsSize.width());
1687 float constraintThresholdScale = 1.5 * zoomedOutScale;
1688 float maxPostionedObjectsRectScale = std::min(frameScaleFactor, constraintThresholdScale);
1690 LayoutRect viewportConstrainedObjectsRect = visibleContentRect;
1692 if (frameScaleFactor > constraintThresholdScale) {
1693 FloatRect contentRect(FloatPoint(), totalContentsSize);
1694 FloatRect viewportRect = visibleContentRect;
1696 // Scale the rect up from a point that is relative to its position in the viewport.
1697 FloatSize sizeDelta = contentRect.size() - viewportRect.size();
1699 FloatPoint scaleOrigin;
1700 scaleOrigin.setX(contentRect.x() + sizeDelta.width() > 0 ? contentRect.width() * (viewportRect.x() - contentRect.x()) / sizeDelta.width() : 0);
1701 scaleOrigin.setY(contentRect.y() + sizeDelta.height() > 0 ? contentRect.height() * (viewportRect.y() - contentRect.y()) / sizeDelta.height() : 0);
1703 AffineTransform rescaleTransform = AffineTransform::translation(scaleOrigin.x(), scaleOrigin.y());
1704 rescaleTransform.scale(frameScaleFactor / maxPostionedObjectsRectScale, frameScaleFactor / maxPostionedObjectsRectScale);
1705 rescaleTransform = CGAffineTransformTranslate(rescaleTransform, -scaleOrigin.x(), -scaleOrigin.y());
1707 viewportConstrainedObjectsRect = enclosingLayoutRect(rescaleTransform.mapRect(visibleContentRect));
1710 if (scrollBehavior == StickToDocumentBounds) {
1711 LayoutRect documentBounds(LayoutPoint(), totalContentsSize);
1712 viewportConstrainedObjectsRect.intersect(documentBounds);
1715 return viewportConstrainedObjectsRect;
1718 LayoutRect FrameView::viewportConstrainedObjectsRect() const
1720 return rectForViewportConstrainedObjects(visibleContentRect(), totalContentsSize(), frame().frameScaleFactor(), fixedElementsLayoutRelativeToFrame(), scrollBehaviorForFixedElements());
1724 IntPoint FrameView::minimumScrollPosition() const
1726 IntPoint minimumPosition(ScrollView::minimumScrollPosition());
1728 if (frame().isMainFrame() && m_scrollPinningBehavior == PinToBottom)
1729 minimumPosition.setY(maximumScrollPosition().y());
1731 return minimumPosition;
1734 IntPoint FrameView::maximumScrollPosition() const
1736 IntPoint maximumOffset(contentsWidth() - visibleWidth() - scrollOrigin().x(), totalContentsSize().height() - visibleHeight() - scrollOrigin().y());
1738 maximumOffset.clampNegativeToZero();
1740 if (frame().isMainFrame() && m_scrollPinningBehavior == PinToTop)
1741 maximumOffset.setY(minimumScrollPosition().y());
1743 return maximumOffset;
1746 void FrameView::delayedScrollEventTimerFired()
1751 bool FrameView::fixedElementsLayoutRelativeToFrame() const
1753 return frame().settings().fixedElementsLayoutRelativeToFrame();
1756 IntPoint FrameView::lastKnownMousePosition() const
1758 return frame().eventHandler().lastKnownMousePosition();
1761 bool FrameView::isHandlingWheelEvent() const
1763 return frame().eventHandler().isHandlingWheelEvent();
1766 bool FrameView::shouldSetCursor() const
1768 Page* page = frame().page();
1769 return page && page->isVisible() && page->focusController().isActive();
1772 bool FrameView::scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
1774 if (!m_viewportConstrainedObjects || m_viewportConstrainedObjects->isEmpty()) {
1775 hostWindow()->scroll(scrollDelta, rectToScroll, clipRect);
1779 const bool isCompositedContentLayer = contentsInCompositedLayer();
1781 // Get the rects of the fixed objects visible in the rectToScroll
1782 Region regionToUpdate;
1783 for (auto& renderer : *m_viewportConstrainedObjects) {
1784 if (!renderer->style().hasViewportConstrainedPosition())
1786 if (renderer->isComposited())
1789 // Fixed items should always have layers.
1790 ASSERT(renderer->hasLayer());
1791 RenderLayer* layer = downcast<RenderBoxModelObject>(*renderer).layer();
1793 if (layer->viewportConstrainedNotCompositedReason() == RenderLayer::NotCompositedForBoundsOutOfView
1794 || layer->viewportConstrainedNotCompositedReason() == RenderLayer::NotCompositedForNoVisibleContent) {
1795 // Don't invalidate for invisible fixed layers.
1799 if (layer->hasAncestorWithFilterOutsets()) {
1800 // If the fixed layer has a blur/drop-shadow filter applied on at least one of its parents, we cannot
1801 // scroll using the fast path, otherwise the outsets of the filter will be moved around the page.
1805 IntRect updateRect = snappedIntRect(layer->repaintRectIncludingNonCompositingDescendants());
1806 updateRect = contentsToRootView(updateRect);
1807 if (!isCompositedContentLayer && clipsRepaints())
1808 updateRect.intersect(rectToScroll);
1809 if (!updateRect.isEmpty())
1810 regionToUpdate.unite(updateRect);
1814 hostWindow()->scroll(scrollDelta, rectToScroll, clipRect);
1816 // 2) update the area of fixed objects that has been invalidated
1817 Vector<IntRect> subRectsToUpdate = regionToUpdate.rects();
1818 size_t viewportConstrainedObjectsCount = subRectsToUpdate.size();
1819 for (size_t i = 0; i < viewportConstrainedObjectsCount; ++i) {
1820 IntRect updateRect = subRectsToUpdate[i];
1821 IntRect scrolledRect = updateRect;
1822 scrolledRect.move(scrollDelta);
1823 updateRect.unite(scrolledRect);
1824 if (isCompositedContentLayer) {
1825 updateRect = rootViewToContents(updateRect);
1826 ASSERT(renderView());
1827 renderView()->layer()->setBackingNeedsRepaintInRect(updateRect);
1830 if (clipsRepaints())
1831 updateRect.intersect(rectToScroll);
1832 hostWindow()->invalidateContentsAndRootView(updateRect);
1838 void FrameView::scrollContentsSlowPath(const IntRect& updateRect)
1840 if (contentsInCompositedLayer()) {
1841 // FIXME: respect paintsEntireContents()?
1842 IntRect updateRect = visibleContentRect(LegacyIOSDocumentVisibleRect);
1844 // Make sure to "apply" the scale factor here since we're converting from frame view
1845 // coordinates to layer backing coordinates.
1846 updateRect.scale(1 / frame().frameScaleFactor());
1848 ASSERT(renderView());
1849 renderView()->layer()->setBackingNeedsRepaintInRect(updateRect, GraphicsLayer::DoNotClipToLayer);
1852 repaintSlowRepaintObjects();
1854 if (RenderWidget* frameRenderer = frame().ownerRenderer()) {
1855 if (isEnclosedInCompositingLayer()) {
1856 LayoutRect rect(frameRenderer->borderLeft() + frameRenderer->paddingLeft(),
1857 frameRenderer->borderTop() + frameRenderer->paddingTop(),
1858 visibleWidth(), visibleHeight());
1859 frameRenderer->repaintRectangle(rect);
1864 ScrollView::scrollContentsSlowPath(updateRect);
1867 void FrameView::repaintSlowRepaintObjects()
1869 if (!m_slowRepaintObjects)
1872 // Renderers with fixed backgrounds may be in compositing layers, so we need to explicitly
1873 // repaint them after scrolling.
1874 for (auto& renderer : *m_slowRepaintObjects)
1875 renderer->repaintSlowRepaintObject();
1878 // Note that this gets called at painting time.
1879 void FrameView::setIsOverlapped(bool isOverlapped)
1881 if (isOverlapped == m_isOverlapped)
1884 m_isOverlapped = isOverlapped;
1885 updateCanBlitOnScrollRecursively();
1887 if (hasCompositedContentIncludingDescendants()) {
1888 // Overlap can affect compositing tests, so if it changes, we need to trigger
1889 // a layer update in the parent document.
1890 if (Frame* parentFrame = frame().tree().parent()) {
1891 if (RenderView* parentView = parentFrame->contentRenderer()) {
1892 RenderLayerCompositor& compositor = parentView->compositor();
1893 compositor.setCompositingLayersNeedRebuild();
1894 compositor.scheduleCompositingLayerUpdate();
1898 if (RenderLayerCompositor::allowsIndependentlyCompositedFrames(this)) {
1899 // We also need to trigger reevaluation for this and all descendant frames,
1900 // since a frame uses compositing if any ancestor is compositing.
1901 for (Frame* frame = m_frame.get(); frame; frame = frame->tree().traverseNext(m_frame.get())) {
1902 if (RenderView* view = frame->contentRenderer()) {
1903 RenderLayerCompositor& compositor = view->compositor();
1904 compositor.setCompositingLayersNeedRebuild();
1905 compositor.scheduleCompositingLayerUpdate();
1912 bool FrameView::isOverlappedIncludingAncestors() const
1917 if (FrameView* parentView = parentFrameView()) {
1918 if (parentView->isOverlapped())
1925 void FrameView::setContentIsOpaque(bool contentIsOpaque)
1927 if (contentIsOpaque == m_contentIsOpaque)
1930 m_contentIsOpaque = contentIsOpaque;
1931 updateCanBlitOnScrollRecursively();
1934 void FrameView::restoreScrollbar()
1936 setScrollbarsSuppressed(false);
1939 bool FrameView::scrollToFragment(const URL& url)
1941 // If our URL has no ref, then we have no place we need to jump to.
1942 // OTOH If CSS target was set previously, we want to set it to 0, recalc
1943 // and possibly repaint because :target pseudo class may have been
1944 // set (see bug 11321).
1945 if (!url.hasFragmentIdentifier() && !frame().document()->cssTarget())
1948 String fragmentIdentifier = url.fragmentIdentifier();
1949 if (scrollToAnchor(fragmentIdentifier))
1952 // Try again after decoding the ref, based on the document's encoding.
1953 if (TextResourceDecoder* decoder = frame().document()->decoder())
1954 return scrollToAnchor(decodeURLEscapeSequences(fragmentIdentifier, decoder->encoding()));
1959 bool FrameView::scrollToAnchor(const String& name)
1961 ASSERT(frame().document());
1963 if (!frame().document()->haveStylesheetsLoaded()) {
1964 frame().document()->setGotoAnchorNeededAfterStylesheetsLoad(true);
1968 frame().document()->setGotoAnchorNeededAfterStylesheetsLoad(false);
1970 Element* anchorElement = frame().document()->findAnchor(name);
1972 // Setting to null will clear the current target.
1973 frame().document()->setCSSTarget(anchorElement);
1975 if (is<SVGDocument>(*frame().document())) {
1976 if (SVGSVGElement* svg = downcast<SVGDocument>(*frame().document()).rootElement()) {
1977 svg->setupInitialView(name, anchorElement);
1983 // Implement the rule that "" and "top" both mean top of page as in other browsers.
1984 if (!anchorElement && !(name.isEmpty() || equalIgnoringCase(name, "top")))
1987 ContainerNode* scrollPositionAnchor = anchorElement;
1988 if (!scrollPositionAnchor)
1989 scrollPositionAnchor = frame().document();
1990 maintainScrollPositionAtAnchor(scrollPositionAnchor);
1992 // If the anchor accepts keyboard focus, move focus there to aid users relying on keyboard navigation.
1993 if (anchorElement && anchorElement->isFocusable())
1994 frame().document()->setFocusedElement(anchorElement);
1999 void FrameView::maintainScrollPositionAtAnchor(ContainerNode* anchorNode)
2001 m_maintainScrollPositionAnchor = anchorNode;
2002 if (!m_maintainScrollPositionAnchor)
2005 // We need to update the layout before scrolling, otherwise we could
2006 // really mess things up if an anchor scroll comes at a bad moment.
2007 frame().document()->updateStyleIfNeeded();
2008 // Only do a layout if changes have occurred that make it necessary.
2009 RenderView* renderView = this->renderView();
2010 if (renderView && renderView->needsLayout())
2016 void FrameView::scrollElementToRect(Element* element, const IntRect& rect)
2018 frame().document()->updateLayoutIgnorePendingStylesheets();
2020 LayoutRect bounds = rendererAnchorRect(*element);
2021 int centeringOffsetX = (rect.width() - bounds.width()) / 2;
2022 int centeringOffsetY = (rect.height() - bounds.height()) / 2;
2023 setScrollPosition(IntPoint(bounds.x() - centeringOffsetX - rect.x(), bounds.y() - centeringOffsetY - rect.y()));
2026 void FrameView::setScrollPosition(const IntPoint& scrollPoint)
2028 TemporaryChange<bool> changeInProgrammaticScroll(m_inProgrammaticScroll, true);
2029 m_maintainScrollPositionAnchor = nullptr;
2030 ScrollView::setScrollPosition(scrollPoint);
2033 void FrameView::delegatesScrollingDidChange()
2035 // When we switch to delgatesScrolling mode, we should destroy the scrolling/clipping layers in RenderLayerCompositor.
2036 if (hasCompositedContent())
2037 clearBackingStores();
2040 #if USE(TILED_BACKING_STORE)
2041 void FrameView::setFixedVisibleContentRect(const IntRect& visibleContentRect)
2043 bool visibleContentSizeDidChange = false;
2044 if (visibleContentRect.size() != this->fixedVisibleContentRect().size()) {
2045 // When the viewport size changes or the content is scaled, we need to
2046 // reposition the fixed and sticky positioned elements.
2047 setViewportConstrainedObjectsNeedLayout();
2048 visibleContentSizeDidChange = true;
2051 IntSize offset = scrollOffset();
2052 IntPoint oldPosition = scrollPosition();
2053 ScrollView::setFixedVisibleContentRect(visibleContentRect);
2054 if (offset != scrollOffset()) {
2055 updateLayerPositionsAfterScrolling();
2056 if (frame().page()->settings().acceleratedCompositingForFixedPositionEnabled())
2057 updateCompositingLayersAfterScrolling();
2058 IntPoint newPosition = scrollPosition();
2059 scrollAnimator()->setCurrentPosition(scrollPosition());
2060 scrollPositionChanged(oldPosition, newPosition);
2062 if (visibleContentSizeDidChange) {
2063 // Update the scroll-bars to calculate new page-step size.
2064 updateScrollbars(scrollOffset());
2066 didChangeScrollOffset();
2070 void FrameView::setViewportConstrainedObjectsNeedLayout()
2072 if (!hasViewportConstrainedObjects())
2075 for (auto& renderer : *m_viewportConstrainedObjects)
2076 renderer->setNeedsLayout();
2079 void FrameView::didChangeScrollOffset()
2081 frame().mainFrame().pageOverlayController().didScrollFrame(frame());
2082 frame().loader().client().didChangeScrollOffset();
2085 void FrameView::scrollPositionChangedViaPlatformWidget(const IntPoint& oldPosition, const IntPoint& newPosition)
2087 updateLayerPositionsAfterScrolling();
2088 updateCompositingLayersAfterScrolling();
2089 repaintSlowRepaintObjects();
2090 scrollPositionChanged(oldPosition, newPosition);
2093 void FrameView::scrollPositionChanged(const IntPoint& oldPosition, const IntPoint& newPosition)
2095 std::chrono::milliseconds throttlingDelay = frame().page()->chrome().client().eventThrottlingDelay();
2097 if (throttlingDelay == std::chrono::milliseconds::zero()) {
2098 m_delayedScrollEventTimer.stop();
2100 } else if (!m_delayedScrollEventTimer.isActive())
2101 m_delayedScrollEventTimer.startOneShot(throttlingDelay);
2103 if (Document* document = frame().document())
2104 document->sendWillRevealEdgeEventsIfNeeded(oldPosition, newPosition, visibleContentRect(), contentsSize());
2106 if (RenderView* renderView = this->renderView()) {
2107 if (renderView->usesCompositing())
2108 renderView->compositor().frameViewDidScroll();
2111 resumeVisibleImageAnimationsIncludingSubframes();
2112 updateThrottledDOMTimersState();
2115 void FrameView::resumeVisibleImageAnimationsIncludingSubframes()
2117 // A change in scroll position may affect image visibility in subframes.
2118 for (auto* frame = m_frame.get(); frame; frame = frame->tree().traverseNext(m_frame.get())) {
2119 if (auto* renderView = frame->contentRenderer())
2120 renderView->resumePausedImageAnimationsIfNeeded();
2124 void FrameView::updateLayerPositionsAfterScrolling()
2126 // If we're scrolling as a result of updating the view size after layout, we'll update widgets and layer positions soon anyway.
2127 if (m_layoutPhase == InViewSizeAdjust)
2130 if (m_nestedLayoutCount <= 1 && hasViewportConstrainedObjects()) {
2131 if (RenderView* renderView = this->renderView()) {
2132 updateWidgetPositions();
2133 renderView->layer()->updateLayerPositionsAfterDocumentScroll();
2138 bool FrameView::shouldUpdateCompositingLayersAfterScrolling() const
2140 #if ENABLE(ASYNC_SCROLLING)
2141 // If the scrolling thread is updating the fixed elements, then the FrameView should not update them as well.
2143 Page* page = frame().page();
2147 if (&page->mainFrame() != &frame())
2150 ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator();
2151 if (!scrollingCoordinator)
2154 if (!scrollingCoordinator->supportsFixedPositionLayers())
2157 if (scrollingCoordinator->shouldUpdateScrollLayerPositionSynchronously())
2160 if (inProgrammaticScroll())
2168 void FrameView::updateCompositingLayersAfterScrolling()
2170 if (!shouldUpdateCompositingLayersAfterScrolling())
2173 if (m_nestedLayoutCount <= 1 && hasViewportConstrainedObjects()) {
2174 if (RenderView* renderView = this->renderView())
2175 renderView->compositor().updateCompositingLayers(CompositingUpdateOnScroll);
2179 bool FrameView::isRubberBandInProgress() const
2181 if (scrollbarsSuppressed())
2184 // If the scrolling thread updates the scroll position for this FrameView, then we should return
2185 // ScrollingCoordinator::isRubberBandInProgress().
2186 if (Page* page = frame().page()) {
2187 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator()) {
2188 if (!scrollingCoordinator->shouldUpdateScrollLayerPositionSynchronously())
2189 return scrollingCoordinator->isRubberBandInProgress();
2193 // If the main thread updates the scroll position for this FrameView, we should return
2194 // ScrollAnimator::isRubberBandInProgress().
2195 if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
2196 return scrollAnimator->isRubberBandInProgress();
2201 bool FrameView::requestScrollPositionUpdate(const IntPoint& position)
2203 #if ENABLE(ASYNC_SCROLLING)
2204 if (TiledBacking* tiledBacking = this->tiledBacking())
2205 tiledBacking->prepopulateRect(FloatRect(position, visibleContentRect().size()));
2208 #if ENABLE(ASYNC_SCROLLING) || USE(TILED_BACKING_STORE)
2209 if (Page* page = frame().page()) {
2210 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
2211 return scrollingCoordinator->requestScrollPositionUpdate(this, position);
2214 UNUSED_PARAM(position);
2220 HostWindow* FrameView::hostWindow() const
2222 if (Page* page = frame().page())
2223 return &page->chrome();
2227 void FrameView::addTrackedRepaintRect(const FloatRect& r)
2229 if (!m_isTrackingRepaints || r.isEmpty())
2232 FloatRect repaintRect = r;
2233 repaintRect.move(-scrollOffset());
2234 m_trackedRepaintRects.append(repaintRect);
2237 void FrameView::repaintContentRectangle(const IntRect& r)
2239 ASSERT(!frame().ownerElement());
2241 if (!shouldUpdate())
2244 ScrollView::repaintContentRectangle(r);
2247 static unsigned countRenderedCharactersInRenderObjectWithThreshold(const RenderElement& renderer, unsigned threshold)
2250 for (const RenderObject* descendant = &renderer; descendant; descendant = descendant->nextInPreOrder()) {
2251 if (is<RenderText>(*descendant)) {
2252 count += downcast<RenderText>(*descendant).text()->length();
2253 if (count >= threshold)
2260 bool FrameView::renderedCharactersExceed(unsigned threshold)
2262 if (!m_frame->contentRenderer())
2264 return countRenderedCharactersInRenderObjectWithThreshold(*m_frame->contentRenderer(), threshold) >= threshold;
2267 void FrameView::contentsResized()
2269 ScrollView::contentsResized();
2273 void FrameView::fixedLayoutSizeChanged()
2275 // Can be triggered before the view is set, see comment in FrameView::visibleContentsResized().
2276 // An ASSERT is triggered when a view schedules a layout before being attached to a frame.
2277 if (!frame().view())
2279 ScrollView::fixedLayoutSizeChanged();
2282 bool FrameView::shouldLayoutAfterContentsResized() const
2284 return !useFixedLayout() || useCustomFixedPositionLayoutRect();
2287 void FrameView::visibleContentsResized()
2289 // We check to make sure the view is attached to a frame() as this method can
2290 // be triggered before the view is attached by Frame::createView(...) setting
2291 // various values such as setScrollBarModes(...) for example. An ASSERT is
2292 // triggered when a view is layout before being attached to a frame().
2293 if (!frame().view())
2297 if (RenderView* root = m_frame->contentRenderer()) {
2298 if (useCustomFixedPositionLayoutRect() && hasViewportConstrainedObjects()) {
2299 setViewportConstrainedObjectsNeedLayout();
2300 // We must eagerly enter compositing mode because fixed position elements
2301 // will not have been made compositing via a preceding style change before
2302 // m_useCustomFixedPositionLayoutRect was true.
2303 root->compositor().enableCompositingMode();
2308 if (shouldLayoutAfterContentsResized() && needsLayout())
2311 if (RenderView* renderView = this->renderView()) {
2312 if (renderView->usesCompositing())
2313 renderView->compositor().frameViewDidChangeSize();
2317 void FrameView::addedOrRemovedScrollbar()
2319 if (RenderView* renderView = this->renderView()) {
2320 if (renderView->usesCompositing())
2321 renderView->compositor().frameViewDidAddOrRemoveScrollbars();
2325 static LayerFlushThrottleState::Flags determineLayerFlushThrottleState(Page& page)
2327 // We only throttle when constantly receiving new data during the inital page load.
2328 if (!page.progress().isMainLoadProgressing())
2330 // Scrolling during page loading disables throttling.
2331 if (page.mainFrame().view()->wasScrolledByUser())
2333 // Disable for image documents so large GIF animations don't get throttled during loading.
2334 auto* document = page.mainFrame().document();
2335 if (!document || is<ImageDocument>(*document))
2337 return LayerFlushThrottleState::Enabled;
2340 void FrameView::disableLayerFlushThrottlingTemporarilyForInteraction()
2342 if (!frame().page())
2344 auto& page = *frame().page();
2346 LayerFlushThrottleState::Flags flags = LayerFlushThrottleState::UserIsInteracting | determineLayerFlushThrottleState(page);
2347 if (page.chrome().client().adjustLayerFlushThrottling(flags))
2350 if (RenderView* view = renderView())
2351 view->compositor().disableLayerFlushThrottlingTemporarilyForInteraction();
2354 void FrameView::loadProgressingStatusChanged()
2356 updateLayerFlushThrottling();
2357 adjustTiledBackingCoverage();
2360 void FrameView::updateLayerFlushThrottling()
2362 ASSERT(frame().isMainFrame());
2363 auto& page = *frame().page();
2365 LayerFlushThrottleState::Flags flags = determineLayerFlushThrottleState(page);
2367 // See if the client is handling throttling.
2368 if (page.chrome().client().adjustLayerFlushThrottling(flags))
2371 for (Frame* frame = m_frame.get(); frame; frame = frame->tree().traverseNext(m_frame.get())) {
2372 if (RenderView* renderView = frame->contentRenderer())
2373 renderView->compositor().setLayerFlushThrottlingEnabled(flags & LayerFlushThrottleState::Enabled);
2377 void FrameView::adjustTiledBackingCoverage()
2379 if (!m_speculativeTilingEnabled)
2380 enableSpeculativeTilingIfNeeded();
2382 RenderView* renderView = this->renderView();
2383 if (renderView && renderView->layer()->backing())
2384 renderView->layer()->backing()->adjustTiledBackingCoverage();
2386 if (LegacyTileCache* tileCache = legacyTileCache())
2387 tileCache->setSpeculativeTileCreationEnabled(m_speculativeTilingEnabled);
2391 static bool shouldEnableSpeculativeTilingDuringLoading(const FrameView& view)
2393 return view.isVisuallyNonEmpty() && !view.frame().page()->progress().isMainLoadProgressing();
2396 void FrameView::enableSpeculativeTilingIfNeeded()
2398 ASSERT(!m_speculativeTilingEnabled);
2399 if (m_wasScrolledByUser) {
2400 m_speculativeTilingEnabled = true;
2403 if (!shouldEnableSpeculativeTilingDuringLoading(*this))
2405 if (m_speculativeTilingEnableTimer.isActive())
2407 // Delay enabling a bit as load completion may trigger further loading from scripts.
2408 static const double speculativeTilingEnableDelay = 0.5;
2409 m_speculativeTilingEnableTimer.startOneShot(speculativeTilingEnableDelay);
2412 void FrameView::speculativeTilingEnableTimerFired()
2414 if (m_speculativeTilingEnabled)
2416 m_speculativeTilingEnabled = shouldEnableSpeculativeTilingDuringLoading(*this);
2417 adjustTiledBackingCoverage();
2420 void FrameView::layoutTimerFired()
2422 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
2423 if (!frame().document()->ownerElement())
2424 printf("Layout timer fired at %lld\n", frame().document()->elapsedTime().count());
2429 void FrameView::scheduleRelayout()
2431 // FIXME: We should assert the page is not in the page cache, but that is causing
2432 // too many false assertions. See <rdar://problem/7218118>.
2433 ASSERT(frame().view() == this);
2436 m_layoutRoot->markContainingBlocksForLayout(false);
2439 if (!m_layoutSchedulingEnabled)
2443 if (!frame().document()->shouldScheduleLayout())
2445 InspectorInstrumentation::didInvalidateLayout(&frame());
2446 // When frame flattening is enabled, the contents of the frame could affect the layout of the parent frames.
2447 // Also invalidate parent frame starting from the owner element of this frame.
2448 if (frame().ownerRenderer() && isInChildFrameWithFrameFlattening())
2449 frame().ownerRenderer()->setNeedsLayout(MarkContainingBlockChain);
2451 std::chrono::milliseconds delay = frame().document()->minimumLayoutDelay();
2452 if (m_layoutTimer.isActive() && m_delayedLayout && !delay.count())
2453 unscheduleRelayout();
2454 if (m_layoutTimer.isActive())
2457 m_delayedLayout = delay.count();
2459 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
2460 if (!frame().document()->ownerElement())
2461 printf("Scheduling layout for %d\n", delay);
2464 m_layoutTimer.startOneShot(delay);
2467 static bool isObjectAncestorContainerOf(RenderObject* ancestor, RenderObject* descendant)
2469 for (RenderObject* r = descendant; r; r = r->container()) {
2476 void FrameView::scheduleRelayoutOfSubtree(RenderElement& newRelayoutRoot)
2478 ASSERT(renderView());
2479 RenderView& renderView = *this->renderView();
2481 // Try to catch unnecessary work during render tree teardown.
2482 ASSERT(!renderView.documentBeingDestroyed());
2483 ASSERT(frame().view() == this);
2485 if (renderView.needsLayout()) {
2486 newRelayoutRoot.markContainingBlocksForLayout(false);
2490 if (!layoutPending() && m_layoutSchedulingEnabled) {
2491 std::chrono::milliseconds delay = renderView.document().minimumLayoutDelay();
2492 ASSERT(!newRelayoutRoot.container() || !newRelayoutRoot.container()->needsLayout());
2493 m_layoutRoot = &newRelayoutRoot;
2494 InspectorInstrumentation::didInvalidateLayout(&frame());
2495 m_delayedLayout = delay.count();
2496 m_layoutTimer.startOneShot(delay);
2500 if (m_layoutRoot == &newRelayoutRoot)
2503 if (!m_layoutRoot) {
2504 // Just relayout the subtree.
2505 newRelayoutRoot.markContainingBlocksForLayout(false);
2506 InspectorInstrumentation::didInvalidateLayout(&frame());
2510 if (isObjectAncestorContainerOf(m_layoutRoot, &newRelayoutRoot)) {
2511 // Keep the current root.
2512 newRelayoutRoot.markContainingBlocksForLayout(false, m_layoutRoot);
2513 ASSERT(!m_layoutRoot->container() || !m_layoutRoot->container()->needsLayout());
2517 if (isObjectAncestorContainerOf(&newRelayoutRoot, m_layoutRoot)) {
2518 // Re-root at newRelayoutRoot.
2519 m_layoutRoot->markContainingBlocksForLayout(false, &newRelayoutRoot);
2520 m_layoutRoot = &newRelayoutRoot;
2521 ASSERT(!m_layoutRoot->container() || !m_layoutRoot->container()->needsLayout());
2522 InspectorInstrumentation::didInvalidateLayout(&frame());
2526 // Just do a full relayout.
2527 m_layoutRoot->markContainingBlocksForLayout(false);
2529 newRelayoutRoot.markContainingBlocksForLayout(false);
2530 InspectorInstrumentation::didInvalidateLayout(&frame());
2533 bool FrameView::layoutPending() const
2535 return m_layoutTimer.isActive();
2538 bool FrameView::needsLayout() const
2540 // This can return true in cases where the document does not have a body yet.
2541 // Document::shouldScheduleLayout takes care of preventing us from scheduling
2542 // layout in that case.
2543 RenderView* renderView = this->renderView();
2544 return layoutPending()
2545 || (renderView && renderView->needsLayout())
2547 || (m_deferSetNeedsLayouts && m_setNeedsLayoutWasDeferred);
2550 void FrameView::setNeedsLayout()
2552 if (m_deferSetNeedsLayouts) {
2553 m_setNeedsLayoutWasDeferred = true;
2557 if (RenderView* renderView = this->renderView())
2558 renderView->setNeedsLayout();
2561 void FrameView::unscheduleRelayout()
2563 if (!m_layoutTimer.isActive())
2566 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
2567 if (!frame().document()->ownerElement())
2568 printf("Layout timer unscheduled at %d\n", frame().document()->elapsedTime());
2571 m_layoutTimer.stop();
2572 m_delayedLayout = false;
2575 #if ENABLE(REQUEST_ANIMATION_FRAME)
2576 void FrameView::serviceScriptedAnimations(double monotonicAnimationStartTime)
2578 for (Frame* frame = m_frame.get(); frame; frame = frame->tree().traverseNext()) {
2579 frame->view()->serviceScrollAnimations();
2580 frame->animation().serviceAnimations();
2583 Vector<RefPtr<Document>> documents;
2584 for (Frame* frame = m_frame.get(); frame; frame = frame->tree().traverseNext())
2585 documents.append(frame->document());
2587 for (size_t i = 0; i < documents.size(); ++i)
2588 documents[i]->serviceScriptedAnimations(monotonicAnimationStartTime);
2592 bool FrameView::isTransparent() const
2594 return m_isTransparent;
2597 void FrameView::setTransparent(bool isTransparent)
2599 if (m_isTransparent == isTransparent)
2602 m_isTransparent = isTransparent;
2604 RenderView* renderView = this->renderView();
2608 // setTransparent can be called in the window between FrameView initialization
2609 // and switching in the new Document; this means that the RenderView that we
2610 // retrieve is actually attached to the previous Document, which is going away,
2611 // and must not update compositing layers.
2612 if (&renderView->frameView() != this)
2615 RenderLayerCompositor& compositor = renderView->compositor();
2616 compositor.setCompositingLayersNeedRebuild();
2617 compositor.scheduleCompositingLayerUpdate();
2620 bool FrameView::hasOpaqueBackground() const
2622 return !m_isTransparent && !m_baseBackgroundColor.hasAlpha();
2625 Color FrameView::baseBackgroundColor() const
2627 return m_baseBackgroundColor;
2630 void FrameView::setBaseBackgroundColor(const Color& backgroundColor)
2632 if (!backgroundColor.isValid())
2633 m_baseBackgroundColor = Color::white;
2635 m_baseBackgroundColor = backgroundColor;
2637 recalculateScrollbarOverlayStyle();
2640 void FrameView::updateBackgroundRecursively(const Color& backgroundColor, bool transparent)
2642 for (Frame* frame = m_frame.get(); frame; frame = frame->tree().traverseNext(m_frame.get())) {
2643 if (FrameView* view = frame->view()) {
2644 view->setTransparent(transparent);
2645 view->setBaseBackgroundColor(backgroundColor);
2650 bool FrameView::hasExtendedBackgroundRectForPainting() const
2652 if (!frame().settings().backgroundShouldExtendBeyondPage())
2655 TiledBacking* tiledBacking = this->tiledBacking();
2659 return tiledBacking->hasMargins();
2662 void FrameView::updateExtendBackgroundIfNecessary()
2664 ExtendedBackgroundMode mode = calculateExtendedBackgroundMode();
2665 if (mode == ExtendedBackgroundModeNone)
2668 updateTilesForExtendedBackgroundMode(mode);
2671 FrameView::ExtendedBackgroundMode FrameView::calculateExtendedBackgroundMode() const
2673 // Just because Settings::backgroundShouldExtendBeyondPage() is true does not necessarily mean
2674 // that the background rect needs to be extended for painting. Simple backgrounds can be extended
2675 // just with RenderLayerCompositor::setRootExtendedBackgroundColor(). More complicated backgrounds,
2676 // such as images, require extending the background rect to continue painting into the extended
2677 // region. This function finds out if it is necessary to extend the background rect for painting.
2680 // <rdar://problem/16201373>
2681 return ExtendedBackgroundModeNone;
2684 if (!frame().settings().backgroundShouldExtendBeyondPage())
2685 return ExtendedBackgroundModeNone;
2687 if (!frame().isMainFrame())
2688 return ExtendedBackgroundModeNone;
2690 Document* document = frame().document();
2692 return ExtendedBackgroundModeNone;
2694 auto documentElement = document->documentElement();
2695 auto documentElementRenderer = documentElement ? documentElement->renderer() : nullptr;
2696 if (!documentElementRenderer)
2697 return ExtendedBackgroundModeNone;
2699 auto& renderer = documentElementRenderer->rendererForRootBackground();
2700 if (!renderer.style().hasBackgroundImage())
2701 return ExtendedBackgroundModeNone;
2703 ExtendedBackgroundMode mode = ExtendedBackgroundModeNone;
2705 if (renderer.style().backgroundRepeatX() == RepeatFill)
2706 mode |= ExtendedBackgroundModeHorizontal;
2707 if (renderer.style().backgroundRepeatY() == RepeatFill)
2708 mode |= ExtendedBackgroundModeVertical;
2713 void FrameView::updateTilesForExtendedBackgroundMode(ExtendedBackgroundMode mode)
2715 if (!frame().settings().backgroundShouldExtendBeyondPage())
2718 RenderView* renderView = this->renderView();
2722 RenderLayerBacking* backing = renderView->layer()->backing();
2726 TiledBacking* tiledBacking = backing->graphicsLayer()->tiledBacking();
2730 ExtendedBackgroundMode existingMode = ExtendedBackgroundModeNone;
2731 if (tiledBacking->hasVerticalMargins())
2732 existingMode |= ExtendedBackgroundModeVertical;
2733 if (tiledBacking->hasHorizontalMargins())
2734 existingMode |= ExtendedBackgroundModeHorizontal;
2736 if (existingMode == mode)
2739 renderView->compositor().setRootExtendedBackgroundColor(mode == ExtendedBackgroundModeAll ? Color() : documentBackgroundColor());
2740 backing->setTiledBackingHasMargins(mode & ExtendedBackgroundModeHorizontal, mode & ExtendedBackgroundModeVertical);
2743 IntRect FrameView::extendedBackgroundRectForPainting() const
2745 TiledBacking* tiledBacking = this->tiledBacking();
2749 RenderView* renderView = this->renderView();
2753 LayoutRect extendedRect = renderView->unextendedBackgroundRect(renderView);
2754 if (!tiledBacking->hasMargins())
2755 return snappedIntRect(extendedRect);
2757 extendedRect.moveBy(LayoutPoint(-tiledBacking->leftMarginWidth(), -tiledBacking->topMarginHeight()));
2758 extendedRect.expand(LayoutSize(tiledBacking->leftMarginWidth() + tiledBacking->rightMarginWidth(), tiledBacking->topMarginHeight() + tiledBacking->bottomMarginHeight()));
2759 return snappedIntRect(extendedRect);
2762 bool FrameView::shouldUpdateWhileOffscreen() const
2764 return m_shouldUpdateWhileOffscreen;
2767 void FrameView::setShouldUpdateWhileOffscreen(bool shouldUpdateWhileOffscreen)
2769 m_shouldUpdateWhileOffscreen = shouldUpdateWhileOffscreen;
2772 bool FrameView::shouldUpdate() const
2774 if (isOffscreen() && !shouldUpdateWhileOffscreen())
2779 void FrameView::scrollToAnchor()
2781 RefPtr<ContainerNode> anchorNode = m_maintainScrollPositionAnchor;
2785 if (!anchorNode->renderer())
2789 if (anchorNode != frame().document())
2790 rect = rendererAnchorRect(*anchorNode.get());
2792 // Scroll nested layers and frames to reveal the anchor.
2793 // Align to the top and to the closest side (this matches other browsers).
2794 anchorNode->renderer()->scrollRectToVisible(rect, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignTopAlways);
2796 if (AXObjectCache* cache = frame().document()->existingAXObjectCache())
2797 cache->handleScrolledToAnchor(anchorNode.get());
2799 // scrollRectToVisible can call into setScrollPosition(), which resets m_maintainScrollPositionAnchor.
2800 m_maintainScrollPositionAnchor = anchorNode;
2803 void FrameView::updateEmbeddedObject(RenderEmbeddedObject& embeddedObject)
2805 // No need to update if it's already crashed or known to be missing.
2806 if (embeddedObject.isPluginUnavailable())
2809 HTMLFrameOwnerElement& element = embeddedObject.frameOwnerElement();
2811 if (embeddedObject.isSnapshottedPlugIn()) {
2812 if (is<HTMLObjectElement>(element) || is<HTMLEmbedElement>(element)) {
2813 HTMLPlugInImageElement& pluginElement = downcast<HTMLPlugInImageElement>(element);
2814 pluginElement.checkSnapshotStatus();
2819 auto weakRenderer = embeddedObject.createWeakPtr();
2821 // FIXME: This could turn into a real virtual dispatch if we defined
2822 // updateWidget(PluginCreationOption) on HTMLElement.
2823 if (is<HTMLPlugInImageElement>(element)) {
2824 HTMLPlugInImageElement& pluginElement = downcast<HTMLPlugInImageElement>(element);
2825 if (pluginElement.needsCheckForSizeChange()) {
2826 pluginElement.checkSnapshotStatus();
2829 if (pluginElement.needsWidgetUpdate())
2830 pluginElement.updateWidget(CreateAnyWidgetType);
2832 ASSERT_NOT_REACHED();
2834 // It's possible the renderer was destroyed below updateWidget() since loading a plugin may execute arbitrary JavaScript.
2838 embeddedObject.updateWidgetPosition();
2841 bool FrameView::updateEmbeddedObjects()
2843 if (m_nestedLayoutCount > 1 || !m_embeddedObjectsToUpdate || m_embeddedObjectsToUpdate->isEmpty())
2846 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
2848 // Insert a marker for where we should stop.
2849 ASSERT(!m_embeddedObjectsToUpdate->contains(nullptr));
2850 m_embeddedObjectsToUpdate->add(nullptr);
2852 while (!m_embeddedObjectsToUpdate->isEmpty()) {
2853 RenderEmbeddedObject* embeddedObject = m_embeddedObjectsToUpdate->takeFirst();
2854 if (!embeddedObject)
2856 updateEmbeddedObject(*embeddedObject);
2859 return m_embeddedObjectsToUpdate->isEmpty();
2862 void FrameView::updateEmbeddedObjectsTimerFired()
2864 RefPtr<FrameView> protect(this);
2865 m_updateEmbeddedObjectsTimer.stop();
2866 for (unsigned i = 0; i < maxUpdateEmbeddedObjectsIterations; i++) {
2867 if (updateEmbeddedObjects())
2872 void FrameView::flushAnyPendingPostLayoutTasks()
2874 if (m_postLayoutTasksTimer.isActive())
2875 performPostLayoutTasks();
2876 if (m_updateEmbeddedObjectsTimer.isActive())
2877 updateEmbeddedObjectsTimerFired();
2880 void FrameView::performPostLayoutTasks()
2882 // FIXME: We should not run any JavaScript code in this function.
2884 m_postLayoutTasksTimer.stop();
2886 frame().selection().didLayout();
2888 if (m_nestedLayoutCount <= 1 && frame().document()->documentElement())
2889 fireLayoutRelatedMilestonesIfNeeded();
2892 // Only send layout-related delegate callbacks synchronously for the main frame to
2893 // avoid re-entering layout for the main frame while delivering a layout-related delegate
2894 // callback for a subframe.
2895 if (frame().isMainFrame())
2896 frame().page()->chrome().client().didLayout();
2899 #if ENABLE(FONT_LOAD_EVENTS)
2900 if (RuntimeEnabledFeatures::sharedFeatures().fontLoadEventsEnabled())
2901 frame().document()->fonts()->didLayout();
2904 // FIXME: We should consider adding DidLayout as a LayoutMilestone. That would let us merge this
2905 // with didLayout(LayoutMilestones).
2906 frame().loader().client().dispatchDidLayout();
2908 updateWidgetPositions();
2910 // layout() protects FrameView, but it still can get destroyed when updateEmbeddedObjects()
2911 // is called through the post layout timer.
2912 Ref<FrameView> protect(*this);
2914 m_updateEmbeddedObjectsTimer.startOneShot(0);
2916 if (auto* page = frame().page()) {
2917 if (auto* scrollingCoordinator = page->scrollingCoordinator())
2918 scrollingCoordinator->frameViewLayoutUpdated(this);
2921 if (RenderView* renderView = this->renderView()) {
2922 if (renderView->usesCompositing())
2923 renderView->compositor().frameViewDidLayout();
2928 sendResizeEventIfNeeded();
2930 // Check if we should unthrottle DOMTimers after layout as the position
2931 // of Elements may have changed.
2932 updateThrottledDOMTimersState();
2935 IntSize FrameView::sizeForResizeEvent() const
2938 if (m_useCustomSizeForResizeEvent)
2939 return m_customSizeForResizeEvent;
2941 if (useFixedLayout() && !fixedLayoutSize().isEmpty() && delegatesScrolling())
2942 return fixedLayoutSize();
2943 return visibleContentRectIncludingScrollbars().size();
2946 void FrameView::sendResizeEventIfNeeded()
2948 if (isInLayout() || needsLayout())
2951 RenderView* renderView = this->renderView();
2952 if (!renderView || renderView->printing())
2955 if (frame().page() && frame().page()->chrome().client().isSVGImageChromeClient())
2958 IntSize currentSize = sizeForResizeEvent();
2959 float currentZoomFactor = renderView->style().zoom();
2961 if (currentSize == m_lastViewportSize && currentZoomFactor == m_lastZoomFactor)
2964 m_lastViewportSize = currentSize;
2965 m_lastZoomFactor = currentZoomFactor;
2971 // Don't send the resize event if the document is loading. Some pages automatically reload
2972 // when the window is resized; Safari on iOS often resizes the window while setting up its
2973 // viewport. This obviously can cause problems.
2974 if (DocumentLoader* documentLoader = frame().loader().documentLoader()) {
2975 if (documentLoader->isLoadingInAPISense())
2980 bool isMainFrame = frame().isMainFrame();
2981 bool canSendResizeEventSynchronously = isMainFrame && !m_shouldAutoSize;
2983 RefPtr<Event> resizeEvent = Event::create(eventNames().resizeEvent, false, false);
2984 if (canSendResizeEventSynchronously)
2985 frame().document()->dispatchWindowEvent(resizeEvent.release());
2987 // FIXME: Queueing this event for an unpredictable time in the future seems
2988 // intrinsically racy. By the time this resize event fires, the frame might
2989 // be resized again, so we could end up with two resize events for the same size.
2990 frame().document()->enqueueWindowEvent(resizeEvent.release());
2993 #if ENABLE(INSPECTOR)
2994 if (InspectorInstrumentation::hasFrontends() && isMainFrame) {
2995 if (Page* page = frame().page()) {
2996 if (InspectorClient* inspectorClient = page->inspectorController().inspectorClient())
2997 inspectorClient->didResizeMainFrame(&frame());
3003 void FrameView::willStartLiveResize()
3005 ScrollView::willStartLiveResize();
3006 adjustTiledBackingCoverage();
3009 void FrameView::willEndLiveResize()
3011 ScrollView::willEndLiveResize();
3012 adjustTiledBackingCoverage();
3015 void FrameView::postLayoutTimerFired()
3017 performPostLayoutTasks();
3020 void FrameView::registerThrottledDOMTimer(DOMTimer* timer)
3022 m_throttledTimers.add(timer);
3025 void FrameView::unregisterThrottledDOMTimer(DOMTimer* timer)
3027 m_throttledTimers.remove(timer);
3030 void FrameView::updateThrottledDOMTimersState()
3032 if (m_throttledTimers.isEmpty())
3035 IntRect visibleRect = windowToContents(windowClipRect());
3037 // Do not iterate over the HashSet because calling DOMTimer::updateThrottlingStateAfterViewportChange()
3038 // may cause timers to remove themselves from it while we are iterating.
3039 Vector<DOMTimer*> timers;
3040 copyToVector(m_throttledTimers, timers);
3041 for (auto* timer : timers)
3042 timer->updateThrottlingStateAfterViewportChange(visibleRect);
3045 void FrameView::autoSizeIfEnabled()
3047 if (!m_shouldAutoSize)
3053 TemporaryChange<bool> changeInAutoSize(m_inAutoSize, true);
3055 Document* document = frame().document();
3059 RenderView* documentView = document->renderView();
3060 Element* documentElement = document->documentElement();
3061 if (!documentView || !documentElement)
3064 // Start from the minimum size and allow it to grow.
3065 resize(m_minAutoSize.width(), m_minAutoSize.height());
3067 IntSize size = frameRect().size();
3069 // Do the resizing twice. The first time is basically a rough calculation using the preferred width
3070 // which may result in a height change during the second iteration.
3071 for (int i = 0; i < 2; i++) {
3072 // Update various sizes including contentsSize, scrollHeight, etc.
3073 document->updateLayoutIgnorePendingStylesheets();
3074 int width = documentView->minPreferredLogicalWidth();
3075 int height = documentView->documentRect().height();
3076 IntSize newSize(width, height);
3078 // Check to see if a scrollbar is needed for a given dimension and
3079 // if so, increase the other dimension to account for the scrollbar.
3080 // Since the dimensions are only for the view rectangle, once a
3081 // dimension exceeds the maximum, there is no need to increase it further.
3082 if (newSize.width() > m_maxAutoSize.width()) {
3083 RefPtr<Scrollbar> localHorizontalScrollbar = horizontalScrollbar();
3084 if (!localHorizontalScrollbar)
3085 localHorizontalScrollbar = createScrollbar(HorizontalScrollbar);
3086 if (!localHorizontalScrollbar->isOverlayScrollbar())
3087 newSize.setHeight(newSize.height() + localHorizontalScrollbar->height());
3089 // Don't bother checking for a vertical scrollbar because the width is at
3090 // already greater the maximum.
3091 } else if (newSize.height() > m_maxAutoSize.height()) {
3092 RefPtr<Scrollbar> localVerticalScrollbar = verticalScrollbar();
3093 if (!localVerticalScrollbar)
3094 localVerticalScrollbar = createScrollbar(VerticalScrollbar);
3095 if (!localVerticalScrollbar->isOverlayScrollbar())
3096 newSize.setWidth(newSize.width() + localVerticalScrollbar->width());
3098 // Don't bother checking for a horizontal scrollbar because the height is
3099 // already greater the maximum.
3102 // Ensure the size is at least the min bounds.
3103 newSize = newSize.expandedTo(m_minAutoSize);
3105 // Bound the dimensions by the max bounds and determine what scrollbars to show.
3106 ScrollbarMode horizonalScrollbarMode = ScrollbarAlwaysOff;
3107 if (newSize.width() > m_maxAutoSize.width()) {
3108 newSize.setWidth(m_maxAutoSize.width());
3109 horizonalScrollbarMode = ScrollbarAlwaysOn;
3111 ScrollbarMode verticalScrollbarMode = ScrollbarAlwaysOff;
3112 if (newSize.height() > m_maxAutoSize.height()) {
3113 newSize.setHeight(m_maxAutoSize.height());
3114 verticalScrollbarMode = ScrollbarAlwaysOn;
3117 if (newSize == size)
3120 // While loading only allow the size to increase (to avoid twitching during intermediate smaller states)
3121 // unless autoresize has just been turned on or the maximum size is smaller than the current size.
3122 if (m_didRunAutosize && size.height() <= m_maxAutoSize.height() && size.width() <= m_maxAutoSize.width()
3123 && !frame().loader().isComplete() && (newSize.height() < size.height() || newSize.width() < size.width()))
3126 resize(newSize.width(), newSize.height());
3127 // Force the scrollbar state to avoid the scrollbar code adding them and causing them to be needed. For example,
3128 // a vertical scrollbar may cause text to wrap and thus increase the height (which is the only reason the scollbar is needed).
3129 setVerticalScrollbarLock(false);
3130 setHorizontalScrollbarLock(false);
3131 setScrollbarModes(horizonalScrollbarMode, verticalScrollbarMode, true, true);
3134 m_autoSizeContentSize = contentsSize();
3136 if (m_autoSizeFixedMinimumHeight) {
3137 resize(m_autoSizeContentSize.width(), std::max(m_autoSizeFixedMinimumHeight, m_autoSizeContentSize.height()));
3138 document->updateLayoutIgnorePendingStylesheets();
3141 m_didRunAutosize = true;
3144 void FrameView::setAutoSizeFixedMinimumHeight(int fixedMinimumHeight)
3146 if (m_autoSizeFixedMinimumHeight == fixedMinimumHeight)
3149 m_autoSizeFixedMinimumHeight = fixedMinimumHeight;
3154 void FrameView::updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow)
3156 if (!m_viewportRenderer)
3159 if (m_overflowStatusDirty) {
3160 m_horizontalOverflow = horizontalOverflow;
3161 m_verticalOverflow = verticalOverflow;
3162 m_overflowStatusDirty = false;
3166 bool horizontalOverflowChanged = (m_horizontalOverflow != horizontalOverflow);
3167 bool verticalOverflowChanged = (m_verticalOverflow != verticalOverflow);
3169 if (horizontalOverflowChanged || verticalOverflowChanged) {
3170 m_horizontalOverflow = horizontalOverflow;
3171 m_verticalOverflow = verticalOverflow;
3173 RefPtr<OverflowEvent> overflowEvent = OverflowEvent::create(horizontalOverflowChanged, horizontalOverflow,
3174 verticalOverflowChanged, verticalOverflow);
3175 overflowEvent->setTarget(m_viewportRenderer->element());
3177 frame().document()->enqueueOverflowEvent(overflowEvent.release());
3181 const Pagination& FrameView::pagination() const
3183 if (m_pagination != Pagination())
3184 return m_pagination;
3186 if (frame().isMainFrame())
3187 return frame().page()->pagination();
3189 return m_pagination;
3192 void FrameView::setPagination(const Pagination& pagination)
3194 if (m_pagination == pagination)
3197 m_pagination = pagination;
3199 frame().document()->styleResolverChanged(DeferRecalcStyle);
3202 IntRect FrameView::windowClipRect(bool clipToContents) const
3204 ASSERT(frame().view() == this);
3206 if (paintsEntireContents())
3207 return contentsToWindow(IntRect(IntPoint(), totalContentsSize()));
3209 // Set our clip rect to be our contents.
3212 clipRect = contentsToWindow(visibleContentRect(LegacyIOSDocumentVisibleRect));
3214 clipRect = contentsToWindow(visibleContentRectIncludingScrollbars(LegacyIOSDocumentVisibleRect));
3215 if (!frame().ownerElement())
3218 // Take our owner element and get its clip rect.
3219 HTMLFrameOwnerElement* ownerElement = frame().ownerElement();
3220 if (FrameView* parentView = ownerElement->document().view())
3221 clipRect.intersect(parentView->windowClipRectForFrameOwner(ownerElement, true));
3225 IntRect FrameView::windowClipRectForFrameOwner(const HTMLFrameOwnerElement* ownerElement, bool clipToLayerContents) const
3227 // The renderer can sometimes be null when style="display:none" interacts
3228 // with external content and plugins.
3229 if (!ownerElement->renderer())
3230 return windowClipRect();
3232 // If we have no layer, just return our window clip rect.
3233 const RenderLayer* enclosingLayer = ownerElement->renderer()->enclosingLayer();
3234 if (!enclosingLayer)
3235 return windowClipRect();
3237 // Apply the clip from the layer.
3239 if (clipToLayerContents)
3240 clipRect = snappedIntRect(enclosingLayer->childrenClipRect());
3242 clipRect = snappedIntRect(enclosingLayer->selfClipRect());
3243 clipRect = contentsToWindow(clipRect);
3244 return intersection(clipRect, windowClipRect());
3247 bool FrameView::isActive() const
3249 Page* page = frame().page();
3250 return page && page->focusController().isActive();
3253 bool FrameView::updatesScrollLayerPositionOnMainThread() const
3255 if (Page* page = frame().page()) {
3256 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
3257 return scrollingCoordinator->shouldUpdateScrollLayerPositionSynchronously();
3263 bool FrameView::forceUpdateScrollbarsOnMainThreadForPerformanceTesting() const
3265 Page* page = frame().page();
3266 return page && page->settings().forceUpdateScrollbarsOnMainThreadForPerformanceTesting();
3269 void FrameView::scrollTo(const IntSize& newOffset)
3271 LayoutSize offset = scrollOffset();
3272 IntPoint oldPosition = scrollPosition();
3273 ScrollView::scrollTo(newOffset);
3274 if (offset != scrollOffset())
3275 scrollPositionChanged(oldPosition, scrollPosition());
3276 didChangeScrollOffset();
3279 float FrameView::adjustScrollStepForFixedContent(float step, ScrollbarOrientation orientation, ScrollGranularity granularity)
3281 if (granularity != ScrollByPage || orientation == HorizontalScrollbar)
3284 TrackedRendererListHashSet* positionedObjects = nullptr;
3285 if (RenderView* root = m_frame->contentRenderer()) {
3286 if (!root->hasPositionedObjects())
3288 positionedObjects = root->positionedObjects();
3291 FloatRect unobscuredContentRect = this->unobscuredContentRect();
3292 float topObscuredArea = 0;
3293 float bottomObscuredArea = 0;
3294 for (const auto& positionedObject : *positionedObjects) {
3295 const RenderStyle& style = positionedObject->style();
3296 if (style.position() != FixedPosition || style.visibility() == HIDDEN || !style.opacity())
3299 FloatQuad contentQuad = positionedObject->absoluteContentQuad();
3300 if (!contentQuad.isRectilinear())
3303 FloatRect contentBoundingBox = contentQuad.boundingBox();
3304 FloatRect fixedRectInView = intersection(unobscuredContentRect, contentBoundingBox);
3306 if (fixedRectInView.width() < unobscuredContentRect.width())
3309 if (fixedRectInView.y() == unobscuredContentRect.y())
3310 topObscuredArea = std::max(topObscuredArea, fixedRectInView.height());
3311 else if (fixedRectInView.maxY() == unobscuredContentRect.maxY())
3312 bottomObscuredArea = std::max(bottomObscuredArea, fixedRectInView.height());
3315 return Scrollbar::pageStep(unobscuredContentRect.height(), unobscuredContentRect.height() - topObscuredArea - bottomObscuredArea);
3318 void FrameView::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect)
3320 // Add in our offset within the FrameView.
3321 IntRect dirtyRect = rect;
3322 dirtyRect.moveBy(scrollbar->location());
3323 invalidateRect(dirtyRect);
3326 IntRect FrameView::windowResizerRect() const
3328 if (Page* page = frame().page())
3329 return page->chrome().windowResizerRect();
3333 float FrameView::visibleContentScaleFactor() const
3335 if (!frame().isMainFrame() || !frame().settings().delegatesPageScaling())
3338 return frame().page()->pageScaleFactor();
3341 void FrameView::setVisibleScrollerThumbRect(const IntRect& scrollerThumb)
3343 if (!frame().isMainFrame())
3346 frame().page()->chrome().client().notifyScrollerThumbIsVisibleInRect(scrollerThumb);
3349 ScrollableArea* FrameView::enclosingScrollableArea() const
3351 // FIXME: Walk up the frame tree and look for a scrollable parent frame or RenderLayer.
3355 IntRect FrameView::scrollableAreaBoundingBox() const
3357 RenderWidget* ownerRenderer = frame().ownerRenderer();
3361 return ownerRenderer->absoluteContentQuad().enclosingBoundingBox();
3364 bool FrameView::isScrollable(Scrollability definitionOfScrollable)
3367 // 1) If there an actual overflow.
3368 // 2) display:none or visibility:hidden set to self or inherited.
3369 // 3) overflow{-x,-y}: hidden;
3370 // 4) scrolling: no;
3372 bool requiresActualOverflowToBeConsideredScrollable = !frame().isMainFrame() || definitionOfScrollable != Scrollability::ScrollableOrRubberbandable;
3373 #if !ENABLE(RUBBER_BANDING)
3374 requiresActualOverflowToBeConsideredScrollable = true;
3378 if (requiresActualOverflowToBeConsideredScrollable) {
3379 IntSize totalContentsSize = this->totalContentsSize();
3380 IntSize visibleContentSize = visibleContentRect(LegacyIOSDocumentVisibleRect).size();
3381 if (totalContentsSize.height() <= visibleContentSize.height() && totalContentsSize.width() <= visibleContentSize.width())
3386 HTMLFrameOwnerElement* owner = frame().ownerElement();
3387 if (owner && (!owner->renderer() || !owner->renderer()->visibleToHitTesting()))
3391 ScrollbarMode horizontalMode;
3392 ScrollbarMode verticalMode;
3393 calculateScrollbarModesForLayout(horizontalMode, verticalMode, RulesFromWebContentOnly);
3394 if (horizontalMode == ScrollbarAlwaysOff && verticalMode == ScrollbarAlwaysOff)
3400 bool FrameView::isScrollableOrRubberbandable()
3402 return isScrollable(Scrollability::ScrollableOrRubberbandable);
3405 bool FrameView::hasScrollableOrRubberbandableAncestor()
3407 if (frame().isMainFrame())
3408 return isScrollableOrRubberbandable();
3410 for (FrameView* parent = this->parentFrameView(); parent; parent = parent->parentFrameView()) {
3411 Scrollability frameScrollability = parent->frame().isMainFrame() ? Scrollability::ScrollableOrRubberbandable : Scrollability::Scrollable;
3412 if (parent->isScrollable(frameScrollability))
3419 void FrameView::updateScrollableAreaSet()
3421 // That ensures that only inner frames are cached.
3422 FrameView* parentFrameView = this->parentFrameView();
3423 if (!parentFrameView)
3426 if (!isScrollable()) {
3427 parentFrameView->removeScrollableArea(this);
3431 parentFrameView->addScrollableArea(this);
3434 bool FrameView::shouldSuspendScrollAnimations() const
3436 return frame().loader().state() != FrameStateComplete;
3439 void FrameView::scrollbarStyleChanged(int newStyle, bool forceUpdate)
3441 if (!frame().isMainFrame())
3444 frame().page()->chrome().client().recommendedScrollbarStyleDidChange(newStyle);
3447 ScrollView::scrollbarStyleChanged(newStyle, forceUpdate);
3450 void FrameView::notifyPageThatContentAreaWillPaint() const
3452 Page* page = frame().page();
3456 contentAreaWillPaint();
3458 if (!m_scrollableAreas)
3461 for (auto& scrollableArea : *m_scrollableAreas)
3462 scrollableArea->contentAreaWillPaint();
3465 bool FrameView::scrollAnimatorEnabled() const
3467 #if ENABLE(SMOOTH_SCROLLING)
3468 if (Page* page = frame().page())
3469 return page->settings().scrollAnimatorEnabled();
3475 #if ENABLE(DASHBOARD_SUPPORT)
3476 void FrameView::updateAnnotatedRegions()
3478 Document* document = frame().document();
3479 if (!document->hasAnnotatedRegions())
3481 Vector<AnnotatedRegionValue> newRegions;
3482 document->renderBox()->collectAnnotatedRegions(newRegions);
3483 if (newRegions == document->annotatedRegions())
3485 document->setAnnotatedRegions(newRegions);
3486 Page* page = frame().page();
3489 page->chrome().client().annotatedRegionsChanged();
3493 void FrameView::updateScrollCorner()
3495 RenderElement* renderer = 0;
3496 RefPtr<RenderStyle> cornerStyle;
3497 IntRect cornerRect = scrollCornerRect();
3499 if (!cornerRect.isEmpty()) {
3500 // Try the <body> element first as a scroll corner source.
3501 Document* doc = frame().document();
3502 Element* body = doc ? doc->body() : 0;
3503 if (body && body->renderer()) {
3504 renderer = body->renderer();
3505 cornerStyle = renderer->getUncachedPseudoStyle(PseudoStyleRequest(SCROLLBAR_CORNER), &renderer->style());
3509 // If the <body> didn't have a custom style, then the root element might.
3510 Element* docElement = doc ? doc->documentElement() : 0;
3511 if (docElement && docElement->renderer()) {
3512 renderer = docElement->renderer();
3513 cornerStyle = renderer->getUncachedPseudoStyle(PseudoStyleRequest(SCROLLBAR_CORNER), &renderer->style());
3518 // If we have an owning iframe/frame element, then it can set the custom scrollbar also.
3519 if (RenderWidget* renderer = frame().ownerRenderer())
3520 cornerStyle = renderer->getUncachedPseudoStyle(PseudoStyleRequest(SCROLLBAR_CORNER), &renderer->style());
3525 m_scrollCorner = nullptr;
3527 if (!m_scrollCorner) {
3528 m_scrollCorner = createRenderer<RenderScrollbarPart>(renderer->document(), cornerStyle.releaseNonNull());
3529 m_scrollCorner->initializeStyle();
3531 m_scrollCorner->setStyle(cornerStyle.releaseNonNull());
3532 invalidateScrollCorner(cornerRect);
3535 ScrollView::updateScrollCorner();
3538 void FrameView::paintScrollCorner(GraphicsContext* context, const IntRect& cornerRect)
3540 if (context->updatingControlTints()) {
3541 updateScrollCorner();
3545 if (m_scrollCorner) {
3546 if (frame().isMainFrame())
3547 context->fillRect(cornerRect, baseBackgroundColor(), ColorSpaceDeviceRGB);
3548 m_scrollCorner->paintIntoRect(context, cornerRect.location(), cornerRect);
3552 ScrollView::paintScrollCorner(context, cornerRect);
3555 void FrameView::paintScrollbar(GraphicsContext* context, Scrollbar* bar, const IntRect& rect)
3557 if (bar->isCustomScrollbar() && frame().isMainFrame()) {
3558 IntRect toFill = bar->frameRect();
3559 toFill.intersect(rect);
3560 context->fillRect(toFill, baseBackgroundColor(), ColorSpaceDeviceRGB);
3563 ScrollView::paintScrollbar(context, bar, rect);
3566 Color FrameView::documentBackgroundColor() const
3568 // <https://bugs.webkit.org/show_bug.cgi?id=59540> We blend the background color of
3569 // the document and the body against the base background color of the frame view.
3570 // Background images are unfortunately impractical to include.
3572 // Return invalid Color objects whenever there is insufficient information.
3573 if (!frame().document())
3576 Element* htmlElement = frame().document()->documentElement();
3577 Element* bodyElement = frame().document()->body();
3579 // Start with invalid colors.
3580 Color htmlBackgroundColor;
3581 Color bodyBackgroundColor;
3582 if (htmlElement && htmlElement->renderer())
3583 htmlBackgroundColor = htmlElement->renderer()->style().visitedDependentColor(CSSPropertyBackgroundColor);
3584 if (bodyElement && bodyElement->renderer())
3585 bodyBackgroundColor = bodyElement->renderer()->style().visitedDependentColor(CSSPropertyBackgroundColor);
3587 if (!bodyBackgroundColor.isValid()) {
3588 if (!htmlBackgroundColor.isValid())
3590 return baseBackgroundColor().blend(htmlBackgroundColor);
3593 if (!htmlBackgroundColor.isValid())
3594 return baseBackgroundColor().blend(bodyBackgroundColor);
3596 // We take the aggregate of the base background color
3597 // the <html> background color, and the <body>
3598 // background color to find the document color. The
3599 // addition of the base background color is not
3600 // technically part of the document background, but it
3601 // otherwise poses problems when the aggregate is not
3603 return baseBackgroundColor().blend(htmlBackgroundColor).blend(bodyBackgroundColor);
3606 bool FrameView::hasCustomScrollbars() const
3608 for (auto& widget : children()) {
3609 if (is<FrameView>(*widget)) {
3610 if (downcast<FrameView>(*widget).hasCustomScrollbars())
3612 } else if (is<Scrollbar>(*widget)) {
3613 if (downcast<Scrollbar>(*widget).isCustomScrollbar())