| 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/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 std::sort(thresholds.begin(), thresholds.end()); | 80 std::sort(thresholds.begin(), thresholds.end()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 IntersectionObserver* IntersectionObserver::create(const IntersectionObserverIni
t& observerInit, IntersectionObserverCallback& callback, ExceptionState& excepti
onState) | 83 IntersectionObserver* IntersectionObserver::create(const IntersectionObserverIni
t& observerInit, IntersectionObserverCallback& callback, ExceptionState& excepti
onState) |
| 84 { | 84 { |
| 85 RawPtr<Node> root = observerInit.root(); | 85 RawPtr<Node> root = observerInit.root(); |
| 86 if (!root) { | 86 if (!root) { |
| 87 // TODO(szager): Use Document instead of document element for implicit r
oot. (crbug.com/570538) | 87 // TODO(szager): Use Document instead of document element for implicit r
oot. (crbug.com/570538) |
| 88 ExecutionContext* context = callback.getExecutionContext(); | 88 ExecutionContext* context = callback.getExecutionContext(); |
| 89 ASSERT(context->isDocument()); | 89 DCHECK(context->isDocument()); |
| 90 Frame* mainFrame = toDocument(context)->frame()->tree().top(); | 90 Frame* mainFrame = toDocument(context)->frame()->tree().top(); |
| 91 if (mainFrame && mainFrame->isLocalFrame()) | 91 if (mainFrame && mainFrame->isLocalFrame()) |
| 92 root = toLocalFrame(mainFrame)->document(); | 92 root = toLocalFrame(mainFrame)->document(); |
| 93 } | 93 } |
| 94 if (!root) { | 94 if (!root) { |
| 95 exceptionState.throwDOMException(HierarchyRequestError, "Unable to get r
oot node in main frame to track."); | 95 exceptionState.throwDOMException(HierarchyRequestError, "Unable to get r
oot node in main frame to track."); |
| 96 return nullptr; | 96 return nullptr; |
| 97 } | 97 } |
| 98 | 98 |
| 99 Vector<Length> rootMargin; | 99 Vector<Length> rootMargin; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 void IntersectionObserver::enqueueIntersectionObserverEntry(IntersectionObserver
Entry& entry) | 261 void IntersectionObserver::enqueueIntersectionObserverEntry(IntersectionObserver
Entry& entry) |
| 262 { | 262 { |
| 263 m_entries.append(&entry); | 263 m_entries.append(&entry); |
| 264 toDocument(m_callback->getExecutionContext())->ensureIntersectionObserverCon
troller().scheduleIntersectionObserverForDelivery(*this); | 264 toDocument(m_callback->getExecutionContext())->ensureIntersectionObserverCon
troller().scheduleIntersectionObserverForDelivery(*this); |
| 265 } | 265 } |
| 266 | 266 |
| 267 static LayoutUnit computeMargin(const Length& length, LayoutUnit referenceLength
) | 267 static LayoutUnit computeMargin(const Length& length, LayoutUnit referenceLength
) |
| 268 { | 268 { |
| 269 if (length.type() == Percent) | 269 if (length.type() == Percent) |
| 270 return LayoutUnit(static_cast<int>(referenceLength.toFloat() * length.pe
rcent() / 100.0)); | 270 return LayoutUnit(static_cast<int>(referenceLength.toFloat() * length.pe
rcent() / 100.0)); |
| 271 ASSERT(length.type() == Fixed); | 271 DCHECK_EQ(length.type(), Fixed); |
| 272 return LayoutUnit(length.intValue()); | 272 return LayoutUnit(length.intValue()); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void IntersectionObserver::applyRootMargin(LayoutRect& rect) const | 275 void IntersectionObserver::applyRootMargin(LayoutRect& rect) const |
| 276 { | 276 { |
| 277 // TODO(szager): Make sure the spec is clear that left/right margins are res
olved against | 277 // TODO(szager): Make sure the spec is clear that left/right margins are res
olved against |
| 278 // width and not height. | 278 // width and not height. |
| 279 LayoutUnit topMargin = computeMargin(m_topMargin, rect.height()); | 279 LayoutUnit topMargin = computeMargin(m_topMargin, rect.height()); |
| 280 LayoutUnit rightMargin = computeMargin(m_rightMargin, rect.width()); | 280 LayoutUnit rightMargin = computeMargin(m_rightMargin, rect.width()); |
| 281 LayoutUnit bottomMargin = computeMargin(m_bottomMargin, rect.height()); | 281 LayoutUnit bottomMargin = computeMargin(m_bottomMargin, rect.height()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 308 | 308 |
| 309 DEFINE_TRACE(IntersectionObserver) | 309 DEFINE_TRACE(IntersectionObserver) |
| 310 { | 310 { |
| 311 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs
erver::clearWeakMembers>(this); | 311 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs
erver::clearWeakMembers>(this); |
| 312 visitor->trace(m_callback); | 312 visitor->trace(m_callback); |
| 313 visitor->trace(m_observations); | 313 visitor->trace(m_observations); |
| 314 visitor->trace(m_entries); | 314 visitor->trace(m_entries); |
| 315 } | 315 } |
| 316 | 316 |
| 317 } // namespace blink | 317 } // namespace blink |
| OLD | NEW |