1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/page/scrolling/RootScrollerController.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/frame/FrameHost.h"
#include "core/frame/FrameView.h"
#include "core/layout/LayoutBox.h"
#include "core/layout/api/LayoutViewItem.h"
#include "core/layout/compositing/PaintLayerCompositor.h"
#include "core/page/scrolling/RootScrollerUtil.h"
#include "core/page/scrolling/TopDocumentRootScrollerController.h"
#include "core/paint/PaintLayer.h"
#include "core/paint/PaintLayerScrollableArea.h"
#include "platform/graphics/GraphicsLayer.h"
#include "platform/scroll/ScrollableArea.h"
namespace blink {
class RootFrameViewport;
namespace {
bool fillsViewport(const Element& element) {
DCHECK(element.layoutObject());
DCHECK(element.layoutObject()->isBox());
LayoutObject* layoutObject = element.layoutObject();
// TODO(bokan): Broken for OOPIF. crbug.com/642378.
Document& topDocument = element.document().topDocument();
Vector<FloatQuad> quads;
layoutObject->absoluteQuads(quads);
DCHECK_EQ(quads.size(), 1u);
if (!quads[0].isRectilinear())
return false;
LayoutRect boundingBox(quads[0].boundingBox());
return boundingBox.location() == LayoutPoint::zero() &&
boundingBox.size() == topDocument.layoutViewItem().size();
}
} // namespace
// static
RootScrollerController* RootScrollerController::create(Document& document) {
return new RootScrollerController(document);
}
RootScrollerController::RootScrollerController(Document& document)
: m_document(&document),
m_effectiveRootScroller(&document),
m_documentHasDocumentElement(false) {}
DEFINE_TRACE(RootScrollerController) {
visitor->trace(m_document);
visitor->trace(m_rootScroller);
visitor->trace(m_effectiveRootScroller);
}
void RootScrollerController::set(Element* newRootScroller) {
m_rootScroller = newRootScroller;
recomputeEffectiveRootScroller();
}
Element* RootScrollerController::get() const {
return m_rootScroller;
}
Node& RootScrollerController::effectiveRootScroller() const {
DCHECK(m_effectiveRootScroller);
return *m_effectiveRootScroller;
}
void RootScrollerController::didUpdateLayout() {
recomputeEffectiveRootScroller();
}
void RootScrollerController::recomputeEffectiveRootScroller() {
bool rootScrollerValid =
m_rootScroller && isValidRootScroller(*m_rootScroller);
Node* newEffectiveRootScroller = m_document;
if (rootScrollerValid)
newEffectiveRootScroller = m_rootScroller;
// TODO(bokan): This is a terrible hack but required because the viewport
// apply scroll works on Elements rather than Nodes. If we're going from
// !documentElement to documentElement, we can't early out even if the root
// scroller didn't change since the global root scroller didn't have an
// Element previously to put it's ViewportScrollCallback onto. We need this
// to kick the global root scroller to recompute itself. We can remove this
// if ScrollCustomization is moved to the Node rather than Element.
bool oldHasDocumentElement = m_documentHasDocumentElement;
m_documentHasDocumentElement = m_document->documentElement();
if (oldHasDocumentElement || !m_documentHasDocumentElement) {
if (m_effectiveRootScroller == newEffectiveRootScroller)
return;
}
PaintLayer* oldRootScrollerLayer = rootScrollerPaintLayer();
m_effectiveRootScroller = newEffectiveRootScroller;
// This change affects both the old and new layers.
if (oldRootScrollerLayer)
oldRootScrollerLayer->setNeedsCompositingInputsUpdate();
if (rootScrollerPaintLayer())
rootScrollerPaintLayer()->setNeedsCompositingInputsUpdate();
// The above may not be enough as we need to update existing ancestor
// GraphicsLayers. This will force us to rebuild the GraphicsLayer tree.
if (LayoutView* layoutView = m_document->layoutView()) {
layoutView->compositor()->setNeedsCompositingUpdate(
CompositingUpdateRebuildTree);
}
if (FrameHost* frameHost = m_document->frameHost())
frameHost->globalRootScrollerController().didChangeRootScroller();
}
bool RootScrollerController::isValidRootScroller(const Element& element) const {
if (!element.layoutObject())
return false;
if (!RootScrollerUtil::scrollableAreaForRootScroller(&element))
return false;
if (!fillsViewport(element))
return false;
return true;
}
PaintLayer* RootScrollerController::rootScrollerPaintLayer() const {
return RootScrollerUtil::paintLayerForRootScroller(m_effectiveRootScroller);
}
bool RootScrollerController::scrollsViewport(const Element& element) const {
if (m_effectiveRootScroller->isDocumentNode())
return element.isSameNode(m_document->documentElement());
return element.isSameNode(m_effectiveRootScroller);
}
} // namespace blink
|