Chromium Code Reviews| 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" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 return toElement(node)->layoutObject(); | 172 return toElement(node)->layoutObject(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void IntersectionObserver::observe(Element* target, ExceptionState& exceptionSta te) | 175 void IntersectionObserver::observe(Element* target, ExceptionState& exceptionSta te) |
| 176 { | 176 { |
| 177 if (!m_root) { | 177 if (!m_root) { |
| 178 exceptionState.throwDOMException(InvalidStateError, "observe() called on an IntersectionObserver with an invalid root."); | 178 exceptionState.throwDOMException(InvalidStateError, "observe() called on an IntersectionObserver with an invalid root."); |
| 179 return; | 179 return; |
| 180 } | 180 } |
| 181 | 181 |
| 182 observe(target); | |
|
szager1
2016/06/10 21:07:17
Infinite recursion.
szager1
2016/06/10 21:09:23
Oh never mind, I see what you did here. I would p
| |
| 183 } | |
| 184 | |
| 185 void IntersectionObserver::observe(Element* target) | |
| 186 { | |
| 187 DCHECK(m_root); | |
| 188 | |
| 182 if (!target || m_root.get() == target) | 189 if (!target || m_root.get() == target) |
| 183 return; | 190 return; |
| 184 | 191 |
| 185 if (target->ensureIntersectionObserverData().getObservationFor(*this)) | 192 if (target->ensureIntersectionObserverData().getObservationFor(*this)) |
| 186 return; | 193 return; |
| 187 | |
| 188 bool shouldReportRootBounds = false; | 194 bool shouldReportRootBounds = false; |
| 189 bool isDOMDescendant = false; | 195 bool isDOMDescendant = false; |
| 190 LocalFrame* targetFrame = target->document().frame(); | 196 LocalFrame* targetFrame = target->document().frame(); |
| 191 LocalFrame* rootFrame = m_root->document().frame(); | 197 LocalFrame* rootFrame = m_root->document().frame(); |
| 192 | 198 |
| 193 if (target->document() == rootNode()->document()) { | 199 if (target->document() == rootNode()->document()) { |
| 194 shouldReportRootBounds = true; | 200 shouldReportRootBounds = true; |
| 195 isDOMDescendant = target->isDescendantOf(rootNode()); | 201 isDOMDescendant = target->isDescendantOf(rootNode()); |
| 196 } else if (targetFrame && rootFrame) { | 202 } else if (targetFrame && rootFrame) { |
| 197 shouldReportRootBounds = targetFrame->securityContext()->getSecurityOrig in()->canAccess(rootFrame->securityContext()->getSecurityOrigin()); | 203 shouldReportRootBounds = targetFrame->securityContext()->getSecurityOrig in()->canAccess(rootFrame->securityContext()->getSecurityOrigin()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 215 rootFrameView->scheduleAnimation(); | 221 rootFrameView->scheduleAnimation(); |
| 216 } | 222 } |
| 217 | 223 |
| 218 void IntersectionObserver::unobserve(Element* target, ExceptionState& exceptionS tate) | 224 void IntersectionObserver::unobserve(Element* target, ExceptionState& exceptionS tate) |
| 219 { | 225 { |
| 220 if (!m_root) { | 226 if (!m_root) { |
| 221 exceptionState.throwDOMException(InvalidStateError, "unobserve() called on an IntersectionObserver with an invalid root."); | 227 exceptionState.throwDOMException(InvalidStateError, "unobserve() called on an IntersectionObserver with an invalid root."); |
| 222 return; | 228 return; |
| 223 } | 229 } |
| 224 | 230 |
| 231 unobserve(target); | |
|
szager1
2016/06/10 21:07:49
Infinite recursion.
szager1
2016/06/10 21:09:23
Same comment.
| |
| 232 } | |
| 233 | |
| 234 void IntersectionObserver::unobserve(Element* target) | |
| 235 { | |
| 236 DCHECK(m_root); | |
| 237 | |
| 225 if (!target || !target->intersectionObserverData()) | 238 if (!target || !target->intersectionObserverData()) |
| 226 return; | 239 return; |
| 227 // TODO(szager): unobserve callback | 240 // TODO(szager): unobserve callback |
| 228 if (IntersectionObservation* observation = target->intersectionObserverData( )->getObservationFor(*this)) | 241 if (IntersectionObservation* observation = target->intersectionObserverData( )->getObservationFor(*this)) |
| 229 observation->disconnect(); | 242 observation->disconnect(); |
| 230 } | 243 } |
| 231 | 244 |
| 232 void IntersectionObserver::computeIntersectionObservations() | 245 void IntersectionObserver::computeIntersectionObservations() |
| 233 { | 246 { |
| 234 Document* callbackDocument = toDocument(m_callback->getExecutionContext()); | 247 Document* callbackDocument = toDocument(m_callback->getExecutionContext()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 unsigned IntersectionObserver::firstThresholdGreaterThan(float ratio) const | 346 unsigned IntersectionObserver::firstThresholdGreaterThan(float ratio) const |
| 334 { | 347 { |
| 335 unsigned result = 0; | 348 unsigned result = 0; |
| 336 while (result < m_thresholds.size() && m_thresholds[result] <= ratio) | 349 while (result < m_thresholds.size() && m_thresholds[result] <= ratio) |
| 337 ++result; | 350 ++result; |
| 338 return result; | 351 return result; |
| 339 } | 352 } |
| 340 | 353 |
| 341 void IntersectionObserver::deliver() | 354 void IntersectionObserver::deliver() |
| 342 { | 355 { |
| 343 | |
| 344 if (m_entries.isEmpty()) | 356 if (m_entries.isEmpty()) |
| 345 return; | 357 return; |
| 346 | 358 |
| 347 HeapVector<Member<IntersectionObserverEntry>> entries; | 359 HeapVector<Member<IntersectionObserverEntry>> entries; |
| 348 entries.swap(m_entries); | 360 entries.swap(m_entries); |
| 349 m_callback->handleEvent(entries, *this); | 361 m_callback->handleEvent(entries, *this); |
| 350 } | 362 } |
| 351 | 363 |
| 352 DEFINE_TRACE(IntersectionObserver) | 364 DEFINE_TRACE(IntersectionObserver) |
| 353 { | 365 { |
| 354 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs erver::clearWeakMembers>(this); | 366 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs erver::clearWeakMembers>(this); |
| 355 visitor->trace(m_callback); | 367 visitor->trace(m_callback); |
| 356 visitor->trace(m_observations); | 368 visitor->trace(m_observations); |
| 357 visitor->trace(m_entries); | 369 visitor->trace(m_entries); |
| 358 } | 370 } |
| 359 | 371 |
| 360 } // namespace blink | 372 } // namespace blink |
| OLD | NEW |