| 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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 int value4 = digits4.toInt(); | 499 int value4 = digits4.toInt(); |
| 500 if (value2 > 59 || value3 > 59) | 500 if (value2 > 59 || value3 > 59) |
| 501 return malformedTime; | 501 return malformedTime; |
| 502 | 502 |
| 503 // Steps 18 - 19 - Calculate result. | 503 // Steps 18 - 19 - Calculate result. |
| 504 return (value1 * secondsPerHour) + (value2 * secondsPerMinute) + value3 + (v
alue4 * secondsPerMillisecond); | 504 return (value1 * secondsPerHour) + (value2 * secondsPerMinute) + value3 + (v
alue4 * secondsPerMillisecond); |
| 505 } | 505 } |
| 506 | 506 |
| 507 static VTTNodeType tokenToNodeType(VTTToken& token) | 507 static VTTNodeType tokenToNodeType(VTTToken& token) |
| 508 { | 508 { |
| 509 switch (token.name().size()) { | 509 switch (token.name().length()) { |
| 510 case 1: | 510 case 1: |
| 511 if (token.name()[0] == 'c') | 511 if (token.name()[0] == 'c') |
| 512 return VTTNodeTypeClass; | 512 return VTTNodeTypeClass; |
| 513 if (token.name()[0] == 'v') | 513 if (token.name()[0] == 'v') |
| 514 return VTTNodeTypeVoice; | 514 return VTTNodeTypeVoice; |
| 515 if (token.name()[0] == 'b') | 515 if (token.name()[0] == 'b') |
| 516 return VTTNodeTypeBold; | 516 return VTTNodeTypeBold; |
| 517 if (token.name()[0] == 'i') | 517 if (token.name()[0] == 'i') |
| 518 return VTTNodeTypeItalic; | 518 return VTTNodeTypeItalic; |
| 519 if (token.name()[0] == 'u') | 519 if (token.name()[0] == 'u') |
| 520 return VTTNodeTypeUnderline; | 520 return VTTNodeTypeUnderline; |
| 521 break; | 521 break; |
| 522 case 2: | 522 case 2: |
| 523 if (token.name()[0] == 'r' && token.name()[1] == 't') | 523 if (token.name()[0] == 'r' && token.name()[1] == 't') |
| 524 return VTTNodeTypeRubyText; | 524 return VTTNodeTypeRubyText; |
| 525 break; | 525 break; |
| 526 case 4: | 526 case 4: |
| 527 if (token.name()[0] == 'r' && token.name()[1] == 'u' && token.name()[2]
== 'b' && token.name()[3] == 'y') | 527 if (token.name()[0] == 'r' && token.name()[1] == 'u' && token.name()[2]
== 'b' && token.name()[3] == 'y') |
| 528 return VTTNodeTypeRuby; | 528 return VTTNodeTypeRuby; |
| 529 if (token.name()[0] == 'l' && token.name()[1] == 'a' && token.name()[2]
== 'n' && token.name()[3] == 'g') | 529 if (token.name()[0] == 'l' && token.name()[1] == 'a' && token.name()[2]
== 'n' && token.name()[3] == 'g') |
| 530 return VTTNodeTypeLanguage; | 530 return VTTNodeTypeLanguage; |
| 531 break; | 531 break; |
| 532 } | 532 } |
| 533 return VTTNodeTypeNone; | 533 return VTTNodeTypeNone; |
| 534 } | 534 } |
| 535 | 535 |
| 536 void VTTTreeBuilder::constructTreeFromToken(Document& document) | 536 void VTTTreeBuilder::constructTreeFromToken(Document& document) |
| 537 { | 537 { |
| 538 QualifiedName tagName(nullAtom, AtomicString(m_token.name()), xhtmlNamespace
URI); | |
| 539 | |
| 540 // http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules | 538 // http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules |
| 541 | 539 |
| 542 switch (m_token.type()) { | 540 switch (m_token.type()) { |
| 543 case VTTTokenTypes::Character: { | 541 case VTTTokenTypes::Character: { |
| 544 String content(m_token.characters()); // FIXME: This should be 8bit if p
ossible. | 542 String content = m_token.characters().toString(); |
| 545 RefPtr<Text> child = Text::create(document, content); | 543 RefPtr<Text> child = Text::create(document, content); |
| 546 m_currentNode->parserAppendChild(child); | 544 m_currentNode->parserAppendChild(child); |
| 547 break; | 545 break; |
| 548 } | 546 } |
| 549 case VTTTokenTypes::StartTag: { | 547 case VTTTokenTypes::StartTag: { |
| 550 RefPtr<VTTElement> child; | 548 RefPtr<VTTElement> child; |
| 551 VTTNodeType nodeType = tokenToNodeType(m_token); | 549 VTTNodeType nodeType = tokenToNodeType(m_token); |
| 552 if (nodeType != VTTNodeTypeNone) | 550 if (nodeType != VTTNodeTypeNone) |
| 553 child = VTTElement::create(nodeType, &document); | 551 child = VTTElement::create(nodeType, &document); |
| 554 if (child) { | 552 if (child) { |
| 555 if (m_token.classes().size() > 0) | 553 if (!m_token.classes().isEmpty()) |
| 556 child->setAttribute(classAttr, AtomicString(m_token.classes())); | 554 child->setAttribute(classAttr, m_token.classes().toAtomicString(
)); |
| 557 | 555 |
| 558 if (child->webVTTNodeType() == VTTNodeTypeVoice) { | 556 if (child->webVTTNodeType() == VTTNodeTypeVoice) { |
| 559 child->setAttribute(VTTElement::voiceAttributeName(), AtomicStri
ng(m_token.annotation())); | 557 child->setAttribute(VTTElement::voiceAttributeName(), m_token.an
notation().toAtomicString()); |
| 560 } else if (child->webVTTNodeType() == VTTNodeTypeLanguage) { | 558 } else if (child->webVTTNodeType() == VTTNodeTypeLanguage) { |
| 561 m_languageStack.append(AtomicString(m_token.annotation())); | 559 m_languageStack.append(m_token.annotation().toAtomicString()); |
| 562 child->setAttribute(VTTElement::langAttributeName(), m_languageS
tack.last()); | 560 child->setAttribute(VTTElement::langAttributeName(), m_languageS
tack.last()); |
| 563 } | 561 } |
| 564 if (!m_languageStack.isEmpty()) | 562 if (!m_languageStack.isEmpty()) |
| 565 child->setLanguage(m_languageStack.last()); | 563 child->setLanguage(m_languageStack.last()); |
| 566 m_currentNode->parserAppendChild(child); | 564 m_currentNode->parserAppendChild(child); |
| 567 m_currentNode = child; | 565 m_currentNode = child; |
| 568 } | 566 } |
| 569 break; | 567 break; |
| 570 } | 568 } |
| 571 case VTTTokenTypes::EndTag: { | 569 case VTTTokenTypes::EndTag: { |
| 572 VTTNodeType nodeType = tokenToNodeType(m_token); | 570 VTTNodeType nodeType = tokenToNodeType(m_token); |
| 573 if (nodeType != VTTNodeTypeNone) { | 571 if (nodeType != VTTNodeTypeNone) { |
| 574 if (nodeType == VTTNodeTypeLanguage && m_currentNode->isVTTElement()
&& toVTTElement(m_currentNode.get())->webVTTNodeType() == VTTNodeTypeLanguage) | 572 if (nodeType == VTTNodeTypeLanguage && m_currentNode->isVTTElement()
&& toVTTElement(m_currentNode.get())->webVTTNodeType() == VTTNodeTypeLanguage) |
| 575 m_languageStack.removeLast(); | 573 m_languageStack.removeLast(); |
| 576 if (m_currentNode->parentNode()) | 574 if (m_currentNode->parentNode()) |
| 577 m_currentNode = m_currentNode->parentNode(); | 575 m_currentNode = m_currentNode->parentNode(); |
| 578 } | 576 } |
| 579 break; | 577 break; |
| 580 } | 578 } |
| 581 case VTTTokenTypes::TimestampTag: { | 579 case VTTTokenTypes::TimestampTag: { |
| 582 unsigned position = 0; | 580 unsigned position = 0; |
| 583 String charactersString(StringImpl::create8BitIfPossible(m_token.charact
ers())); | 581 String charactersString = m_token.characters().toString(); |
| 584 double time = VTTParser::collectTimeStamp(charactersString, &position); | 582 double time = VTTParser::collectTimeStamp(charactersString, &position); |
| 585 if (time != malformedTime) | 583 if (time != malformedTime) |
| 586 m_currentNode->parserAppendChild(ProcessingInstruction::create(docum
ent, "timestamp", charactersString)); | 584 m_currentNode->parserAppendChild(ProcessingInstruction::create(docum
ent, "timestamp", charactersString)); |
| 587 break; | 585 break; |
| 588 } | 586 } |
| 589 default: | 587 default: |
| 590 break; | 588 break; |
| 591 } | 589 } |
| 592 m_token.clear(); | 590 m_token.clear(); |
| 593 } | 591 } |
| 594 | 592 |
| 595 void VTTParser::skipWhiteSpace(const String& line, unsigned* position) | 593 void VTTParser::skipWhiteSpace(const String& line, unsigned* position) |
| 596 { | 594 { |
| 597 while (*position < line.length() && isASpace(line[*position])) | 595 while (*position < line.length() && isASpace(line[*position])) |
| 598 (*position)++; | 596 (*position)++; |
| 599 } | 597 } |
| 600 | 598 |
| 601 } | 599 } |
| 602 | 600 |
| OLD | NEW |