Changeset 200907 in webkit


Ignore:
Timestamp:
May 13, 2016 7:10:27 PM (8 years ago)
Author:
Chris Dumez
Message:

Align window.scroll() / scrollTo() / scrollBy() with the CSSOM specification
https://bugs.webkit.org/show_bug.cgi?id=157666

Reviewed by Darin Adler.

Source/WebCore:

Align window.scroll() / scrollTo() / scrollBy() with Firefox and the CSSOM
specification:
https://drafts.csswg.org/cssom-view/#extensions-to-the-window-interface

In particular, the following changes were made:

  1. Make parameters to scroll() / scrollTo() / scrollBy() mandatory.
  2. Add overloads for scroll() / scrollTo() / scrollBy() that take an optional ScrollToOptions dictionary.
  3. Update API to use "unrestricted double" typing for x/y instead of "long". This matches the specification but it does not really change our behavior at this point because the values are still casted to int in our implementation.

Web-Exposed behavior changes:

  1. JS can now pass a dictionary to scroll() / scrollTo() / scrollBy(). This a new feature that Firefox already supports (Chrome does not).
  2. Passing only 1 parameter to scroll() / scrollTo() / scrollBy() that is not a dictionary will now throw a TypeError. The compatibility risky should be low because Firefox and Chrome already throw in this case (Chrome has been throwing for 2 years and a half).
  3. Calling scrollTo() / scroll() without any parameter no longer scrolls to 0. Instead we use the current viewport's x/y which means we don't scroll at all. The new behavior matches Firefox, Chrome and IE 11. This fixes scrolling on the following Website: https://members.chosun.com/cms_subscribe/application/index.jsp

No new tests, extended existing testing.

  • bindings/js/JSDOMConvert.h:

(WebCore::convert):
(WebCore::convertOptional):

  • bindings/scripts/CodeGeneratorJS.pm:

(ShouldAllowNonFiniteForFloatingPointType):
(GenerateConversionRuleWithLeadingComma):
(GenerateDictionaryImplementationContent):
(JSValueToNative):

  • bindings/scripts/test/JS/JSTestObj.cpp:

(WebCore::convert<TestObj::Dictionary>):

  • bindings/scripts/test/TestObj.idl:
  • page/DOMWindow.cpp:

(WebCore::DOMWindow::scrollBy):
(WebCore::DOMWindow::scrollTo):

  • page/DOMWindow.h:
  • page/DOMWindow.idl:

LayoutTests:

