OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 12 matching lines...) Expand all Loading... |
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 */ | 30 */ |
31 | 31 |
32 #include "config.h" | 32 #include "config.h" |
33 | |
34 #include "core/html/track/TextTrackCue.h" | 33 #include "core/html/track/TextTrackCue.h" |
35 | 34 |
36 #include "CSSPropertyNames.h" | 35 #include "CSSPropertyNames.h" |
37 #include "CSSValueKeywords.h" | 36 #include "CSSValueKeywords.h" |
| 37 #include "RuntimeEnabledFeatures.h" |
38 #include "bindings/v8/ExceptionStatePlaceholder.h" | 38 #include "bindings/v8/ExceptionStatePlaceholder.h" |
39 #include "core/dom/DocumentFragment.h" | 39 #include "core/dom/DocumentFragment.h" |
40 #include "core/events/Event.h" | 40 #include "core/events/Event.h" |
41 #include "core/dom/NodeTraversal.h" | 41 #include "core/dom/NodeTraversal.h" |
42 #include "core/html/HTMLDivElement.h" | 42 #include "core/html/HTMLDivElement.h" |
43 #include "core/html/track/TextTrack.h" | 43 #include "core/html/track/TextTrack.h" |
44 #include "core/html/track/TextTrackCueList.h" | 44 #include "core/html/track/TextTrackCueList.h" |
45 #include "core/html/track/TextTrackRegionList.h" | 45 #include "core/html/track/TextTrackRegionList.h" |
46 #include "core/html/track/WebVTTElement.h" | 46 #include "core/html/track/WebVTTElement.h" |
47 #include "core/html/track/WebVTTParser.h" | 47 #include "core/html/track/WebVTTParser.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 124 } |
125 | 125 |
126 TextTrackCue* TextTrackCueBox::getCue() const | 126 TextTrackCue* TextTrackCueBox::getCue() const |
127 { | 127 { |
128 return m_cue; | 128 return m_cue; |
129 } | 129 } |
130 | 130 |
131 void TextTrackCueBox::applyCSSProperties(const IntSize&) | 131 void TextTrackCueBox::applyCSSProperties(const IntSize&) |
132 { | 132 { |
133 // FIXME: Apply all the initial CSS positioning properties. http://wkb.ug/79
916 | 133 // FIXME: Apply all the initial CSS positioning properties. http://wkb.ug/79
916 |
134 #if ENABLE(WEBVTT_REGIONS) | |
135 if (!m_cue->regionId().isEmpty()) { | 134 if (!m_cue->regionId().isEmpty()) { |
136 setInlineStyleProperty(CSSPropertyPosition, CSSValueRelative); | 135 setInlineStyleProperty(CSSPropertyPosition, CSSValueRelative); |
137 return; | 136 return; |
138 } | 137 } |
139 #endif | |
140 | 138 |
141 // 3.5.1 On the (root) List of WebVTT Node Objects: | 139 // 3.5.1 On the (root) List of WebVTT Node Objects: |
142 | 140 |
143 // the 'position' property must be set to 'absolute' | 141 // the 'position' property must be set to 'absolute' |
144 setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute); | 142 setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute); |
145 | 143 |
146 // the 'unicode-bidi' property must be set to 'plaintext' | 144 // the 'unicode-bidi' property must be set to 'plaintext' |
147 setInlineStyleProperty(CSSPropertyUnicodeBidi, CSSValueWebkitPlaintext); | 145 setInlineStyleProperty(CSSPropertyUnicodeBidi, CSSValueWebkitPlaintext); |
148 | 146 |
149 // the 'direction' property must be set to direction | 147 // the 'direction' property must be set to direction |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 , m_cueAlignment(Middle) | 217 , m_cueAlignment(Middle) |
220 , m_webVTTNodeTree(0) | 218 , m_webVTTNodeTree(0) |
221 , m_track(0) | 219 , m_track(0) |
222 , m_executionContext(context) | 220 , m_executionContext(context) |
223 , m_isActive(false) | 221 , m_isActive(false) |
224 , m_pauseOnExit(false) | 222 , m_pauseOnExit(false) |
225 , m_snapToLines(true) | 223 , m_snapToLines(true) |
226 , m_cueBackgroundBox(HTMLDivElement::create(*toDocument(context))) | 224 , m_cueBackgroundBox(HTMLDivElement::create(*toDocument(context))) |
227 , m_displayTreeShouldChange(true) | 225 , m_displayTreeShouldChange(true) |
228 , m_displayDirection(CSSValueLtr) | 226 , m_displayDirection(CSSValueLtr) |
| 227 , m_notifyRegion(true) |
229 { | 228 { |
230 ASSERT(m_executionContext->isDocument()); | 229 ASSERT(m_executionContext->isDocument()); |
231 ScriptWrappable::init(this); | 230 ScriptWrappable::init(this); |
232 } | 231 } |
233 | 232 |
234 TextTrackCue::~TextTrackCue() | 233 TextTrackCue::~TextTrackCue() |
235 { | 234 { |
236 displayTreeInternal()->remove(ASSERT_NO_EXCEPTION); | 235 displayTreeInternal()->remove(ASSERT_NO_EXCEPTION); |
237 } | 236 } |
238 | 237 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 549 |
551 bool TextTrackCue::dispatchEvent(PassRefPtr<Event> event) | 550 bool TextTrackCue::dispatchEvent(PassRefPtr<Event> event) |
552 { | 551 { |
553 // When a TextTrack's mode is disabled: no cues are active, no events fired. | 552 // When a TextTrack's mode is disabled: no cues are active, no events fired. |
554 if (!track() || track()->mode() == TextTrack::disabledKeyword()) | 553 if (!track() || track()->mode() == TextTrack::disabledKeyword()) |
555 return false; | 554 return false; |
556 | 555 |
557 return EventTarget::dispatchEvent(event); | 556 return EventTarget::dispatchEvent(event); |
558 } | 557 } |
559 | 558 |
560 #if ENABLE(WEBVTT_REGIONS) | |
561 void TextTrackCue::setRegionId(const String& regionId) | 559 void TextTrackCue::setRegionId(const String& regionId) |
562 { | 560 { |
563 if (m_regionId == regionId) | 561 if (m_regionId == regionId) |
564 return; | 562 return; |
565 | 563 |
566 cueWillChange(); | 564 cueWillChange(); |
567 m_regionId = regionId; | 565 m_regionId = regionId; |
568 cueDidChange(); | 566 cueDidChange(); |
569 } | 567 } |
570 #endif | 568 |
| 569 void TextTrackCue::notifyRegionWhenRemovingDisplayTree(bool notifyRegion) |
| 570 { |
| 571 m_notifyRegion = notifyRegion; |
| 572 } |
571 | 573 |
572 bool TextTrackCue::isActive() | 574 bool TextTrackCue::isActive() |
573 { | 575 { |
574 return m_isActive && track() && track()->mode() != TextTrack::disabledKeywor
d(); | 576 return m_isActive && track() && track()->mode() != TextTrack::disabledKeywor
d(); |
575 } | 577 } |
576 | 578 |
577 void TextTrackCue::setIsActive(bool active) | 579 void TextTrackCue::setIsActive(bool active) |
578 { | 580 { |
579 m_isActive = active; | 581 m_isActive = active; |
580 | 582 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 | 872 |
871 m_displayTreeShouldChange = false; | 873 m_displayTreeShouldChange = false; |
872 | 874 |
873 // 10.15. Let cue's text track cue display state have the CSS boxes in | 875 // 10.15. Let cue's text track cue display state have the CSS boxes in |
874 // boxes. | 876 // boxes. |
875 return displayTree; | 877 return displayTree; |
876 } | 878 } |
877 | 879 |
878 void TextTrackCue::removeDisplayTree() | 880 void TextTrackCue::removeDisplayTree() |
879 { | 881 { |
880 #if ENABLE(WEBVTT_REGIONS) | 882 if (m_notifyRegion && m_track->regions()) { |
881 // The region needs to be informed about the cue removal. | 883 // The region needs to be informed about the cue removal. |
882 TextTrackRegion* region = m_track->regions()->getRegionById(m_regionId); | 884 TextTrackRegion* region = m_track->regions()->getRegionById(m_regionId); |
883 if (region) | 885 if (region) |
884 region->willRemoveTextTrackCueBox(m_displayTree.get()); | 886 region->willRemoveTextTrackCueBox(m_displayTree.get()); |
885 #endif | 887 } |
886 | 888 |
887 displayTreeInternal()->remove(ASSERT_NO_EXCEPTION); | 889 displayTreeInternal()->remove(ASSERT_NO_EXCEPTION); |
888 } | 890 } |
889 | 891 |
890 std::pair<double, double> TextTrackCue::getPositionCoordinates() const | 892 std::pair<double, double> TextTrackCue::getPositionCoordinates() const |
891 { | 893 { |
892 // This method is used for setting x and y when snap to lines is not set. | 894 // This method is used for setting x and y when snap to lines is not set. |
893 std::pair<double, double> coordinates; | 895 std::pair<double, double> coordinates; |
894 | 896 |
895 if (m_writingDirection == Horizontal && m_displayDirection == CSSValueLtr) { | 897 if (m_writingDirection == Horizontal && m_displayDirection == CSSValueLtr) { |
(...skipping 29 matching lines...) Expand all Loading... |
925 return coordinates; | 927 return coordinates; |
926 } | 928 } |
927 | 929 |
928 TextTrackCue::CueSetting TextTrackCue::settingName(const String& name) | 930 TextTrackCue::CueSetting TextTrackCue::settingName(const String& name) |
929 { | 931 { |
930 DEFINE_STATIC_LOCAL(const String, verticalKeyword, ("vertical")); | 932 DEFINE_STATIC_LOCAL(const String, verticalKeyword, ("vertical")); |
931 DEFINE_STATIC_LOCAL(const String, lineKeyword, ("line")); | 933 DEFINE_STATIC_LOCAL(const String, lineKeyword, ("line")); |
932 DEFINE_STATIC_LOCAL(const String, positionKeyword, ("position")); | 934 DEFINE_STATIC_LOCAL(const String, positionKeyword, ("position")); |
933 DEFINE_STATIC_LOCAL(const String, sizeKeyword, ("size")); | 935 DEFINE_STATIC_LOCAL(const String, sizeKeyword, ("size")); |
934 DEFINE_STATIC_LOCAL(const String, alignKeyword, ("align")); | 936 DEFINE_STATIC_LOCAL(const String, alignKeyword, ("align")); |
935 #if ENABLE(WEBVTT_REGIONS) | |
936 DEFINE_STATIC_LOCAL(const String, regionIdKeyword, ("region")); | 937 DEFINE_STATIC_LOCAL(const String, regionIdKeyword, ("region")); |
937 #endif | |
938 | 938 |
939 if (name == verticalKeyword) | 939 if (name == verticalKeyword) |
940 return Vertical; | 940 return Vertical; |
941 else if (name == lineKeyword) | 941 else if (name == lineKeyword) |
942 return Line; | 942 return Line; |
943 else if (name == positionKeyword) | 943 else if (name == positionKeyword) |
944 return Position; | 944 return Position; |
945 else if (name == sizeKeyword) | 945 else if (name == sizeKeyword) |
946 return Size; | 946 return Size; |
947 else if (name == alignKeyword) | 947 else if (name == alignKeyword) |
948 return Align; | 948 return Align; |
949 #if ENABLE(WEBVTT_REGIONS) | 949 else if (RuntimeEnabledFeatures::webVTTRegionsEnabled() && name == regionIdK
eyword) |
950 else if (name == regionIdKeyword) | |
951 return RegionId; | 950 return RegionId; |
952 #endif | |
953 | 951 |
954 return None; | 952 return None; |
955 } | 953 } |
956 | 954 |
957 void TextTrackCue::setCueSettings(const String& input) | 955 void TextTrackCue::setCueSettings(const String& input) |
958 { | 956 { |
959 m_settings = input; | 957 m_settings = input; |
960 unsigned position = 0; | 958 unsigned position = 0; |
961 | 959 |
962 while (position < input.length()) { | 960 while (position < input.length()) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 | 1142 |
1145 // 4. If value is a case-sensitive match for the string "left", then
let cue's text track cue alignment be left alignment. | 1143 // 4. If value is a case-sensitive match for the string "left", then
let cue's text track cue alignment be left alignment. |
1146 else if (cueAlignment == leftKeyword()) | 1144 else if (cueAlignment == leftKeyword()) |
1147 m_cueAlignment = Left; | 1145 m_cueAlignment = Left; |
1148 | 1146 |
1149 // 5. If value is a case-sensitive match for the string "right", the
n let cue's text track cue alignment be right alignment. | 1147 // 5. If value is a case-sensitive match for the string "right", the
n let cue's text track cue alignment be right alignment. |
1150 else if (cueAlignment == rightKeyword()) | 1148 else if (cueAlignment == rightKeyword()) |
1151 m_cueAlignment = Right; | 1149 m_cueAlignment = Right; |
1152 } | 1150 } |
1153 break; | 1151 break; |
1154 #if ENABLE(WEBVTT_REGIONS) | |
1155 case RegionId: | 1152 case RegionId: |
1156 m_regionId = WebVTTParser::collectWord(input, &position); | 1153 m_regionId = WebVTTParser::collectWord(input, &position); |
1157 break; | 1154 break; |
1158 #endif | |
1159 case None: | 1155 case None: |
1160 break; | 1156 break; |
1161 } | 1157 } |
1162 | 1158 |
1163 NextSetting: | 1159 NextSetting: |
1164 position = endOfSetting; | 1160 position = endOfSetting; |
1165 } | 1161 } |
1166 #if ENABLE(WEBVTT_REGIONS) | 1162 |
1167 // If cue's line position is not auto or cue's size is not 100 or cue's | 1163 // If cue's line position is not auto or cue's size is not 100 or cue's |
1168 // writing direction is not horizontal, but cue's region identifier is not | 1164 // writing direction is not horizontal, but cue's region identifier is not |
1169 // the empty string, let cue's region identifier be the empty string. | 1165 // the empty string, let cue's region identifier be the empty string. |
1170 if (m_regionId.isEmpty()) | 1166 if (m_regionId.isEmpty()) |
1171 return; | 1167 return; |
1172 | 1168 |
1173 if (m_linePosition != undefinedPosition || m_cueSize != 100 || m_writingDire
ction != Horizontal) | 1169 if (m_linePosition != undefinedPosition || m_cueSize != 100 || m_writingDire
ction != Horizontal) |
1174 m_regionId = emptyString(); | 1170 m_regionId = emptyString(); |
1175 #endif | |
1176 } | 1171 } |
1177 | 1172 |
1178 CSSValueID TextTrackCue::getCSSAlignment() const | 1173 CSSValueID TextTrackCue::getCSSAlignment() const |
1179 { | 1174 { |
1180 return displayAlignmentMap[m_cueAlignment]; | 1175 return displayAlignmentMap[m_cueAlignment]; |
1181 } | 1176 } |
1182 | 1177 |
1183 CSSValueID TextTrackCue::getCSSWritingDirection() const | 1178 CSSValueID TextTrackCue::getCSSWritingDirection() const |
1184 { | 1179 { |
1185 return m_displayDirection; | 1180 return m_displayDirection; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 return false; | 1229 return false; |
1235 if (m_cueSize != cue.size()) | 1230 if (m_cueSize != cue.size()) |
1236 return false; | 1231 return false; |
1237 if (align() != cue.align()) | 1232 if (align() != cue.align()) |
1238 return false; | 1233 return false; |
1239 | 1234 |
1240 return true; | 1235 return true; |
1241 } | 1236 } |
1242 | 1237 |
1243 } // namespace WebCore | 1238 } // namespace WebCore |
OLD | NEW |