Changeset 138784 in webkit


Ignore:
Timestamp:
Jan 4, 2013 1:15:55 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Implement :future pseudo class for the WebVTT ::cue pseudo element
https://bugs.webkit.org/show_bug.cgi?id=105473

Patch by Dima Gorbik <dgorbik@apple.com> on 2013-01-04
Reviewed by Antti Koivisto.

Source/WebCore:

This patch changes the approach of showing past/future node objects.
Before upper-level containers were used to put past and future nodes inside. Styles were applied
to containers. Now styles could be applied directly to nodes by using ::cue(:future).
That allows to style future/past WebVTT nodes even if they are nested.

Existing test was modified to cover new cases.

  • css/CSSSelector.cpp: added :future pseudo class support.

(WebCore::CSSSelector::pseudoId):
(WebCore::nameToPseudoTypeMap):
(WebCore::CSSSelector::extractPseudoType):

  • css/CSSSelector.h:
  • css/SelectorChecker.cpp: ditto.

(WebCore::SelectorChecker::checkOneSelector):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::canShareStyleWithElement): define style sharing rules for WebVTT objects.

  • css/mediaControls.css:

(video::-webkit-media-text-track-all-nodes):
(video::cue(:future)): added standard user-agent styles for the future nodes.

  • dom/Element.cpp: setter functions don't have an argument now because WebVTT type enum was introduced and the right type is set

when the setter is being called.
(WebCore::Element::setIsWebVTTNode):
(WebCore):
(WebCore::Element::isWebVTTFutureNode):
(WebCore::Element::setIsWebVTTFutureNode):

  • dom/Element.h:

(Element):

  • dom/ElementRareData.h:

(ElementRareData):

  • dom/NodeRareData.cpp:

(SameSizeAsNodeRareData): added a dummy enum value. Enum is integer type and is aligned in Windows when placed in the bitfield,
so it takes more space.

  • dom/NodeRareData.h:

(WebCore::NodeRareData::NodeRareData):
(WebCore::NodeRareData::isWebVTTNode):
(WebCore::NodeRareData::setIsWebVTTNode):
(WebCore::NodeRareData::isWebVTTFutureNode):
(WebCore::NodeRareData::setIsWebVTTFutureNode):
(NodeRareData):

  • html/shadow/MediaControlElements.cpp:

(WebCore):

  • html/track/TextTrack.h: add a WebVTT node object type enum.

(TextTrack):

  • html/track/TextTrackCue.cpp:

(WebCore::TextTrackCue::allNodesShadowPseudoId):
(WebCore::TextTrackCue::TextTrackCue):
(WebCore::TextTrackCue::getCueAsHTML):
(WebCore):
(WebCore::TextTrackCue::setNodeObjectFlags): determine if the node is future or past and mark as WebVTT node.
This combines the functionality related to marking nodes implemented before in updateDisplayTree and
markNodesAsWebVTTNodes.
(WebCore::TextTrackCue::updateDisplayTree):
(WebCore::TextTrackCue::getDisplayTree):

  • html/track/TextTrackCue.h:

(TextTrackCue):

  • html/track/WebVTTParser.cpp:

(WebCore::WebVTTParser::constructTreeFromToken): no need to mark nodes as WebVTT nodes when parsing. This is done at the
rendering stage later.

  • page/CaptionUserPreferencesMac.mm:

(WebCore::CaptionUserPreferencesMac::captionsStyleSheetOverride): the container name has changed.

LayoutTests:

Modified the track css matching test to cover :future pseudo-class case.

  • media/track/captions-webvtt/captions-inner-timestamps.vtt: Removed.
  • media/track/captions-webvtt/styling.vtt:
  • media/track/track-css-matching-expected.txt:
  • media/track/track-css-matching.html:
  • media/track/track-cue-rendering-inner-timestamps-expected.txt: Removed.
  • media/track/track-cue-rendering-inner-timestamps.html: The test was removed because it was based on the old

future/past nodes rendering logic.

