Chromium Code Reviews| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 return false; | 136 return false; |
| 137 } | 137 } |
| 138 | 138 |
| 139 VTTCueBox::VTTCueBox(Document& document, VTTCue* cue) | 139 VTTCueBox::VTTCueBox(Document& document, VTTCue* cue) |
| 140 : HTMLDivElement(document) | 140 : HTMLDivElement(document) |
| 141 , m_cue(cue) | 141 , m_cue(cue) |
| 142 { | 142 { |
| 143 setShadowPseudoId(AtomicString("-webkit-media-text-track-display", AtomicStr ing::ConstructFromLiteral)); | 143 setShadowPseudoId(AtomicString("-webkit-media-text-track-display", AtomicStr ing::ConstructFromLiteral)); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void VTTCueBox::applyCSSProperties(const IntSize&) | 146 void VTTCueBox::applyCSSProperties(const VTTDisplayParameters& displayParameters ) |
| 147 { | 147 { |
| 148 // FIXME: Apply all the initial CSS positioning properties. http://wkb.ug/79 916 | 148 // FIXME: Apply all the initial CSS positioning properties. http://wkb.ug/79 916 |
| 149 if (!m_cue->regionId().isEmpty()) { | 149 if (!m_cue->regionId().isEmpty()) { |
| 150 setInlineStyleProperty(CSSPropertyPosition, CSSValueRelative); | 150 setInlineStyleProperty(CSSPropertyPosition, CSSValueRelative); |
| 151 return; | 151 return; |
| 152 } | 152 } |
| 153 | 153 |
| 154 // 3.5.1 On the (root) List of WebVTT Node Objects: | 154 // 3.5.1 On the (root) List of WebVTT Node Objects: |
| 155 | 155 |
| 156 // the 'position' property must be set to 'absolute' | 156 // the 'position' property must be set to 'absolute' |
| 157 setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute); | 157 setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute); |
| 158 | 158 |
| 159 // the 'unicode-bidi' property must be set to 'plaintext' | 159 // the 'unicode-bidi' property must be set to 'plaintext' |
| 160 setInlineStyleProperty(CSSPropertyUnicodeBidi, CSSValueWebkitPlaintext); | 160 setInlineStyleProperty(CSSPropertyUnicodeBidi, CSSValueWebkitPlaintext); |
| 161 | 161 |
| 162 // the 'direction' property must be set to direction | 162 // the 'direction' property must be set to direction |
| 163 setInlineStyleProperty(CSSPropertyDirection, m_cue->getCSSWritingDirection() ); | 163 setInlineStyleProperty(CSSPropertyDirection, displayParameters.direction); |
| 164 | 164 |
| 165 // the 'writing-mode' property must be set to writing-mode | 165 // the 'writing-mode' property must be set to writing-mode |
| 166 setInlineStyleProperty(CSSPropertyWebkitWritingMode, m_cue->getCSSWritingMod e()); | 166 setInlineStyleProperty(CSSPropertyWebkitWritingMode, displayParameters.writi ngMode); |
| 167 | 167 |
| 168 FloatPoint position = m_cue->getCSSPosition(); | 168 const FloatPoint& position = displayParameters.position; |
| 169 | 169 |
| 170 // the 'top' property must be set to top, | 170 // the 'top' property must be set to top, |
| 171 setInlineStyleProperty(CSSPropertyTop, position.y(), CSSPrimitiveValue::CSS_ PERCENTAGE); | 171 setInlineStyleProperty(CSSPropertyTop, position.y(), CSSPrimitiveValue::CSS_ PERCENTAGE); |
| 172 | 172 |
| 173 // the 'left' property must be set to left | 173 // the 'left' property must be set to left |
| 174 setInlineStyleProperty(CSSPropertyLeft, position.x(), CSSPrimitiveValue::CSS _PERCENTAGE); | 174 setInlineStyleProperty(CSSPropertyLeft, position.x(), CSSPrimitiveValue::CSS _PERCENTAGE); |
| 175 | 175 |
| 176 // the 'width' property must be set to width, and the 'height' property mus t be set to height | 176 // the 'width' property must be set to width, and the 'height' property mus t be set to height |
| 177 if (m_cue->vertical() == horizontalKeyword()) { | 177 if (m_cue->vertical() == horizontalKeyword()) { |
| 178 setInlineStyleProperty(CSSPropertyWidth, static_cast<double>(m_cue->getC SSSize()), CSSPrimitiveValue::CSS_PERCENTAGE); | 178 setInlineStyleProperty(CSSPropertyWidth, displayParameters.size, CSSPrim itiveValue::CSS_PERCENTAGE); |
| 179 setInlineStyleProperty(CSSPropertyHeight, CSSValueAuto); | 179 setInlineStyleProperty(CSSPropertyHeight, CSSValueAuto); |
| 180 } else { | 180 } else { |
| 181 setInlineStyleProperty(CSSPropertyWidth, CSSValueAuto); | 181 setInlineStyleProperty(CSSPropertyWidth, CSSValueAuto); |
| 182 setInlineStyleProperty(CSSPropertyHeight, static_cast<double>(m_cue->get CSSSize()), CSSPrimitiveValue::CSS_PERCENTAGE); | 182 setInlineStyleProperty(CSSPropertyHeight, displayParameters.size, CSSPr imitiveValue::CSS_PERCENTAGE); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // The 'text-align' property on the (root) List of WebVTT Node Objects must | 185 // The 'text-align' property on the (root) List of WebVTT Node Objects must |
| 186 // be set to the value in the second cell of the row of the table below | 186 // be set to the value in the second cell of the row of the table below |
| 187 // whose first cell is the value of the corresponding cue's text track cue | 187 // whose first cell is the value of the corresponding cue's text track cue |
| 188 // alignment: | 188 // alignment: |
| 189 setInlineStyleProperty(CSSPropertyTextAlign, m_cue->getCSSAlignment()); | 189 setInlineStyleProperty(CSSPropertyTextAlign, displayAlignmentMap[m_cue->cueA lignment()]); |
| 190 | 190 |
| 191 if (!m_cue->snapToLines()) { | 191 if (!m_cue->snapToLines()) { |
| 192 // 10.13.1 Set up x and y: | 192 // 10.13.1 Set up x and y: |
| 193 // Note: x and y are set through the CSS left and top above. | 193 // Note: x and y are set through the CSS left and top above. |
| 194 | 194 |
| 195 // 10.13.2 Position the boxes in boxes such that the point x% along the | 195 // 10.13.2 Position the boxes in boxes such that the point x% along the |
| 196 // width of the bounding box of the boxes in boxes is x% of the way | 196 // width of the bounding box of the boxes in boxes is x% of the way |
| 197 // across the width of the video's rendering area, and the point y% | 197 // across the width of the video's rendering area, and the point y% |
| 198 // along the height of the bounding box of the boxes in boxes is y% | 198 // along the height of the bounding box of the boxes in boxes is y% |
| 199 // of the way across the height of the video's rendering area, while | 199 // of the way across the height of the video's rendering area, while |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 214 void VTTCueBox::trace(Visitor* visitor) | 214 void VTTCueBox::trace(Visitor* visitor) |
| 215 { | 215 { |
| 216 visitor->trace(m_cue); | 216 visitor->trace(m_cue); |
| 217 HTMLDivElement::trace(visitor); | 217 HTMLDivElement::trace(visitor); |
| 218 } | 218 } |
| 219 | 219 |
| 220 VTTCue::VTTCue(Document& document, double startTime, double endTime, const Strin g& text) | 220 VTTCue::VTTCue(Document& document, double startTime, double endTime, const Strin g& text) |
| 221 : TextTrackCue(startTime, endTime) | 221 : TextTrackCue(startTime, endTime) |
| 222 , m_text(text) | 222 , m_text(text) |
| 223 , m_linePosition(std::numeric_limits<float>::quiet_NaN()) | 223 , m_linePosition(std::numeric_limits<float>::quiet_NaN()) |
| 224 , m_computedLinePosition(std::numeric_limits<float>::quiet_NaN()) | |
| 225 , m_textPosition(std::numeric_limits<float>::quiet_NaN()) | 224 , m_textPosition(std::numeric_limits<float>::quiet_NaN()) |
| 226 , m_cueSize(100) | 225 , m_cueSize(100) |
| 227 , m_writingDirection(Horizontal) | 226 , m_writingDirection(Horizontal) |
| 228 , m_cueAlignment(Middle) | 227 , m_cueAlignment(Middle) |
| 229 , m_vttNodeTree(nullptr) | 228 , m_vttNodeTree(nullptr) |
| 230 , m_cueBackgroundBox(HTMLDivElement::create(document)) | 229 , m_cueBackgroundBox(HTMLDivElement::create(document)) |
| 231 , m_displayDirection(CSSValueLtr) | |
| 232 , m_displaySize(std::numeric_limits<float>::quiet_NaN()) | |
| 233 , m_snapToLines(true) | 230 , m_snapToLines(true) |
| 234 , m_displayTreeShouldChange(true) | 231 , m_displayTreeShouldChange(true) |
| 235 , m_notifyRegion(true) | 232 , m_notifyRegion(true) |
| 236 { | 233 { |
| 237 UseCounter::count(document, UseCounter::VTTCue); | 234 UseCounter::count(document, UseCounter::VTTCue); |
| 238 } | 235 } |
| 239 | 236 |
| 240 VTTCue::~VTTCue() | 237 VTTCue::~VTTCue() |
| 241 { | 238 { |
| 242 // Using oilpan, if m_displayTree is in the document it will strongly keep | 239 // Using oilpan, if m_displayTree is in the document it will strongly keep |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 floatPosition = std::numeric_limits<float>::quiet_NaN(); | 345 floatPosition = std::numeric_limits<float>::quiet_NaN(); |
| 349 } else { | 346 } else { |
| 350 ASSERT(position.isDouble()); | 347 ASSERT(position.isDouble()); |
| 351 floatPosition = narrowPrecisionToFloat(position.getAsDouble()); | 348 floatPosition = narrowPrecisionToFloat(position.getAsDouble()); |
| 352 if (m_linePosition == floatPosition) | 349 if (m_linePosition == floatPosition) |
| 353 return; | 350 return; |
| 354 } | 351 } |
| 355 | 352 |
| 356 cueWillChange(); | 353 cueWillChange(); |
| 357 m_linePosition = floatPosition; | 354 m_linePosition = floatPosition; |
| 358 m_computedLinePosition = calculateComputedLinePosition(); | |
| 359 cueDidChange(); | 355 cueDidChange(); |
| 360 } | 356 } |
| 361 | 357 |
| 362 bool VTTCue::textPositionIsAuto() const | 358 bool VTTCue::textPositionIsAuto() const |
| 363 { | 359 { |
| 364 return std::isnan(m_textPosition); | 360 return std::isnan(m_textPosition); |
| 365 } | 361 } |
| 366 | 362 |
| 367 void VTTCue::position(DoubleOrAutoKeyword& result) const | 363 void VTTCue::position(DoubleOrAutoKeyword& result) const |
| 368 { | 364 { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 cueWillChange(); | 518 cueWillChange(); |
| 523 m_regionId = regionId; | 519 m_regionId = regionId; |
| 524 cueDidChange(); | 520 cueDidChange(); |
| 525 } | 521 } |
| 526 | 522 |
| 527 void VTTCue::notifyRegionWhenRemovingDisplayTree(bool notifyRegion) | 523 void VTTCue::notifyRegionWhenRemovingDisplayTree(bool notifyRegion) |
| 528 { | 524 { |
| 529 m_notifyRegion = notifyRegion; | 525 m_notifyRegion = notifyRegion; |
| 530 } | 526 } |
| 531 | 527 |
| 532 float VTTCue::calculateComputedLinePosition() | 528 float VTTCue::calculateComputedLinePosition() const |
| 533 { | 529 { |
| 534 // http://dev.w3.org/html5/webvtt/#dfn-text-track-cue-computed-line-position | 530 // http://dev.w3.org/html5/webvtt/#dfn-text-track-cue-computed-line-position |
| 535 // A text track cue has a text track cue computed line position whose value | 531 // A text track cue has a text track cue computed line position whose value |
| 536 // is that returned by the following algorithm, which is defined in terms | 532 // is that returned by the following algorithm, which is defined in terms |
| 537 // of the other aspects of the cue: | 533 // of the other aspects of the cue: |
| 538 | 534 |
| 539 // 1. If the text track cue line position is numeric, the text track cue | 535 // 1. If the text track cue line position is numeric, the text track cue |
| 540 // snap-to-lines flag of the text track cue is not set, and the text | 536 // snap-to-lines flag of the text track cue is not set, and the text |
| 541 // track cue line position is negative or greater than 100, then return | 537 // track cue line position is negative or greater than 100, then return |
| 542 // 100 and abort these steps. | 538 // 100 and abort these steps. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 switch (m_cueAlignment) { | 658 switch (m_cueAlignment) { |
| 663 case VTTCue::Left: | 659 case VTTCue::Left: |
| 664 return VTTCue::Start; | 660 return VTTCue::Start; |
| 665 case VTTCue::Right: | 661 case VTTCue::Right: |
| 666 return VTTCue::End; | 662 return VTTCue::End; |
| 667 default: | 663 default: |
| 668 return m_cueAlignment; | 664 return m_cueAlignment; |
| 669 } | 665 } |
| 670 } | 666 } |
| 671 | 667 |
| 672 void VTTCue::calculateDisplayParameters() | 668 VTTDisplayParameters::VTTDisplayParameters() |
| 669 : size(std::numeric_limits<float>::quiet_NaN()) | |
| 670 , direction(CSSValueNone) | |
| 671 , writingMode(CSSValueNone) { } | |
| 672 | |
| 673 VTTDisplayParameters VTTCue::calculateDisplayParameters() const | |
| 673 { | 674 { |
| 674 createVTTNodeTree(); | |
| 675 | |
| 676 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings | 675 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings |
| 677 | 676 |
| 677 VTTDisplayParameters displayParameters; | |
| 678 // Steps 1 and 2. | 678 // Steps 1 and 2. |
| 679 m_displayDirection = determineTextDirection(m_vttNodeTree.get()); | 679 displayParameters.direction = determineTextDirection(m_vttNodeTree.get()); |
| 680 | 680 |
| 681 if (m_displayDirection == CSSValueRtl) | 681 if (displayParameters.direction == CSSValueRtl) |
| 682 UseCounter::count(document(), UseCounter::VTTCueRenderRtl); | 682 UseCounter::count(document(), UseCounter::VTTCueRenderRtl); |
| 683 | 683 |
| 684 // 3. If the text track cue writing direction is horizontal, then let | 684 // 3. If the text track cue writing direction is horizontal, then let |
| 685 // 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 |
| 686 // 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 |
| 687 // 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 |
| 688 // 'rl'. | 688 // 'rl'. |
| 689 | 689 displayParameters.writingMode = displayWritingModeMap[m_writingDirection]; |
| 690 // The above step is done through the writing direction static map. | |
| 691 | 690 |
| 692 // Resolve the cue alignment to one of the values {start, end, middle}. | 691 // Resolve the cue alignment to one of the values {start, end, middle}. |
| 693 CueAlignment computedCueAlignment = calculateComputedCueAlignment(); | 692 CueAlignment computedCueAlignment = calculateComputedCueAlignment(); |
| 694 | 693 |
| 695 // 4. Determine the value of maximum size for cue as per the appropriate | 694 // 4. Determine the value of maximum size for cue as per the appropriate |
| 696 // rules from the following list: | 695 // rules from the following list: |
| 697 float computedTextPosition = calculateComputedTextPosition(); | 696 float computedTextPosition = calculateComputedTextPosition(); |
| 698 float maximumSize = computedTextPosition; | 697 float maximumSize = computedTextPosition; |
| 699 if (computedCueAlignment == Start) { | 698 if (computedCueAlignment == Start) { |
| 700 maximumSize = 100 - computedTextPosition; | 699 maximumSize = 100 - computedTextPosition; |
| 701 } else if (computedCueAlignment == End) { | 700 } else if (computedCueAlignment == End) { |
| 702 maximumSize = computedTextPosition; | 701 maximumSize = computedTextPosition; |
| 703 } else if (computedCueAlignment == Middle) { | 702 } else if (computedCueAlignment == Middle) { |
| 704 maximumSize = computedTextPosition <= 50 ? computedTextPosition : (100 - computedTextPosition); | 703 maximumSize = computedTextPosition <= 50 ? computedTextPosition : (100 - computedTextPosition); |
| 705 maximumSize = maximumSize * 2; | 704 maximumSize = maximumSize * 2; |
| 706 } else { | 705 } else { |
| 707 ASSERT_NOT_REACHED(); | 706 ASSERT_NOT_REACHED(); |
| 708 } | 707 } |
| 709 | 708 |
| 710 // 5. If the text track cue size is less than maximum size, then let size | 709 // 5. If the text track cue size is less than maximum size, then let size |
| 711 // be text track cue size. Otherwise, let size be maximum size. | 710 // be text track cue size. Otherwise, let size be maximum size. |
| 712 m_displaySize = std::min(m_cueSize, maximumSize); | 711 displayParameters.size = std::min(m_cueSize, maximumSize); |
| 713 | 712 |
| 714 // 6. If the text track cue writing direction is horizontal, then let width | 713 // 6. If the text track cue writing direction is horizontal, then let width |
| 715 // be 'size vw' and height be 'auto'. Otherwise, let width be 'auto' and | 714 // 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 | 715 // 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.) | 716 // set CSS properties for the rendering; 'vw' and 'vh' are CSS units.) |
| 718 // (Emulated in VTTCueBox::applyCSSProperties.) | 717 // (Emulated in VTTCueBox::applyCSSProperties.) |
| 719 | 718 |
| 720 // 7. Determine the value of x-position or y-position for cue as per the | 719 // 7. Determine the value of x-position or y-position for cue as per the |
| 721 // appropriate rules from the following list: | 720 // appropriate rules from the following list: |
| 722 if (m_writingDirection == Horizontal) { | 721 if (m_writingDirection == Horizontal) { |
| 723 switch (computedCueAlignment) { | 722 switch (computedCueAlignment) { |
| 724 case Start: | 723 case Start: |
| 725 m_displayPosition.setX(computedTextPosition); | 724 displayParameters.position.setX(computedTextPosition); |
| 726 break; | 725 break; |
| 727 case End: | 726 case End: |
| 728 m_displayPosition.setX(computedTextPosition - m_displaySize); | 727 displayParameters.position.setX(computedTextPosition - displayParame ters.size); |
| 729 break; | 728 break; |
| 730 case Middle: | 729 case Middle: |
| 731 m_displayPosition.setX(computedTextPosition - m_displaySize / 2); | 730 displayParameters.position.setX(computedTextPosition - displayParame ters.size / 2); |
| 732 break; | 731 break; |
| 733 default: | 732 default: |
| 734 ASSERT_NOT_REACHED(); | 733 ASSERT_NOT_REACHED(); |
| 735 } | 734 } |
| 736 } else { | 735 } else { |
| 737 // Cases for m_writingDirection being VerticalGrowing{Left|Right} | 736 // Cases for m_writingDirection being VerticalGrowing{Left|Right} |
| 738 switch (computedCueAlignment) { | 737 switch (computedCueAlignment) { |
| 739 case Start: | 738 case Start: |
| 740 m_displayPosition.setY(computedTextPosition); | 739 displayParameters.position.setY(computedTextPosition); |
| 741 break; | 740 break; |
| 742 case End: | 741 case End: |
| 743 m_displayPosition.setY(computedTextPosition - m_displaySize); | 742 displayParameters.position.setY(computedTextPosition - displayParame ters.size); |
| 744 break; | 743 break; |
| 745 case Middle: | 744 case Middle: |
| 746 m_displayPosition.setY(computedTextPosition - m_displaySize / 2); | 745 displayParameters.position.setY(computedTextPosition - displayParame ters.size / 2); |
| 747 break; | 746 break; |
| 748 default: | 747 default: |
| 749 ASSERT_NOT_REACHED(); | 748 ASSERT_NOT_REACHED(); |
| 750 } | 749 } |
| 751 } | 750 } |
| 752 | 751 |
| 753 // A text track cue has a text track cue computed line position whose value | 752 // A text track cue has a text track cue computed line position whose value |
| 754 // is defined in terms of the other aspects of the cue. | 753 // is defined in terms of the other aspects of the cue. |
| 755 m_computedLinePosition = calculateComputedLinePosition(); | 754 float computedLinePosition = calculateComputedLinePosition(); |
| 756 | 755 |
| 757 // 8. Determine the value of whichever of x-position or y-position is not | 756 // 8. Determine the value of whichever of x-position or y-position is not |
| 758 // yet calculated for cue as per the appropriate rules from the following | 757 // yet calculated for cue as per the appropriate rules from the following |
| 759 // list: | 758 // list: |
| 760 if (!m_snapToLines) { | 759 if (!m_snapToLines) { |
| 761 if (m_writingDirection == Horizontal) | 760 if (m_writingDirection == Horizontal) |
| 762 m_displayPosition.setY(m_computedLinePosition); | 761 displayParameters.position.setY(computedLinePosition); |
| 763 else | 762 else |
| 764 m_displayPosition.setX(m_computedLinePosition); | 763 displayParameters.position.setX(computedLinePosition); |
| 765 } else { | 764 } else { |
| 766 if (m_writingDirection == Horizontal) | 765 if (m_writingDirection == Horizontal) |
| 767 m_displayPosition.setY(0); | 766 displayParameters.position.setY(0); |
| 768 else | 767 else |
| 769 m_displayPosition.setX(0); | 768 displayParameters.position.setX(0); |
| 770 } | 769 } |
| 770 | |
| 771 // FIXME: Remove this block. | |
|
fs
2015/01/22 17:43:21
Kept this block (from getPositionCoordinates) arou
philipj_slow
2015/01/26 03:00:16
Acknowledged.
| |
| 772 if (!m_snapToLines) { | |
| 773 if (m_writingDirection == Horizontal && displayParameters.direction == C SSValueLtr) | |
| 774 displayParameters.position.setX(computedTextPosition); | |
| 775 | |
| 776 if (m_writingDirection == Horizontal && displayParameters.direction == C SSValueRtl) | |
| 777 displayParameters.position.setX(100 - computedTextPosition); | |
| 778 | |
| 779 if (m_writingDirection == VerticalGrowingLeft) | |
| 780 displayParameters.position = FloatPoint(100 - computedLinePosition, computedTextPosition); | |
| 781 | |
| 782 if (m_writingDirection == VerticalGrowingRight) | |
| 783 displayParameters.position.setY(computedTextPosition); | |
| 784 } | |
| 785 | |
| 786 // Step 9 not implemented (margin == 0). | |
| 787 | |
| 788 ASSERT(std::isfinite(displayParameters.size)); | |
| 789 ASSERT(displayParameters.direction != CSSValueNone); | |
| 790 ASSERT(displayParameters.writingMode != CSSValueNone); | |
| 791 return displayParameters; | |
| 771 } | 792 } |
| 772 | 793 |
| 773 void VTTCue::markFutureAndPastNodes(ContainerNode* root, double previousTimestam p, double movieTime) | 794 void VTTCue::markFutureAndPastNodes(ContainerNode* root, double previousTimestam p, double movieTime) |
| 774 { | 795 { |
| 775 DEFINE_STATIC_LOCAL(const String, timestampTag, ("timestamp")); | 796 DEFINE_STATIC_LOCAL(const String, timestampTag, ("timestamp")); |
| 776 | 797 |
| 777 bool isPastNode = true; | 798 bool isPastNode = true; |
| 778 double currentTimestamp = previousTimestamp; | 799 double currentTimestamp = previousTimestamp; |
| 779 if (currentTimestamp > movieTime) | 800 if (currentTimestamp > movieTime) |
| 780 isPastNode = false; | 801 isPastNode = false; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 808 | 829 |
| 809 // Clear the contents of the set. | 830 // Clear the contents of the set. |
| 810 m_cueBackgroundBox->removeChildren(); | 831 m_cueBackgroundBox->removeChildren(); |
| 811 | 832 |
| 812 // Update the two sets containing past and future WebVTT objects. | 833 // Update the two sets containing past and future WebVTT objects. |
| 813 RefPtrWillBeRawPtr<DocumentFragment> referenceTree = createCueRenderingTree( ); | 834 RefPtrWillBeRawPtr<DocumentFragment> referenceTree = createCueRenderingTree( ); |
| 814 markFutureAndPastNodes(referenceTree.get(), startTime(), movieTime); | 835 markFutureAndPastNodes(referenceTree.get(), startTime(), movieTime); |
| 815 m_cueBackgroundBox->appendChild(referenceTree, ASSERT_NO_EXCEPTION); | 836 m_cueBackgroundBox->appendChild(referenceTree, ASSERT_NO_EXCEPTION); |
| 816 } | 837 } |
| 817 | 838 |
| 818 PassRefPtrWillBeRawPtr<VTTCueBox> VTTCue::getDisplayTree(const IntSize& videoSiz e) | 839 PassRefPtrWillBeRawPtr<VTTCueBox> VTTCue::getDisplayTree() |
| 819 { | 840 { |
| 820 RefPtrWillBeRawPtr<VTTCueBox> displayTree(ensureDisplayTree()); | 841 RefPtrWillBeRawPtr<VTTCueBox> displayTree(ensureDisplayTree()); |
| 821 if (!m_displayTreeShouldChange || !track()->isRendered()) | 842 if (!m_displayTreeShouldChange || !track()->isRendered()) |
| 822 return displayTree.release(); | 843 return displayTree.release(); |
| 823 | 844 |
| 845 createVTTNodeTree(); | |
| 846 | |
| 824 // 10.1 - 10.10 | 847 // 10.1 - 10.10 |
| 825 calculateDisplayParameters(); | 848 VTTDisplayParameters displayParameters = calculateDisplayParameters(); |
| 826 | 849 |
| 827 // 10.11. Apply the terms of the CSS specifications to nodes within the | 850 // 10.11. Apply the terms of the CSS specifications to nodes within the |
| 828 // following constraints, thus obtaining a set of CSS boxes positioned | 851 // following constraints, thus obtaining a set of CSS boxes positioned |
| 829 // relative to an initial containing block: | 852 // relative to an initial containing block: |
| 830 displayTree->removeChildren(); | 853 displayTree->removeChildren(); |
| 831 | 854 |
| 832 // The document tree is the tree of WebVTT Node Objects rooted at nodes. | 855 // The document tree is the tree of WebVTT Node Objects rooted at nodes. |
| 833 | 856 |
| 834 // The children of the nodes must be wrapped in an anonymous box whose | 857 // The children of the nodes must be wrapped in an anonymous box whose |
| 835 // 'display' property has the value 'inline'. This is the WebVTT cue | 858 // 'display' property has the value 'inline'. This is the WebVTT cue |
| 836 // background box. | 859 // background box. |
| 837 | 860 |
| 838 // Note: This is contained by default in m_cueBackgroundBox. | 861 // Note: This is contained by default in m_cueBackgroundBox. |
| 839 m_cueBackgroundBox->setShadowPseudoId(cueShadowPseudoId()); | 862 m_cueBackgroundBox->setShadowPseudoId(cueShadowPseudoId()); |
| 840 displayTree->appendChild(m_cueBackgroundBox); | 863 displayTree->appendChild(m_cueBackgroundBox); |
| 841 | 864 |
| 842 // FIXME(BUG 79916): Runs of children of WebVTT Ruby Objects that are not | 865 // FIXME(BUG 79916): Runs of children of WebVTT Ruby Objects that are not |
| 843 // WebVTT Ruby Text Objects must be wrapped in anonymous boxes whose | 866 // WebVTT Ruby Text Objects must be wrapped in anonymous boxes whose |
| 844 // 'display' property has the value 'ruby-base'. | 867 // 'display' property has the value 'ruby-base'. |
| 845 | 868 |
| 846 // FIXME(BUG 79916): Text runs must be wrapped according to the CSS | 869 // FIXME(BUG 79916): Text runs must be wrapped according to the CSS |
| 847 // line-wrapping rules, except that additionally, regardless of the value of | 870 // line-wrapping rules, except that additionally, regardless of the value of |
| 848 // the 'white-space' property, lines must be wrapped at the edge of their | 871 // the 'white-space' property, lines must be wrapped at the edge of their |
| 849 // containing blocks, even if doing so requires splitting a word where there | 872 // containing blocks, even if doing so requires splitting a word where there |
| 850 // is no line breaking opportunity. (Thus, normally text wraps as needed, | 873 // is no line breaking opportunity. (Thus, normally text wraps as needed, |
| 851 // but if there is a particularly long word, it does not overflow as it | 874 // but if there is a particularly long word, it does not overflow as it |
| 852 // normally would in CSS, it is instead forcibly wrapped at the box's edge.) | 875 // normally would in CSS, it is instead forcibly wrapped at the box's edge.) |
| 853 displayTree->applyCSSProperties(videoSize); | 876 displayTree->applyCSSProperties(displayParameters); |
| 854 | 877 |
| 855 m_displayTreeShouldChange = false; | 878 m_displayTreeShouldChange = false; |
| 856 | 879 |
| 857 // 10.15. Let cue's text track cue display state have the CSS boxes in | 880 // 10.15. Let cue's text track cue display state have the CSS boxes in |
| 858 // boxes. | 881 // boxes. |
| 859 return displayTree.release(); | 882 return displayTree.release(); |
| 860 } | 883 } |
| 861 | 884 |
| 862 void VTTCue::removeDisplayTree() | 885 void VTTCue::removeDisplayTree() |
| 863 { | 886 { |
| 864 if (m_notifyRegion && track()->regions()) { | 887 if (m_notifyRegion && track()->regions()) { |
| 865 // The region needs to be informed about the cue removal. | 888 // The region needs to be informed about the cue removal. |
| 866 VTTRegion* region = track()->regions()->getRegionById(m_regionId); | 889 VTTRegion* region = track()->regions()->getRegionById(m_regionId); |
| 867 if (region) | 890 if (region) |
| 868 region->willRemoveVTTCueBox(m_displayTree.get()); | 891 region->willRemoveVTTCueBox(m_displayTree.get()); |
| 869 } | 892 } |
| 870 | 893 |
| 871 if (m_displayTree) | 894 if (m_displayTree) |
| 872 m_displayTree->remove(ASSERT_NO_EXCEPTION); | 895 m_displayTree->remove(ASSERT_NO_EXCEPTION); |
| 873 } | 896 } |
| 874 | 897 |
| 875 void VTTCue::updateDisplay(const IntSize& videoSize, HTMLDivElement& container) | 898 void VTTCue::updateDisplay(HTMLDivElement& container) |
| 876 { | 899 { |
| 877 UseCounter::count(document(), UseCounter::VTTCueRender); | 900 UseCounter::count(document(), UseCounter::VTTCueRender); |
| 878 | 901 |
| 879 if (m_writingDirection != Horizontal) | 902 if (m_writingDirection != Horizontal) |
| 880 UseCounter::count(document(), UseCounter::VTTCueRenderVertical); | 903 UseCounter::count(document(), UseCounter::VTTCueRenderVertical); |
| 881 | 904 |
| 882 if (!m_snapToLines) | 905 if (!m_snapToLines) |
| 883 UseCounter::count(document(), UseCounter::VTTCueRenderSnapToLinesFalse); | 906 UseCounter::count(document(), UseCounter::VTTCueRenderSnapToLinesFalse); |
| 884 | 907 |
| 885 if (!lineIsAuto()) | 908 if (!lineIsAuto()) |
| 886 UseCounter::count(document(), UseCounter::VTTCueRenderLineNotAuto); | 909 UseCounter::count(document(), UseCounter::VTTCueRenderLineNotAuto); |
| 887 | 910 |
| 888 if (textPositionIsAuto()) | 911 if (textPositionIsAuto()) |
| 889 UseCounter::count(document(), UseCounter::VTTCueRenderPositionNot50); | 912 UseCounter::count(document(), UseCounter::VTTCueRenderPositionNot50); |
| 890 | 913 |
| 891 if (m_cueSize != 100) | 914 if (m_cueSize != 100) |
| 892 UseCounter::count(document(), UseCounter::VTTCueRenderSizeNot100); | 915 UseCounter::count(document(), UseCounter::VTTCueRenderSizeNot100); |
| 893 | 916 |
| 894 if (m_cueAlignment != Middle) | 917 if (m_cueAlignment != Middle) |
| 895 UseCounter::count(document(), UseCounter::VTTCueRenderAlignNotMiddle); | 918 UseCounter::count(document(), UseCounter::VTTCueRenderAlignNotMiddle); |
| 896 | 919 |
| 897 RefPtrWillBeRawPtr<VTTCueBox> displayBox = getDisplayTree(videoSize); | 920 RefPtrWillBeRawPtr<VTTCueBox> displayBox = getDisplayTree(); |
| 898 VTTRegion* region = 0; | 921 VTTRegion* region = 0; |
| 899 if (track()->regions()) | 922 if (track()->regions()) |
| 900 region = track()->regions()->getRegionById(regionId()); | 923 region = track()->regions()->getRegionById(regionId()); |
| 901 | 924 |
| 902 if (!region) { | 925 if (!region) { |
| 903 // If cue has an empty text track cue region identifier or there is no | 926 // If cue has an empty text track cue region identifier or there is no |
| 904 // WebVTT region whose region identifier is identical to cue's text | 927 // WebVTT region whose region identifier is identical to cue's text |
| 905 // track cue region identifier, run the following substeps: | 928 // track cue region identifier, run the following substeps: |
| 906 if (displayBox->hasChildren() && !container.contains(displayBox.get())) { | 929 if (displayBox->hasChildren() && !container.contains(displayBox.get())) { |
| 907 // Note: the display tree of a cue is removed when the active flag o f the cue is unset. | 930 // Note: the display tree of a cue is removed when the active flag o f the cue is unset. |
| 908 container.appendChild(displayBox); | 931 container.appendChild(displayBox); |
| 909 } | 932 } |
| 910 } else { | 933 } else { |
| 911 // Let region be the WebVTT region whose region identifier | 934 // Let region be the WebVTT region whose region identifier |
| 912 // matches the text track cue region identifier of cue. | 935 // matches the text track cue region identifier of cue. |
| 913 RefPtrWillBeRawPtr<HTMLDivElement> regionNode = region->getDisplayTree(d ocument()); | 936 RefPtrWillBeRawPtr<HTMLDivElement> regionNode = region->getDisplayTree(d ocument()); |
| 914 | 937 |
| 915 // Append the region to the viewport, if it was not already. | 938 // Append the region to the viewport, if it was not already. |
| 916 if (!container.contains(regionNode.get())) | 939 if (!container.contains(regionNode.get())) |
| 917 container.appendChild(regionNode); | 940 container.appendChild(regionNode); |
| 918 | 941 |
| 919 region->appendVTTCueBox(displayBox); | 942 region->appendVTTCueBox(displayBox); |
| 920 } | 943 } |
| 921 } | 944 } |
| 922 | 945 |
| 923 FloatPoint VTTCue::getPositionCoordinates() const | 946 VTTCue::CueSetting VTTCue::settingName(VTTScanner& input) const |
| 924 { | |
| 925 // This method is used for setting x and y when snap to lines is not set. | |
| 926 ASSERT(std::isfinite(m_computedLinePosition)); | |
| 927 float computedTextPosition = calculateComputedTextPosition(); | |
| 928 | |
| 929 if (m_writingDirection == Horizontal && m_displayDirection == CSSValueLtr) | |
| 930 return FloatPoint(computedTextPosition, m_computedLinePosition); | |
| 931 | |
| 932 if (m_writingDirection == Horizontal && m_displayDirection == CSSValueRtl) | |
| 933 return FloatPoint(100 - computedTextPosition, m_computedLinePosition); | |
| 934 | |
| 935 if (m_writingDirection == VerticalGrowingLeft) | |
| 936 return FloatPoint(100 - m_computedLinePosition, computedTextPosition); | |
| 937 | |
| 938 if (m_writingDirection == VerticalGrowingRight) | |
| 939 return FloatPoint(m_computedLinePosition, computedTextPosition); | |
| 940 | |
| 941 ASSERT_NOT_REACHED(); | |
| 942 return FloatPoint(); | |
| 943 } | |
| 944 | |
| 945 VTTCue::CueSetting VTTCue::settingName(VTTScanner& input) | |
| 946 { | 947 { |
| 947 CueSetting parsedSetting = None; | 948 CueSetting parsedSetting = None; |
| 948 if (input.scan("vertical")) | 949 if (input.scan("vertical")) |
| 949 parsedSetting = Vertical; | 950 parsedSetting = Vertical; |
| 950 else if (input.scan("line")) | 951 else if (input.scan("line")) |
| 951 parsedSetting = Line; | 952 parsedSetting = Line; |
| 952 else if (input.scan("position")) | 953 else if (input.scan("position")) |
| 953 parsedSetting = Position; | 954 parsedSetting = Position; |
| 954 else if (input.scan("size")) | 955 else if (input.scan("size")) |
| 955 parsedSetting = Size; | 956 parsedSetting = Size; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1139 // If cue's line position is not auto or cue's size is not 100 or cue's | 1140 // If cue's line position is not auto or cue's size is not 100 or cue's |
| 1140 // writing direction is not horizontal, but cue's region identifier is not | 1141 // writing direction is not horizontal, but cue's region identifier is not |
| 1141 // the empty string, let cue's region identifier be the empty string. | 1142 // the empty string, let cue's region identifier be the empty string. |
| 1142 if (m_regionId.isEmpty()) | 1143 if (m_regionId.isEmpty()) |
| 1143 return; | 1144 return; |
| 1144 | 1145 |
| 1145 if (!lineIsAuto() || m_cueSize != 100 || m_writingDirection != Horizontal) | 1146 if (!lineIsAuto() || m_cueSize != 100 || m_writingDirection != Horizontal) |
| 1146 m_regionId = emptyString(); | 1147 m_regionId = emptyString(); |
| 1147 } | 1148 } |
| 1148 | 1149 |
| 1149 CSSValueID VTTCue::getCSSAlignment() const | |
| 1150 { | |
| 1151 return displayAlignmentMap[m_cueAlignment]; | |
| 1152 } | |
| 1153 | |
| 1154 CSSValueID VTTCue::getCSSWritingDirection() const | |
| 1155 { | |
| 1156 return m_displayDirection; | |
| 1157 } | |
| 1158 | |
| 1159 CSSValueID VTTCue::getCSSWritingMode() const | |
| 1160 { | |
| 1161 return displayWritingModeMap[m_writingDirection]; | |
| 1162 } | |
| 1163 | |
| 1164 float VTTCue::getCSSSize() const | |
| 1165 { | |
| 1166 ASSERT(std::isfinite(m_displaySize)); | |
| 1167 return m_displaySize; | |
| 1168 } | |
| 1169 | |
| 1170 FloatPoint VTTCue::getCSSPosition() const | |
| 1171 { | |
| 1172 if (!m_snapToLines) | |
| 1173 return getPositionCoordinates(); | |
| 1174 | |
| 1175 return m_displayPosition; | |
| 1176 } | |
| 1177 | |
| 1178 ExecutionContext* VTTCue::executionContext() const | 1150 ExecutionContext* VTTCue::executionContext() const |
| 1179 { | 1151 { |
| 1180 ASSERT(m_cueBackgroundBox); | 1152 ASSERT(m_cueBackgroundBox); |
| 1181 return m_cueBackgroundBox->executionContext(); | 1153 return m_cueBackgroundBox->executionContext(); |
| 1182 } | 1154 } |
| 1183 | 1155 |
| 1184 Document& VTTCue::document() const | 1156 Document& VTTCue::document() const |
| 1185 { | 1157 { |
| 1186 ASSERT(m_cueBackgroundBox); | 1158 ASSERT(m_cueBackgroundBox); |
| 1187 return m_cueBackgroundBox->document(); | 1159 return m_cueBackgroundBox->document(); |
| 1188 } | 1160 } |
| 1189 | 1161 |
| 1190 void VTTCue::trace(Visitor* visitor) | 1162 void VTTCue::trace(Visitor* visitor) |
| 1191 { | 1163 { |
| 1192 visitor->trace(m_vttNodeTree); | 1164 visitor->trace(m_vttNodeTree); |
| 1193 visitor->trace(m_cueBackgroundBox); | 1165 visitor->trace(m_cueBackgroundBox); |
| 1194 visitor->trace(m_displayTree); | 1166 visitor->trace(m_displayTree); |
| 1195 TextTrackCue::trace(visitor); | 1167 TextTrackCue::trace(visitor); |
| 1196 } | 1168 } |
| 1197 | 1169 |
| 1198 } // namespace blink | 1170 } // namespace blink |
| OLD | NEW |