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

Side by Side Diff: third_party/WebKit/Source/core/dom/IntersectionObservation.cpp

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Consolidate two ElementVisibilityObserver in AUtoplayUmaHelper. Created 4 years, 1 month 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/IntersectionObservation.h" 5 #include "core/dom/IntersectionObservation.h"
6 6
7 #include "core/dom/ElementRareData.h" 7 #include "core/dom/ElementRareData.h"
8 #include "core/dom/IntersectionObserver.h" 8 #include "core/dom/IntersectionObserver.h"
9 #include "core/frame/FrameView.h" 9 #include "core/frame/FrameView.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
11 #include "core/layout/LayoutBox.h" 11 #include "core/layout/LayoutBox.h"
12 #include "core/layout/LayoutView.h" 12 #include "core/layout/LayoutView.h"
13 #include "core/paint/PaintLayer.h" 13 #include "core/paint/PaintLayer.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 IntersectionObservation::IntersectionObservation(IntersectionObserver& observer, 17 IntersectionObservation::IntersectionObservation(IntersectionObserver& observer,
18 Element& target, 18 Element& target,
19 bool shouldReportRootBounds) 19 bool shouldReportRootBounds)
miu 2016/11/05 02:47:46 Did you intend to remove the 3rd argument to this
xjz 2016/11/09 02:24:28 Now keep this argument for original purpose.
20 : m_observer(observer), 20 : m_observer(observer),
21 m_target(&target), 21 m_target(&target),
22 m_shouldReportRootBounds(shouldReportRootBounds), 22 m_shouldReportRootBounds(true),
23 m_lastThresholdIndex(0) {} 23 m_lastThresholdIndex(0) {}
24 24
25 void IntersectionObservation::applyRootMargin(LayoutRect& rect) const { 25 void IntersectionObservation::applyRootMargin(LayoutRect& rect) const {
26 if (m_shouldReportRootBounds) 26 if (m_shouldReportRootBounds)
27 m_observer->applyRootMargin(rect); 27 m_observer->applyRootMargin(rect);
28 } 28 }
29 29
30 void IntersectionObservation::initializeGeometry( 30 void IntersectionObservation::initializeGeometry(
31 IntersectionGeometry& geometry) const { 31 IntersectionGeometry& geometry) const {
32 initializeTargetRect(geometry.targetRect); 32 initializeTargetRect(geometry.targetRect);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 unsigned newThresholdIndex; 213 unsigned newThresholdIndex;
214 float newVisibleRatio = 0; 214 float newVisibleRatio = 0;
215 if (geometry.targetRect.isEmpty()) { 215 if (geometry.targetRect.isEmpty()) {
216 newThresholdIndex = geometry.doesIntersect ? 1 : 0; 216 newThresholdIndex = geometry.doesIntersect ? 1 : 0;
217 } else if (!geometry.doesIntersect) { 217 } else if (!geometry.doesIntersect) {
218 newThresholdIndex = 0; 218 newThresholdIndex = 0;
219 } else { 219 } else {
220 float intersectionArea = 220 float intersectionArea =
221 geometry.intersectionRect.size().width().toFloat() * 221 geometry.intersectionRect.size().width().toFloat() *
222 geometry.intersectionRect.size().height().toFloat(); 222 geometry.intersectionRect.size().height().toFloat();
223 float targetArea = geometry.targetRect.size().width().toFloat() * 223 float rootArea = geometry.rootRect.size().width().toFloat() *
224 geometry.targetRect.size().height().toFloat(); 224 geometry.rootRect.size().height().toFloat();
225 newVisibleRatio = intersectionArea / targetArea; 225 newVisibleRatio = intersectionArea / rootArea;
226 newThresholdIndex = observer().firstThresholdGreaterThan(newVisibleRatio); 226 newThresholdIndex = observer().firstThresholdGreaterThan(newVisibleRatio);
227 } 227 }
228 if (m_lastThresholdIndex != newThresholdIndex) { 228 if (m_lastThresholdIndex != newThresholdIndex) {
229 IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect); 229 IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect);
230 IntRect* rootBoundsPointer = 230 IntRect* rootBoundsPointer =
231 m_shouldReportRootBounds ? &snappedRootBounds : nullptr; 231 m_shouldReportRootBounds ? &snappedRootBounds : nullptr;
232 IntersectionObserverEntry* newEntry = new IntersectionObserverEntry( 232 IntersectionObserverEntry* newEntry = new IntersectionObserverEntry(
233 timestamp, newVisibleRatio, pixelSnappedIntRect(geometry.targetRect), 233 timestamp, newVisibleRatio, pixelSnappedIntRect(geometry.targetRect),
234 rootBoundsPointer, pixelSnappedIntRect(geometry.intersectionRect), 234 rootBoundsPointer, pixelSnappedIntRect(geometry.intersectionRect),
235 target()); 235 target());
(...skipping 13 matching lines...) Expand all
249 target()->ensureIntersectionObserverData().removeObservation(observer()); 249 target()->ensureIntersectionObserverData().removeObservation(observer());
250 m_observer.clear(); 250 m_observer.clear();
251 } 251 }
252 252
253 DEFINE_TRACE(IntersectionObservation) { 253 DEFINE_TRACE(IntersectionObservation) {
254 visitor->trace(m_observer); 254 visitor->trace(m_observer);
255 visitor->trace(m_target); 255 visitor->trace(m_target);
256 } 256 }
257 257
258 } // namespace blink 258 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698