Title: [136131] trunk
Revision
136131
Author
[email protected]
Date
2012-11-29 07:33:03 -0800 (Thu, 29 Nov 2012)

Log Message

Source/WebCore: HTMLMediaElement's .textTracks property does not reflect <track> element
https://bugs.webkit.org/show_bug.cgi?id=103420

Reviewed by Eric Carlson.

There were some assumptions that <track> elements are valid only
if the parent <media> is in document. This change relaxes this
assumption so that <track> is valid when it has <media> as a
parent regardless whether the <media> is in the document or not.

HTMLMediaElement::didAddTrack and didRemoveTrack are now called
when the <track> is inserted to or removed from the parent <media>
element.

Test: media/track/track-node-add-remove.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::didRemoveTrack):
Renamed from willRemoveTrack() to reflect the timing. This was once called from
Node::willRemove(), which was removed a while ago.
* html/HTMLMediaElement.h:
(HTMLMediaElement):
* html/HTMLTrackElement.cpp:
(WebCore::HTMLTrackElement::insertedInto):
The old code notified parent <media> only if the subtree became a part of the document.
Now it notifies the <media> when this <track> becomes a child of that <media>.

(WebCore::HTMLTrackElement::removedFrom):
The old code notifies the parent <media> every time as long as the parent is available.
Now it notifies the <media> only if this <track> is removed from the parent <media>.
This matches how corresponding notification is done in insertedInto().

* html/track/LoadableTextTrack.cpp:
(WebCore::LoadableTextTrack::trackElementIndex):

LayoutTests: HTMLMediaElement's .textTracks property does not reflect <track> element
https://bugs.webkit.org/show_bug.cgi?id=103420

Reviewed by Eric Carlson.

* media/track/track-node-add-remove-expected.txt: Added.
* media/track/track-node-add-remove.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (136130 => 136131)


--- trunk/LayoutTests/ChangeLog	2012-11-29 15:31:17 UTC (rev 136130)
+++ trunk/LayoutTests/ChangeLog	2012-11-29 15:33:03 UTC (rev 136131)
@@ -1,3 +1,13 @@
+2012-11-29  Hajime Morrita  <[email protected]>
+
+        HTMLMediaElement's .textTracks property does not reflect <track> element
+        https://bugs.webkit.org/show_bug.cgi?id=103420
+        
+        Reviewed by Eric Carlson.
+
+        * media/track/track-node-add-remove-expected.txt: Added.
+        * media/track/track-node-add-remove.html: Added.
+
 2012-11-29  Alexander Pavlov  <[email protected]>
 
         [Chromium] Unreviewed, update Mac expectation after r136128.

Added: trunk/LayoutTests/media/track/track-node-add-remove-expected.txt (0 => 136131)


--- trunk/LayoutTests/media/track/track-node-add-remove-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/track/track-node-add-remove-expected.txt	2012-11-29 15:33:03 UTC (rev 136131)
@@ -0,0 +1,24 @@
+Adding tracks outside the DOM tree:
+PASS video.textTracks.length is 2
+PASS video.textTracks[0] is tracka.track
+PASS video.textTracks[1] is trackb.track
+Inserting the parent video element into the document.
+PASS video.textTracks.length is 2
+PASS video.textTracks[0] is tracka.track
+PASS video.textTracks[1] is trackb.track
+Inserting and removing another track in the document.
+PASS video.textTracks.length is 3
+PASS video.textTracks[2] is trackc.track
+PASS video.textTracks.length is 2
+PASS video.textTracks[0] is tracka.track
+PASS video.textTracks[1] is trackc.track
+Removing the video from the document.
+PASS video.textTracks.length is 2
+PASS video.textTracks[0] is tracka.track
+PASS video.textTracks[1] is trackc.track
+PASS video.textTracks.length is 1
+PASS video.textTracks[0] is trackc.track
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/media/track/track-node-add-remove.html (0 => 136131)


--- trunk/LayoutTests/media/track/track-node-add-remove.html	                        (rev 0)
+++ trunk/LayoutTests/media/track/track-node-add-remove.html	2012-11-29 15:33:03 UTC (rev 136131)
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+var video = document.createElement('video');
+
+var tracka = document.createElement('track');
+video.appendChild(tracka);
+var trackb = document.createElement('track');
+video.appendChild(trackb);
+
+debug("Adding tracks outside the DOM tree:");
+shouldBe("video.textTracks.length", "2");
+shouldBe("video.textTracks[0]", "tracka.track");
+shouldBe("video.textTracks[1]", "trackb.track");
+
+debug("Inserting the parent video element into the document.");
+document.body.appendChild(video);
+shouldBe("video.textTracks.length", "2");
+shouldBe("video.textTracks[0]", "tracka.track");
+shouldBe("video.textTracks[1]", "trackb.track");
+
+debug("Inserting and removing another track in the document.");
+var trackc = document.createElement('track');
+video.appendChild(trackc);
+shouldBe("video.textTracks.length", "3");
+shouldBe("video.textTracks[2]", "trackc.track");
+
+trackb.parentNode.removeChild(trackb);
+shouldBe("video.textTracks.length", "2");
+shouldBe("video.textTracks[0]", "tracka.track");
+shouldBe("video.textTracks[1]", "trackc.track");
+
+debug("Removing the video from the document.");
+document.body.removeChild(video);
+shouldBe("video.textTracks.length", "2");
+shouldBe("video.textTracks[0]", "tracka.track");
+shouldBe("video.textTracks[1]", "trackc.track");
+
+tracka.parentNode.removeChild(tracka);
+shouldBe("video.textTracks.length", "1");
+shouldBe("video.textTracks[0]", "trackc.track");
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (136130 => 136131)


