OLD | NEW |
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 static const String& autoKeyword() { | 72 static const String& autoKeyword() { |
73 DEFINE_STATIC_LOCAL(const String, autoString, ("auto")); | 73 DEFINE_STATIC_LOCAL(const String, autoString, ("auto")); |
74 return autoString; | 74 return autoString; |
75 } | 75 } |
76 | 76 |
77 static const String& startKeyword() { | 77 static const String& startKeyword() { |
78 DEFINE_STATIC_LOCAL(const String, start, ("start")); | 78 DEFINE_STATIC_LOCAL(const String, start, ("start")); |
79 return start; | 79 return start; |
80 } | 80 } |
81 | 81 |
82 static const String& middleKeyword() { | 82 static const String& centerKeyword() { |
83 DEFINE_STATIC_LOCAL(const String, middle, ("middle")); | 83 DEFINE_STATIC_LOCAL(const String, center, ("center")); |
84 return middle; | 84 return center; |
85 } | 85 } |
86 | 86 |
87 static const String& endKeyword() { | 87 static const String& endKeyword() { |
88 DEFINE_STATIC_LOCAL(const String, end, ("end")); | 88 DEFINE_STATIC_LOCAL(const String, end, ("end")); |
89 return end; | 89 return end; |
90 } | 90 } |
91 | 91 |
92 static const String& leftKeyword() { | 92 static const String& leftKeyword() { |
93 DEFINE_STATIC_LOCAL(const String, left, ("left")); | 93 DEFINE_STATIC_LOCAL(const String, left, ("left")); |
94 return left; | 94 return left; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 VTTCue::VTTCue(Document& document, | 232 VTTCue::VTTCue(Document& document, |
233 double startTime, | 233 double startTime, |
234 double endTime, | 234 double endTime, |
235 const String& text) | 235 const String& text) |
236 : TextTrackCue(startTime, endTime), | 236 : TextTrackCue(startTime, endTime), |
237 m_text(text), | 237 m_text(text), |
238 m_linePosition(std::numeric_limits<float>::quiet_NaN()), | 238 m_linePosition(std::numeric_limits<float>::quiet_NaN()), |
239 m_textPosition(std::numeric_limits<float>::quiet_NaN()), | 239 m_textPosition(std::numeric_limits<float>::quiet_NaN()), |
240 m_cueSize(100), | 240 m_cueSize(100), |
241 m_writingDirection(Horizontal), | 241 m_writingDirection(Horizontal), |
242 m_cueAlignment(Middle), | 242 m_cueAlignment(Center), |
243 m_vttNodeTree(nullptr), | 243 m_vttNodeTree(nullptr), |
244 m_cueBackgroundBox(HTMLDivElement::create(document)), | 244 m_cueBackgroundBox(HTMLDivElement::create(document)), |
245 m_snapToLines(true), | 245 m_snapToLines(true), |
246 m_displayTreeShouldChange(true) { | 246 m_displayTreeShouldChange(true) { |
247 UseCounter::count(document, UseCounter::VTTCue); | 247 UseCounter::count(document, UseCounter::VTTCue); |
248 m_cueBackgroundBox->setShadowPseudoId(cueShadowPseudoId()); | 248 m_cueBackgroundBox->setShadowPseudoId(cueShadowPseudoId()); |
249 } | 249 } |
250 | 250 |
251 VTTCue::~VTTCue() {} | 251 VTTCue::~VTTCue() {} |
252 | 252 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 389 |
390 cueWillChange(); | 390 cueWillChange(); |
391 m_cueSize = floatSize; | 391 m_cueSize = floatSize; |
392 cueDidChange(); | 392 cueDidChange(); |
393 } | 393 } |
394 | 394 |
395 const String& VTTCue::align() const { | 395 const String& VTTCue::align() const { |
396 switch (m_cueAlignment) { | 396 switch (m_cueAlignment) { |
397 case Start: | 397 case Start: |
398 return startKeyword(); | 398 return startKeyword(); |
399 case Middle: | 399 case Center: |
400 return middleKeyword(); | 400 return centerKeyword(); |
401 case End: | 401 case End: |
402 return endKeyword(); | 402 return endKeyword(); |
403 case Left: | 403 case Left: |
404 return leftKeyword(); | 404 return leftKeyword(); |
405 case Right: | 405 case Right: |
406 return rightKeyword(); | 406 return rightKeyword(); |
407 default: | 407 default: |
408 NOTREACHED(); | 408 NOTREACHED(); |
409 return emptyString; | 409 return emptyString; |
410 } | 410 } |
411 } | 411 } |
412 | 412 |
413 void VTTCue::setAlign(const String& value) { | 413 void VTTCue::setAlign(const String& value) { |
414 CueAlignment alignment = m_cueAlignment; | 414 CueAlignment alignment = m_cueAlignment; |
415 if (value == startKeyword()) | 415 if (value == startKeyword()) |
416 alignment = Start; | 416 alignment = Start; |
417 else if (value == middleKeyword()) | 417 else if (value == centerKeyword()) |
418 alignment = Middle; | 418 alignment = Center; |
419 else if (value == endKeyword()) | 419 else if (value == endKeyword()) |
420 alignment = End; | 420 alignment = End; |
421 else if (value == leftKeyword()) | 421 else if (value == leftKeyword()) |
422 alignment = Left; | 422 alignment = Left; |
423 else if (value == rightKeyword()) | 423 else if (value == rightKeyword()) |
424 alignment = Right; | 424 alignment = Right; |
425 else | 425 else |
426 NOTREACHED(); | 426 NOTREACHED(); |
427 | 427 |
428 if (alignment == m_cueAlignment) | 428 if (alignment == m_cueAlignment) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 // 2. If the cue text alignment is start or left, return 0 and abort these | 592 // 2. If the cue text alignment is start or left, return 0 and abort these |
593 // steps. | 593 // steps. |
594 case Start: | 594 case Start: |
595 case Left: | 595 case Left: |
596 return 0; | 596 return 0; |
597 // 3. If the cue text alignment is end or right, return 100 and abort these | 597 // 3. If the cue text alignment is end or right, return 100 and abort these |
598 // steps. | 598 // steps. |
599 case End: | 599 case End: |
600 case Right: | 600 case Right: |
601 return 100; | 601 return 100; |
602 // 4. If the cue text alignment is middle, return 50 and abort these steps. | 602 // 4. If the cue text alignment is center, return 50 and abort these steps. |
603 case Middle: | 603 case Center: |
604 return 50; | 604 return 50; |
605 default: | 605 default: |
606 NOTREACHED(); | 606 NOTREACHED(); |
607 return 0; | 607 return 0; |
608 } | 608 } |
609 } | 609 } |
610 | 610 |
611 VTTCue::CueAlignment VTTCue::calculateComputedCueAlignment() const { | 611 VTTCue::CueAlignment VTTCue::calculateComputedCueAlignment() const { |
612 switch (m_cueAlignment) { | 612 switch (m_cueAlignment) { |
613 case VTTCue::Left: | 613 case VTTCue::Left: |
(...skipping 26 matching lines...) Expand all Loading... |
640 // Note: The 'text-align' property is also determined here so that | 640 // Note: The 'text-align' property is also determined here so that |
641 // VTTCueBox::applyCSSProperties need not have access to a VTTCue. | 641 // VTTCueBox::applyCSSProperties need not have access to a VTTCue. |
642 displayParameters.textAlign = displayAlignmentMap[getCueAlignment()]; | 642 displayParameters.textAlign = displayAlignmentMap[getCueAlignment()]; |
643 | 643 |
644 // 3. If the cue writing direction is horizontal, then let block-flow be | 644 // 3. If the cue writing direction is horizontal, then let block-flow be |
645 // 'tb'. Otherwise, if the cue writing direction is vertical growing left, | 645 // 'tb'. Otherwise, if the cue writing direction is vertical growing left, |
646 // then let block-flow be 'lr'. Otherwise, the cue writing direction is | 646 // then let block-flow be 'lr'. Otherwise, the cue writing direction is |
647 // vertical growing right; let block-flow be 'rl'. | 647 // vertical growing right; let block-flow be 'rl'. |
648 displayParameters.writingMode = displayWritingModeMap[m_writingDirection]; | 648 displayParameters.writingMode = displayWritingModeMap[m_writingDirection]; |
649 | 649 |
650 // Resolve the cue alignment to one of the values {start, end, middle}. | 650 // Resolve the cue alignment to one of the values {start, end, center}. |
651 CueAlignment computedCueAlignment = calculateComputedCueAlignment(); | 651 CueAlignment computedCueAlignment = calculateComputedCueAlignment(); |
652 | 652 |
653 // 4. Determine the value of maximum size for cue as per the appropriate | 653 // 4. Determine the value of maximum size for cue as per the appropriate |
654 // rules from the following list: | 654 // rules from the following list: |
655 float computedTextPosition = calculateComputedTextPosition(); | 655 float computedTextPosition = calculateComputedTextPosition(); |
656 float maximumSize = computedTextPosition; | 656 float maximumSize = computedTextPosition; |
657 if (computedCueAlignment == Start) { | 657 if (computedCueAlignment == Start) { |
658 maximumSize = 100 - computedTextPosition; | 658 maximumSize = 100 - computedTextPosition; |
659 } else if (computedCueAlignment == End) { | 659 } else if (computedCueAlignment == End) { |
660 maximumSize = computedTextPosition; | 660 maximumSize = computedTextPosition; |
661 } else if (computedCueAlignment == Middle) { | 661 } else if (computedCueAlignment == Center) { |
662 maximumSize = computedTextPosition <= 50 ? computedTextPosition | 662 maximumSize = computedTextPosition <= 50 ? computedTextPosition |
663 : (100 - computedTextPosition); | 663 : (100 - computedTextPosition); |
664 maximumSize = maximumSize * 2; | 664 maximumSize = maximumSize * 2; |
665 } else { | 665 } else { |
666 NOTREACHED(); | 666 NOTREACHED(); |
667 } | 667 } |
668 | 668 |
669 // 5. If the cue size is less than maximum size, then let size | 669 // 5. If the cue size is less than maximum size, then let size |
670 // be cue size. Otherwise, let size be maximum size. | 670 // be cue size. Otherwise, let size be maximum size. |
671 displayParameters.size = std::min(m_cueSize, maximumSize); | 671 displayParameters.size = std::min(m_cueSize, maximumSize); |
672 | 672 |
673 // 6. If the cue writing direction is horizontal, then let width | 673 // 6. If the cue writing direction is horizontal, then let width |
674 // be 'size vw' and height be 'auto'. Otherwise, let width be 'auto' and | 674 // be 'size vw' and height be 'auto'. Otherwise, let width be 'auto' and |
675 // height be 'size vh'. (These are CSS values used by the next section to | 675 // height be 'size vh'. (These are CSS values used by the next section to |
676 // set CSS properties for the rendering; 'vw' and 'vh' are CSS units.) | 676 // set CSS properties for the rendering; 'vw' and 'vh' are CSS units.) |
677 // (Emulated in VTTCueBox::applyCSSProperties.) | 677 // (Emulated in VTTCueBox::applyCSSProperties.) |
678 | 678 |
679 // 7. Determine the value of x-position or y-position for cue as per the | 679 // 7. Determine the value of x-position or y-position for cue as per the |
680 // appropriate rules from the following list: | 680 // appropriate rules from the following list: |
681 if (m_writingDirection == Horizontal) { | 681 if (m_writingDirection == Horizontal) { |
682 switch (computedCueAlignment) { | 682 switch (computedCueAlignment) { |
683 case Start: | 683 case Start: |
684 displayParameters.position.setX(computedTextPosition); | 684 displayParameters.position.setX(computedTextPosition); |
685 break; | 685 break; |
686 case End: | 686 case End: |
687 displayParameters.position.setX(computedTextPosition - | 687 displayParameters.position.setX(computedTextPosition - |
688 displayParameters.size); | 688 displayParameters.size); |
689 break; | 689 break; |
690 case Middle: | 690 case Center: |
691 displayParameters.position.setX(computedTextPosition - | 691 displayParameters.position.setX(computedTextPosition - |
692 displayParameters.size / 2); | 692 displayParameters.size / 2); |
693 break; | 693 break; |
694 default: | 694 default: |
695 NOTREACHED(); | 695 NOTREACHED(); |
696 } | 696 } |
697 } else { | 697 } else { |
698 // Cases for m_writingDirection being VerticalGrowing{Left|Right} | 698 // Cases for m_writingDirection being VerticalGrowing{Left|Right} |
699 switch (computedCueAlignment) { | 699 switch (computedCueAlignment) { |
700 case Start: | 700 case Start: |
701 displayParameters.position.setY(computedTextPosition); | 701 displayParameters.position.setY(computedTextPosition); |
702 break; | 702 break; |
703 case End: | 703 case End: |
704 displayParameters.position.setY(computedTextPosition - | 704 displayParameters.position.setY(computedTextPosition - |
705 displayParameters.size); | 705 displayParameters.size); |
706 break; | 706 break; |
707 case Middle: | 707 case Center: |
708 displayParameters.position.setY(computedTextPosition - | 708 displayParameters.position.setY(computedTextPosition - |
709 displayParameters.size / 2); | 709 displayParameters.size / 2); |
710 break; | 710 break; |
711 default: | 711 default: |
712 NOTREACHED(); | 712 NOTREACHED(); |
713 } | 713 } |
714 } | 714 } |
715 | 715 |
716 // A cue has a computed line whose value is defined in terms of | 716 // A cue has a computed line whose value is defined in terms of |
717 // the other aspects of the cue. | 717 // the other aspects of the cue. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 | 850 |
851 if (!lineIsAuto()) | 851 if (!lineIsAuto()) |
852 UseCounter::count(document(), UseCounter::VTTCueRenderLineNotAuto); | 852 UseCounter::count(document(), UseCounter::VTTCueRenderLineNotAuto); |
853 | 853 |
854 if (textPositionIsAuto()) | 854 if (textPositionIsAuto()) |
855 UseCounter::count(document(), UseCounter::VTTCueRenderPositionNot50); | 855 UseCounter::count(document(), UseCounter::VTTCueRenderPositionNot50); |
856 | 856 |
857 if (m_cueSize != 100) | 857 if (m_cueSize != 100) |
858 UseCounter::count(document(), UseCounter::VTTCueRenderSizeNot100); | 858 UseCounter::count(document(), UseCounter::VTTCueRenderSizeNot100); |
859 | 859 |
860 if (m_cueAlignment != Middle) | 860 if (m_cueAlignment != Center) |
861 UseCounter::count(document(), UseCounter::VTTCueRenderAlignNotMiddle); | 861 UseCounter::count(document(), UseCounter::VTTCueRenderAlignNotCenter); |
862 | 862 |
863 VTTCueBox* displayBox = getDisplayTree(); | 863 VTTCueBox* displayBox = getDisplayTree(); |
864 if (!region()) { | 864 if (!region()) { |
865 if (displayBox->hasChildren() && !container.contains(displayBox)) { | 865 if (displayBox->hasChildren() && !container.contains(displayBox)) { |
866 // Note: the display tree of a cue is removed when the active flag of the | 866 // Note: the display tree of a cue is removed when the active flag of the |
867 // cue is unset. | 867 // cue is unset. |
868 container.appendChild(displayBox); | 868 container.appendChild(displayBox); |
869 } | 869 } |
870 } else { | 870 } else { |
871 HTMLDivElement* regionNode = region()->getDisplayTree(document()); | 871 HTMLDivElement* regionNode = region()->getDisplayTree(document()); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 m_cueSize = number; | 1043 m_cueSize = number; |
1044 break; | 1044 break; |
1045 } | 1045 } |
1046 case Align: { | 1046 case Align: { |
1047 // If name is a case-sensitive match for "align" | 1047 // If name is a case-sensitive match for "align" |
1048 // 1. If value is a case-sensitive match for the string "start", | 1048 // 1. If value is a case-sensitive match for the string "start", |
1049 // then let cue's WebVTT cue text alignment be start alignment. | 1049 // then let cue's WebVTT cue text alignment be start alignment. |
1050 if (input.scanRun(valueRun, startKeyword())) | 1050 if (input.scanRun(valueRun, startKeyword())) |
1051 m_cueAlignment = Start; | 1051 m_cueAlignment = Start; |
1052 | 1052 |
1053 // 2. If value is a case-sensitive match for the string "middle", | 1053 // 2. If value is a case-sensitive match for the string "center", |
1054 // then let cue's WebVTT cue text alignment be middle alignment. | 1054 // then let cue's WebVTT cue text alignment be center alignment. |
1055 else if (input.scanRun(valueRun, middleKeyword())) | 1055 else if (input.scanRun(valueRun, centerKeyword())) |
1056 m_cueAlignment = Middle; | 1056 m_cueAlignment = Center; |
1057 | 1057 |
1058 // 3. If value is a case-sensitive match for the string "end", then | 1058 // 3. If value is a case-sensitive match for the string "end", then |
1059 // let cue's WebVTT cue text alignment be end alignment. | 1059 // let cue's WebVTT cue text alignment be end alignment. |
1060 else if (input.scanRun(valueRun, endKeyword())) | 1060 else if (input.scanRun(valueRun, endKeyword())) |
1061 m_cueAlignment = End; | 1061 m_cueAlignment = End; |
1062 | 1062 |
1063 // 4. If value is a case-sensitive match for the string "left", | 1063 // 4. If value is a case-sensitive match for the string "left", |
1064 // then let cue's WebVTT cue text alignment be left alignment. | 1064 // then let cue's WebVTT cue text alignment be left alignment. |
1065 else if (input.scanRun(valueRun, leftKeyword())) | 1065 else if (input.scanRun(valueRun, leftKeyword())) |
1066 m_cueAlignment = Left; | 1066 m_cueAlignment = Left; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 | 1118 |
1119 DEFINE_TRACE(VTTCue) { | 1119 DEFINE_TRACE(VTTCue) { |
1120 visitor->trace(m_region); | 1120 visitor->trace(m_region); |
1121 visitor->trace(m_vttNodeTree); | 1121 visitor->trace(m_vttNodeTree); |
1122 visitor->trace(m_cueBackgroundBox); | 1122 visitor->trace(m_cueBackgroundBox); |
1123 visitor->trace(m_displayTree); | 1123 visitor->trace(m_displayTree); |
1124 TextTrackCue::trace(visitor); | 1124 TextTrackCue::trace(visitor); |
1125 } | 1125 } |
1126 | 1126 |
1127 } // namespace blink | 1127 } // namespace blink |
OLD | NEW |