15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *                     1999 Lars Knoll <knoll@kde.org>
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *                     1999 Antti Koivisto <koivisto@kde.org>
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *                     2000 Dirk Mueller <mueller@kde.org>
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *           (C) 2006 Alexey Proskuryakov (ap@nypop.com)
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2009 Google Inc. All rights reserved.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is free software; you can redistribute it and/or
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modify it under the terms of the GNU Library General Public
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * License as published by the Free Software Foundation; either
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * version 2 of the License, or (at your option) any later version.
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is distributed in the hope that it will be useful,
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Library General Public License for more details.
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * You should have received a copy of the GNU Library General Public License
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * along with this library; see the file COPYING.LIB.  If not, write to
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Boston, MA 02110-1301, USA.
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/frame/FrameView.h"
2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
305d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "core/HTMLNames.h"
317242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "core/MediaTypeNames.h"
3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/accessibility/AXObjectCache.h"
339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)#include "core/css/FontFaceSet.h"
3481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#include "core/css/resolver/StyleResolver.h"
3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/DocumentMarkerController.h"
3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/editing/FrameSelection.h"
377242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "core/editing/RenderedPosition.h"
381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/events/OverflowEvent.h"
39e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include "core/fetch/ResourceFetcher.h"
40a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "core/fetch/ResourceLoadPriorityOptimizer.h"
4110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch#include "core/frame/FrameHost.h"
42d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/frame/LocalFrame.h"
4309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/frame/Settings.h"
4453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/html/HTMLFrameElement.h"
45f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "core/html/HTMLPlugInElement.h"
4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/html/parser/TextResourceDecoder.h"
4753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/inspector/InspectorInstrumentation.h"
48f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "core/inspector/InspectorTraceEvents.h"
4953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/loader/FrameLoader.h"
5053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/loader/FrameLoaderClient.h"
5153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/Chrome.h"
5253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/ChromeClient.h"
5353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/EventHandler.h"
5453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/FocusController.h"
5553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/FrameTree.h"
56197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/page/Page.h"
5753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/scrolling/ScrollingCoordinator.h"
588abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "core/rendering/RenderCounter.h"
5953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderEmbeddedObject.h"
6053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderLayer.h"
6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/rendering/RenderListBox.h"
6253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderPart.h"
6353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderScrollbar.h"
6453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderScrollbarPart.h"
6553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderTheme.h"
6653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderView.h"
6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/rendering/RenderWidget.h"
6853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/TextAutosizer.h"
69d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/rendering/compositing/CompositedLayerMapping.h"
707242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "core/rendering/compositing/CompositedSelectionBound.h"
71d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/rendering/compositing/RenderLayerCompositor.h"
7253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/style/RenderStyle.h"
7393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/rendering/svg/RenderSVGRoot.h"
74323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)#include "core/svg/SVGDocumentExtensions.h"
7593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/svg/SVGSVGElement.h"
765d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "platform/RuntimeEnabledFeatures.h"
77197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "platform/ScriptForbiddenScope.h"
7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/TraceEvent.h"
79a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/fonts/FontCache.h"
801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/geometry/FloatRect.h"
81a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/GraphicsContext.h"
8209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/graphics/GraphicsLayerDebugInfo.h"
83a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/scroll/ScrollAnimator.h"
84a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/scroll/ScrollbarTheme.h"
851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/text/TextStream.h"
86591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/CurrentTime.h"
87591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/TemporaryChange.h"
885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
89c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)using namespace HTMLNames;
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
93e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)double FrameView::s_currentFrameTimeStamp = 0.0;
94e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)bool FrameView::s_inPaintContents = false;
955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// The maximum number of updateWidgets iterations that should be done before returning.
975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static const unsigned maxUpdateWidgetsIterations = 2;
9809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)static const double resourcePriorityUpdateDelayAfterScroll = 0.250;
995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
100d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)FrameView::FrameView(LocalFrame* frame)
1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    : m_frame(frame)
1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_canHaveScrollbars(true)
1035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_slowRepaintObjectCount(0)
10409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    , m_hasPendingLayout(false)
10509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    , m_layoutSubtreeRoot(0)
1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_inSynchronousPostLayout(false)
1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_postLayoutTasksTimer(this, &FrameView::postLayoutTimerFired)
10851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    , m_updateWidgetsTimer(this, &FrameView::updateWidgetsTimerFired)
1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_isTransparent(false)
1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_baseBackgroundColor(Color::white)
1117242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    , m_mediaType(MediaTypeNames::screen)
1125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_overflowStatusDirty(true)
1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_viewportRenderer(0)
1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_wasScrolledByUser(false)
1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_inProgrammaticScroll(false)
1165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_safeToPropagateScrollToParent(true)
117f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    , m_isTrackingPaintInvalidations(false)
118e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    , m_scrollCorner(nullptr)
11953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    , m_visibleContentScaleFactor(1)
1201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    , m_inputEventsScaleFactorForEmulation(1)
121bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    , m_layoutSizeFixedToFrameSize(true)
12209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    , m_didScrollTimer(this, &FrameView::didScrollTimerFired)
1239e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    , m_needsUpdateWidgetPositions(false)
1247242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    , m_topControlsViewportAdjustment(0)
1255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1268abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    ASSERT(m_frame);
1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    init();
1285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
12910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (!m_frame->isMainFrame())
1305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1328abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    ScrollableArea::setVerticalScrollElasticity(ScrollElasticityAllowed);
1338abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    ScrollableArea::setHorizontalScrollElasticity(ScrollElasticityAllowed);
1345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
136d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)PassRefPtr<FrameView> FrameView::create(LocalFrame* frame)
1375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RefPtr<FrameView> view = adoptRef(new FrameView(frame));
1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    view->show();
1405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return view.release();
1415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
143d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)PassRefPtr<FrameView> FrameView::create(LocalFrame* frame, const IntSize& initialSize)
1445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RefPtr<FrameView> view = adoptRef(new FrameView(frame));
1465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    view->Widget::setFrameRect(IntRect(view->location(), initialSize));
147bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    view->setLayoutSizeInternal(initialSize);
148bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    view->show();
1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return view.release();
1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)FrameView::~FrameView()
1545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
15551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    if (m_postLayoutTasksTimer.isActive())
1565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_postLayoutTasksTimer.stop();
157591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
15809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (m_didScrollTimer.isActive())
15909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_didScrollTimer.stop();
16009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
161926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    removeFromAXObjectCache();
1625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Custom scrollbars should already be destroyed at this point
1645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(!horizontalScrollbar() || !horizontalScrollbar()->isCustomScrollbar());
1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(!verticalScrollbar() || !verticalScrollbar()->isCustomScrollbar());
1665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    setHasHorizontalScrollbar(false); // Remove native scrollbars now before we lose the connection to the HostWindow.
1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    setHasVerticalScrollbar(false);
169591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(!m_scrollCorner);
1715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1728abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    ASSERT(m_frame);
1738abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    ASSERT(m_frame->view() != this || !m_frame->contentRenderer());
174f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // FIXME: Do we need to do something here for OOPI?
175f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    HTMLFrameOwnerElement* ownerElement = m_frame->deprecatedLocalOwner();
176a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    if (ownerElement && ownerElement->ownedWidget() == this)
177a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch        ownerElement->setWidget(nullptr);
1785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::reset()
1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
18209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_hasPendingLayout = false;
18309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_layoutSubtreeRoot = 0;
184f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    m_doFullPaintInvalidation = false;
1855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_layoutSchedulingEnabled = true;
18609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_inPerformLayout = false;
187f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    m_canInvalidatePaintDuringPerformLayout = false;
1885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_inSynchronousPostLayout = false;
1895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_layoutCount = 0;
1905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_nestedLayoutCount = 0;
1915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_postLayoutTasksTimer.stop();
19251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    m_updateWidgetsTimer.stop();
1935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_firstLayout = true;
1945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_firstLayoutCallbackPending = false;
1955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_wasScrolledByUser = false;
1965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_safeToPropagateScrollToParent = true;
1975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_lastViewportSize = IntSize();
1985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_lastZoomFactor = 1.0f;
199f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    m_isTrackingPaintInvalidations = false;
200f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    m_trackedPaintInvalidationRects.clear();
2015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_lastPaintTime = 0;
2025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_paintBehavior = PaintBehaviorNormal;
2035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_isPainting = false;
2045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_visuallyNonEmptyCharacterCount = 0;
2055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_visuallyNonEmptyPixelCount = 0;
2065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_isVisuallyNonEmpty = false;
2075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_firstVisuallyNonEmptyLayoutCallbackPending = true;
208d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    m_maintainScrollPositionAnchor = nullptr;
20951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    m_viewportConstrainedObjects.clear();
2105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
212926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void FrameView::removeFromAXObjectCache()
213926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
2147242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (AXObjectCache* cache = axObjectCache()) {
215926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        cache->remove(this);
2167242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        cache->childrenChanged(m_frame->pagePopupOwner());
2177242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    }
2185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::init()
2215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    reset();
2235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_size = LayoutSize();
2255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Propagate the marginwidth/height and scrolling modes to the view.
227f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // FIXME: Do we need to do this for OOPI?
228f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    Element* ownerElement = m_frame->deprecatedLocalOwner();
229d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (ownerElement && (isHTMLFrameElement(*ownerElement) || isHTMLIFrameElement(*ownerElement))) {
230e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        HTMLFrameElementBase* frameElt = toHTMLFrameElementBase(ownerElement);
2315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (frameElt->scrollingMode() == ScrollbarAlwaysOff)
2325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            setCanHaveScrollbars(false);
2335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
2345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
235591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
236926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void FrameView::prepareForDetach()
237926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
23809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    RELEASE_ASSERT(!isInPerformLayout());
2397757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch
240fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch    if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
241fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch        scrollAnimator->cancelAnimations();
242c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    cancelProgrammaticScrollAnimation();
243fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch
244926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    detachCustomScrollbars();
245926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // When the view is no longer associated with a frame, it needs to be removed from the ax object cache
246926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // right now, otherwise it won't be able to reach the topDocument()'s axObject cache later.
247926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    removeFromAXObjectCache();
248926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
2498abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    if (m_frame->page()) {
250926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        if (ScrollingCoordinator* scrollingCoordinator = m_frame->page()->scrollingCoordinator())
251926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            scrollingCoordinator->willDestroyScrollableArea(this);
252926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
253926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
2545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::detachCustomScrollbars()
2565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Scrollbar* horizontalBar = horizontalScrollbar();
2585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (horizontalBar && horizontalBar->isCustomScrollbar())
2595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        setHasHorizontalScrollbar(false);
2605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Scrollbar* verticalBar = verticalScrollbar();
2625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (verticalBar && verticalBar->isCustomScrollbar())
2635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        setHasVerticalScrollbar(false);
2645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_scrollCorner) {
2665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_scrollCorner->destroy();
267e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        m_scrollCorner = nullptr;
2685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
2695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::recalculateScrollbarOverlayStyle()
2725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollbarOverlayStyle oldOverlayStyle = scrollbarOverlayStyle();
2745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollbarOverlayStyle overlayStyle = ScrollbarOverlayStyleDefault;
2755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2768abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    Color backgroundColor = documentBackgroundColor();
27709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Reduce the background color from RGB to a lightness value
27809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // and determine which scrollbar style to use based on a lightness
27909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // heuristic.
28009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    double hue, saturation, lightness;
28109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    backgroundColor.getHSL(hue, saturation, lightness);
28209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (lightness <= .5)
28309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        overlayStyle = ScrollbarOverlayStyleLight;
2845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (oldOverlayStyle != overlayStyle)
2865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        setScrollbarOverlayStyle(overlayStyle);
2875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::clear()
2905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    reset();
2925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    setScrollbarsSuppressed(true);
2935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool FrameView::didFirstLayout() const
2965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return !m_firstLayout;
2985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::invalidateRect(const IntRect& rect)
3015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
3027242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // For querying RenderLayer::compositingState() when invalidating scrollbars.
3037242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // FIXME: do all scrollbar invalidations after layout of all frames is complete. It's currently not recursively true.
3047242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    DisableCompositingQueryAsserts disabler;
3055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!parent()) {
306521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)        if (HostWindow* window = hostWindow())
307521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)            window->invalidateContentsAndRootView(rect);
3085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
3095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
3105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderPart* renderer = m_frame->ownerRenderer();
3125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!renderer)
3135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
3145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
315f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    IntRect paintInvalidationRect = rect;
316f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    paintInvalidationRect.move(renderer->borderLeft() + renderer->paddingLeft(),
3175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                     renderer->borderTop() + renderer->paddingTop());
3185d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    renderer->invalidatePaintRectangle(paintInvalidationRect);
3195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::setFrameRect(const IntRect& newRect)
3225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
3235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    IntRect oldRect = frameRect();
324d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (newRect == oldRect)
3255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
3265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
327926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // Autosized font sizes depend on the width of the viewing area.
328aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    bool autosizerNeedsUpdating = false;
329c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    if (newRect.width() != oldRect.width() && m_frame->isMainFrame() && m_frame->settings()->textAutosizingEnabled())
330c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        autosizerNeedsUpdating = true;
331926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
3325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollView::setFrameRect(newRect);
3335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    updateScrollableAreaSet();
3355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
336aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    if (autosizerNeedsUpdating) {
337aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch        // This needs to be after the call to ScrollView::setFrameRect, because it reads the new width.
338c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        if (TextAutosizer* textAutosizer = m_frame->document()->textAutosizer())
339aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch            textAutosizer->updatePageInfoInAllFrames();
340aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    }
341aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch
342926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (RenderView* renderView = this->renderView()) {
343926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        if (renderView->usesCompositing())
344926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            renderView->compositor()->frameViewDidChangeSize();
3455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
34609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
347d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    viewportConstrainedVisibleContentSizeChanged(newRect.width() != oldRect.width(), newRect.height() != oldRect.height());
348323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)
349323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    if (oldRect.size() != newRect.size()
350323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        && m_frame->isMainFrame()
351323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        && m_frame->settings()->pinchVirtualViewportEnabled())
352323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        page()->frameHost().pinchViewport().mainFrameDidChangeSize();
3535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
355d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)Page* FrameView::page() const
356d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
357d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return frame().page();
358d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
359d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
3608abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)RenderView* FrameView::renderView() const
3618abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){
3628abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    return frame().contentRenderer();
3638abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)}
3648abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
3655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::setCanHaveScrollbars(bool canHaveScrollbars)
3665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
3675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_canHaveScrollbars = canHaveScrollbars;
3685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollView::setCanHaveScrollbars(canHaveScrollbars);
3695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
371d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)bool FrameView::shouldUseCustomScrollbars(Element*& customScrollbarElement, LocalFrame*& customScrollbarFrame)
3725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
37309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    customScrollbarElement = 0;
37409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    customScrollbarFrame = 0;
3755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
376926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (Settings* settings = m_frame->settings()) {
37710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        if (!settings->allowCustomScrollbarInMainFrame() && m_frame->isMainFrame())
37809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            return false;
379926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
380926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
3815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // FIXME: We need to update the scrollbar dynamically as documents change (or as doc elements and bodies get discovered that have custom styles).
3825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Document* doc = m_frame->document();
3835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Try the <body> element first as a scrollbar source.
3855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Element* body = doc ? doc->body() : 0;
38609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (body && body->renderer() && body->renderer()->style()->hasPseudoStyle(SCROLLBAR)) {
38709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        customScrollbarElement = body;
38809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return true;
38909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
390591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
3915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // If the <body> didn't have a custom style, then the root element might.
3925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Element* docElement = doc ? doc->documentElement() : 0;
39309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (docElement && docElement->renderer() && docElement->renderer()->style()->hasPseudoStyle(SCROLLBAR)) {
39409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        customScrollbarElement = docElement;
39509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return true;
39609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
397591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
398d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // If we have an owning ipage/LocalFrame element, then it can set the custom scrollbar also.
3995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderPart* frameRenderer = m_frame->ownerRenderer();
40009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (frameRenderer && frameRenderer->style()->hasPseudoStyle(SCROLLBAR)) {
40109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        customScrollbarFrame = m_frame.get();
40209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return true;
40309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
40409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
40509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return false;
40609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
40709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
40809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)PassRefPtr<Scrollbar> FrameView::createScrollbar(ScrollbarOrientation orientation)
40909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
41009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    Element* customScrollbarElement = 0;
411d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    LocalFrame* customScrollbarFrame = 0;
41209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (shouldUseCustomScrollbars(customScrollbarElement, customScrollbarFrame))
41309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return RenderScrollbar::createCustomScrollbar(this, orientation, customScrollbarElement, customScrollbarFrame);
414591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
4155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Nobody set a custom style, so we just use a native scrollbar.
4165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return ScrollView::createScrollbar(orientation);
4175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::setContentsSize(const IntSize& size)
4205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (size == contentsSize())
4225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
4235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollView::setContentsSize(size);
4255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollView::contentsResized();
426591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
4278abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    Page* page = frame().page();
4285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!page)
4295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
4305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    updateScrollableAreaSet();
4325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
433a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    page->chrome().contentsSizeChanged(m_frame.get(), size);
4345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
436d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)IntPoint FrameView::clampOffsetAtScale(const IntPoint& offset, float scale) const
437d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
438d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    IntPoint maxScrollExtent(contentsSize().width() - scrollOrigin().x(), contentsSize().height() - scrollOrigin().y());
439d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    FloatSize scaledSize = unscaledVisibleContentSize();
440d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (scale)
441d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        scaledSize.scale(1 / scale);
442d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
443d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    IntPoint clampedOffset = offset;
444d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    clampedOffset = clampedOffset.shrunkTo(maxScrollExtent - expandedIntSize(scaledSize));
445d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    clampedOffset = clampedOffset.expandedTo(-scrollOrigin());
446d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
447d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return clampedOffset;
448d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
449d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
4505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::adjustViewSize()
4515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
452926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
453926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!renderView)
4545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
4555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_frame->view() == this);
4575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
458926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    const IntRect rect = renderView->documentRect();
4595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const IntSize& size = rect.size();
4605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollView::setScrollOrigin(IntPoint(-rect.x(), -rect.y()), !m_frame->document()->printing(), size == contentsSize());
461591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
4625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    setContentsSize(size);
4635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
46509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void FrameView::applyOverflowToViewportAndSetRenderer(RenderObject* o, ScrollbarMode& hMode, ScrollbarMode& vMode)
4665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
4675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Handle the overflow:hidden/scroll case for the body/html elements.  WinIE treats
4685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // overflow:hidden and overflow:scroll on <body> as applying to the document's
4695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // scrollbars.  The CSS2.1 draft states that HTML UAs should use the <html> or <body> element and XML/XHTML UAs should
4705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // use the root element.
4715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EOverflow overflowX = o->style()->overflowX();
4735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EOverflow overflowY = o->style()->overflowY();
4745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (o->isSVGRoot()) {
476d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        // Don't allow overflow to affect <img> and css backgrounds
477d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        if (toRenderSVGRoot(o)->isEmbeddedThroughSVGImage())
478d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)            return;
479d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
48010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        // FIXME: evaluate if we can allow overflow for these cases too.
48110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        // Overflow is always hidden when stand-alone SVG documents are embedded.
48210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        if (toRenderSVGRoot(o)->isEmbeddedThroughFrameContainingSVGDocument()) {
48310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch            overflowX = OHIDDEN;
48410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch            overflowY = OHIDDEN;
48510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        }
4865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
4875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
48806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    bool ignoreOverflowHidden = false;
48951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    if (m_frame->settings()->ignoreMainFrameOverflowHiddenQuirk() && m_frame->isMainFrame())
49006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)        ignoreOverflowHidden = true;
49106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
4925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    switch (overflowX) {
4935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        case OHIDDEN:
49406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)            if (!ignoreOverflowHidden)
49506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)                hMode = ScrollbarAlwaysOff;
4965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            break;
4975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        case OSCROLL:
4985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            hMode = ScrollbarAlwaysOn;
4995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            break;
5005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        case OAUTO:
5015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            hMode = ScrollbarAuto;
5025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            break;
5035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        default:
5045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Don't set it at all.
5055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            ;
5065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
507591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
5085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)     switch (overflowY) {
5095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        case OHIDDEN:
51006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)            if (!ignoreOverflowHidden)
51106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)                vMode = ScrollbarAlwaysOff;
5125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            break;
5135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        case OSCROLL:
5145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            vMode = ScrollbarAlwaysOn;
5155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            break;
5165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        case OAUTO:
5175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            vMode = ScrollbarAuto;
5185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            break;
5195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        default:
52009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            // Don't set it at all.
5215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            ;
5225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
5235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_viewportRenderer = o;
5255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
52709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void FrameView::calculateScrollbarModesForLayoutAndSetViewportRenderer(ScrollbarMode& hMode, ScrollbarMode& vMode, ScrollbarModesCalculationStrategy strategy)
5285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_viewportRenderer = 0;
5305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
531f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // FIXME: How do we handle this for OOPI?
532f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    const HTMLFrameOwnerElement* owner = m_frame->deprecatedLocalOwner();
5335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (owner && (owner->scrollingMode() == ScrollbarAlwaysOff)) {
5345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        hMode = ScrollbarAlwaysOff;
5355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        vMode = ScrollbarAlwaysOff;
5365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
537591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    }
538591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
5395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_canHaveScrollbars || strategy == RulesFromWebContentOnly) {
5405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        hMode = ScrollbarAuto;
54109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        vMode = ScrollbarAuto;
5425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } else {
5435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        hMode = ScrollbarAlwaysOff;
5445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        vMode = ScrollbarAlwaysOff;
5455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
546591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
54709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!isSubtreeLayout()) {
5485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        Document* document = m_frame->document();
5495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        Node* body = document->body();
550d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (isHTMLFrameSetElement(body) && body->renderer()) {
55109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            vMode = ScrollbarAlwaysOff;
55209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            hMode = ScrollbarAlwaysOff;
55309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        } else if (Element* viewportElement = document->viewportDefiningElement()) {
55409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            if (RenderObject* viewportRenderer = viewportElement->renderer()) {
55509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                if (viewportRenderer->style())
55609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    applyOverflowToViewportAndSetRenderer(viewportRenderer, hMode, vMode);
5575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
55809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
559591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    }
5605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5626f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdochvoid FrameView::updateAcceleratedCompositingSettings()
5636f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch{
5646f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    if (RenderView* renderView = this->renderView())
5656f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch        renderView->compositor()->updateAcceleratedCompositingSettings();
5666f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch}
5676f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch
568f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liuvoid FrameView::recalcOverflowAfterStyleChange()
569f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu{
570f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    RenderView* renderView = this->renderView();
5717242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    RELEASE_ASSERT(renderView);
572f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    if (!renderView->needsOverflowRecalcAfterStyleChange())
573f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        return;
574f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
575f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    renderView->recalcOverflowAfterStyleChange();
576f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
577c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    IntRect documentRect = renderView->documentRect();
578c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    if (scrollOrigin() == -documentRect.location() && contentsSize() == documentRect.size())
579c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        return;
580c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
5815d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    if (needsLayout())
5825d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        return;
583f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
5845d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    InUpdateScrollbarsScope inUpdateScrollbarsScope(this);
5855d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
5865d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    bool shouldHaveHorizontalScrollbar = false;
5875d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    bool shouldHaveVerticalScrollbar = false;
588c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    computeScrollbarExistence(shouldHaveHorizontalScrollbar, shouldHaveVerticalScrollbar, documentRect.size());
5895d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
5905d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    bool hasHorizontalScrollbar = horizontalScrollbar();
5915d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    bool hasVerticalScrollbar = verticalScrollbar();
5925d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar
5935d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        || hasVerticalScrollbar != shouldHaveVerticalScrollbar) {
5945d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        setNeedsLayout();
5955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
5965d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    }
5975d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
5985d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    adjustViewSize();
5995d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    updateScrollbarGeometry();
6005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
602926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)bool FrameView::usesCompositedScrolling() const
603926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
604926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
605926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!renderView)
606926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return false;
6079e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    if (m_frame->settings() && m_frame->settings()->preferCompositingToLCDTextEnabled())
60810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        return renderView->compositor()->inCompositingMode();
609926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return false;
610926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
611926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
612926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)GraphicsLayer* FrameView::layerForScrolling() const
613926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
614926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
615926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!renderView)
616926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return 0;
617926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return renderView->compositor()->scrollLayer();
618926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
619926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
6205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)GraphicsLayer* FrameView::layerForHorizontalScrollbar() const
6215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
622926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
623926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!renderView)
6245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
625926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return renderView->compositor()->layerForHorizontalScrollbar();
6265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)GraphicsLayer* FrameView::layerForVerticalScrollbar() const
6295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
630926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
631926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!renderView)
6325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
633926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return renderView->compositor()->layerForVerticalScrollbar();
6345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)GraphicsLayer* FrameView::layerForScrollCorner() const
6375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
638926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
639926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!renderView)
6405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
641926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return renderView->compositor()->layerForScrollCorner();
6425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool FrameView::isEnclosedInCompositingLayer() const
6455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
646f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    // FIXME: It's a bug that compositing state isn't always up to date when this is called. crbug.com/366314
647f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    DisableCompositingQueryAsserts disabler;
648f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
6495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderObject* frameOwnerRenderer = m_frame->ownerRenderer();
650197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    return frameOwnerRenderer && frameOwnerRenderer->enclosingLayer()->enclosingLayerForPaintInvalidationCrossingFrameBoundaries();
6515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
652591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
6535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)RenderObject* FrameView::layoutRoot(bool onlyDuringLayout) const
6545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
65509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return onlyDuringLayout && layoutPending() ? 0 : m_layoutSubtreeRoot;
6565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)inline void FrameView::forceLayoutParentViewIfNeeded()
6595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderPart* ownerRenderer = m_frame->ownerRenderer();
6615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!ownerRenderer || !ownerRenderer->frame())
6625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
6635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderBox* contentBox = embeddedContentBox();
6655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!contentBox)
6665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
6675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderSVGRoot* svgRoot = toRenderSVGRoot(contentBox);
6695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (svgRoot->everHadLayout() && !svgRoot->needsLayout())
6705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
6715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // If the embedded SVG document appears the first time, the ownerRenderer has already finished
6735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // layout without knowing about the existence of the embedded SVG document, because RenderReplaced
6745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // embeddedContentBox() returns 0, as long as the embedded document isn't loaded yet. Before
6755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // bothering to lay out the SVG document, mark the ownerRenderer needing layout and ask its
6765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // FrameView for a layout. After that the RenderEmbeddedObject (ownerRenderer) carries the
6775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // correct size, which RenderSVGRoot::computeReplacedLogicalWidth/Height rely on, when laying
6785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // out for the first time, or when the RenderSVGRoot size has changed dynamically (eg. via <script>).
6795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RefPtr<FrameView> frameView = ownerRenderer->frame()->view();
6805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Mark the owner renderer as needing layout.
6825d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    ownerRenderer->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
6835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Synchronously enter layout, to layout the view containing the host object/embed/iframe.
6855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(frameView);
6865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    frameView->layout();
6875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
689e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void FrameView::performPreLayoutTasks()
690e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
691197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT0("blink", "FrameView::performPreLayoutTasks");
69209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    lifecycle().advanceTo(DocumentLifecycle::InPreLayout);
69309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
694e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    // Don't schedule more layouts, we're in one.
695e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    TemporaryChange<bool> changeSchedulingEnabled(m_layoutSchedulingEnabled, false);
696e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
69709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!m_nestedLayoutCount && !m_inSynchronousPostLayout && m_postLayoutTasksTimer.isActive()) {
698e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        // This is a new top-level layout. If there are any remaining tasks from the previous layout, finish them now.
699e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        m_inSynchronousPostLayout = true;
700e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        performPostLayoutTasks();
701e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        m_inSynchronousPostLayout = false;
702e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    }
703e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
704e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    Document* document = m_frame->document();
7057242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (wasViewportResized())
7067242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        document->notifyResizeForViewportUnits();
70709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
70809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Viewport-dependent media queries may cause us to need completely different style information.
70909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!document->styleResolver() || document->styleResolver()->mediaQueryAffectedByViewportChange()) {
710d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        document->styleResolverChanged();
71151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        document->mediaQueryAffectingValueChanged();
71251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
713e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        // FIXME: This instrumentation event is not strictly accurate since cached media query results
714e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        //        do not persist across StyleResolver rebuilds.
715e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        InspectorInstrumentation::mediaQueryResultChanged(document);
716e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    } else {
717e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        document->evaluateMediaQueryList();
718e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    }
719e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
72007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    document->updateRenderTreeIfNeeded();
72109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    lifecycle().advanceTo(DocumentLifecycle::StyleClean);
722e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
723e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
724e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void FrameView::performLayout(RenderObject* rootForThisLayout, bool inSubtreeLayout)
725e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
726197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT0("blink", "FrameView::performLayout");
72709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
728f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    ScriptForbiddenScope forbidScript;
729f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
73009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ASSERT(!isInPerformLayout());
73109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    lifecycle().advanceTo(DocumentLifecycle::InPerformLayout);
73209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
73309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    TemporaryChange<bool> changeInPerformLayout(m_inPerformLayout, true);
73409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
735e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    // performLayout is the actual guts of layout().
736e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    // FIXME: The 300 other lines in layout() probably belong in other helper functions
737e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    // so that a single human could understand what layout() is actually doing.
7381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
7395d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    LayoutState layoutState(*rootForThisLayout);
7405d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
741d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    forceLayoutParentViewIfNeeded();
742e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
743d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // FIXME (crbug.com/256657): Do not do two layouts for text autosizing.
744d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    rootForThisLayout->layout();
745d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    gatherDebugLayoutRects(rootForThisLayout);
7468abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
747d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->updateAllImageResourcePriorities();
748e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
74909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    lifecycle().advanceTo(DocumentLifecycle::AfterPerformLayout);
750e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
751e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
752e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void FrameView::scheduleOrPerformPostLayoutTasks()
753e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
75451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    if (m_postLayoutTasksTimer.isActive())
755e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        return;
756e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
757e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    if (!m_inSynchronousPostLayout) {
75809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_inSynchronousPostLayout = true;
75909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        // Calls resumeScheduledEvents()
76009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        performPostLayoutTasks();
76109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_inSynchronousPostLayout = false;
762e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    }
763e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
76409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!m_postLayoutTasksTimer.isActive() && (needsLayout() || m_inSynchronousPostLayout)) {
765e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        // If we need layout or are already in a synchronous call to postLayoutTasks(),
766e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        // defer widget updates and event dispatch until after we return. postLayoutTasks()
767e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        // can make us need to update again, and we can get stuck in a nasty cycle unless
768e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        // we call it through the timer here.
769d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_postLayoutTasksTimer.startOneShot(0, FROM_HERE);
770d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (needsLayout())
771e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)            layout();
772e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    }
773e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
774e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
7755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::layout(bool allowSubtree)
7765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
777d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // We should never layout a Document which is not in a LocalFrame.
7787757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    ASSERT(m_frame);
7797757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    ASSERT(m_frame->view() == this);
7807757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    ASSERT(m_frame->page());
7817757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch
782197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    ScriptForbiddenScope forbidScript;
783197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
78409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (isInPerformLayout() || !m_frame->document()->isActive())
7855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
7865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
787197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT0("blink", "FrameView::layout");
788197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "Layout");
789926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
7905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Protect the view from being deleted during layout (in recalcStyle)
7915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RefPtr<FrameView> protector(this);
7925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
793926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // Every scroll that happens during layout is programmatic.
794926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    TemporaryChange<bool> changeInProgrammaticScroll(m_inProgrammaticScroll, true);
795926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
7967242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (m_autoSizeInfo)
7977242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        m_autoSizeInfo->autoSizeIfNeeded();
7987242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
79909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_hasPendingLayout = false;
80009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    DocumentLifecycle::Scope lifecycleScope(lifecycle(), DocumentLifecycle::LayoutClean);
8015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
80209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    RELEASE_ASSERT(!isPainting());
8035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
804f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    TRACE_EVENT_BEGIN1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Layout", "beginData", InspectorLayoutEvent::beginData(this));
805323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "CallStack", "stack", InspectorCallStackEvent::currentCallStack());
806f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeline migrates to tracing.
8075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willLayout(m_frame.get());
8085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
80909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!allowSubtree && isSubtreeLayout()) {
81009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_layoutSubtreeRoot->markContainingBlocksForLayout(false);
81109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_layoutSubtreeRoot = 0;
8125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
8135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
814e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    performPreLayoutTasks();
8155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
816e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    // If there is only one ref to this view left, then its going to be destroyed as soon as we exit,
817e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    // so there's no point to continuing to layout
818e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    if (protector->hasOneRef())
819e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        return;
8205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
821e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    Document* document = m_frame->document();
82209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    bool inSubtreeLayout = isSubtreeLayout();
823d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    RenderObject* rootForThisLayout = inSubtreeLayout ? m_layoutSubtreeRoot : document->renderView();
824e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    if (!rootForThisLayout) {
825e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        // FIXME: Do we need to set m_size here?
826e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        ASSERT_NOT_REACHED();
827e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        return;
828e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    }
8295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    FontCachePurgePreventer fontCachePurgePreventer;
8315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderLayer* layer;
8325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
8335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        TemporaryChange<bool> changeSchedulingEnabled(m_layoutSchedulingEnabled, false);
8345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_nestedLayoutCount++;
83609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (!inSubtreeLayout) {
83719cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)            Document* document = m_frame->document();
83819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)            Node* body = document->body();
83919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)            if (body && body->renderer()) {
840d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                if (isHTMLFrameSetElement(*body)) {
84119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)                    body->renderer()->setChildNeedsLayout();
842d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                } else if (isHTMLBodyElement(*body)) {
84319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)                    if (!m_firstLayout && m_size.height() != layoutSize().height() && body->renderer()->enclosingBox()->stretchesToViewport())
84419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)                        body->renderer()->setChildNeedsLayout();
84519cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)                }
84619cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)            }
84719cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)        }
8488abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        updateCounters();
8495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        ScrollbarMode hMode;
851591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        ScrollbarMode vMode;
85209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        calculateScrollbarModesForLayoutAndSetViewportRenderer(hMode, vMode);
8535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
854d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (!inSubtreeLayout) {
8555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Now set our scrollbar state for the layout.
8565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            ScrollbarMode currentHMode = horizontalScrollbarMode();
8575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            ScrollbarMode currentVMode = verticalScrollbarMode();
8585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
859d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            if (m_firstLayout) {
860d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                setScrollbarsSuppressed(true);
861d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
862f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)                m_doFullPaintInvalidation = true;
863d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                m_firstLayout = false;
864d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                m_firstLayoutCallbackPending = true;
865d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                m_lastViewportSize = layoutSize(IncludeScrollbars);
866d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                m_lastZoomFactor = rootForThisLayout->style()->zoom();
867d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
868d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                // Set the initial vMode to AlwaysOn if we're auto.
869d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                if (vMode == ScrollbarAuto)
870d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                    setVerticalScrollbarMode(ScrollbarAlwaysOn); // This causes a vertical scrollbar to appear.
871d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                // Set the initial hMode to AlwaysOff if we're auto.
872d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                if (hMode == ScrollbarAuto)
873d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                    setHorizontalScrollbarMode(ScrollbarAlwaysOff); // This causes a horizontal scrollbar to disappear.
874d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
875d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                setScrollbarModes(hMode, vMode);
876d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                setScrollbarsSuppressed(false, true);
877d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            } else if (hMode != currentHMode || vMode != currentVMode) {
878d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                setScrollbarModes(hMode, vMode);
8795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
8805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutSize oldSize = m_size;
8825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
883bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)            m_size = LayoutSize(layoutSize().width(), layoutSize().height());
8845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
885d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)            if (oldSize != m_size && !m_firstLayout) {
886d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)                RenderBox* rootRenderer = document->documentElement() ? document->documentElement()->renderBox() : 0;
887d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)                RenderBox* bodyRenderer = rootRenderer && document->body() ? document->body()->renderBox() : 0;
888d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)                if (bodyRenderer && bodyRenderer->stretchesToViewport())
889d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)                    bodyRenderer->setChildNeedsLayout();
890d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)                else if (rootRenderer && rootRenderer->stretchesToViewport())
891d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)                    rootRenderer->setChildNeedsLayout();
8925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
893d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
8945d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            // We need to set m_doFullPaintInvalidation before triggering layout as RenderObject::checkForPaintInvalidation
895f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)            // checks the boolean to disable local paint invalidations.
896c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)            m_doFullPaintInvalidation |= renderView()->shouldDoFullPaintInvalidationForNextLayout();
8975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
8985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8997757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch        layer = rootForThisLayout->enclosingLayer();
9005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
901e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        performLayout(rootForThisLayout, inSubtreeLayout);
90251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
90309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_layoutSubtreeRoot = 0;
904197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        // We need to ensure that we mark up all renderers up to the RenderView
905197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        // for paint invalidation. This simplifies our code as we just always
906197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        // do a full tree walk.
907197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        if (RenderObject* container = rootForThisLayout->container())
908197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            container->setMayNeedPaintInvalidation(true);
9095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } // Reset m_layoutSchedulingEnabled to its previous value.
9105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
911d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (!inSubtreeLayout && !toRenderView(rootForThisLayout)->document().printing())
9125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        adjustViewSize();
9135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
914c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    layer->updateLayerPositionsAfterLayout();
915c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
9165d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    renderView()->compositor()->didLayout();
91753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
9185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_layoutCount++;
9195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
920f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    if (AXObjectCache* cache = rootForThisLayout->document().axObjectCache()) {
921f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        const KURL& url = rootForThisLayout->document().url();
922f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        if (url.isValid() && !url.isAboutBlankURL())
923f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu            cache->handleLayoutComplete(rootForThisLayout);
924f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    }
9255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    updateAnnotatedRegions();
92653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
927d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(!rootForThisLayout->needsLayout());
9285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (document->hasListenerType(Document::OVERFLOWCHANGED_LISTENER))
930bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        updateOverflowStatus(layoutSize().width() < contentsWidth(), layoutSize().height() < contentsHeight());
9315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
932e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    scheduleOrPerformPostLayoutTasks();
9335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
934f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    TRACE_EVENT_END1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Layout", "endData", InspectorLayoutEvent::endData(rootForThisLayout));
935f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeline migrates to tracing.
9367757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    InspectorInstrumentation::didLayout(cookie, rootForThisLayout);
9375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_nestedLayoutCount--;
9395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_nestedLayoutCount)
9405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
9415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
942197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if ENABLE(ASSERT)
943f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)    // Post-layout assert that nobody was re-marked as needing layout during layout.
944d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    document->renderView()->assertSubtreeIsLaidOut();
945f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)#endif
946f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)
9477757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    // FIXME: It should be not possible to remove the FrameView from the frame/page during layout
94809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // however m_inPerformLayout is not set for most of this function, so none of our RELEASE_ASSERTS
949d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // in LocalFrame/Page will fire. One of the post-layout tasks is disconnecting the LocalFrame from
9507757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    // the page in fast/frames/crash-remove-iframe-during-object-beforeload-2.html
9517757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    // necessitating this check here.
9527757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    // ASSERT(frame()->page());
9538abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    if (frame().page())
9548abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        frame().page()->chrome().client().layoutUpdated(m_frame.get());
95553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
95653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
957f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)// The plan is to move to compositor-queried paint invalidation, in which case this
95851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)// method would setNeedsRedraw on the GraphicsLayers with invalidations and
95951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)// let the compositor pick which to actually draw.
96051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)// See http://crbug.com/306706
961197021e6b966cfb06891637935ef33fff06433d1Ben Murdochvoid FrameView::invalidateTreeIfNeeded()
96251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
9637242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ASSERT(renderView());
9649e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    RenderView& rootForPaintInvalidation = *renderView();
9659e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    ASSERT(!rootForPaintInvalidation.needsLayout());
966aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch
9679e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    TRACE_EVENT1("blink", "FrameView::invalidateTree", "root", rootForPaintInvalidation.debugName().ascii());
96851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
9699e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    PaintInvalidationState rootPaintInvalidationState(rootForPaintInvalidation);
97007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
971a372c30a9dc26aa32e51fa7b85e0c47b55479f89Ben Murdoch    if (m_doFullPaintInvalidation)
972a372c30a9dc26aa32e51fa7b85e0c47b55479f89Ben Murdoch        renderView()->compositor()->fullyInvalidatePaint();
973a372c30a9dc26aa32e51fa7b85e0c47b55479f89Ben Murdoch
9749e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    rootForPaintInvalidation.invalidateTreeIfNeeded(rootPaintInvalidationState);
97509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
976f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // Invalidate the paint of the frameviews scrollbars if needed
97709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (hasVerticalBarDamage())
97809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        invalidateRect(verticalBarDamage());
97909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (hasHorizontalBarDamage())
98009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        invalidateRect(horizontalBarDamage());
98109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    resetScrollbarDamage();
982197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
983a372c30a9dc26aa32e51fa7b85e0c47b55479f89Ben Murdoch
984c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#ifndef NDEBUG
985c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    renderView()->assertSubtreeClearedPaintInvalidationState();
986c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#endif
987e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
988e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    if (m_frame->selection().isCaretBoundsDirty())
989e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        m_frame->selection().invalidateCaretRect();
99009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
99109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
99209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)DocumentLifecycle& FrameView::lifecycle() const
99309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
99409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return m_frame->document()->lifecycle();
995a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)}
996a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
997a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)void FrameView::gatherDebugLayoutRects(RenderObject* layoutRoot)
998a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){
999a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    bool isTracing;
1000a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("blink.debug.layout"), &isTracing);
1001a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    if (!isTracing)
1002a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        return;
1003a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    if (!layoutRoot->enclosingLayer()->hasCompositedLayerMapping())
1004a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        return;
1005197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // For access to compositedLayerMapping().
1006197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    DisableCompositingQueryAsserts disabler;
1007a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    GraphicsLayer* graphicsLayer = layoutRoot->enclosingLayer()->compositedLayerMapping()->mainGraphicsLayer();
1008a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    if (!graphicsLayer)
1009a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        return;
1010a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
101109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    GraphicsLayerDebugInfo& debugInfo = graphicsLayer->debugInfo();
101209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
101309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    debugInfo.currentLayoutRects().clear();
1014a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    for (RenderObject* renderer = layoutRoot; renderer; renderer = renderer->nextInPreOrder()) {
1015a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        if (renderer->layoutDidGetCalled()) {
1016f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)            FloatQuad quad = renderer->localToAbsoluteQuad(FloatQuad(renderer->previousPaintInvalidationRect()));
101709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            LayoutRect rect = quad.enclosingBoundingBox();
101809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            debugInfo.currentLayoutRects().append(rect);
1019a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)            renderer->setLayoutDidGetCalled(false);
1020a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        }
1021a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    }
102251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
102351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
10245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)RenderBox* FrameView::embeddedContentBox() const
10255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1026926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
1027926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!renderView)
10285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
10295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1030926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderObject* firstChild = renderView->firstChild();
1031926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!firstChild || !firstChild->isBox())
10325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
10335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Curently only embedded SVG documents participate in the size-negotiation logic.
1035926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (firstChild->isSVGRoot())
1036926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return toRenderBox(firstChild);
10375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
10395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
10405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
104109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
104209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void FrameView::addWidget(RenderWidget* object)
104309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
104409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_widgets.add(object);
104509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
104609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
104709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void FrameView::removeWidget(RenderWidget* object)
104809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
104909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_widgets.remove(object);
105009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
105109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
105209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void FrameView::updateWidgetPositions()
105309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
1054e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    WillBeHeapVector<RefPtrWillBeMember<RenderWidget> > widgets;
105509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    copyToVector(m_widgets, widgets);
105609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
105709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Script or plugins could detach the frame so abort processing if that happens.
105809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
105909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    for (size_t i = 0; i < widgets.size() && renderView(); ++i)
106009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        widgets[i]->updateWidgetPosition();
106109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
106209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    for (size_t i = 0; i < widgets.size() && renderView(); ++i)
106309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        widgets[i]->widgetPositionsUpdated();
106409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
106509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
1066a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)void FrameView::addWidgetToUpdate(RenderEmbeddedObject& object)
10675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1068d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(isInPerformLayout());
10695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Tell the DOM element that it needs a widget update.
1070a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    Node* node = object.node();
1071d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(node);
1072d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (isHTMLObjectElement(*node) || isHTMLEmbedElement(*node))
1073f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        toHTMLPlugInElement(node)->setNeedsWidgetUpdate(true);
10745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1075a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    m_widgetUpdateSet.add(&object);
10765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
10775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1078591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochvoid FrameView::setMediaType(const AtomicString& mediaType)
10795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
108051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    ASSERT(m_frame->document());
108151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    m_frame->document()->mediaQueryAffectingValueChanged();
10825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_mediaType = mediaType;
10835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
10845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1085591b958dee2cf159d33a0b931e6231072eaf38d5Ben MurdochAtomicString FrameView::mediaType() const
10865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
10875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // See if we have an override type.
108853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    String overrideType;
1089926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    InspectorInstrumentation::applyEmulatedMedia(m_frame.get(), &overrideType);
10905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!overrideType.isNull())
109109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return AtomicString(overrideType);
10925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return m_mediaType;
10935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
10945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::adjustMediaTypeForPrinting(bool printing)
10965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
10975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (printing) {
10985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (m_mediaTypeWhenNotPrinting.isNull())
10995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_mediaTypeWhenNotPrinting = mediaType();
11007242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            setMediaType(MediaTypeNames::print);
11015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } else {
11025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!m_mediaTypeWhenNotPrinting.isNull())
11035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            setMediaType(m_mediaTypeWhenNotPrinting);
1104591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        m_mediaTypeWhenNotPrinting = nullAtom;
11055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
11065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool FrameView::contentsInCompositedLayer() const
11095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1110926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
1111bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (renderView && renderView->compositingState() == PaintsIntoOwnBacking) {
11121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        GraphicsLayer* layer = renderView->layer()->compositedLayerMapping()->mainGraphicsLayer();
11135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (layer && layer->drawsContent())
11145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            return true;
11155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
111653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
11175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
11185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::addSlowRepaintObject()
11215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
11225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_slowRepaintObjectCount++) {
11235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (Page* page = m_frame->page()) {
11245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
11255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                scrollingCoordinator->frameViewHasSlowRepaintObjectsDidChange(this);
11265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
11275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
11285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::removeSlowRepaintObject()
11315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
11325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_slowRepaintObjectCount > 0);
11335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_slowRepaintObjectCount--;
11345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_slowRepaintObjectCount) {
11355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (Page* page = m_frame->page()) {
11365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
11375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                scrollingCoordinator->frameViewHasSlowRepaintObjectsDidChange(this);
11385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
11395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
11405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::addViewportConstrainedObject(RenderObject* object)
11435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
11445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_viewportConstrainedObjects)
11455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_viewportConstrainedObjects = adoptPtr(new ViewportConstrainedObjectSet);
11465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_viewportConstrainedObjects->contains(object)) {
11485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_viewportConstrainedObjects->add(object);
11495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (Page* page = m_frame->page()) {
11515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
11525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                scrollingCoordinator->frameViewFixedObjectsDidChange(this);
11535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
11545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
11555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::removeViewportConstrainedObject(RenderObject* object)
11585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
11595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_viewportConstrainedObjects && m_viewportConstrainedObjects->contains(object)) {
11605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_viewportConstrainedObjects->remove(object);
1161d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
11625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (Page* page = m_frame->page()) {
11635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
11645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                scrollingCoordinator->frameViewFixedObjectsDidChange(this);
11655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
11665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
11675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1169926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)LayoutRect FrameView::viewportConstrainedVisibleContentRect() const
1170926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
1171926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    LayoutRect viewportRect = visibleContentRect();
117253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    // Ignore overhang. No-op when not using rubber banding.
117353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    viewportRect.setLocation(clampScrollPosition(scrollPosition()));
1174926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return viewportRect;
1175926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
1176926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1177d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void FrameView::viewportConstrainedVisibleContentSizeChanged(bool widthChanged, bool heightChanged)
117809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
1179d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    if (!hasViewportConstrainedObjects())
1180d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        return;
1181d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
118209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // If viewport is not enabled, frameRect change will cause layout size change and then layout.
118309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Otherwise, viewport constrained objects need their layout flags set separately to ensure
1184d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // they are positioned correctly. In the virtual-viewport pinch mode frame rect changes wont
1185d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // necessarily cause a layout size change so only take this early-out if we're in old-style
1186d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // pinch.
1187d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    if (m_frame->settings()
1188d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        && !m_frame->settings()->viewportEnabled()
1189d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        && !m_frame->settings()->pinchVirtualViewportEnabled())
119009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return;
119109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
119209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ViewportConstrainedObjectSet::const_iterator end = m_viewportConstrainedObjects->end();
119309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    for (ViewportConstrainedObjectSet::const_iterator it = m_viewportConstrainedObjects->begin(); it != end; ++it) {
119409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        RenderObject* renderer = *it;
119509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        RenderStyle* style = renderer->style();
119609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (widthChanged) {
119709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            if (style->width().isFixed() && (style->left().isAuto() || style->right().isAuto()))
119809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                renderer->setNeedsPositionedMovementLayout();
119909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            else
12005d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)                renderer->setNeedsLayoutAndFullPaintInvalidation();
120109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
120209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (heightChanged) {
120309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            if (style->height().isFixed() && (style->top().isAuto() || style->bottom().isAuto()))
120409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                renderer->setNeedsPositionedMovementLayout();
120509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            else
12065d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)                renderer->setNeedsLayoutAndFullPaintInvalidation();
120709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
120809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
120909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
1210926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
12115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)IntSize FrameView::scrollOffsetForFixedPosition() const
12125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
121353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    return toIntSize(clampScrollPosition(scrollPosition()));
12145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
12155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1216926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)IntPoint FrameView::lastKnownMousePosition() const
12175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1218f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    return m_frame->eventHandler().lastKnownMousePosition();
12195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
12205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
12211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)bool FrameView::shouldSetCursor() const
12221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
12231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    Page* page = frame().page();
122410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    return page && page->visibilityState() != PageVisibilityStateHidden && page->focusController().isActive() && page->settings().deviceSupportsMouse();
12251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
12261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
122707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochvoid FrameView::scrollContentsIfNeededRecursive()
122807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch{
122907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    scrollContentsIfNeeded();
123007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
12315d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    for (Frame* child = m_frame->tree().firstChild(); child; child = child->tree().nextSibling()) {
12325d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        if (!child->isLocalFrame())
12335d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            continue;
12345d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        if (FrameView* view = toLocalFrame(child)->view())
123507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            view->scrollContentsIfNeededRecursive();
123607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    }
123707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch}
123807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
1239018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdochvoid FrameView::scrollContentsIfNeeded()
124007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch{
1241018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    bool didScroll = !pendingScrollDelta().isZero();
1242018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    ScrollView::scrollContentsIfNeeded();
1243018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    if (didScroll)
1244018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        updateFixedElementPaintInvalidationRectsAfterScroll();
1245018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch}
12467242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
1247018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdochstatic LayoutRect paintInvalidationRectIncludingNonCompositingDescendants(const RenderLayer* layer)
1248018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch{
1249018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    LayoutRect paintInvalidationRect = layer->renderer()->previousPaintInvalidationRect();
1250018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1251018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    for (const RenderLayer* child = layer->firstChild(); child; child = child->nextSibling()) {
12527242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        // Don't include paint invalidation rects for composited child layers; they will paint themselves and have a different origin.
1253018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        if (child->compositingState() == PaintsIntoOwnBacking || child->compositingState() == PaintsIntoGroupedBacking)
12547242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            continue;
12557242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
1256018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        paintInvalidationRect.unite(paintInvalidationRectIncludingNonCompositingDescendants(child));
12577242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    }
1258018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    return paintInvalidationRect;
125907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch}
126007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
12619e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)bool FrameView::scrollContentsFastPath(const IntSize& scrollDelta)
12625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1263e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    if (!contentsInCompositedLayer() || hasSlowRepaintObjects())
1264e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        return false;
1265197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
12665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_viewportConstrainedObjects || m_viewportConstrainedObjects->isEmpty()) {
12677242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        InspectorInstrumentation::didScroll(page());
12685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return true;
12695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
12705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1271018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    Region regionToUpdate;
12725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ViewportConstrainedObjectSet::const_iterator end = m_viewportConstrainedObjects->end();
12735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    for (ViewportConstrainedObjectSet::const_iterator it = m_viewportConstrainedObjects->begin(); it != end; ++it) {
12745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        RenderObject* renderer = *it;
127507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        ASSERT(renderer->style()->hasViewportConstrainedPosition());
12765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        ASSERT(renderer->hasLayer());
12775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        RenderLayer* layer = toRenderBoxModelObject(renderer)->layer();
127853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
1279018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        CompositingState state = layer->compositingState();
1280018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        if (state == PaintsIntoOwnBacking || state == PaintsIntoGroupedBacking)
12819e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)            continue;
12829e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)
12839e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        if (layer->subtreeIsInvisible())
12849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)            continue;
12859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)
12869e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        // If the fixed layer has a blur/drop-shadow filter applied on at least one of its parents, we cannot
12879e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        // scroll using the fast path, otherwise the outsets of the filter will be moved around the page.
12889e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        if (layer->hasAncestorWithFilterOutsets())
12895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            return false;
12909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)
1291018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        IntRect updateRect = pixelSnappedIntRect(paintInvalidationRectIncludingNonCompositingDescendants(layer));
1292018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1293018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        const RenderLayerModelObject* repaintContainer = layer->renderer()->containerForPaintInvalidation();
1294018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        if (repaintContainer && !repaintContainer->isRenderView()) {
1295018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            // Invalidate the old and new locations of fixed position elements that are not drawn into the RenderView.
1296018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            updateRect.moveBy(scrollPosition());
1297018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            IntRect previousRect = updateRect;
1298018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            previousRect.move(scrollDelta);
1299018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            // FIXME: Rather than uniting the rects, we should just issue both invalidations.
1300018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            updateRect.unite(previousRect);
1301018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            layer->renderer()->invalidatePaintUsingContainer(repaintContainer, updateRect, InvalidationScroll);
1302018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        } else {
1303018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            // Coalesce the paint invalidations that will be issued to the renderView.
1304018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            updateRect = contentsToRootView(updateRect);
1305018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            if (!updateRect.isEmpty())
1306018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch                regionToUpdate.unite(updateRect);
1307018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        }
13085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
13095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13107242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    InspectorInstrumentation::didScroll(page());
1311018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1312018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    // Invalidate the old and new locations of fixed position elements that are drawn into the RenderView.
1313018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    Vector<IntRect> subRectsToUpdate = regionToUpdate.rects();
1314018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    size_t viewportConstrainedObjectsCount = subRectsToUpdate.size();
1315018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    for (size_t i = 0; i < viewportConstrainedObjectsCount; ++i) {
1316018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        IntRect updateRect = subRectsToUpdate[i];
1317018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        IntRect scrolledRect = updateRect;
1318018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        scrolledRect.move(-scrollDelta);
1319018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        updateRect.unite(scrolledRect);
1320018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        // FIXME: We should be able to issue these invalidations separately and before we actually scroll.
1321018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        renderView()->setBackingNeedsPaintInvalidationInRect(rootViewToContents(updateRect));
1322018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    }
1323018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
13245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
13255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
13265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::scrollContentsSlowPath(const IntRect& updateRect)
13285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
13295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (contentsInCompositedLayer()) {
13305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        IntRect updateRect = visibleContentRect();
1331926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        ASSERT(renderView());
13327242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        renderView()->invalidatePaintRectangle(updateRect);
13335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
13345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (RenderPart* frameRenderer = m_frame->ownerRenderer()) {
13355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (isEnclosedInCompositingLayer()) {
13365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutRect rect(frameRenderer->borderLeft() + frameRenderer->paddingLeft(),
13375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            frameRenderer->borderTop() + frameRenderer->paddingTop(),
13385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            visibleWidth(), visibleHeight());
13395d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            frameRenderer->invalidatePaintRectangle(rect);
13405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            return;
13415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
13425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
13435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollView::scrollContentsSlowPath(updateRect);
13455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
13465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::restoreScrollbar()
13485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
13495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    setScrollbarsSuppressed(false);
13505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
13515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool FrameView::scrollToFragment(const KURL& url)
13535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
13545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // If our URL has no ref, then we have no place we need to jump to.
13555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // OTOH If CSS target was set previously, we want to set it to 0, recalc
1356f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // and possibly paint invalidation because :target pseudo class may have been
13575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // set (see bug 11321).
13585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!url.hasFragmentIdentifier() && !m_frame->document()->cssTarget())
13595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
13605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    String fragmentIdentifier = url.fragmentIdentifier();
13625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (scrollToAnchor(fragmentIdentifier))
13635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return true;
13645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Try again after decoding the ref, based on the document's encoding.
1366c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)    if (m_frame->document()->encoding().isValid())
1367c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        return scrollToAnchor(decodeURLEscapeSequences(fragmentIdentifier, m_frame->document()->encoding()));
13685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
13705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
13715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool FrameView::scrollToAnchor(const String& name)
13735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
13745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_frame->document());
13755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1376a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    if (!m_frame->document()->isRenderingReady()) {
13775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(true);
13785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
13795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
13805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(false);
13825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Element* anchorNode = m_frame->document()->findAnchor(name);
13845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Setting to null will clear the current target.
13865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_frame->document()->setCSSTarget(anchorNode);
13875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_frame->document()->isSVGDocument()) {
1389323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        if (SVGSVGElement* svg = SVGDocumentExtensions::rootElement(*m_frame->document())) {
13905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            svg->setupInitialView(name, anchorNode);
13915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (!anchorNode)
13925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                return true;
13935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
13945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1395591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
13965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Implement the rule that "" and "top" both mean top of page as in other browsers.
13975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!anchorNode && !(name.isEmpty() || equalIgnoringCase(name, "top")))
13985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
13995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
14005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    maintainScrollPositionAtAnchor(anchorNode ? static_cast<Node*>(anchorNode) : m_frame->document());
140153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
140253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    // If the anchor accepts keyboard focus, move focus there to aid users relying on keyboard navigation.
1403f542a0e9557608d421c9d165487573efa35a5f91Ben Murdoch    // If anchorNode is not focusable, setFocusedElement() will still clear focus, which matches the behavior of other browsers.
1404f542a0e9557608d421c9d165487573efa35a5f91Ben Murdoch    if (anchorNode)
1405e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        m_frame->document()->setFocusedElement(anchorNode);
140653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
14075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
14085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
14095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
14105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::maintainScrollPositionAtAnchor(Node* anchorNode)
14115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
14125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_maintainScrollPositionAnchor = anchorNode;
14135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_maintainScrollPositionAnchor)
14145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
14155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
14165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // We need to update the layout before scrolling, otherwise we could
14175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // really mess things up if an anchor scroll comes at a bad moment.
141807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    m_frame->document()->updateRenderTreeIfNeeded();
14195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Only do a layout if changes have occurred that make it necessary.
1420926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
1421926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (renderView && renderView->needsLayout())
14225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        layout();
14235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
14245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        scrollToAnchor();
14255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
14265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
14275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::scrollElementToRect(Element* element, const IntRect& rect)
14285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1429d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // FIXME(http://crbug.com/371896) - This method shouldn't be manually doing
1430d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // coordinate transformations to the PinchViewport.
1431d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    IntRect targetRect(rect);
1432d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
14335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_frame->document()->updateLayoutIgnorePendingStylesheets();
14345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1435d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    bool pinchVirtualViewportEnabled = m_frame->settings()->pinchVirtualViewportEnabled();
1436d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
1437d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    if (pinchVirtualViewportEnabled) {
1438d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        PinchViewport& pinchViewport = m_frame->page()->frameHost().pinchViewport();
1439d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
1440d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        IntSize pinchViewportSize = expandedIntSize(pinchViewport.visibleRect().size());
1441d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        targetRect.moveBy(ceiledIntPoint(pinchViewport.visibleRect().location()));
1442d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        targetRect.setSize(pinchViewportSize.shrunkTo(targetRect.size()));
1443d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    }
1444d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
14455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutRect bounds = element->boundingBox();
1446d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    int centeringOffsetX = (targetRect.width() - bounds.width()) / 2;
1447d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    int centeringOffsetY = (targetRect.height() - bounds.height()) / 2;
1448d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
1449d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    IntPoint targetOffset(
1450d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        bounds.x() - centeringOffsetX - targetRect.x(),
1451d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        bounds.y() - centeringOffsetY - targetRect.y());
1452d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
1453d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    setScrollPosition(targetOffset);
1454d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
1455d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    if (pinchVirtualViewportEnabled) {
1456d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        IntPoint remainder = IntPoint(targetOffset - scrollPosition());
1457d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        m_frame->page()->frameHost().pinchViewport().move(remainder);
1458d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    }
14595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
14605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1461c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)void FrameView::setScrollPosition(const IntPoint& scrollPoint, ScrollBehavior scrollBehavior)
14625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1463c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    cancelProgrammaticScrollAnimation();
14645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    TemporaryChange<bool> changeInProgrammaticScroll(m_inProgrammaticScroll, true);
1465d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    m_maintainScrollPositionAnchor = nullptr;
14665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1467926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint);
1468926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1469926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (newScrollPosition == scrollPosition())
1470926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return;
1471926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1472c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    if (scrollBehavior == ScrollBehaviorAuto) {
1473c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        RenderObject* renderer = m_frame->document()->documentElement() ? m_frame->document()->documentElement()->renderer() : 0;
1474c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        if (renderer)
1475c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)            scrollBehavior = renderer->style()->scrollBehavior();
1476c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        else
1477c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)            scrollBehavior = ScrollBehaviorInstant;
1478c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    }
1479c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    ScrollView::setScrollPosition(newScrollPosition, scrollBehavior);
14805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
14815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
14825267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)void FrameView::setScrollPositionNonProgrammatically(const IntPoint& scrollPoint)
14835267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles){
14845267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint);
14855267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
14865267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    if (newScrollPosition == scrollPosition())
14875267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        return;
14885267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
14895267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    TemporaryChange<bool> changeInProgrammaticScroll(m_inProgrammaticScroll, false);
14905267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    notifyScrollPositionChanged(newScrollPosition);
14915267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)}
14925267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1493bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)IntSize FrameView::layoutSize(IncludeScrollbarsInRect scrollbarInclusion) const
1494bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){
1495bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return scrollbarInclusion == ExcludeScrollbars ? excludeScrollbars(m_layoutSize) : m_layoutSize;
1496bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)}
1497bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
1498bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)void FrameView::setLayoutSize(const IntSize& size)
1499bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){
1500bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    ASSERT(!layoutSizeFixedToFrameSize());
1501bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
1502bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    setLayoutSizeInternal(size);
1503bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)}
15045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
15055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::scrollPositionChanged()
15065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
150709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    setWasScrolledByUser(true);
150809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
150909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    Document* document = m_frame->document();
151009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    document->enqueueScrollEventForNode(document);
151109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
1512f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    m_frame->eventHandler().dispatchFakeMouseMoveEventSoon();
15135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
151409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (RenderView* renderView = document->renderView()) {
151507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        if (renderView->usesCompositing())
1516926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            renderView->compositor()->frameViewDidScroll();
15175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1518a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
151909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (m_didScrollTimer.isActive())
152009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_didScrollTimer.stop();
1521d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    m_didScrollTimer.startOneShot(resourcePriorityUpdateDelayAfterScroll, FROM_HERE);
1522d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
1523d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (AXObjectCache* cache = m_frame->document()->existingAXObjectCache())
1524d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        cache->handleScrollPositionChanged(this);
1525d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
1526d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    frame().loader().saveScrollState();
152709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
152809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
152909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void FrameView::didScrollTimerFired(Timer<FrameView>*)
153009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
1531d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    if (m_frame->document() && m_frame->document()->renderView()) {
153209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->updateAllImageResourcePriorities();
1533a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    }
15345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
15355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
153607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochvoid FrameView::updateLayersAndCompositingAfterScrollIfNeeded()
15375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
153807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    // Nothing to do after scrolling if there are no fixed position elements.
153907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    if (!hasViewportConstrainedObjects())
154007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        return;
154107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
154209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    RefPtr<FrameView> protect(this);
154307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
154407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    // If there fixed position elements, scrolling may cause compositing layers to change.
154507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    // Update widget and layer positions after scrolling, but only if we're not inside of
154607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    // layout.
154707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    if (!m_nestedLayoutCount) {
154809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        updateWidgetPositions();
1549197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        if (RenderView* renderView = this->renderView())
15505d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            renderView->layer()->setNeedsCompositingInputsUpdate();
15515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
15525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
15535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
15547242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccibool FrameView::computeCompositedSelectionBounds(LocalFrame& frame, CompositedSelectionBound& start, CompositedSelectionBound& end)
15555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
15567242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    const VisibleSelection &selection = frame.selection().selection();
15577242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (!selection.isCaretOrRange())
15587242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        return false;
155907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
15607242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    VisiblePosition visibleStart(selection.visibleStart());
15617242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    VisiblePosition visibleEnd(selection.visibleEnd());
156207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
15637242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    RenderedPosition renderedStart(visibleStart);
15647242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    RenderedPosition renderedEnd(visibleEnd);
156507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
15667242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    renderedStart.positionInGraphicsLayerBacking(start);
15672fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)    if (!start.layer)
15682fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)        return false;
15692fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)
15707242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    renderedEnd.positionInGraphicsLayerBacking(end);
15712fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)    if (!end.layer)
15722fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)        return false;
157307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
15747242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (selection.isCaret()) {
15757242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        start.type = end.type = CompositedSelectionBound::Caret;
15767242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        return true;
15775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
15787242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
15797242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    TextDirection startDir = visibleStart.deepEquivalent().primaryDirection();
15807242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    TextDirection endDir = visibleEnd.deepEquivalent().primaryDirection();
15817242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    start.type = startDir == RTL ? CompositedSelectionBound::SelectionRight : CompositedSelectionBound::SelectionLeft;
15827242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    end.type = endDir == RTL ? CompositedSelectionBound::SelectionLeft : CompositedSelectionBound::SelectionRight;
15837242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    return true;
15845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
15855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1586018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdochstatic void computePaintInvalidationRectsIncludingNonCompositingDescendants(RenderLayer* layer)
1587018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch{
1588018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    // FIXME: boundsRectForPaintInvalidation() has to walk up the parent chain
1589018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    // for every layer to compute the rects. We should make this more efficient.
1590018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    // FIXME: it's wrong to call this when layout is not up-to-date, which we do.
1591018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    layer->renderer()->setPreviousPaintInvalidationRect(layer->renderer()->boundsRectForPaintInvalidation(layer->renderer()->containerForPaintInvalidation()));
1592018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    // FIXME: We are only updating the paint invalidation bounds but not
1593018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    // the positionFromPaintInvalidationContainer. This means that we may
1594018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    // forcing a full invaliation of the new position. Is this really correct?
1595018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1596018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    for (RenderLayer* child = layer->firstChild(); child; child = child->nextSibling()) {
1597018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        if (child->compositingState() != PaintsIntoOwnBacking && child->compositingState() != PaintsIntoGroupedBacking)
1598018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            computePaintInvalidationRectsIncludingNonCompositingDescendants(child);
1599018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    }
1600018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch}
1601018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1602018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdochvoid FrameView::updateFixedElementPaintInvalidationRectsAfterScroll()
1603018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch{
1604018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    if (!hasViewportConstrainedObjects())
1605018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        return;
1606018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1607018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    // Update the paint invalidation rects for fixed elements after scrolling and invalidation to reflect
1608018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    // the new scroll position.
1609018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    ViewportConstrainedObjectSet::const_iterator end = m_viewportConstrainedObjects->end();
1610018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    for (ViewportConstrainedObjectSet::const_iterator it = m_viewportConstrainedObjects->begin(); it != end; ++it) {
1611018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        RenderObject* renderer = *it;
1612018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        // m_viewportConstrainedObjects should not contain non-viewport constrained objects.
1613018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        ASSERT(renderer->style()->hasViewportConstrainedPosition());
1614018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1615018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        // Fixed items should always have layers.
1616018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        ASSERT(renderer->hasLayer());
1617018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1618018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        RenderLayer* layer = toRenderBoxModelObject(renderer)->layer();
1619018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1620018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        // Don't need to do this for composited fixed items.
1621018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        if (layer->compositingState() == PaintsIntoOwnBacking)
1622018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch            continue;
1623018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1624018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch        computePaintInvalidationRectsIncludingNonCompositingDescendants(layer);
1625018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch    }
1626018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch}
1627018c2aa55614eda57c6617f8d0747eacefc389a3Ben Murdoch
1628197021e6b966cfb06891637935ef33fff06433d1Ben Murdochvoid FrameView::updateCompositedSelectionBoundsIfNeeded()
1629197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{
16307242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (!RuntimeEnabledFeatures::compositedSelectionUpdateEnabled())
1631197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return;
1632197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
1633197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    Page* page = frame().page();
1634197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    ASSERT(page);
1635197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
16367242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    CompositedSelectionBound start, end;
1637197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    LocalFrame* frame = toLocalFrame(page->focusController().focusedOrMainFrame());
16387242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (!frame || !computeCompositedSelectionBounds(*frame, start, end)) {
1639197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        page->chrome().client().clearCompositedSelectionBounds();
1640197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return;
1641197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    }
1642197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
16437242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    page->chrome().client().updateCompositedSelectionBounds(start, end);
1644197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch}
1645197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
1646926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)bool FrameView::isRubberBandInProgress() const
1647926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
1648926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (scrollbarsSuppressed())
1649926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return false;
1650926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1651926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // If the main thread updates the scroll position for this FrameView, we should return
1652926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // ScrollAnimator::isRubberBandInProgress().
1653926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
1654926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return scrollAnimator->isRubberBandInProgress();
1655926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1656926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return false;
1657926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
1658926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
16595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)HostWindow* FrameView::hostWindow() const
16605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
16618abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    Page* page = frame().page();
16625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!page)
16635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
166493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    return &page->chrome();
16655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
16665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1667f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)void FrameView::contentRectangleForPaintInvalidation(const IntRect& r)
16685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1669f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    ASSERT(paintInvalidationIsAllowed());
16709e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    ASSERT(!m_frame->ownerRenderer());
16715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1672f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    if (m_isTrackingPaintInvalidations) {
1673f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        IntRect paintInvalidationRect = r;
1674f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        paintInvalidationRect.move(-scrollOffset());
1675f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        m_trackedPaintInvalidationRects.append(paintInvalidationRect);
1676f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        // FIXME: http://crbug.com/368518. Eventually, invalidateContentRectangleForPaint
1677323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        // is going away entirely once all layout tests are FCM. In the short
1678f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        // term, no code should be tracking non-composited FrameView paint invalidations.
1679323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        RELEASE_ASSERT_NOT_REACHED();
16805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
16815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1682f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    ScrollView::contentRectangleForPaintInvalidation(r);
16835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
16845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
16855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::contentsResized()
16865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
168710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (m_frame->isMainFrame() && m_frame->document()) {
1688c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        if (TextAutosizer* textAutosizer = m_frame->document()->textAutosizer())
1689aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch            textAutosizer->updatePageInfoInAllFrames();
1690aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    }
1691aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch
16925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollView::contentsResized();
16936f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    setNeedsLayout();
16945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
16955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1696bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)void FrameView::scrollbarExistenceDidChange()
16975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
16985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // We check to make sure the view is attached to a frame() as this method can
1699d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // be triggered before the view is attached by LocalFrame::createView(...) setting
17005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // various values such as setScrollBarModes(...) for example.  An ASSERT is
17015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // triggered when a view is layout before being attached to a frame().
17028abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    if (!frame().view())
17035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
17045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
170509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Note that simply having overlay scrollbars is not sufficient to be
170609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // certain that scrollbars' presence does not impact layout. This should
170709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // also check if custom scrollbars (as reported by shouldUseCustomScrollbars)
170809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // are in use as well.
170909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // http://crbug.com/269692
1710bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    bool useOverlayScrollbars = ScrollbarTheme::theme()->usesOverlayScrollbars();
1711bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
1712a372c30a9dc26aa32e51fa7b85e0c47b55479f89Ben Murdoch    // FIXME: this call to layout() could be called within FrameView::layout(), but before performLayout(),
1713a372c30a9dc26aa32e51fa7b85e0c47b55479f89Ben Murdoch    // causing double-layout. See also crbug.com/429242.
1714bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (!useOverlayScrollbars && needsLayout())
17155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        layout();
17165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1717bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (renderView() && renderView()->usesCompositing()) {
1718bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        renderView()->compositor()->frameViewScrollbarsExistenceDidChange();
1719bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
1720bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        if (!useOverlayScrollbars)
1721bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)            renderView()->compositor()->frameViewDidChangeSize();
17225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
17235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
17245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
17255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::handleLoadCompleted()
17265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
17275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Once loading has completed, allow autoSize one last opportunity to
17285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // reduce the size of the frame.
17299e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    if (m_autoSizeInfo)
17309e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        m_autoSizeInfo->autoSizeIfNeeded();
17315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
17325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
17335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::scheduleRelayout()
17345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
17355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_frame->view() == this);
17365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
173709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (isSubtreeLayout()) {
173809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_layoutSubtreeRoot->markContainingBlocksForLayout(false);
173909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_layoutSubtreeRoot = 0;
17405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
17415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_layoutSchedulingEnabled)
17425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
17435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!needsLayout())
17445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
17455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_frame->document()->shouldScheduleLayout())
17465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
1747f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "InvalidateLayout", "frame", m_frame.get());
1748323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "CallStack", "stack", InspectorCallStackEvent::currentCallStack());
1749f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeline migrates to tracing.
17505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    InspectorInstrumentation::didInvalidateLayout(m_frame.get());
175193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
175209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (m_hasPendingLayout)
17535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
175409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_hasPendingLayout = true;
17556f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch
1756d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    page()->animator().scheduleVisualUpdate();
17576f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    lifecycle().ensureStateAtMost(DocumentLifecycle::StyleClean);
17585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
17595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
17605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static bool isObjectAncestorContainerOf(RenderObject* ancestor, RenderObject* descendant)
17615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
17625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    for (RenderObject* r = descendant; r; r = r->container()) {
17635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (r == ancestor)
17645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            return true;
17655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
17665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
17675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
17685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
17695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::scheduleRelayoutOfSubtree(RenderObject* relayoutRoot)
17705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
17715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_frame->view() == this);
17725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
17736f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    // FIXME: Should this call shouldScheduleLayout instead?
17746f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    if (!m_frame->document()->isActive())
17756f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch        return;
17766f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch
1777926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
1778926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (renderView && renderView->needsLayout()) {
17795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (relayoutRoot)
17805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            relayoutRoot->markContainingBlocksForLayout(false);
17815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
17825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
17835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
17845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (layoutPending() || !m_layoutSchedulingEnabled) {
178509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (m_layoutSubtreeRoot != relayoutRoot) {
178609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            if (isObjectAncestorContainerOf(m_layoutSubtreeRoot, relayoutRoot)) {
17875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // Keep the current root
178809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                relayoutRoot->markContainingBlocksForLayout(false, m_layoutSubtreeRoot);
178909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                ASSERT(!m_layoutSubtreeRoot->container() || !m_layoutSubtreeRoot->container()->needsLayout());
179009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            } else if (isSubtreeLayout() && isObjectAncestorContainerOf(relayoutRoot, m_layoutSubtreeRoot)) {
17915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // Re-root at relayoutRoot
179209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                m_layoutSubtreeRoot->markContainingBlocksForLayout(false, relayoutRoot);
179309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                m_layoutSubtreeRoot = relayoutRoot;
179409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                ASSERT(!m_layoutSubtreeRoot->container() || !m_layoutSubtreeRoot->container()->needsLayout());
17955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            } else {
17965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // Just do a full relayout
179709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                if (isSubtreeLayout())
179809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    m_layoutSubtreeRoot->markContainingBlocksForLayout(false);
179909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                m_layoutSubtreeRoot = 0;
18005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                relayoutRoot->markContainingBlocksForLayout(false);
18015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
18025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
18035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } else if (m_layoutSchedulingEnabled) {
180409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_layoutSubtreeRoot = relayoutRoot;
180509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        ASSERT(!m_layoutSubtreeRoot->container() || !m_layoutSubtreeRoot->container()->needsLayout());
180609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_hasPendingLayout = true;
18076f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch
1808d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        page()->animator().scheduleVisualUpdate();
18096f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch        lifecycle().ensureStateAtMost(DocumentLifecycle::StyleClean);
18105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1811f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "InvalidateLayout", "frame", m_frame.get());
1812323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "CallStack", "stack", InspectorCallStackEvent::currentCallStack());
1813f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeline migrates to tracing.
1814f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    InspectorInstrumentation::didInvalidateLayout(m_frame.get());
18155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
18165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
18175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool FrameView::layoutPending() const
18185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1819a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    // FIXME: This should check Document::lifecycle instead.
182009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return m_hasPendingLayout;
182109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
182209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
182309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)bool FrameView::isInPerformLayout() const
182409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
182509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ASSERT(m_inPerformLayout == (lifecycle().state() == DocumentLifecycle::InPerformLayout));
182609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return m_inPerformLayout;
18275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
18285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
18295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool FrameView::needsLayout() const
18305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
18315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // This can return true in cases where the document does not have a body yet.
18325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Document::shouldScheduleLayout takes care of preventing us from scheduling
18335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // layout in that case.
18345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1835926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    RenderView* renderView = this->renderView();
18365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return layoutPending()
1837926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        || (renderView && renderView->needsLayout())
183809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        || isSubtreeLayout();
18395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
18405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
18415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::setNeedsLayout()
18425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1843926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (RenderView* renderView = this->renderView())
18443c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        renderView->setNeedsLayout();
18455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
18465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
18475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool FrameView::isTransparent() const
18485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
18495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return m_isTransparent;
18505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
18515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
18525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::setTransparent(bool isTransparent)
18535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
18545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_isTransparent = isTransparent;
1855d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    DisableCompositingQueryAsserts disabler;
185651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    if (renderView() && renderView()->layer()->hasCompositedLayerMapping())
18571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        renderView()->layer()->compositedLayerMapping()->updateContentsOpaque();
18585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
18595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1860926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)bool FrameView::hasOpaqueBackground() const
1861926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
1862926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return !m_isTransparent && !m_baseBackgroundColor.hasAlpha();
1863926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
1864926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
18655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)Color FrameView::baseBackgroundColor() const
18665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
18675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return m_baseBackgroundColor;
18685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
18695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
18708abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)void FrameView::setBaseBackgroundColor(const Color& backgroundColor)
18715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
187209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_baseBackgroundColor = backgroundColor;
18735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
187451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    if (renderView() && renderView()->layer()->hasCompositedLayerMapping()) {
1875e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        CompositedLayerMapping* compositedLayerMapping = renderView()->layer()->compositedLayerMapping();
18761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        compositedLayerMapping->updateContentsOpaque();
18771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (compositedLayerMapping->mainGraphicsLayer())
18781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            compositedLayerMapping->mainGraphicsLayer()->setNeedsDisplay();
187902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch    }
18805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    recalculateScrollbarOverlayStyle();
18815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
18825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
18838abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)void FrameView::updateBackgroundRecursively(const Color& backgroundColor, bool transparent)
18845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
18855d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    for (Frame* frame = m_frame.get(); frame; frame = frame->tree().traverseNext(m_frame.get())) {
18865d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        if (!frame->isLocalFrame())
18875d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            continue;
18885d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        if (FrameView* view = toLocalFrame(frame)->view()) {
18895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            view->setTransparent(transparent);
18905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            view->setBaseBackgroundColor(backgroundColor);
18915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
18925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
18935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
18945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
18955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::scrollToAnchor()
18965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1897f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    RefPtrWillBeRawPtr<Node> anchorNode = m_maintainScrollPositionAnchor;
18985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!anchorNode)
18995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
19005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
19015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!anchorNode->renderer())
19025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
19035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
19045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutRect rect;
19055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (anchorNode != m_frame->document())
19065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        rect = anchorNode->boundingBox();
19075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
19082fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)    RefPtrWillBeRawPtr<LocalFrame> boundaryFrame = m_frame->document()->findUnsafeParentScrollPropagationBoundary();
19092fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)
19102fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)    if (boundaryFrame)
19112fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)        boundaryFrame->view()->setSafeToPropagateScrollToParent(false);
19122fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)
19135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Scroll nested layers and frames to reveal the anchor.
19145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Align to the top and to the closest side (this matches other browsers).
19155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    anchorNode->renderer()->scrollRectToVisible(rect, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignTopAlways);
19165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
19172fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)    if (boundaryFrame)
19182fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)        boundaryFrame->view()->setSafeToPropagateScrollToParent(true);
19192fb29a03d7c71253319f61b77edc6c1e3a8fc8e2Torne (Richard Coles)
1920926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (AXObjectCache* cache = m_frame->document()->existingAXObjectCache())
1921926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        cache->handleScrolledToAnchor(anchorNode.get());
19225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
19235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // scrollRectToVisible can call into setScrollPosition(), which resets m_maintainScrollPositionAnchor.
19245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_maintainScrollPositionAnchor = anchorNode;
19255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
19265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
19275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool FrameView::updateWidgets()
19285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1929d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // This is always called from updateWidgetsTimerFired.
1930d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // m_updateWidgetsTimer should only be scheduled if we have widgets to update.
1931d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // Thus I believe we can stop checking isEmpty here, and just ASSERT isEmpty:
1932d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(!m_widgetUpdateSet.isEmpty());
1933a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    if (m_nestedLayoutCount > 1 || m_widgetUpdateSet.isEmpty())
19345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return true;
1935591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
1936a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    // Need to swap because script will run inside the below loop and invalidate the iterator.
1937a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    EmbeddedObjectSet objects;
1938a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    objects.swap(m_widgetUpdateSet);
19395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1940a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    for (EmbeddedObjectSet::iterator it = objects.begin(); it != objects.end(); ++it) {
1941a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        RenderEmbeddedObject& object = **it;
1942a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        HTMLPlugInElement* element = toHTMLPlugInElement(object.node());
19435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1944a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        // The object may have already been destroyed (thus node cleared),
1945a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        // but FrameView holds a manual ref, so it won't have been deleted.
1946a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        if (!element)
1947a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)            continue;
19485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1949a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        // No need to update if it's already crashed or known to be missing.
1950a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        if (object.showsUnavailablePluginIndicator())
1951a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)            continue;
19525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1953a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        if (element->needsWidgetUpdate())
1954a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)            element->updateWidget();
1955a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        object.updateWidgetPosition();
1956a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
1957a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        // Prevent plugins from causing infinite updates of themselves.
1958a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        // FIXME: Do we really need to prevent this?
1959a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        m_widgetUpdateSet.remove(&object);
1960926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
1961591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
1962a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    return m_widgetUpdateSet.isEmpty();
19635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
19645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
196551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void FrameView::updateWidgetsTimerFired(Timer<FrameView>*)
19665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1967d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(!isInPerformLayout());
196851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    RefPtr<FrameView> protect(this);
196951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    m_updateWidgetsTimer.stop();
197051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    for (unsigned i = 0; i < maxUpdateWidgetsIterations; ++i) {
197151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        if (updateWidgets())
197251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)            return;
197351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    }
197451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
19755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
197651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void FrameView::flushAnyPendingPostLayoutTasks()
197751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
1978d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(!isInPerformLayout());
197951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    if (m_postLayoutTasksTimer.isActive())
198051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        performPostLayoutTasks();
198151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    if (m_updateWidgetsTimer.isActive())
198251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        updateWidgetsTimerFired(0);
19835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
19845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1985d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void FrameView::scheduleUpdateWidgetsIfNecessary()
1986d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
1987d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(!isInPerformLayout());
1988d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (m_updateWidgetsTimer.isActive() || m_widgetUpdateSet.isEmpty())
1989d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        return;
1990d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    m_updateWidgetsTimer.startOneShot(0, FROM_HERE);
1991d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
1992d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
19935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::performPostLayoutTasks()
19945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1995d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // FIXME: We can reach here, even when the page is not active!
1996d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // http/tests/inspector/elements/html-link-import.html and many other
1997d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // tests hit that case.
1998d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // We should ASSERT(isActive()); or at least return early if we can!
1999d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(!isInPerformLayout()); // Always before or after performLayout(), part of the highest-level layout() call.
2000197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT0("blink", "FrameView::performPostLayoutTasks");
200181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    RefPtr<FrameView> protect(this);
200281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
20035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_postLayoutTasksTimer.stop();
20045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
20058abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    m_frame->selection().setCaretRectNeedsUpdate();
20065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2007d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {
2008d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        // Hits in compositing/overflow/do-not-repaint-if-scrolling-composited-layers.html
2009d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        DisableCompositingQueryAsserts disabler;
2010d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_frame->selection().updateAppearance();
2011d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    }
2012d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
2013d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(m_frame->document());
20145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_nestedLayoutCount <= 1) {
2015d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (m_firstLayoutCallbackPending)
20165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_firstLayoutCallbackPending = false;
20175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
20185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Ensure that we always send this eventually.
2019f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        if (!m_frame->document()->parsing() && m_frame->loader().stateMachine()->committedFirstRealDocumentLoad())
20205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_isVisuallyNonEmpty = true;
20215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
20225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // If the layout was done with pending sheets, we are not in fact visually non-empty yet.
20235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (m_isVisuallyNonEmpty && !m_frame->document()->didLayoutWithPendingStylesheets() && m_firstVisuallyNonEmptyLayoutCallbackPending) {
20245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_firstVisuallyNonEmptyLayoutCallbackPending = false;
20251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            // FIXME: This callback is probably not needed, but is currently used
20261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            // by android for setting the background color.
2027f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)            m_frame->loader().client()->dispatchDidFirstVisuallyNonEmptyLayout();
20285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
20295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
20305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2031d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    FontFaceSet::didLayout(*m_frame->document());
20325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
203309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    updateWidgetPositions();
203409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
203509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Plugins could have torn down the page inside updateWidgetPositions().
203609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!renderView())
203709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return;
203853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
2039d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    scheduleUpdateWidgetsIfNecessary();
20405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
20411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (Page* page = m_frame->page()) {
20425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
204319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)            scrollingCoordinator->notifyLayoutUpdated();
20445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
20455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
20465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    scrollToAnchor();
20475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2048e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    sendResizeEventIfNeeded();
2049e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
2050e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
20517242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccibool FrameView::wasViewportResized()
20527242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{
20537242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ASSERT(m_frame);
20547242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    RenderView* renderView = this->renderView();
20557242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (!renderView)
20567242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        return false;
20577242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    return (layoutSize(IncludeScrollbars) != m_lastViewportSize || renderView->style()->zoom() != m_lastZoomFactor);
20587242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci}
20597242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
2060e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void FrameView::sendResizeEventIfNeeded()
2061e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
2062e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    ASSERT(m_frame);
2063e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
2064e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    RenderView* renderView = this->renderView();
20659bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)    if (!renderView || renderView->document().printing())
2066e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        return;
2067e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
20687242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (!wasViewportResized())
2069e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        return;
2070e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
20717242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    m_lastViewportSize = layoutSize(IncludeScrollbars);
20727242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    m_lastZoomFactor = renderView->style()->zoom();
20737242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
207451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    m_frame->document()->enqueueResizeEvent();
2075e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
207610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (m_frame->isMainFrame())
20771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        InspectorInstrumentation::didResizeMainFrame(m_frame->page());
20785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
20795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
20805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::postLayoutTimerFired(Timer<FrameView>*)
20815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
20825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    performPostLayoutTasks();
20835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
20845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
20858abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)void FrameView::updateCounters()
20868abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){
20878abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    RenderView* view = renderView();
20888abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    if (!view->hasRenderCounters())
20898abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        return;
20908abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
20918abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    for (RenderObject* renderer = view; renderer; renderer = renderer->nextInPreOrder()) {
20928abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        if (!renderer->isCounter())
20938abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)            continue;
20948abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
20958abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        toRenderCounter(renderer)->updateCounter();
20968abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    }
20978abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)}
20988abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
20995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow)
21005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
21015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_viewportRenderer)
21025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
2103591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
21045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_overflowStatusDirty) {
21055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_horizontalOverflow = horizontalOverflow;
21065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_verticalOverflow = verticalOverflow;
21075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_overflowStatusDirty = false;
21085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
21095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
2110591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
21115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool horizontalOverflowChanged = (m_horizontalOverflow != horizontalOverflow);
21125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool verticalOverflowChanged = (m_verticalOverflow != verticalOverflow);
2113591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
21145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (horizontalOverflowChanged || verticalOverflowChanged) {
21155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_horizontalOverflow = horizontalOverflow;
21165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_verticalOverflow = verticalOverflow;
2117591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
2118a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch        RefPtrWillBeRawPtr<OverflowEvent> event = OverflowEvent::create(horizontalOverflowChanged, horizontalOverflow, verticalOverflowChanged, verticalOverflow);
21191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        event->setTarget(m_viewportRenderer->node());
212051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        m_frame->document()->enqueueAnimationFrameEvent(event.release());
21215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
2122591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
21235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
21245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2125d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)IntRect FrameView::windowClipRect(IncludeScrollbarsInRect scrollbarInclusion) const
21265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
21275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_frame->view() == this);
21285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
21295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Set our clip rect to be our contents.
2130d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    IntRect clipRect = contentsToWindow(visibleContentRect(scrollbarInclusion));
2131f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    if (!m_frame->deprecatedLocalOwner())
21325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return clipRect;
21335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
21345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Take our owner element and get its clip rect.
2135f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // FIXME: Do we need to do this for remote frames?
2136f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    HTMLFrameOwnerElement* ownerElement = m_frame->deprecatedLocalOwner();
21378abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    FrameView* parentView = ownerElement->document().view();
21385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (parentView)
2139d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        clipRect.intersect(parentView->windowClipRectForFrameOwner(ownerElement));
21405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return clipRect;
21415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
21425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2143d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)IntRect FrameView::windowClipRectForFrameOwner(const HTMLFrameOwnerElement* ownerElement) const
21445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
21455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // The renderer can sometimes be null when style="display:none" interacts
21465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // with external content and plugins.
21475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!ownerElement->renderer())
21485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return windowClipRect();
21495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
21505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // If we have no layer, just return our window clip rect.
21515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const RenderLayer* enclosingLayer = ownerElement->renderer()->enclosingLayer();
21525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!enclosingLayer)
21535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return windowClipRect();
21545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2155d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // FIXME: childrenClipRect relies on compositingState, which is not necessarily up to date.
2156d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // https://code.google.com/p/chromium/issues/detail?id=343769
2157d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    DisableCompositingQueryAsserts disabler;
2158d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
21595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Apply the clip from the layer.
2160d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    IntRect clipRect = contentsToWindow(pixelSnappedIntRect(enclosingLayer->clipper().childrenClipRect()));
21615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return intersection(clipRect, windowClipRect());
21625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
21635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
21645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool FrameView::isActive() const
21655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
21668abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    Page* page = frame().page();
21673c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    return page && page->focusController().isActive();
21685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
21695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
21705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::scrollTo(const IntSize& newOffset)
21715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
21725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutSize offset = scrollOffset();
21735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollView::scrollTo(newOffset);
217407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    if (offset != scrollOffset()) {
217507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        updateLayersAndCompositingAfterScrollIfNeeded();
21765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        scrollPositionChanged();
217707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    }
2178f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    frame().loader().client()->didChangeScrollOffset();
21795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
21805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
21815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect)
21825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
21835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Add in our offset within the FrameView.
21845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    IntRect dirtyRect = rect;
21855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    dirtyRect.moveBy(scrollbar->location());
218609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
2187c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    if (isInPerformLayout())
2188c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        addScrollbarDamage(scrollbar, rect);
2189c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    else
219009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        invalidateRect(dirtyRect);
21915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
21925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
21935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const
21945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
219543e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)    if (!m_tickmarks.isEmpty())
219643e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)        tickmarks = m_tickmarks;
219743e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)    else
219843e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)        tickmarks = frame().document()->markers().renderedRectsForMarkers(DocumentMarker::TextMatch);
21995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
22005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
22015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)IntRect FrameView::windowResizerRect() const
22025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
22038abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    Page* page = frame().page();
22045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!page)
22055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return IntRect();
220693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    return page->chrome().windowResizerRect();
22075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
22085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
220953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)void FrameView::setVisibleContentScaleFactor(float visibleContentScaleFactor)
2210926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
221153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    if (m_visibleContentScaleFactor == visibleContentScaleFactor)
221253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        return;
2213926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
221453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    m_visibleContentScaleFactor = visibleContentScaleFactor;
221553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    updateScrollbars(scrollOffset());
2216926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
2217926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
221819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)void FrameView::setInputEventsTransformForEmulation(const IntSize& offset, float contentScaleFactor)
22191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
222019cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)    m_inputEventsOffsetForEmulation = offset;
22211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    m_inputEventsScaleFactorForEmulation = contentScaleFactor;
22221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
22231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
222419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)IntSize FrameView::inputEventsOffsetForEmulation() const
222519cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles){
222619cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)    return m_inputEventsOffsetForEmulation;
222719cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)}
222819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)
22291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)float FrameView::inputEventsScaleFactor() const
2230