--- trunk/Source/WebCore/ChangeLog	2012-11-29 15:31:17 UTC (rev 136130)
+++ trunk/Source/WebCore/ChangeLog	2012-11-29 15:33:03 UTC (rev 136131)
@@ -1,3 +1,40 @@
+2012-11-29  Hajime Morrita  <[email protected]>
+
+        HTMLMediaElement's .textTracks property does not reflect <track> element
+        https://bugs.webkit.org/show_bug.cgi?id=103420
+
+        Reviewed by Eric Carlson.
+
+        There were some assumptions that <track> elements are valid only
+        if the parent <media> is in document. This change relaxes this
+        assumption so that <track> is valid when it has <media> as a
+        parent regardless whether the <media> is in the document or not.
+
+        HTMLMediaElement::didAddTrack and didRemoveTrack are now called
+        when the <track> is inserted to or removed from the parent <media>
+        element.
+
+        Test: media/track/track-node-add-remove.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::didRemoveTrack):
+        Renamed from willRemoveTrack() to reflect the timing. This was once called from
+        Node::willRemove(), which was removed a while ago.
+        * html/HTMLMediaElement.h:
+        (HTMLMediaElement):
+        * html/HTMLTrackElement.cpp:
+        (WebCore::HTMLTrackElement::insertedInto):
+        The old code notified parent <media> only if the subtree became a part of the document.
+        Now it notifies the <media> when this <track> becomes a child of that <media>.
+
+        (WebCore::HTMLTrackElement::removedFrom):
+        The old code notifies the parent <media> every time as long as the parent is available.
+        Now it notifies the <media> only if this <track> is removed from the parent <media>.
+        This matches how corresponding notification is done in insertedInto().
+
+        * html/track/LoadableTextTrack.cpp:
+        (WebCore::LoadableTextTrack::trackElementIndex):
+
 2012-11-29  Florin Malita  <[email protected]>
 
         [Skia] Add missing OpaqueRegionSkia notifier calls

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (136130 => 136131)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2012-11-29 15:31:17 UTC (rev 136130)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2012-11-29 15:33:03 UTC (rev 136131)
@@ -2841,7 +2841,7 @@
         scheduleLoad(TextTrackResource);
 }
 
-void HTMLMediaElement::willRemoveTrack(HTMLTrackElement* trackElement)
+void HTMLMediaElement::didRemoveTrack(HTMLTrackElement* trackElement)
 {
     ASSERT(trackElement->hasTagName(trackTag));
 
@@ -2851,7 +2851,7 @@
 #if !LOG_DISABLED
     if (trackElement->hasTagName(trackTag)) {
         KURL url = ""
-        LOG(Media, "HTMLMediaElement::willRemoveTrack - 'src' is %s", urlForLogging(url).utf8().data());
+        LOG(Media, "HTMLMediaElement::didRemoveTrack - 'src' is %s", urlForLogging(url).utf8().data());
     }
 #endif
 

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (136130 => 136131)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2012-11-29 15:31:17 UTC (rev 136130)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2012-11-29 15:33:03 UTC (rev 136131)
@@ -221,7 +221,7 @@
     CueList currentlyActiveCues() const { return m_currentlyActiveCues; }
 
     virtual void didAddTrack(HTMLTrackElement*);
-    virtual void willRemoveTrack(HTMLTrackElement*);
+    virtual void didRemoveTrack(HTMLTrackElement*);
 
     struct TrackGroup {
         enum GroupKind { CaptionsAndSubtitles, Description, Chapter, Metadata, Other };

Modified: trunk/Source/WebCore/html/HTMLTrackElement.cpp (136130 => 136131)


--- trunk/Source/WebCore/html/HTMLTrackElement.cpp	2012-11-29 15:31:17 UTC (rev 136130)
+++ trunk/Source/WebCore/html/HTMLTrackElement.cpp	2012-11-29 15:33:03 UTC (rev 136131)
@@ -75,22 +75,16 @@
 Node::InsertionNotificationRequest HTMLTrackElement::insertedInto(ContainerNode* insertionPoint)
 {
     HTMLElement::insertedInto(insertionPoint);
-    if (insertionPoint->inDocument()) {
-        if (HTMLMediaElement* parent = mediaElement())
-            parent->didAddTrack(this);
-    }
-
+    HTMLMediaElement* parent = mediaElement();
+    if (insertionPoint == parent)
+        parent->didAddTrack(this);
     return InsertionDone;
 }
 
 void HTMLTrackElement::removedFrom(ContainerNode* insertionPoint)
 {
-    HTMLMediaElement* parent = mediaElement();
-    if (!parent && WebCore::isMediaElement(insertionPoint))
-        parent = toMediaElement(insertionPoint);
-    if (parent)
-        parent->willRemoveTrack(this);
-
+    if (!parentNode() && WebCore::isMediaElement(insertionPoint))
+        toMediaElement(insertionPoint)->didRemoveTrack(this);
     HTMLElement::removedFrom(insertionPoint);
 }
 

Modified: trunk/Source/WebCore/html/track/LoadableTextTrack.cpp (136130 => 136131)


--- trunk/Source/WebCore/html/track/LoadableTextTrack.cpp	2012-11-29 15:31:17 UTC (rev 136130)
+++ trunk/Source/WebCore/html/track/LoadableTextTrack.cpp	2012-11-29 15:33:03 UTC (rev 136131)
@@ -130,7 +130,7 @@
 
     size_t index = 0;
     for (Node* node = m_trackElement->parentNode()->firstChild(); node; node = node->nextSibling()) {
-        if (!node->hasTagName(trackTag) || !node->inDocument())
+        if (!node->hasTagName(trackTag) || !node->parentNode())
             continue;
         if (node == m_trackElement)
             return index;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to