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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 | 57 |
58 private: | 58 private: |
59 WeakMember<ExecutionContext> m_context; | 59 WeakMember<ExecutionContext> m_context; |
60 std::unique_ptr<IntersectionObserver::EventCallback> m_callback; | 60 std::unique_ptr<IntersectionObserver::EventCallback> m_callback; |
61 }; | 61 }; |
62 | 62 |
63 void parseRootMargin(String rootMarginParameter, | 63 void parseRootMargin(String rootMarginParameter, |
64 Vector<Length>& rootMargin, | 64 Vector<Length>& rootMargin, |
65 ExceptionState& exceptionState) { | 65 ExceptionState& exceptionState) { |
66 // TODO(szager): Make sure this exact syntax and behavior is spec-ed somewhere
. | 66 // TODO(szager): Make sure this exact syntax and behavior is spec-ed |
| 67 // somewhere. |
67 | 68 |
68 // The root margin argument accepts syntax similar to that for CSS margin: | 69 // The root margin argument accepts syntax similar to that for CSS margin: |
69 // | 70 // |
70 // "1px" = top/right/bottom/left | 71 // "1px" = top/right/bottom/left |
71 // "1px 2px" = top/bottom left/right | 72 // "1px 2px" = top/bottom left/right |
72 // "1px 2px 3px" = top left/right bottom | 73 // "1px 2px 3px" = top left/right bottom |
73 // "1px 2px 3px 4px" = top left right bottom | 74 // "1px 2px 3px 4px" = top left right bottom |
74 CSSTokenizer::Scope tokenizerScope(rootMarginParameter); | 75 CSSTokenizer::Scope tokenizerScope(rootMarginParameter); |
75 CSSParserTokenRange tokenRange = tokenizerScope.tokenRange(); | 76 CSSParserTokenRange tokenRange = tokenizerScope.tokenRange(); |
76 while (tokenRange.peek().type() != EOFToken && | 77 while (tokenRange.peek().type() != EOFToken && |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 static LayoutUnit computeMargin(const Length& length, | 398 static LayoutUnit computeMargin(const Length& length, |
398 LayoutUnit referenceLength) { | 399 LayoutUnit referenceLength) { |
399 if (length.type() == Percent) | 400 if (length.type() == Percent) |
400 return LayoutUnit( | 401 return LayoutUnit( |
401 static_cast<int>(referenceLength.toFloat() * length.percent() / 100.0)); | 402 static_cast<int>(referenceLength.toFloat() * length.percent() / 100.0)); |
402 DCHECK_EQ(length.type(), Fixed); | 403 DCHECK_EQ(length.type(), Fixed); |
403 return LayoutUnit(length.intValue()); | 404 return LayoutUnit(length.intValue()); |
404 } | 405 } |
405 | 406 |
406 void IntersectionObserver::applyRootMargin(LayoutRect& rect) const { | 407 void IntersectionObserver::applyRootMargin(LayoutRect& rect) const { |
407 // TODO(szager): Make sure the spec is clear that left/right margins are resol
ved against | 408 // TODO(szager): Make sure the spec is clear that left/right margins are |
408 // width and not height. | 409 // resolved against width and not height. |
409 LayoutUnit topMargin = computeMargin(m_topMargin, rect.height()); | 410 LayoutUnit topMargin = computeMargin(m_topMargin, rect.height()); |
410 LayoutUnit rightMargin = computeMargin(m_rightMargin, rect.width()); | 411 LayoutUnit rightMargin = computeMargin(m_rightMargin, rect.width()); |
411 LayoutUnit bottomMargin = computeMargin(m_bottomMargin, rect.height()); | 412 LayoutUnit bottomMargin = computeMargin(m_bottomMargin, rect.height()); |
412 LayoutUnit leftMargin = computeMargin(m_leftMargin, rect.width()); | 413 LayoutUnit leftMargin = computeMargin(m_leftMargin, rect.width()); |
413 | 414 |
414 rect.setX(rect.x() - leftMargin); | 415 rect.setX(rect.x() - leftMargin); |
415 rect.setWidth(rect.width() + leftMargin + rightMargin); | 416 rect.setWidth(rect.width() + leftMargin + rightMargin); |
416 rect.setY(rect.y() - topMargin); | 417 rect.setY(rect.y() - topMargin); |
417 rect.setHeight(rect.height() + topMargin + bottomMargin); | 418 rect.setHeight(rect.height() + topMargin + bottomMargin); |
418 } | 419 } |
(...skipping 16 matching lines...) Expand all Loading... |
435 | 436 |
436 DEFINE_TRACE(IntersectionObserver) { | 437 DEFINE_TRACE(IntersectionObserver) { |
437 visitor->template registerWeakMembers< | 438 visitor->template registerWeakMembers< |
438 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); | 439 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); |
439 visitor->trace(m_callback); | 440 visitor->trace(m_callback); |
440 visitor->trace(m_observations); | 441 visitor->trace(m_observations); |
441 visitor->trace(m_entries); | 442 visitor->trace(m_entries); |
442 } | 443 } |
443 | 444 |
444 } // namespace blink | 445 } // namespace blink |
OLD | NEW |