| 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/IntersectionObserver.h" | 5 #include "core/dom/IntersectionObserver.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "core/css/parser/CSSParserTokenRange.h" | 8 #include "core/css/parser/CSSParserTokenRange.h" |
| 9 #include "core/css/parser/CSSTokenizer.h" | 9 #include "core/css/parser/CSSTokenizer.h" |
| 10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/dom/ExecutionContext.h" | 12 #include "core/dom/ExecutionContext.h" |
| 13 #include "core/dom/IntersectionObserverCallback.h" | 13 #include "core/dom/IntersectionObserverCallback.h" |
| 14 #include "core/dom/IntersectionObserverController.h" | 14 #include "core/dom/IntersectionObserverController.h" |
| 15 #include "core/dom/IntersectionObserverEntry.h" | 15 #include "core/dom/IntersectionObserverEntry.h" |
| 16 #include "core/dom/IntersectionObserverInit.h" | 16 #include "core/dom/IntersectionObserverInit.h" |
| 17 #include "core/dom/NodeIntersectionObserverData.h" | 17 #include "core/dom/NodeIntersectionObserverData.h" |
| 18 #include "core/frame/FrameView.h" | 18 #include "core/frame/FrameView.h" |
| 19 #include "core/frame/LocalDOMWindow.h" | 19 #include "core/frame/LocalDOMWindow.h" |
| 20 #include "core/frame/LocalFrame.h" | 20 #include "core/frame/LocalFrame.h" |
| 21 #include "core/html/HTMLFrameOwnerElement.h" | 21 #include "core/html/HTMLFrameOwnerElement.h" |
| 22 #include "core/inspector/ConsoleMessage.h" |
| 22 #include "core/layout/LayoutView.h" | 23 #include "core/layout/LayoutView.h" |
| 23 #include "core/timing/DOMWindowPerformance.h" | 24 #include "core/timing/DOMWindowPerformance.h" |
| 24 #include "core/timing/Performance.h" | 25 #include "core/timing/Performance.h" |
| 25 #include "platform/Timer.h" | 26 #include "platform/Timer.h" |
| 26 #include <algorithm> | 27 #include <algorithm> |
| 27 | 28 |
| 28 namespace blink { | 29 namespace blink { |
| 29 | 30 |
| 30 static void parseRootMargin(String rootMarginParameter, Vector<Length>& rootMarg
in, ExceptionState& exceptionState) | 31 static void parseRootMargin(String rootMarginParameter, Vector<Length>& rootMarg
in, ExceptionState& exceptionState) |
| 31 { | 32 { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 173 |
| 173 void IntersectionObserver::observe(Element* target) | 174 void IntersectionObserver::observe(Element* target) |
| 174 { | 175 { |
| 175 if (!m_root || !target || m_root.get() == target) | 176 if (!m_root || !target || m_root.get() == target) |
| 176 return; | 177 return; |
| 177 | 178 |
| 178 if (target->ensureIntersectionObserverData().getObservationFor(*this)) | 179 if (target->ensureIntersectionObserverData().getObservationFor(*this)) |
| 179 return; | 180 return; |
| 180 | 181 |
| 181 bool shouldReportRootBounds = false; | 182 bool shouldReportRootBounds = false; |
| 183 bool isDOMDescendant = false; |
| 182 LocalFrame* targetFrame = target->document().frame(); | 184 LocalFrame* targetFrame = target->document().frame(); |
| 183 LocalFrame* rootFrame = rootNode()->document().frame(); | 185 LocalFrame* rootFrame = m_root->document().frame(); |
| 184 if (targetFrame && rootFrame) | 186 |
| 187 if (target->document() == rootNode()->document()) { |
| 188 shouldReportRootBounds = true; |
| 189 isDOMDescendant = target->isDescendantOf(rootNode()); |
| 190 } else if (targetFrame && rootFrame) { |
| 185 shouldReportRootBounds = targetFrame->securityContext()->getSecurityOrig
in()->canAccess(rootFrame->securityContext()->getSecurityOrigin()); | 191 shouldReportRootBounds = targetFrame->securityContext()->getSecurityOrig
in()->canAccess(rootFrame->securityContext()->getSecurityOrigin()); |
| 192 isDOMDescendant = (targetFrame->tree().top() == rootFrame); |
| 193 } |
| 194 |
| 186 IntersectionObservation* observation = new IntersectionObservation(*this, *t
arget, shouldReportRootBounds); | 195 IntersectionObservation* observation = new IntersectionObservation(*this, *t
arget, shouldReportRootBounds); |
| 187 target->ensureIntersectionObserverData().addObservation(*observation); | 196 target->ensureIntersectionObserverData().addObservation(*observation); |
| 188 m_observations.add(observation); | 197 m_observations.add(observation); |
| 198 |
| 199 if (!isDOMDescendant) { |
| 200 m_root->document().addConsoleMessage(ConsoleMessage::create( |
| 201 JSMessageSource, WarningMessageLevel, |
| 202 "IntersectionObserver.observe(target): target element is not a desce
ndant of root.")); |
| 203 return; |
| 204 } |
| 205 |
| 189 if (!rootFrame) | 206 if (!rootFrame) |
| 190 return; | 207 return; |
| 191 if (FrameView* rootFrameView = rootFrame->view()) | 208 if (FrameView* rootFrameView = rootFrame->view()) |
| 192 rootFrameView->scheduleAnimation(); | 209 rootFrameView->scheduleAnimation(); |
| 193 } | 210 } |
| 194 | 211 |
| 195 void IntersectionObserver::unobserve(Element* target) | 212 void IntersectionObserver::unobserve(Element* target) |
| 196 { | 213 { |
| 197 if (!target || !target->intersectionObserverData()) | 214 if (!target || !target->intersectionObserverData()) |
| 198 return; | 215 return; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 330 |
| 314 DEFINE_TRACE(IntersectionObserver) | 331 DEFINE_TRACE(IntersectionObserver) |
| 315 { | 332 { |
| 316 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs
erver::clearWeakMembers>(this); | 333 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs
erver::clearWeakMembers>(this); |
| 317 visitor->trace(m_callback); | 334 visitor->trace(m_callback); |
| 318 visitor->trace(m_observations); | 335 visitor->trace(m_observations); |
| 319 visitor->trace(m_entries); | 336 visitor->trace(m_entries); |
| 320 } | 337 } |
| 321 | 338 |
| 322 } // namespace blink | 339 } // namespace blink |
| OLD | NEW |