| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 default: | 95 default: |
| 96 exceptionState.throwDOMException(SyntaxError, "rootMargin must b
e specified in pixels or percent."); | 96 exceptionState.throwDOMException(SyntaxError, "rootMargin must b
e specified in pixels or percent."); |
| 97 } | 97 } |
| 98 break; | 98 break; |
| 99 default: | 99 default: |
| 100 exceptionState.throwDOMException(SyntaxError, "rootMargin must be sp
ecified in pixels or percent."); | 100 exceptionState.throwDOMException(SyntaxError, "rootMargin must be sp
ecified in pixels or percent."); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 void parseThresholds(const DoubleOrDoubleArray& thresholdParameter, Vector<float
>& thresholds, ExceptionState& exceptionState) | 105 void parseThresholds(const DoubleOrDoubleSequence& thresholdParameter, Vector<fl
oat>& thresholds, ExceptionState& exceptionState) |
| 106 { | 106 { |
| 107 if (thresholdParameter.isDouble()) { | 107 if (thresholdParameter.isDouble()) { |
| 108 thresholds.append(static_cast<float>(thresholdParameter.getAsDouble())); | 108 thresholds.append(static_cast<float>(thresholdParameter.getAsDouble())); |
| 109 } else { | 109 } else { |
| 110 for (auto thresholdValue : thresholdParameter.getAsDoubleArray()) | 110 for (auto thresholdValue : thresholdParameter.getAsDoubleSequence()) |
| 111 thresholds.append(static_cast<float>(thresholdValue)); | 111 thresholds.append(static_cast<float>(thresholdValue)); |
| 112 } | 112 } |
| 113 | 113 |
| 114 for (auto thresholdValue : thresholds) { | 114 for (auto thresholdValue : thresholds) { |
| 115 if (std::isnan(thresholdValue) || thresholdValue < 0.0 || thresholdValue
> 1.0) { | 115 if (std::isnan(thresholdValue) || thresholdValue < 0.0 || thresholdValue
> 1.0) { |
| 116 exceptionState.throwRangeError("Threshold values must be numbers bet
ween 0 and 1"); | 116 exceptionState.throwRangeError("Threshold values must be numbers bet
ween 0 and 1"); |
| 117 break; | 117 break; |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 141 ExecutionContext* context = callback.getExecutionContext(); | 141 ExecutionContext* context = callback.getExecutionContext(); |
| 142 DCHECK(context->isDocument()); | 142 DCHECK(context->isDocument()); |
| 143 root = getRootNode(toDocument(context)); | 143 root = getRootNode(toDocument(context)); |
| 144 } | 144 } |
| 145 if (!root) { | 145 if (!root) { |
| 146 exceptionState.throwDOMException(HierarchyRequestError, "Unable to get r
oot node in main frame to track."); | 146 exceptionState.throwDOMException(HierarchyRequestError, "Unable to get r
oot node in main frame to track."); |
| 147 return nullptr; | 147 return nullptr; |
| 148 } | 148 } |
| 149 | 149 |
| 150 Vector<Length> rootMargin; | 150 Vector<Length> rootMargin; |
| 151 if (observerInit.hasRootMargin()) | 151 parseRootMargin(observerInit.rootMargin(), rootMargin, exceptionState); |
| 152 parseRootMargin(observerInit.rootMargin(), rootMargin, exceptionState); | |
| 153 if (exceptionState.hadException()) | 152 if (exceptionState.hadException()) |
| 154 return nullptr; | 153 return nullptr; |
| 155 | 154 |
| 156 Vector<float> thresholds; | 155 Vector<float> thresholds; |
| 157 if (observerInit.hasThreshold()) | 156 parseThresholds(observerInit.threshold(), thresholds, exceptionState); |
| 158 parseThresholds(observerInit.threshold(), thresholds, exceptionState); | |
| 159 else | |
| 160 thresholds.append(0); | |
| 161 if (exceptionState.hadException()) | 157 if (exceptionState.hadException()) |
| 162 return nullptr; | 158 return nullptr; |
| 163 | 159 |
| 164 return new IntersectionObserver(callback, *root, rootMargin, thresholds); | 160 return new IntersectionObserver(callback, *root, rootMargin, thresholds); |
| 165 } | 161 } |
| 166 | 162 |
| 167 IntersectionObserver* IntersectionObserver::create(const Vector<Length>& rootMar
gin, const Vector<float>& thresholds, Document* document, std::unique_ptr<EventC
allback> callback, ExceptionState& exceptionState) | 163 IntersectionObserver* IntersectionObserver::create(const Vector<Length>& rootMar
gin, const Vector<float>& thresholds, Document* document, std::unique_ptr<EventC
allback> callback, ExceptionState& exceptionState) |
| 168 { | 164 { |
| 169 Node* root = getRootNode(document); | 165 Node* root = getRootNode(document); |
| 170 if (!root) { | 166 if (!root) { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 | 403 |
| 408 DEFINE_TRACE(IntersectionObserver) | 404 DEFINE_TRACE(IntersectionObserver) |
| 409 { | 405 { |
| 410 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs
erver::clearWeakMembers>(this); | 406 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs
erver::clearWeakMembers>(this); |
| 411 visitor->trace(m_callback); | 407 visitor->trace(m_callback); |
| 412 visitor->trace(m_observations); | 408 visitor->trace(m_observations); |
| 413 visitor->trace(m_entries); | 409 visitor->trace(m_entries); |
| 414 } | 410 } |
| 415 | 411 |
| 416 } // namespace blink | 412 } // namespace blink |
| OLD | NEW |