Changeset 270738 in webkit


Ignore:
Timestamp:
Dec 12, 2020 11:39:51 AM (19 months ago)
Author:
commit-queue@webkit.org
Message:

Implement WebVTT VTTCue region attribute
https://bugs.webkit.org/show_bug.cgi?id=168716

LayoutTests/imported/w3c:

Patch by Frank Olivier <frankolivier@apple.com> on 2020-12-12
Reviewed by Eric Carlson.

  • web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-webvtt-align-text-line-position-expected.txt:
  • web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-webvtt-line-position-expected.txt:

Source/WebCore:

Patch by Frank Olivier <frankolivier@apple.com> on 2020-12-12
Reviewed by Eric Carlson.

Updated existing region tests.

  • WebCore.xcodeproj/project.pbxproj:
  • html/shadow/MediaControlTextTrackContainerElement.cpp:

(WebCore::MediaControlTextTrackContainerElement::processActiveVTTCue):

  • html/track/TextTrackCueGeneric.cpp:

(WebCore::TextTrackCueGenericBoxElement::applyCSSProperties):
(WebCore::TextTrackCueGeneric::setLine):

  • html/track/TextTrackCueGeneric.h:
  • html/track/VTTCue.cpp:

(WebCore::horizontalKeyword):
(WebCore::lineLeftKeyword):
(WebCore::lineRightKeyword):
(WebCore::autoKeyword):
(WebCore::VTTCueBox::applyCSSProperties):
(WebCore::VTTCue::setVertical):
(WebCore::VTTCue::line const):
(WebCore::VTTCue::setLine):
(WebCore::VTTCue::lineAlign const):
(WebCore::VTTCue::setLineAlign):
(WebCore::VTTCue::positionAlign const):
(WebCore::VTTCue::setPositionAlign):
(WebCore::VTTCue::setAlign):
(WebCore::VTTCue::setTrack):
(WebCore::VTTCue::setRegion):
(WebCore::VTTCue::region):
(WebCore::VTTCue::regionId):
(WebCore::VTTCue::calculateComputedLinePosition):
(WebCore::VTTCue::getDisplayTree):
(WebCore::VTTCue::removeDisplayTree):
(WebCore::VTTCue::settingName):
(WebCore::VTTCue::setCueSettings):
(WebCore::VTTCue::toJSON const):
(WebCore::VTTCue::setRegionId): Deleted.

  • html/track/VTTCue.h:

(WebCore::VTTCue::line const): Deleted.
(WebCore::VTTCue::regionId const): Deleted.

  • html/track/VTTCue.idl:
  • rendering/RenderVTTCue.cpp:

(WebCore::RenderVTTCue::layout):

LayoutTests:

Updated VTTCue to current IDL

Patch by Frank Olivier <frankolivier@apple.com> on 2020-12-12
Reviewed by Eric Carlson.

  • media/track/captions-webvtt/header-regions.vtt:
  • media/track/regions-webvtt/text-track-cue-region-attribute-expected.txt:
  • media/track/regions-webvtt/text-track-cue-region-attribute.html:
  • media/track/regions-webvtt/vtt-region-parser-expected.txt:
  • media/track/regions-webvtt/vtt-region-parser.html:
  • media/track/track-add-remove-cue-expected.txt:
  • media/track/track-add-remove-cue.html:
  • media/track/track-cue-container-rendering-position.html:
  • media/track/track-cue-mutable-expected.txt:
  • media/track/track-cue-mutable.html:
  • media/track/track-vttcue-expected.txt:
  • media/track/track-vttcue.html:
  • media/track/track-webvtt-tc013-settings-expected.txt:
  • media/track/track-webvtt-tc013-settings.html:
  • media/track/track-webvtt-tc017-line-position-expected.txt:
  • media/track/track-webvtt-tc017-line-position.html:
  • media/track/track-webvtt-tc018-align-text-line-position-expected.txt:
  • media/track/track-webvtt-tc018-align-text-line-position.html:
