OLD | NEW |
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/layout/LayoutBox.h" | 10 #include "core/layout/LayoutBox.h" |
11 #include "core/layout/LayoutText.h" | 11 #include "core/layout/LayoutText.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,
Element& target, bool shouldReportRootBounds) | 17 IntersectionObservation::IntersectionObservation(IntersectionObserver& observer,
Element& target, bool shouldReportRootBounds) |
18 : m_observer(observer) | 18 : m_observer(observer) |
19 , m_target(target.ensureIntersectionObserverData().createWeakPtr(&target)) | 19 , m_target(target.ensureIntersectionObserverData().createWeakPtr(&target)) |
20 , m_active(true) | 20 , m_active(true) |
21 , m_shouldReportRootBounds(shouldReportRootBounds) | 21 , m_shouldReportRootBounds(shouldReportRootBounds) |
22 , m_lastThresholdIndex(0) | 22 , m_lastThresholdIndex(0) |
23 { | 23 { |
24 } | 24 } |
25 | 25 |
26 void IntersectionObservation::initializeGeometry(IntersectionGeometry& geometry) | 26 void IntersectionObservation::initializeGeometry(IntersectionGeometry& geometry) |
27 { | 27 { |
| 28 ASSERT(m_target); |
28 LayoutObject* targetLayoutObject = m_target->layoutObject(); | 29 LayoutObject* targetLayoutObject = m_target->layoutObject(); |
29 if (targetLayoutObject->isBoxModelObject()) | 30 if (targetLayoutObject->isBoxModelObject()) |
30 geometry.targetRect = toLayoutBoxModelObject(targetLayoutObject)->visual
OverflowRect(); | 31 geometry.targetRect = toLayoutBoxModelObject(targetLayoutObject)->visual
OverflowRect(); |
31 else | 32 else |
32 geometry.targetRect = toLayoutText(targetLayoutObject)->visualOverflowRe
ct(); | 33 geometry.targetRect = toLayoutText(targetLayoutObject)->visualOverflowRe
ct(); |
33 geometry.intersectionRect = geometry.targetRect; | 34 geometry.intersectionRect = geometry.targetRect; |
34 } | 35 } |
35 | 36 |
36 void IntersectionObservation::clipToRoot(LayoutRect& rect) | 37 void IntersectionObservation::clipToRoot(LayoutRect& rect) |
37 { | 38 { |
38 // Map and clip rect into root element coordinates. | 39 // Map and clip rect into root element coordinates. |
39 // TODO(szager): the writing mode flipping needs a test. | 40 // TODO(szager): the writing mode flipping needs a test. |
| 41 ASSERT(m_target); |
40 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); | 42 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); |
41 LayoutObject* targetLayoutObject = m_target->layoutObject(); | 43 LayoutObject* targetLayoutObject = m_target->layoutObject(); |
42 targetLayoutObject->mapToVisibleRectInAncestorSpace(toLayoutBoxModelObject(r
ootLayoutObject), rect, nullptr); | 44 targetLayoutObject->mapToVisibleRectInAncestorSpace(toLayoutBoxModelObject(r
ootLayoutObject), rect, nullptr); |
43 if (rootLayoutObject->hasOverflowClip()) { | 45 if (rootLayoutObject->hasOverflowClip()) { |
44 LayoutBox* rootLayoutBox = toLayoutBox(rootLayoutObject); | 46 LayoutBox* rootLayoutBox = toLayoutBox(rootLayoutObject); |
45 LayoutRect clipRect(LayoutPoint(), LayoutSize(rootLayoutBox->layer()->si
ze())); | 47 LayoutRect clipRect(LayoutPoint(), LayoutSize(rootLayoutBox->layer()->si
ze())); |
46 rootLayoutBox->flipForWritingMode(rect); | 48 rootLayoutBox->flipForWritingMode(rect); |
47 rect.intersect(clipRect); | 49 rect.intersect(clipRect); |
48 rootLayoutBox->flipForWritingMode(rect); | 50 rootLayoutBox->flipForWritingMode(rect); |
49 } | 51 } |
(...skipping 19 matching lines...) Expand all Loading... |
69 geometry.rootRect.moveBy(-scrollPosition); | 71 geometry.rootRect.moveBy(-scrollPosition); |
70 } | 72 } |
71 | 73 |
72 static void mapRectToDocumentCoordinates(LayoutObject& layoutObject, LayoutRect&
rect) | 74 static void mapRectToDocumentCoordinates(LayoutObject& layoutObject, LayoutRect&
rect) |
73 { | 75 { |
74 rect = LayoutRect(layoutObject.localToAbsoluteQuad(FloatQuad(FloatRect(rect)
), UseTransforms | ApplyContainerFlip | TraverseDocumentBoundaries).boundingBox(
)); | 76 rect = LayoutRect(layoutObject.localToAbsoluteQuad(FloatQuad(FloatRect(rect)
), UseTransforms | ApplyContainerFlip | TraverseDocumentBoundaries).boundingBox(
)); |
75 } | 77 } |
76 | 78 |
77 bool IntersectionObservation::computeGeometry(IntersectionGeometry& geometry) | 79 bool IntersectionObservation::computeGeometry(IntersectionGeometry& geometry) |
78 { | 80 { |
| 81 ASSERT(m_target); |
79 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); | 82 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); |
80 LayoutObject* targetLayoutObject = m_target->layoutObject(); | 83 LayoutObject* targetLayoutObject = m_target->layoutObject(); |
81 if (!rootLayoutObject->isBoxModelObject()) | 84 if (!rootLayoutObject->isBoxModelObject()) |
82 return false; | 85 return false; |
83 if (!targetLayoutObject->isBoxModelObject() && !targetLayoutObject->isText()
) | 86 if (!targetLayoutObject->isBoxModelObject() && !targetLayoutObject->isText()
) |
84 return false; | 87 return false; |
85 | 88 |
86 // Initialize targetRect and intersectionRect to bounds of target, in target
's coordinate space. | 89 // Initialize targetRect and intersectionRect to bounds of target, in target
's coordinate space. |
87 initializeGeometry(geometry); | 90 initializeGeometry(geometry); |
88 | 91 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 pixelSnappedIntRect(geometry.rootRect), | 141 pixelSnappedIntRect(geometry.rootRect), |
139 pixelSnappedIntRect(geometry.intersectionRect), | 142 pixelSnappedIntRect(geometry.intersectionRect), |
140 targetElement); | 143 targetElement); |
141 observer().enqueueIntersectionObserverEntry(*newEntry); | 144 observer().enqueueIntersectionObserverEntry(*newEntry); |
142 } | 145 } |
143 setLastThresholdIndex(newThresholdIndex); | 146 setLastThresholdIndex(newThresholdIndex); |
144 } | 147 } |
145 | 148 |
146 void IntersectionObservation::disconnect() | 149 void IntersectionObservation::disconnect() |
147 { | 150 { |
148 if (m_target) { | 151 if (m_target) |
149 m_target->ensureIntersectionObserverData().removeObservation(this->obser
ver()); | 152 m_target->ensureIntersectionObserverData().removeObservation(this->obser
ver()); |
150 m_target.clear(); | |
151 } | |
152 m_observer->removeObservation(*this); | 153 m_observer->removeObservation(*this); |
153 m_observer.clear(); | 154 m_observer.clear(); |
154 } | 155 } |
155 | 156 |
156 DEFINE_TRACE(IntersectionObservation) | 157 DEFINE_TRACE(IntersectionObservation) |
157 { | 158 { |
158 visitor->trace(m_observer); | 159 visitor->trace(m_observer); |
159 visitor->trace(m_target); | 160 visitor->trace(m_target); |
160 } | 161 } |
161 | 162 |
162 } // namespace blink | 163 } // namespace blink |
OLD | NEW |