Remove CSS_FILTERS flag
[WebKit-https.git] / Source / WebCore / rendering / RenderView.cpp
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include "config.h"
22 #include "RenderView.h"
23
24 #include "Document.h"
25 #include "Element.h"
26 #include "FloatQuad.h"
27 #include "FloatingObjects.h"
28 #include "FlowThreadController.h"
29 #include "Frame.h"
30 #include "FrameSelection.h"
31 #include "FrameView.h"
32 #include "GraphicsContext.h"
33 #include "HTMLFrameOwnerElement.h"
34 #include "HTMLIFrameElement.h"
35 #include "HitTestResult.h"
36 #include "ImageQualityController.h"
37 #include "NodeTraversal.h"
38 #include "Page.h"
39 #include "RenderGeometryMap.h"
40 #include "RenderIterator.h"
41 #include "RenderLayer.h"
42 #include "RenderLayerBacking.h"
43 #include "RenderLayerCompositor.h"
44 #include "RenderMultiColumnFlowThread.h"
45 #include "RenderMultiColumnSet.h"
46 #include "RenderMultiColumnSpannerPlaceholder.h"
47 #include "RenderNamedFlowThread.h"
48 #include "RenderSelectionInfo.h"
49 #include "RenderWidget.h"
50 #include "Settings.h"
51 #include "StyleInheritedData.h"
52 #include "TransformState.h"
53 #include <wtf/StackStats.h>
54
55 namespace WebCore {
56
57 struct SelectionIterator {
58     RenderObject* m_current;
59     Vector<RenderMultiColumnSpannerPlaceholder*> m_spannerStack;
60     
61     SelectionIterator(RenderObject* o)
62     {
63         m_current = o;
64         checkForSpanner();
65     }
66     
67     void checkForSpanner()
68     {
69         if (!m_current || !m_current->isRenderMultiColumnSpannerPlaceholder())
70             return;
71         RenderMultiColumnSpannerPlaceholder* placeholder = toRenderMultiColumnSpannerPlaceholder(m_current);
72         m_spannerStack.append(placeholder);
73         m_current = placeholder->spanner();
74     }
75     
76     RenderObject* current()
77     {
78         return m_current;
79     }
80     
81     RenderObject* next()
82     {
83         RenderObject* currentSpan = m_spannerStack.isEmpty() ? 0 : m_spannerStack.last()->spanner();
84         m_current = m_current->nextInPreOrder(currentSpan);
85         checkForSpanner();
86         if (!m_current && currentSpan) {
87             RenderObject* placeholder = m_spannerStack.last();
88             m_spannerStack.removeLast();
89             m_current = placeholder->nextInPreOrder();
90             checkForSpanner();
91         }
92         return m_current;
93     }
94 };
95
96 RenderView::RenderView(Document& document, PassRef<RenderStyle> style)
97     : RenderBlockFlow(document, WTF::move(style))
98     , m_frameView(*document.view())
99     , m_selectionUnsplitStart(0)
100     , m_selectionUnsplitEnd(0)
101     , m_selectionUnsplitStartPos(-1)
102     , m_selectionUnsplitEndPos(-1)
103     , m_rendererCount(0)
104     , m_maximalOutlineSize(0)
105     , m_lazyRepaintTimer(this, &RenderView::lazyRepaintTimerFired)
106     , m_pageLogicalHeight(0)
107     , m_pageLogicalHeightChanged(false)
108     , m_layoutState(nullptr)
109     , m_layoutStateDisableCount(0)
110     , m_renderQuoteHead(0)
111     , m_renderCounterCount(0)
112     , m_selectionWasCaret(false)
113     , m_hasSoftwareFilters(false)
114 #if ENABLE(SERVICE_CONTROLS)
115     , m_selectionRectGatherer(*this)
116 #endif
117 {
118     setIsRenderView();
119
120     // FIXME: We should find a way to enforce this at compile time.
121     ASSERT(document.view());
122
123     // init RenderObject attributes
124     setInline(false);
125     
126     m_minPreferredLogicalWidth = 0;
127     m_maxPreferredLogicalWidth = 0;
128
129     setPreferredLogicalWidthsDirty(true, MarkOnlyThis);
130     
131     setPositionState(AbsolutePosition); // to 0,0 :)
132 }
133
134 RenderView::~RenderView()
135 {
136 }
137
138 void RenderView::scheduleLazyRepaint(RenderBox& renderer)
139 {
140     if (renderer.renderBoxNeedsLazyRepaint())
141         return;
142     renderer.setRenderBoxNeedsLazyRepaint(true);
143     m_renderersNeedingLazyRepaint.add(&renderer);
144     if (!m_lazyRepaintTimer.isActive())
145         m_lazyRepaintTimer.startOneShot(0);
146 }
147
148 void RenderView::unscheduleLazyRepaint(RenderBox& renderer)
149 {
150     if (!renderer.renderBoxNeedsLazyRepaint())
151         return;
152     renderer.setRenderBoxNeedsLazyRepaint(false);
153     m_renderersNeedingLazyRepaint.remove(&renderer);
154     if (m_renderersNeedingLazyRepaint.isEmpty())
155         m_lazyRepaintTimer.stop();
156 }
157
158 void RenderView::lazyRepaintTimerFired(Timer<RenderView>&)
159 {
160     bool shouldRepaint = !document().inPageCache();
161
162     for (auto& renderer : m_renderersNeedingLazyRepaint) {
163         if (shouldRepaint)
164             renderer->repaint();
165         renderer->setRenderBoxNeedsLazyRepaint(false);
166     }
167     m_renderersNeedingLazyRepaint.clear();
168 }
169
170 bool RenderView::hitTest(const HitTestRequest& request, HitTestResult& result)
171 {
172     return hitTest(request, result.hitTestLocation(), result);
173 }
174
175 bool RenderView::hitTest(const HitTestRequest& request, const HitTestLocation& location, HitTestResult& result)
176 {
177     if (layer()->hitTest(request, location, result))
178         return true;
179
180     // FIXME: Consider if this test should be done unconditionally.
181     if (request.allowsFrameScrollbars()) {
182         // ScrollView scrollbars are not the same as RenderLayer scrollbars tested by RenderLayer::hitTestOverflowControls,
183         // so we need to test ScrollView scrollbars separately here.
184         Scrollbar* frameScrollbar = frameView().scrollbarAtPoint(location.roundedPoint());
185         if (frameScrollbar) {
186             result.setScrollbar(frameScrollbar);
187             return true;
188         }
189     }
190
191     return false;
192 }
193
194 void RenderView::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit, LogicalExtentComputedValues& computedValues) const
195 {
196     computedValues.m_extent = !shouldUsePrintingLayout() ? LayoutUnit(viewLogicalHeight()) : logicalHeight;
197 }
198
199 void RenderView::updateLogicalWidth()
200 {
201     if (!shouldUsePrintingLayout())
202         setLogicalWidth(viewLogicalWidth());
203 }
204
205 LayoutUnit RenderView::availableLogicalHeight(AvailableLogicalHeightType) const
206 {
207     // Make sure block progression pagination for percentages uses the column extent and
208     // not the view's extent. See https://bugs.webkit.org/show_bug.cgi?id=135204.
209     if (multiColumnFlowThread() && multiColumnFlowThread()->firstMultiColumnSet())
210         return multiColumnFlowThread()->firstMultiColumnSet()->computedColumnHeight();
211
212 #if PLATFORM(IOS)
213     // Workaround for <rdar://problem/7166808>.
214     if (document().isPluginDocument() && frameView().useFixedLayout())
215         return frameView().fixedLayoutSize().height();
216 #endif
217     return isHorizontalWritingMode() ? frameView().visibleHeight() : frameView().visibleWidth();
218 }
219
220 bool RenderView::isChildAllowed(const RenderObject& child, const RenderStyle&) const
221 {
222     return child.isBox();
223 }
224
225 void RenderView::layoutContent(const LayoutState& state)
226 {
227     UNUSED_PARAM(state);
228     ASSERT(needsLayout());
229
230     RenderBlockFlow::layout();
231     if (hasRenderNamedFlowThreads())
232         flowThreadController().layoutRenderNamedFlowThreads();
233 #ifndef NDEBUG
234     checkLayoutState(state);
235 #endif
236 }
237
238 #ifndef NDEBUG
239 void RenderView::checkLayoutState(const LayoutState& state)
240 {
241     ASSERT(layoutDeltaMatches(LayoutSize()));
242     ASSERT(!m_layoutStateDisableCount);
243     ASSERT(m_layoutState.get() == &state);
244 }
245 #endif
246
247 void RenderView::initializeLayoutState(LayoutState& state)
248 {
249     // FIXME: May be better to push a clip and avoid issuing offscreen repaints.
250     state.m_clipped = false;
251
252     state.m_pageLogicalHeight = m_pageLogicalHeight;
253     state.m_pageLogicalHeightChanged = m_pageLogicalHeightChanged;
254     state.m_isPaginated = state.m_pageLogicalHeight;
255 }
256
257 // The algorithm below assumes this is a full layout. In case there are previously computed values for regions, supplemental steps are taken
258 // to ensure the results are the same as those obtained from a full layout (i.e. the auto-height regions from all the flows are marked as needing
259 // layout).
260 // 1. The flows are laid out from the outer flow to the inner flow. This successfully computes the outer non-auto-height regions size so the 
261 // inner flows have the necessary information to correctly fragment the content.
262 // 2. The flows are laid out from the inner flow to the outer flow. After an inner flow is laid out it goes into the constrained layout phase
263 // and marks the auto-height regions they need layout. This means the outer flows will relayout if they depend on regions with auto-height regions
264 // belonging to inner flows. This step will correctly set the computedAutoHeight for the auto-height regions. It's possible for non-auto-height
265 // regions to relayout if they depend on auto-height regions. This will invalidate the inner flow threads and mark them as needing layout.
266 // 3. The last step is to do one last layout if there are pathological dependencies between non-auto-height regions and auto-height regions
267 // as detected in the previous step.
268 void RenderView::layoutContentInAutoLogicalHeightRegions(const LayoutState& state)
269 {
270     // We need to invalidate all the flows with auto-height regions if one such flow needs layout.
271     // If none is found we do a layout a check back again afterwards.
272     if (!flowThreadController().updateFlowThreadsNeedingLayout()) {
273         // Do a first layout of the content. In some cases more layouts are not needed (e.g. only flows with non-auto-height regions have changed).
274         layoutContent(state);
275
276         // If we find no named flow needing a two step layout after the first layout, exit early.
277         // Otherwise, initiate the two step layout algorithm and recompute all the flows.
278         if (!flowThreadController().updateFlowThreadsNeedingTwoStepLayout())
279             return;
280     }
281
282     // Layout to recompute all the named flows with auto-height regions.
283     layoutContent(state);
284
285     // Propagate the computed auto-height values upwards.
286     // Non-auto-height regions may invalidate the flow thread because they depended on auto-height regions, but that's ok.
287     flowThreadController().updateFlowThreadsIntoConstrainedPhase();
288
289     // Do one last layout that should update the auto-height regions found in the main flow
290     // and solve pathological dependencies between regions (e.g. a non-auto-height region depending
291     // on an auto-height one).
292     if (needsLayout())
293         layoutContent(state);
294 }
295
296 void RenderView::layoutContentToComputeOverflowInRegions(const LayoutState& state)
297 {
298     if (!hasRenderNamedFlowThreads())
299         return;
300
301     // First pass through the flow threads and mark the regions as needing a simple layout.
302     // The regions extract the overflow from the flow thread and pass it to their containg
303     // block chain.
304     flowThreadController().updateFlowThreadsIntoOverflowPhase();
305     if (needsLayout())
306         layoutContent(state);
307
308     // In case scrollbars resized the regions a new pass is necessary to update the flow threads
309     // and recompute the overflow on regions. This is the final state of the flow threads.
310     flowThreadController().updateFlowThreadsIntoFinalPhase();
311     if (needsLayout())
312         layoutContent(state);
313
314     // Finally reset the layout state of the flow threads.
315     flowThreadController().updateFlowThreadsIntoMeasureContentPhase();
316 }
317
318 void RenderView::layout()
319 {
320     StackStats::LayoutCheckPoint layoutCheckPoint;
321     if (!document().paginated())
322         setPageLogicalHeight(0);
323
324     if (shouldUsePrintingLayout())
325         m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = logicalWidth();
326
327     // Use calcWidth/Height to get the new width/height, since this will take the full page zoom factor into account.
328     bool relayoutChildren = !shouldUsePrintingLayout() && (width() != viewWidth() || height() != viewHeight());
329     if (relayoutChildren) {
330         setChildNeedsLayout(MarkOnlyThis);
331
332         for (auto& box : childrenOfType<RenderBox>(*this)) {
333             if (box.hasRelativeLogicalHeight()
334                 || box.style().logicalHeight().isPercent()
335                 || box.style().logicalMinHeight().isPercent()
336                 || box.style().logicalMaxHeight().isPercent()
337                 || box.isSVGRoot()
338                 )
339                 box.setChildNeedsLayout(MarkOnlyThis);
340         }
341     }
342
343     ASSERT(!m_layoutState);
344     if (!needsLayout())
345         return;
346
347     m_layoutState = std::make_unique<LayoutState>();
348     initializeLayoutState(*m_layoutState);
349
350     m_pageLogicalHeightChanged = false;
351
352     if (checkTwoPassLayoutForAutoHeightRegions())
353         layoutContentInAutoLogicalHeightRegions(*m_layoutState);
354     else
355         layoutContent(*m_layoutState);
356
357     layoutContentToComputeOverflowInRegions(*m_layoutState);
358
359 #ifndef NDEBUG
360     checkLayoutState(*m_layoutState);
361 #endif
362     m_layoutState = nullptr;
363     clearNeedsLayout();
364 }
365
366 LayoutUnit RenderView::pageOrViewLogicalHeight() const
367 {
368     if (document().printing())
369         return pageLogicalHeight();
370     
371     if (multiColumnFlowThread() && !style().hasInlineColumnAxis()) {
372         if (int pageLength = frameView().pagination().pageLength)
373             return pageLength;
374     }
375
376     return viewLogicalHeight();
377 }
378
379 LayoutUnit RenderView::clientLogicalWidthForFixedPosition() const
380 {
381     // FIXME: If the FrameView's fixedVisibleContentRect() is not empty, perhaps it should be consulted here too?
382     if (frameView().fixedElementsLayoutRelativeToFrame())
383         return (isHorizontalWritingMode() ? frameView().visibleWidth() : frameView().visibleHeight()) / frameView().frame().frameScaleFactor();
384
385 #if PLATFORM(IOS)
386     if (frameView().useCustomFixedPositionLayoutRect())
387         return isHorizontalWritingMode() ? frameView().customFixedPositionLayoutRect().width() : frameView().customFixedPositionLayoutRect().height();
388 #endif
389
390     return clientLogicalWidth();
391 }
392
393 LayoutUnit RenderView::clientLogicalHeightForFixedPosition() const
394 {
395     // FIXME: If the FrameView's fixedVisibleContentRect() is not empty, perhaps it should be consulted here too?
396     if (frameView().fixedElementsLayoutRelativeToFrame())
397         return (isHorizontalWritingMode() ? frameView().visibleHeight() : frameView().visibleWidth()) / frameView().frame().frameScaleFactor();
398
399 #if PLATFORM(IOS)
400     if (frameView().useCustomFixedPositionLayoutRect())
401         return isHorizontalWritingMode() ? frameView().customFixedPositionLayoutRect().height() : frameView().customFixedPositionLayoutRect().width();
402 #endif
403
404     return clientLogicalHeight();
405 }
406
407 #if PLATFORM(IOS)
408 static inline LayoutSize fixedPositionOffset(const FrameView& frameView)
409 {
410     return frameView.useCustomFixedPositionLayoutRect() ? (frameView.customFixedPositionLayoutRect().location() - LayoutPoint()) : frameView.scrollOffset();
411 }
412 #endif
413
414 void RenderView::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags mode, bool* wasFixed) const
415 {
416     // If a container was specified, and was not 0 or the RenderView,
417     // then we should have found it by now.
418     ASSERT_ARG(repaintContainer, !repaintContainer || repaintContainer == this);
419     ASSERT_UNUSED(wasFixed, !wasFixed || *wasFixed == (mode & IsFixed));
420
421     if (!repaintContainer && mode & UseTransforms && shouldUseTransformFromContainer(0)) {
422         TransformationMatrix t;
423         getTransformFromContainer(0, LayoutSize(), t);
424         transformState.applyTransform(t);
425     }
426     
427     if (mode & IsFixed)
428 #if PLATFORM(IOS)
429         transformState.move(fixedPositionOffset(m_frameView));
430 #else
431         transformState.move(frameView().scrollOffsetForFixedPosition());
432 #endif
433 }
434
435 const RenderObject* RenderView::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
436 {
437     // If a container was specified, and was not 0 or the RenderView,
438     // then we should have found it by now.
439     ASSERT_ARG(ancestorToStopAt, !ancestorToStopAt || ancestorToStopAt == this);
440
441 #if PLATFORM(IOS)
442     LayoutSize scrollOffset = fixedPositionOffset(frameView());
443 #else
444     LayoutSize scrollOffset = frameView().scrollOffsetForFixedPosition();
445 #endif
446
447     if (!ancestorToStopAt && shouldUseTransformFromContainer(0)) {
448         TransformationMatrix t;
449         getTransformFromContainer(0, LayoutSize(), t);
450         geometryMap.pushView(this, scrollOffset, &t);
451     } else
452         geometryMap.pushView(this, scrollOffset);
453
454     return 0;
455 }
456
457 void RenderView::mapAbsoluteToLocalPoint(MapCoordinatesFlags mode, TransformState& transformState) const
458 {
459     if (mode & IsFixed)
460 #if PLATFORM(IOS)
461         transformState.move(fixedPositionOffset(frameView()));
462 #else
463         transformState.move(frameView().scrollOffsetForFixedPosition());
464 #endif
465
466     if (mode & UseTransforms && shouldUseTransformFromContainer(0)) {
467         TransformationMatrix t;
468         getTransformFromContainer(0, LayoutSize(), t);
469         transformState.applyTransform(t);
470     }
471 }
472
473 bool RenderView::requiresColumns(int) const
474 {
475     return frameView().pagination().mode != Pagination::Unpaginated;
476 }
477
478 void RenderView::computeColumnCountAndWidth()
479 {
480     int columnWidth = contentLogicalWidth();
481     if (style().hasInlineColumnAxis()) {
482         if (int pageLength = frameView().pagination().pageLength)
483             columnWidth = pageLength;
484     }
485     setComputedColumnCountAndWidth(1, columnWidth);
486 }
487
488 void RenderView::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
489 {
490     // If we ever require layout but receive a paint anyway, something has gone horribly wrong.
491     ASSERT(!needsLayout());
492     // RenderViews should never be called to paint with an offset not on device pixels.
493     ASSERT(LayoutPoint(IntPoint(paintOffset.x(), paintOffset.y())) == paintOffset);
494
495     // This avoids painting garbage between columns if there is a column gap.
496     if (frameView().pagination().mode != Pagination::Unpaginated && paintInfo.shouldPaintWithinRoot(*this))
497         paintInfo.context->fillRect(paintInfo.rect, frameView().baseBackgroundColor(), ColorSpaceDeviceRGB);
498
499     paintObject(paintInfo, paintOffset);
500 }
501
502 static inline bool isComposited(RenderElement* object)
503 {
504     return object->hasLayer() && toRenderLayerModelObject(object)->layer()->isComposited();
505 }
506
507 static inline bool rendererObscuresBackground(RenderElement* rootObject)
508 {
509     if (!rootObject)
510         return false;
511     
512     const RenderStyle& style = rootObject->style();
513     if (style.visibility() != VISIBLE
514         || style.opacity() != 1
515         || style.hasTransform())
516         return false;
517     
518     if (isComposited(rootObject))
519         return false;
520
521     if (rootObject->rendererForRootBackground().style().backgroundClip() == TextFillBox)
522         return false;
523
524     if (style.hasBorderRadius())
525         return false;
526
527     return true;
528 }
529
530 void RenderView::paintBoxDecorations(PaintInfo& paintInfo, const LayoutPoint&)
531 {
532     if (!paintInfo.shouldPaintWithinRoot(*this))
533         return;
534
535     // Check to see if we are enclosed by a layer that requires complex painting rules.  If so, we cannot blit
536     // when scrolling, and we need to use slow repaints.  Examples of layers that require this are transparent layers,
537     // layers with reflections, or transformed layers.
538     // FIXME: This needs to be dynamic.  We should be able to go back to blitting if we ever stop being inside
539     // a transform, transparency layer, etc.
540     Element* elt;
541     for (elt = document().ownerElement(); elt && elt->renderer(); elt = elt->document().ownerElement()) {
542         RenderLayer* layer = elt->renderer()->enclosingLayer();
543         if (layer->cannotBlitToWindow()) {
544             frameView().setCannotBlitToWindow();
545             break;
546         }
547
548         if (RenderLayer* compositingLayer = layer->enclosingCompositingLayerForRepaint()) {
549             if (!compositingLayer->backing()->paintsIntoWindow()) {
550                 frameView().setCannotBlitToWindow();
551                 break;
552             }
553         }
554     }
555
556     if (document().ownerElement())
557         return;
558
559     if (paintInfo.skipRootBackground())
560         return;
561
562     bool rootFillsViewport = false;
563     bool rootObscuresBackground = false;
564     Element* documentElement = document().documentElement();
565     if (RenderElement* rootRenderer = documentElement ? documentElement->renderer() : 0) {
566         // The document element's renderer is currently forced to be a block, but may not always be.
567         RenderBox* rootBox = rootRenderer->isBox() ? toRenderBox(rootRenderer) : 0;
568         rootFillsViewport = rootBox && !rootBox->x() && !rootBox->y() && rootBox->width() >= width() && rootBox->height() >= height();
569         rootObscuresBackground = rendererObscuresBackground(rootRenderer);
570     }
571
572     compositor().setRootExtendedBackgroundColor(frameView().frame().settings().backgroundShouldExtendBeyondPage()
573         ? frameView().documentBackgroundColor() : Color());
574
575     Page* page = document().page();
576     float pageScaleFactor = page ? page->pageScaleFactor() : 1;
577
578     // If painting will entirely fill the view, no need to fill the background.
579     if (rootFillsViewport && rootObscuresBackground && pageScaleFactor >= 1)
580         return;
581
582     // This code typically only executes if the root element's visibility has been set to hidden,
583     // if there is a transform on the <html>, or if there is a page scale factor less than 1.
584     // Only fill with the base background color (typically white) if we're the root document, 
585     // since iframes/frames with no background in the child document should show the parent's background.
586     if (frameView().isTransparent()) // FIXME: This needs to be dynamic. We should be able to go back to blitting if we ever stop being transparent.
587         frameView().setCannotBlitToWindow(); // The parent must show behind the child.
588     else {
589         Color backgroundColor = frameView().baseBackgroundColor();
590         if (backgroundColor.alpha()) {
591             CompositeOperator previousOperator = paintInfo.context->compositeOperation();
592             paintInfo.context->setCompositeOperation(CompositeCopy);
593             paintInfo.context->fillRect(paintInfo.rect, backgroundColor, style().colorSpace());
594             paintInfo.context->setCompositeOperation(previousOperator);
595         } else
596             paintInfo.context->clearRect(paintInfo.rect);
597     }
598 }
599
600 bool RenderView::shouldRepaint(const LayoutRect& rect) const
601 {
602     return !printing() && !rect.isEmpty();
603 }
604
605 void RenderView::repaintRootContents()
606 {
607     if (layer()->isComposited()) {
608         layer()->setBackingNeedsRepaint(GraphicsLayer::DoNotClipToLayer);
609         return;
610     }
611     repaint();
612 }
613
614 void RenderView::repaintViewRectangle(const LayoutRect& repaintRect) const
615 {
616     if (!shouldRepaint(repaintRect))
617         return;
618
619     if (auto ownerElement = document().ownerElement()) {
620         RenderBox* ownerBox = ownerElement->renderBox();
621         if (!ownerBox)
622             return;
623         LayoutRect viewRect = this->viewRect();
624 #if PLATFORM(IOS)
625         // Don't clip using the visible rect since clipping is handled at a higher level on iPhone.
626         LayoutRect adjustedRect = repaintRect;
627 #else
628         LayoutRect adjustedRect = intersection(repaintRect, viewRect);
629 #endif
630         adjustedRect.moveBy(-viewRect.location());
631         adjustedRect.moveBy(ownerBox->contentBoxRect().location());
632         ownerBox->repaintRectangle(adjustedRect);
633         return;
634     }
635
636     frameView().addTrackedRepaintRect(snapRectToDevicePixels(repaintRect, document().deviceScaleFactor()));
637
638     // FIXME: convert all repaint rect dependencies to FloatRect.
639     IntRect enclosingRect = enclosingIntRect(repaintRect);
640     if (!m_accumulatedRepaintRegion) {
641         frameView().repaintContentRectangle(enclosingRect);
642         return;
643     }
644     m_accumulatedRepaintRegion->unite(enclosingRect);
645
646     // Region will get slow if it gets too complex. Merge all rects so far to bounds if this happens.
647     // FIXME: Maybe there should be a region type that does this automatically.
648     static const unsigned maximumRepaintRegionGridSize = 16 * 16;
649     if (m_accumulatedRepaintRegion->gridSize() > maximumRepaintRegionGridSize)
650         m_accumulatedRepaintRegion = std::make_unique<Region>(m_accumulatedRepaintRegion->bounds());
651 }
652
653 void RenderView::flushAccumulatedRepaintRegion() const
654 {
655     ASSERT(!document().ownerElement());
656     ASSERT(m_accumulatedRepaintRegion);
657     auto repaintRects = m_accumulatedRepaintRegion->rects();
658     for (auto& rect : repaintRects)
659         frameView().repaintContentRectangle(rect);
660     m_accumulatedRepaintRegion = nullptr;
661 }
662
663 void RenderView::repaintViewAndCompositedLayers()
664 {
665     repaintRootContents();
666
667     RenderLayerCompositor& compositor = this->compositor();
668     if (compositor.inCompositingMode())
669         compositor.repaintCompositedLayers();
670 }
671
672 LayoutRect RenderView::visualOverflowRect() const
673 {
674     if (frameView().paintsEntireContents())
675         return layoutOverflowRect();
676
677     return RenderBlockFlow::visualOverflowRect();
678 }
679
680 void RenderView::computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect& rect, bool fixed) const
681 {
682     // If a container was specified, and was not 0 or the RenderView,
683     // then we should have found it by now.
684     ASSERT_ARG(repaintContainer, !repaintContainer || repaintContainer == this);
685
686     if (printing())
687         return;
688
689     if (style().isFlippedBlocksWritingMode()) {
690         // We have to flip by hand since the view's logical height has not been determined.  We
691         // can use the viewport width and height.
692         if (style().isHorizontalWritingMode())
693             rect.setY(viewHeight() - rect.maxY());
694         else
695             rect.setX(viewWidth() - rect.maxX());
696     }
697
698     if (fixed) {
699 #if PLATFORM(IOS)
700         rect.move(fixedPositionOffset(frameView()));
701 #else
702         rect.move(frameView().scrollOffsetForFixedPosition());
703 #endif
704     }
705         
706     // Apply our transform if we have one (because of full page zooming).
707     if (!repaintContainer && layer() && layer()->transform())
708         rect = LayoutRect(layer()->transform()->mapRect(snapRectToDevicePixels(rect, document().deviceScaleFactor())));
709 }
710
711 bool RenderView::isScrollableOrRubberbandable() const
712 {
713     // The main frame might be allowed to rubber-band even if there is no content to scroll to. This is unique to
714     // the main frame; subframes and overflow areas have to have content that can be scrolled to in order to rubber-band.
715     FrameView::Scrollability defineScrollable = frame().ownerElement() ? FrameView::Scrollability::Scrollable : FrameView::Scrollability::ScrollableOrRubberbandable;
716     return frameView().isScrollable(defineScrollable);
717 }
718
719 void RenderView::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumulatedOffset) const
720 {
721     rects.append(snappedIntRect(accumulatedOffset, layer()->size()));
722 }
723
724 void RenderView::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
725 {
726     if (wasFixed)
727         *wasFixed = false;
728     quads.append(FloatRect(FloatPoint(), layer()->size()));
729 }
730
731 static RenderObject* rendererAfterPosition(RenderObject* object, unsigned offset)
732 {
733     if (!object)
734         return 0;
735
736     RenderObject* child = object->childAt(offset);
737     return child ? child : object->nextInPreOrderAfterChildren();
738 }
739
740 IntRect RenderView::selectionBounds(bool clipToVisibleContent) const
741 {
742     LayoutRect selRect = subtreeSelectionBounds(*this, clipToVisibleContent);
743
744     if (hasRenderNamedFlowThreads()) {
745         for (auto* namedFlowThread : *m_flowThreadController->renderNamedFlowThreadList()) {
746             LayoutRect currRect = subtreeSelectionBounds(*namedFlowThread, clipToVisibleContent);
747             selRect.unite(currRect);
748         }
749     }
750
751     return snappedIntRect(selRect);
752 }
753
754 LayoutRect RenderView::subtreeSelectionBounds(const SelectionSubtreeRoot& root, bool clipToVisibleContent) const
755 {
756     typedef HashMap<RenderObject*, std::unique_ptr<RenderSelectionInfo>> SelectionMap;
757     SelectionMap selectedObjects;
758
759     RenderObject* os = root.selectionStart();
760     RenderObject* stop = rendererAfterPosition(root.selectionEnd(), root.selectionEndPos());
761     SelectionIterator selectionIterator(os);
762     while (os && os != stop) {
763         if ((os->canBeSelectionLeaf() || os == root.selectionStart() || os == root.selectionEnd()) && os->selectionState() != SelectionNone) {
764             // Blocks are responsible for painting line gaps and margin gaps. They must be examined as well.
765             selectedObjects.set(os, std::make_unique<RenderSelectionInfo>(*os, clipToVisibleContent));
766             RenderBlock* cb = os->containingBlock();
767             while (cb && !cb->isRenderView()) {
768                 std::unique_ptr<RenderSelectionInfo>& blockInfo = selectedObjects.add(cb, nullptr).iterator->value;
769                 if (blockInfo)
770                     break;
771                 blockInfo = std::make_unique<RenderSelectionInfo>(*cb, clipToVisibleContent);
772                 cb = cb->containingBlock();
773             }
774         }
775
776         os = selectionIterator.next();
777     }
778
779     // Now create a single bounding box rect that encloses the whole selection.
780     LayoutRect selRect;
781     SelectionMap::iterator end = selectedObjects.end();
782     for (SelectionMap::iterator i = selectedObjects.begin(); i != end; ++i) {
783         RenderSelectionInfo* info = i->value.get();
784         // RenderSelectionInfo::rect() is in the coordinates of the repaintContainer, so map to page coordinates.
785         LayoutRect currRect = info->rect();
786         if (RenderLayerModelObject* repaintContainer = info->repaintContainer()) {
787             FloatQuad absQuad = repaintContainer->localToAbsoluteQuad(FloatRect(currRect));
788             currRect = absQuad.enclosingBoundingBox(); 
789         }
790         selRect.unite(currRect);
791     }
792     return selRect;
793 }
794
795 void RenderView::repaintSelection() const
796 {
797     repaintSubtreeSelection(*this);
798
799     if (hasRenderNamedFlowThreads()) {
800         for (auto* namedFlowThread : *m_flowThreadController->renderNamedFlowThreadList())
801             repaintSubtreeSelection(*namedFlowThread);
802     }
803 }
804
805 void RenderView::repaintSubtreeSelection(const SelectionSubtreeRoot& root) const
806 {
807     HashSet<RenderBlock*> processedBlocks;
808
809     RenderObject* end = rendererAfterPosition(root.selectionEnd(), root.selectionEndPos());
810     SelectionIterator selectionIterator(root.selectionStart());
811     for (RenderObject* o = selectionIterator.current(); o && o != end; o = selectionIterator.next()) {
812         if (!o->canBeSelectionLeaf() && o != root.selectionStart() && o != root.selectionEnd())
813             continue;
814         if (o->selectionState() == SelectionNone)
815             continue;
816
817         RenderSelectionInfo(*o, true).repaint();
818
819         // Blocks are responsible for painting line gaps and margin gaps. They must be examined as well.
820         for (RenderBlock* block = o->containingBlock(); block && !block->isRenderView(); block = block->containingBlock()) {
821             if (!processedBlocks.add(block).isNewEntry)
822                 break;
823             RenderSelectionInfo(*block, true).repaint();
824         }
825     }
826 }
827
828 // Compositing layer dimensions take outline size into account, so we have to recompute layer
829 // bounds when it changes.
830 // FIXME: This is ugly; it would be nice to have a better way to do this.
831 void RenderView::setMaximalOutlineSize(int o)
832 {
833     if (o != m_maximalOutlineSize) {
834         m_maximalOutlineSize = o;
835
836         // maximalOutlineSize affects compositing layer dimensions.
837         compositor().setCompositingLayersNeedRebuild();    // FIXME: this really just needs to be a geometry update.
838     }
839 }
840
841 void RenderView::setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode)
842 {
843     // Make sure both our start and end objects are defined.
844     // Check www.msnbc.com and try clicking around to find the case where this happened.
845     if ((start && !end) || (end && !start))
846         return;
847
848     bool caretChanged = m_selectionWasCaret != frame().selection().isCaret();
849     m_selectionWasCaret = frame().selection().isCaret();
850     // Just return if the selection hasn't changed.
851     if (m_selectionUnsplitStart == start && m_selectionUnsplitStartPos == startPos
852         && m_selectionUnsplitEnd == end && m_selectionUnsplitEndPos == endPos && !caretChanged) {
853         return;
854     }
855
856 #if ENABLE(SERVICE_CONTROLS)
857     // Clear the current rects and create a notifier for the new rects we are about to gather.
858     // The Notifier updates the Editor when it goes out of scope and is destroyed.
859     std::unique_ptr<SelectionRectGatherer::Notifier> rectNotifier = m_selectionRectGatherer.clearAndCreateNotifier();
860 #endif // ENABLE(SERVICE_CONTROLS)
861     // Set global positions for new selection.
862     m_selectionUnsplitStart = start;
863     m_selectionUnsplitStartPos = startPos;
864     m_selectionUnsplitEnd = end;
865     m_selectionUnsplitEndPos = endPos;
866
867     // If there is no RenderNamedFlowThreads we follow the regular selection.
868     if (!hasRenderNamedFlowThreads()) {
869         RenderSubtreesMap singleSubtreeMap;
870         singleSubtreeMap.set(this, SelectionSubtreeRoot(start, startPos, end, endPos));
871         updateSelectionForSubtrees(singleSubtreeMap, blockRepaintMode);
872         return;
873     }
874
875     splitSelectionBetweenSubtrees(start, startPos, end, endPos, blockRepaintMode);
876 }
877
878 void RenderView::splitSelectionBetweenSubtrees(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode)
879 {
880     // Compute the visible selection end points for each of the subtrees.
881     RenderSubtreesMap renderSubtreesMap;
882
883     SelectionSubtreeRoot initialSelection;
884     renderSubtreesMap.set(this, initialSelection);
885     for (auto* namedFlowThread : *flowThreadController().renderNamedFlowThreadList())
886         renderSubtreesMap.set(namedFlowThread, initialSelection);
887
888     if (start && end) {
889         Node* startNode = start->node();
890         Node* endNode = end->node();
891         Node* stopNode = NodeTraversal::nextSkippingChildren(endNode);
892
893         for (Node* node = startNode; node != stopNode; node = NodeTraversal::next(node)) {
894             RenderObject* renderer = node->renderer();
895             if (!renderer)
896                 continue;
897
898             SelectionSubtreeRoot& root = renderer->selectionRoot();
899             SelectionSubtreeRoot selectionData = renderSubtreesMap.get(&root);
900             if (selectionData.selectionClear()) {
901                 selectionData.setSelectionStart(node->renderer());
902                 selectionData.setSelectionStartPos(node == startNode ? startPos : 0);
903             }
904
905             selectionData.setSelectionEnd(node->renderer());
906             if (node == endNode)
907                 selectionData.setSelectionEndPos(endPos);
908             else
909                 selectionData.setSelectionEndPos(node->offsetInCharacters() ? node->maxCharacterOffset() : node->childNodeCount());
910
911             renderSubtreesMap.set(&root, selectionData);
912         }
913     }
914     
915     updateSelectionForSubtrees(renderSubtreesMap, blockRepaintMode);
916 }
917
918 void RenderView::updateSelectionForSubtrees(RenderSubtreesMap& renderSubtreesMap, SelectionRepaintMode blockRepaintMode)
919 {
920     SubtreeOldSelectionDataMap oldSelectionDataMap;
921     for (auto it = renderSubtreesMap.begin(); it != renderSubtreesMap.end(); ++it) {
922         SelectionSubtreeRoot& subtreeSelectionData = it->value;
923         if (hasRenderNamedFlowThreads())
924             subtreeSelectionData.adjustForVisibleSelection(document());
925
926         std::unique_ptr<OldSelectionData> oldSelectionData = std::make_unique<OldSelectionData>();
927         clearSubtreeSelection(*it->key, blockRepaintMode, *oldSelectionData);
928         oldSelectionDataMap.set(it->key, WTF::move(oldSelectionData));
929
930         SelectionSubtreeRoot& root = *it->key;
931         root.setSelectionStart(subtreeSelectionData.selectionStart());
932         root.setSelectionStartPos(subtreeSelectionData.selectionStartPos());
933         root.setSelectionEnd(subtreeSelectionData.selectionEnd());
934         root.setSelectionEndPos(subtreeSelectionData.selectionEndPos());
935     }
936
937     // Update selection status for the objects inside the selection subtrees.
938     // This needs to be done after the previous loop updated the selectionStart/End
939     // parameters of all subtrees because we're going to be climbing up the containing
940     // block chain and we might end up in a different selection subtree.
941     for (auto it = renderSubtreesMap.begin(); it != renderSubtreesMap.end(); ++it) {
942         SelectionSubtreeRoot subtreeSelectionData = it->value;
943         OldSelectionData& oldSelectionData = *oldSelectionDataMap.get(it->key);
944         applySubtreeSelection(*it->key, subtreeSelectionData.selectionStart(), subtreeSelectionData.selectionEnd(), subtreeSelectionData.selectionEndPos(), blockRepaintMode, oldSelectionData);
945     }
946 }
947
948 void RenderView::clearSubtreeSelection(const SelectionSubtreeRoot& root, SelectionRepaintMode blockRepaintMode, OldSelectionData& oldSelectionData)
949 {
950     // Record the old selected objects.  These will be used later
951     // when we compare against the new selected objects.
952     oldSelectionData.selectionStartPos = root.selectionStartPos();
953     oldSelectionData.selectionEndPos = root.selectionEndPos();
954     
955     // Blocks contain selected objects and fill gaps between them, either on the left, right, or in between lines and blocks.
956     // In order to get the repaint rect right, we have to examine left, middle, and right rects individually, since otherwise
957     // the union of those rects might remain the same even when changes have occurred.
958
959     RenderObject* os = root.selectionStart();
960     RenderObject* stop = rendererAfterPosition(root.selectionEnd(), root.selectionEndPos());
961     SelectionIterator selectionIterator(os);
962     while (os && os != stop) {
963         if ((os->canBeSelectionLeaf() || os == root.selectionStart() || os == root.selectionEnd())
964             && os->selectionState() != SelectionNone) {
965             // Blocks are responsible for painting line gaps and margin gaps.  They must be examined as well.
966             oldSelectionData.selectedObjects.set(os, std::make_unique<RenderSelectionInfo>(*os, true));
967             if (blockRepaintMode == RepaintNewXOROld) {
968                 RenderBlock* cb = os->containingBlock();
969                 while (cb && !cb->isRenderView()) {
970                     std::unique_ptr<RenderBlockSelectionInfo>& blockInfo = oldSelectionData.selectedBlocks.add(cb, nullptr).iterator->value;
971                     if (blockInfo)
972                         break;
973                     blockInfo = std::make_unique<RenderBlockSelectionInfo>(*cb);
974                     cb = cb->containingBlock();
975                 }
976             }
977         }
978
979         os = selectionIterator.next();
980     }
981
982     auto oldObjectsEnd = oldSelectionData.selectedObjects.end();
983     for (auto i = oldSelectionData.selectedObjects.begin(); i != oldObjectsEnd; ++i)
984         i->key->setSelectionStateIfNeeded(SelectionNone);
985 }
986
987 void RenderView::applySubtreeSelection(SelectionSubtreeRoot& root, RenderObject* start, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode, const OldSelectionData& oldSelectionData)
988 {
989     // Update the selection status of all objects between selectionStart and selectionEnd
990     if (start && start == end)
991         start->setSelectionStateIfNeeded(SelectionBoth);
992     else {
993         if (start)
994             start->setSelectionStateIfNeeded(SelectionStart);
995         if (end)
996             end->setSelectionStateIfNeeded(SelectionEnd);
997     }
998
999     RenderObject* o = start;
1000     RenderObject* stop = rendererAfterPosition(end, endPos);
1001     SelectionIterator selectionIterator(o);
1002     
1003     while (o && o != stop) {
1004         if (o != start && o != end && o->canBeSelectionLeaf())
1005             o->setSelectionStateIfNeeded(SelectionInside);
1006         o = selectionIterator.next();
1007     }
1008
1009     if (blockRepaintMode != RepaintNothing)
1010         layer()->clearBlockSelectionGapsBounds();
1011
1012     // Now that the selection state has been updated for the new objects, walk them again and
1013     // put them in the new objects list.
1014     SelectedObjectMap newSelectedObjects;
1015     SelectedBlockMap newSelectedBlocks;
1016     o = start;
1017     selectionIterator = SelectionIterator(o);
1018     while (o && o != stop) {
1019         if ((o->canBeSelectionLeaf() || o == start || o == end) && o->selectionState() != SelectionNone) {
1020             std::unique_ptr<RenderSelectionInfo> selectionInfo = std::make_unique<RenderSelectionInfo>(*o, true);
1021
1022 #if ENABLE(SERVICE_CONTROLS)
1023             for (auto& rect : selectionInfo->collectedSelectionRects())
1024                 m_selectionRectGatherer.addRect(selectionInfo->repaintContainer(), rect);
1025             if (!o->isTextOrLineBreak())
1026                 m_selectionRectGatherer.setTextOnly(false);
1027 #endif
1028
1029             newSelectedObjects.set(o, WTF::move(selectionInfo));
1030
1031             RenderBlock* cb = o->containingBlock();
1032             while (cb && !cb->isRenderView()) {
1033                 std::unique_ptr<RenderBlockSelectionInfo>& blockInfo = newSelectedBlocks.add(cb, nullptr).iterator->value;
1034                 if (blockInfo)
1035                     break;
1036                 blockInfo = std::make_unique<RenderBlockSelectionInfo>(*cb);
1037                 cb = cb->containingBlock();
1038
1039 #if ENABLE(SERVICE_CONTROLS)
1040                 m_selectionRectGatherer.addGapRects(blockInfo->repaintContainer(), blockInfo->rects());
1041 #endif
1042             }
1043         }
1044
1045         o = selectionIterator.next();
1046     }
1047
1048     if (blockRepaintMode == RepaintNothing)
1049         return;
1050
1051     // Have any of the old selected objects changed compared to the new selection?
1052     auto oldObjectsEnd = oldSelectionData.selectedObjects.end();
1053     for (auto it = oldSelectionData.selectedObjects.begin(); it != oldObjectsEnd; ++it) {
1054         RenderObject* obj = it->key;
1055         RenderSelectionInfo* newInfo = newSelectedObjects.get(obj);
1056         RenderSelectionInfo* oldInfo = it->value.get();
1057         if (!newInfo || oldInfo->rect() != newInfo->rect() || oldInfo->state() != newInfo->state()
1058             || (root.selectionStart() == obj && oldSelectionData.selectionStartPos != root.selectionStartPos())
1059             || (root.selectionEnd() == obj && oldSelectionData.selectionEndPos != root.selectionEndPos())) {
1060             oldInfo->repaint();
1061             if (newInfo) {
1062                 newInfo->repaint();
1063                 newSelectedObjects.remove(obj);
1064             }
1065         }
1066     }
1067
1068     // Any new objects that remain were not found in the old objects dict, and so they need to be updated.
1069     auto newObjectsEnd = newSelectedObjects.end();
1070     for (auto it = newSelectedObjects.begin(); it != newObjectsEnd; ++it)
1071         it->value->repaint();
1072
1073     // Have any of the old blocks changed?
1074     auto oldBlocksEnd = oldSelectionData.selectedBlocks.end();
1075     for (auto it = oldSelectionData.selectedBlocks.begin(); it != oldBlocksEnd; ++it) {
1076         RenderBlock* block = it->key;
1077         RenderBlockSelectionInfo* newInfo = newSelectedBlocks.get(block);
1078         RenderBlockSelectionInfo* oldInfo = it->value.get();
1079         if (!newInfo || oldInfo->rects() != newInfo->rects() || oldInfo->state() != newInfo->state()) {
1080             oldInfo->repaint();
1081             if (newInfo) {
1082                 newInfo->repaint();
1083                 newSelectedBlocks.remove(block);
1084             }
1085         }
1086     }
1087
1088     // Any new blocks that remain were not found in the old blocks dict, and so they need to be updated.
1089     auto newBlocksEnd = newSelectedBlocks.end();
1090     for (auto it = newSelectedBlocks.begin(); it != newBlocksEnd; ++it)
1091         it->value->repaint();
1092 }
1093
1094 void RenderView::getSelection(RenderObject*& startRenderer, int& startOffset, RenderObject*& endRenderer, int& endOffset) const
1095 {
1096     startRenderer = m_selectionUnsplitStart;
1097     startOffset = m_selectionUnsplitStartPos;
1098     endRenderer = m_selectionUnsplitEnd;
1099     endOffset = m_selectionUnsplitEndPos;
1100 }
1101
1102 void RenderView::clearSelection()
1103 {
1104     layer()->repaintBlockSelectionGaps();
1105     setSelection(0, -1, 0, -1, RepaintNewMinusOld);
1106 }
1107
1108 bool RenderView::printing() const
1109 {
1110     return document().printing();
1111 }
1112
1113 bool RenderView::shouldUsePrintingLayout() const
1114 {
1115     if (!printing())
1116         return false;
1117     return frameView().frame().shouldUsePrintingLayout();
1118 }
1119
1120 LayoutRect RenderView::viewRect() const
1121 {
1122     if (shouldUsePrintingLayout())
1123         return LayoutRect(LayoutPoint(), size());
1124     return frameView().visibleContentRect(ScrollableArea::LegacyIOSDocumentVisibleRect);
1125 }
1126
1127 IntRect RenderView::unscaledDocumentRect() const
1128 {
1129     LayoutRect overflowRect(layoutOverflowRect());
1130     flipForWritingMode(overflowRect);
1131     return snappedIntRect(overflowRect);
1132 }
1133
1134 bool RenderView::rootBackgroundIsEntirelyFixed() const
1135 {
1136     RenderElement* rootObject = document().documentElement() ? document().documentElement()->renderer() : 0;
1137     if (!rootObject)
1138         return false;
1139
1140     return rootObject->rendererForRootBackground().hasEntirelyFixedBackground();
1141 }
1142     
1143 LayoutRect RenderView::unextendedBackgroundRect(RenderBox*) const
1144 {
1145     // FIXME: What is this? Need to patch for new columns?
1146     return unscaledDocumentRect();
1147 }
1148     
1149 LayoutRect RenderView::backgroundRect(RenderBox* backgroundRenderer) const
1150 {
1151     // FIXME: New columns care about this?
1152     if (frameView().hasExtendedBackgroundRectForPainting())
1153         return frameView().extendedBackgroundRectForPainting();
1154
1155     return unextendedBackgroundRect(backgroundRenderer);
1156 }
1157
1158 IntRect RenderView::documentRect() const
1159 {
1160     FloatRect overflowRect(unscaledDocumentRect());
1161     if (hasTransform())
1162         overflowRect = layer()->currentTransform().mapRect(overflowRect);
1163     return IntRect(overflowRect);
1164 }
1165
1166 int RenderView::viewHeight() const
1167 {
1168     int height = 0;
1169     if (!shouldUsePrintingLayout()) {
1170         height = frameView().layoutHeight();
1171         height = frameView().useFixedLayout() ? ceilf(style().effectiveZoom() * float(height)) : height;
1172     }
1173     return height;
1174 }
1175
1176 int RenderView::viewWidth() const
1177 {
1178     int width = 0;
1179     if (!shouldUsePrintingLayout()) {
1180         width = frameView().layoutWidth();
1181         width = frameView().useFixedLayout() ? ceilf(style().effectiveZoom() * float(width)) : width;
1182     }
1183     return width;
1184 }
1185
1186 int RenderView::viewLogicalHeight() const
1187 {
1188     int height = style().isHorizontalWritingMode() ? viewHeight() : viewWidth();
1189     return height;
1190 }
1191
1192 float RenderView::zoomFactor() const
1193 {
1194     return frameView().frame().pageZoomFactor();
1195 }
1196
1197 void RenderView::pushLayoutState(RenderObject& root)
1198 {
1199     ASSERT(m_layoutStateDisableCount == 0);
1200     ASSERT(m_layoutState == 0);
1201
1202     m_layoutState = std::make_unique<LayoutState>(root);
1203     pushLayoutStateForCurrentFlowThread(root);
1204 }
1205
1206 bool RenderView::shouldDisableLayoutStateForSubtree(RenderObject* renderer) const
1207 {
1208     RenderObject* o = renderer;
1209     while (o) {
1210         if (o->hasTransform() || o->hasReflection())
1211             return true;
1212         o = o->container();
1213     }
1214     return false;
1215 }
1216
1217 IntSize RenderView::viewportSizeForCSSViewportUnits() const
1218 {
1219     return frameView().viewportSizeForCSSViewportUnits();
1220 }
1221
1222 void RenderView::updateHitTestResult(HitTestResult& result, const LayoutPoint& point)
1223 {
1224     if (result.innerNode())
1225         return;
1226
1227     Node* node = document().documentElement();
1228     if (node) {
1229         result.setInnerNode(node);
1230         if (!result.innerNonSharedNode())
1231             result.setInnerNonSharedNode(node);
1232
1233         LayoutPoint adjustedPoint = point;
1234         offsetForContents(adjustedPoint);
1235
1236         result.setLocalPoint(adjustedPoint);
1237     }
1238 }
1239
1240 // FIXME: This function is obsolete and only used by embedded WebViews inside AppKit NSViews.
1241 // Do not add callers of this function!
1242 // The idea here is to take into account what object is moving the pagination point, and
1243 // thus choose the best place to chop it.
1244 void RenderView::setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak)
1245 {
1246     // Nobody else can set a page break once we have a forced break.
1247     if (m_legacyPrinting.m_forcedPageBreak)
1248         return;
1249
1250     // Forced breaks always win over unforced breaks.
1251     if (forcedBreak) {
1252         m_legacyPrinting.m_forcedPageBreak = true;
1253         m_legacyPrinting.m_bestTruncatedAt = y;
1254         return;
1255     }
1256
1257     // Prefer the widest object that tries to move the pagination point
1258     IntRect boundingBox = forRenderer->borderBoundingBox();
1259     if (boundingBox.width() > m_legacyPrinting.m_truncatorWidth) {
1260         m_legacyPrinting.m_truncatorWidth = boundingBox.width();
1261         m_legacyPrinting.m_bestTruncatedAt = y;
1262     }
1263 }
1264
1265 bool RenderView::usesCompositing() const
1266 {
1267     return m_compositor && m_compositor->inCompositingMode();
1268 }
1269
1270 RenderLayerCompositor& RenderView::compositor()
1271 {
1272     if (!m_compositor)
1273         m_compositor = std::make_unique<RenderLayerCompositor>(*this);
1274
1275     return *m_compositor;
1276 }
1277
1278 void RenderView::setIsInWindow(bool isInWindow)
1279 {
1280     if (m_compositor)
1281         m_compositor->setIsInWindow(isInWindow);
1282 }
1283
1284 void RenderView::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
1285 {
1286     RenderBlockFlow::styleDidChange(diff, oldStyle);
1287     if (hasRenderNamedFlowThreads())
1288         flowThreadController().styleDidChange();
1289
1290     frameView().styleDidChange();
1291 }
1292
1293 bool RenderView::hasRenderNamedFlowThreads() const
1294 {
1295     return m_flowThreadController && m_flowThreadController->hasRenderNamedFlowThreads();
1296 }
1297
1298 bool RenderView::checkTwoPassLayoutForAutoHeightRegions() const
1299 {
1300     return hasRenderNamedFlowThreads() && m_flowThreadController->hasFlowThreadsWithAutoLogicalHeightRegions();
1301 }
1302
1303 FlowThreadController& RenderView::flowThreadController()
1304 {
1305     if (!m_flowThreadController)
1306         m_flowThreadController = std::make_unique<FlowThreadController>(this);
1307
1308     return *m_flowThreadController;
1309 }
1310
1311 void RenderView::pushLayoutStateForCurrentFlowThread(const RenderObject& object)
1312 {
1313     if (!m_flowThreadController)
1314         return;
1315
1316     RenderFlowThread* currentFlowThread = m_flowThreadController->currentRenderFlowThread();
1317     if (!currentFlowThread)
1318         return;
1319
1320     currentFlowThread->pushFlowThreadLayoutState(object);
1321 }
1322
1323 void RenderView::popLayoutStateForCurrentFlowThread()
1324 {
1325     if (!m_flowThreadController)
1326         return;
1327
1328     RenderFlowThread* currentFlowThread = m_flowThreadController->currentRenderFlowThread();
1329     if (!currentFlowThread)
1330         return;
1331
1332     currentFlowThread->popFlowThreadLayoutState();
1333 }
1334
1335 IntervalArena* RenderView::intervalArena()
1336 {
1337     if (!m_intervalArena)
1338         m_intervalArena = IntervalArena::create();
1339     return m_intervalArena.get();
1340 }
1341
1342 ImageQualityController& RenderView::imageQualityController()
1343 {
1344     if (!m_imageQualityController)
1345         m_imageQualityController = std::make_unique<ImageQualityController>(*this);
1346     return *m_imageQualityController;
1347 }
1348
1349 void RenderView::addRendererWithPausedImageAnimations(RenderElement& renderer)
1350 {
1351     if (renderer.hasPausedImageAnimations()) {
1352         ASSERT(m_renderersWithPausedImageAnimation.contains(&renderer));
1353         return;
1354     }
1355     renderer.setHasPausedImageAnimations(true);
1356     m_renderersWithPausedImageAnimation.add(&renderer);
1357 }
1358
1359 void RenderView::removeRendererWithPausedImageAnimations(RenderElement& renderer)
1360 {
1361     ASSERT(renderer.hasPausedImageAnimations());
1362     ASSERT(m_renderersWithPausedImageAnimation.contains(&renderer));
1363
1364     renderer.setHasPausedImageAnimations(false);
1365     m_renderersWithPausedImageAnimation.remove(&renderer);
1366 }
1367
1368 void RenderView::resumePausedImageAnimationsIfNeeded()
1369 {
1370     auto visibleRect = frameView().windowToContents(frameView().windowClipRect());
1371     Vector<RenderElement*, 10> toRemove;
1372     for (auto* renderer : m_renderersWithPausedImageAnimation) {
1373         if (renderer->repaintForPausedImageAnimationsIfNeeded(visibleRect))
1374             toRemove.append(renderer);
1375     }
1376     for (auto& renderer : toRemove)
1377         removeRendererWithPausedImageAnimations(*renderer);
1378 }
1379
1380 RenderView::RepaintRegionAccumulator::RepaintRegionAccumulator(RenderView* view)
1381     : m_rootView(view ? view->document().topDocument().renderView() : nullptr)
1382 {
1383     if (!m_rootView)
1384         return;
1385     m_wasAccumulatingRepaintRegion = !!m_rootView->m_accumulatedRepaintRegion;
1386     if (!m_wasAccumulatingRepaintRegion)
1387         m_rootView->m_accumulatedRepaintRegion = std::make_unique<Region>();
1388 }
1389
1390 RenderView::RepaintRegionAccumulator::~RepaintRegionAccumulator()
1391 {
1392     if (!m_rootView)
1393         return;
1394     if (m_wasAccumulatingRepaintRegion)
1395         return;
1396     m_rootView->flushAccumulatedRepaintRegion();
1397 }
1398
1399 unsigned RenderView::pageNumberForBlockProgressionOffset(int offset) const
1400 {
1401     int columnNumber = 0;
1402     const Pagination& pagination = frameView().frame().page()->pagination();
1403     if (pagination.mode == Pagination::Unpaginated)
1404         return columnNumber;
1405     
1406     bool progressionIsInline = false;
1407     bool progressionIsReversed = false;
1408     
1409     if (multiColumnFlowThread()) {
1410         progressionIsInline = multiColumnFlowThread()->progressionIsInline();
1411         progressionIsReversed = multiColumnFlowThread()->progressionIsReversed();
1412     } else
1413         return columnNumber;
1414     
1415     if (!progressionIsInline) {
1416         if (!progressionIsReversed)
1417             columnNumber = (pagination.pageLength + pagination.gap - offset) / (pagination.pageLength + pagination.gap);
1418         else
1419             columnNumber = offset / (pagination.pageLength + pagination.gap);
1420     }
1421
1422     return columnNumber;
1423 }
1424
1425 unsigned RenderView::pageCount() const
1426 {
1427     const Pagination& pagination = frameView().frame().page()->pagination();
1428     if (pagination.mode == Pagination::Unpaginated)
1429         return 0;
1430     
1431     if (multiColumnFlowThread() && multiColumnFlowThread()->firstMultiColumnSet())
1432         return multiColumnFlowThread()->firstMultiColumnSet()->columnCount();
1433
1434     return 0;
1435 }
1436
1437 } // namespace WebCore