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/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 void IntersectionObservation::initializeRootRect(LayoutRect& rect) const { | 46 void IntersectionObservation::initializeRootRect(LayoutRect& rect) const { |
47 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); | 47 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); |
48 if (rootLayoutObject->isLayoutView()) | 48 if (rootLayoutObject->isLayoutView()) |
49 rect = LayoutRect( | 49 rect = LayoutRect( |
50 toLayoutView(rootLayoutObject)->frameView()->visibleContentRect()); | 50 toLayoutView(rootLayoutObject)->frameView()->visibleContentRect()); |
51 else if (rootLayoutObject->isBox() && rootLayoutObject->hasOverflowClip()) | 51 else if (rootLayoutObject->isBox() && rootLayoutObject->hasOverflowClip()) |
52 rect = LayoutRect(toLayoutBox(rootLayoutObject)->contentBoxRect()); | 52 rect = LayoutRect(toLayoutBox(rootLayoutObject)->contentBoxRect()); |
53 else | 53 else |
54 rect = LayoutRect( | 54 rect = LayoutRect( |
55 toLayoutBoxModelObject(rootLayoutObject)->borderBoundingBox()); | 55 toLayoutBoxModelObject(rootLayoutObject)->borderBoundingBox()); |
| 56 m_observer->intersectWithRemoteAncestorsIfNeeded(rect); |
56 applyRootMargin(rect); | 57 applyRootMargin(rect); |
57 } | 58 } |
58 | 59 |
59 void IntersectionObservation::clipToRoot(IntersectionGeometry& geometry) const { | 60 void IntersectionObservation::clipToRoot(IntersectionGeometry& geometry) const { |
60 // Map and clip rect into root element coordinates. | 61 // Map and clip rect into root element coordinates. |
61 // TODO(szager): the writing mode flipping needs a test. | 62 // TODO(szager): the writing mode flipping needs a test. |
62 DCHECK(m_target); | 63 DCHECK(m_target); |
63 LayoutBox* rootLayoutObject = toLayoutBox(m_observer->rootLayoutObject()); | 64 LayoutBox* rootLayoutObject = toLayoutBox(m_observer->rootLayoutObject()); |
64 LayoutObject* targetLayoutObject = target()->layoutObject(); | 65 LayoutObject* targetLayoutObject = target()->layoutObject(); |
65 | 66 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 targetDocument); | 125 targetDocument); |
125 | 126 |
126 rect.move(-scrollPosition); | 127 rect.move(-scrollPosition); |
127 } | 128 } |
128 | 129 |
129 static bool isContainingBlockChainDescendant(LayoutObject* descendant, | 130 static bool isContainingBlockChainDescendant(LayoutObject* descendant, |
130 LayoutObject* ancestor) { | 131 LayoutObject* ancestor) { |
131 LocalFrame* ancestorFrame = ancestor->document().frame(); | 132 LocalFrame* ancestorFrame = ancestor->document().frame(); |
132 LocalFrame* descendantFrame = descendant->document().frame(); | 133 LocalFrame* descendantFrame = descendant->document().frame(); |
133 | 134 |
134 if (ancestor->isLayoutView()) | 135 if (ancestor->isLayoutView()) { |
135 return descendantFrame && descendantFrame->tree().top() == ancestorFrame; | 136 return descendantFrame && |
| 137 descendantFrame->localFrameRoot() == ancestorFrame; |
| 138 } |
136 | 139 |
137 if (ancestorFrame != descendantFrame) | 140 if (ancestorFrame != descendantFrame) |
138 return false; | 141 return false; |
139 | 142 |
140 while (descendant && descendant != ancestor) | 143 while (descendant && descendant != ancestor) |
141 descendant = descendant->containingBlock(); | 144 descendant = descendant->containingBlock(); |
142 return descendant; | 145 return descendant; |
143 } | 146 } |
144 | 147 |
145 bool IntersectionObservation::computeGeometry( | 148 bool IntersectionObservation::computeGeometry( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 183 |
181 if (geometry.doesIntersect) | 184 if (geometry.doesIntersect) |
182 mapRootRectToTargetFrameCoordinates(geometry.intersectionRect); | 185 mapRootRectToTargetFrameCoordinates(geometry.intersectionRect); |
183 else | 186 else |
184 geometry.intersectionRect = LayoutRect(); | 187 geometry.intersectionRect = LayoutRect(); |
185 | 188 |
186 // Small optimization: if we're not going to report root bounds, don't bother | 189 // Small optimization: if we're not going to report root bounds, don't bother |
187 // transforming them to the frame. | 190 // transforming them to the frame. |
188 if (m_shouldReportRootBounds) | 191 if (m_shouldReportRootBounds) |
189 mapRootRectToRootFrameCoordinates(geometry.rootRect); | 192 mapRootRectToRootFrameCoordinates(geometry.rootRect); |
190 | |
191 return true; | 193 return true; |
192 } | 194 } |
193 | 195 |
194 void IntersectionObservation::computeIntersectionObservations( | 196 void IntersectionObservation::computeIntersectionObservations( |
195 DOMHighResTimeStamp timestamp) { | 197 DOMHighResTimeStamp timestamp) { |
196 IntersectionGeometry geometry; | 198 IntersectionGeometry geometry; |
197 if (!computeGeometry(geometry)) | 199 if (!computeGeometry(geometry)) |
198 return; | 200 return; |
199 | 201 |
200 // Some corner cases for threshold index: | 202 // Some corner cases for threshold index: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 target()->ensureIntersectionObserverData().removeObservation(observer()); | 251 target()->ensureIntersectionObserverData().removeObservation(observer()); |
250 m_observer.clear(); | 252 m_observer.clear(); |
251 } | 253 } |
252 | 254 |
253 DEFINE_TRACE(IntersectionObservation) { | 255 DEFINE_TRACE(IntersectionObservation) { |
254 visitor->trace(m_observer); | 256 visitor->trace(m_observer); |
255 visitor->trace(m_target); | 257 visitor->trace(m_target); |
256 } | 258 } |
257 | 259 |
258 } // namespace blink | 260 } // namespace blink |
OLD | NEW |