Changeset 235659 in webkit


Ignore:
Timestamp:
Sep 4, 2018 10:19:58 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Add basic support for ScrollIntoViewOptions
https://bugs.webkit.org/show_bug.cgi?id=189258

Patch by Frederic Wang <fwang@igalia.com> on 2018-09-04
Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

Update test expectations for WPT scrollIntoView tests.

  • web-platform-tests/css/cssom-view/scrollIntoView-scrollMargin-expected.txt: This is not

supported yet but update the error message.

  • web-platform-tests/css/cssom-view/scrollIntoView-scrollPadding-expected.txt: Ditto.
  • web-platform-tests/css/cssom-view/scrollIntoView-shadow-expected.txt: Update expectation

now that this test passes.

  • web-platform-tests/css/cssom-view/scrollIntoView-smooth-expected.txt: Ditto.
  • web-platform-tests/css/cssom-view/scrollintoview-expected.txt: Ditto.

Source/WebCore:

This patch introduces a new ScrollIntoViewOptions parameter that can be passed into
Element.scrollIntoView instead of a boolean. A basic support for scroll alignments is
implemented, so that it is closer to the behavior of the CSSOMView spec while still remaining
compatible with the current boolean-parameter implementation. Full implementation that
takes into account orientation/direction will be handled in bug 161611. This patch is also a
preliminary step to support the ScrollBehavior (bug 188043) for ScrollIntoView.

Tests: web-platform-tests/css/cssom-view/scrollintoview-html

web-platform-tests/css/cssom-view/scrollIntoView-smooth.html

  • CMakeLists.txt: Add new IDL files.
  • DerivedSources.make: Ditto.
  • Sources.txt: Add new generated cpp JS bindings.
  • WebCore.xcodeproj/project.pbxproj: Add files to build to XCode.
  • dom/Element.cpp:

(WebCore::toScrollAlignment): Convert ScrollLogicalPosition to scroll alignment. Orientation
and direction are not implemented yet.
(WebCore::Element::scrollIntoView): Implement new scrollIntoView version accepting
ScrollIntoViewOptions parameter.

  • dom/Element.h: Declare new scrollIntoView.
  • dom/Element.idl: Make scrollIntoView accept a ScrollIntoViewOptions parameter.
  • page/ScrollIntoViewOptions.h: Added.
  • page/ScrollIntoViewOptions.idl: Added.
  • page/ScrollLogicalPosition.h: Added.
  • page/ScrollLogicalPosition.idl: Added.

Source/WebKit:

  • DOM/DOMElement.mm: Add ScrollIntoViewOptions

header so that this file can build despite the new scrollIntoView function.

Source/WebKitLegacy/mac:

  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElementGtk.cpp: Add ScrollIntoViewOptions

header so that this file can build despite the new scrollIntoView function.

Source/WebKitLegacy/win:

  • DOMCoreClasses.cpp: Add ScrollIntoViewOptions header so that this file

can build despite the new scrollIntoView function.

LayoutTests:

Update test expectations for WPT scrollIntoView tests.

  • platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-smooth-expected.txt: Removed.