Location:
trunk
Files:
3 deleted
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r138782 r138784  
     12013-01-04  Dima Gorbik  <dgorbik@apple.com>
     2
     3        Implement :future pseudo class for the WebVTT ::cue pseudo element
     4        https://bugs.webkit.org/show_bug.cgi?id=105473
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Modified the track css matching test to cover :future pseudo-class case.
     9
     10        * media/track/captions-webvtt/captions-inner-timestamps.vtt: Removed.
     11        * media/track/captions-webvtt/styling.vtt:
     12        * media/track/track-css-matching-expected.txt:
     13        * media/track/track-css-matching.html:
     14        * media/track/track-cue-rendering-inner-timestamps-expected.txt: Removed.
     15        * media/track/track-cue-rendering-inner-timestamps.html: The test was removed because it was based on the old
     16        future/past nodes rendering logic.
     17
    1182013-01-04  Carlos Garcia Campos  <cgarcia@igalia.com>
    219
  • trunk/LayoutTests/media/track/captions-webvtt/styling.vtt

    r137955 r138784  
    8800:01.000 --> 00:02.000
    99<c.red>dolor sit </c><c.green>amet, consectetur </c><c.red2>adipiscing elit</c>
     10
     113
     1200:02.000 --> 00:05.000
     13<00:02.000><c>Suspendisse accumsan, </c><00:03.000><c>mauris sed </c><00:04.000><c>euismod pharetra</c>
  • trunk/LayoutTests/media/track/track-css-matching-expected.txt

    r137955 r138784  
    1 Test that cues are being matched properly by the class name
     11. Test that cues are being matched properly by the class name
    22EVENT(canplaythrough)
    33EVENT(seeked)
     
    55EXPECTED (getComputedStyle(cueNode).color == 'rgb(0, 128, 0)') OK
    66EXPECTED (getComputedStyle(cueNode).color == 'rgb(255, 0, 0)') OK
     7
     8RUN(video.currentTime = 2.5)
     9EVENT(seeked)
     10
     11
     122. Test that cues are being matched properly by the ':future' pseudo class.
     13EXPECTED (getComputedStyle(cueNode).color == 'rgb(255, 255, 255)') OK
     14EXPECTED (getComputedStyle(cueNode).color == 'rgb(128, 128, 128)') OK
     15EXPECTED (getComputedStyle(cueNode).color == 'rgb(128, 128, 128)') OK
     16
     17RUN(video.currentTime = 3.5)
     18EVENT(seeked)
     19EXPECTED (getComputedStyle(cueNode).color == 'rgb(255, 255, 255)') OK
     20EXPECTED (getComputedStyle(cueNode).color == 'rgb(255, 255, 255)') OK
     21EXPECTED (getComputedStyle(cueNode).color == 'rgb(128, 128, 128)') OK
     22
     23RUN(video.currentTime = 4.5)
     24EVENT(seeked)
     25EXPECTED (getComputedStyle(cueNode).color == 'rgb(255, 255, 255)') OK
     26EXPECTED (getComputedStyle(cueNode).color == 'rgb(255, 255, 255)') OK
     27EXPECTED (getComputedStyle(cueNode).color == 'rgb(255, 255, 255)') OK
    728END OF TEST
    829
  • trunk/LayoutTests/media/track/track-css-matching.html

    r137955 r138784  
    1818
    1919        var cueNode;
    20 
     20        var seekedCount = 0;
     21        var info = [["rgb(255, 0, 0)", "rgb(0, 128, 0)", "rgb(255, 0, 0)"],
     22                    ["rgb(255, 255, 255)", "rgb(128, 128, 128)", "rgb(128, 128, 128)"],
     23                    ["rgb(255, 255, 255)", "rgb(255, 255, 255)", "rgb(128, 128, 128)"],
     24                    ["rgb(255, 255, 255)", "rgb(255, 255, 255)", "rgb(255, 255, 255)"]];
     25       
     26        function skipNonElements(root)
     27        {
     28            nextElementSibling = root;
     29            while (nextElementSibling.nodeType != 1) {
     30                nextElementSibling = nextElementSibling.nextSibling;
     31            }
     32            return nextElementSibling;
     33        }
     34       
    2135        function seeked()
    2236        {
    23             cueNode = textTrackDisplayElement(video, 'past-nodes').firstChild;
    24             testExpected("getComputedStyle(cueNode).color", "rgb(255, 0, 0)");
    25             cueNode = cueNode.nextSibling;
    26             testExpected("getComputedStyle(cueNode).color", "rgb(0, 128, 0)");
    27             cueNode = cueNode.nextSibling;
    28             testExpected("getComputedStyle(cueNode).color", "rgb(255, 0, 0)");
    29             endTest();
     37            if (testEnded)
     38                return;
     39
     40            if (seekedCount == 1) {
     41                consoleWrite("");
     42                consoleWrite("");
     43                consoleWrite("2. Test that cues are being matched properly by the ':future' pseudo class.");
     44            }
     45
     46            cueNode = skipNonElements(textTrackDisplayElement(video, 'all-nodes').firstChild);
     47            skipNonElements(cueNode);
     48            testExpected("getComputedStyle(cueNode).color", info[seekedCount][0]);
     49            cueNode = skipNonElements(cueNode.nextSibling);
     50            testExpected("getComputedStyle(cueNode).color", info[seekedCount][1]);
     51            cueNode = skipNonElements(cueNode.nextSibling);
     52            testExpected("getComputedStyle(cueNode).color", info[seekedCount][2]);
     53
     54            if (++seekedCount == info.length)
     55                endTest();
     56            else {
     57                consoleWrite("");
     58                run("video.currentTime = " + (video.currentTime + 1));
     59            }
    3060        }
    3161
    3262        function loaded()
    3363        {
    34             consoleWrite("Test that cues are being matched properly by the class name");
     64            consoleWrite("1. Test that cues are being matched properly by the class name");
    3565            findMediaElement();
    3666            video.src = findMediaFile('video', '../content/test');
  • trunk/Source/WebCore/ChangeLog

    r138782 r138784  
     12013-01-04  Dima Gorbik  <dgorbik@apple.com>
     2
     3        Implement :future pseudo class for the WebVTT ::cue pseudo element
     4        https://bugs.webkit.org/show_bug.cgi?id=105473
     5
     6        Reviewed by Antti Koivisto.
     7
     8        This patch changes the approach of showing past/future node objects.
     9        Before upper-level containers were used to put past and future nodes inside. Styles were applied
     10        to containers. Now styles could be applied directly to nodes by using ::cue(:future).
     11        That allows to style future/past WebVTT nodes even if they are nested.
     12
     13        Existing test was modified to cover new cases.
     14
     15        * css/CSSSelector.cpp: added :future pseudo class support.
     16        (WebCore::CSSSelector::pseudoId):
     17        (WebCore::nameToPseudoTypeMap):
     18        (WebCore::CSSSelector::extractPseudoType):
     19        * css/CSSSelector.h:
     20        * css/SelectorChecker.cpp: ditto.
     21        (WebCore::SelectorChecker::checkOneSelector):
     22        * css/StyleResolver.cpp:
     23        (WebCore::StyleResolver::canShareStyleWithElement): define style sharing rules for WebVTT objects.
     24        * css/mediaControls.css:
     25        (video::-webkit-media-text-track-all-nodes):
     26        (video::cue(:future)): added standard user-agent styles for the future nodes.
     27        * dom/Element.cpp: setter functions don't have an argument now because WebVTT type enum was introduced and the right type is set
     28        when the setter is being called.
     29        (WebCore::Element::setIsWebVTTNode):
     30        (WebCore):
     31        (WebCore::Element::isWebVTTFutureNode):
     32        (WebCore::Element::setIsWebVTTFutureNode):
     33        * dom/Element.h:
     34        (Element):
     35        * dom/ElementRareData.h:
     36        (ElementRareData):
     37        * dom/NodeRareData.cpp:
     38        (SameSizeAsNodeRareData): added a dummy enum value. Enum is integer type and is aligned in Windows when placed in the bitfield,
     39        so it takes more space.
     40        * dom/NodeRareData.h:
     41        (WebCore::NodeRareData::NodeRareData):
     42        (WebCore::NodeRareData::isWebVTTNode):
     43        (WebCore::NodeRareData::setIsWebVTTNode):
     44        (WebCore::NodeRareData::isWebVTTFutureNode):
     45        (WebCore::NodeRareData::setIsWebVTTFutureNode):
     46        (NodeRareData):
     47        * html/shadow/MediaControlElements.cpp:
     48        (WebCore):
     49        * html/track/TextTrack.h: add a WebVTT node object type enum.
     50        (TextTrack):
     51        * html/track/TextTrackCue.cpp:
     52        (WebCore::TextTrackCue::allNodesShadowPseudoId):
     53        (WebCore::TextTrackCue::TextTrackCue):
     54        (WebCore::TextTrackCue::getCueAsHTML):
     55        (WebCore):
     56        (WebCore::TextTrackCue::setNodeObjectFlags): determine if the node is future or past and mark as WebVTT node.
     57        This combines the functionality related to marking nodes implemented before in updateDisplayTree and
     58        markNodesAsWebVTTNodes.
     59        (WebCore::TextTrackCue::updateDisplayTree):
     60        (WebCore::TextTrackCue::getDisplayTree):
     61        * html/track/TextTrackCue.h:
     62        (TextTrackCue):
     63        * html/track/WebVTTParser.cpp:
     64        (WebCore::WebVTTParser::constructTreeFromToken): no need to mark nodes as WebVTT nodes when parsing. This is done at the
     65        rendering stage later.
     66        * page/CaptionUserPreferencesMac.mm:
     67        (WebCore::CaptionUserPreferencesMac::captionsStyleSheetOverride): the container name has changed.
     68
    1692013-01-04  Carlos Garcia Campos  <cgarcia@igalia.com>
    270
  • trunk/Source/WebCore/css/CSSSelector.cpp

    r138709 r138784  
    223223#if ENABLE(VIDEO_TRACK)
    224224    case PseudoCue:
     225    case PseudoFutureCue:
    225226#endif
    226227#if ENABLE(IFRAME_SEAMLESS)
     
    311312#if ENABLE(VIDEO_TRACK)
    312313    DEFINE_STATIC_LOCAL(AtomicString, cue, ("cue(", AtomicString::ConstructFromLiteral));
     314    DEFINE_STATIC_LOCAL(AtomicString, futureCue, ("future", AtomicString::ConstructFromLiteral));
    313315#endif
    314316#if ENABLE(IFRAME_SEAMLESS)
     
    392394#if ENABLE(VIDEO_TRACK)
    393395        nameToPseudoType->set(cue.impl(), CSSSelector::PseudoCue);
     396        nameToPseudoType->set(futureCue.impl(), CSSSelector::PseudoFutureCue);
    394397#endif
    395398#if ENABLE(IFRAME_SEAMLESS)
     
    520523    case PseudoInRange:
    521524    case PseudoOutOfRange:
     525#if ENABLE(VIDEO_TRACK)
     526    case PseudoFutureCue:
     527#endif
    522528        break;
    523529    case PseudoFirstPage:
  • trunk/Source/WebCore/css/CSSSelector.h

    r138709 r138784  
    159159#if ENABLE(VIDEO_TRACK)
    160160            PseudoCue,
     161            PseudoFutureCue,
    161162#endif
    162163#if ENABLE(IFRAME_SEAMLESS)
  • trunk/Source/WebCore/css/SelectorChecker.cpp

    r138709 r138784  
    940940            element->document()->setContainsValidityStyleRules();
    941941            return element->isOutOfRange();
     942#if ENABLE(VIDEO_TRACK)
     943        case CSSSelector::PseudoFutureCue:
     944            if (element->isWebVTTFutureNode())
     945                return true;
     946            return false;
     947#endif
    942948        case CSSSelector::PseudoUnknown:
    943949        case CSSSelector::PseudoNotParsed:
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r138639 r138784  
    12411241        return false;
    12421242
     1243#if ENABLE(VIDEO_TRACK)
     1244    if (element->isWebVTTNode() && m_element->isWebVTTNode() && element->isWebVTTFutureNode() != m_element->isWebVTTFutureNode())
     1245        return false;
     1246    // Deny sharing styles between WebVTT nodes and non-WebVTT nodes.
     1247    if (element->isWebVTTNode() != m_element->isWebVTTNode())
     1248        return false;
     1249#endif
     1250
    12431251    return true;
    12441252}
  • trunk/Source/WebCore/css/mediaControls.css

    r138282 r138784  
    239239}
    240240
    241 video::-webkit-media-text-track-past-nodes {
     241video::-webkit-media-text-track-all-nodes {
    242242    display: inline;
    243243
    244244    background-color: rgba(0, 0, 0, 0.8);
    245245    padding: 2px 2px;
    246 }
    247 
    248 video::-webkit-media-text-track-future-nodes {
    249     visibility: hidden;
    250     display: inline;
    251 
    252     background-color: rgba(0, 0, 0, 0.8);
    253 
    254     margin-left: -2px;
    255     padding: 2px 2px 2px 0px;
    256246}
    257247
     
    261251    white-space: pre-wrap;
    262252}
     253
     254video::cue(:future) {
     255    color: gray;
     256}
  • trunk/Source/WebCore/dom/Element.cpp

    r138735 r138784  
    22852285}
    22862286
    2287 void Element::setIsWebVTTNode(bool flag)
    2288 {
    2289     ensureElementRareData()->setIsWebVTTNode(flag);
     2287void Element::setIsWebVTTNode()
     2288{
     2289    ensureElementRareData()->setIsWebVTTNode();
     2290}
     2291
     2292bool Element::isWebVTTFutureNode() const
     2293{
     2294    return hasRareData() && elementRareData()->isWebVTTFutureNode();
     2295}
     2296
     2297void Element::setIsWebVTTFutureNode()
     2298{
     2299    ensureElementRareData()->setIsWebVTTFutureNode();
    22902300}
    22912301#endif
  • trunk/Source/WebCore/dom/Element.h

    r138691 r138784  
    434434#if ENABLE(VIDEO_TRACK)
    435435    bool isWebVTTNode() const;
    436     void setIsWebVTTNode(bool flag);
     436    void setIsWebVTTNode();
     437    bool isWebVTTFutureNode() const;
     438    void setIsWebVTTFutureNode();
    437439#endif
    438440   
  • trunk/Source/WebCore/dom/ElementRareData.h

    r138735 r138784  
    5858    using NodeRareData::isWebVTTNode;
    5959    using NodeRareData::setIsWebVTTNode;
     60    using NodeRareData::isWebVTTFutureNode;
     61    using NodeRareData::setIsWebVTTFutureNode;
    6062#endif
    6163#if ENABLE(FULLSCREEN_API)
  • trunk/Source/WebCore/dom/NodeRareData.cpp

    r138735 r138784  
    5050    void* m_microData;
    5151#endif
     52
     53// Enum is integer type and is aligned in Windows when placed in the bitfield, so it takes more space.
     54#if PLATFORM(WIN)
     55    TextTrack::WebVTTNodeType m_WebVTTNodeType;
     56#endif
    5257};
    5358COMPILE_ASSERT(sizeof(NodeRareData) == sizeof(SameSizeAsNodeRareData), NodeRareDataShouldStaySmall);
  • trunk/Source/WebCore/dom/NodeRareData.h

    r138735 r138784  
    3030#include "QualifiedName.h"
    3131#include "TagNodeList.h"
     32#if ENABLE(VIDEO_TRACK)
     33#include "TextTrack.h"
     34#endif
    3235#include <wtf/HashSet.h>
    3336#include <wtf/OwnPtr.h>
     
    254257        , m_styleAffectedByEmpty(false)
    255258        , m_isInCanvasSubtree(false)
    256 #if ENABLE(VIDEO_TRACK)
    257         , m_isWebVTTNode(false)
    258 #endif
    259259#if ENABLE(FULLSCREEN_API)
    260260        , m_containsFullScreenElement(false)
     
    271271        , m_childrenAffectedByForwardPositionalRules(false)
    272272        , m_childrenAffectedByBackwardPositionalRules(false)
     273#if ENABLE(VIDEO_TRACK)
     274        , m_WebVTTNodeType(TextTrack::WebVTTNodeTypeNone)
     275#endif
    273276    {
    274277    }
     
    371374protected:
    372375#if ENABLE(VIDEO_TRACK)
    373     bool isWebVTTNode() { return m_isWebVTTNode; }
    374     void setIsWebVTTNode(bool value) { m_isWebVTTNode = value; }
     376    bool isWebVTTNode() { return m_WebVTTNodeType != TextTrack::WebVTTNodeTypeNone; }
     377    void setIsWebVTTNode() { m_WebVTTNodeType = TextTrack::WebVTTNodeTypePast; }
     378    bool isWebVTTFutureNode() { return m_WebVTTNodeType == TextTrack::WebVTTNodeTypeFuture; }
     379    void setIsWebVTTFutureNode() { m_WebVTTNodeType = TextTrack::WebVTTNodeTypeFuture; }
    375380#endif
    376381    short m_tabIndex;
     
    380385    bool m_styleAffectedByEmpty : 1;
    381386    bool m_isInCanvasSubtree : 1;
    382 #if ENABLE(VIDEO_TRACK)
    383     bool m_isWebVTTNode : 1;
    384 #endif
    385387#if ENABLE(FULLSCREEN_API)
    386388    bool m_containsFullScreenElement : 1;
     
    400402    bool m_childrenAffectedByForwardPositionalRules : 1;
    401403    bool m_childrenAffectedByBackwardPositionalRules : 1;
    402 
     404#if ENABLE(VIDEO_TRACK)
     405    TextTrack::WebVTTNodeType m_WebVTTNodeType : 2;
     406#endif
    403407private:
    404408    OwnPtr<NodeListsNodeData> m_nodeLists;
  • trunk/Source/WebCore/html/shadow/MediaControlElements.cpp

    r138071 r138784  
    12191219{
    12201220}
    1221    
     1221
    12221222void MediaControlTextTrackContainerElement::createSubtrees(Document* document)
    12231223{
  • trunk/Source/WebCore/html/track/TextTrack.h

    r138766 r138784  
    111111    enum TextTrackType { TrackElement, AddTrack, InBand };
    112112    TextTrackType trackType() const { return m_trackType; }
     113   
     114    enum WebVTTNodeType {WebVTTNodeTypeNone, WebVTTNodeTypeFuture, WebVTTNodeTypePast};
    113115
    114116    int trackIndex();
  • trunk/Source/WebCore/html/track/TextTrackCue.cpp

    r138674 r138784  
    184184// ----------------------------
    185185
    186 const AtomicString& TextTrackCue::pastNodesShadowPseudoId()
    187 {
    188     DEFINE_STATIC_LOCAL(const AtomicString, subtitles, ("-webkit-media-text-track-past-nodes", AtomicString::ConstructFromLiteral));
    189     return subtitles;
    190 }
    191 
    192 const AtomicString& TextTrackCue::futureNodesShadowPseudoId()
    193 {
    194     DEFINE_STATIC_LOCAL(const AtomicString, subtitles, ("-webkit-media-text-track-future-nodes", AtomicString::ConstructFromLiteral));
     186const AtomicString& TextTrackCue::allNodesShadowPseudoId()
     187{
     188    DEFINE_STATIC_LOCAL(const AtomicString, subtitles, ("-webkit-media-text-track-all-nodes", AtomicString::ConstructFromLiteral));
    195189    return subtitles;
    196190}
     
    214208    , m_snapToLines(true)
    215209    , m_hasInnerTimestamps(false)
    216     , m_pastDocumentNodes(HTMLDivElement::create(static_cast<Document*>(context)))
    217     , m_futureDocumentNodes(HTMLDivElement::create(static_cast<Document*>(context)))
     210    , m_allDocumentNodes(HTMLDivElement::create(static_cast<Document*>(context)))
    218211    , m_displayTreeShouldChange(true)
    219212    , m_displayTree(TextTrackCueBox::create(static_cast<Document*>(m_scriptExecutionContext), this))
     
    489482}
    490483
    491 void TextTrackCue::markNodesAsWebVTTNodes(Node* root)
    492 {
    493     for (Element* child = ElementTraversal::firstWithin(root); child; child = ElementTraversal::next(child, root))
    494         child->setIsWebVTTNode(true);
    495 }
    496 
    497484PassRefPtr<DocumentFragment> TextTrackCue::getCueAsHTML()
    498485{
     
    517504    clonedFragment = DocumentFragment::create(document);
    518505    m_documentFragment->cloneChildNodes(clonedFragment.get());
    519     markNodesAsWebVTTNodes(clonedFragment.get());
    520506
    521507    return clonedFragment.release();
     
    672658    m_computedLinePosition = calculateComputedLinePosition();
    673659}
     660   
     661void TextTrackCue::markFutureAndPastNodes(Element* root, double previousTimestamp, double movieTime)
     662{
     663    DEFINE_STATIC_LOCAL(const String, timestampTag, (ASCIILiteral("timestamp")));
     664   
     665    bool isPastNode = true;
     666    double currentTimestamp = previousTimestamp;
     667    if (currentTimestamp > movieTime)
     668        isPastNode = false;
     669   
     670    for (Node* child = root->firstChild(); child; child = NodeTraversal::next(child, root)) {
     671        if (child->nodeName() == timestampTag) {
     672            unsigned position = 0;
     673            String timestamp = child->nodeValue();
     674            double currentTimestamp = WebVTTParser::create(0, m_scriptExecutionContext)->collectTimeStamp(timestamp, &position);
     675            ASSERT(currentTimestamp != -1);
     676           
     677            if (currentTimestamp > movieTime)
     678                isPastNode = false;
     679        }
     680       
     681        if (child->isElementNode()) {
     682            if (!isPastNode)
     683                toElement(child)->setIsWebVTTFutureNode();
     684            else
     685                toElement(child)->setIsWebVTTNode();
     686        }
     687    }
     688}
    674689
    675690void TextTrackCue::updateDisplayTree(float movieTime)
     
    677692    // The display tree may contain WebVTT timestamp objects representing
    678693    // timestamps (processing instructions), along with displayable nodes.
    679     DEFINE_STATIC_LOCAL(const String, timestampTag, (ASCIILiteral("timestamp")));
    680694
    681695    if (!track()->isRendered())
    682696      return;
    683697
    684     bool isPastNode = true;
    685 
    686     // Clear the contents of the two sets.
    687     m_futureDocumentNodes->removeChildren();
    688     m_futureDocumentNodes->setPseudo(futureNodesShadowPseudoId());
    689 
    690     m_pastDocumentNodes->removeChildren();
    691     m_pastDocumentNodes->setPseudo(pastNodesShadowPseudoId());
     698
     699    // Clear the contents of the set.
     700    m_allDocumentNodes->removeChildren();
     701    m_allDocumentNodes->setPseudo(allNodesShadowPseudoId());
    692702
    693703    // Update the two sets containing past and future WebVTT objects.
    694704    RefPtr<DocumentFragment> referenceTree = getCueAsHTML();
    695705
    696     if (!m_hasInnerTimestamps) {
    697         m_pastDocumentNodes->appendChild(referenceTree);
    698         return;
    699     }
    700 
    701     for (Node *child = referenceTree->firstChild(); child; child = child->nextSibling()) {
    702         if (child->nodeName() == timestampTag) {
    703             unsigned int position = 0;
    704             String timestamp = child->nodeValue();
    705 
    706             double timestampTime = WebVTTParser::create(0, m_scriptExecutionContext)->collectTimeStamp(timestamp, &position);
    707             ASSERT(timestampTime != -1);
    708 
    709             if (timestampTime > movieTime)
    710                 isPastNode = false;
    711         }
    712 
    713         if (isPastNode)
    714             m_pastDocumentNodes->appendChild(child->cloneNode(true), ASSERT_NO_EXCEPTION, false);
    715         else
    716             m_futureDocumentNodes->appendChild(child->cloneNode(true), ASSERT_NO_EXCEPTION, false);
    717     }
     706    m_allDocumentNodes->appendChild(referenceTree);
     707    markFutureAndPastNodes(m_allDocumentNodes.get(), startTime(), movieTime);
    718708}
    719709
     
    737727    // background box.
    738728
    739     // Note: This is contained by default in m_pastDocumentNodes.
    740     m_displayTree->appendChild(m_pastDocumentNodes, ASSERT_NO_EXCEPTION, true);
    741     m_displayTree->appendChild(m_futureDocumentNodes, ASSERT_NO_EXCEPTION, true);
     729    // Note: This is contained by default in m_allDocumentNodes.
     730    m_displayTree->appendChild(m_allDocumentNodes, ASSERT_NO_EXCEPTION, true);
    742731
    743732    // FIXME(BUG 79916): Runs of children of WebVTT Ruby Objects that are not
  • trunk/Source/WebCore/html/track/TextTrackCue.h

    r138674 r138784  
    8181    virtual ~TextTrackCue();
    8282
    83     static const AtomicString& pastNodesShadowPseudoId();
    84     static const AtomicString& futureNodesShadowPseudoId();
     83    static const AtomicString& allNodesShadowPseudoId();
    8584
    8685    TextTrack* track() const;
     
    127126
    128127    PassRefPtr<DocumentFragment> getCueAsHTML();
    129     void markNodesAsWebVTTNodes(Node*);
    130128
    131129    using EventTarget::dispatchEvent;
     
    138136    void updateDisplayTree(float);
    139137    void removeDisplayTree();
     138    void markFutureAndPastNodes(Element*, double, double);
    140139
    141140    int calculateComputedLinePosition();
     
    210209
    211210    bool m_hasInnerTimestamps;
    212     RefPtr<HTMLDivElement> m_pastDocumentNodes;
    213     RefPtr<HTMLDivElement> m_futureDocumentNodes;
     211    RefPtr<HTMLDivElement> m_allDocumentNodes;
    214212
    215213    bool m_displayTreeShouldChange;
  • trunk/Source/WebCore/html/track/WebVTTParser.cpp

    r137955 r138784  
    365365
    366366        if (child) {
    367             child->setIsWebVTTNode(true);
    368367            if (m_token.classes().size() > 0)
    369368                child->setAttribute(classAttr, AtomicString(m_token.classes().data(), m_token.classes().size()));
  • trunk/Source/WebCore/page/CaptionUserPreferencesMac.mm

    r132356 r138784  
    254254    if (color.isValid()) {
    255255        captionsOverrideStyleSheet.append(" video::");
    256         captionsOverrideStyleSheet.append(TextTrackCue::pastNodesShadowPseudoId());
    257         captionsOverrideStyleSheet.append('{');
    258         captionsOverrideStyleSheet.append(cssColorProperty(CSSPropertyBackgroundColor, color));
    259         captionsOverrideStyleSheet.append('}');
    260        
    261         captionsOverrideStyleSheet.append(" video::");
    262         captionsOverrideStyleSheet.append(TextTrackCue::futureNodesShadowPseudoId());
     256        captionsOverrideStyleSheet.append(TextTrackCue::allNodesShadowPseudoId());
    263257        captionsOverrideStyleSheet.append('{');
    264258        captionsOverrideStyleSheet.append(cssColorProperty(CSSPropertyBackgroundColor, color));
Note: See TracChangeset for help on using the changeset viewer.