| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 , m_textPosition(std::numeric_limits<float>::quiet_NaN()) | 224 , m_textPosition(std::numeric_limits<float>::quiet_NaN()) |
| 225 , m_cueSize(100) | 225 , m_cueSize(100) |
| 226 , m_writingDirection(Horizontal) | 226 , m_writingDirection(Horizontal) |
| 227 , m_cueAlignment(Middle) | 227 , m_cueAlignment(Middle) |
| 228 , m_vttNodeTree(nullptr) | 228 , m_vttNodeTree(nullptr) |
| 229 , m_cueBackgroundBox(HTMLDivElement::create(document)) | 229 , m_cueBackgroundBox(HTMLDivElement::create(document)) |
| 230 , m_snapToLines(true) | 230 , m_snapToLines(true) |
| 231 , m_displayTreeShouldChange(true) | 231 , m_displayTreeShouldChange(true) |
| 232 { | 232 { |
| 233 UseCounter::count(document, UseCounter::VTTCue); | 233 UseCounter::count(document, UseCounter::VTTCue); |
| 234 m_cueBackgroundBox->setShadowPseudoId(cueShadowPseudoId()); |
| 234 } | 235 } |
| 235 | 236 |
| 236 VTTCue::~VTTCue() | 237 VTTCue::~VTTCue() |
| 237 { | 238 { |
| 238 // 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 |
| 239 // the cue alive. Thus, if the cue is dead, either m_displayTree is not in | 240 // the cue alive. Thus, if the cue is dead, either m_displayTree is not in |
| 240 // the document or the entire document is dead too. | 241 // the document or the entire document is dead too. |
| 241 #if !ENABLE(OILPAN) | 242 #if !ENABLE(OILPAN) |
| 242 // FIXME: This is scary, we should make the life cycle smarter so the destru
ctor | 243 // FIXME: This is scary, we should make the life cycle smarter so the destru
ctor |
| 243 // doesn't need to do DOM mutations. | 244 // doesn't need to do DOM mutations. |
| 244 if (m_displayTree) | 245 if (m_displayTree) |
| 245 m_displayTree->remove(ASSERT_NO_EXCEPTION); | 246 m_displayTree->remove(ASSERT_NO_EXCEPTION); |
| 246 #endif | 247 #endif |
| 247 } | 248 } |
| 248 | 249 |
| 249 #ifndef NDEBUG | 250 #ifndef NDEBUG |
| 250 String VTTCue::toString() const | 251 String VTTCue::toString() const |
| 251 { | 252 { |
| 252 return String::format("%p id=%s interval=%f-->%f cue=%s)", this, id().utf8()
.data(), startTime(), endTime(), text().utf8().data()); | 253 return String::format("%p id=%s interval=%f-->%f cue=%s)", this, id().utf8()
.data(), startTime(), endTime(), text().utf8().data()); |
| 253 } | 254 } |
| 254 #endif | 255 #endif |
| 255 | 256 |
| 256 VTTCueBox& VTTCue::ensureDisplayTree() | |
| 257 { | |
| 258 if (!m_displayTree) | |
| 259 m_displayTree = VTTCueBox::create(document(), this); | |
| 260 return *m_displayTree; | |
| 261 } | |
| 262 | |
| 263 void VTTCue::cueDidChange() | 257 void VTTCue::cueDidChange() |
| 264 { | 258 { |
| 265 TextTrackCue::cueDidChange(); | 259 TextTrackCue::cueDidChange(); |
| 266 m_displayTreeShouldChange = true; | 260 m_displayTreeShouldChange = true; |
| 267 } | 261 } |
| 268 | 262 |
| 269 const String& VTTCue::vertical() const | 263 const String& VTTCue::vertical() const |
| 270 { | 264 { |
| 271 switch (m_writingDirection) { | 265 switch (m_writingDirection) { |
| 272 case Horizontal: | 266 case Horizontal: |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 // Update the two sets containing past and future WebVTT objects. | 786 // Update the two sets containing past and future WebVTT objects. |
| 793 createVTTNodeTree(); | 787 createVTTNodeTree(); |
| 794 RefPtrWillBeRawPtr<DocumentFragment> referenceTree = DocumentFragment::creat
e(document()); | 788 RefPtrWillBeRawPtr<DocumentFragment> referenceTree = DocumentFragment::creat
e(document()); |
| 795 m_vttNodeTree->cloneChildNodes(referenceTree.get()); | 789 m_vttNodeTree->cloneChildNodes(referenceTree.get()); |
| 796 markFutureAndPastNodes(referenceTree.get(), startTime(), movieTime); | 790 markFutureAndPastNodes(referenceTree.get(), startTime(), movieTime); |
| 797 m_cueBackgroundBox->appendChild(referenceTree, ASSERT_NO_EXCEPTION); | 791 m_cueBackgroundBox->appendChild(referenceTree, ASSERT_NO_EXCEPTION); |
| 798 } | 792 } |
| 799 | 793 |
| 800 PassRefPtrWillBeRawPtr<VTTCueBox> VTTCue::getDisplayTree() | 794 PassRefPtrWillBeRawPtr<VTTCueBox> VTTCue::getDisplayTree() |
| 801 { | 795 { |
| 802 RefPtrWillBeRawPtr<VTTCueBox> displayTree(ensureDisplayTree()); | 796 ASSERT(track() && track()->isRendered() && isActive()); |
| 803 if (!m_displayTreeShouldChange || !track()->isRendered()) | 797 |
| 804 return displayTree.release(); | 798 if (!m_displayTree) { |
| 799 m_displayTree = VTTCueBox::create(document(), this); |
| 800 m_displayTree->appendChild(m_cueBackgroundBox); |
| 801 } |
| 802 |
| 803 ASSERT(m_displayTree->firstChild() == m_cueBackgroundBox); |
| 804 |
| 805 // Note: It is updateDisplayTree() which actually adds the child |
| 806 // nodes to m_cueBackgroundBox. |
| 807 |
| 808 if (!m_displayTreeShouldChange) |
| 809 return m_displayTree; |
| 805 | 810 |
| 806 createVTTNodeTree(); | 811 createVTTNodeTree(); |
| 807 | |
| 808 // 10.1 - 10.10 | |
| 809 VTTDisplayParameters displayParameters = calculateDisplayParameters(); | 812 VTTDisplayParameters displayParameters = calculateDisplayParameters(); |
| 810 | 813 m_displayTree->applyCSSProperties(displayParameters); |
| 811 // 10.11. Apply the terms of the CSS specifications to nodes within the | |
| 812 // following constraints, thus obtaining a set of CSS boxes positioned | |
| 813 // relative to an initial containing block: | |
| 814 displayTree->removeChildren(); | |
| 815 | |
| 816 // The document tree is the tree of WebVTT Node Objects rooted at nodes. | |
| 817 | |
| 818 // The children of the nodes must be wrapped in an anonymous box whose | |
| 819 // 'display' property has the value 'inline'. This is the WebVTT cue | |
| 820 // background box. | |
| 821 | |
| 822 // Note: This is contained by default in m_cueBackgroundBox. | |
| 823 m_cueBackgroundBox->setShadowPseudoId(cueShadowPseudoId()); | |
| 824 displayTree->appendChild(m_cueBackgroundBox); | |
| 825 | |
| 826 // FIXME(BUG 79916): Runs of children of WebVTT Ruby Objects that are not | |
| 827 // WebVTT Ruby Text Objects must be wrapped in anonymous boxes whose | |
| 828 // 'display' property has the value 'ruby-base'. | |
| 829 | |
| 830 // FIXME(BUG 79916): Text runs must be wrapped according to the CSS | |
| 831 // line-wrapping rules, except that additionally, regardless of the value of | |
| 832 // the 'white-space' property, lines must be wrapped at the edge of their | |
| 833 // containing blocks, even if doing so requires splitting a word where there | |
| 834 // is no line breaking opportunity. (Thus, normally text wraps as needed, | |
| 835 // but if there is a particularly long word, it does not overflow as it | |
| 836 // normally would in CSS, it is instead forcibly wrapped at the box's edge.) | |
| 837 displayTree->applyCSSProperties(displayParameters); | |
| 838 | 814 |
| 839 m_displayTreeShouldChange = false; | 815 m_displayTreeShouldChange = false; |
| 840 | 816 |
| 841 // 10.15. Let cue's text track cue display state have the CSS boxes in | 817 return m_displayTree; |
| 842 // boxes. | |
| 843 return displayTree.release(); | |
| 844 } | 818 } |
| 845 | 819 |
| 846 void VTTCue::removeDisplayTree(RemovalNotification removalNotification) | 820 void VTTCue::removeDisplayTree(RemovalNotification removalNotification) |
| 847 { | 821 { |
| 848 if (removalNotification == NotifyRegion && track()->regions()) { | 822 if (removalNotification == NotifyRegion && track()->regions()) { |
| 849 // The region needs to be informed about the cue removal. | 823 // The region needs to be informed about the cue removal. |
| 850 VTTRegion* region = track()->regions()->getRegionById(m_regionId); | 824 VTTRegion* region = track()->regions()->getRegionById(m_regionId); |
| 851 if (region) | 825 if (region) |
| 852 region->willRemoveVTTCueBox(m_displayTree.get()); | 826 region->willRemoveVTTCueBox(m_displayTree.get()); |
| 853 } | 827 } |
| 854 | 828 |
| 855 if (m_displayTree) | 829 if (m_displayTree) |
| 856 m_displayTree->remove(ASSERT_NO_EXCEPTION); | 830 m_displayTree->remove(ASSERT_NO_EXCEPTION); |
| 857 } | 831 } |
| 858 | 832 |
| 859 void VTTCue::updateDisplay(HTMLDivElement& container) | 833 void VTTCue::updateDisplay(HTMLDivElement& container) |
| 860 { | 834 { |
| 835 ASSERT(track() && track()->isRendered() && isActive()); |
| 836 |
| 861 UseCounter::count(document(), UseCounter::VTTCueRender); | 837 UseCounter::count(document(), UseCounter::VTTCueRender); |
| 862 | 838 |
| 863 if (m_writingDirection != Horizontal) | 839 if (m_writingDirection != Horizontal) |
| 864 UseCounter::count(document(), UseCounter::VTTCueRenderVertical); | 840 UseCounter::count(document(), UseCounter::VTTCueRenderVertical); |
| 865 | 841 |
| 866 if (!m_snapToLines) | 842 if (!m_snapToLines) |
| 867 UseCounter::count(document(), UseCounter::VTTCueRenderSnapToLinesFalse); | 843 UseCounter::count(document(), UseCounter::VTTCueRenderSnapToLinesFalse); |
| 868 | 844 |
| 869 if (!lineIsAuto()) | 845 if (!lineIsAuto()) |
| 870 UseCounter::count(document(), UseCounter::VTTCueRenderLineNotAuto); | 846 UseCounter::count(document(), UseCounter::VTTCueRenderLineNotAuto); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 | 1098 |
| 1123 DEFINE_TRACE(VTTCue) | 1099 DEFINE_TRACE(VTTCue) |
| 1124 { | 1100 { |
| 1125 visitor->trace(m_vttNodeTree); | 1101 visitor->trace(m_vttNodeTree); |
| 1126 visitor->trace(m_cueBackgroundBox); | 1102 visitor->trace(m_cueBackgroundBox); |
| 1127 visitor->trace(m_displayTree); | 1103 visitor->trace(m_displayTree); |
| 1128 TextTrackCue::trace(visitor); | 1104 TextTrackCue::trace(visitor); |
| 1129 } | 1105 } |
| 1130 | 1106 |
| 1131 } // namespace blink | 1107 } // namespace blink |
| OLD | NEW |