OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 "value", value, 0.0, ExceptionMessages::InclusiveBound, 100.0, | 79 "value", value, 0.0, ExceptionMessages::InclusiveBound, 100.0, |
80 ExceptionMessages::InclusiveBound)); | 80 ExceptionMessages::InclusiveBound)); |
81 return true; | 81 return true; |
82 } | 82 } |
83 return false; | 83 return false; |
84 } | 84 } |
85 | 85 |
86 VTTRegion::VTTRegion() | 86 VTTRegion::VTTRegion() |
87 : m_id(emptyString), | 87 : m_id(emptyString), |
88 m_width(defaultWidth), | 88 m_width(defaultWidth), |
89 m_heightInLines(defaultHeightInLines), | 89 m_lines(defaultHeightInLines), |
90 m_regionAnchor(FloatPoint(defaultAnchorPointX, defaultAnchorPointY)), | 90 m_regionAnchor(FloatPoint(defaultAnchorPointX, defaultAnchorPointY)), |
91 m_viewportAnchor(FloatPoint(defaultAnchorPointX, defaultAnchorPointY)), | 91 m_viewportAnchor(FloatPoint(defaultAnchorPointX, defaultAnchorPointY)), |
92 m_scroll(defaultScroll), | 92 m_scroll(defaultScroll), |
93 m_track(nullptr), | |
94 m_currentTop(0), | 93 m_currentTop(0), |
95 m_scrollTimer(this, &VTTRegion::scrollTimerFired) {} | 94 m_scrollTimer(this, &VTTRegion::scrollTimerFired) {} |
96 | 95 |
97 VTTRegion::~VTTRegion() {} | 96 VTTRegion::~VTTRegion() {} |
98 | 97 |
99 void VTTRegion::setTrack(TextTrack* track) { | |
100 m_track = track; | |
101 } | |
102 | |
103 void VTTRegion::setId(const String& id) { | 98 void VTTRegion::setId(const String& id) { |
104 m_id = id; | 99 m_id = id; |
105 } | 100 } |
106 | 101 |
107 void VTTRegion::setWidth(double value, ExceptionState& exceptionState) { | 102 void VTTRegion::setWidth(double value, ExceptionState& exceptionState) { |
108 if (isNonPercentage(value, "width", exceptionState)) | 103 if (isNonPercentage(value, "width", exceptionState)) |
109 return; | 104 return; |
110 | 105 |
111 m_width = value; | 106 m_width = value; |
112 } | 107 } |
113 | 108 |
114 void VTTRegion::setHeight(long value, ExceptionState& exceptionState) { | 109 void VTTRegion::setLines(long value, ExceptionState& exceptionState) { |
115 if (value < 0) { | 110 if (value < 0) { |
116 exceptionState.throwDOMException( | 111 exceptionState.throwDOMException( |
117 IndexSizeError, | 112 IndexSizeError, |
118 "The height provided (" + String::number(value) + ") is negative."); | 113 "The height provided (" + String::number(value) + ") is negative."); |
119 return; | 114 return; |
120 } | 115 } |
121 | 116 m_lines = value; |
122 m_heightInLines = value; | |
123 } | 117 } |
124 | 118 |
125 void VTTRegion::setRegionAnchorX(double value, ExceptionState& exceptionState) { | 119 void VTTRegion::setRegionAnchorX(double value, ExceptionState& exceptionState) { |
126 if (isNonPercentage(value, "regionAnchorX", exceptionState)) | 120 if (isNonPercentage(value, "regionAnchorX", exceptionState)) |
127 return; | 121 return; |
128 | 122 |
129 m_regionAnchor.setX(value); | 123 m_regionAnchor.setX(value); |
130 } | 124 } |
131 | 125 |
132 void VTTRegion::setRegionAnchorY(double value, ExceptionState& exceptionState) { | 126 void VTTRegion::setRegionAnchorY(double value, ExceptionState& exceptionState) { |
(...skipping 14 matching lines...) Expand all Loading... |
147 void VTTRegion::setViewportAnchorY(double value, | 141 void VTTRegion::setViewportAnchorY(double value, |
148 ExceptionState& exceptionState) { | 142 ExceptionState& exceptionState) { |
149 if (isNonPercentage(value, "viewportAnchorY", exceptionState)) | 143 if (isNonPercentage(value, "viewportAnchorY", exceptionState)) |
150 return; | 144 return; |
151 | 145 |
152 m_viewportAnchor.setY(value); | 146 m_viewportAnchor.setY(value); |
153 } | 147 } |
154 | 148 |
155 const AtomicString VTTRegion::scroll() const { | 149 const AtomicString VTTRegion::scroll() const { |
156 DEFINE_STATIC_LOCAL(const AtomicString, upScrollValueKeyword, ("up")); | 150 DEFINE_STATIC_LOCAL(const AtomicString, upScrollValueKeyword, ("up")); |
157 | 151 return m_scroll ? upScrollValueKeyword : emptyAtom; |
158 if (m_scroll) | |
159 return upScrollValueKeyword; | |
160 | |
161 return ""; | |
162 } | 152 } |
163 | 153 |
164 void VTTRegion::setScroll(const AtomicString& value, | 154 void VTTRegion::setScroll(const AtomicString& value) { |
165 ExceptionState& exceptionState) { | 155 DCHECK(value == "up" || value == emptyAtom); |
166 DEFINE_STATIC_LOCAL(const AtomicString, upScrollValueKeyword, ("up")); | 156 m_scroll = value != emptyAtom; |
167 | |
168 if (value != emptyString && value != upScrollValueKeyword) { | |
169 exceptionState.throwDOMException( | |
170 SyntaxError, "The value provided ('" + value + | |
171 "') is invalid. The 'scroll' property must be either " | |
172 "the empty string, or 'up'."); | |
173 return; | |
174 } | |
175 | |
176 m_scroll = value == upScrollValueKeyword; | |
177 } | 157 } |
178 | 158 |
179 void VTTRegion::updateParametersFromRegion(VTTRegion* region) { | 159 void VTTRegion::updateParametersFromRegion(VTTRegion* region) { |
180 m_heightInLines = region->height(); | 160 m_lines = region->lines(); |
181 m_width = region->width(); | 161 m_width = region->width(); |
182 | 162 |
183 m_regionAnchor = FloatPoint(region->regionAnchorX(), region->regionAnchorY()); | 163 m_regionAnchor = FloatPoint(region->regionAnchorX(), region->regionAnchorY()); |
184 m_viewportAnchor = | 164 m_viewportAnchor = |
185 FloatPoint(region->viewportAnchorX(), region->viewportAnchorY()); | 165 FloatPoint(region->viewportAnchorX(), region->viewportAnchorY()); |
186 | 166 |
187 setScroll(region->scroll(), ASSERT_NO_EXCEPTION); | 167 setScroll(region->scroll()); |
188 } | 168 } |
189 | 169 |
190 void VTTRegion::setRegionSettings(const String& inputString) { | 170 void VTTRegion::setRegionSettings(const String& inputString) { |
191 m_settings = inputString; | 171 m_settings = inputString; |
192 | 172 |
193 VTTScanner input(inputString); | 173 VTTScanner input(inputString); |
194 | 174 |
195 while (!input.isAtEnd()) { | 175 while (!input.isAtEnd()) { |
196 input.skipWhile<VTTParser::isValidSettingDelimiter>(); | 176 input.skipWhile<VTTParser::isValidSettingDelimiter>(); |
197 | 177 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 if (VTTParser::parseFloatPercentageValue(input, floatWidth) && | 231 if (VTTParser::parseFloatPercentageValue(input, floatWidth) && |
252 parsedEntireRun(input, valueRun)) | 232 parsedEntireRun(input, valueRun)) |
253 m_width = floatWidth; | 233 m_width = floatWidth; |
254 else | 234 else |
255 DVLOG(VTT_LOG_LEVEL) << "parseSettingValue, invalid Width"; | 235 DVLOG(VTT_LOG_LEVEL) << "parseSettingValue, invalid Width"; |
256 break; | 236 break; |
257 } | 237 } |
258 case Height: { | 238 case Height: { |
259 int number; | 239 int number; |
260 if (input.scanDigits(number) && parsedEntireRun(input, valueRun)) | 240 if (input.scanDigits(number) && parsedEntireRun(input, valueRun)) |
261 m_heightInLines = number; | 241 m_lines = number; |
262 else | 242 else |
263 DVLOG(VTT_LOG_LEVEL) << "parseSettingValue, invalid Height"; | 243 DVLOG(VTT_LOG_LEVEL) << "parseSettingValue, invalid Height"; |
264 break; | 244 break; |
265 } | 245 } |
266 case RegionAnchor: { | 246 case RegionAnchor: { |
267 FloatPoint anchor; | 247 FloatPoint anchor; |
268 if (VTTParser::parseFloatPercentageValuePair(input, ',', anchor) && | 248 if (VTTParser::parseFloatPercentageValuePair(input, ',', anchor) && |
269 parsedEntireRun(input, valueRun)) | 249 parsedEntireRun(input, valueRun)) |
270 m_regionAnchor = anchor; | 250 m_regionAnchor = anchor; |
271 else | 251 else |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 // http://crbug/244618 is fixed. | 377 // http://crbug/244618 is fixed. |
398 | 378 |
399 // Let regionWidth be the text track region width. | 379 // Let regionWidth be the text track region width. |
400 // Let width be 'regionWidth vw' ('vw' is a CSS unit) | 380 // Let width be 'regionWidth vw' ('vw' is a CSS unit) |
401 m_regionDisplayTree->setInlineStyleProperty( | 381 m_regionDisplayTree->setInlineStyleProperty( |
402 CSSPropertyWidth, m_width, CSSPrimitiveValue::UnitType::Percentage); | 382 CSSPropertyWidth, m_width, CSSPrimitiveValue::UnitType::Percentage); |
403 | 383 |
404 // Let lineHeight be '0.0533vh' ('vh' is a CSS unit) and regionHeight be | 384 // Let lineHeight be '0.0533vh' ('vh' is a CSS unit) and regionHeight be |
405 // the text track region height. Let height be 'lineHeight' multiplied | 385 // the text track region height. Let height be 'lineHeight' multiplied |
406 // by regionHeight. | 386 // by regionHeight. |
407 double height = lineHeight * m_heightInLines; | 387 double height = lineHeight * m_lines; |
408 m_regionDisplayTree->setInlineStyleProperty( | 388 m_regionDisplayTree->setInlineStyleProperty( |
409 CSSPropertyHeight, height, CSSPrimitiveValue::UnitType::ViewportHeight); | 389 CSSPropertyHeight, height, CSSPrimitiveValue::UnitType::ViewportHeight); |
410 | 390 |
411 // Let viewportAnchorX be the x dimension of the text track region viewport | 391 // Let viewportAnchorX be the x dimension of the text track region viewport |
412 // anchor and regionAnchorX be the x dimension of the text track region | 392 // anchor and regionAnchorX be the x dimension of the text track region |
413 // anchor. Let leftOffset be regionAnchorX multiplied by width divided by | 393 // anchor. Let leftOffset be regionAnchorX multiplied by width divided by |
414 // 100.0. Let left be leftOffset subtracted from 'viewportAnchorX vw'. | 394 // 100.0. Let left be leftOffset subtracted from 'viewportAnchorX vw'. |
415 double leftOffset = m_regionAnchor.x() * m_width / 100; | 395 double leftOffset = m_regionAnchor.x() * m_width / 100; |
416 m_regionDisplayTree->setInlineStyleProperty( | 396 m_regionDisplayTree->setInlineStyleProperty( |
417 CSSPropertyLeft, m_viewportAnchor.x() - leftOffset, | 397 CSSPropertyLeft, m_viewportAnchor.x() - leftOffset, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 void VTTRegion::scrollTimerFired(TimerBase*) { | 437 void VTTRegion::scrollTimerFired(TimerBase*) { |
458 DVLOG(VTT_LOG_LEVEL) << "scrollTimerFired"; | 438 DVLOG(VTT_LOG_LEVEL) << "scrollTimerFired"; |
459 | 439 |
460 stopTimer(); | 440 stopTimer(); |
461 displayLastVTTCueBox(); | 441 displayLastVTTCueBox(); |
462 } | 442 } |
463 | 443 |
464 DEFINE_TRACE(VTTRegion) { | 444 DEFINE_TRACE(VTTRegion) { |
465 visitor->trace(m_cueContainer); | 445 visitor->trace(m_cueContainer); |
466 visitor->trace(m_regionDisplayTree); | 446 visitor->trace(m_regionDisplayTree); |
467 visitor->trace(m_track); | |
468 } | 447 } |
469 | 448 |
470 } // namespace blink | 449 } // namespace blink |
OLD | NEW |