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

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

Issue 851333003: WebVTT: Update cue alignment to a later spec. version (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added test. Created 5 years, 11 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 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 return 100; 650 return 100;
651 // 4. If the text track cue text alignment is middle, return 50 and abort th ese steps. 651 // 4. If the text track cue text alignment is middle, return 50 and abort th ese steps.
652 case Middle: 652 case Middle:
653 return 50; 653 return 50;
654 default: 654 default:
655 ASSERT_NOT_REACHED(); 655 ASSERT_NOT_REACHED();
656 return 0; 656 return 0;
657 } 657 }
658 } 658 }
659 659
660 static inline VTTCue::CueAlignment resolveCueAlignment(VTTCue::CueAlignment spec ifiedCueAlignment, CSSValueID direction) 660 VTTCue::CueAlignment VTTCue::calculateComputedCueAlignment() const
661 { 661 {
662 ASSERT(direction == CSSValueLtr || direction == CSSValueRtl); 662 switch (m_cueAlignment) {
663 switch (specifiedCueAlignment) { 663 case VTTCue::Left:
664 case VTTCue::Start: 664 return VTTCue::Start;
665 return direction == CSSValueLtr ? VTTCue::Left : VTTCue::Right; 665 case VTTCue::Right:
666 case VTTCue::End: 666 return VTTCue::End;
667 return direction == CSSValueLtr ? VTTCue::Right : VTTCue::Left;
668 default: 667 default:
669 return specifiedCueAlignment; 668 return m_cueAlignment;
670 } 669 }
671 } 670 }
672 671
673 void VTTCue::calculateDisplayParameters() 672 void VTTCue::calculateDisplayParameters()
674 { 673 {
675 createVTTNodeTree(); 674 createVTTNodeTree();
676 675
677 // Steps 10.2, 10.3 676 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings
677
678 // Steps 1 and 2.
678 m_displayDirection = determineTextDirection(m_vttNodeTree.get()); 679 m_displayDirection = determineTextDirection(m_vttNodeTree.get());
679 680
680 if (m_displayDirection == CSSValueRtl) 681 if (m_displayDirection == CSSValueRtl)
681 UseCounter::count(document(), UseCounter::VTTCueRenderRtl); 682 UseCounter::count(document(), UseCounter::VTTCueRenderRtl);
682 683
683 // 10.4 If the text track cue writing direction is horizontal, then let 684 // 3. If the text track cue writing direction is horizontal, then let
684 // block-flow be 'tb'. Otherwise, if the text track cue writing direction is 685 // block-flow be 'tb'. Otherwise, if the text track cue writing direction is
685 // vertical growing left, then let block-flow be 'lr'. Otherwise, the text 686 // vertical growing left, then let block-flow be 'lr'. Otherwise, the text
686 // track cue writing direction is vertical growing right; let block-flow be 687 // track cue writing direction is vertical growing right; let block-flow be
687 // 'rl'. 688 // 'rl'.
688 689
689 // The above step is done through the writing direction static map. 690 // The above step is done through the writing direction static map.
690 691
691 // 10.5 Determine the value of maximum size for cue as per the appropriate 692 // Resolve the cue alignment to one of the values {start, end, middle}.
693 CueAlignment computedCueAlignment = calculateComputedCueAlignment();
694
695 // 4. Determine the value of maximum size for cue as per the appropriate
692 // rules from the following list: 696 // rules from the following list:
693 float computedTextPosition = calculateComputedTextPosition(); 697 float computedTextPosition = calculateComputedTextPosition();
694 float maximumSize = computedTextPosition; 698 float maximumSize = computedTextPosition;
695 if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displa yDirection == CSSValueLtr) 699 if (computedCueAlignment == Start) {
696 || (m_writingDirection == Horizontal && m_cueAlignment == End && m_displ ayDirection == CSSValueRtl)
697 || (m_writingDirection == Horizontal && m_cueAlignment == Left)
698 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == Star t || m_cueAlignment == Left))
699 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == Sta rt || m_cueAlignment == Left))) {
700 maximumSize = 100 - computedTextPosition; 700 maximumSize = 100 - computedTextPosition;
701 } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_d isplayDirection == CSSValueLtr) 701 } else if (computedCueAlignment == End) {
702 || (m_writingDirection == Horizontal && m_cueAlignment == Start && m_dis playDirection == CSSValueRtl)
703 || (m_writingDirection == Horizontal && m_cueAlignment == Right)
704 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == End || m_cueAlignment == Right))
705 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == End || m_cueAlignment == Right))) {
706 maximumSize = computedTextPosition; 702 maximumSize = computedTextPosition;
707 } else if (m_cueAlignment == Middle) { 703 } else if (computedCueAlignment == Middle) {
708 maximumSize = computedTextPosition <= 50 ? computedTextPosition : (100 - computedTextPosition); 704 maximumSize = computedTextPosition <= 50 ? computedTextPosition : (100 - computedTextPosition);
709 maximumSize = maximumSize * 2; 705 maximumSize = maximumSize * 2;
710 } else { 706 } else {
711 ASSERT_NOT_REACHED(); 707 ASSERT_NOT_REACHED();
712 } 708 }
713 709
714 // 10.6 If the text track cue size is less than maximum size, then let size 710 // 5. If the text track cue size is less than maximum size, then let size
715 // be text track cue size. Otherwise, let size be maximum size. 711 // be text track cue size. Otherwise, let size be maximum size.
716 m_displaySize = std::min(m_cueSize, maximumSize); 712 m_displaySize = std::min(m_cueSize, maximumSize);
717 713
718 // FIXME: Understand why step 10.7 is missing (just a copy/paste error?) 714 // 6. If the text track cue writing direction is horizontal, then let width
719 // Could be done within a spec implementation check - http://crbug.com/30158 0 715 // be 'size vw' and height be 'auto'. Otherwise, let width be 'auto' and
716 // height be 'size vh'. (These are CSS values used by the next section to
717 // set CSS properties for the rendering; 'vw' and 'vh' are CSS units.)
718 // (Emulated in VTTCueBox::applyCSSProperties.)
720 719
721 // 10.8 Determine the value of x-position or y-position for cue as per the 720 // 7. Determine the value of x-position or y-position for cue as per the
722 // appropriate rules from the following list: 721 // appropriate rules from the following list:
723 if (m_writingDirection == Horizontal) { 722 if (m_writingDirection == Horizontal) {
724 float visualTextPosition = m_displayDirection == CSSValueLtr ? computedT extPosition : 100 - computedTextPosition; 723 switch (computedCueAlignment) {
725 724 case Start:
726 switch (resolveCueAlignment(m_cueAlignment, m_displayDirection)) { 725 m_displayPosition.setX(computedTextPosition);
727 case Left:
728 m_displayPosition.setX(visualTextPosition);
729 break; 726 break;
730 case Right: 727 case End:
731 m_displayPosition.setX(visualTextPosition - m_displaySize); 728 m_displayPosition.setX(computedTextPosition - m_displaySize);
732 break; 729 break;
733 case Middle: 730 case Middle:
734 m_displayPosition.setX(visualTextPosition - m_displaySize / 2); 731 m_displayPosition.setX(computedTextPosition - m_displaySize / 2);
735 break; 732 break;
736 default: 733 default:
737 ASSERT_NOT_REACHED(); 734 ASSERT_NOT_REACHED();
738 } 735 }
739 } else { 736 } else {
740 // Cases for m_writingDirection being VerticalGrowing{Left|Right} 737 // Cases for m_writingDirection being VerticalGrowing{Left|Right}
741 switch (m_cueAlignment) { 738 switch (computedCueAlignment) {
742 case Start: 739 case Start:
743 case Left:
744 m_displayPosition.setY(computedTextPosition); 740 m_displayPosition.setY(computedTextPosition);
745 break; 741 break;
746 case End: 742 case End:
747 case Right:
748 m_displayPosition.setY(computedTextPosition - m_displaySize); 743 m_displayPosition.setY(computedTextPosition - m_displaySize);
749 break; 744 break;
750 case Middle: 745 case Middle:
751 m_displayPosition.setY(computedTextPosition - m_displaySize / 2); 746 m_displayPosition.setY(computedTextPosition - m_displaySize / 2);
752 break; 747 break;
753 default: 748 default:
754 ASSERT_NOT_REACHED(); 749 ASSERT_NOT_REACHED();
755 } 750 }
756 } 751 }
757 752
758 // A text track cue has a text track cue computed line position whose value 753 // A text track cue has a text track cue computed line position whose value
759 // is defined in terms of the other aspects of the cue. 754 // is defined in terms of the other aspects of the cue.
760 m_computedLinePosition = calculateComputedLinePosition(); 755 m_computedLinePosition = calculateComputedLinePosition();
761 756
762 // 10.9 Determine the value of whichever of x-position or y-position is not 757 // 8. Determine the value of whichever of x-position or y-position is not
763 // yet calculated for cue as per the appropriate rules from the following 758 // yet calculated for cue as per the appropriate rules from the following
764 // list: 759 // list:
765 if (m_snapToLines && m_writingDirection == Horizontal) 760 if (!m_snapToLines) {
766 m_displayPosition.setY(0); 761 if (m_writingDirection == Horizontal)
767 762 m_displayPosition.setY(m_computedLinePosition);
768 if (!m_snapToLines && m_writingDirection == Horizontal) 763 else
769 m_displayPosition.setY(m_computedLinePosition); 764 m_displayPosition.setX(m_computedLinePosition);
770 765 } else {
771 if (m_snapToLines && (m_writingDirection == VerticalGrowingLeft || m_writing Direction == VerticalGrowingRight)) 766 if (m_writingDirection == Horizontal)
772 m_displayPosition.setX(0); 767 m_displayPosition.setY(0);
773 768 else
774 if (!m_snapToLines && (m_writingDirection == VerticalGrowingLeft || m_writin gDirection == VerticalGrowingRight)) 769 m_displayPosition.setX(0);
775 m_displayPosition.setX(m_computedLinePosition); 770 }
776 } 771 }
777 772
778 void VTTCue::markFutureAndPastNodes(ContainerNode* root, double previousTimestam p, double movieTime) 773 void VTTCue::markFutureAndPastNodes(ContainerNode* root, double previousTimestam p, double movieTime)
779 { 774 {
780 DEFINE_STATIC_LOCAL(const String, timestampTag, ("timestamp")); 775 DEFINE_STATIC_LOCAL(const String, timestampTag, ("timestamp"));
781 776
782 bool isPastNode = true; 777 bool isPastNode = true;
783 double currentTimestamp = previousTimestamp; 778 double currentTimestamp = previousTimestamp;
784 if (currentTimestamp > movieTime) 779 if (currentTimestamp > movieTime)
785 isPastNode = false; 780 isPastNode = false;
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 1181
1187 void VTTCue::trace(Visitor* visitor) 1182 void VTTCue::trace(Visitor* visitor)
1188 { 1183 {
1189 visitor->trace(m_vttNodeTree); 1184 visitor->trace(m_vttNodeTree);
1190 visitor->trace(m_cueBackgroundBox); 1185 visitor->trace(m_cueBackgroundBox);
1191 visitor->trace(m_displayTree); 1186 visitor->trace(m_displayTree);
1192 TextTrackCue::trace(visitor); 1187 TextTrackCue::trace(visitor);
1193 } 1188 }
1194 1189
1195 } // namespace blink 1190 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698