Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: third_party/WebKit/Source/core/frame/FrameView.cpp

Issue 1449623002: IntersectionObserver: second cut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: sigbjornf nits Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org> 3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org> 4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Dirk Mueller <mueller@kde.org> 5 * 2000 Dirk Mueller <mueller@kde.org>
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
9 * Copyright (C) 2009 Google Inc. All rights reserved. 9 * Copyright (C) 2009 Google Inc. All rights reserved.
10 * 10 *
(...skipping 14 matching lines...) Expand all
25 */ 25 */
26 26
27 #include "core/frame/FrameView.h" 27 #include "core/frame/FrameView.h"
28 28
29 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
30 #include "core/MediaTypeNames.h" 30 #include "core/MediaTypeNames.h"
31 #include "core/css/FontFaceSet.h" 31 #include "core/css/FontFaceSet.h"
32 #include "core/css/resolver/StyleResolver.h" 32 #include "core/css/resolver/StyleResolver.h"
33 #include "core/dom/AXObjectCache.h" 33 #include "core/dom/AXObjectCache.h"
34 #include "core/dom/Fullscreen.h" 34 #include "core/dom/Fullscreen.h"
35 #include "core/dom/IntersectionObserverController.h"
35 #include "core/editing/EditingUtilities.h" 36 #include "core/editing/EditingUtilities.h"
36 #include "core/editing/FrameSelection.h" 37 #include "core/editing/FrameSelection.h"
37 #include "core/editing/RenderedPosition.h" 38 #include "core/editing/RenderedPosition.h"
38 #include "core/editing/markers/DocumentMarkerController.h" 39 #include "core/editing/markers/DocumentMarkerController.h"
39 #include "core/fetch/ResourceFetcher.h" 40 #include "core/fetch/ResourceFetcher.h"
40 #include "core/frame/FrameHost.h" 41 #include "core/frame/FrameHost.h"
41 #include "core/frame/LocalFrame.h" 42 #include "core/frame/LocalFrame.h"
42 #include "core/frame/Settings.h" 43 #include "core/frame/Settings.h"
43 #include "core/html/HTMLFrameElement.h" 44 #include "core/html/HTMLFrameElement.h"
44 #include "core/html/HTMLPlugInElement.h" 45 #include "core/html/HTMLPlugInElement.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 static bool s_initialTrackAllPaintInvalidations = false; 114 static bool s_initialTrackAllPaintInvalidations = false;
114 115
115 FrameView::FrameView(LocalFrame* frame) 116 FrameView::FrameView(LocalFrame* frame)
116 : m_frame(frame) 117 : m_frame(frame)
117 , m_displayMode(WebDisplayModeBrowser) 118 , m_displayMode(WebDisplayModeBrowser)
118 , m_canHaveScrollbars(true) 119 , m_canHaveScrollbars(true)
119 , m_hasPendingLayout(false) 120 , m_hasPendingLayout(false)
120 , m_inSynchronousPostLayout(false) 121 , m_inSynchronousPostLayout(false)
121 , m_postLayoutTasksTimer(this, &FrameView::postLayoutTimerFired) 122 , m_postLayoutTasksTimer(this, &FrameView::postLayoutTimerFired)
122 , m_updateWidgetsTimer(this, &FrameView::updateWidgetsTimerFired) 123 , m_updateWidgetsTimer(this, &FrameView::updateWidgetsTimerFired)
123 , m_intersectionObserverNotificationFactory(CancellableTaskFactory::create(t his, &FrameView::notifyIntersectionObservers)) 124 , m_renderThrottlingObserverNotificationFactory(CancellableTaskFactory::crea te(this, &FrameView::notifyRenderThrottlingObservers))
124 , m_isTransparent(false) 125 , m_isTransparent(false)
125 , m_baseBackgroundColor(Color::white) 126 , m_baseBackgroundColor(Color::white)
126 , m_mediaType(MediaTypeNames::screen) 127 , m_mediaType(MediaTypeNames::screen)
127 , m_safeToPropagateScrollToParent(true) 128 , m_safeToPropagateScrollToParent(true)
128 , m_isTrackingPaintInvalidations(false) 129 , m_isTrackingPaintInvalidations(false)
129 , m_scrollCorner(nullptr) 130 , m_scrollCorner(nullptr)
130 , m_inputEventsScaleFactorForEmulation(1) 131 , m_inputEventsScaleFactorForEmulation(1)
131 , m_layoutSizeFixedToFrameSize(true) 132 , m_layoutSizeFixedToFrameSize(true)
132 , m_didScrollTimer(this, &FrameView::didScrollTimerFired) 133 , m_didScrollTimer(this, &FrameView::didScrollTimerFired)
133 , m_topControlsViewportAdjustment(0) 134 , m_topControlsViewportAdjustment(0)
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 279
279 // Destroy |m_autoSizeInfo| as early as possible, to avoid dereferencing 280 // Destroy |m_autoSizeInfo| as early as possible, to avoid dereferencing
280 // partially destroyed |this| via |m_autoSizeInfo->m_frameView|. 281 // partially destroyed |this| via |m_autoSizeInfo->m_frameView|.
281 m_autoSizeInfo.clear(); 282 m_autoSizeInfo.clear();
282 283
283 if (m_postLayoutTasksTimer.isActive()) 284 if (m_postLayoutTasksTimer.isActive())
284 m_postLayoutTasksTimer.stop(); 285 m_postLayoutTasksTimer.stop();
285 286
286 if (m_didScrollTimer.isActive()) 287 if (m_didScrollTimer.isActive())
287 m_didScrollTimer.stop(); 288 m_didScrollTimer.stop();
288 m_intersectionObserverNotificationFactory->cancel(); 289 m_renderThrottlingObserverNotificationFactory->cancel();
289 290
290 // FIXME: Do we need to do something here for OOPI? 291 // FIXME: Do we need to do something here for OOPI?
291 HTMLFrameOwnerElement* ownerElement = m_frame->deprecatedLocalOwner(); 292 HTMLFrameOwnerElement* ownerElement = m_frame->deprecatedLocalOwner();
292 // TODO(dcheng): It seems buggy that we can have an owner element that 293 // TODO(dcheng): It seems buggy that we can have an owner element that
293 // points to another Widget. 294 // points to another Widget.
294 if (ownerElement && ownerElement->ownedWidget() == this) 295 if (ownerElement && ownerElement->ownedWidget() == this)
295 ownerElement->setWidget(nullptr); 296 ownerElement->setWidget(nullptr);
296 297
297 #if ENABLE(ASSERT) 298 #if ENABLE(ASSERT)
298 m_hasBeenDisposed = true; 299 m_hasBeenDisposed = true;
(...skipping 2072 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 // Otherwise the lifecycles of the frames might be out of sync. 2372 // Otherwise the lifecycles of the frames might be out of sync.
2372 ASSERT(m_frame->isLocalRoot()); 2373 ASSERT(m_frame->isLocalRoot());
2373 2374
2374 // Updating layout can run script, which can tear down the FrameView. 2375 // Updating layout can run script, which can tear down the FrameView.
2375 RefPtrWillBeRawPtr<FrameView> protector(this); 2376 RefPtrWillBeRawPtr<FrameView> protector(this);
2376 2377
2377 updateStyleAndLayoutIfNeededRecursive(); 2378 updateStyleAndLayoutIfNeededRecursive();
2378 ASSERT(lifecycle().state() >= DocumentLifecycle::LayoutClean); 2379 ASSERT(lifecycle().state() >= DocumentLifecycle::LayoutClean);
2379 2380
2380 if (phases == OnlyUpToLayoutClean) { 2381 if (phases == OnlyUpToLayoutClean) {
2381 updateViewportIntersectionsForSubtree(); 2382 updateViewportIntersectionsForSubtree(phases);
2382 return; 2383 return;
2383 } 2384 }
2384 2385
2385 if (LayoutView* view = layoutView()) { 2386 if (LayoutView* view = layoutView()) {
2386 { 2387 {
2387 TRACE_EVENT1("devtools.timeline", "UpdateLayerTree", "data", Inspect orUpdateLayerTreeEvent::data(m_frame.get())); 2388 TRACE_EVENT1("devtools.timeline", "UpdateLayerTree", "data", Inspect orUpdateLayerTreeEvent::data(m_frame.get()));
2388 2389
2389 // This was required for slimming paint v1 but is only temporarily 2390 // This was required for slimming paint v1 but is only temporarily
2390 // needed for slimming paint v2. 2391 // needed for slimming paint v2.
2391 view->compositor()->updateIfNeededRecursive(); 2392 view->compositor()->updateIfNeededRecursive();
(...skipping 23 matching lines...) Expand all
2415 2416
2416 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 2417 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
2417 pushPaintArtifactToCompositor(); 2418 pushPaintArtifactToCompositor();
2418 2419
2419 ASSERT(!view->hasPendingSelection()); 2420 ASSERT(!view->hasPendingSelection());
2420 ASSERT(lifecycle().state() == DocumentLifecycle::PaintInvalidationCl ean 2421 ASSERT(lifecycle().state() == DocumentLifecycle::PaintInvalidationCl ean
2421 || (RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEna bled() && lifecycle().state() == DocumentLifecycle::PaintClean)); 2422 || (RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEna bled() && lifecycle().state() == DocumentLifecycle::PaintClean));
2422 } 2423 }
2423 } 2424 }
2424 2425
2425 updateViewportIntersectionsForSubtree(); 2426 updateViewportIntersectionsForSubtree(phases);
2426 } 2427 }
2427 2428
2428 void FrameView::updatePaintProperties() 2429 void FrameView::updatePaintProperties()
2429 { 2430 {
2430 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 2431 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled());
2431 2432
2432 forAllNonThrottledFrameViews([](FrameView& frameView) { frameView.lifecycle( ).advanceTo(DocumentLifecycle::InUpdatePaintProperties); }); 2433 forAllNonThrottledFrameViews([](FrameView& frameView) { frameView.lifecycle( ).advanceTo(DocumentLifecycle::InUpdatePaintProperties); });
2433 PaintPropertyTreeBuilder().buildPropertyTrees(*this); 2434 PaintPropertyTreeBuilder().buildPropertyTrees(*this);
2434 forAllNonThrottledFrameViews([](FrameView& frameView) { frameView.lifecycle( ).advanceTo(DocumentLifecycle::UpdatePaintPropertiesClean); }); 2435 forAllNonThrottledFrameViews([](FrameView& frameView) { frameView.lifecycle( ).advanceTo(DocumentLifecycle::UpdatePaintPropertiesClean); });
2435 } 2436 }
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
3912 3913
3913 void FrameView::setNeedsUpdateViewportIntersection() 3914 void FrameView::setNeedsUpdateViewportIntersection()
3914 { 3915 {
3915 m_needsUpdateViewportIntersection = true; 3916 m_needsUpdateViewportIntersection = true;
3916 for (FrameView* parent = parentFrameView(); parent; parent = parent->parentF rameView()) 3917 for (FrameView* parent = parentFrameView(); parent; parent = parent->parentF rameView())
3917 parent->m_needsUpdateViewportIntersectionInSubtree = true; 3918 parent->m_needsUpdateViewportIntersectionInSubtree = true;
3918 } 3919 }
3919 3920
3920 void FrameView::updateViewportIntersectionIfNeeded() 3921 void FrameView::updateViewportIntersectionIfNeeded()
3921 { 3922 {
3922 // TODO(skyostil): Replace this with a real intersection observer.
3923 if (!m_needsUpdateViewportIntersection) 3923 if (!m_needsUpdateViewportIntersection)
3924 return; 3924 return;
3925 m_needsUpdateViewportIntersection = false; 3925 m_needsUpdateViewportIntersection = false;
3926 m_viewportIntersectionValid = true; 3926 m_viewportIntersectionValid = true;
3927
3928 FrameView* parent = parentFrameView(); 3927 FrameView* parent = parentFrameView();
3929 if (!parent) { 3928 if (!parent) {
3930 m_viewportIntersection = frameRect(); 3929 m_viewportIntersection = frameRect();
3931 return; 3930 return;
3932 } 3931 }
3933 ASSERT(!parent->m_needsUpdateViewportIntersection); 3932 ASSERT(!parent->m_needsUpdateViewportIntersection);
3934 3933
3935 // If our parent is hidden, then we are too. 3934 // If our parent is hidden, then we are too.
3936 if (parent->m_viewportIntersection.isEmpty()) { 3935 if (parent->m_viewportIntersection.isEmpty()) {
3937 m_viewportIntersection = parent->m_viewportIntersection; 3936 m_viewportIntersection = parent->m_viewportIntersection;
3938 return; 3937 return;
3939 } 3938 }
3940 3939
3941 // Transform our bounds into the root frame's content coordinate space, 3940 // Transform our bounds into the root frame's content coordinate space,
3942 // making sure we have valid layout data in our parent document. If our 3941 // making sure we have valid layout data in our parent document. If our
3943 // parent is throttled, we'll use possible stale layout information and 3942 // parent is throttled, we'll use possible stale layout information and
3944 // rely on the fact that another lifecycle update will be scheduled once 3943 // rely on the fact that another lifecycle update will be scheduled once
3945 // our parent becomes unthrottled. 3944 // our parent becomes unthrottled.
3946 ASSERT(parent->lifecycle().state() >= DocumentLifecycle::LayoutClean || pare nt->shouldThrottleRendering()); 3945 ASSERT(parent->lifecycle().state() >= DocumentLifecycle::LayoutClean || pare nt->shouldThrottleRendering());
3947 m_viewportIntersection = parent->contentsToRootFrame(frameRect()); 3946 m_viewportIntersection = parent->contentsToRootFrame(frameRect());
3948 3947
3949 // TODO(skyostil): Expand the viewport to make it less likely to see stale c ontent while scrolling. 3948 // TODO(skyostil): Expand the viewport to make it less likely to see stale c ontent while scrolling.
3950 IntRect viewport = parent->m_viewportIntersection; 3949 IntRect viewport = parent->m_viewportIntersection;
3951 m_viewportIntersection.intersect(viewport); 3950 m_viewportIntersection.intersect(viewport);
3952 } 3951 }
3953 3952
3954 void FrameView::updateViewportIntersectionsForSubtree() 3953 void FrameView::updateViewportIntersectionsForSubtree(LifeCycleUpdateOption phas es)
3955 { 3954 {
3956 bool hadValidIntersection = m_viewportIntersectionValid; 3955 bool hadValidIntersection = m_viewportIntersectionValid;
3957 bool hadEmptyIntersection = m_viewportIntersection.isEmpty(); 3956 bool hadEmptyIntersection = m_viewportIntersection.isEmpty();
3958 updateViewportIntersectionIfNeeded(); 3957 updateViewportIntersectionIfNeeded();
3958
3959 // Notify javascript IntersectionObservers
3960 if (phases == AllPhases)
3961 frame().document()->ensureIntersectionObserverController().computeTracke dIntersectionObservations();
3962
3963 // Adjust render throttling for iframes based on visibility
3959 bool shouldNotify = !hadValidIntersection || hadEmptyIntersection != m_viewp ortIntersection.isEmpty(); 3964 bool shouldNotify = !hadValidIntersection || hadEmptyIntersection != m_viewp ortIntersection.isEmpty();
3960 if (shouldNotify && !m_intersectionObserverNotificationFactory->isPending()) 3965 if (shouldNotify && !m_renderThrottlingObserverNotificationFactory->isPendin g())
3961 m_frame->frameScheduler()->timerTaskRunner()->postTask(BLINK_FROM_HERE, m_intersectionObserverNotificationFactory->cancelAndCreate()); 3966 m_frame->frameScheduler()->timerTaskRunner()->postTask(BLINK_FROM_HERE, m_renderThrottlingObserverNotificationFactory->cancelAndCreate());
3962 3967
3963 if (!m_needsUpdateViewportIntersectionInSubtree) 3968 if (!m_needsUpdateViewportIntersectionInSubtree)
3964 return; 3969 return;
3965 m_needsUpdateViewportIntersectionInSubtree = false; 3970 m_needsUpdateViewportIntersectionInSubtree = false;
3966 3971
3967 for (Frame* child = m_frame->tree().firstChild(); child; child = child->tree ().nextSibling()) { 3972 for (Frame* child = m_frame->tree().firstChild(); child; child = child->tree ().nextSibling()) {
3968 if (!child->isLocalFrame()) 3973 if (!child->isLocalFrame())
3969 continue; 3974 continue;
3970 if (FrameView* view = toLocalFrame(child)->view()) 3975 if (FrameView* view = toLocalFrame(child)->view())
3971 view->updateViewportIntersectionsForSubtree(); 3976 view->updateViewportIntersectionsForSubtree(phases);
3972 } 3977 }
3973 } 3978 }
3974 3979
3975 void FrameView::notifyIntersectionObservers() 3980 void FrameView::notifyRenderThrottlingObservers()
3976 { 3981 {
3977 TRACE_EVENT0("blink", "FrameView::notifyIntersectionObservers"); 3982 TRACE_EVENT0("blink", "FrameView::notifyRenderThrottlingObservers");
3978 ASSERT(!isInPerformLayout()); 3983 ASSERT(!isInPerformLayout());
3979 ASSERT(!m_frame->document()->inStyleRecalc()); 3984 ASSERT(!m_frame->document()->inStyleRecalc());
3980 bool wasThrottled = canThrottleRendering(); 3985 bool wasThrottled = canThrottleRendering();
3981 3986
3982 // Only offscreen frames can be throttled. 3987 // Only offscreen frames can be throttled.
3983 m_hiddenForThrottling = m_viewportIntersectionValid && m_viewportIntersectio n.isEmpty(); 3988 m_hiddenForThrottling = m_viewportIntersectionValid && m_viewportIntersectio n.isEmpty();
3984 3989
3985 // We only throttle the rendering pipeline in cross-origin frames. This is 3990 // We only throttle the rendering pipeline in cross-origin frames. This is
3986 // to avoid a situation where an ancestor frame directly depends on the 3991 // to avoid a situation where an ancestor frame directly depends on the
3987 // pipeline timing of a descendant and breaks as a result of throttling. 3992 // pipeline timing of a descendant and breaks as a result of throttling.
(...skipping 29 matching lines...) Expand all
4017 return m_hiddenForThrottling && m_crossOriginForThrottling; 4022 return m_hiddenForThrottling && m_crossOriginForThrottling;
4018 } 4023 }
4019 4024
4020 LayoutBox& FrameView::boxForScrollControlPaintInvalidation() const 4025 LayoutBox& FrameView::boxForScrollControlPaintInvalidation() const
4021 { 4026 {
4022 ASSERT(layoutView()); 4027 ASSERT(layoutView());
4023 return *layoutView(); 4028 return *layoutView();
4024 } 4029 }
4025 4030
4026 } // namespace blink 4031 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698