From ed93c318ea694da22ab23080a68b7f6240ed997f Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Fri, 29 Sep 2023 03:29:28 -0700 Subject: [PATCH] Implement updated TextTrackCue constructor proposal https://bugs.webkit.org/show_bug.cgi?id=262053 rdar://116002871 Reviewed by Eric Carlson. Implements spec changes suggested at: https://github.com/whatwg/html/pull/9771 Specifically: * supports `b` and `i` elements, to match WebVTT * drops support for allowing `img` in the cue fragment * implements more robust error checking to prevent malformed ::cue and :cuebackground hierarchies * As such, ::tagPseudoObjects() can now throw * Switch from InvalidStateError to InvalidNodeTypeError for when required attributes are missing * implements cuebackground and cue global attributes * LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement.html: * LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cue-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cue.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor.html: * LayoutTests/inspector/model/remote-object/dom-expected.txt: * LayoutTests/media/track/texttrackcue/texttrackcue-constructor-expected.txt: * LayoutTests/media/track/texttrackcue/texttrackcue-constructor.html: * Source/WebCore/html/HTMLAttributeNames.in: * Source/WebCore/html/HTMLElement.idl: * Source/WebCore/html/track/TextTrackCue.cpp: (WebCore::isLegalNode): (WebCore::tagPseudoObjects): (WebCore::removePseudoAttributes): (WebCore::TextTrackCue::create): (WebCore::TextTrackCue::setPauseOnExit): (WebCore::cueAttributName): Deleted. (WebCore::cueBackgroundAttributName): Deleted. Canonical link: https://commits.webkit.org/268644@main --- .../reactions/HTMLElement-expected.txt | 4 + .../reactions/HTMLElement.html | 3 +- .../global-attributes/cue-expected.txt | 25 + .../dom/elements/global-attributes/cue.html | 112 ++++ .../cuebackground-expected.txt | 25 + .../global-attributes/cuebackground.html | 110 ++++ .../media-elements/historical-expected.txt | 1 - .../media-elements/historical.html | 7 - .../TextTrackCue/constructor-expected.txt | 147 ++++- .../interfaces/TextTrackCue/constructor.html | 607 +++++++++++++++++- .../model/remote-object/dom-expected.txt | 2 +- .../texttrackcue-constructor-expected.txt | 2 +- .../texttrackcue-constructor.html | 9 +- Source/WebCore/html/HTMLAttributeNames.in | 2 + Source/WebCore/html/HTMLElement.idl | 4 + Source/WebCore/html/track/TextTrackCue.cpp | 69 +- 16 files changed, 1069 insertions(+), 60 deletions(-) create mode 100644 LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cue-expected.txt create mode 100644 LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cue.html create mode 100644 LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground-expected.txt create mode 100644 LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground.html diff --git a/LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement-expected.txt index fc0e54a15b2e4..9deb712ef7105 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement-expected.txt @@ -1,4 +1,8 @@ +PASS cue on HTMLElement must enqueue an attributeChanged reaction when adding cue content attribute +PASS cue on HTMLElement must enqueue an attributeChanged reaction when replacing an existing attribute +PASS cuebackground on HTMLElement must enqueue an attributeChanged reaction when adding cuebackground content attribute +PASS cuebackground on HTMLElement must enqueue an attributeChanged reaction when replacing an existing attribute PASS title on HTMLElement must enqueue an attributeChanged reaction when adding title content attribute PASS title on HTMLElement must enqueue an attributeChanged reaction when replacing an existing attribute PASS lang on HTMLElement must enqueue an attributeChanged reaction when adding lang content attribute diff --git a/LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement.html b/LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement.html index bd252282161b5..38b7efc2b18f4 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement.html +++ b/LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement.html @@ -13,7 +13,8 @@
+ + + + + + + + + diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground-expected.txt new file mode 100644 index 0000000000000..686c431f48252 --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground-expected.txt @@ -0,0 +1,25 @@ + +PASS "cuebackground" attribute in HTML defaults to false +PASS Boolean attributes should be case-insensitive +PASS Setting "cuebackground" attribute in HTML should set the property to true +PASS Getting a present "cuebackground" attribute should return the attribute value +PASS Setting "cuebackground" attribute using setAttribute should set the property to true +PASS Setting the 'cuebackground' to true should set its value to empty string +PASS Toggling "cuebackground" attribute should result in the correct value +PASS Cloning an element should preserve the boolean attribute +PASS Boolean attribute should work correctly on dynamically created elements +PASS Removing "cuebackground" attribute using removeAttribute should set the property to false +PASS Setting "cuebackground" property via JavaScript should reflect the correct boolean value +PASS Setting "cue" property via JavaScript should reflect in the content attribute +PASS Setting "cuebackground" property in JavaScript with truthy value (boolean true) should set the property to true +PASS Setting "cuebackground" property in JavaScript with truthy value (number 1) should set the property to true +PASS Setting "cuebackground" property in JavaScript with truthy value (string true) should set the property to true +PASS Setting "cuebackground" property in JavaScript with truthy value (object [object Object]) should set the property to true +PASS Setting "cuebackground" property in JavaScript with truthy value (object ) should set the property to true +PASS Setting "cuebackground" property in JavaScript with truthy value (string any-non-empty-string) should set the property to true +PASS Setting "cuebackground" property in JavaScript with falsy value (false) should set the property to false +PASS Setting "cuebackground" property in JavaScript with falsy value (0) should set the property to false +PASS Setting "cuebackground" property in JavaScript with falsy value () should set the property to false +PASS Setting "cuebackground" property in JavaScript with falsy value (null) should set the property to false +PASS Setting "cuebackground" property in JavaScript with falsy value (undefined) should set the property to false + diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground.html b/LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground.html new file mode 100644 index 0000000000000..634b80fc67bf0 --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground.html @@ -0,0 +1,110 @@ + + + + Test for cuebackground attribute + + + + + + + + + + + diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical-expected.txt index 619386c985ddf..6a0dc4292c2cf 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical-expected.txt @@ -47,7 +47,6 @@ PASS audio.mozPreservesPitch should not be supported PASS video.mozPreservesPitch should not be supported FAIL audio.webkitPreservesPitch should not be supported assert_false: expected false got true FAIL video.webkitPreservesPitch should not be supported assert_false: expected false got true -PASS TextTrackCue constructor should not be supported FAIL audio.mediaGroup should not be supported assert_false: expected false got true FAIL video.mediaGroup should not be supported assert_false: expected false got true FAIL audio.controller should not be supported assert_false: expected false got true diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical.html b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical.html index d7395632eb909..7d381a586dc95 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical.html +++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical.html @@ -39,13 +39,6 @@ t('mozPreservesPitch'); // prefixed version should be removed. t('webkitPreservesPitch'); // prefixed version should be removed. -// TextTrackCue constructor: added in r5723, removed in r7742. -test(function() { - assert_throws_js(TypeError, function() { - new TextTrackCue(0, 0, ''); - }); -}, 'TextTrackCue constructor should not be supported'); - // added in https://github.com/whatwg/html/commit/66c5b32240c202c74f475872e7ea2cd163777b4a // removed in https://github.com/whatwg/html/commit/634698e70ea4586d58c989fa7d2cbfcad20d33e6 t('mediaGroup'); diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor-expected.txt index 18a48042addf0..02c129a257b99 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor-expected.txt @@ -1,4 +1,149 @@ PASS TextTrackCue and VTTCue are separate interfaces -PASS TextTrackCue constructor should not be supported +PASS TextTrackCue constructor sets start time and end time correctly +PASS TextTrackCue constructor with equal startTime and endTime +PASS TextTrackCue constructor with extreme values for startTime and endTime +PASS TextTrackCue constructor with reversed extreme values for startTime and endTime +PASS TextTrackCue constructor with non-numeric startTime and endTime +PASS TextTrackCue constructor with NaN and Infinity for startTime and endTime +PASS TextTrackCue constructor throws InvalidNodeTypeError if cueFragment's first child is null +PASS TextTrackCue constructor with a DocumentFragment containing only Text nodes +PASS TextTrackCue constructor throws for non-exclusive Text nodes +PASS TextTrackCue can be successfully constructed with cue and cuebackground on the same element +PASS TextTrackCue constructor throws InvalidNodeTypeError for Comment +PASS TextTrackCue constructor throws InvalidNodeTypeError for ProcessingInstruction +PASS TextTrackCue with a CDATASection Node should throw InvalidNodeTypeError +PASS TextTrackCue constructor throws InvalidNodeTypeError for non-HTML namespace elements +PASS TextTrackCue constructor throws InvalidNodeTypeError for mixed namespace elements +PASS TextTrackCue constructor allows individual b element +PASS TextTrackCue constructor allows individual br element +PASS TextTrackCue constructor allows individual div element +PASS TextTrackCue constructor allows individual i element +PASS TextTrackCue constructor allows individual p element +PASS TextTrackCue constructor allows individual rb element +PASS TextTrackCue constructor allows individual rt element +PASS TextTrackCue constructor allows individual rtc element +PASS TextTrackCue constructor allows individual ruby element +PASS TextTrackCue constructor allows individual span element +PASS TextTrackCue constructor allows multiple allowed elements nested in a div with cue and cuebackground attributes +PASS TextTrackCue constructor allows nested allowed elements in a div with cue and cuebackground attributes +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual a element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual abbr element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual address element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual area element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual article element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual aside element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual audio element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual base element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual bdi element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual bdo element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual blockquote element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual body element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual button element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual canvas element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual caption element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual cite element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual code element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual col element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual colgroup element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual data element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual datalist element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual dd element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual del element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual details element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual dfn element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual dialog element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual dl element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual dt element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual em element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual embed element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual fieldset element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual figcaption element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual figure element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual footer element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual form element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual h1 element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual h2 element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual h3 element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual h4 element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual h5 element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual h6 element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual head element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual header element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual hgroup element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual hr element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual html element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual iframe element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual img element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual input element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual ins element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual kbd element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual label element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual legend element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual li element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual link element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual main element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual map element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual mark element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual meta element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual meter element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual nav element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual noscript element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual object element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual ol element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual optgroup element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual option element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual output element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual param element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual picture element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual pre element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual progress element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual q element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual s element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual samp element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual script element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual section element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual select element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual small element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual source element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual strong element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual style element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual sub element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual summary element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual sup element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual svg element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual table element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual tbody element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual td element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual template element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual textarea element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual tfoot element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual th element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual thead element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual time element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual title element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual tr element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual track element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual u element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual ul element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual var element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual video element +PASS TextTrackCue constructor throws InvalidNodeTypeError for individual wbr element +PASS TextTrackCue constructor throws InvalidNodeTypeError for interleaved b and a +PASS TextTrackCue constructor throws InvalidNodeTypeError for interleaved br and abbr +PASS TextTrackCue constructor throws InvalidNodeTypeError for interleaved div and address +PASS TextTrackCue constructor throws InvalidNodeTypeError for interleaved i and area +PASS TextTrackCue constructor throws InvalidNodeTypeError for interleaved p and article +PASS TextTrackCue constructor throws InvalidNodeTypeError for interleaved rb and aside +PASS TextTrackCue constructor throws InvalidNodeTypeError for interleaved rt and audio +PASS TextTrackCue constructor throws InvalidNodeTypeError for interleaved rtc and base +PASS TextTrackCue constructor throws InvalidNodeTypeError for interleaved ruby and bdi +PASS TextTrackCue constructor throws InvalidNodeTypeError for interleaved span and bdo +PASS TextTrackCue constructor with deeply nested allowed elements and each disallowed element at the end +PASS TextTrackCue constructor allows DocumentFragment from different documents +PASS TextTrackCue constructor throws if cue attribute is present with no cuebackground attribute +PASS TextTrackCue constructor throws if cuebackground attribute is present with no cue attribute +PASS TextTrackCue constructor allows multiple cue attributes with a cuebackground ancestor or on the same element +PASS Invalid hierarchy of cue and cuebackground attributes +PASS Invalid hierarchy with cue as ancestor of cuebackground diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor.html b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor.html index 8ee9adb1c0d30..57532765e5324 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor.html +++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor.html @@ -7,17 +7,608 @@ diff --git a/LayoutTests/inspector/model/remote-object/dom-expected.txt b/LayoutTests/inspector/model/remote-object/dom-expected.txt index e94ec7d803a22..6cca84080240d 100644 --- a/LayoutTests/inspector/model/remote-object/dom-expected.txt +++ b/LayoutTests/inspector/model/remote-object/dom-expected.txt @@ -166,7 +166,7 @@ EXPRESSION: span = document.createElement("span"); span.id = "foo"; span "_value": "" }, { - "_name": "hidden", + "_name": "cue", "_type": "boolean", "_value": "false" } diff --git a/LayoutTests/media/track/texttrackcue/texttrackcue-constructor-expected.txt b/LayoutTests/media/track/texttrackcue/texttrackcue-constructor-expected.txt index 46bbe355598c6..d73eed536c528 100644 --- a/LayoutTests/media/track/texttrackcue/texttrackcue-constructor-expected.txt +++ b/LayoutTests/media/track/texttrackcue/texttrackcue-constructor-expected.txt @@ -2,7 +2,7 @@ PASS TextTrackCue should throw "TypeError" if the cue node is not a documentFragment PASS TextTrackCue should throw "InvalidNodeTypeError" if passed an invalid documentFragment PASS TextTrackCue should throw "InvalidNodeTypeError" if documentFragment has an invalid node -PASS TextTrackCue should throw "InvalidStateError" if documentFragment doesn't have 'cuebackground' and 'cue' nodes +PASS TextTrackCue should throw "InvalidNodeTypeError" if documentFragment doesn't have 'cuebackground' and 'cue' nodes PASS TextTrackCue should allow all valid node types PASS Test TextTrackCue.getCueAsHTML() diff --git a/LayoutTests/media/track/texttrackcue/texttrackcue-constructor.html b/LayoutTests/media/track/texttrackcue/texttrackcue-constructor.html index 9e3a66eee30db..2261c5a72fbad 100644 --- a/LayoutTests/media/track/texttrackcue/texttrackcue-constructor.html +++ b/LayoutTests/media/track/texttrackcue/texttrackcue-constructor.html @@ -45,12 +45,12 @@ let validCue = new TextTrackCue(0, 10, fragment); fragment.firstChild.removeAttribute('cuebackground') - assert_throws_dom("InvalidStateError", _ => { new TextTrackCue(0, 10, fragment) }); + assert_throws_dom("InvalidNodeTypeError", _ => { new TextTrackCue(0, 10, fragment) }); fragment = createValidCueFragment(); fragment.firstChild.firstChild.removeAttribute('cue') - assert_throws_dom("InvalidStateError", _ => { new TextTrackCue(0, 10, fragment) }); -}, `TextTrackCue should throw "InvalidStateError" if documentFragment doesn't have 'cuebackground' and 'cue' nodes`); + assert_throws_dom("InvalidNodeTypeError", _ => { new TextTrackCue(0, 10, fragment) }); +}, `TextTrackCue should throw "InvalidNodeTypeError" if documentFragment doesn't have 'cuebackground' and 'cue' nodes`); test( test => { let fragment = createValidCueFragment(); @@ -62,9 +62,6 @@ fragment.firstChild.appendChild(document.createElement('div')); validCue = new TextTrackCue(0, 10, fragment); - fragment.firstChild.appendChild(document.createElement('img')); - validCue = new TextTrackCue(0, 10, fragment); - fragment.firstChild.appendChild(document.createElement('p')); validCue = new TextTrackCue(0, 10, fragment); diff --git a/Source/WebCore/html/HTMLAttributeNames.in b/Source/WebCore/html/HTMLAttributeNames.in index a0b579e643b43..16397c905f256 100644 --- a/Source/WebCore/html/HTMLAttributeNames.in +++ b/Source/WebCore/html/HTMLAttributeNames.in @@ -111,6 +111,8 @@ contenteditable controls coords crossorigin +cue +cuebackground data datetime declare diff --git a/Source/WebCore/html/HTMLElement.idl b/Source/WebCore/html/HTMLElement.idl index c4349feeb7509..1f10b47b786ad 100644 --- a/Source/WebCore/html/HTMLElement.idl +++ b/Source/WebCore/html/HTMLElement.idl @@ -34,6 +34,10 @@ [CEReactions=Needed] attribute boolean translate; [CEReactions=Needed] attribute [AtomString] DOMString dir; + // TextTrackCue related + [CEReactions=Needed, Reflect] attribute boolean cue; + [CEReactions=Needed, Reflect] attribute boolean cuebackground; + // user interaction [CEReactions=Needed, Reflect] attribute boolean hidden; undefined click(); diff --git a/Source/WebCore/html/track/TextTrackCue.cpp b/Source/WebCore/html/track/TextTrackCue.cpp index e6a3ad30cfb44..e3c645dad45e0 100644 --- a/Source/WebCore/html/track/TextTrackCue.cpp +++ b/Source/WebCore/html/track/TextTrackCue.cpp @@ -65,18 +65,6 @@ namespace WebCore { WTF_MAKE_ISO_ALLOCATED_IMPL(TextTrackCue); WTF_MAKE_ISO_ALLOCATED_IMPL(TextTrackCueBox); -static const QualifiedName& cueAttributName() -{ - static NeverDestroyed cueTag(nullAtom(), "cue"_s, nullAtom()); - return cueTag; -} - -static const QualifiedName& cueBackgroundAttributName() -{ - static NeverDestroyed cueBackgroundTag(nullAtom(), "cuebackground"_s, nullAtom()); - return cueBackgroundTag; -} - Ref TextTrackCueBox::create(Document& document, TextTrackCue& cue) { auto box = adoptRef(*new TextTrackCueBox(document, cue)); @@ -102,13 +90,14 @@ TextTrackCue* TextTrackCueBox::getCue() const static inline bool isLegalNode(Node& node) { - return node.hasTagName(HTMLNames::brTag) + return node.hasTagName(HTMLNames::bTag) + || node.hasTagName(HTMLNames::brTag) || node.hasTagName(HTMLNames::divTag) - || node.hasTagName(HTMLNames::imgTag) + || node.hasTagName(HTMLNames::iTag) || node.hasTagName(HTMLNames::pTag) || node.hasTagName(HTMLNames::rbTag) - || node.hasTagName(HTMLNames::rtTag) || node.hasTagName(HTMLNames::rtcTag) + || node.hasTagName(HTMLNames::rtTag) || node.hasTagName(HTMLNames::rubyTag) || node.hasTagName(HTMLNames::spanTag) || node.nodeType() == Node::TEXT_NODE; @@ -143,26 +132,32 @@ enum RequiredNodes { CueBackground = 1 << 1, }; -static OptionSet tagPseudoObjects(Node& node) +static ExceptionOr tagPseudoObjects(Node& node, OptionSet& nodeTypes) { if (!is(node)) return { }; - OptionSet nodeTypes = { }; - auto& element = downcast(node); - if (element.hasAttributeWithoutSynchronization(cueAttributName())) { - element.setPseudo(ShadowPseudoIds::cue()); - nodeTypes = { RequiredNodes::Cue }; - } else if (element.hasAttributeWithoutSynchronization(cueBackgroundAttributName())) { + + if (element.hasAttributeWithoutSynchronization(HTMLNames::cuebackgroundAttr)) { element.setPseudo(ShadowPseudoIds::webkitMediaTextTrackDisplayBackdrop()); - nodeTypes = { RequiredNodes::CueBackground }; + nodeTypes.add(RequiredNodes::CueBackground); } - for (auto* child = element.firstChild(); child; child = child->nextSibling()) - nodeTypes.add(tagPseudoObjects(*child)); + if (element.hasAttributeWithoutSynchronization(HTMLNames::cueAttr)) { + if (!nodeTypes.contains(RequiredNodes::CueBackground) || !element.closest("[cuebackground]"_s).returnValue()) + return Exception { HierarchyRequestError, "Found cue attribute but no cuebackground attribute in hierarchy "_s }; - return nodeTypes; + element.setPseudo(ShadowPseudoIds::cue()); + nodeTypes.add(RequiredNodes::Cue); + } + + if (nodeTypes.contains(RequiredNodes::CueBackground) && nodeTypes.contains(RequiredNodes::Cue)) + return { }; + + for (auto* child = element.firstChild(); child; child = child->nextSibling()) + tagPseudoObjects(*child, nodeTypes); + return { }; } static void removePseudoAttributes(Node& node) @@ -171,7 +166,7 @@ static void removePseudoAttributes(Node& node) return; auto& element = downcast(node); - if (element.hasAttributeWithoutSynchronization(cueAttributName()) || element.hasAttributeWithoutSynchronization(cueBackgroundAttributName())) + if (element.hasAttributeWithoutSynchronization(HTMLNames::cueAttr) || element.hasAttributeWithoutSynchronization(HTMLNames::cuebackgroundAttr)) element.removeAttribute(HTMLNames::pseudoAttr); for (auto* child = element.firstChild(); child; child = child->nextSibling()) @@ -183,6 +178,9 @@ ExceptionOr> TextTrackCue::create(Document& document, double s if (!cueFragment.firstChild()) return Exception { InvalidNodeTypeError, "Empty cue fragment"_s }; + if (cueFragment.firstChild()->nodeType() == Node::TEXT_NODE) + return Exception { InvalidNodeTypeError, "Invalid first child"_s }; + for (Node* node = cueFragment.firstChild(); node; node = node->nextSibling()) { auto result = checkForInvalidNodeTypes(*node); if (result.hasException()) @@ -198,13 +196,16 @@ ExceptionOr> TextTrackCue::create(Document& document, double s cueFragment.cloneChildNodes(fragment); OptionSet nodeTypes = { }; - for (Node* node = fragment->firstChild(); node; node = node->nextSibling()) - nodeTypes.add(tagPseudoObjects(*node)); + for (Node* node = fragment->firstChild(); node; node = node->nextSibling()) { + auto result = tagPseudoObjects(*node, nodeTypes); + if (result.hasException()) + return result.releaseException(); + } if (!nodeTypes.contains(RequiredNodes::Cue)) - return Exception { InvalidStateError, makeString("Missing required attribute: ", cueAttributName().toString()) }; + return Exception { InvalidNodeTypeError, "Missing required attribute: cue"_s }; if (!nodeTypes.contains(RequiredNodes::CueBackground)) - return Exception { InvalidStateError, makeString("Missing required attribute: ", cueBackgroundAttributName().toString()) }; + return Exception { InvalidNodeTypeError, "Missing required attribute: cuebackground"_s }; auto textTrackCue = adoptRef(*new TextTrackCue(document, MediaTime::createWithDouble(start), MediaTime::createWithDouble(end), WTFMove(fragment))); textTrackCue->suspendIfNeeded(); @@ -291,7 +292,7 @@ void TextTrackCue::setStartTime(const MediaTime& value) m_startTime = value; didChange(); } - + void TextTrackCue::setEndTime(double value) { if (m_endTime.toDouble() == value) @@ -306,12 +307,12 @@ void TextTrackCue::setEndTime(const MediaTime& value) m_endTime = value; didChange(); } - + void TextTrackCue::setPauseOnExit(bool value) { if (m_pauseOnExit == value) return; - + m_pauseOnExit = value; }