Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: third_party/WebKit/Source/core/html/track/vtt/VTTParser.cpp

Issue 2393633005: reflow comments in core/imagebitmap,core/html/track (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 collectMetadataHeader(line); 136 collectMetadataHeader(line);
137 137
138 if (line.isEmpty()) { 138 if (line.isEmpty()) {
139 if (m_client && m_regionList.size()) 139 if (m_client && m_regionList.size())
140 m_client->newRegionsParsed(); 140 m_client->newRegionsParsed();
141 141
142 m_state = Id; 142 m_state = Id;
143 break; 143 break;
144 } 144 }
145 145
146 // Step 15 - Break out of header loop if the line could be a timestamp l ine. 146 // Step 15 - Break out of header loop if the line could be a timestamp
147 // line.
147 if (line.contains("-->")) 148 if (line.contains("-->"))
148 m_state = recoverCue(line); 149 m_state = recoverCue(line);
149 150
150 // Step 16 - Line is not the empty string and does not contain "-->". 151 // Step 16 - Line is not the empty string and does not contain "-->".
151 break; 152 break;
152 153
153 case Id: 154 case Id:
154 // Steps 17 - 20 - Allow any number of line terminators, then initialize new cue values. 155 // Steps 17 - 20 - Allow any number of line terminators, then initialize
156 // new cue values.
155 if (line.isEmpty()) 157 if (line.isEmpty())
156 break; 158 break;
157 159
158 // Step 21 - Cue creation (start a new cue). 160 // Step 21 - Cue creation (start a new cue).
159 resetCueValues(); 161 resetCueValues();
160 162
161 // Steps 22 - 25 - Check if this line contains an optional identifier or timing data. 163 // Steps 22 - 25 - Check if this line contains an optional identifier or
164 // timing data.
162 m_state = collectCueId(line); 165 m_state = collectCueId(line);
163 break; 166 break;
164 167
165 case TimingsAndSettings: 168 case TimingsAndSettings:
166 // Steps 26 - 27 - Discard current cue if the line is empty. 169 // Steps 26 - 27 - Discard current cue if the line is empty.
167 if (line.isEmpty()) { 170 if (line.isEmpty()) {
168 m_state = Id; 171 m_state = Id;
169 break; 172 break;
170 } 173 }
171 174
172 // Steps 28 - 29 - Collect cue timings and settings. 175 // Steps 28 - 29 - Collect cue timings and settings.
173 m_state = collectTimingsAndSettings(line); 176 m_state = collectTimingsAndSettings(line);
174 break; 177 break;
175 178
176 case CueText: 179 case CueText:
177 // Steps 31 - 41 - Collect the cue text, create a cue, and add it to the output. 180 // Steps 31 - 41 - Collect the cue text, create a cue, and add it to the
181 // output.
178 m_state = collectCueText(line); 182 m_state = collectCueText(line);
179 break; 183 break;
180 184
181 case BadCue: 185 case BadCue:
182 // Steps 42 - 48 - Discard lines until an empty line or a potential timi ng line is seen. 186 // Steps 42 - 48 - Discard lines until an empty line or a potential
187 // timing line is seen.
183 m_state = ignoreBadCue(line); 188 m_state = ignoreBadCue(line);
184 break; 189 break;
185 } 190 }
186 } 191 }
187 } 192 }
188 193
189 void VTTParser::flushPendingCue() { 194 void VTTParser::flushPendingCue() {
190 DCHECK(m_lineReader.isAtEndOfStream()); 195 DCHECK(m_lineReader.isAtEndOfStream());
191 // If we're in the CueText state when we run out of data, we emit the pending cue. 196 // If we're in the CueText state when we run out of data, we emit the pending
197 // cue.
192 if (m_state == CueText) 198 if (m_state == CueText)
193 createNewCue(); 199 createNewCue();
194 } 200 }
195 201
196 bool VTTParser::hasRequiredFileIdentifier(const String& line) { 202 bool VTTParser::hasRequiredFileIdentifier(const String& line) {
197 // WebVTT parser algorithm step 6: 203 // WebVTT parser algorithm step 6:
198 // If input is more than six characters long but the first six characters 204 // If input is more than six characters long but the first six characters
199 // do not exactly equal "WEBVTT", or the seventh character is not a U+0020 205 // do not exactly equal "WEBVTT", or the seventh character is not a U+0020
200 // SPACE character, a U+0009 CHARACTER TABULATION (tab) character, or a 206 // SPACE character, a U+0009 CHARACTER TABULATION (tab) character, or a
201 // U+000A LINE FEED (LF) character, then abort these steps. 207 // U+000A LINE FEED (LF) character, then abort these steps.
(...skipping 11 matching lines...) Expand all
213 } 219 }
214 220
215 void VTTParser::collectMetadataHeader(const String& line) { 221 void VTTParser::collectMetadataHeader(const String& line) {
216 // WebVTT header parsing (WebVTT parser algorithm step 12) 222 // WebVTT header parsing (WebVTT parser algorithm step 12)
217 DEFINE_STATIC_LOCAL(const AtomicString, regionHeaderName, ("Region")); 223 DEFINE_STATIC_LOCAL(const AtomicString, regionHeaderName, ("Region"));
218 224
219 // The only currently supported header is the "Region" header. 225 // The only currently supported header is the "Region" header.
220 if (!RuntimeEnabledFeatures::webVTTRegionsEnabled()) 226 if (!RuntimeEnabledFeatures::webVTTRegionsEnabled())
221 return; 227 return;
222 228
223 // Step 12.4 If line contains the character ":" (A U+003A COLON), then set met adata's 229 // Step 12.4 If line contains the character ":" (A U+003A COLON), then set
224 // name to the substring of line before the first ":" character and 230 // metadata's name to the substring of line before the first ":" character and
225 // metadata's value to the substring after this character. 231 // metadata's value to the substring after this character.
226 size_t colonPosition = line.find(':'); 232 size_t colonPosition = line.find(':');
227 if (colonPosition == kNotFound) 233 if (colonPosition == kNotFound)
228 return; 234 return;
229 235
230 String headerName = line.substring(0, colonPosition); 236 String headerName = line.substring(0, colonPosition);
231 237
232 // Steps 12.5 If metadata's name equals "Region": 238 // Steps 12.5 If metadata's name equals "Region":
233 if (headerName == regionHeaderName) { 239 if (headerName == regionHeaderName) {
234 String headerValue = line.substring(colonPosition + 1); 240 String headerValue = line.substring(colonPosition + 1);
235 // Steps 12.5.1 - 12.5.11 Region creation: Let region be a new text track re gion [...] 241 // Steps 12.5.1 - 12.5.11 Region creation: Let region be a new text track
242 // region [...]
236 createNewRegion(headerValue); 243 createNewRegion(headerValue);
237 } 244 }
238 } 245 }
239 246
240 VTTParser::ParseState VTTParser::collectCueId(const String& line) { 247 VTTParser::ParseState VTTParser::collectCueId(const String& line) {
241 if (line.contains("-->")) 248 if (line.contains("-->"))
242 return collectTimingsAndSettings(line); 249 return collectTimingsAndSettings(line);
243 m_currentId = AtomicString(line); 250 m_currentId = AtomicString(line);
244 return TimingsAndSettings; 251 return TimingsAndSettings;
245 } 252 }
246 253
247 VTTParser::ParseState VTTParser::collectTimingsAndSettings(const String& line) { 254 VTTParser::ParseState VTTParser::collectTimingsAndSettings(const String& line) {
248 VTTScanner input(line); 255 VTTScanner input(line);
249 256
250 // Collect WebVTT cue timings and settings. (5.3 WebVTT cue timings and settin gs parsing.) 257 // Collect WebVTT cue timings and settings. (5.3 WebVTT cue timings and
251 // Steps 1 - 3 - Let input be the string being parsed and position be a pointe r into input. 258 // settings parsing.)
259 // Steps 1 - 3 - Let input be the string being parsed and position be a
260 // pointer into input.
252 input.skipWhile<isASpace>(); 261 input.skipWhile<isASpace>();
253 262
254 // Steps 4 - 5 - Collect a WebVTT timestamp. If that fails, then abort and ret urn failure. Otherwise, let cue's text track cue start time be the collected tim e. 263 // Steps 4 - 5 - Collect a WebVTT timestamp. If that fails, then abort and
264 // return failure. Otherwise, let cue's text track cue start time be the
265 // collected time.
255 if (!collectTimeStamp(input, m_currentStartTime)) 266 if (!collectTimeStamp(input, m_currentStartTime))
256 return BadCue; 267 return BadCue;
257 input.skipWhile<isASpace>(); 268 input.skipWhile<isASpace>();
258 269
259 // Steps 6 - 9 - If the next three characters are not "-->", abort and return failure. 270 // Steps 6 - 9 - If the next three characters are not "-->", abort and return
271 // failure.
260 if (!input.scan("-->")) 272 if (!input.scan("-->"))
261 return BadCue; 273 return BadCue;
262 input.skipWhile<isASpace>(); 274 input.skipWhile<isASpace>();
263 275
264 // Steps 10 - 11 - Collect a WebVTT timestamp. If that fails, then abort and r eturn failure. Otherwise, let cue's text track cue end time be the collected tim e. 276 // Steps 10 - 11 - Collect a WebVTT timestamp. If that fails, then abort and
277 // return failure. Otherwise, let cue's text track cue end time be the
278 // collected time.
265 if (!collectTimeStamp(input, m_currentEndTime)) 279 if (!collectTimeStamp(input, m_currentEndTime))
266 return BadCue; 280 return BadCue;
267 input.skipWhile<isASpace>(); 281 input.skipWhile<isASpace>();
268 282
269 // Step 12 - Parse the WebVTT settings for the cue (conducted in TextTrackCue) . 283 // Step 12 - Parse the WebVTT settings for the cue (conducted in
284 // TextTrackCue).
270 m_currentSettings = input.restOfInputAsString(); 285 m_currentSettings = input.restOfInputAsString();
271 return CueText; 286 return CueText;
272 } 287 }
273 288
274 VTTParser::ParseState VTTParser::collectCueText(const String& line) { 289 VTTParser::ParseState VTTParser::collectCueText(const String& line) {
275 // Step 34. 290 // Step 34.
276 if (line.isEmpty()) { 291 if (line.isEmpty()) {
277 createNewCue(); 292 createNewCue();
278 return Id; 293 return Id;
279 } 294 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 425
411 // Steps 5 - 7 - Collect a sequence of characters that are 0-9. 426 // Steps 5 - 7 - Collect a sequence of characters that are 0-9.
412 // If not 2 characters or value is greater than 59, interpret as hours. 427 // If not 2 characters or value is greater than 59, interpret as hours.
413 int value1; 428 int value1;
414 unsigned value1Digits = input.scanDigits(value1); 429 unsigned value1Digits = input.scanDigits(value1);
415 if (!value1Digits) 430 if (!value1Digits)
416 return false; 431 return false;
417 if (value1Digits != 2 || value1 > 59) 432 if (value1Digits != 2 || value1 > 59)
418 mode = Hours; 433 mode = Hours;
419 434
420 // Steps 8 - 11 - Collect the next sequence of 0-9 after ':' (must be 2 chars) . 435 // Steps 8 - 11 - Collect the next sequence of 0-9 after ':' (must be 2
436 // chars).
421 int value2; 437 int value2;
422 if (!input.scan(':') || input.scanDigits(value2) != 2) 438 if (!input.scan(':') || input.scanDigits(value2) != 2)
423 return false; 439 return false;
424 440
425 // Step 12 - Detect whether this timestamp includes hours. 441 // Step 12 - Detect whether this timestamp includes hours.
426 int value3; 442 int value3;
427 if (mode == Hours || input.match(':')) { 443 if (mode == Hours || input.match(':')) {
428 if (!input.scan(':') || input.scanDigits(value3) != 2) 444 if (!input.scan(':') || input.scanDigits(value3) != 2)
429 return false; 445 return false;
430 } else { 446 } else {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } 574 }
559 575
560 DEFINE_TRACE(VTTParser) { 576 DEFINE_TRACE(VTTParser) {
561 visitor->trace(m_document); 577 visitor->trace(m_document);
562 visitor->trace(m_client); 578 visitor->trace(m_client);
563 visitor->trace(m_cueList); 579 visitor->trace(m_cueList);
564 visitor->trace(m_regionList); 580 visitor->trace(m_regionList);
565 } 581 }
566 582
567 } // namespace blink 583 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/track/vtt/VTTParser.h ('k') | third_party/WebKit/Source/core/html/track/vtt/VTTRegion.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698