| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 "rootMargin must be specified in pixels or percent."); | 100 "rootMargin must be specified in pixels or percent."); |
| 101 } | 101 } |
| 102 break; | 102 break; |
| 103 default: | 103 default: |
| 104 exceptionState.throwDOMException( | 104 exceptionState.throwDOMException( |
| 105 SyntaxError, "rootMargin must be specified in pixels or percent."); | 105 SyntaxError, "rootMargin must be specified in pixels or percent."); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 void parseThresholds(const DoubleOrDoubleArray& thresholdParameter, | 110 void parseThresholds(const DoubleOrDoubleSequence& thresholdParameter, |
| 111 Vector<float>& thresholds, | 111 Vector<float>& thresholds, |
| 112 ExceptionState& exceptionState) { | 112 ExceptionState& exceptionState) { |
| 113 if (thresholdParameter.isDouble()) { | 113 if (thresholdParameter.isDouble()) { |
| 114 thresholds.append(static_cast<float>(thresholdParameter.getAsDouble())); | 114 thresholds.append(static_cast<float>(thresholdParameter.getAsDouble())); |
| 115 } else { | 115 } else { |
| 116 for (auto thresholdValue : thresholdParameter.getAsDoubleArray()) | 116 for (auto thresholdValue : thresholdParameter.getAsDoubleSequence()) |
| 117 thresholds.append(static_cast<float>(thresholdValue)); | 117 thresholds.append(static_cast<float>(thresholdValue)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 for (auto thresholdValue : thresholds) { | 120 for (auto thresholdValue : thresholds) { |
| 121 if (std::isnan(thresholdValue) || thresholdValue < 0.0 || | 121 if (std::isnan(thresholdValue) || thresholdValue < 0.0 || |
| 122 thresholdValue > 1.0) { | 122 thresholdValue > 1.0) { |
| 123 exceptionState.throwRangeError( | 123 exceptionState.throwRangeError( |
| 124 "Threshold values must be numbers between 0 and 1"); | 124 "Threshold values must be numbers between 0 and 1"); |
| 125 break; | 125 break; |
| 126 } | 126 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 152 root = getRootNode(toDocument(context)); | 152 root = getRootNode(toDocument(context)); |
| 153 } | 153 } |
| 154 if (!root) { | 154 if (!root) { |
| 155 exceptionState.throwDOMException( | 155 exceptionState.throwDOMException( |
| 156 HierarchyRequestError, | 156 HierarchyRequestError, |
| 157 "Unable to get root node in main frame to track."); | 157 "Unable to get root node in main frame to track."); |
| 158 return nullptr; | 158 return nullptr; |
| 159 } | 159 } |
| 160 | 160 |
| 161 Vector<Length> rootMargin; | 161 Vector<Length> rootMargin; |
| 162 if (observerInit.hasRootMargin()) | 162 parseRootMargin(observerInit.rootMargin(), rootMargin, exceptionState); |
| 163 parseRootMargin(observerInit.rootMargin(), rootMargin, exceptionState); | |
| 164 if (exceptionState.hadException()) | 163 if (exceptionState.hadException()) |
| 165 return nullptr; | 164 return nullptr; |
| 166 | 165 |
| 167 Vector<float> thresholds; | 166 Vector<float> thresholds; |
| 168 if (observerInit.hasThreshold()) | 167 parseThresholds(observerInit.threshold(), thresholds, exceptionState); |
| 169 parseThresholds(observerInit.threshold(), thresholds, exceptionState); | |
| 170 else | |
| 171 thresholds.append(0); | |
| 172 if (exceptionState.hadException()) | 168 if (exceptionState.hadException()) |
| 173 return nullptr; | 169 return nullptr; |
| 174 | 170 |
| 175 return new IntersectionObserver(callback, *root, rootMargin, thresholds); | 171 return new IntersectionObserver(callback, *root, rootMargin, thresholds); |
| 176 } | 172 } |
| 177 | 173 |
| 178 IntersectionObserver* IntersectionObserver::create( | 174 IntersectionObserver* IntersectionObserver::create( |
| 179 const Vector<Length>& rootMargin, | 175 const Vector<Length>& rootMargin, |
| 180 const Vector<float>& thresholds, | 176 const Vector<float>& thresholds, |
| 181 Document* document, | 177 Document* document, |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 435 |
| 440 DEFINE_TRACE(IntersectionObserver) { | 436 DEFINE_TRACE(IntersectionObserver) { |
| 441 visitor->template registerWeakMembers< | 437 visitor->template registerWeakMembers< |
| 442 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); | 438 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); |
| 443 visitor->trace(m_callback); | 439 visitor->trace(m_callback); |
| 444 visitor->trace(m_observations); | 440 visitor->trace(m_observations); |
| 445 visitor->trace(m_entries); | 441 visitor->trace(m_entries); |
| 446 } | 442 } |
| 447 | 443 |
| 448 } // namespace blink | 444 } // namespace blink |
| OLD | NEW |