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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 return recoverCue(line); | 314 return recoverCue(line); |
315 return BadCue; | 315 return BadCue; |
316 } | 316 } |
317 | 317 |
318 // A helper class for the construction of a "cue fragment" from the cue text. | 318 // A helper class for the construction of a "cue fragment" from the cue text. |
319 class VTTTreeBuilder { | 319 class VTTTreeBuilder { |
320 public: | 320 public: |
321 VTTTreeBuilder(Document& document) | 321 VTTTreeBuilder(Document& document) |
322 : m_document(document) { } | 322 : m_document(document) { } |
323 | 323 |
324 PassRefPtrWillBeRawPtr<DocumentFragment> buildFromString(const String& cueTe
xt); | 324 PassRefPtr<DocumentFragment> buildFromString(const String& cueText); |
325 | 325 |
326 private: | 326 private: |
327 void constructTreeFromToken(Document&); | 327 void constructTreeFromToken(Document&); |
328 | 328 |
329 VTTToken m_token; | 329 VTTToken m_token; |
330 RefPtr<ContainerNode> m_currentNode; | 330 RefPtr<ContainerNode> m_currentNode; |
331 Vector<AtomicString> m_languageStack; | 331 Vector<AtomicString> m_languageStack; |
332 Document& m_document; | 332 Document& m_document; |
333 }; | 333 }; |
334 | 334 |
335 PassRefPtrWillBeRawPtr<DocumentFragment> VTTTreeBuilder::buildFromString(const S
tring& cueText) | 335 PassRefPtr<DocumentFragment> VTTTreeBuilder::buildFromString(const String& cueTe
xt) |
336 { | 336 { |
337 // Cue text processing based on | 337 // Cue text processing based on |
338 // 5.4 WebVTT cue text parsing rules, and | 338 // 5.4 WebVTT cue text parsing rules, and |
339 // 5.5 WebVTT cue text DOM construction rules | 339 // 5.5 WebVTT cue text DOM construction rules |
340 | 340 |
341 RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(m_d
ocument); | 341 RefPtr<DocumentFragment> fragment = DocumentFragment::create(m_document); |
342 | 342 |
343 if (cueText.isEmpty()) { | 343 if (cueText.isEmpty()) { |
344 fragment->parserAppendChild(Text::create(m_document, "")); | 344 fragment->parserAppendChild(Text::create(m_document, "")); |
345 return fragment; | 345 return fragment; |
346 } | 346 } |
347 | 347 |
348 m_currentNode = fragment; | 348 m_currentNode = fragment; |
349 | 349 |
350 VTTTokenizer tokenizer(cueText); | 350 VTTTokenizer tokenizer(cueText); |
351 m_languageStack.clear(); | 351 m_languageStack.clear(); |
352 | 352 |
353 while (tokenizer.nextToken(m_token)) | 353 while (tokenizer.nextToken(m_token)) |
354 constructTreeFromToken(m_document); | 354 constructTreeFromToken(m_document); |
355 | 355 |
356 return fragment.release(); | 356 return fragment.release(); |
357 } | 357 } |
358 | 358 |
359 PassRefPtrWillBeRawPtr<DocumentFragment> VTTParser::createDocumentFragmentFromCu
eText(Document& document, const String& cueText) | 359 PassRefPtr<DocumentFragment> VTTParser::createDocumentFragmentFromCueText(Docume
nt& document, const String& cueText) |
360 { | 360 { |
361 VTTTreeBuilder treeBuilder(document); | 361 VTTTreeBuilder treeBuilder(document); |
362 return treeBuilder.buildFromString(cueText); | 362 return treeBuilder.buildFromString(cueText); |
363 } | 363 } |
364 | 364 |
365 void VTTParser::createNewCue() | 365 void VTTParser::createNewCue() |
366 { | 366 { |
367 RefPtrWillBeRawPtr<VTTCue> cue = VTTCue::create(*m_document, m_currentStartT
ime, m_currentEndTime, m_currentContent.toString()); | 367 RefPtrWillBeRawPtr<VTTCue> cue = VTTCue::create(*m_document, m_currentStartT
ime, m_currentEndTime, m_currentContent.toString()); |
368 cue->setId(m_currentId); | 368 cue->setId(m_currentId); |
369 cue->parseSettings(m_currentSettings); | 369 cue->parseSettings(m_currentSettings); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 } | 557 } |
558 } | 558 } |
559 | 559 |
560 void VTTParser::trace(Visitor* visitor) | 560 void VTTParser::trace(Visitor* visitor) |
561 { | 561 { |
562 visitor->trace(m_cueList); | 562 visitor->trace(m_cueList); |
563 visitor->trace(m_regionList); | 563 visitor->trace(m_regionList); |
564 } | 564 } |
565 | 565 |
566 } | 566 } |
OLD | NEW |