OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 DEFINE_STATIC_LOCAL(const String, middle, ("middle")); | 66 DEFINE_STATIC_LOCAL(const String, middle, ("middle")); |
67 return middle; | 67 return middle; |
68 } | 68 } |
69 | 69 |
70 static const String& endKeyword() | 70 static const String& endKeyword() |
71 { | 71 { |
72 DEFINE_STATIC_LOCAL(const String, end, ("end")); | 72 DEFINE_STATIC_LOCAL(const String, end, ("end")); |
73 return end; | 73 return end; |
74 } | 74 } |
75 | 75 |
76 static const String& leftKeyword() | |
77 { | |
78 DEFINE_STATIC_LOCAL(const String, left, ("left")); | |
79 return left; | |
80 } | |
81 | |
82 static const String& rightKeyword() | |
83 { | |
84 DEFINE_STATIC_LOCAL(const String, right, ("right")); | |
85 return right; | |
86 } | |
87 | |
76 static const String& horizontalKeyword() | 88 static const String& horizontalKeyword() |
77 { | 89 { |
78 return emptyString(); | 90 return emptyString(); |
79 } | 91 } |
80 | 92 |
81 static const String& verticalGrowingLeftKeyword() | 93 static const String& verticalGrowingLeftKeyword() |
82 { | 94 { |
83 DEFINE_STATIC_LOCAL(const String, verticalrl, ("rl")); | 95 DEFINE_STATIC_LOCAL(const String, verticalrl, ("rl")); |
84 return verticalrl; | 96 return verticalrl; |
85 } | 97 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 158 } |
147 | 159 |
148 // The 'text-align' property on the (root) List of WebVTT Node Objects must | 160 // The 'text-align' property on the (root) List of WebVTT Node Objects must |
149 // be set to the value in the second cell of the row of the table below | 161 // be set to the value in the second cell of the row of the table below |
150 // whose first cell is the value of the corresponding cue's text track cue | 162 // whose first cell is the value of the corresponding cue's text track cue |
151 // alignment: | 163 // alignment: |
152 if (m_cue->align() == startKeyword()) | 164 if (m_cue->align() == startKeyword()) |
153 setInlineStyleProperty(CSSPropertyTextAlign, CSSValueStart); | 165 setInlineStyleProperty(CSSPropertyTextAlign, CSSValueStart); |
154 else if (m_cue->align() == endKeyword()) | 166 else if (m_cue->align() == endKeyword()) |
155 setInlineStyleProperty(CSSPropertyTextAlign, CSSValueEnd); | 167 setInlineStyleProperty(CSSPropertyTextAlign, CSSValueEnd); |
156 else | 168 else if (m_cue->align() == middleKeyword()) |
philipj_slow
2013/10/03 09:04:43
The implementation of TextTrackCue::align() alread
vcarbune.chromium
2013/10/04 13:30:26
I added the map and a getCSSAlignment method on Te
| |
157 setInlineStyleProperty(CSSPropertyTextAlign, CSSValueCenter); | 169 setInlineStyleProperty(CSSPropertyTextAlign, CSSValueCenter); |
170 else if (m_cue->align() == leftKeyword()) | |
171 setInlineStyleProperty(CSSPropertyTextAlign, CSSValueLeft); | |
172 else if (m_cue->align() == rightKeyword()) | |
173 setInlineStyleProperty(CSSPropertyTextAlign, CSSValueRight); | |
158 | 174 |
159 if (!m_cue->snapToLines()) { | 175 if (!m_cue->snapToLines()) { |
160 // 10.13.1 Set up x and y: | 176 // 10.13.1 Set up x and y: |
161 // Note: x and y are set through the CSS left and top above. | 177 // Note: x and y are set through the CSS left and top above. |
162 | 178 |
163 // 10.13.2 Position the boxes in boxes such that the point x% along the | 179 // 10.13.2 Position the boxes in boxes such that the point x% along the |
164 // width of the bounding box of the boxes in boxes is x% of the way | 180 // width of the bounding box of the boxes in boxes is x% of the way |
165 // across the width of the video's rendering area, and the point y% | 181 // across the width of the video's rendering area, and the point y% |
166 // along the height of the bounding box of the boxes in boxes is y% | 182 // along the height of the bounding box of the boxes in boxes is y% |
167 // of the way across the height of the video's rendering area, while | 183 // of the way across the height of the video's rendering area, while |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 | 444 |
429 const String& TextTrackCue::align() const | 445 const String& TextTrackCue::align() const |
430 { | 446 { |
431 switch (m_cueAlignment) { | 447 switch (m_cueAlignment) { |
432 case Start: | 448 case Start: |
433 return startKeyword(); | 449 return startKeyword(); |
434 case Middle: | 450 case Middle: |
435 return middleKeyword(); | 451 return middleKeyword(); |
436 case End: | 452 case End: |
437 return endKeyword(); | 453 return endKeyword(); |
454 case Left: | |
455 return leftKeyword(); | |
456 case Right: | |
457 return rightKeyword(); | |
438 default: | 458 default: |
439 ASSERT_NOT_REACHED(); | 459 ASSERT_NOT_REACHED(); |
440 return emptyString(); | 460 return emptyString(); |
441 } | 461 } |
442 } | 462 } |
443 | 463 |
444 void TextTrackCue::setAlign(const String& value, ExceptionState& es) | 464 void TextTrackCue::setAlign(const String& value, ExceptionState& es) |
445 { | 465 { |
446 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele ment.html#dom-texttrackcue-align | 466 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele ment.html#dom-texttrackcue-align |
447 // On setting, the text track cue alignment must be set to the value given i n the | 467 // On setting, the text track cue alignment must be set to the value given i n the |
448 // first cell of the row in the table above whose second cell is a case-sens itive | 468 // first cell of the row in the table above whose second cell is a case-sens itive |
449 // match for the new value, if any. If none of the values match, then the us er | 469 // match for the new value, if any. If none of the values match, then the us er |
450 // agent must instead throw a SyntaxError exception. | 470 // agent must instead throw a SyntaxError exception. |
451 | 471 |
452 CueAlignment alignment = m_cueAlignment; | 472 CueAlignment alignment = m_cueAlignment; |
453 if (value == startKeyword()) | 473 if (value == startKeyword()) |
454 alignment = Start; | 474 alignment = Start; |
455 else if (value == middleKeyword()) | 475 else if (value == middleKeyword()) |
456 alignment = Middle; | 476 alignment = Middle; |
457 else if (value == endKeyword()) | 477 else if (value == endKeyword()) |
458 alignment = End; | 478 alignment = End; |
479 else if (value == leftKeyword()) | |
480 alignment = Left; | |
481 else if (value == rightKeyword()) | |
482 alignment = Right; | |
459 else | 483 else |
460 es.throwUninformativeAndGenericDOMException(SyntaxError); | 484 es.throwUninformativeAndGenericDOMException(SyntaxError); |
461 | 485 |
462 if (alignment == m_cueAlignment) | 486 if (alignment == m_cueAlignment) |
463 return; | 487 return; |
464 | 488 |
465 cueWillChange(); | 489 cueWillChange(); |
466 m_cueAlignment = alignment; | 490 m_cueAlignment = alignment; |
467 cueDidChange(); | 491 cueDidChange(); |
468 } | 492 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 || charDirection == WTF::Unicode::RightToLeftArabic) { | 667 || charDirection == WTF::Unicode::RightToLeftArabic) { |
644 m_displayDirection = CSSValueRtl; | 668 m_displayDirection = CSSValueRtl; |
645 return; | 669 return; |
646 } | 670 } |
647 } | 671 } |
648 } | 672 } |
649 } | 673 } |
650 | 674 |
651 void TextTrackCue::calculateDisplayParameters() | 675 void TextTrackCue::calculateDisplayParameters() |
652 { | 676 { |
677 // A text track cue has a text track cue computed line position whose value | |
678 // is defined in terms of the other aspects of the cue. | |
679 m_computedLinePosition = calculateComputedLinePosition(); | |
acolwell GONE FROM CHROMIUM
2013/10/02 16:19:37
Does this really need to be moved to the top of th
philipj_slow
2013/10/03 09:04:43
In <http://dev.w3.org/html5/webvtt/> it's used in
vcarbune.chromium
2013/10/04 13:30:26
I moved it right before the point where it's used.
| |
680 | |
653 // Steps 10.2, 10.3 | 681 // Steps 10.2, 10.3 |
654 determineTextDirection(); | 682 determineTextDirection(); |
655 | 683 |
656 // 10.4 If the text track cue writing direction is horizontal, then let | 684 // 10.4 If the text track cue writing direction is horizontal, then let |
657 // 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 |
658 // 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 |
659 // 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 |
660 // 'rl'. | 688 // 'rl'. |
661 m_displayWritingMode = m_displayWritingModeMap[m_writingDirection]; | 689 m_displayWritingMode = m_displayWritingModeMap[m_writingDirection]; |
662 | 690 |
663 // 10.5 Determine the value of maximum size for cue as per the appropriate | 691 // 10.5 Determine the value of maximum size for cue as per the appropriate |
664 // rules from the following list: | 692 // rules from the following list: |
665 int maximumSize = m_textPosition; | 693 int maximumSize = m_textPosition; |
666 if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displa yDirection == CSSValueLtr) | 694 if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displa yDirection == CSSValueLtr) |
667 || (m_writingDirection == Horizontal && m_cueAlignment == End && m_d isplayDirection == CSSValueRtl) | 695 || (m_writingDirection == Horizontal && m_cueAlignment == End && m_d isplayDirection == CSSValueRtl) |
668 || (m_writingDirection == VerticalGrowingLeft && m_cueAlignment == S tart) | 696 || (m_writingDirection == Horizontal && m_cueAlignment == Left) |
669 || (m_writingDirection == VerticalGrowingRight && m_cueAlignment == Start)) { | 697 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == Start || m_cueAlignment == Left)) |
698 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == Start || m_cueAlignment == Left))) { | |
670 maximumSize = 100 - m_textPosition; | 699 maximumSize = 100 - m_textPosition; |
671 } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_d isplayDirection == CSSValueLtr) | 700 } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_d isplayDirection == CSSValueLtr) |
672 || (m_writingDirection == Horizontal && m_cueAlignment == Start && m _displayDirection == CSSValueRtl) | 701 || (m_writingDirection == Horizontal && m_cueAlignment == Start && m _displayDirection == CSSValueRtl) |
673 || (m_writingDirection == VerticalGrowingLeft && m_cueAlignment == E nd) | 702 || (m_writingDirection == Horizontal && m_cueAlignment == Right) |
674 || (m_writingDirection == VerticalGrowingRight && m_cueAlignment == End)) { | 703 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == End || m_cueAlignment == Right)) |
704 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == End || m_cueAlignment == Right))) { | |
675 maximumSize = m_textPosition; | 705 maximumSize = m_textPosition; |
676 } else if (m_cueAlignment == Middle) { | 706 } else if (m_cueAlignment == Middle) { |
677 maximumSize = m_textPosition <= 50 ? m_textPosition : (100 - m_textPosit ion); | 707 maximumSize = m_textPosition <= 50 ? m_textPosition : (100 - m_textPosit ion); |
678 maximumSize = maximumSize * 2; | 708 maximumSize = maximumSize * 2; |
679 } | 709 } |
acolwell GONE FROM CHROMIUM
2013/10/02 16:19:37
nit: Should we have an } else { ASSERT_NOT_REACHED
vcarbune.chromium
2013/10/04 13:30:26
Done.
| |
680 | 710 |
681 // 10.6 If the text track cue size is less than maximum size, then let size | 711 // 10.6 If the text track cue size is less than maximum size, then let size |
682 // be text track cue size. Otherwise, let size be maximum size. | 712 // be text track cue size. Otherwise, let size be maximum size. |
683 m_displaySize = std::min(m_cueSize, maximumSize); | 713 m_displaySize = std::min(m_cueSize, maximumSize); |
684 | 714 |
685 // 10.8 Determine the value of x-position or y-position for cue as per the | 715 // 10.8 Determine the value of x-position or y-position for cue as per the |
686 // appropriate rules from the following list: | 716 // appropriate rules from the following list: |
687 if (m_writingDirection == Horizontal) { | 717 if (m_writingDirection == Horizontal) { |
688 if (m_cueAlignment == Start) { | 718 if (m_cueAlignment == Start) { |
689 if (m_displayDirection == CSSValueLtr) | 719 if (m_displayDirection == CSSValueLtr) |
690 m_displayPosition.first = m_textPosition; | 720 m_displayPosition.first = m_textPosition; |
691 else | 721 else |
692 m_displayPosition.first = 100 - m_textPosition - m_displaySize; | 722 m_displayPosition.first = 100 - m_textPosition - m_displaySize; |
693 } else if (m_cueAlignment == End) { | 723 } else if (m_cueAlignment == End) { |
694 if (m_displayDirection == CSSValueRtl) | 724 if (m_displayDirection == CSSValueRtl) |
695 m_displayPosition.first = 100 - m_textPosition; | 725 m_displayPosition.first = 100 - m_textPosition; |
696 else | 726 else |
697 m_displayPosition.first = m_textPosition - m_displaySize; | 727 m_displayPosition.first = m_textPosition - m_displaySize; |
728 } else if (m_cueAlignment == Left) { | |
729 if (m_displayDirection == CSSValueLtr) | |
730 m_displayPosition.first = m_textPosition; | |
731 else | |
732 m_displayPosition.first = 100 - m_textPosition; | |
733 } else if (m_cueAlignment == Right) { | |
734 if (m_displayDirection == CSSValueLtr) | |
735 m_displayPosition.first = m_textPosition - m_displaySize; | |
736 else | |
737 m_displayPosition.first = 100 - m_textPosition - m_displaySize; | |
738 } else if (m_cueAlignment == Middle) { | |
739 if (m_displayDirection == CSSValueLtr) | |
740 m_displayPosition.first = m_textPosition - m_displaySize / 2; | |
741 else | |
742 m_displayPosition.first = 100 - m_textPosition - m_displaySize / 2; | |
698 } | 743 } |
744 } else { | |
745 // Cases for m_writingDirection being VerticalGrowing{Left|Right} | |
acolwell GONE FROM CHROMIUM
2013/10/02 16:19:37
nit: Please use switch(m_cueAlignment) here and ab
vcarbune.chromium
2013/10/04 13:30:26
Done. I had to add a default case though because o
| |
746 if (m_cueAlignment == Start || m_cueAlignment == Left) | |
747 m_displayPosition.second = m_textPosition; | |
748 else if (m_cueAlignment == End || m_cueAlignment == Right) | |
749 m_displayPosition.second = m_textPosition - m_displaySize; | |
750 else if (m_cueAlignment == Middle) | |
751 m_displayPosition.second = m_textPosition - m_displaySize / 2; | |
699 } | 752 } |
700 | 753 |
701 if ((m_writingDirection == VerticalGrowingLeft && m_cueAlignment == Start) | |
702 || (m_writingDirection == VerticalGrowingRight && m_cueAlignment == Start)) { | |
703 m_displayPosition.second = m_textPosition; | |
704 } else if ((m_writingDirection == VerticalGrowingLeft && m_cueAlignment == E nd) | |
705 || (m_writingDirection == VerticalGrowingRight && m_cueAlignment == End)) { | |
706 m_displayPosition.second = 100 - m_textPosition; | |
707 } | |
708 | |
709 if (m_writingDirection == Horizontal && m_cueAlignment == Middle) { | |
710 if (m_displayDirection == CSSValueLtr) | |
711 m_displayPosition.first = m_textPosition - m_displaySize / 2; | |
712 else | |
713 m_displayPosition.first = 100 - m_textPosition - m_displaySize / 2; | |
714 } | |
715 | |
716 if ((m_writingDirection == VerticalGrowingLeft && m_cueAlignment == Middle) | |
717 || (m_writingDirection == VerticalGrowingRight && m_cueAlignment == Midd le)) | |
718 m_displayPosition.second = m_textPosition - m_displaySize / 2; | |
719 | |
720 // 10.9 Determine the value of whichever of x-position or y-position is not | 754 // 10.9 Determine the value of whichever of x-position or y-position is not |
philipj_slow
2013/10/03 09:04:43
This is step 10.8 in <http://dev.w3.org/html5/webv
vcarbune.chromium
2013/10/04 13:30:26
Looking at the dates when this was submitted, look
philipj_slow
2013/10/07 08:52:31
For HTML there's <https://github.com/whatwg/html-m
vcarbune.chromium
2013/10/07 09:37:28
Thanks for the explanation, I think this can be ea
| |
721 // yet calculated for cue as per the appropriate rules from the following | 755 // yet calculated for cue as per the appropriate rules from the following |
722 // list: | 756 // list: |
723 if (m_snapToLines && m_displayPosition.second == undefinedPosition && m_writ ingDirection == Horizontal) | 757 if (m_snapToLines && m_displayPosition.second == undefinedPosition && m_writ ingDirection == Horizontal) |
724 m_displayPosition.second = 0; | 758 m_displayPosition.second = 0; |
725 | 759 |
726 if (!m_snapToLines && m_displayPosition.second == undefinedPosition && m_wri tingDirection == Horizontal) | 760 if (!m_snapToLines && m_displayPosition.second == undefinedPosition && m_wri tingDirection == Horizontal) |
727 m_displayPosition.second = m_computedLinePosition; | 761 m_displayPosition.second = m_computedLinePosition; |
728 | 762 |
729 if (m_snapToLines && m_displayPosition.first == undefinedPosition | 763 if (m_snapToLines && m_displayPosition.first == undefinedPosition |
730 && (m_writingDirection == VerticalGrowingLeft || m_writingDirection == VerticalGrowingRight)) | 764 && (m_writingDirection == VerticalGrowingLeft || m_writingDirection == VerticalGrowingRight)) |
731 m_displayPosition.first = 0; | 765 m_displayPosition.first = 0; |
732 | 766 |
733 if (!m_snapToLines && (m_writingDirection == VerticalGrowingLeft || m_writin gDirection == VerticalGrowingRight)) | 767 if (!m_snapToLines && (m_writingDirection == VerticalGrowingLeft || m_writin gDirection == VerticalGrowingRight)) |
734 m_displayPosition.first = m_computedLinePosition; | 768 m_displayPosition.first = m_computedLinePosition; |
735 | |
736 // A text track cue has a text track cue computed line position whose value | |
737 // is defined in terms of the other aspects of the cue. | |
738 m_computedLinePosition = calculateComputedLinePosition(); | |
739 } | 769 } |
740 | 770 |
741 void TextTrackCue::markFutureAndPastNodes(ContainerNode* root, double previousTi mestamp, double movieTime) | 771 void TextTrackCue::markFutureAndPastNodes(ContainerNode* root, double previousTi mestamp, double movieTime) |
742 { | 772 { |
743 DEFINE_STATIC_LOCAL(const String, timestampTag, ("timestamp")); | 773 DEFINE_STATIC_LOCAL(const String, timestampTag, ("timestamp")); |
744 | 774 |
745 bool isPastNode = true; | 775 bool isPastNode = true; |
746 double currentTimestamp = previousTimestamp; | 776 double currentTimestamp = previousTimestamp; |
747 if (currentTimestamp > movieTime) | 777 if (currentTimestamp > movieTime) |
748 isPastNode = false; | 778 isPastNode = false; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1087 if (cueAlignment == startKeyword()) | 1117 if (cueAlignment == startKeyword()) |
1088 m_cueAlignment = Start; | 1118 m_cueAlignment = Start; |
1089 | 1119 |
1090 // 2. If value is a case-sensitive match for the string "middle", th en let cue's text track cue alignment be middle alignment. | 1120 // 2. If value is a case-sensitive match for the string "middle", th en let cue's text track cue alignment be middle alignment. |
1091 else if (cueAlignment == middleKeyword()) | 1121 else if (cueAlignment == middleKeyword()) |
1092 m_cueAlignment = Middle; | 1122 m_cueAlignment = Middle; |
1093 | 1123 |
1094 // 3. If value is a case-sensitive match for the string "end", then let cue's text track cue alignment be end alignment. | 1124 // 3. If value is a case-sensitive match for the string "end", then let cue's text track cue alignment be end alignment. |
1095 else if (cueAlignment == endKeyword()) | 1125 else if (cueAlignment == endKeyword()) |
1096 m_cueAlignment = End; | 1126 m_cueAlignment = End; |
1127 | |
1128 // 4. If value is a case-sensitive match for the string "left", then let cue's text track cue alignment be left alignment. | |
1129 else if (cueAlignment == leftKeyword()) | |
1130 m_cueAlignment = Left; | |
1131 | |
1132 // 5. If value is a case-sensitive match for the string "right", the n let cue's text track cue alignment be right alignment. | |
1133 else if (cueAlignment == rightKeyword()) | |
1134 m_cueAlignment = Right; | |
1097 } | 1135 } |
1098 break; | 1136 break; |
1099 #if ENABLE(WEBVTT_REGIONS) | 1137 #if ENABLE(WEBVTT_REGIONS) |
1100 case RegionId: | 1138 case RegionId: |
1101 m_regionId = WebVTTParser::collectWord(input, &position); | 1139 m_regionId = WebVTTParser::collectWord(input, &position); |
1102 break; | 1140 break; |
1103 #endif | 1141 #endif |
1104 case None: | 1142 case None: |
1105 break; | 1143 break; |
1106 } | 1144 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 return false; | 1222 return false; |
1185 if (m_cueSize != cue.size()) | 1223 if (m_cueSize != cue.size()) |
1186 return false; | 1224 return false; |
1187 if (align() != cue.align()) | 1225 if (align() != cue.align()) |
1188 return false; | 1226 return false; |
1189 | 1227 |
1190 return true; | 1228 return true; |
1191 } | 1229 } |
1192 | 1230 |
1193 } // namespace WebCore | 1231 } // namespace WebCore |
OLD | NEW |