Location:
trunk
Files:
4 added
1 deleted
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r235655 r235659  
     12018-09-04  Frederic Wang  <fwang@igalia.com>
     2
     3        Add basic support for ScrollIntoViewOptions
     4        https://bugs.webkit.org/show_bug.cgi?id=189258
     5
     6        Reviewed by Simon Fraser.
     7
     8        Update test expectations for WPT scrollIntoView tests.
     9
     10        * platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-smooth-expected.txt: Removed.
     11
    1122018-09-04  Michael Saboff  <msaboff@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r235658 r235659  
     12018-09-04  Frederic Wang  <fwang@igalia.com>
     2
     3        Add basic support for ScrollIntoViewOptions
     4        https://bugs.webkit.org/show_bug.cgi?id=189258
     5
     6        Reviewed by Simon Fraser.
     7
     8        Update test expectations for WPT scrollIntoView tests.
     9
     10        * web-platform-tests/css/cssom-view/scrollIntoView-scrollMargin-expected.txt: This is not
     11        supported yet but update the error message.
     12        * web-platform-tests/css/cssom-view/scrollIntoView-scrollPadding-expected.txt: Ditto.
     13        * web-platform-tests/css/cssom-view/scrollIntoView-shadow-expected.txt: Update expectation
     14        now that this test passes.
     15        * web-platform-tests/css/cssom-view/scrollIntoView-smooth-expected.txt: Ditto.
     16        * web-platform-tests/css/cssom-view/scrollintoview-expected.txt: Ditto.
     17
    1182018-09-04  Oriol Brufau  <obrufau@igalia.com>
    219
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-scrollMargin-expected.txt

    r232903 r235659  
    11
    2 FAIL scrollIntoView({block: "center", inline: "center"}) assert_approx_equals: scrollX expected 153.5 +/- 0.5 but got 115
    3 FAIL scrollIntoView({block: "start", inline: "start"}) assert_approx_equals: scrollX expected 184 +/- 0.5 but got 115
     2FAIL scrollIntoView({block: "center", inline: "center"}) assert_approx_equals: scrollX expected 153.5 +/- 0.5 but got 158
     3FAIL scrollIntoView({block: "start", inline: "start"}) assert_approx_equals: scrollX expected 184 +/- 0.5 but got 200
    44FAIL scrollIntoView({block: "end", inline: "end"}) assert_approx_equals: scrollX expected 123 +/- 0.5 but got 115
    55
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-scrollPadding-expected.txt

    r232903 r235659  
    11
    2 FAIL scrollIntoView({block: "center", inline: "center"}) assert_approx_equals: scrollX expected 153.5 +/- 0.5 but got 115
    3 FAIL scrollIntoView({block: "start", inline: "start"}) assert_approx_equals: scrollX expected 184 +/- 0.5 but got 115
     2FAIL scrollIntoView({block: "center", inline: "center"}) assert_approx_equals: scrollX expected 153.5 +/- 0.5 but got 158
     3FAIL scrollIntoView({block: "start", inline: "start"}) assert_approx_equals: scrollX expected 184 +/- 0.5 but got 200
    44FAIL scrollIntoView({block: "end", inline: "end"}) assert_approx_equals: scrollX expected 123 +/- 0.5 but got 115
    55
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-shadow-expected.txt

    r232903 r235659  
    11
    2 FAIL scrollIntoView should behave correctly if applies to shadow dom elements assert_approx_equals: expected 8 +/- 1 but got 0
     2PASS scrollIntoView should behave correctly if applies to shadow dom elements
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-smooth-expected.txt

    r232903 r235659  
    11
    2 FAIL Smooth scrollIntoView should scroll the element to the 'nearest' position assert_approx_equals: scrollY expected 915 +/- 1 but got 1000
    3 FAIL Smooth scrollIntoView should scroll the element to the 'start' position assert_approx_equals: scrollX expected 1008 +/- 1 but got 723
    4 FAIL Smooth scrollIntoView should scroll the element to the 'center' position assert_approx_equals: scrollX expected 865.5 +/- 1 but got 723
    5 FAIL Smooth scrollIntoView should scroll the element to the 'end' position assert_approx_equals: scrollY expected 915 +/- 1 but got 1000
     2PASS Smooth scrollIntoView should scroll the element to the 'nearest' position
     3PASS Smooth scrollIntoView should scroll the element to the 'start' position
     4PASS Smooth scrollIntoView should scroll the element to the 'center' position
     5PASS Smooth scrollIntoView should scroll the element to the 'end' position
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollintoview-expected.txt

    r232903 r235659  
    1616PASS scrollIntoView(undefined) starting at right,top
    1717PASS scrollIntoView(undefined) starting at right,bottom
    18 FAIL scrollIntoView(null) starting at left,top assert_approx_equals: scrollY expected 4000 +/- 0.5 but got 3600
    19 FAIL scrollIntoView(null) starting at left,bottom assert_approx_equals: scrollY expected 4000 +/- 0.5 but got 3600
    20 FAIL scrollIntoView(null) starting at right,top assert_approx_equals: scrollY expected 4000 +/- 0.5 but got 3600
    21 FAIL scrollIntoView(null) starting at right,bottom assert_approx_equals: scrollY expected 4000 +/- 0.5 but got 3600
     18PASS scrollIntoView(null) starting at left,top
     19PASS scrollIntoView(null) starting at left,bottom
     20PASS scrollIntoView(null) starting at right,top
     21PASS scrollIntoView(null) starting at right,bottom
    2222PASS scrollIntoView({}) starting at left,top
    2323PASS scrollIntoView({}) starting at left,bottom
    2424PASS scrollIntoView({}) starting at right,top
    2525PASS scrollIntoView({}) starting at right,bottom
    26 FAIL scrollIntoView({block: "center", inline: "center"}) starting at left,top assert_approx_equals: scrollX expected 3700 +/- 0.5 but got 3400
    27 FAIL scrollIntoView({block: "center", inline: "center"}) starting at left,bottom assert_approx_equals: scrollX expected 3700 +/- 0.5 but got 3400
    28 FAIL scrollIntoView({block: "center", inline: "center"}) starting at right,top assert_approx_equals: scrollX expected 3700 +/- 0.5 but got 4000
    29 FAIL scrollIntoView({block: "center", inline: "center"}) starting at right,bottom assert_approx_equals: scrollX expected 3700 +/- 0.5 but got 4000
    30 FAIL scrollIntoView({block: "start", inline: "start"}) starting at left,top assert_approx_equals: scrollX expected 4000 +/- 0.5 but got 3400
    31 FAIL scrollIntoView({block: "start", inline: "start"}) starting at left,bottom assert_approx_equals: scrollX expected 4000 +/- 0.5 but got 3400
     26PASS scrollIntoView({block: "center", inline: "center"}) starting at left,top
     27PASS scrollIntoView({block: "center", inline: "center"}) starting at left,bottom
     28PASS scrollIntoView({block: "center", inline: "center"}) starting at right,top
     29PASS scrollIntoView({block: "center", inline: "center"}) starting at right,bottom
     30PASS scrollIntoView({block: "start", inline: "start"}) starting at left,top
     31PASS scrollIntoView({block: "start", inline: "start"}) starting at left,bottom
    3232PASS scrollIntoView({block: "start", inline: "start"}) starting at right,top
    3333PASS scrollIntoView({block: "start", inline: "start"}) starting at right,bottom
    34 FAIL scrollIntoView({block: "end", inline: "end"}) starting at left,top assert_approx_equals: scrollY expected 3600 +/- 0.5 but got 4000
    35 FAIL scrollIntoView({block: "end", inline: "end"}) starting at left,bottom assert_approx_equals: scrollY expected 3600 +/- 0.5 but got 4000
    36 FAIL scrollIntoView({block: "end", inline: "end"}) starting at right,top assert_approx_equals: scrollX expected 3400 +/- 0.5 but got 4000
    37 FAIL scrollIntoView({block: "end", inline: "end"}) starting at right,bottom assert_approx_equals: scrollX expected 3400 +/- 0.5 but got 4000
    38 FAIL scrollIntoView({block: "nearest", inline: "nearest"}) starting at left,top assert_approx_equals: scrollY expected 3600 +/- 0.5 but got 4000
     34PASS scrollIntoView({block: "end", inline: "end"}) starting at left,top
     35PASS scrollIntoView({block: "end", inline: "end"}) starting at left,bottom
     36PASS scrollIntoView({block: "end", inline: "end"}) starting at right,top
     37PASS scrollIntoView({block: "end", inline: "end"}) starting at right,bottom
     38PASS scrollIntoView({block: "nearest", inline: "nearest"}) starting at left,top
    3939PASS scrollIntoView({block: "nearest", inline: "nearest"}) starting at left,bottom
    40 FAIL scrollIntoView({block: "nearest", inline: "nearest"}) starting at right,top assert_approx_equals: scrollY expected 3600 +/- 0.5 but got 4000
     40PASS scrollIntoView({block: "nearest", inline: "nearest"}) starting at right,top
    4141PASS scrollIntoView({block: "nearest", inline: "nearest"}) starting at right,bottom
    4242
  • trunk/Source/WebCore/CMakeLists.txt

    r235623 r235659  
    832832    page/RemoteDOMWindow.idl
    833833    page/Screen.idl
     834    page/ScrollIntoViewOptions.idl
     835    page/ScrollLogicalPosition.idl
    834836    page/ScrollToOptions.idl
    835837    page/ShareData.idl
  • trunk/Source/WebCore/ChangeLog

    r235658 r235659  
     12018-09-04  Frederic Wang  <fwang@igalia.com>
     2
     3        Add basic support for ScrollIntoViewOptions
     4        https://bugs.webkit.org/show_bug.cgi?id=189258
     5
     6        Reviewed by Simon Fraser.
     7
     8        This patch introduces a new ScrollIntoViewOptions parameter that can be passed into
     9        Element.scrollIntoView instead of a boolean. A basic support for scroll alignments is
     10        implemented, so that it is closer to the behavior of the CSSOMView spec while still remaining
     11        compatible with the current boolean-parameter implementation. Full implementation that
     12        takes into account orientation/direction will be handled in bug 161611. This patch is also a
     13        preliminary step to support the ScrollBehavior (bug 188043) for ScrollIntoView.
     14
     15        Tests: web-platform-tests/css/cssom-view/scrollintoview-html
     16               web-platform-tests/css/cssom-view/scrollIntoView-smooth.html
     17
     18        * CMakeLists.txt: Add new IDL files.
     19        * DerivedSources.make: Ditto.
     20        * Sources.txt: Add new generated cpp JS bindings.
     21        * WebCore.xcodeproj/project.pbxproj: Add files to build to XCode.
     22        * dom/Element.cpp:
     23        (WebCore::toScrollAlignment): Convert ScrollLogicalPosition to scroll alignment. Orientation
     24        and direction are not implemented yet.
     25        (WebCore::Element::scrollIntoView): Implement new scrollIntoView version accepting
     26        ScrollIntoViewOptions parameter.
     27        * dom/Element.h: Declare new scrollIntoView.
     28        * dom/Element.idl: Make scrollIntoView accept a ScrollIntoViewOptions parameter.
     29        * page/ScrollIntoViewOptions.h: Added.
     30        * page/ScrollIntoViewOptions.idl: Added.
     31        * page/ScrollLogicalPosition.h: Added.
     32        * page/ScrollLogicalPosition.idl: Added.
     33
    1342018-09-04  Oriol Brufau  <obrufau@igalia.com>
    235
  • trunk/Source/WebCore/DerivedSources.make

    r235606 r235659  
    797797    $(WebCore)/page/RemoteDOMWindow.idl \
    798798    $(WebCore)/page/Screen.idl \
     799    $(WebCore)/page/ScrollIntoViewOptions.idl \
     800    $(WebCore)/page/ScrollLogicalPosition.idl \
    799801    $(WebCore)/page/ScrollToOptions.idl \
    800802    $(WebCore)/page/UserMessageHandler.idl \
  • trunk/Source/WebCore/Sources.txt

    r235630 r235659  
    30593059JSScreenLuminance.cpp
    30603060JSScriptProcessorNode.cpp
     3061JSScrollIntoViewOptions.cpp
     3062JSScrollLogicalPosition.cpp
    30613063JSScrollToOptions.cpp
    30623064JSSecurityPolicyViolationEvent.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r235630 r235659  
    23382338                833B9E361F508D8500E0E428 /* JSFileSystemFileEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 833B9E2C1F508D8000E0E428 /* JSFileSystemFileEntry.h */; };
    23392339                83407FC11E8D9C1700E048D3 /* VisibilityChangeClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 83407FC01E8D9C1200E048D3 /* VisibilityChangeClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2340                834476EF1DA5BC5E002B5EB0 /* JSScrollLogicalPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E9B3011DA5A51E00FFD8D4 /* JSScrollLogicalPosition.h */; };
     2341                834476EF1DA5BC5E002B5EC1 /* JSScrollIntoViewOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E9B3011DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.h */; };
    23402342                834476EF1DA5BC5E002B6ED2 /* JSScrollToOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E9B3011DA5A51E00FFE8F6 /* JSScrollToOptions.h */; };
    23412343                8348BFAC1B85729800912F36 /* ClassCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 8348BFAA1B85729500912F36 /* ClassCollection.h */; };
     
    24102412                83C1F5941EDF69D300410D27 /* QualifiedNameCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 83C1F5921EDF69D300410D27 /* QualifiedNameCache.h */; };
    24112413                83C45B8E1DC2B68A008871BA /* ValidationBubble.h in Headers */ = {isa = PBXBuildFile; fileRef = 83C45B8D1DC2B67C008871BA /* ValidationBubble.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2414                83C5795D1DA5C301006F9C86 /* ScrollLogicalPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = 8350C3E71DA59B6200355424 /* ScrollLogicalPosition.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2415                83C5795D1DA5C301006F9C97 /* ScrollIntoViewOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 8350C3E71DA59B6200355435 /* ScrollIntoViewOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
    24122416                83C5795D1DA5C301006FACA8 /* ScrollToOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 8350C3E71DA59B6200356446 /* ScrollToOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
    24132417                83D35AEC1C7187FA00F70D5A /* XMLHttpRequestEventTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 83D35AEA1C7187ED00F70D5A /* XMLHttpRequestEventTarget.h */; };
     
    97979801                834DFACC1F7DAE5600C2725B /* SharedStringHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedStringHash.h; sourceTree = "<group>"; };
    97989802                834DFACE1F7DAE5700C2725B /* SharedStringHash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedStringHash.cpp; sourceTree = "<group>"; };
     9803                8350C3E71DA59B6200355424 /* ScrollLogicalPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollLogicalPosition.h; sourceTree = "<group>"; };
     9804                8350C3E81DA59B6200355424 /* ScrollLogicalPosition.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ScrollLogicalPosition.idl; sourceTree = "<group>"; };
     9805                8350C3E71DA59B6200355435 /* ScrollIntoViewOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollIntoViewOptions.h; sourceTree = "<group>"; };
     9806                8350C3E81DA59B6200355435 /* ScrollIntoViewOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ScrollIntoViewOptions.idl; sourceTree = "<group>"; };
    97999807                8350C3E71DA59B6200356446 /* ScrollToOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollToOptions.h; sourceTree = "<group>"; };
    98009808                8350C3E81DA59B6200356446 /* ScrollToOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ScrollToOptions.idl; sourceTree = "<group>"; };
     
    99349942                83E8667F1FBA5640008855C5 /* ServiceWorkerData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerData.cpp; sourceTree = "<group>"; };
    99359943                83E959E11B8BC22B004D9385 /* NativeNodeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeNodeFilter.h; sourceTree = "<group>"; };
     9944                83E9B3001DA5A51E00FFD8D4 /* JSScrollLogicalPosition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScrollLogicalPosition.cpp; sourceTree = "<group>"; };
     9945                83E9B3011DA5A51E00FFD8D4 /* JSScrollLogicalPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScrollLogicalPosition.h; sourceTree = "<group>"; };
     9946                83E9B3001DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScrollIntoViewOptions.cpp; sourceTree = "<group>"; };
     9947                83E9B3011DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScrollIntoViewOptions.h; sourceTree = "<group>"; };
    99369948                83E9B3001DA5A51E00FFE8F6 /* JSScrollToOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScrollToOptions.cpp; sourceTree = "<group>"; };
    99379949                83E9B3011DA5A51E00FFE8F6 /* JSScrollToOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScrollToOptions.h; sourceTree = "<group>"; };
     
    1941719429                                BCEC01BB0C274DAC009F4EC9 /* Screen.h */,
    1941819430                                BCEC01BC0C274DAC009F4EC9 /* Screen.idl */,
     19431                                8350C3E71DA59B6200355435 /* ScrollIntoViewOptions.h */,
     19432                                8350C3E81DA59B6200355435 /* ScrollIntoViewOptions.idl */,
     19433                                8350C3E71DA59B6200355424 /* ScrollLogicalPosition.h */,
     19434                                8350C3E81DA59B6200355424 /* ScrollLogicalPosition.idl */,
    1941919435                                8350C3E71DA59B6200356446 /* ScrollToOptions.h */,
    1942019436                                8350C3E81DA59B6200356446 /* ScrollToOptions.idl */,
     
    2415524171                                BCEC01C00C274DDD009F4EC9 /* JSScreen.cpp */,
    2415624172                                BCEC01C10C274DDD009F4EC9 /* JSScreen.h */,
     24173                                83E9B3001DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.cpp */,
     24174                                83E9B3011DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.h */,
     24175                                83E9B3001DA5A51E00FFD8D4 /* JSScrollLogicalPosition.cpp */,
     24176                                83E9B3011DA5A51E00FFD8D4 /* JSScrollLogicalPosition.h */,
    2415724177                                83E9B3001DA5A51E00FFE8F6 /* JSScrollToOptions.cpp */,
    2415824178                                83E9B3011DA5A51E00FFE8F6 /* JSScrollToOptions.h */,
     
    2893628956                                BCEC01C30C274DDD009F4EC9 /* JSScreen.h in Headers */,
    2893728957                                FDA15ECE12B03F61003A583A /* JSScriptProcessorNode.h in Headers */,
     28958                                834476EF1DA5BC5E002B5EC1 /* JSScrollIntoViewOptions.h in Headers */,
     28959                                834476EF1DA5BC5E002B5EB0 /* JSScrollLogicalPosition.h in Headers */,
    2893828960                                834476EF1DA5BC5E002B6ED2 /* JSScrollToOptions.h in Headers */,
    2893928961                                CED06AD11C77754800FDFAF1 /* JSSecurityPolicyViolationEvent.h in Headers */,
     
    3012130143                                A6D5A99D1629D70000297330 /* ScrollingTreeScrollingNodeDelegate.h in Headers */,
    3012230144                                0FB8890A167D2FA10010CDA5 /* ScrollingTreeStickyNode.h in Headers */,
     30145                                83C5795D1DA5C301006F9C97 /* ScrollIntoViewOptions.h in Headers */,
    3012330146                                7AAFE8D019CB8672000F56D8 /* ScrollLatchingState.h in Headers */,
     30147                                83C5795D1DA5C301006F9C86 /* ScrollLogicalPosition.h in Headers */,
    3012430148                                F478755419983AFF0024A287 /* ScrollSnapAnimatorState.h in Headers */,
    3012530149                                F46729281E0DE68500ACC3D8 /* ScrollSnapOffsetsInfo.h in Headers */,
  • trunk/Source/WebCore/dom/Element.cpp

    r235458 r235659  
    9292#include "SVGSVGElement.h"
    9393#include "ScriptDisallowedScope.h"
     94#include "ScrollIntoViewOptions.h"
    9495#include "ScrollLatchingState.h"
    9596#include "SelectorQuery.h"
     
    650651    if (renderer()->style().hasAppearance())
    651652        renderer()->theme().stateChanged(*renderer(), ControlStates::HoverState);
     653}
     654
     655// FIXME(webkit.org/b/161611): Take into account orientation/direction.
     656inline ScrollAlignment toScrollAlignment(std::optional<ScrollLogicalPosition> position, bool isVertical)
     657{
     658    switch (position.value_or(isVertical ? ScrollLogicalPosition::Start : ScrollLogicalPosition::Nearest)) {
     659    case ScrollLogicalPosition::Start:
     660        return isVertical ? ScrollAlignment::alignTopAlways : ScrollAlignment::alignLeftAlways;
     661    case ScrollLogicalPosition::Center:
     662        return ScrollAlignment::alignCenterAlways;
     663    case ScrollLogicalPosition::End:
     664        return isVertical ? ScrollAlignment::alignBottomAlways : ScrollAlignment::alignRightAlways;
     665    case ScrollLogicalPosition::Nearest:
     666        return ScrollAlignment::alignToEdgeIfNeeded;
     667    default:
     668        ASSERT_NOT_REACHED();
     669        return ScrollAlignment::alignToEdgeIfNeeded;
     670    }
     671}
     672
     673void Element::scrollIntoView(std::optional<Variant<bool, ScrollIntoViewOptions>>&& arg)
     674{
     675    document().updateLayoutIgnorePendingStylesheets();
     676
     677    if (!renderer())
     678        return;
     679
     680    bool insideFixed;
     681    LayoutRect absoluteBounds = renderer()->absoluteAnchorRect(&insideFixed);
     682
     683    // FIXME(webkit.org/b/188043): Support ScrollBehavior.
     684    ScrollIntoViewOptions options;
     685    if (arg) {
     686        auto value = arg.value();
     687        if (WTF::holds_alternative<ScrollIntoViewOptions>(value))
     688            options = WTF::get<ScrollIntoViewOptions>(value);
     689        else if (!WTF::get<bool>(value))
     690            options.blockPosition = ScrollLogicalPosition::End;
     691    }
     692
     693    ScrollAlignment alignX = toScrollAlignment(options.inlinePosition, false);
     694    ScrollAlignment alignY = toScrollAlignment(options.blockPosition, true);
     695    renderer()->scrollRectToVisible(SelectionRevealMode::Reveal, absoluteBounds, insideFixed, alignX, alignY, ShouldAllowCrossOriginScrolling::No);
    652696}
    653697
  • trunk/Source/WebCore/dom/Element.h

    r234884 r235659  
    5656class WebAnimation;
    5757struct ElementStyle;
     58struct ScrollIntoViewOptions;
    5859
    5960#if ENABLE(INTERSECTION_OBSERVER)
     
    142143    unsigned findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->findAttributeIndexByName(name, shouldIgnoreAttributeCase); }
    143144
     145    WEBCORE_EXPORT void scrollIntoView(std::optional<Variant<bool, ScrollIntoViewOptions>>&& arg);
    144146    WEBCORE_EXPORT void scrollIntoView(bool alignToTop = true);
    145147    WEBCORE_EXPORT void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
  • trunk/Source/WebCore/dom/Element.idl

    r234482 r235659  
    7272    DOMRectList getClientRects();
    7373    [NewObject] DOMRect getBoundingClientRect();
    74     void scrollIntoView(optional boolean alignWithTop = true); // FIXME(webkit.org/b/161611): Parameter type should be (boolean or object).
     74    void scrollIntoView(optional (boolean or ScrollIntoViewOptions) arg);
    7575    [ImplementedAs=scrollTo] void scroll(optional ScrollToOptions options);
    7676    [ImplementedAs=scrollTo] void scroll(unrestricted double x, unrestricted double y);
  • trunk/Source/WebKit/ChangeLog

    r235656 r235659  
     12018-09-04  Frederic Wang  <fwang@igalia.com>
     2
     3        Add basic support for ScrollIntoViewOptions
     4        https://bugs.webkit.org/show_bug.cgi?id=189258
     5
     6        Reviewed by Simon Fraser.
     7
     8        * DOM/DOMElement.mm: Add ScrollIntoViewOptions
     9        header so that this file can build despite the new scrollIntoView function.
     10
    1112018-09-04  Chris Dumez  <cdumez@apple.com>
    212
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElementGtk.cpp

    r234586 r235659  
    2828#include <WebCore/HTMLNames.h>
    2929#include <WebCore/JSExecState.h>
     30#include <WebCore/ScrollIntoViewOptions.h>
    3031#include <WebCore/StyledElement.h>
    3132#include "WebKitDOMAttrPrivate.h"
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r235647 r235659  
     12018-09-04  Frederic Wang  <fwang@igalia.com>
     2
     3        Add basic support for ScrollIntoViewOptions
     4        https://bugs.webkit.org/show_bug.cgi?id=189258
     5
     6        Reviewed by Simon Fraser.
     7
     8        * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElementGtk.cpp: Add ScrollIntoViewOptions
     9        header so that this file can build despite the new scrollIntoView function.
     10
    1112018-09-04  Wenson Hsieh  <wenson_hsieh@apple.com>
    212
  • trunk/Source/WebKitLegacy/mac/DOM/DOMElement.mm

    r234586 r235659  
    4141#import <WebCore/NameNodeList.h>
    4242#import <WebCore/NodeList.h>
     43#import <WebCore/ScrollIntoViewOptions.h>
    4344#import <WebCore/StyleProperties.h>
    4445#import <WebCore/StyledElement.h>
  • trunk/Source/WebKitLegacy/win/ChangeLog

    r235566 r235659  
     12018-09-04  Frederic Wang  <fwang@igalia.com>
     2
     3        Add basic support for ScrollIntoViewOptions
     4        https://bugs.webkit.org/show_bug.cgi?id=189258
     5
     6        Reviewed by Simon Fraser.
     7
     8        * DOMCoreClasses.cpp: Add ScrollIntoViewOptions header so that this file
     9        can build despite the new scrollIntoView function.
     10
    1112018-08-31  Chris Dumez  <cdumez@apple.com>
    212
  • trunk/Source/WebKitLegacy/win/DOMCoreClasses.cpp

    r233935 r235659  
    5555#include <WebCore/RenderElement.h>
    5656#include <WebCore/RenderTreeAsText.h>
     57#include <WebCore/ScrollIntoViewOptions.h>
    5758#include <WebCore/StyledElement.h>
    5859
Note: See TracChangeset for help on using the changeset viewer.