Update / improve testing coverage for the API.

  • fast/dom/Window/window-scroll-arguments-expected.txt:
  • fast/dom/Window/window-scroll-arguments.html:
  • fast/dom/non-numeric-values-numeric-parameters-expected.txt:
  • fast/dom/script-tests/non-numeric-values-numeric-parameters.js:
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r200889 r200907  
     12016-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
    1152016-05-13  Simon Fraser  <simon.fraser@apple.com>
    216
  • 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.
     1This tests calling the window scrolling with only 1 argument
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
     
    1010PASS window.scrollX is resetX
    1111PASS window.scrollY is resetY
    12 Testing - scrollTo with 1 argument
    13 PASS window.scrollX is resetX + x
     12PASS window.scrollX is x
     13PASS window.scrollY is y
     14Testing - scrollTo with 1 non-dictionary argument
     15PASS scrollTo(0) threw exception TypeError: Type error.
     16Testing - scrollTo with 1 dictionary argument
     17PASS window.scrollX is x
    1418PASS window.scrollY is resetY
     19PASS window.scrollX is resetX
     20PASS window.scrollY is y
     21PASS window.scrollX is x
     22PASS window.scrollY is y
     23PASS window.scrollX is 0
     24PASS window.scrollY is 0
    1525Testing - scrollTo with more than 2 arguments
    1626PASS window.scrollX is x
     
    2232PASS window.scrollX is resetX
    2333PASS window.scrollY is resetY
    24 Testing - scroll with 1 argument
    25 PASS window.scrollX is resetX + x
     34PASS window.scrollX is x
     35PASS window.scrollY is y
     36Testing - scroll with 1 non-dictionary argument
     37PASS scroll(0) threw exception TypeError: Type error.
     38Testing - scroll with 1 dictionary argument
     39PASS window.scrollX is x
    2640PASS window.scrollY is resetY
     41PASS window.scrollX is resetX
     42PASS window.scrollY is y
     43PASS window.scrollX is x
     44PASS window.scrollY is y
     45PASS window.scrollX is 0
     46PASS window.scrollY is 0
    2747Testing - scroll with more than 2 arguments
    2848PASS window.scrollX is x
     
    3454PASS window.scrollX is resetX
    3555PASS window.scrollY is resetY
     56PASS window.scrollX is x
     57PASS window.scrollY is y
     58Testing - scrollBy with 1 non-dictionary argument
     59PASS scrollBy(0) threw exception TypeError: Type error.
    3660Testing - scrollBy with 1 argument
    3761PASS window.scrollX is resetX + x
    3862PASS window.scrollY is resetY
     63PASS window.scrollX is resetX
     64PASS window.scrollY is resetY + y
     65PASS window.scrollX is resetX + x
     66PASS window.scrollY is resetY + y
     67PASS window.scrollX is resetX + x
     68PASS window.scrollY is resetY + y
    3969Testing - scrollBy with more than 2 arguments
    4070PASS window.scrollX is resetX + x
  • trunk/LayoutTests/fast/dom/Window/window-scroll-arguments.html

    r155265 r200907  
    2525    reset();
    2626
    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");
    2928
    3029    // scrollTo /////////////////////////
     
    3837    shouldBe('window.scrollY', 'resetY');
    3938    reset();
     39    window.scrollTo(x, y);
     40    window.scrollTo();
     41    shouldBe('window.scrollX', 'x');
     42    shouldBe('window.scrollY', 'y');
     43    reset();
    4044
    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');
    4452    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');
    4566    reset();
    4667
     
    6182    shouldBe('window.scrollY', 'resetY');
    6283    reset();
     84    window.scroll(x, y);
     85    window.scroll();
     86    shouldBe('window.scrollX', 'x');
     87    shouldBe('window.scrollY', 'y');
     88    reset();
    6389
    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');
    6797    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');
    68111    reset();
    69112
     
    84127    shouldBe('window.scrollY', 'resetY');
    85128    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();
    86138
    87139    debug("Testing - scrollBy with 1 argument");
    88     window.scrollBy(x);
     140    window.scrollBy({ left: x });
    89141    shouldBe('window.scrollX', 'resetX + x');
    90142    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');
    91156    reset();
    92157
  • trunk/LayoutTests/fast/dom/non-numeric-values-numeric-parameters-expected.txt

    r189676 r200907  
    6767PASS nonNumericPolicy('document.createEvent("UIEvent").initUIEvent("a", false, false, null, x)') is 'any type allowed'
    6868PASS nonNumericPolicy('window.scrollBy(x, 0)') is 'any type allowed'
    69 PASS nonNumericPolicy('window.scrollBy(0, x)') is 'any type allowed'
     69PASS nonNumericPolicy('window.scrollBy(0, x)') is 'any type allowed (but not omitted)'
    7070PASS nonNumericPolicy('window.scrollTo(x, 0)') is 'any type allowed'
    71 PASS nonNumericPolicy('window.scrollTo(0, x)') is 'any type allowed'
     71PASS nonNumericPolicy('window.scrollTo(0, x)') is 'any type allowed (but not omitted)'
    7272PASS nonNumericPolicy('window.scroll(x, 0)') is 'any type allowed'
    73 PASS nonNumericPolicy('window.scroll(0, x)') is 'any type allowed'
     73PASS nonNumericPolicy('window.scroll(0, x)') is 'any type allowed (but not omitted)'
    7474PASS nonNumericPolicy('window.moveBy(x, 0)') is 'any type allowed'
    7575PASS nonNumericPolicy('window.moveBy(0, x)') is 'any type allowed'
  • trunk/LayoutTests/fast/dom/script-tests/non-numeric-values-numeric-parameters.js

    r189676 r200907  
    345345
    346346shouldBe("nonNumericPolicy('window.scrollBy(x, 0)')", "'any type allowed'");
    347 shouldBe("nonNumericPolicy('window.scrollBy(0, x)')", "'any type allowed'");
     347shouldBe("nonNumericPolicy('window.scrollBy(0, x)')", "'any type allowed (but not omitted)'");
    348348shouldBe("nonNumericPolicy('window.scrollTo(x, 0)')", "'any type allowed'");
    349 shouldBe("nonNumericPolicy('window.scrollTo(0, x)')", "'any type allowed'");
     349shouldBe("nonNumericPolicy('window.scrollTo(0, x)')", "'any type allowed (but not omitted)'");
    350350shouldBe("nonNumericPolicy('window.scroll(x, 0)')", "'any type allowed'");
    351 shouldBe("nonNumericPolicy('window.scroll(0, x)')", "'any type allowed'");
     351shouldBe("nonNumericPolicy('window.scroll(0, x)')", "'any type allowed (but not omitted)'");
    352352shouldBe("nonNumericPolicy('window.moveBy(x, 0)')", "'any type allowed'");
    353353shouldBe("nonNumericPolicy('window.moveBy(0, x)')", "'any type allowed'");
  • trunk/Source/WebCore/ChangeLog

    r200901 r200907  
     12016-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
    1532016-05-13  Commit Queue  <commit-queue@webkit.org>
    254
  • trunk/Source/WebCore/bindings/js/JSDOMConvert.h

    r200607 r200907  
    3333enum class ShouldAllowNonFinite { No, Yes };
    3434
    35 template<typename T> struct Converter;
     35template<typename T, typename Enable = void> struct Converter;
    3636
    3737template<typename T> T convert(JSC::ExecState&, JSC::JSValue);
     
    4242template<typename T, typename U> T convertOptional(JSC::ExecState&, JSC::JSValue, U&& defaultValue);
    4343
     44template<typename T> typename Converter<T>::OptionalValue convertOptional(JSC::ExecState&, JSC::JSValue, ShouldAllowNonFinite);
     45template<typename T, typename U> T convertOptional(JSC::ExecState&, JSC::JSValue, ShouldAllowNonFinite, U&& defaultValue);
     46
    4447// This is where the implementation of the things declared above begins:
    4548
     
    5760{
    5861    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);
    6363}
    6464
     
    7171{
    7272    return value.isUndefined() ? std::forward<U>(defaultValue) : convert<T>(state, value);
     73}
     74
     75template<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
     80template<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);
    7383}
    7484
     
    7787};
    7888
    79 template<typename T> struct Converter : DefaultConverter<T> {
     89template<typename T, typename Enable> struct Converter : DefaultConverter<T> {
    8090};
    8191
     
    229239};
    230240
     241template<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
    231251} // namespace WebCore
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r200895 r200907  
    959959}
    960960
     961sub 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
     969sub 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
    961980sub GenerateDefaultValueWithLeadingComma
    962981{
     
    10121031            # FIXME: Eventually we will want this to share a lot more code with JSValueToNative.
    10131032            my $function = $member->isOptional ? "convertOptional" : "convert";
    1014             my $defaultValueWithLeadingComma = $member->isOptional && defined $member->default ? ", " . $member->default : "";
    10151033            $result .= "    auto " . $member->name . " = " . $function . "<" . GetNativeTypeFromSignature($interface, $member) . ">"
    10161034                . "(state, object->get(&state, Identifier::fromString(&state, \"" . $member->name . "\"))"
     1035                . GenerateConversionRuleWithLeadingComma($interface, $member)
    10171036                . GenerateDefaultValueWithLeadingComma($interface, $member) . ");\n";
    10181037            $needExceptionCheck = 1;
     
    44264445    if ($codeGenerator->IsFloatingPointType($type)) {
    44274446        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);
    44334450    }
    44344451
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r200775 r200907  
    456456{
    457457    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 };
    459459    auto* object = value.getObject();
    460460    if (UNLIKELY(!object || object->type() == RegExpObjectType)) {
     
    484484        return { };
    485485    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) };
    487511}
    488512
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r200607 r200907  
    392392    boolean booleanWithoutDefault;
    393393    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;
    394402};
    395403
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r200895 r200907  
    14941494}
    14951495
    1496 void DOMWindow::scrollBy(int x, int y) const
     1496void DOMWindow::scrollBy(const ScrollToOptions& options) const
     1497{
     1498    return scrollBy(options.left.valueOr(0), options.top.valueOr(0));
     1499}
     1500
     1501void DOMWindow::scrollBy(double x, double y) const
    14971502{
    14981503    if (!isCurrentlyDisplayedInFrame())
     
    15051510        return;
    15061511
     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
    15071516    IntSize scaledOffset(view->mapFromCSSToLayoutUnits(x), view->mapFromCSSToLayoutUnits(y));
    15081517    view->setContentsScrollPosition(view->contentsScrollPosition() + scaledOffset);
    15091518}
    15101519
    1511 void DOMWindow::scrollTo(int x, int y) const
    1512 {
    1513     if (!isCurrentlyDisplayedInFrame())
    1514         return;
    1515 
     1520void DOMWindow::scrollTo(const ScrollToOptions& options) const
     1521{
    15161522    RefPtr<FrameView> view = m_frame->view();
    15171523    if (!view)
    15181524        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
     1531void 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;
    15191543
    15201544    if (!x && !y && view->contentsScrollPosition() == IntPoint(0, 0))
  • trunk/Source/WebCore/page/DOMWindow.h

    r200789 r200907  
    249249        void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, Event&, PassRefPtr<Inspector::ScriptCallStack>);
    250250
    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;
    254260
    255261        void moveBy(float x, float y) const;
  • trunk/Source/WebCore/page/DOMWindow.idl

    r200788 r200907  
    103103    readonly attribute long pageYOffset;
    104104
    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
    108115    void moveBy(optional unrestricted float x = NaN, optional unrestricted float y = NaN); // FIXME: this should take longs not floats.
    109116    void moveTo(optional unrestricted float x = NaN, optional unrestricted float y = NaN); // FIXME: this should take longs not floats.
     
    218225};
    219226
     227// FIXME: Support ScrollBehavior.
     228dictionary ScrollToOptions {
     229    unrestricted double left;
     230    unrestricted double top;
     231};
     232
    220233DOMWindow implements GlobalEventHandlers;
    221234DOMWindow implements WindowBase64;
Note: See TracChangeset for help on using the changeset viewer.