Changeset 234761 in webkit
- Timestamp:
- Aug 10, 2018 10:08:44 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r234756 r234761 1 2018-08-10 Ali Juma <ajuma@chromium.org> 2 3 [IntersectionObserver] Implement rootMargin parsing 4 https://bugs.webkit.org/show_bug.cgi?id=188469 5 6 Reviewed by Darin Adler. 7 8 * intersection-observer/intersection-observer-interface-expected.txt: 9 * intersection-observer/intersection-observer-interface.html: 10 1 11 2018-08-10 Joseph Pecoraro <pecoraro@apple.com> 2 12 -
trunk/LayoutTests/imported/w3c/ChangeLog
r234723 r234761 1 2018-08-10 Ali Juma <ajuma@chromium.org> 2 3 [IntersectionObserver] Implement rootMargin parsing 4 https://bugs.webkit.org/show_bug.cgi?id=188469 5 6 Reviewed by Darin Adler. 7 8 Update expectations for newly passing test cases. 9 10 * web-platform-tests/intersection-observer/observer-attributes-expected.txt: 11 * web-platform-tests/intersection-observer/observer-exceptions-expected.txt: 12 1 13 2018-08-09 Ali Juma <ajuma@chromium.org> 2 14 -
trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-attributes-expected.txt
r234723 r234761 3 3 PASS observer.root 4 4 PASS observer.thresholds 5 FAIL observer.rootMargin assert_equals: expected "0px 0px 0px 0px" but got "0px" 5 PASS observer.rootMargin 6 6 PASS set observer.root 7 7 PASS set observer.thresholds 8 FAIL set observer.rootMargin assert_equals: expected "10% 20px 10% 20px" but got "10% 20px" 8 PASS set observer.rootMargin 9 9 -
trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions-expected.txt
r234723 r234761 4 4 }" did not throw 5 5 PASS IntersectionObserver constructor with { threshold: ["foo"] } 6 FAIL IntersectionObserver constructor witth { rootMargin: "1" } assert_throws: function "function () { 7 new IntersectionObserver(e => {}, {rootMargin: "1"}) 8 }" did not throw 9 FAIL IntersectionObserver constructor with { rootMargin: "2em" } assert_throws: function "function () { 10 new IntersectionObserver(e => {}, {rootMargin: "2em"}) 11 }" did not throw 12 FAIL IntersectionObserver constructor with { rootMargin: "auto" } assert_throws: function "function () { 13 new IntersectionObserver(e => {}, {rootMargin: "auto"}) 14 }" did not throw 15 FAIL IntersectionObserver constructor with { rootMargin: "calc(1px + 2px)" } assert_throws: function "function () { 16 new IntersectionObserver(e => {}, {rootMargin: "calc(1px + 2px)"}) 17 }" did not throw 18 FAIL IntersectionObserver constructor with { rootMargin: "1px !important" } assert_throws: function "function () { 19 new IntersectionObserver(e => {}, {rootMargin: "1px !important"}) 20 }" did not throw 21 FAIL IntersectionObserver constructor with { rootMargin: "1px 1px 1px 1px 1px" } assert_throws: function "function () { 22 new IntersectionObserver(e => {}, {rootMargin: "1px 1px 1px 1px 1px"}) 23 }" did not throw 6 PASS IntersectionObserver constructor witth { rootMargin: "1" } 7 PASS IntersectionObserver constructor with { rootMargin: "2em" } 8 PASS IntersectionObserver constructor with { rootMargin: "auto" } 9 PASS IntersectionObserver constructor with { rootMargin: "calc(1px + 2px)" } 10 PASS IntersectionObserver constructor with { rootMargin: "1px !important" } 11 PASS IntersectionObserver constructor with { rootMargin: "1px 1px 1px 1px 1px" } 24 12 PASS IntersectionObserver.observe("foo") 25 13 -
trunk/LayoutTests/intersection-observer/intersection-observer-interface-expected.txt
r208181 r234761 4 4 PASS DefaultRoot 5 5 PASS DefaultThresholds 6 PASS ExplicitRootMargin 6 PASS ExplicitOneArgumentRootMargin 7 PASS ExplicitTwoArgumentRootMargin 8 PASS ExplicitThreeArgumentRootMargin 9 PASS ExplicitFourArgumentRootMargin 7 10 PASS ExplicitRoot 8 11 PASS ExplicitThreshold -
trunk/LayoutTests/intersection-observer/intersection-observer-interface.html
r208983 r234761 16 16 test(function() { 17 17 var observer = new IntersectionObserver(function() {}); 18 assert_equals(observer.rootMargin, '0px ');18 assert_equals(observer.rootMargin, '0px 0px 0px 0px'); 19 19 },'DefaultRootMargin'); 20 20 test(function() { … … 27 27 },'DefaultThresholds'); 28 28 test(function() { 29 var observer = new IntersectionObserver(function() {}, { rootMargin: '33em 10px -120px 3pt' }); 30 assert_equals(observer.rootMargin, '33em 10px -120px 3pt'); 31 },'ExplicitRootMargin'); 29 var observer = new IntersectionObserver(function() {}, { rootMargin: '33%' }); 30 assert_equals(observer.rootMargin, '33% 33% 33% 33%'); 31 },'ExplicitOneArgumentRootMargin'); 32 test(function() { 33 var observer = new IntersectionObserver(function() {}, { rootMargin: '33% 10px' }); 34 assert_equals(observer.rootMargin, '33% 10px 33% 10px'); 35 },'ExplicitTwoArgumentRootMargin'); 36 test(function() { 37 var observer = new IntersectionObserver(function() {}, { rootMargin: '33% 10px -120px' }); 38 assert_equals(observer.rootMargin, '33% 10px -120px 10px'); 39 },'ExplicitThreeArgumentRootMargin'); 40 test(function() { 41 var observer = new IntersectionObserver(function() {}, { rootMargin: '33% 10px -120px 3%' }); 42 assert_equals(observer.rootMargin, '33% 10px -120px 3%'); 43 },'ExplicitFourArgumentRootMargin'); 32 44 test(function() { 33 45 var observer = new IntersectionObserver(function() {}, { root: document.body }); -
trunk/Source/WebCore/ChangeLog
r234747 r234761 1 2018-08-10 Ali Juma <ajuma@chromium.org> 2 3 [IntersectionObserver] Implement rootMargin parsing 4 https://bugs.webkit.org/show_bug.cgi?id=188469 5 6 Reviewed by Darin Adler. 7 8 Parse IntersectionObserver's rootMargin argument and throw an exception if it's invalid. 9 Change the stored rootMargin from a String to a LengthBox so that future patches can 10 use this value in intersection logic. 11 12 Tested by: imported/w3c/web-platform-tests/intersection-observer/observer-attributes.html 13 imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html 14 intersection-observer/intersection-observer-interface.html 15 16 * page/IntersectionObserver.cpp: 17 (WebCore::parseRootMargin): 18 (WebCore::IntersectionObserver::create): 19 (WebCore::IntersectionObserver::IntersectionObserver): 20 (WebCore::IntersectionObserver::rootMargin const): 21 * page/IntersectionObserver.h: 22 (WebCore::IntersectionObserver::create): Deleted. 23 (WebCore::IntersectionObserver::rootMargin const): Deleted. 24 * page/IntersectionObserver.idl: 25 1 26 2018-08-09 Ben Richards <benton_richards@apple.com> 2 27 -
trunk/Source/WebCore/page/IntersectionObserver.cpp
r208181 r234761 29 29 #include "IntersectionObserver.h" 30 30 31 #include "CSSParserTokenRange.h" 32 #include "CSSPropertyParserHelpers.h" 33 #include "CSSTokenizer.h" 31 34 #include "Element.h" 32 35 #include "IntersectionObserverCallback.h" … … 36 39 namespace WebCore { 37 40 38 IntersectionObserver::IntersectionObserver(Ref<IntersectionObserverCallback>&& callback, Init&& init) 41 static ExceptionOr<LengthBox> parseRootMargin(String& rootMargin) 42 { 43 CSSTokenizer tokenizer(rootMargin); 44 auto tokenRange = tokenizer.tokenRange(); 45 Vector<Length, 4> margins; 46 while (!tokenRange.atEnd()) { 47 if (margins.size() == 4) 48 return Exception { SyntaxError, "Failed to construct 'IntersectionObserver': Extra text found at the end of rootMargin." }; 49 RefPtr<CSSPrimitiveValue> parsedValue = CSSPropertyParserHelpers::consumeLengthOrPercent(tokenRange, HTMLStandardMode, ValueRangeAll); 50 if (!parsedValue || parsedValue->isCalculated()) 51 return Exception { SyntaxError, "Failed to construct 'IntersectionObserver': rootMargin must be specified in pixels or percent." }; 52 if (parsedValue->isPercentage()) 53 margins.append(Length(parsedValue->doubleValue(), Percent)); 54 else if (parsedValue->isPx()) 55 margins.append(Length(parsedValue->intValue(), Fixed)); 56 else 57 return Exception { SyntaxError, "Failed to construct 'IntersectionObserver': rootMargin must be specified in pixels or percent." }; 58 } 59 switch (margins.size()) { 60 case 0: 61 for (unsigned i = 0; i < 4; ++i) 62 margins.append(Length()); 63 break; 64 case 1: 65 for (unsigned i = 0; i < 3; ++i) 66 margins.append(margins[0]); 67 break; 68 case 2: 69 margins.append(margins[0]); 70 margins.append(margins[1]); 71 break; 72 case 3: 73 margins.append(margins[1]); 74 break; 75 case 4: 76 break; 77 default: 78 ASSERT_NOT_REACHED(); 79 } 80 81 return LengthBox(WTFMove(margins[0]), WTFMove(margins[1]), WTFMove(margins[2]), WTFMove(margins[3])); 82 } 83 84 ExceptionOr<Ref<IntersectionObserver>> IntersectionObserver::create(Ref<IntersectionObserverCallback>&& callback, IntersectionObserver::Init&& init) 85 { 86 auto rootMarginOrException = parseRootMargin(init.rootMargin); 87 if (rootMarginOrException.hasException()) 88 return rootMarginOrException.releaseException(); 89 90 return adoptRef(*new IntersectionObserver(WTFMove(callback), WTFMove(init), rootMarginOrException.releaseReturnValue())); 91 } 92 93 IntersectionObserver::IntersectionObserver(Ref<IntersectionObserverCallback>&& callback, Init&& init, LengthBox&& parsedRootMargin) 39 94 : m_root(init.root) 40 , m_rootMargin(WTFMove( init.rootMargin))95 , m_rootMargin(WTFMove(parsedRootMargin)) 41 96 , m_callback(WTFMove(callback)) 42 97 { … … 45 100 else 46 101 m_thresholds = WTF::get<Vector<double>>(WTFMove(init.threshold)); 102 } 103 104 String IntersectionObserver::rootMargin() const 105 { 106 StringBuilder stringBuilder; 107 PhysicalBoxSide sides[4] = { PhysicalBoxSide::Top, PhysicalBoxSide::Right, PhysicalBoxSide::Bottom, PhysicalBoxSide::Left }; 108 for (auto side : sides) { 109 auto& length = m_rootMargin.at(side); 110 stringBuilder.appendNumber(length.intValue()); 111 if (length.type() == Percent) 112 stringBuilder.append('%'); 113 else 114 stringBuilder.append("px", 2); 115 if (side != PhysicalBoxSide::Left) 116 stringBuilder.append(' '); 117 } 118 return stringBuilder.toString(); 47 119 } 48 120 -
trunk/Source/WebCore/page/IntersectionObserver.h
r211406 r234761 30 30 #include "IntersectionObserverCallback.h" 31 31 #include "IntersectionObserverEntry.h" 32 #include "LengthBox.h" 32 33 #include <wtf/RefCounted.h> 33 34 #include <wtf/Variant.h> … … 46 47 }; 47 48 48 static Ref<IntersectionObserver> create(Ref<IntersectionObserverCallback>&& callback, Init&& init) 49 { 50 return adoptRef(*new IntersectionObserver(WTFMove(callback), WTFMove(init))); 51 } 49 static ExceptionOr<Ref<IntersectionObserver>> create(Ref<IntersectionObserverCallback>&&, Init&&); 52 50 53 51 Element* root() const { return m_root.get(); } 54 String rootMargin() const { return m_rootMargin; }52 String rootMargin() const; 55 53 const Vector<double>& thresholds() const { return m_thresholds; } 56 54 … … 62 60 63 61 private: 64 IntersectionObserver(Ref<IntersectionObserverCallback>&&, Init&& );62 IntersectionObserver(Ref<IntersectionObserverCallback>&&, Init&&, LengthBox&& parsedRootMargin); 65 63 66 64 RefPtr<Element> m_root; 67 Stringm_rootMargin;65 LengthBox m_rootMargin; 68 66 Vector<double> m_thresholds; 69 67 Ref<IntersectionObserverCallback> m_callback; -
trunk/Source/WebCore/page/IntersectionObserver.idl
r208983 r234761 28 28 [ 29 29 Conditional=INTERSECTION_OBSERVER, 30 ConstructorMayThrowException, 30 31 Constructor(IntersectionObserverCallback callback, optional IntersectionObserverInit options), 31 32 ImplementationLacksVTable,
Note: See TracChangeset
for help on using the changeset viewer.