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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 { | 217 { |
218 visitor->trace(m_cue); | 218 visitor->trace(m_cue); |
219 HTMLDivElement::trace(visitor); | 219 HTMLDivElement::trace(visitor); |
220 } | 220 } |
221 | 221 |
222 VTTCue::VTTCue(Document& document, double startTime, double endTime, const Strin
g& text) | 222 VTTCue::VTTCue(Document& document, double startTime, double endTime, const Strin
g& text) |
223 : TextTrackCue(startTime, endTime) | 223 : TextTrackCue(startTime, endTime) |
224 , m_text(text) | 224 , m_text(text) |
225 , m_linePosition(std::numeric_limits<float>::quiet_NaN()) | 225 , m_linePosition(std::numeric_limits<float>::quiet_NaN()) |
226 , m_computedLinePosition(std::numeric_limits<float>::quiet_NaN()) | 226 , m_computedLinePosition(std::numeric_limits<float>::quiet_NaN()) |
227 , m_textPosition(50) | 227 , m_textPosition(std::numeric_limits<float>::quiet_NaN()) |
228 , m_cueSize(100) | 228 , m_cueSize(100) |
229 , m_writingDirection(Horizontal) | 229 , m_writingDirection(Horizontal) |
230 , m_cueAlignment(Middle) | 230 , m_cueAlignment(Middle) |
231 , m_vttNodeTree(nullptr) | 231 , m_vttNodeTree(nullptr) |
232 , m_cueBackgroundBox(HTMLDivElement::create(document)) | 232 , m_cueBackgroundBox(HTMLDivElement::create(document)) |
233 , m_displayDirection(CSSValueLtr) | 233 , m_displayDirection(CSSValueLtr) |
234 , m_displaySize(undefinedSize) | 234 , m_displaySize(undefinedSize) |
235 , m_snapToLines(true) | 235 , m_snapToLines(true) |
236 , m_displayTreeShouldChange(true) | 236 , m_displayTreeShouldChange(true) |
237 , m_notifyRegion(true) | 237 , m_notifyRegion(true) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 if (m_linePosition == floatPosition) | 354 if (m_linePosition == floatPosition) |
355 return; | 355 return; |
356 } | 356 } |
357 | 357 |
358 cueWillChange(); | 358 cueWillChange(); |
359 m_linePosition = floatPosition; | 359 m_linePosition = floatPosition; |
360 m_computedLinePosition = calculateComputedLinePosition(); | 360 m_computedLinePosition = calculateComputedLinePosition(); |
361 cueDidChange(); | 361 cueDidChange(); |
362 } | 362 } |
363 | 363 |
364 void VTTCue::setPosition(double position, ExceptionState& exceptionState) | 364 bool VTTCue::textPositionIsAuto() const |
365 { | 365 { |
366 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#dom-texttrackcue-position | 366 return std::isnan(m_textPosition); |
367 // On setting, if the new value is negative or greater than 100, then throw
an IndexSizeError exception. | 367 } |
368 // Otherwise, set the text track cue text position to the new value. | 368 |
369 if (isInvalidPercentage(position, exceptionState)) | 369 void VTTCue::position(DoubleOrAutoKeyword& result) const |
| 370 { |
| 371 if (textPositionIsAuto()) |
| 372 result.setAutoKeyword(autoKeyword()); |
| 373 else |
| 374 result.setDouble(m_textPosition); |
| 375 } |
| 376 |
| 377 void VTTCue::setPosition(const DoubleOrAutoKeyword& position, ExceptionState& ex
ceptionState) |
| 378 { |
| 379 // FIXME: Expecting bindings code to handle this case: https://crbug.com/450
252. |
| 380 if (position.isDouble() && !std::isfinite(position.getAsDouble())) { |
| 381 exceptionState.throwTypeError("The provided double value is non-finite."
); |
370 return; | 382 return; |
| 383 } |
371 | 384 |
372 // Otherwise, set the text track cue line position to the new value. | 385 // http://dev.w3.org/html5/webvtt/#dfn-vttcue-position |
373 float floatPosition = narrowPrecisionToFloat(position); | 386 // On setting, if the new value is negative or greater than 100, then an |
374 if (m_textPosition == floatPosition) | 387 // IndexSizeError exception must be thrown. Otherwise, the text track cue |
375 return; | 388 // text position must be set to the new value; if the new value is the |
| 389 // string "auto", then it must be interpreted as the special value auto. |
| 390 float floatPosition; |
| 391 if (position.isAutoKeyword()) { |
| 392 if (textPositionIsAuto()) |
| 393 return; |
| 394 floatPosition = std::numeric_limits<float>::quiet_NaN(); |
| 395 } else { |
| 396 ASSERT(position.isDouble()); |
| 397 if (isInvalidPercentage(position.getAsDouble(), exceptionState)) |
| 398 return; |
| 399 floatPosition = narrowPrecisionToFloat(position.getAsDouble()); |
| 400 if (m_textPosition == floatPosition) |
| 401 return; |
| 402 } |
376 | 403 |
377 cueWillChange(); | 404 cueWillChange(); |
378 m_textPosition = floatPosition; | 405 m_textPosition = floatPosition; |
379 cueDidChange(); | 406 cueDidChange(); |
380 } | 407 } |
381 | 408 |
382 void VTTCue::setSize(double size, ExceptionState& exceptionState) | 409 void VTTCue::setSize(double size, ExceptionState& exceptionState) |
383 { | 410 { |
384 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#dom-texttrackcue-size | 411 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#dom-texttrackcue-size |
385 // On setting, if the new value is negative or greater than 100, then throw
an IndexSizeError | 412 // On setting, if the new value is negative or greater than 100, then throw
an IndexSizeError |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 node = NodeTraversal::nextSkippingChildren(*node); | 624 node = NodeTraversal::nextSkippingChildren(*node); |
598 continue; | 625 continue; |
599 } | 626 } |
600 } | 627 } |
601 | 628 |
602 node = NodeTraversal::next(*node); | 629 node = NodeTraversal::next(*node); |
603 } | 630 } |
604 return isLeftToRightDirection(textDirection) ? CSSValueLtr : CSSValueRtl; | 631 return isLeftToRightDirection(textDirection) ? CSSValueLtr : CSSValueRtl; |
605 } | 632 } |
606 | 633 |
| 634 float VTTCue::calculateComputedTextPosition() const |
| 635 { |
| 636 // http://dev.w3.org/html5/webvtt/#dfn-text-track-cue-computed-text-position |
| 637 |
| 638 // 1. If the text track cue text position is numeric, then return the value |
| 639 // of the text track cue text position and abort these steps. (Otherwise, |
| 640 // the text track cue text position is the special value auto.) |
| 641 if (!textPositionIsAuto()) |
| 642 return m_textPosition; |
| 643 |
| 644 switch (m_cueAlignment) { |
| 645 // 2. If the text track cue text alignment is start or left, return 0 and ab
ort these steps. |
| 646 case Start: |
| 647 case Left: |
| 648 return 0; |
| 649 // 3. If the text track cue text alignment is end or right, return 100 and a
bort these steps. |
| 650 case End: |
| 651 case Right: |
| 652 return 100; |
| 653 // 4. If the text track cue text alignment is middle, return 50 and abort th
ese steps. |
| 654 case Middle: |
| 655 return 50; |
| 656 default: |
| 657 ASSERT_NOT_REACHED(); |
| 658 return 0; |
| 659 } |
| 660 } |
| 661 |
607 static inline VTTCue::CueAlignment resolveCueAlignment(VTTCue::CueAlignment spec
ifiedCueAlignment, CSSValueID direction) | 662 static inline VTTCue::CueAlignment resolveCueAlignment(VTTCue::CueAlignment spec
ifiedCueAlignment, CSSValueID direction) |
608 { | 663 { |
609 ASSERT(direction == CSSValueLtr || direction == CSSValueRtl); | 664 ASSERT(direction == CSSValueLtr || direction == CSSValueRtl); |
610 switch (specifiedCueAlignment) { | 665 switch (specifiedCueAlignment) { |
611 case VTTCue::Start: | 666 case VTTCue::Start: |
612 return direction == CSSValueLtr ? VTTCue::Left : VTTCue::Right; | 667 return direction == CSSValueLtr ? VTTCue::Left : VTTCue::Right; |
613 case VTTCue::End: | 668 case VTTCue::End: |
614 return direction == CSSValueLtr ? VTTCue::Right : VTTCue::Left; | 669 return direction == CSSValueLtr ? VTTCue::Right : VTTCue::Left; |
615 default: | 670 default: |
616 return specifiedCueAlignment; | 671 return specifiedCueAlignment; |
(...skipping 13 matching lines...) Expand all Loading... |
630 // 10.4 If the text track cue writing direction is horizontal, then let | 685 // 10.4 If the text track cue writing direction is horizontal, then let |
631 // block-flow be 'tb'. Otherwise, if the text track cue writing direction is | 686 // block-flow be 'tb'. Otherwise, if the text track cue writing direction is |
632 // vertical growing left, then let block-flow be 'lr'. Otherwise, the text | 687 // vertical growing left, then let block-flow be 'lr'. Otherwise, the text |
633 // track cue writing direction is vertical growing right; let block-flow be | 688 // track cue writing direction is vertical growing right; let block-flow be |
634 // 'rl'. | 689 // 'rl'. |
635 | 690 |
636 // The above step is done through the writing direction static map. | 691 // The above step is done through the writing direction static map. |
637 | 692 |
638 // 10.5 Determine the value of maximum size for cue as per the appropriate | 693 // 10.5 Determine the value of maximum size for cue as per the appropriate |
639 // rules from the following list: | 694 // rules from the following list: |
640 float maximumSize = m_textPosition; | 695 float computedTextPosition = calculateComputedTextPosition(); |
| 696 float maximumSize = computedTextPosition; |
641 if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displa
yDirection == CSSValueLtr) | 697 if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displa
yDirection == CSSValueLtr) |
642 || (m_writingDirection == Horizontal && m_cueAlignment == End && m_displ
ayDirection == CSSValueRtl) | 698 || (m_writingDirection == Horizontal && m_cueAlignment == End && m_displ
ayDirection == CSSValueRtl) |
643 || (m_writingDirection == Horizontal && m_cueAlignment == Left) | 699 || (m_writingDirection == Horizontal && m_cueAlignment == Left) |
644 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == Star
t || m_cueAlignment == Left)) | 700 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == Star
t || m_cueAlignment == Left)) |
645 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == Sta
rt || m_cueAlignment == Left))) { | 701 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == Sta
rt || m_cueAlignment == Left))) { |
646 maximumSize = 100 - m_textPosition; | 702 maximumSize = 100 - computedTextPosition; |
647 } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_d
isplayDirection == CSSValueLtr) | 703 } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_d
isplayDirection == CSSValueLtr) |
648 || (m_writingDirection == Horizontal && m_cueAlignment == Start && m_dis
playDirection == CSSValueRtl) | 704 || (m_writingDirection == Horizontal && m_cueAlignment == Start && m_dis
playDirection == CSSValueRtl) |
649 || (m_writingDirection == Horizontal && m_cueAlignment == Right) | 705 || (m_writingDirection == Horizontal && m_cueAlignment == Right) |
650 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == End
|| m_cueAlignment == Right)) | 706 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == End
|| m_cueAlignment == Right)) |
651 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == End
|| m_cueAlignment == Right))) { | 707 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == End
|| m_cueAlignment == Right))) { |
652 maximumSize = m_textPosition; | 708 maximumSize = computedTextPosition; |
653 } else if (m_cueAlignment == Middle) { | 709 } else if (m_cueAlignment == Middle) { |
654 maximumSize = m_textPosition <= 50 ? m_textPosition : (100 - m_textPosit
ion); | 710 maximumSize = computedTextPosition <= 50 ? computedTextPosition : (100 -
computedTextPosition); |
655 maximumSize = maximumSize * 2; | 711 maximumSize = maximumSize * 2; |
656 } else { | 712 } else { |
657 ASSERT_NOT_REACHED(); | 713 ASSERT_NOT_REACHED(); |
658 } | 714 } |
659 | 715 |
660 // 10.6 If the text track cue size is less than maximum size, then let size | 716 // 10.6 If the text track cue size is less than maximum size, then let size |
661 // be text track cue size. Otherwise, let size be maximum size. | 717 // be text track cue size. Otherwise, let size be maximum size. |
662 m_displaySize = std::min(m_cueSize, maximumSize); | 718 m_displaySize = std::min(m_cueSize, maximumSize); |
663 | 719 |
664 // FIXME: Understand why step 10.7 is missing (just a copy/paste error?) | 720 // FIXME: Understand why step 10.7 is missing (just a copy/paste error?) |
665 // Could be done within a spec implementation check - http://crbug.com/30158
0 | 721 // Could be done within a spec implementation check - http://crbug.com/30158
0 |
666 | 722 |
667 // 10.8 Determine the value of x-position or y-position for cue as per the | 723 // 10.8 Determine the value of x-position or y-position for cue as per the |
668 // appropriate rules from the following list: | 724 // appropriate rules from the following list: |
669 if (m_writingDirection == Horizontal) { | 725 if (m_writingDirection == Horizontal) { |
670 float visualTextPosition = m_displayDirection == CSSValueLtr ? m_textPos
ition : 100 - m_textPosition; | 726 float visualTextPosition = m_displayDirection == CSSValueLtr ? computedT
extPosition : 100 - computedTextPosition; |
671 | 727 |
672 switch (resolveCueAlignment(m_cueAlignment, m_displayDirection)) { | 728 switch (resolveCueAlignment(m_cueAlignment, m_displayDirection)) { |
673 case Left: | 729 case Left: |
674 m_displayPosition.setX(visualTextPosition); | 730 m_displayPosition.setX(visualTextPosition); |
675 break; | 731 break; |
676 case Right: | 732 case Right: |
677 m_displayPosition.setX(visualTextPosition - m_displaySize); | 733 m_displayPosition.setX(visualTextPosition - m_displaySize); |
678 break; | 734 break; |
679 case Middle: | 735 case Middle: |
680 m_displayPosition.setX(visualTextPosition - m_displaySize / 2); | 736 m_displayPosition.setX(visualTextPosition - m_displaySize / 2); |
681 break; | 737 break; |
682 default: | 738 default: |
683 ASSERT_NOT_REACHED(); | 739 ASSERT_NOT_REACHED(); |
684 } | 740 } |
685 } else { | 741 } else { |
686 // Cases for m_writingDirection being VerticalGrowing{Left|Right} | 742 // Cases for m_writingDirection being VerticalGrowing{Left|Right} |
687 switch (m_cueAlignment) { | 743 switch (m_cueAlignment) { |
688 case Start: | 744 case Start: |
689 case Left: | 745 case Left: |
690 m_displayPosition.setY(m_textPosition); | 746 m_displayPosition.setY(computedTextPosition); |
691 break; | 747 break; |
692 case End: | 748 case End: |
693 case Right: | 749 case Right: |
694 m_displayPosition.setY(m_textPosition - m_displaySize); | 750 m_displayPosition.setY(computedTextPosition - m_displaySize); |
695 break; | 751 break; |
696 case Middle: | 752 case Middle: |
697 m_displayPosition.setY(m_textPosition - m_displaySize / 2); | 753 m_displayPosition.setY(computedTextPosition - m_displaySize / 2); |
698 break; | 754 break; |
699 default: | 755 default: |
700 ASSERT_NOT_REACHED(); | 756 ASSERT_NOT_REACHED(); |
701 } | 757 } |
702 } | 758 } |
703 | 759 |
704 // A text track cue has a text track cue computed line position whose value | 760 // A text track cue has a text track cue computed line position whose value |
705 // is defined in terms of the other aspects of the cue. | 761 // is defined in terms of the other aspects of the cue. |
706 m_computedLinePosition = calculateComputedLinePosition(); | 762 m_computedLinePosition = calculateComputedLinePosition(); |
707 | 763 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 885 |
830 if (m_writingDirection != Horizontal) | 886 if (m_writingDirection != Horizontal) |
831 UseCounter::count(document(), UseCounter::VTTCueRenderVertical); | 887 UseCounter::count(document(), UseCounter::VTTCueRenderVertical); |
832 | 888 |
833 if (!m_snapToLines) | 889 if (!m_snapToLines) |
834 UseCounter::count(document(), UseCounter::VTTCueRenderSnapToLinesFalse); | 890 UseCounter::count(document(), UseCounter::VTTCueRenderSnapToLinesFalse); |
835 | 891 |
836 if (!lineIsAuto()) | 892 if (!lineIsAuto()) |
837 UseCounter::count(document(), UseCounter::VTTCueRenderLineNotAuto); | 893 UseCounter::count(document(), UseCounter::VTTCueRenderLineNotAuto); |
838 | 894 |
839 if (m_textPosition != 50) | 895 if (textPositionIsAuto()) |
840 UseCounter::count(document(), UseCounter::VTTCueRenderPositionNot50); | 896 UseCounter::count(document(), UseCounter::VTTCueRenderPositionNot50); |
841 | 897 |
842 if (m_cueSize != 100) | 898 if (m_cueSize != 100) |
843 UseCounter::count(document(), UseCounter::VTTCueRenderSizeNot100); | 899 UseCounter::count(document(), UseCounter::VTTCueRenderSizeNot100); |
844 | 900 |
845 if (m_cueAlignment != Middle) | 901 if (m_cueAlignment != Middle) |
846 UseCounter::count(document(), UseCounter::VTTCueRenderAlignNotMiddle); | 902 UseCounter::count(document(), UseCounter::VTTCueRenderAlignNotMiddle); |
847 | 903 |
848 RefPtrWillBeRawPtr<VTTCueBox> displayBox = getDisplayTree(videoSize); | 904 RefPtrWillBeRawPtr<VTTCueBox> displayBox = getDisplayTree(videoSize); |
849 VTTRegion* region = 0; | 905 VTTRegion* region = 0; |
(...skipping 18 matching lines...) Expand all Loading... |
868 container.appendChild(regionNode); | 924 container.appendChild(regionNode); |
869 | 925 |
870 region->appendVTTCueBox(displayBox); | 926 region->appendVTTCueBox(displayBox); |
871 } | 927 } |
872 } | 928 } |
873 | 929 |
874 FloatPoint VTTCue::getPositionCoordinates() const | 930 FloatPoint VTTCue::getPositionCoordinates() const |
875 { | 931 { |
876 // This method is used for setting x and y when snap to lines is not set. | 932 // This method is used for setting x and y when snap to lines is not set. |
877 ASSERT(std::isfinite(m_computedLinePosition)); | 933 ASSERT(std::isfinite(m_computedLinePosition)); |
| 934 float computedTextPosition = calculateComputedTextPosition(); |
878 | 935 |
879 if (m_writingDirection == Horizontal && m_displayDirection == CSSValueLtr) | 936 if (m_writingDirection == Horizontal && m_displayDirection == CSSValueLtr) |
880 return FloatPoint(m_textPosition, m_computedLinePosition); | 937 return FloatPoint(computedTextPosition, m_computedLinePosition); |
881 | 938 |
882 if (m_writingDirection == Horizontal && m_displayDirection == CSSValueRtl) | 939 if (m_writingDirection == Horizontal && m_displayDirection == CSSValueRtl) |
883 return FloatPoint(100 - m_textPosition, m_computedLinePosition); | 940 return FloatPoint(100 - computedTextPosition, m_computedLinePosition); |
884 | 941 |
885 if (m_writingDirection == VerticalGrowingLeft) | 942 if (m_writingDirection == VerticalGrowingLeft) |
886 return FloatPoint(100 - m_computedLinePosition, m_textPosition); | 943 return FloatPoint(100 - m_computedLinePosition, computedTextPosition); |
887 | 944 |
888 if (m_writingDirection == VerticalGrowingRight) | 945 if (m_writingDirection == VerticalGrowingRight) |
889 return FloatPoint(m_computedLinePosition, m_textPosition); | 946 return FloatPoint(m_computedLinePosition, computedTextPosition); |
890 | 947 |
891 ASSERT_NOT_REACHED(); | 948 ASSERT_NOT_REACHED(); |
892 return FloatPoint(); | 949 return FloatPoint(); |
893 } | 950 } |
894 | 951 |
895 VTTCue::CueSetting VTTCue::settingName(VTTScanner& input) | 952 VTTCue::CueSetting VTTCue::settingName(VTTScanner& input) |
896 { | 953 { |
897 CueSetting parsedSetting = None; | 954 CueSetting parsedSetting = None; |
898 if (input.scan("vertical")) | 955 if (input.scan("vertical")) |
899 parsedSetting = Vertical; | 956 parsedSetting = Vertical; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 | 1188 |
1132 void VTTCue::trace(Visitor* visitor) | 1189 void VTTCue::trace(Visitor* visitor) |
1133 { | 1190 { |
1134 visitor->trace(m_vttNodeTree); | 1191 visitor->trace(m_vttNodeTree); |
1135 visitor->trace(m_cueBackgroundBox); | 1192 visitor->trace(m_cueBackgroundBox); |
1136 visitor->trace(m_displayTree); | 1193 visitor->trace(m_displayTree); |
1137 TextTrackCue::trace(visitor); | 1194 TextTrackCue::trace(visitor); |
1138 } | 1195 } |
1139 | 1196 |
1140 } // namespace blink | 1197 } // namespace blink |
OLD | NEW |