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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 // 4.8.10.13.4 WebVTT cue text parsing rules and | 328 // 4.8.10.13.4 WebVTT cue text parsing rules and |
329 // 4.8.10.13.5 WebVTT cue text DOM construction rules. | 329 // 4.8.10.13.5 WebVTT cue text DOM construction rules. |
330 | 330 |
331 ASSERT(m_scriptExecutionContext->isDocument()); | 331 ASSERT(m_scriptExecutionContext->isDocument()); |
332 Document* document = toDocument(m_scriptExecutionContext); | 332 Document* document = toDocument(m_scriptExecutionContext); |
333 ASSERT(document); | 333 ASSERT(document); |
334 | 334 |
335 RefPtr<DocumentFragment> fragment = DocumentFragment::create(*document); | 335 RefPtr<DocumentFragment> fragment = DocumentFragment::create(*document); |
336 | 336 |
337 if (!text.length()) { | 337 if (!text.length()) { |
338 fragment->parserAppendChild(Text::create(document, "")); | 338 fragment->parserAppendChild(Text::create(*document, "")); |
339 return fragment; | 339 return fragment; |
340 } | 340 } |
341 | 341 |
342 m_currentNode = fragment; | 342 m_currentNode = fragment; |
343 m_tokenizer->reset(); | 343 m_tokenizer->reset(); |
344 m_token.clear(); | 344 m_token.clear(); |
345 | 345 |
346 m_languageStack.clear(); | 346 m_languageStack.clear(); |
347 SegmentedString content(text); | 347 SegmentedString content(text); |
348 while (m_tokenizer->nextToken(content, m_token)) | 348 while (m_tokenizer->nextToken(content, m_token)) |
349 constructTreeFromToken(document); | 349 constructTreeFromToken(*document); |
350 | 350 |
351 return fragment.release(); | 351 return fragment.release(); |
352 } | 352 } |
353 | 353 |
354 void WebVTTParser::createNewCue() | 354 void WebVTTParser::createNewCue() |
355 { | 355 { |
356 if (!m_currentContent.length()) | 356 if (!m_currentContent.length()) |
357 return; | 357 return; |
358 | 358 |
359 RefPtr<TextTrackCue> cue = TextTrackCue::create(m_scriptExecutionContext, m_
currentStartTime, m_currentEndTime, m_currentContent.toString()); | 359 RefPtr<TextTrackCue> cue = TextTrackCue::create(m_scriptExecutionContext, m_
currentStartTime, m_currentEndTime, m_currentContent.toString()); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 case 4: | 477 case 4: |
478 if (token.name()[0] == 'r' && token.name()[1] == 'u' && token.name()[2]
== 'b' && token.name()[3] == 'y') | 478 if (token.name()[0] == 'r' && token.name()[1] == 'u' && token.name()[2]
== 'b' && token.name()[3] == 'y') |
479 return WebVTTNodeTypeRuby; | 479 return WebVTTNodeTypeRuby; |
480 if (token.name()[0] == 'l' && token.name()[1] == 'a' && token.name()[2]
== 'n' && token.name()[3] == 'g') | 480 if (token.name()[0] == 'l' && token.name()[1] == 'a' && token.name()[2]
== 'n' && token.name()[3] == 'g') |
481 return WebVTTNodeTypeLanguage; | 481 return WebVTTNodeTypeLanguage; |
482 break; | 482 break; |
483 } | 483 } |
484 return WebVTTNodeTypeNone; | 484 return WebVTTNodeTypeNone; |
485 } | 485 } |
486 | 486 |
487 void WebVTTParser::constructTreeFromToken(Document* document) | 487 void WebVTTParser::constructTreeFromToken(Document& document) |
488 { | 488 { |
489 QualifiedName tagName(nullAtom, AtomicString(m_token.name()), xhtmlNamespace
URI); | 489 QualifiedName tagName(nullAtom, AtomicString(m_token.name()), xhtmlNamespace
URI); |
490 | 490 |
491 // http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules | 491 // http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules |
492 | 492 |
493 switch (m_token.type()) { | 493 switch (m_token.type()) { |
494 case WebVTTTokenTypes::Character: { | 494 case WebVTTTokenTypes::Character: { |
495 String content(m_token.characters()); // FIXME: This should be 8bit if p
ossible. | 495 String content(m_token.characters()); // FIXME: This should be 8bit if p
ossible. |
496 RefPtr<Text> child = Text::create(document, content); | 496 RefPtr<Text> child = Text::create(document, content); |
497 m_currentNode->parserAppendChild(child); | 497 m_currentNode->parserAppendChild(child); |
498 break; | 498 break; |
499 } | 499 } |
500 case WebVTTTokenTypes::StartTag: { | 500 case WebVTTTokenTypes::StartTag: { |
501 RefPtr<WebVTTElement> child; | 501 RefPtr<WebVTTElement> child; |
502 WebVTTNodeType nodeType = tokenToNodeType(m_token); | 502 WebVTTNodeType nodeType = tokenToNodeType(m_token); |
503 if (nodeType != WebVTTNodeTypeNone) | 503 if (nodeType != WebVTTNodeTypeNone) |
504 child = WebVTTElement::create(nodeType, document); | 504 child = WebVTTElement::create(nodeType, &document); |
505 if (child) { | 505 if (child) { |
506 if (m_token.classes().size() > 0) | 506 if (m_token.classes().size() > 0) |
507 child->setAttribute(classAttr, AtomicString(m_token.classes())); | 507 child->setAttribute(classAttr, AtomicString(m_token.classes())); |
508 | 508 |
509 if (child->webVTTNodeType() == WebVTTNodeTypeVoice) | 509 if (child->webVTTNodeType() == WebVTTNodeTypeVoice) |
510 child->setAttribute(WebVTTElement::voiceAttributeName(), AtomicS
tring(m_token.annotation())); | 510 child->setAttribute(WebVTTElement::voiceAttributeName(), AtomicS
tring(m_token.annotation())); |
511 else if (child->webVTTNodeType() == WebVTTNodeTypeLanguage) { | 511 else if (child->webVTTNodeType() == WebVTTNodeTypeLanguage) { |
512 m_languageStack.append(AtomicString(m_token.annotation())); | 512 m_languageStack.append(AtomicString(m_token.annotation())); |
513 child->setAttribute(WebVTTElement::langAttributeName(), m_langua
geStack.last()); | 513 child->setAttribute(WebVTTElement::langAttributeName(), m_langua
geStack.last()); |
514 } | 514 } |
(...skipping 12 matching lines...) Expand all Loading... |
527 if (m_currentNode->parentNode()) | 527 if (m_currentNode->parentNode()) |
528 m_currentNode = m_currentNode->parentNode(); | 528 m_currentNode = m_currentNode->parentNode(); |
529 } | 529 } |
530 break; | 530 break; |
531 } | 531 } |
532 case WebVTTTokenTypes::TimestampTag: { | 532 case WebVTTTokenTypes::TimestampTag: { |
533 unsigned position = 0; | 533 unsigned position = 0; |
534 String charactersString(StringImpl::create8BitIfPossible(m_token.charact
ers())); | 534 String charactersString(StringImpl::create8BitIfPossible(m_token.charact
ers())); |
535 double time = collectTimeStamp(charactersString, &position); | 535 double time = collectTimeStamp(charactersString, &position); |
536 if (time != malformedTime) | 536 if (time != malformedTime) |
537 m_currentNode->parserAppendChild(ProcessingInstruction::create(docum
ent, "timestamp", charactersString)); | 537 m_currentNode->parserAppendChild(ProcessingInstruction::create(&docu
ment, "timestamp", charactersString)); |
538 break; | 538 break; |
539 } | 539 } |
540 default: | 540 default: |
541 break; | 541 break; |
542 } | 542 } |
543 m_token.clear(); | 543 m_token.clear(); |
544 } | 544 } |
545 | 545 |
546 void WebVTTParser::skipWhiteSpace(const String& line, unsigned* position) | 546 void WebVTTParser::skipWhiteSpace(const String& line, unsigned* position) |
547 { | 547 { |
(...skipping 18 matching lines...) Expand all Loading... |
566 unsigned oldPosition = *position; | 566 unsigned oldPosition = *position; |
567 while (*position < length && data[*position] != '\r' && data[*position] != '
\n') | 567 while (*position < length && data[*position] != '\r' && data[*position] != '
\n') |
568 (*position)++; | 568 (*position)++; |
569 String line = String::fromUTF8(data + oldPosition, *position - oldPosition); | 569 String line = String::fromUTF8(data + oldPosition, *position - oldPosition); |
570 skipLineTerminator(data, length, position); | 570 skipLineTerminator(data, length, position); |
571 return line; | 571 return line; |
572 } | 572 } |
573 | 573 |
574 } | 574 } |
575 | 575 |
OLD | NEW |