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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 RefPtr<DocumentFragment> fragment = DocumentFragment::create(m_document); | 379 RefPtr<DocumentFragment> fragment = DocumentFragment::create(m_document); |
380 | 380 |
381 if (cueText.isEmpty()) { | 381 if (cueText.isEmpty()) { |
382 fragment->parserAppendChild(Text::create(m_document, "")); | 382 fragment->parserAppendChild(Text::create(m_document, "")); |
383 return fragment; | 383 return fragment; |
384 } | 384 } |
385 | 385 |
386 m_currentNode = fragment; | 386 m_currentNode = fragment; |
387 | 387 |
388 VTTTokenizer tokenizer(cueText); | 388 VTTTokenizer tokenizer(cueText); |
389 m_token.clear(); | |
390 m_languageStack.clear(); | 389 m_languageStack.clear(); |
391 | 390 |
392 while (tokenizer.nextToken(m_token)) | 391 while (tokenizer.nextToken(m_token)) |
393 constructTreeFromToken(m_document); | 392 constructTreeFromToken(m_document); |
394 | 393 |
395 return fragment.release(); | 394 return fragment.release(); |
396 } | 395 } |
397 | 396 |
398 PassRefPtr<DocumentFragment> VTTParser::createDocumentFragmentFromCueText(Docume
nt& document, const String& cueText) | 397 PassRefPtr<DocumentFragment> VTTParser::createDocumentFragmentFromCueText(Docume
nt& document, const String& cueText) |
399 { | 398 { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 } | 530 } |
532 return VTTNodeTypeNone; | 531 return VTTNodeTypeNone; |
533 } | 532 } |
534 | 533 |
535 void VTTTreeBuilder::constructTreeFromToken(Document& document) | 534 void VTTTreeBuilder::constructTreeFromToken(Document& document) |
536 { | 535 { |
537 // http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules | 536 // http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules |
538 | 537 |
539 switch (m_token.type()) { | 538 switch (m_token.type()) { |
540 case VTTTokenTypes::Character: { | 539 case VTTTokenTypes::Character: { |
541 String content = m_token.characters().toString(); | 540 RefPtr<Text> child = Text::create(document, m_token.characters()); |
542 RefPtr<Text> child = Text::create(document, content); | |
543 m_currentNode->parserAppendChild(child); | 541 m_currentNode->parserAppendChild(child); |
544 break; | 542 break; |
545 } | 543 } |
546 case VTTTokenTypes::StartTag: { | 544 case VTTTokenTypes::StartTag: { |
547 RefPtr<VTTElement> child; | 545 RefPtr<VTTElement> child; |
548 VTTNodeType nodeType = tokenToNodeType(m_token); | 546 VTTNodeType nodeType = tokenToNodeType(m_token); |
549 if (nodeType != VTTNodeTypeNone) | 547 if (nodeType != VTTNodeTypeNone) |
550 child = VTTElement::create(nodeType, &document); | 548 child = VTTElement::create(nodeType, &document); |
551 if (child) { | 549 if (child) { |
552 if (!m_token.classes().isEmpty()) | 550 if (!m_token.classes().isEmpty()) |
553 child->setAttribute(classAttr, m_token.classes().toAtomicString(
)); | 551 child->setAttribute(classAttr, m_token.classes()); |
554 | 552 |
555 if (child->webVTTNodeType() == VTTNodeTypeVoice) { | 553 if (child->webVTTNodeType() == VTTNodeTypeVoice) { |
556 child->setAttribute(VTTElement::voiceAttributeName(), m_token.an
notation().toAtomicString()); | 554 child->setAttribute(VTTElement::voiceAttributeName(), m_token.an
notation()); |
557 } else if (child->webVTTNodeType() == VTTNodeTypeLanguage) { | 555 } else if (child->webVTTNodeType() == VTTNodeTypeLanguage) { |
558 m_languageStack.append(m_token.annotation().toAtomicString()); | 556 m_languageStack.append(m_token.annotation()); |
559 child->setAttribute(VTTElement::langAttributeName(), m_languageS
tack.last()); | 557 child->setAttribute(VTTElement::langAttributeName(), m_languageS
tack.last()); |
560 } | 558 } |
561 if (!m_languageStack.isEmpty()) | 559 if (!m_languageStack.isEmpty()) |
562 child->setLanguage(m_languageStack.last()); | 560 child->setLanguage(m_languageStack.last()); |
563 m_currentNode->parserAppendChild(child); | 561 m_currentNode->parserAppendChild(child); |
564 m_currentNode = child; | 562 m_currentNode = child; |
565 } | 563 } |
566 break; | 564 break; |
567 } | 565 } |
568 case VTTTokenTypes::EndTag: { | 566 case VTTTokenTypes::EndTag: { |
569 VTTNodeType nodeType = tokenToNodeType(m_token); | 567 VTTNodeType nodeType = tokenToNodeType(m_token); |
570 if (nodeType != VTTNodeTypeNone) { | 568 if (nodeType != VTTNodeTypeNone) { |
571 if (nodeType == VTTNodeTypeLanguage && m_currentNode->isVTTElement()
&& toVTTElement(m_currentNode.get())->webVTTNodeType() == VTTNodeTypeLanguage) | 569 if (nodeType == VTTNodeTypeLanguage && m_currentNode->isVTTElement()
&& toVTTElement(m_currentNode.get())->webVTTNodeType() == VTTNodeTypeLanguage) |
572 m_languageStack.removeLast(); | 570 m_languageStack.removeLast(); |
573 if (m_currentNode->parentNode()) | 571 if (m_currentNode->parentNode()) |
574 m_currentNode = m_currentNode->parentNode(); | 572 m_currentNode = m_currentNode->parentNode(); |
575 } | 573 } |
576 break; | 574 break; |
577 } | 575 } |
578 case VTTTokenTypes::TimestampTag: { | 576 case VTTTokenTypes::TimestampTag: { |
579 unsigned position = 0; | 577 unsigned position = 0; |
580 String charactersString = m_token.characters().toString(); | 578 String charactersString = m_token.characters(); |
581 double time = VTTParser::collectTimeStamp(charactersString, &position); | 579 double time = VTTParser::collectTimeStamp(charactersString, &position); |
582 if (time != malformedTime) | 580 if (time != malformedTime) |
583 m_currentNode->parserAppendChild(ProcessingInstruction::create(docum
ent, "timestamp", charactersString)); | 581 m_currentNode->parserAppendChild(ProcessingInstruction::create(docum
ent, "timestamp", charactersString)); |
584 break; | 582 break; |
585 } | 583 } |
586 default: | 584 default: |
587 break; | 585 break; |
588 } | 586 } |
589 m_token.clear(); | |
590 } | 587 } |
591 | 588 |
592 void VTTParser::skipWhiteSpace(const String& line, unsigned* position) | 589 void VTTParser::skipWhiteSpace(const String& line, unsigned* position) |
593 { | 590 { |
594 while (*position < line.length() && isASpace(line[*position])) | 591 while (*position < line.length() && isASpace(line[*position])) |
595 (*position)++; | 592 (*position)++; |
596 } | 593 } |
597 | 594 |
598 } | 595 } |
599 | 596 |
OLD | NEW |