Changeset 200907 in webkit
- Timestamp:
- May 13, 2016 7:10:27 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r200889 r200907 1 2016-05-13 Chris Dumez <cdumez@apple.com> 2 3 Align window.scroll() / scrollTo() / scrollBy() with the CSSOM specification 4 https://bugs.webkit.org/show_bug.cgi?id=157666 5 6 Reviewed by Darin Adler. 7 8 Update / improve testing coverage for the API. 9 10 * fast/dom/Window/window-scroll-arguments-expected.txt: 11 * fast/dom/Window/window-scroll-arguments.html: 12 * fast/dom/non-numeric-values-numeric-parameters-expected.txt: 13 * fast/dom/script-tests/non-numeric-values-numeric-parameters.js: 14 1 15 2016-05-13 Simon Fraser <simon.fraser@apple.com> 2 16 -
trunk/LayoutTests/fast/dom/Window/window-scroll-arguments-expected.txt
r100163 r200907 1 This test makes sure that calling the window scrolling methods with less than 2 arguments treats the missing arguments as 0.1 This tests calling the window scrolling with only 1 argument 2 2 3 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". … … 10 10 PASS window.scrollX is resetX 11 11 PASS window.scrollY is resetY 12 Testing - scrollTo with 1 argument 13 PASS window.scrollX is resetX + x 12 PASS window.scrollX is x 13 PASS window.scrollY is y 14 Testing - scrollTo with 1 non-dictionary argument 15 PASS scrollTo(0) threw exception TypeError: Type error. 16 Testing - scrollTo with 1 dictionary argument 17 PASS window.scrollX is x 14 18 PASS window.scrollY is resetY 19 PASS window.scrollX is resetX 20 PASS window.scrollY is y 21 PASS window.scrollX is x 22 PASS window.scrollY is y 23 PASS window.scrollX is 0 24 PASS window.scrollY is 0 15 25 Testing - scrollTo with more than 2 arguments 16 26 PASS window.scrollX is x … … 22 32 PASS window.scrollX is resetX 23 33 PASS window.scrollY is resetY 24 Testing - scroll with 1 argument 25 PASS window.scrollX is resetX + x 34 PASS window.scrollX is x 35 PASS window.scrollY is y 36 Testing - scroll with 1 non-dictionary argument 37 PASS scroll(0) threw exception TypeError: Type error. 38 Testing - scroll with 1 dictionary argument 39 PASS window.scrollX is x 26 40 PASS window.scrollY is resetY 41 PASS window.scrollX is resetX 42 PASS window.scrollY is y 43 PASS window.scrollX is x 44 PASS window.scrollY is y 45 PASS window.scrollX is 0 46 PASS window.scrollY is 0 27 47 Testing - scroll with more than 2 arguments 28 48 PASS window.scrollX is x … … 34 54 PASS window.scrollX is resetX 35 55 PASS window.scrollY is resetY 56 PASS window.scrollX is x 57 PASS window.scrollY is y 58 Testing - scrollBy with 1 non-dictionary argument 59 PASS scrollBy(0) threw exception TypeError: Type error. 36 60 Testing - scrollBy with 1 argument 37 61 PASS window.scrollX is resetX + x 38 62 PASS window.scrollY is resetY 63 PASS window.scrollX is resetX 64 PASS window.scrollY is resetY + y 65 PASS window.scrollX is resetX + x 66 PASS window.scrollY is resetY + y 67 PASS window.scrollX is resetX + x 68 PASS window.scrollY is resetY + y 39 69 Testing - scrollBy with more than 2 arguments 40 70 PASS window.scrollX is resetX + x -
trunk/LayoutTests/fast/dom/Window/window-scroll-arguments.html
r155265 r200907 25 25 reset(); 26 26 27 description("This test makes sure that calling the window scrolling\ 28 methods with less than 2 arguments treats the missing arguments as 0."); 27 description("This tests calling the window scrolling with only 1 argument"); 29 28 30 29 // scrollTo ///////////////////////// … … 38 37 shouldBe('window.scrollY', 'resetY'); 39 38 reset(); 39 window.scrollTo(x, y); 40 window.scrollTo(); 41 shouldBe('window.scrollX', 'x'); 42 shouldBe('window.scrollY', 'y'); 43 reset(); 40 44 41 debug("Testing - scrollTo with 1 argument"); 42 window.scrollTo(x); 43 shouldBe('window.scrollX', 'resetX + x'); 45 debug("Testing - scrollTo with 1 non-dictionary argument"); 46 shouldThrow("scrollTo(0)"); 47 reset(); 48 49 debug("Testing - scrollTo with 1 dictionary argument"); 50 window.scrollTo({ left: x }); 51 shouldBe('window.scrollX', 'x'); 44 52 shouldBe('window.scrollY', 'resetY'); 53 reset(); 54 window.scrollTo({ top: y }); 55 shouldBe('window.scrollX', 'resetX'); 56 shouldBe('window.scrollY', 'y'); 57 reset(); 58 window.scrollTo({ left: x, top: y }); 59 shouldBe('window.scrollX', 'x'); 60 shouldBe('window.scrollY', 'y'); 61 reset(); 62 window.scrollTo(x, y); 63 window.scrollTo({ left: NaN, top: NaN }); 64 shouldBe('window.scrollX', '0'); 65 shouldBe('window.scrollY', '0'); 45 66 reset(); 46 67 … … 61 82 shouldBe('window.scrollY', 'resetY'); 62 83 reset(); 84 window.scroll(x, y); 85 window.scroll(); 86 shouldBe('window.scrollX', 'x'); 87 shouldBe('window.scrollY', 'y'); 88 reset(); 63 89 64 debug("Testing - scroll with 1 argument"); 65 window.scroll(x); 66 shouldBe('window.scrollX', 'resetX + x'); 90 debug("Testing - scroll with 1 non-dictionary argument"); 91 shouldThrow("scroll(0)"); 92 reset(); 93 94 debug("Testing - scroll with 1 dictionary argument"); 95 window.scroll({ left: x }); 96 shouldBe('window.scrollX', 'x'); 67 97 shouldBe('window.scrollY', 'resetY'); 98 reset(); 99 window.scroll({ top: y }); 100 shouldBe('window.scrollX', 'resetX'); 101 shouldBe('window.scrollY', 'y'); 102 reset(); 103 window.scroll({ left: x, top: y }); 104 shouldBe('window.scrollX', 'x'); 105 shouldBe('window.scrollY', 'y'); 106 reset(); 107 window.scroll(x, y); 108 window.scroll({ left: NaN, top: NaN }); 109 shouldBe('window.scrollX', '0'); 110 shouldBe('window.scrollY', '0'); 68 111 reset(); 69 112 … … 84 127 shouldBe('window.scrollY', 'resetY'); 85 128 reset(); 129 window.scrollBy(x, y); 130 window.scrollBy(); 131 shouldBe('window.scrollX', 'x'); 132 shouldBe('window.scrollY', 'y'); 133 reset(); 134 135 debug("Testing - scrollBy with 1 non-dictionary argument"); 136 shouldThrow("scrollBy(0)"); 137 reset(); 86 138 87 139 debug("Testing - scrollBy with 1 argument"); 88 window.scrollBy( x);140 window.scrollBy({ left: x }); 89 141 shouldBe('window.scrollX', 'resetX + x'); 90 142 shouldBe('window.scrollY', 'resetY'); 143 reset(); 144 window.scrollBy({ top: y }); 145 shouldBe('window.scrollX', 'resetX'); 146 shouldBe('window.scrollY', 'resetY + y'); 147 reset(); 148 window.scrollBy({ left: x, top: y }); 149 shouldBe('window.scrollX', 'resetX + x'); 150 shouldBe('window.scrollY', 'resetY + y'); 151 reset(); 152 window.scrollBy(x, y); 153 window.scrollBy({ left: NaN, top: NaN }); 154 shouldBe('window.scrollX', 'resetX + x'); 155 shouldBe('window.scrollY', 'resetY + y'); 91 156 reset(); 92 157 -
trunk/LayoutTests/fast/dom/non-numeric-values-numeric-parameters-expected.txt
r189676 r200907 67 67 PASS nonNumericPolicy('document.createEvent("UIEvent").initUIEvent("a", false, false, null, x)') is 'any type allowed' 68 68 PASS nonNumericPolicy('window.scrollBy(x, 0)') is 'any type allowed' 69 PASS nonNumericPolicy('window.scrollBy(0, x)') is 'any type allowed '69 PASS nonNumericPolicy('window.scrollBy(0, x)') is 'any type allowed (but not omitted)' 70 70 PASS nonNumericPolicy('window.scrollTo(x, 0)') is 'any type allowed' 71 PASS nonNumericPolicy('window.scrollTo(0, x)') is 'any type allowed '71 PASS nonNumericPolicy('window.scrollTo(0, x)') is 'any type allowed (but not omitted)' 72 72 PASS nonNumericPolicy('window.scroll(x, 0)') is 'any type allowed' 73 PASS nonNumericPolicy('window.scroll(0, x)') is 'any type allowed '73 PASS nonNumericPolicy('window.scroll(0, x)') is 'any type allowed (but not omitted)' 74 74 PASS nonNumericPolicy('window.moveBy(x, 0)') is 'any type allowed' 75 75 PASS nonNumericPolicy('window.moveBy(0, x)') is 'any type allowed' -
trunk/LayoutTests/fast/dom/script-tests/non-numeric-values-numeric-parameters.js
r189676 r200907 345 345 346 346 shouldBe("nonNumericPolicy('window.scrollBy(x, 0)')", "'any type allowed'"); 347 shouldBe("nonNumericPolicy('window.scrollBy(0, x)')", "'any type allowed '");347 shouldBe("nonNumericPolicy('window.scrollBy(0, x)')", "'any type allowed (but not omitted)'"); 348 348 shouldBe("nonNumericPolicy('window.scrollTo(x, 0)')", "'any type allowed'"); 349 shouldBe("nonNumericPolicy('window.scrollTo(0, x)')", "'any type allowed '");349 shouldBe("nonNumericPolicy('window.scrollTo(0, x)')", "'any type allowed (but not omitted)'"); 350 350 shouldBe("nonNumericPolicy('window.scroll(x, 0)')", "'any type allowed'"); 351 shouldBe("nonNumericPolicy('window.scroll(0, x)')", "'any type allowed '");351 shouldBe("nonNumericPolicy('window.scroll(0, x)')", "'any type allowed (but not omitted)'"); 352 352 shouldBe("nonNumericPolicy('window.moveBy(x, 0)')", "'any type allowed'"); 353 353 shouldBe("nonNumericPolicy('window.moveBy(0, x)')", "'any type allowed'"); -
trunk/Source/WebCore/ChangeLog
r200901 r200907 1 2016-05-13 Chris Dumez <cdumez@apple.com> 2 3 Align window.scroll() / scrollTo() / scrollBy() with the CSSOM specification 4 https://bugs.webkit.org/show_bug.cgi?id=157666 5 6 Reviewed by Darin Adler. 7 8 Align window.scroll() / scrollTo() / scrollBy() with Firefox and the CSSOM 9 specification: 10 https://drafts.csswg.org/cssom-view/#extensions-to-the-window-interface 11 12 In particular, the following changes were made: 13 1. Make parameters to scroll() / scrollTo() / scrollBy() mandatory. 14 2. Add overloads for scroll() / scrollTo() / scrollBy() that take an 15 optional ScrollToOptions dictionary. 16 3. Update API to use "unrestricted double" typing for x/y instead of 17 "long". This matches the specification but it does not really change 18 our behavior at this point because the values are still casted to 19 int in our implementation. 20 21 Web-Exposed behavior changes: 22 1. JS can now pass a dictionary to scroll() / scrollTo() / scrollBy(). 23 This a new feature that Firefox already supports (Chrome does not). 24 2. Passing only 1 parameter to scroll() / scrollTo() / scrollBy() that 25 is not a dictionary will now throw a TypeError. The compatibility 26 risky should be low because Firefox and Chrome already throw in this 27 case (Chrome has been throwing for 2 years and a half). 28 3. Calling scrollTo() / scroll() without any parameter no longer 29 scrolls to 0. Instead we use the current viewport's x/y which means 30 we don't scroll at all. The new behavior matches Firefox, Chrome and 31 IE 11. This fixes scrolling on the following Website: 32 https://members.chosun.com/cms_subscribe/application/index.jsp 33 34 No new tests, extended existing testing. 35 36 * bindings/js/JSDOMConvert.h: 37 (WebCore::convert): 38 (WebCore::convertOptional): 39 * bindings/scripts/CodeGeneratorJS.pm: 40 (ShouldAllowNonFiniteForFloatingPointType): 41 (GenerateConversionRuleWithLeadingComma): 42 (GenerateDictionaryImplementationContent): 43 (JSValueToNative): 44 * bindings/scripts/test/JS/JSTestObj.cpp: 45 (WebCore::convert<TestObj::Dictionary>): 46 * bindings/scripts/test/TestObj.idl: 47 * page/DOMWindow.cpp: 48 (WebCore::DOMWindow::scrollBy): 49 (WebCore::DOMWindow::scrollTo): 50 * page/DOMWindow.h: 51 * page/DOMWindow.idl: 52 1 53 2016-05-13 Commit Queue <commit-queue@webkit.org> 2 54 -
trunk/Source/WebCore/bindings/js/JSDOMConvert.h
r200607 r200907 33 33 enum class ShouldAllowNonFinite { No, Yes }; 34 34 35 template<typename T > struct Converter;35 template<typename T, typename Enable = void> struct Converter; 36 36 37 37 template<typename T> T convert(JSC::ExecState&, JSC::JSValue); … … 42 42 template<typename T, typename U> T convertOptional(JSC::ExecState&, JSC::JSValue, U&& defaultValue); 43 43 44 template<typename T> typename Converter<T>::OptionalValue convertOptional(JSC::ExecState&, JSC::JSValue, ShouldAllowNonFinite); 45 template<typename T, typename U> T convertOptional(JSC::ExecState&, JSC::JSValue, ShouldAllowNonFinite, U&& defaultValue); 46 44 47 // This is where the implementation of the things declared above begins: 45 48 … … 57 60 { 58 61 static_assert(std::is_same<T, float>::value || std::is_same<T, double>::value, "ShouldAllowNonFinite can only be used with float or double"); 59 double number = value.toNumber(&state); 60 if (allow == ShouldAllowNonFinite::No && UNLIKELY(!std::isfinite(number))) 61 throwNonFiniteTypeError(state); 62 return static_cast<T>(number); 62 return Converter<T>::convert(state, value, allow); 63 63 } 64 64 … … 71 71 { 72 72 return value.isUndefined() ? std::forward<U>(defaultValue) : convert<T>(state, value); 73 } 74 75 template<typename T> typename Converter<T>::OptionalValue inline convertOptional(JSC::ExecState& state, JSC::JSValue value, ShouldAllowNonFinite allow) 76 { 77 return value.isUndefined() ? typename Converter<T>::OptionalValue() : convert<T>(state, value, allow); 78 } 79 80 template<typename T, typename U> inline T convertOptional(JSC::ExecState& state, JSC::JSValue value, ShouldAllowNonFinite allow, U&& defaultValue) 81 { 82 return value.isUndefined() ? std::forward<U>(defaultValue) : convert<T>(state, value, allow); 73 83 } 74 84 … … 77 87 }; 78 88 79 template<typename T > struct Converter : DefaultConverter<T> {89 template<typename T, typename Enable> struct Converter : DefaultConverter<T> { 80 90 }; 81 91 … … 229 239 }; 230 240 241 template<typename T> struct Converter<T, typename std::enable_if<std::is_floating_point<T>::value>::type> : DefaultConverter<T> { 242 static T convert(JSC::ExecState& state, JSC::JSValue value, ShouldAllowNonFinite allow) 243 { 244 double number = value.toNumber(&state); 245 if (allow == ShouldAllowNonFinite::No && UNLIKELY(!std::isfinite(number))) 246 throwNonFiniteTypeError(state); 247 return static_cast<T>(number); 248 } 249 }; 250 231 251 } // namespace WebCore -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r200895 r200907 959 959 } 960 960 961 sub ShouldAllowNonFiniteForFloatingPointType 962 { 963 my $type = shift; 964 965 die "Can only be called with floating point types" unless $codeGenerator->IsFloatingPointType($type); 966 return $type eq "unrestricted double" || $type eq "unrestricted float"; 967 } 968 969 sub GenerateConversionRuleWithLeadingComma 970 { 971 my ($interface, $member) = @_; 972 973 if ($codeGenerator->IsFloatingPointType($member->type)) { 974 return ", " . (ShouldAllowNonFiniteForFloatingPointType($member->type) ? "ShouldAllowNonFinite::Yes" : "ShouldAllowNonFinite::No"); 975 } 976 # FIXME: Add support for integer types. 977 return ""; 978 } 979 961 980 sub GenerateDefaultValueWithLeadingComma 962 981 { … … 1012 1031 # FIXME: Eventually we will want this to share a lot more code with JSValueToNative. 1013 1032 my $function = $member->isOptional ? "convertOptional" : "convert"; 1014 my $defaultValueWithLeadingComma = $member->isOptional && defined $member->default ? ", " . $member->default : "";1015 1033 $result .= " auto " . $member->name . " = " . $function . "<" . GetNativeTypeFromSignature($interface, $member) . ">" 1016 1034 . "(state, object->get(&state, Identifier::fromString(&state, \"" . $member->name . "\"))" 1035 . GenerateConversionRuleWithLeadingComma($interface, $member) 1017 1036 . GenerateDefaultValueWithLeadingComma($interface, $member) . ");\n"; 1018 1037 $needExceptionCheck = 1; … … 4426 4445 if ($codeGenerator->IsFloatingPointType($type)) { 4427 4446 AddToImplIncludes("JSDOMConvert.h"); 4428 return ("convert<double>(*state, $value, ShouldAllowNonFinite::No)", 1) if $type eq "double"; 4429 return ("convert<double>(*state, $value, ShouldAllowNonFinite::Yes)", 1) if $type eq "unrestricted double"; 4430 return ("convert<float>(*state, $value, ShouldAllowNonFinite::No)", 1) if $type eq "float"; 4431 return ("convert<float>(*state, $value, ShouldAllowNonFinite::Yes)", 1) if $type eq "unrestricted float"; 4432 die "Unhandled floating point type: " . $type; 4447 my $allowNonFinite = ShouldAllowNonFiniteForFloatingPointType($type) ? "ShouldAllowNonFinite::Yes" : "ShouldAllowNonFinite::No"; 4448 my $nativeType = GetNativeType($interface, $type); 4449 return ("convert<$nativeType>(*state, $value, $allowNonFinite)", 1); 4433 4450 } 4434 4451 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
r200775 r200907 456 456 { 457 457 if (value.isUndefinedOrNull()) 458 return { { }, TestObj::EnumType::EnumValue1, TestObj::EnumType::EmptyString, "defaultString", { }, false, { }, { } };458 return { { }, TestObj::EnumType::EnumValue1, TestObj::EnumType::EmptyString, "defaultString", { }, false, { }, { }, { }, { }, 0, 0, { }, { }, 0, 0 }; 459 459 auto* object = value.getObject(); 460 460 if (UNLIKELY(!object || object->type() == RegExpObjectType)) { … … 484 484 return { }; 485 485 auto sequenceOfStrings = convertOptional<Vector<String>>(state, object->get(&state, Identifier::fromString(&state, "sequenceOfStrings"))); 486 return { WTFMove(enumerationValueWithoutDefault), WTFMove(enumerationValueWithDefault), WTFMove(enumerationValueWithEmptyStringDefault), WTFMove(stringWithDefault), WTFMove(stringWithoutDefault), WTFMove(booleanWithDefault), WTFMove(booleanWithoutDefault), WTFMove(sequenceOfStrings) }; 486 if (UNLIKELY(state.hadException())) 487 return { }; 488 auto restrictedDouble = convertOptional<double>(state, object->get(&state, Identifier::fromString(&state, "restrictedDouble")), ShouldAllowNonFinite::No); 489 if (UNLIKELY(state.hadException())) 490 return { }; 491 auto unrestrictedDouble = convertOptional<double>(state, object->get(&state, Identifier::fromString(&state, "unrestrictedDouble")), ShouldAllowNonFinite::Yes); 492 if (UNLIKELY(state.hadException())) 493 return { }; 494 auto restrictedDoubleWithDefault = convertOptional<double>(state, object->get(&state, Identifier::fromString(&state, "restrictedDoubleWithDefault")), ShouldAllowNonFinite::No, 0); 495 if (UNLIKELY(state.hadException())) 496 return { }; 497 auto unrestrictedDoubleWithDefault = convertOptional<double>(state, object->get(&state, Identifier::fromString(&state, "unrestrictedDoubleWithDefault")), ShouldAllowNonFinite::Yes, 0); 498 if (UNLIKELY(state.hadException())) 499 return { }; 500 auto restrictedFloat = convertOptional<float>(state, object->get(&state, Identifier::fromString(&state, "restrictedFloat")), ShouldAllowNonFinite::No); 501 if (UNLIKELY(state.hadException())) 502 return { }; 503 auto unrestrictedFloat = convertOptional<float>(state, object->get(&state, Identifier::fromString(&state, "unrestrictedFloat")), ShouldAllowNonFinite::Yes); 504 if (UNLIKELY(state.hadException())) 505 return { }; 506 auto restrictedFloatWithDefault = convertOptional<float>(state, object->get(&state, Identifier::fromString(&state, "restrictedFloatWithDefault")), ShouldAllowNonFinite::No, 0); 507 if (UNLIKELY(state.hadException())) 508 return { }; 509 auto unrestrictedFloatWithDefault = convertOptional<float>(state, object->get(&state, Identifier::fromString(&state, "unrestrictedFloatWithDefault")), ShouldAllowNonFinite::Yes, 0); 510 return { WTFMove(enumerationValueWithoutDefault), WTFMove(enumerationValueWithDefault), WTFMove(enumerationValueWithEmptyStringDefault), WTFMove(stringWithDefault), WTFMove(stringWithoutDefault), WTFMove(booleanWithDefault), WTFMove(booleanWithoutDefault), WTFMove(sequenceOfStrings), WTFMove(restrictedDouble), WTFMove(unrestrictedDouble), WTFMove(restrictedDoubleWithDefault), WTFMove(unrestrictedDoubleWithDefault), WTFMove(restrictedFloat), WTFMove(unrestrictedFloat), WTFMove(restrictedFloatWithDefault), WTFMove(unrestrictedFloatWithDefault) }; 487 511 } 488 512 -
trunk/Source/WebCore/bindings/scripts/test/TestObj.idl
r200607 r200907 392 392 boolean booleanWithoutDefault; 393 393 sequence<DOMString> sequenceOfStrings; 394 double restrictedDouble; 395 unrestricted double unrestrictedDouble; 396 double restrictedDoubleWithDefault = 0; 397 unrestricted double unrestrictedDoubleWithDefault = 0; 398 float restrictedFloat; 399 unrestricted float unrestrictedFloat; 400 float restrictedFloatWithDefault = 0; 401 unrestricted float unrestrictedFloatWithDefault = 0; 394 402 }; 395 403 -
trunk/Source/WebCore/page/DOMWindow.cpp
r200895 r200907 1494 1494 } 1495 1495 1496 void DOMWindow::scrollBy(int x, int y) const 1496 void DOMWindow::scrollBy(const ScrollToOptions& options) const 1497 { 1498 return scrollBy(options.left.valueOr(0), options.top.valueOr(0)); 1499 } 1500 1501 void DOMWindow::scrollBy(double x, double y) const 1497 1502 { 1498 1503 if (!isCurrentlyDisplayedInFrame()) … … 1505 1510 return; 1506 1511 1512 // Normalize non-finite values (https://drafts.csswg.org/cssom-view/#normalize-non-finite-values). 1513 x = std::isfinite(x) ? x : 0; 1514 y = std::isfinite(y) ? y : 0; 1515 1507 1516 IntSize scaledOffset(view->mapFromCSSToLayoutUnits(x), view->mapFromCSSToLayoutUnits(y)); 1508 1517 view->setContentsScrollPosition(view->contentsScrollPosition() + scaledOffset); 1509 1518 } 1510 1519 1511 void DOMWindow::scrollTo(int x, int y) const 1512 { 1513 if (!isCurrentlyDisplayedInFrame()) 1514 return; 1515 1520 void DOMWindow::scrollTo(const ScrollToOptions& options) const 1521 { 1516 1522 RefPtr<FrameView> view = m_frame->view(); 1517 1523 if (!view) 1518 1524 return; 1525 1526 double x = options.left ? options.left.value() : view->contentsScrollPosition().x(); 1527 double y = options.top ? options.top.value() : view->contentsScrollPosition().y(); 1528 return scrollTo(x, y); 1529 } 1530 1531 void DOMWindow::scrollTo(double x, double y) const 1532 { 1533 if (!isCurrentlyDisplayedInFrame()) 1534 return; 1535 1536 RefPtr<FrameView> view = m_frame->view(); 1537 if (!view) 1538 return; 1539 1540 // Normalize non-finite values (https://drafts.csswg.org/cssom-view/#normalize-non-finite-values). 1541 x = std::isfinite(x) ? x : 0; 1542 y = std::isfinite(y) ? y : 0; 1519 1543 1520 1544 if (!x && !y && view->contentsScrollPosition() == IntPoint(0, 0)) -
trunk/Source/WebCore/page/DOMWindow.h
r200789 r200907 249 249 void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, Event&, PassRefPtr<Inspector::ScriptCallStack>); 250 250 251 void scrollBy(int x, int y) const; 252 void scrollTo(int x, int y) const; 253 void scroll(int x, int y) const { scrollTo(x, y); } 251 struct ScrollToOptions { 252 Optional<double> left; 253 Optional<double> top; 254 }; 255 256 void scrollBy(const ScrollToOptions&) const; 257 void scrollBy(double x, double y) const; 258 void scrollTo(const ScrollToOptions&) const; 259 void scrollTo(double x, double y) const; 254 260 255 261 void moveBy(float x, float y) const; -
trunk/Source/WebCore/page/DOMWindow.idl
r200788 r200907 103 103 readonly attribute long pageYOffset; 104 104 105 void scrollBy(optional long x = 0, optional long y = 0); 106 void scrollTo(optional long x = 0, optional long y = 0); 107 void scroll(optional long x = 0, optional long y = 0); 105 void scrollBy(unrestricted double x, unrestricted double y); 106 void scrollTo(unrestricted double x, unrestricted double y); 107 [ImplementedAs=scrollTo] void scroll(unrestricted double x, unrestricted double y); 108 109 #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT 110 void scrollBy(optional ScrollToOptions option); 111 void scrollTo(optional ScrollToOptions options); 112 [ImplementedAs=scrollTo] void scroll(optional ScrollToOptions options); 113 #endif 114 108 115 void moveBy(optional unrestricted float x = NaN, optional unrestricted float y = NaN); // FIXME: this should take longs not floats. 109 116 void moveTo(optional unrestricted float x = NaN, optional unrestricted float y = NaN); // FIXME: this should take longs not floats. … … 218 225 }; 219 226 227 // FIXME: Support ScrollBehavior. 228 dictionary ScrollToOptions { 229 unrestricted double left; 230 unrestricted double top; 231 }; 232 220 233 DOMWindow implements GlobalEventHandlers; 221 234 DOMWindow implements WindowBase64;
Note: See TracChangeset
for help on using the changeset viewer.