Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: Source/core/html/track/vtt/VTTCue.cpp

Issue 1013393004: Eliminate TextTrackCue::updateDisplayTree() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 737 }
738 738
739 // Step 9 not implemented (margin == 0). 739 // Step 9 not implemented (margin == 0).
740 740
741 ASSERT(std::isfinite(displayParameters.size)); 741 ASSERT(std::isfinite(displayParameters.size));
742 ASSERT(displayParameters.direction != CSSValueNone); 742 ASSERT(displayParameters.direction != CSSValueNone);
743 ASSERT(displayParameters.writingMode != CSSValueNone); 743 ASSERT(displayParameters.writingMode != CSSValueNone);
744 return displayParameters; 744 return displayParameters;
745 } 745 }
746 746
747 void VTTCue::markFutureAndPastNodes(ContainerNode* root, double previousTimestam p, double movieTime) 747 void VTTCue::updatePastAndFutureNodes(double movieTime)
748 { 748 {
749 DEFINE_STATIC_LOCAL(const String, timestampTag, ("timestamp")); 749 DEFINE_STATIC_LOCAL(const String, timestampTag, ("timestamp"));
750 750
751 ASSERT(isActive());
752
753 // An active cue may still not have a display tree, e.g. if its track is
754 // hidden or if the track belongs to an audio element.
755 if (!m_displayTree)
756 return;
757
758 // FIXME: Per spec it's possible for neither :past nor :future to match, but
759 // as implemented here and in SelectorChecker they are simply each others
760 // negations. For a cue with no internal timestamps, :past will match but
761 // should not per spec. :future is correct, however. See the spec bug to
762 // determine what the correct behavior should be:
763 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28237
764
751 bool isPastNode = true; 765 bool isPastNode = true;
752 double currentTimestamp = previousTimestamp; 766 double currentTimestamp = startTime();
753 if (currentTimestamp > movieTime) 767 if (currentTimestamp > movieTime)
fs 2015/03/19 12:10:02 Since you touched upon this above and in the descr
philipj_slow 2015/03/19 12:36:36 Good catch, this branch looks unreachable, and an
754 isPastNode = false; 768 isPastNode = false;
755 769
756 for (Node& child : NodeTraversal::descendantsOf(*root)) { 770 for (Node& child : NodeTraversal::descendantsOf(*m_displayTree)) {
757 if (child.nodeName() == timestampTag) { 771 if (child.nodeName() == timestampTag) {
758 double currentTimestamp; 772 double currentTimestamp;
759 bool check = VTTParser::collectTimeStamp(child.nodeValue(), currentT imestamp); 773 bool check = VTTParser::collectTimeStamp(child.nodeValue(), currentT imestamp);
760 ASSERT_UNUSED(check, check); 774 ASSERT_UNUSED(check, check);
761 775
762 if (currentTimestamp > movieTime) 776 if (currentTimestamp > movieTime)
763 isPastNode = false; 777 isPastNode = false;
764 } 778 }
765 779
766 if (child.isVTTElement()) { 780 if (child.isVTTElement()) {
767 toVTTElement(child).setIsPastNode(isPastNode); 781 toVTTElement(child).setIsPastNode(isPastNode);
768 // Make an elemenet id match a cue id for style matching purposes. 782 // Make an elemenet id match a cue id for style matching purposes.
769 if (!id().isEmpty()) 783 if (!id().isEmpty())
770 toElement(child).setIdAttribute(id()); 784 toElement(child).setIdAttribute(id());
771 } 785 }
772 } 786 }
773 } 787 }
774 788
775 void VTTCue::updateDisplayTree(double movieTime)
776 {
777 // The display tree may contain WebVTT timestamp objects representing
778 // timestamps (processing instructions), along with displayable nodes.
779
780 if (!track()->isRendered())
781 return;
782
783 // Clear the contents of the set.
784 m_cueBackgroundBox->removeChildren();
785
786 // Update the two sets containing past and future WebVTT objects.
787 createVTTNodeTree();
788 RefPtrWillBeRawPtr<DocumentFragment> referenceTree = DocumentFragment::creat e(document());
789 m_vttNodeTree->cloneChildNodes(referenceTree.get());
790 markFutureAndPastNodes(referenceTree.get(), startTime(), movieTime);
791 m_cueBackgroundBox->appendChild(referenceTree, ASSERT_NO_EXCEPTION);
792 }
793
794 PassRefPtrWillBeRawPtr<VTTCueBox> VTTCue::getDisplayTree() 789 PassRefPtrWillBeRawPtr<VTTCueBox> VTTCue::getDisplayTree()
795 { 790 {
796 ASSERT(track() && track()->isRendered() && isActive()); 791 ASSERT(track() && track()->isRendered() && isActive());
797 792
798 if (!m_displayTree) { 793 if (!m_displayTree) {
799 m_displayTree = VTTCueBox::create(document(), this); 794 m_displayTree = VTTCueBox::create(document(), this);
800 m_displayTree->appendChild(m_cueBackgroundBox); 795 m_displayTree->appendChild(m_cueBackgroundBox);
801 } 796 }
802 797
803 ASSERT(m_displayTree->firstChild() == m_cueBackgroundBox); 798 ASSERT(m_displayTree->firstChild() == m_cueBackgroundBox);
804 799
805 // Note: It is updateDisplayTree() which actually adds the child
806 // nodes to m_cueBackgroundBox.
807
808 if (!m_displayTreeShouldChange) 800 if (!m_displayTreeShouldChange)
809 return m_displayTree; 801 return m_displayTree;
810 802
811 createVTTNodeTree(); 803 createVTTNodeTree();
804
805 m_cueBackgroundBox->removeChildren();
806 m_vttNodeTree->cloneChildNodes(m_cueBackgroundBox.get());
807
812 VTTDisplayParameters displayParameters = calculateDisplayParameters(); 808 VTTDisplayParameters displayParameters = calculateDisplayParameters();
813 m_displayTree->applyCSSProperties(displayParameters); 809 m_displayTree->applyCSSProperties(displayParameters);
814 810
815 m_displayTreeShouldChange = false; 811 m_displayTreeShouldChange = false;
816 812
817 return m_displayTree; 813 return m_displayTree;
818 } 814 }
819 815
820 void VTTCue::removeDisplayTree(RemovalNotification removalNotification) 816 void VTTCue::removeDisplayTree(RemovalNotification removalNotification)
821 { 817 {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 1094
1099 DEFINE_TRACE(VTTCue) 1095 DEFINE_TRACE(VTTCue)
1100 { 1096 {
1101 visitor->trace(m_vttNodeTree); 1097 visitor->trace(m_vttNodeTree);
1102 visitor->trace(m_cueBackgroundBox); 1098 visitor->trace(m_cueBackgroundBox);
1103 visitor->trace(m_displayTree); 1099 visitor->trace(m_displayTree);
1104 TextTrackCue::trace(visitor); 1100 TextTrackCue::trace(visitor);
1105 } 1101 }
1106 1102
1107 } // namespace blink 1103 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698