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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 node = NodeTraversal::nextSkippingChildren(*node); | 547 node = NodeTraversal::nextSkippingChildren(*node); |
548 continue; | 548 continue; |
549 } | 549 } |
550 } | 550 } |
551 | 551 |
552 node = NodeTraversal::next(*node); | 552 node = NodeTraversal::next(*node); |
553 } | 553 } |
554 return isLeftToRightDirection(textDirection) ? CSSValueLtr : CSSValueRtl; | 554 return isLeftToRightDirection(textDirection) ? CSSValueLtr : CSSValueRtl; |
555 } | 555 } |
556 | 556 |
| 557 static inline VTTCue::CueAlignment resolveCueAlignment(VTTCue::CueAlignment spec
ifiedCueAlignment, CSSValueID direction) |
| 558 { |
| 559 ASSERT(direction == CSSValueLtr || direction == CSSValueRtl); |
| 560 switch (specifiedCueAlignment) { |
| 561 case VTTCue::Start: |
| 562 return direction == CSSValueLtr ? VTTCue::Left : VTTCue::Right; |
| 563 case VTTCue::End: |
| 564 return direction == CSSValueLtr ? VTTCue::Right : VTTCue::Left; |
| 565 default: |
| 566 return specifiedCueAlignment; |
| 567 } |
| 568 } |
| 569 |
557 void VTTCue::calculateDisplayParameters() | 570 void VTTCue::calculateDisplayParameters() |
558 { | 571 { |
559 createVTTNodeTree(); | 572 createVTTNodeTree(); |
560 | 573 |
561 // Steps 10.2, 10.3 | 574 // Steps 10.2, 10.3 |
562 m_displayDirection = determineTextDirection(m_vttNodeTree.get()); | 575 m_displayDirection = determineTextDirection(m_vttNodeTree.get()); |
563 | 576 |
564 if (m_displayDirection == CSSValueRtl) | 577 if (m_displayDirection == CSSValueRtl) |
565 UseCounter::count(document(), UseCounter::VTTCueRenderRtl); | 578 UseCounter::count(document(), UseCounter::VTTCueRenderRtl); |
566 | 579 |
(...skipping 30 matching lines...) Expand all Loading... |
597 // 10.6 If the text track cue size is less than maximum size, then let size | 610 // 10.6 If the text track cue size is less than maximum size, then let size |
598 // be text track cue size. Otherwise, let size be maximum size. | 611 // be text track cue size. Otherwise, let size be maximum size. |
599 m_displaySize = std::min(m_cueSize, maximumSize); | 612 m_displaySize = std::min(m_cueSize, maximumSize); |
600 | 613 |
601 // FIXME: Understand why step 10.7 is missing (just a copy/paste error?) | 614 // FIXME: Understand why step 10.7 is missing (just a copy/paste error?) |
602 // Could be done within a spec implementation check - http://crbug.com/30158
0 | 615 // Could be done within a spec implementation check - http://crbug.com/30158
0 |
603 | 616 |
604 // 10.8 Determine the value of x-position or y-position for cue as per the | 617 // 10.8 Determine the value of x-position or y-position for cue as per the |
605 // appropriate rules from the following list: | 618 // appropriate rules from the following list: |
606 if (m_writingDirection == Horizontal) { | 619 if (m_writingDirection == Horizontal) { |
607 switch (m_cueAlignment) { | 620 int visualTextPosition = m_displayDirection == CSSValueLtr ? m_textPosit
ion : 100 - m_textPosition; |
608 case Start: | 621 |
609 if (m_displayDirection == CSSValueLtr) | 622 switch (resolveCueAlignment(m_cueAlignment, m_displayDirection)) { |
610 m_displayPosition.first = m_textPosition; | |
611 else | |
612 m_displayPosition.first = 100 - m_textPosition - m_displaySize; | |
613 break; | |
614 case End: | |
615 if (m_displayDirection == CSSValueRtl) | |
616 m_displayPosition.first = 100 - m_textPosition; | |
617 else | |
618 m_displayPosition.first = m_textPosition - m_displaySize; | |
619 break; | |
620 case Left: | 623 case Left: |
621 if (m_displayDirection == CSSValueLtr) | 624 m_displayPosition.first = visualTextPosition; |
622 m_displayPosition.first = m_textPosition; | |
623 else | |
624 m_displayPosition.first = 100 - m_textPosition; | |
625 break; | 625 break; |
626 case Right: | 626 case Right: |
627 if (m_displayDirection == CSSValueLtr) | 627 m_displayPosition.first = visualTextPosition - m_displaySize; |
628 m_displayPosition.first = m_textPosition - m_displaySize; | |
629 else | |
630 m_displayPosition.first = 100 - m_textPosition - m_displaySize; | |
631 break; | 628 break; |
632 case Middle: | 629 case Middle: |
633 if (m_displayDirection == CSSValueLtr) | 630 m_displayPosition.first = visualTextPosition - m_displaySize / 2; |
634 m_displayPosition.first = m_textPosition - m_displaySize / 2; | |
635 else | |
636 m_displayPosition.first = 100 - m_textPosition - m_displaySize /
2; | |
637 break; | 631 break; |
638 default: | 632 default: |
639 ASSERT_NOT_REACHED(); | 633 ASSERT_NOT_REACHED(); |
640 } | 634 } |
641 } else { | 635 } else { |
642 // Cases for m_writingDirection being VerticalGrowing{Left|Right} | 636 // Cases for m_writingDirection being VerticalGrowing{Left|Right} |
643 switch (m_cueAlignment) { | 637 switch (m_cueAlignment) { |
644 case Start: | 638 case Start: |
645 case Left: | 639 case Left: |
646 m_displayPosition.second = m_textPosition; | 640 m_displayPosition.second = m_textPosition; |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 | 1098 |
1105 void VTTCue::trace(Visitor* visitor) | 1099 void VTTCue::trace(Visitor* visitor) |
1106 { | 1100 { |
1107 visitor->trace(m_vttNodeTree); | 1101 visitor->trace(m_vttNodeTree); |
1108 visitor->trace(m_cueBackgroundBox); | 1102 visitor->trace(m_cueBackgroundBox); |
1109 visitor->trace(m_displayTree); | 1103 visitor->trace(m_displayTree); |
1110 TextTrackCue::trace(visitor); | 1104 TextTrackCue::trace(visitor); |
1111 } | 1105 } |
1112 | 1106 |
1113 } // namespace blink | 1107 } // namespace blink |
OLD | NEW |