Location:
trunk
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r270735 r270738  
     12020-12-12  Frank Olivier  <frankolivier@apple.com>
     2
     3        Implement WebVTT VTTCue region attribute
     4        https://bugs.webkit.org/show_bug.cgi?id=168716
     5
     6        Updated VTTCue to current IDL
     7
     8        Reviewed by Eric Carlson.
     9
     10        * media/track/captions-webvtt/header-regions.vtt:
     11        * media/track/regions-webvtt/text-track-cue-region-attribute-expected.txt:
     12        * media/track/regions-webvtt/text-track-cue-region-attribute.html:
     13        * media/track/regions-webvtt/vtt-region-parser-expected.txt:
     14        * media/track/regions-webvtt/vtt-region-parser.html:
     15        * media/track/track-add-remove-cue-expected.txt:
     16        * media/track/track-add-remove-cue.html:
     17        * media/track/track-cue-container-rendering-position.html:
     18        * media/track/track-cue-mutable-expected.txt:
     19        * media/track/track-cue-mutable.html:
     20        * media/track/track-vttcue-expected.txt:
     21        * media/track/track-vttcue.html:
     22        * media/track/track-webvtt-tc013-settings-expected.txt:
     23        * media/track/track-webvtt-tc013-settings.html:
     24        * media/track/track-webvtt-tc017-line-position-expected.txt:
     25        * media/track/track-webvtt-tc017-line-position.html:
     26        * media/track/track-webvtt-tc018-align-text-line-position-expected.txt:
     27        * media/track/track-webvtt-tc018-align-text-line-position.html:
     28
    1292020-12-12  Diego Pino Garcia  <dpino@igalia.com>
    230
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r270702 r270738  
     12020-12-12  Frank Olivier  <frankolivier@apple.com>
     2
     3        Implement WebVTT VTTCue region attribute
     4        https://bugs.webkit.org/show_bug.cgi?id=168716
     5
     6        Reviewed by Eric Carlson.
     7
     8        * web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-webvtt-align-text-line-position-expected.txt:
     9        * web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-webvtt-line-position-expected.txt:
     10
    1112020-12-11  Alexey Shvayka  <shvaikalesh@gmail.com>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-webvtt-align-text-line-position-expected.txt

    r242549 r270738  
    11
    22
    3 FAIL Cue alignment, line and text position from settings assert_equals: expected (string) "auto" but got (number) -1
     3PASS Cue alignment, line and text position from settings
    44
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-webvtt-line-position-expected.txt

    r242549 r270738  
    11
    22
    3 FAIL Cue line position from settings assert_equals: expected (string) "auto" but got (number) -1
     3PASS Cue line position from settings
    44
  • trunk/LayoutTests/media/track/captions-webvtt/header-regions.vtt

    r237270 r270738  
    2929: Invalid Header
    3030
     31REGION
     32id:someregionattributeid
     33
    31341
    323500:00:00.000 --> 00:00:02.500 region:someregionattributeid
  • trunk/LayoutTests/media/track/regions-webvtt/text-track-cue-region-attribute-expected.txt

    r165867 r270738  
    1 Tests the regionId attribute of a cue.
     1Tests the region attribute of a cue.
    22
    33
     4EXPECTED (!!window.VTTRegion == 'true') OK
    45
    56** Test the setter and getter through the JS API **
    6 EXPECTED (cue.regionId == '') OK
    7 EXPECTED (cue.regionId == 'someId') OK
     7EXPECTED (cue.region == 'null') OK
    88
    99** Test parsing a region attribute of a cue **
    10 EXPECTED (cue.regionId == 'someregionattributeid') OK
     10EXPECTED (typeof cue.region == 'object') OK
    1111
    1212** Test that region attribute is ignored if either line position or cue size are specified or writing direction is not horizontal **
    13 EXPECTED (cue.regionId == '') OK
    14 EXPECTED (cue.regionId == '') OK
    15 EXPECTED (cue.regionId == '') OK
     13EXPECTED (cue.region == 'null') OK
     14EXPECTED (cue.region == 'null') OK
     15EXPECTED (cue.region == 'null') OK
    1616
    1717END OF TEST
  • trunk/LayoutTests/media/track/regions-webvtt/text-track-cue-region-attribute.html

    r204765 r270738  
    1111            function startTest()
    1212            {
    13                 if (!window.VTTRegion) {
    14                     failTest();
    15                     return;
    16                 }
     13                testExpected("!!window.VTTRegion", true);
    1714
    1815                consoleWrite("<br>** Test the setter and getter through the JS API **");
    1916                cue = new VTTCue(0.0, 1.0, "sample");
    2017
    21                 testExpected("cue.regionId", "");
    22                 cue.regionId = "someId";
    23                 testExpected("cue.regionId", "someId");
     18                testExpected("cue.region", null);
    2419
    2520                consoleWrite("<br>** Test parsing a region attribute of a cue **");
     
    2722
    2823                cue = video.textTracks[0].cues[0];
    29                 testExpected("cue.regionId", "someregionattributeid");
     24                testExpected("typeof cue.region", "object");
    3025
    3126                consoleWrite("<br>** Test that region attribute is ignored if either line position or cue size are specified or writing direction is not horizontal **");
    3227                for (i = 1; i < 4; ++i) {
    3328                  cue = video.textTracks[0].cues[i];
    34                   testExpected("cue.regionId", "");
     29                  testExpected("cue.region", null);
    3530                }
    3631
     
    4338    </head>
    4439    <body>
    45         <p>Tests the regionId attribute of a cue.</p>
     40        <p>Tests the region attribute of a cue.</p>
    4641        <video controls>
    4742            <track src="../captions-webvtt/header-regions.vtt" kind="captions" default onload="startTest()">
  • trunk/LayoutTests/media/track/regions-webvtt/vtt-region-parser-expected.txt

    r236403 r270738  
    22
    33
    4 EXPECTED (video.textTracks[0].regions.length == '4') OK
     4EXPECTED (video.textTracks[0].regions.length == '5') OK
    55
    66EXPECTED (region.id == 'region_without_settings') OK
  • trunk/LayoutTests/media/track/regions-webvtt/vtt-region-parser.html

    r236403 r270738  
    1717
    1818            findMediaElement();
    19             testExpected("video.textTracks[0].regions.length", 4);
     19            testExpected("video.textTracks[0].regions.length", 5);
    2020
    2121            consoleWrite("");
  • trunk/LayoutTests/media/track/track-add-remove-cue-expected.txt

    r236531 r270738  
    2020EXPECTED (textCue.vertical == '') OK
    2121EXPECTED (textCue.snapToLines == 'true') OK
    22 EXPECTED (textCue.line == '-1') OK
     22EXPECTED (textCue.line == 'auto') OK
    2323EXPECTED (textCue.position == 'auto') OK
    2424EXPECTED (textCue.size == '100') OK
     
    4343EXPECTED (newCue.vertical == '') OK
    4444EXPECTED (newCue.snapToLines == 'true') OK
    45 EXPECTED (newCue.line == '-1') OK
     45EXPECTED (newCue.line == 'auto') OK
    4646EXPECTED (newCue.position == 'auto') OK
    4747EXPECTED (newCue.size == '100') OK
  • trunk/LayoutTests/media/track/track-add-remove-cue.html

    r236531 r270738  
    3232                testExpected("textCue.vertical", "");
    3333                testExpected("textCue.snapToLines", true);
    34                 testExpected("textCue.line", -1);
     34                testExpected("textCue.line", 'auto');
    3535                testExpected("textCue.position", 'auto');
    3636                testExpected("textCue.size", 100);
     
    5757                testExpected("newCue.vertical", "");
    5858                testExpected("newCue.snapToLines", true);
    59                 testExpected("newCue.line", -1);
     59                testExpected("newCue.line", 'auto');
    6060                testExpected("newCue.position", 'auto');
    6161                testExpected("newCue.size", 100);
  • trunk/LayoutTests/media/track/track-cue-mutable-expected.txt

    r236531 r270738  
    99EXPECTED (textCue.vertical == '') OK
    1010EXPECTED (textCue.snapToLines == 'true') OK
    11 EXPECTED (textCue.line == '-1') OK
     11EXPECTED (textCue.line == 'auto') OK
    1212EXPECTED (textCue.position == 'auto') OK
    1313EXPECTED (textCue.size == '100') OK
     
    2323RUN(textCue.pauseOnExit = true)
    2424EXPECTED (textCue.pauseOnExit == 'true') OK
    25 
    26 On setting, the text track cue writing direction must be set to the value ... is a case-sensitive match for the new value, if any. If none of the values match, then the user agent must instead throw a SyntaxError exception.
    27 http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-vertical
    28 TEST(textCue.vertical = 'RL') THROWS(DOMException.SYNTAX_ERR) OK
    2925EXPECTED (textCue.vertical == '') OK
    3026RUN(textCue.vertical = 'rl')
     
    3329RUN(textCue.snapToLines = false)
    3430EXPECTED (textCue.snapToLines == 'false') OK
    35 
    36 On setting, if the text track cue snap-to-lines flag is not set, and the new value is negative or greater than 100, then throw an IndexSizeError exception.
    37 http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-line
    38 TEST(textCue.line = -2) THROWS(DOMException.INDEX_SIZE_ERR) OK
    39 TEST(textCue.line = 102) THROWS(DOMException.INDEX_SIZE_ERR) OK
    40 EXPECTED (textCue.line == '-1') OK
    4131RUN(textCue.line = 42)
    4232EXPECTED (textCue.line == '42') OK
     
    6050RUN(textCue.size = 57)
    6151EXPECTED (textCue.size == '57') OK
    62 
    63 On setting, the text track cue alignment must be set to the value ... is a case-sensitive match for the new value, if any. If none of the values match, then the user agent must instead throw a SyntaxError exception.
    64 http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-align
    65 TEST(textCue.align = 'End') THROWS(DOMException.SYNTAX_ERR) OK
     52RUN(textCue.align = 'End')
    6653EXPECTED (textCue.align == 'center') OK
    6754RUN(textCue.align = 'end')
  • trunk/LayoutTests/media/track/track-cue-mutable.html

    r236531 r270738  
    2929                testExpected("textCue.vertical", "");
    3030                testExpected("textCue.snapToLines", true);
    31                 testExpected("textCue.line", -1);
     31                testExpected("textCue.line", 'auto');
    3232                testExpected("textCue.position", 'auto');
    3333                testExpected("textCue.size", 100);
     
    4747                testExpected("textCue.pauseOnExit", true);
    4848
    49                 logSpecURL("http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-vertical",
    50                            "On setting, the text track cue writing direction must be set to the value ... is a case-sensitive match for the new value, if any. If none of the values match, then the user agent must instead throw a SyntaxError exception.");
    51                 testDOMException("textCue.vertical = 'RL'", "DOMException.SYNTAX_ERR");
     49                textCue.vertical = 'xyz';
    5250                testExpected("textCue.vertical", "");
    5351                run("textCue.vertical = 'rl'");
     
    5856                testExpected("textCue.snapToLines", false);
    5957
    60                 logSpecURL("http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-line",
    61                             "On setting, if the text track cue snap-to-lines flag is not set, and the new value is negative or greater than 100, then throw an IndexSizeError exception.");
    62                 testDOMException("textCue.line = -2", "DOMException.INDEX_SIZE_ERR");
    63                 testDOMException("textCue.line = 102", "DOMException.INDEX_SIZE_ERR");
    64                 testExpected("textCue.line", -1);
    6558                run("textCue.line = 42");
    6659                testExpected("textCue.line", 42);
     
    8578                testExpected("textCue.size", 57);
    8679
    87                 logSpecURL("http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-align",
    88                            "On setting, the text track cue alignment must be set to the value ... is a case-sensitive match for the new value, if any. If none of the values match, then the user agent must instead throw a SyntaxError exception.");
    89                 testDOMException("textCue.align = 'End'", "DOMException.SYNTAX_ERR");
     80                run("textCue.align = 'End'");
    9081                testExpected("textCue.align", "center");
    9182                run("textCue.align = 'end'");
  • trunk/LayoutTests/media/track/track-vttcue-expected.txt

    r236531 r270738  
    1414EXPECTED (trackCue.vertical == '') OK
    1515EXPECTED (trackCue.snapToLines == 'true') OK
    16 EXPECTED (trackCue.line == '-1') OK
     16EXPECTED (trackCue.line == 'auto') OK
    1717EXPECTED (trackCue.position == 'auto') OK
    1818EXPECTED (trackCue.size == '100') OK
     
    3232EXPECTED (newCue.vertical == '') OK
    3333EXPECTED (newCue.snapToLines == 'true') OK
    34 EXPECTED (newCue.line == '-1') OK
     34EXPECTED (newCue.line == 'auto') OK
    3535EXPECTED (newCue.position == 'auto') OK
    3636EXPECTED (newCue.size == '100') OK
  • trunk/LayoutTests/media/track/track-vttcue.html

    r236531 r270738  
    3333                testExpected("trackCue.vertical", "");
    3434                testExpected("trackCue.snapToLines", true);
    35                 testExpected("trackCue.line", -1);
     35                testExpected("trackCue.line", 'auto');
    3636                testExpected("trackCue.position", 'auto');
    3737                testExpected("trackCue.size", 100);
     
    5353                testExpected("newCue.vertical", "");
    5454                testExpected("newCue.snapToLines", true);
    55                 testExpected("newCue.line", -1);
     55                testExpected("newCue.line", 'auto');
    5656                testExpected("newCue.position", 'auto');
    5757                testExpected("newCue.size", 100);
  • trunk/LayoutTests/media/track/track-webvtt-tc013-settings-expected.txt

    r236531 r270738  
    1313EXPECTED (cues[1].align == 'center') OK
    1414EXPECTED (cues[1].vertical == 'rl') OK
    15 EXPECTED (cues[2].line == '-1') OK
     15EXPECTED (cues[2].line == 'auto') OK
    1616EXPECTED (cues[2].position == '10') OK
    1717EXPECTED (cues[2].align == 'center') OK
     
    2828EXPECTED (cues[0].align == 'center') OK
    2929EXPECTED (cues[0].vertical == '') OK
    30 EXPECTED (cues[1].line == '-1') OK
     30EXPECTED (cues[1].line == 'auto') OK
    3131EXPECTED (cues[1].position == '50') OK
    3232EXPECTED (cues[1].align == 'end') OK
    3333EXPECTED (cues[1].vertical == '') OK
    34 EXPECTED (cues[2].line == '-1') OK
     34EXPECTED (cues[2].line == 'auto') OK
    3535EXPECTED (cues[2].position == 'auto') OK
    3636EXPECTED (cues[2].align == 'center') OK
    3737EXPECTED (cues[2].vertical == '') OK
    38 EXPECTED (cues[3].line == '-1') OK
     38EXPECTED (cues[3].line == 'auto') OK
    3939EXPECTED (cues[3].position == '90') OK
    4040EXPECTED (cues[3].align == 'center') OK
  • trunk/LayoutTests/media/track/track-webvtt-tc013-settings.html

    r236531 r270738  
    3030                            {
    3131                                property : "line",
    32                                 values : [100, 15, -1, 95],
     32                                values : [100, 15, 'auto', 95],
    3333                            },
    3434                            {
     
    5252                            {
    5353                                property : "line",
    54                                 values : [43, -1, -1, -1],
     54                                values : [43, 'auto', 'auto', 'auto'],
    5555                            },
    5656                            {
  • trunk/LayoutTests/media/track/track-webvtt-tc017-line-position-expected.txt

    r170694 r270738  
    2222*** Testing text track 1
    2323EXPECTED (cues.length == '6') OK
    24 EXPECTED (cues[0].line == '-1') OK
     24EXPECTED (cues[0].line == 'auto') OK
    2525EXPECTED (cues[0].snapToLines == 'true') OK
    26 EXPECTED (cues[1].line == '-1') OK
     26EXPECTED (cues[1].line == '0.5'), OBSERVED 'auto' FAIL
    2727EXPECTED (cues[1].snapToLines == 'true') OK
    28 EXPECTED (cues[2].line == '-1') OK
     28EXPECTED (cues[2].line == 'auto') OK
    2929EXPECTED (cues[2].snapToLines == 'true') OK
    30 EXPECTED (cues[3].line == '-1') OK
     30EXPECTED (cues[3].line == 'auto') OK
    3131EXPECTED (cues[3].snapToLines == 'true') OK
    32 EXPECTED (cues[4].line == '-1') OK
     32EXPECTED (cues[4].line == 'auto') OK
    3333EXPECTED (cues[4].snapToLines == 'true') OK
    34 EXPECTED (cues[5].line == '-1') OK
     34EXPECTED (cues[5].line == 'auto') OK
    3535EXPECTED (cues[5].snapToLines == 'true') OK
    3636END OF TEST
  • trunk/LayoutTests/media/track/track-webvtt-tc017-line-position.html

    r170694 r270738  
    5353                        {
    5454                            property : "line",
    55                             values : [-1, -1, -1, -1, -1, -1, -1],
     55                            values : ['auto', 0.5, 'auto', 'auto', 'auto', 'auto', 'auto'],
    5656                        },
    5757                        {
  • trunk/LayoutTests/media/track/track-webvtt-tc018-align-text-line-position-expected.txt

    r236531 r270738  
    3030EXPECTED (cues[0].align == 'center') OK
    3131EXPECTED (cues[0].position == 'auto') OK
    32 EXPECTED (cues[0].line == '-1') OK
     32EXPECTED (cues[0].line == 'auto') OK
    3333EXPECTED (cues[0].snapToLines == 'true') OK
    3434EXPECTED (cues[1].align == 'end') OK
    3535EXPECTED (cues[1].position == '0') OK
    36 EXPECTED (cues[1].line == '-1') OK
     36EXPECTED (cues[1].line == 'auto') OK
    3737EXPECTED (cues[1].snapToLines == 'true') OK
    3838EXPECTED (cues[2].align == 'center') OK
  • trunk/LayoutTests/media/track/track-webvtt-tc018-align-text-line-position.html

    r236531 r270738  
    7171                        {
    7272                            property : "line",
    73                             values : [-1, -1, -3],
     73                            values : ['auto', 'auto', -3],
    7474                        },
    7575                        {
  • trunk/Source/WebCore/ChangeLog

    r270737 r270738  
     12020-12-12  Frank Olivier  <frankolivier@apple.com>
     2
     3        Implement WebVTT VTTCue region attribute
     4        https://bugs.webkit.org/show_bug.cgi?id=168716
     5
     6        Reviewed by Eric Carlson.
     7
     8        Updated existing region tests.
     9
     10        * WebCore.xcodeproj/project.pbxproj:
     11        * html/shadow/MediaControlTextTrackContainerElement.cpp:
     12        (WebCore::MediaControlTextTrackContainerElement::processActiveVTTCue):
     13        * html/track/TextTrackCueGeneric.cpp:
     14        (WebCore::TextTrackCueGenericBoxElement::applyCSSProperties):
     15        (WebCore::TextTrackCueGeneric::setLine):
     16        * html/track/TextTrackCueGeneric.h:
     17        * html/track/VTTCue.cpp:
     18        (WebCore::horizontalKeyword):
     19        (WebCore::lineLeftKeyword):
     20        (WebCore::lineRightKeyword):
     21        (WebCore::autoKeyword):
     22        (WebCore::VTTCueBox::applyCSSProperties):
     23        (WebCore::VTTCue::setVertical):
     24        (WebCore::VTTCue::line const):
     25        (WebCore::VTTCue::setLine):
     26        (WebCore::VTTCue::lineAlign const):
     27        (WebCore::VTTCue::setLineAlign):
     28        (WebCore::VTTCue::positionAlign const):
     29        (WebCore::VTTCue::setPositionAlign):
     30        (WebCore::VTTCue::setAlign):
     31        (WebCore::VTTCue::setTrack):
     32        (WebCore::VTTCue::setRegion):
     33        (WebCore::VTTCue::region):
     34        (WebCore::VTTCue::regionId):
     35        (WebCore::VTTCue::calculateComputedLinePosition):
     36        (WebCore::VTTCue::getDisplayTree):
     37        (WebCore::VTTCue::removeDisplayTree):
     38        (WebCore::VTTCue::settingName):
     39        (WebCore::VTTCue::setCueSettings):
     40        (WebCore::VTTCue::toJSON const):
     41        (WebCore::VTTCue::setRegionId): Deleted.
     42        * html/track/VTTCue.h:
     43        (WebCore::VTTCue::line const): Deleted.
     44        (WebCore::VTTCue::regionId const): Deleted.
     45        * html/track/VTTCue.idl:
     46        * rendering/RenderVTTCue.cpp:
     47        (WebCore::RenderVTTCue::layout):
     48
    1492020-12-12  Simon Fraser  <simon.fraser@apple.com>
    250
  • trunk/Source/WebCore/html/shadow/MediaControlTextTrackContainerElement.cpp

    r269323 r270738  
    201201void MediaControlTextTrackContainerElement::processActiveVTTCue(VTTCue& cue)
    202202{
    203     DEBUG_LOG(LOGIDENTIFIER, "adding and positioning cue: \"", cue.text(), "\", start=", cue.startTime(), ", end=", cue.endTime(), ", line=", cue.line());
     203    DEBUG_LOG(LOGIDENTIFIER, "adding and positioning cue: \"", cue.text(), "\", start=", cue.startTime(), ", end=", cue.endTime());
    204204    Ref<TextTrackCueBox> displayBox = *cue.getDisplayTree(m_videoDisplaySize.size(), m_fontSize);
    205205
  • trunk/Source/WebCore/html/track/TextTrackCueGeneric.cpp

    r267074 r270738  
    8585
    8686    double textPosition = cue->calculateComputedTextPosition();
     87    double linePosition = cue->calculateComputedLinePosition();
    8788
    8889    CSSValueID alignment = cue->getCSSAlignment();
     
    9394    } else {
    9495        setInlineStyleProperty(CSSPropertyLeft, static_cast<float>(textPosition), CSSUnitType::CSS_PERCENTAGE);
    95         setInlineStyleProperty(CSSPropertyTop, static_cast<float>(cue->line()), CSSUnitType::CSS_PERCENTAGE);
     96        setInlineStyleProperty(CSSPropertyTop, static_cast<float>(linePosition), CSSUnitType::CSS_PERCENTAGE);
    9697
    9798        double authorFontSize = videoSize.height() * cue->baseFontSizeRelativeToVideoHeight() / 100.0;
     
    111112            setInlineStyleProperty(CSSPropertyHeight, newCueSize,  CSSUnitType::CSS_PERCENTAGE);
    112113            if ((alignment == CSSValueMiddle || alignment == CSSValueCenter) && multiplier != 1.0)
    113                 setInlineStyleProperty(CSSPropertyTop, static_cast<double>(cue->line() - (newCueSize - cue->getCSSSize()) / 2), CSSUnitType::CSS_PERCENTAGE);
     114                setInlineStyleProperty(CSSPropertyTop, static_cast<double>(linePosition - (newCueSize - cue->getCSSSize()) / 2), CSSUnitType::CSS_PERCENTAGE);
    114115        }
    115116    }
     
    175176}
    176177
    177 ExceptionOr<void> TextTrackCueGeneric::setLine(double line)
     178ExceptionOr<void> TextTrackCueGeneric::setLine(const LineAndPositionSetting& line)
    178179{
    179180    auto result = VTTCue::setLine(line);
  • trunk/Source/WebCore/html/track/TextTrackCueGeneric.h

    r262695 r270738  
    3939    WEBCORE_EXPORT static Ref<TextTrackCueGeneric> create(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end, const String& content);
    4040
    41     ExceptionOr<void> setLine(double) final;
     41    ExceptionOr<void> setLine(const LineAndPositionSetting&) final;
    4242    ExceptionOr<void> setPosition(const LineAndPositionSetting&) final;
    4343
  • trunk/Source/WebCore/html/track/VTTCue.cpp

    r267074 r270738  
    124124}
    125125
     126static const String& lineLeftKeyword()
     127{
     128    static NeverDestroyed<const String> lineLeft(MAKE_STATIC_STRING_IMPL("line-left"));
     129    return lineLeft;
     130}
     131
     132static const String& lineRightKeyword()
     133{
     134    static NeverDestroyed<const String> lineRight(MAKE_STATIC_STRING_IMPL("line-right"));
     135    return lineRight;
     136}
     137
     138static const String& autoKeyword()
     139{
     140    static NeverDestroyed<const String> autoX(MAKE_STATIC_STRING_IMPL("auto"));
     141    return autoX;
     142}
     143
    126144// ----------------------------
    127145
     
    337355        direction = VerticalGrowingRight;
    338356    else
    339         return Exception { SyntaxError };
    340    
     357        return { };
     358
    341359    if (direction == m_writingDirection)
    342360        return { };
     
    359377}
    360378
    361 ExceptionOr<void> VTTCue::setLine(double position)
    362 {
    363     // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-line
    364     // On setting, if the text track cue snap-to-lines flag is not set, and the new
    365     // value is negative or greater than 100, then throw an IndexSizeError exception.
    366     if (!m_snapToLines && !(position >= 0 && position <= 100))
    367         return Exception { IndexSizeError };
    368 
    369     // Otherwise, set the text track cue line position to the new value.
    370     if (m_linePosition == position)
    371         return { };
     379VTTCue::LineAndPositionSetting VTTCue::line() const
     380{
     381    if (std::isnan(m_linePosition))
     382        return Auto;
     383
     384    return m_linePosition;
     385}
     386
     387ExceptionOr<void> VTTCue::setLine(const LineAndPositionSetting& position)
     388{
     389    double linePosition = 0;
     390
     391    if (WTF::holds_alternative<AutoKeyword>(position)) {
     392        if (std::isnan(m_linePosition))
     393            return { };
     394        linePosition = std::numeric_limits<double>::quiet_NaN();
     395    } else {
     396        linePosition = WTF::get<double>(position);
     397
     398        if (m_linePosition == linePosition)
     399            return { };
     400    }
    372401
    373402    willChange();
    374     m_linePosition = position;
     403    m_linePosition = linePosition;
    375404    m_computedLinePosition = calculateComputedLinePosition();
    376405    didChange();
     
    378407    return { };
    379408}
     409
     410const String& VTTCue::lineAlign() const
     411{
     412    switch (m_lineAlignment) {
     413    case LignAlignmentStart:
     414        return startKeyword();
     415    case LignAlignmentCenter:
     416        return centerKeyword();
     417    case LignAlignmentEnd:
     418        return endKeyword();
     419    default:
     420        ASSERT_NOT_REACHED();
     421        return emptyString();
     422    }
     423}
     424
     425ExceptionOr<void> VTTCue::setLineAlign(const String& value)
     426{
     427    CueLignAlignment lineAlignment;
     428    if (value == startKeyword())
     429        lineAlignment = LignAlignmentStart;
     430    else if (value == centerKeyword())
     431        lineAlignment = LignAlignmentCenter;
     432    else if (value == endKeyword())
     433        lineAlignment = LignAlignmentEnd;
     434    else
     435        return { };
     436
     437    if (lineAlignment == m_lineAlignment)
     438        return { };
     439
     440    willChange();
     441    m_lineAlignment = lineAlignment;
     442    didChange();
     443
     444    return { };
     445}
     446
    380447
    381448VTTCue::LineAndPositionSetting VTTCue::position() const
     
    410477    willChange();
    411478    m_textPosition = textPosition;
     479    didChange();
     480
     481    return { };
     482}
     483
     484const String& VTTCue::positionAlign() const
     485{
     486    switch (m_positionAlignment) {
     487    case PositionAlignmentLignLeft:
     488        return lineLeftKeyword();
     489    case PositionAlignmentLignCenter:
     490        return centerKeyword();
     491    case PositionAlignmentLignRight:
     492        return lineRightKeyword();
     493    case PositionAlignmentLignAuto:
     494        return autoKeyword();
     495    default:
     496        ASSERT_NOT_REACHED();
     497        return emptyString();
     498    }
     499}
     500
     501ExceptionOr<void> VTTCue::setPositionAlign(const String& value)
     502{
     503    CuePositionAlignment positionAlignment;
     504    if (value == lineLeftKeyword())
     505        positionAlignment = PositionAlignmentLignLeft;
     506    else if (value == centerKeyword())
     507        positionAlignment = PositionAlignmentLignCenter;
     508    else if (value == lineRightKeyword())
     509        positionAlignment = PositionAlignmentLignRight;
     510    else if (value == autoKeyword())
     511        positionAlignment = PositionAlignmentLignAuto;
     512    else
     513        return { };
     514
     515    if (positionAlignment == m_positionAlignment)
     516        return { };
     517
     518    willChange();
     519    m_positionAlignment = positionAlignment;
    412520    didChange();
    413521
     
    473581        alignment = Right;
    474582    else
    475         return Exception { SyntaxError };
    476    
     583        return { };
     584
    477585    if (alignment == m_cueAlignment)
    478586        return { };
     
    544652}
    545653
    546 void VTTCue::setRegionId(const String& regionId)
    547 {
    548     if (m_regionId == regionId)
    549         return;
    550 
    551     willChange();
    552     m_regionId = regionId;
    553     didChange();
    554 }
    555 
    556654void VTTCue::notifyRegionWhenRemovingDisplayTree(bool notifyRegion)
    557655{
     
    572670}
    573671
     672void VTTCue::setTrack(TextTrack* track)
     673{
     674    LOG(Media, "VTTCue::setTrack");
     675    TextTrackCue::setTrack(track);
     676    if (!m_parsedRegionId.isEmpty()) {
     677        if (track != nullptr) {
     678            if (auto* regions = track->regions()) {
     679                if (auto region = regions->getRegionById(m_parsedRegionId))
     680                    m_region = RefPtr<VTTRegion>(region);
     681            }
     682        }
     683    }
     684}
     685
     686void VTTCue::setRegion(VTTRegion* region)
     687{
     688    if (m_region != region) {
     689        willChange();
     690        m_region = region;
     691        didChange();
     692    }
     693}
     694
     695VTTRegion* VTTCue::region()
     696{
     697    if (!m_region)
     698        return nullptr;
     699
     700    return &*m_region;
     701}
     702
     703const String& VTTCue::regionId()
     704{
     705    if (!m_region)
     706        return emptyString();
     707
     708    return m_region->id();
     709}
     710
    574711int VTTCue::calculateComputedLinePosition()
    575712{
     
    578715    // If the text track cue line position is numeric, then that is the text
    579716    // track cue computed line position.
    580     if (m_linePosition != undefinedPosition)
     717    if (!std::isnan(m_linePosition))
    581718        return m_linePosition;
    582719
     
    9031040
    9041041    if (track()) {
    905         if (auto* regions = track()->regions()) {
    906             if (auto region = regions->getRegionById(m_regionId))
    907                 region->cueStyleChanged();
    908         }
     1042        if (m_region)
     1043            m_region->cueStyleChanged();
    9091044    }
    9101045
     
    9211056    // The region needs to be informed about the cue removal.
    9221057    if (m_notifyRegion && track()) {
    923         if (VTTRegionList* regions = track()->regions()) {
    924             if (RefPtr<VTTRegion> region = regions->getRegionById(m_regionId)) {
    925                 if (m_displayTree)
    926                     region->willRemoveTextTrackCueBox(m_displayTree.get());
    927             }
    928         }
     1058        if (m_region && m_displayTree)
     1059            m_region->willRemoveTextTrackCueBox(m_displayTree.get());
    9291060    }
    9301061
     
    9881119        parsedSetting = Align;
    9891120    else if (input.scan("region"))
    990         parsedSetting = RegionId;
     1121        parsedSetting = Region;
    9911122
    9921123    // Verify that a ':' follows.
     
    11491280            break;
    11501281        }
    1151         case RegionId:
    1152             m_regionId = input.extractString(valueRun);
     1282        case Region: {
     1283            m_parsedRegionId = input.extractString(valueRun);
    11531284            break;
     1285        }
    11541286        case None:
    11551287            break;
     
    11601292    }
    11611293
    1162     // If cue's line position is not auto or cue's size is not 100 or cue's
    1163     // writing direction is not horizontal, but cue's region identifier is not
    1164     // the empty string, let cue's region identifier be the empty string.
    1165     if (!m_regionId.isEmpty() && (m_linePosition != undefinedPosition || m_cueSize != 100 || m_writingDirection != Horizontal))
    1166         m_regionId = emptyString();
    11671294}
    11681295
     
    12351362    object.setInteger("size"_s, m_cueSize);
    12361363    object.setString("align"_s, align());
    1237     object.setString("regionId"_s, regionId());
    12381364}
    12391365
  • trunk/Source/WebCore/html/track/VTTCue.h

    r267074 r270738  
    3636#include "HTMLElement.h"
    3737#include "TextTrackCue.h"
     38#include "VTTRegion.h"
    3839#include <wtf/TypeCasts.h>
    3940
     
    8485    using LineAndPositionSetting = Variant<double, AutoKeyword>;
    8586
     87    void setTrack(TextTrack*);
     88
    8689    const String& vertical() const;
    8790    ExceptionOr<void> setVertical(const String&);
     
    9093    void setSnapToLines(bool);
    9194
    92     double line() const { return m_linePosition; }
    93     virtual ExceptionOr<void> setLine(double);
     95    LineAndPositionSetting line() const;
     96    virtual ExceptionOr<void> setLine(const LineAndPositionSetting&);
     97
     98    const String& lineAlign() const;
     99    ExceptionOr<void> setLineAlign(const String&);
    94100
    95101    LineAndPositionSetting position() const;
    96102    virtual ExceptionOr<void> setPosition(const LineAndPositionSetting&);
    97103
     104    const String& positionAlign() const;
     105    ExceptionOr<void> setPositionAlign(const String&);
     106
    98107    int size() const { return m_cueSize; }
    99108    ExceptionOr<void> setSize(int);
     
    111120    RefPtr<DocumentFragment> createCueRenderingTree();
    112121
    113     const String& regionId() const { return m_regionId; }
    114     void setRegionId(const String&);
    115122    void notifyRegionWhenRemovingDisplayTree(bool);
     123
     124    VTTRegion* region();
     125    void setRegion(VTTRegion*);
     126
     127    const String& regionId();
    116128
    117129    void setIsActive(bool) override;
     
    153165    CueAlignment getAlignment() const { return m_cueAlignment; }
    154166
     167    enum CueLignAlignment {
     168        LignAlignmentStart,
     169        LignAlignmentCenter,
     170        LignAlignmentEnd,
     171        NumberOfCueLineAlignments
     172    };
     173
     174    enum CuePositionAlignment {
     175        PositionAlignmentLignLeft,
     176        PositionAlignmentLignCenter,
     177        PositionAlignmentLignRight,
     178        PositionAlignmentLignAuto,
     179        NumberOfCuePositionAlignments
     180    };
     181
    155182    void recalculateStyles() final { m_displayTreeShouldChange = true; }
    156183    void setFontSize(int, const IntSize&, bool important) override;
     
    182209
    183210    bool textPositionIsAuto() const;
    184    
     211
    185212    void determineTextDirection();
    186213    void calculateDisplayParameters();
     
    193220        Size,
    194221        Align,
    195         RegionId
     222        Region
    196223    };
    197224    CueSetting settingName(VTTScanner&);
     
    201228    String m_content;
    202229    String m_settings;
    203     double m_linePosition { undefinedPosition };
    204     double m_computedLinePosition { undefinedPosition };
     230    double m_linePosition { std::numeric_limits<double>::quiet_NaN() };
     231    double m_computedLinePosition { std::numeric_limits<double>::quiet_NaN() };
    205232    double m_textPosition { std::numeric_limits<double>::quiet_NaN() };
    206233    int m_cueSize { 100 };
     
    208235    WritingDirection m_writingDirection { Horizontal };
    209236    CueAlignment m_cueAlignment { Center };
    210     String m_regionId;
     237
     238    RefPtr<VTTRegion> m_region;
     239    String m_parsedRegionId;
    211240
    212241    RefPtr<DocumentFragment> m_webVTTNodeTree;
     
    227256    bool m_displayTreeShouldChange : 1;
    228257    bool m_notifyRegion : 1;
     258
     259    CuePositionAlignment m_positionAlignment { PositionAlignmentLignAuto };
     260    CueLignAlignment m_lineAlignment { LignAlignmentStart };
    229261};
    230262
  • trunk/Source/WebCore/html/track/VTTCue.idl

    r267813 r270738  
    3737    attribute DOMString vertical;
    3838    attribute boolean snapToLines;
    39     attribute double line;
     39    attribute LineAndPositionSetting line;
     40    attribute DOMString lineAlign;
    4041    attribute LineAndPositionSetting position;
     42    attribute DOMString positionAlign;
    4143    attribute double size;
    4244    attribute DOMString align;
     
    4446    DocumentFragment getCueAsHTML();
    4547
    46     attribute DOMString regionId;
     48    attribute VTTRegion? region;
    4749};
Note: See TracChangeset for help on using the changeset viewer.