OLD | NEW |
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 m_lineReader.append(textData); | 104 m_lineReader.append(textData); |
105 parse(); | 105 parse(); |
106 } | 106 } |
107 | 107 |
108 void VTTParser::flush() { | 108 void VTTParser::flush() { |
109 String textData = m_decoder->flush(); | 109 String textData = m_decoder->flush(); |
110 m_lineReader.append(textData); | 110 m_lineReader.append(textData); |
111 m_lineReader.setEndOfStream(); | 111 m_lineReader.setEndOfStream(); |
112 parse(); | 112 parse(); |
113 flushPendingCue(); | 113 flushPendingCue(); |
| 114 m_regionMap.clear(); |
114 } | 115 } |
115 | 116 |
116 void VTTParser::parse() { | 117 void VTTParser::parse() { |
117 // WebVTT parser algorithm. (5.1 WebVTT file parsing.) | 118 // WebVTT parser algorithm. (5.1 WebVTT file parsing.) |
118 // Steps 1 - 3 - Initial setup. | 119 // Steps 1 - 3 - Initial setup. |
119 | 120 |
120 String line; | 121 String line; |
121 while (m_lineReader.getLine(line)) { | 122 while (m_lineReader.getLine(line)) { |
122 switch (m_state) { | 123 switch (m_state) { |
123 case Initial: | 124 case Initial: |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 Document& document, | 370 Document& document, |
370 const String& cueText) { | 371 const String& cueText) { |
371 VTTTreeBuilder treeBuilder(document); | 372 VTTTreeBuilder treeBuilder(document); |
372 return treeBuilder.buildFromString(cueText); | 373 return treeBuilder.buildFromString(cueText); |
373 } | 374 } |
374 | 375 |
375 void VTTParser::createNewCue() { | 376 void VTTParser::createNewCue() { |
376 VTTCue* cue = VTTCue::create(*m_document, m_currentStartTime, | 377 VTTCue* cue = VTTCue::create(*m_document, m_currentStartTime, |
377 m_currentEndTime, m_currentContent.toString()); | 378 m_currentEndTime, m_currentContent.toString()); |
378 cue->setId(m_currentId); | 379 cue->setId(m_currentId); |
379 cue->parseSettings(m_currentSettings); | 380 cue->parseSettings(&m_regionMap, m_currentSettings); |
380 | 381 |
381 m_cueList.push_back(cue); | 382 m_cueList.push_back(cue); |
382 if (m_client) | 383 if (m_client) |
383 m_client->newCuesParsed(); | 384 m_client->newCuesParsed(); |
384 } | 385 } |
385 | 386 |
386 void VTTParser::resetCueValues() { | 387 void VTTParser::resetCueValues() { |
387 m_currentId = emptyAtom; | 388 m_currentId = emptyAtom; |
388 m_currentSettings = emptyString; | 389 m_currentSettings = emptyString; |
389 m_currentStartTime = 0; | 390 m_currentStartTime = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
403 // with the same region identifier value as region, remove that region. | 404 // with the same region identifier value as region, remove that region. |
404 for (size_t i = 0; i < m_regionList.size(); ++i) { | 405 for (size_t i = 0; i < m_regionList.size(); ++i) { |
405 if (m_regionList[i]->id() == region->id()) { | 406 if (m_regionList[i]->id() == region->id()) { |
406 m_regionList.remove(i); | 407 m_regionList.remove(i); |
407 break; | 408 break; |
408 } | 409 } |
409 } | 410 } |
410 | 411 |
411 // Step 12.5.11 | 412 // Step 12.5.11 |
412 m_regionList.push_back(region); | 413 m_regionList.push_back(region); |
| 414 |
| 415 if (region->id().isEmpty()) |
| 416 return; |
| 417 m_regionMap.set(region->id(), region); |
413 } | 418 } |
414 | 419 |
415 bool VTTParser::collectTimeStamp(const String& line, double& timeStamp) { | 420 bool VTTParser::collectTimeStamp(const String& line, double& timeStamp) { |
416 VTTScanner input(line); | 421 VTTScanner input(line); |
417 return collectTimeStamp(input, timeStamp); | 422 return collectTimeStamp(input, timeStamp); |
418 } | 423 } |
419 | 424 |
420 bool VTTParser::collectTimeStamp(VTTScanner& input, double& timeStamp) { | 425 bool VTTParser::collectTimeStamp(VTTScanner& input, double& timeStamp) { |
421 // Collect a WebVTT timestamp (5.3 WebVTT cue timings and settings parsing.) | 426 // Collect a WebVTT timestamp (5.3 WebVTT cue timings and settings parsing.) |
422 // Steps 1 - 4 - Initial checks, let most significant units be minutes. | 427 // Steps 1 - 4 - Initial checks, let most significant units be minutes. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 } | 575 } |
571 default: | 576 default: |
572 break; | 577 break; |
573 } | 578 } |
574 } | 579 } |
575 | 580 |
576 DEFINE_TRACE(VTTParser) { | 581 DEFINE_TRACE(VTTParser) { |
577 visitor->trace(m_document); | 582 visitor->trace(m_document); |
578 visitor->trace(m_client); | 583 visitor->trace(m_client); |
579 visitor->trace(m_cueList); | 584 visitor->trace(m_cueList); |
| 585 visitor->trace(m_regionMap); |
580 visitor->trace(m_regionList); | 586 visitor->trace(m_regionList); |
581 } | 587 } |
582 | 588 |
583 } // namespace blink | 589 } // namespace blink |
OLD | NEW |