Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: Source/core/html/track/vtt/VTTParser.cpp

Issue 98783005: WebVTT only allows <rt> if the currently innermost node is <ruby> (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « LayoutTests/media/track/track-webvtt-tc023-markup.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 { 535 {
536 // 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
537 537
538 switch (m_token.type()) { 538 switch (m_token.type()) {
539 case VTTTokenTypes::Character: { 539 case VTTTokenTypes::Character: {
540 RefPtr<Text> child = Text::create(document, m_token.characters()); 540 RefPtr<Text> child = Text::create(document, m_token.characters());
541 m_currentNode->parserAppendChild(child); 541 m_currentNode->parserAppendChild(child);
542 break; 542 break;
543 } 543 }
544 case VTTTokenTypes::StartTag: { 544 case VTTTokenTypes::StartTag: {
545 RefPtr<VTTElement> child;
546 VTTNodeType nodeType = tokenToNodeType(m_token); 545 VTTNodeType nodeType = tokenToNodeType(m_token);
547 if (nodeType != VTTNodeTypeNone) 546 if (nodeType == VTTNodeTypeNone)
548 child = VTTElement::create(nodeType, &document); 547 break;
549 if (child) {
550 if (!m_token.classes().isEmpty())
551 child->setAttribute(classAttr, m_token.classes());
552 548
553 if (child->webVTTNodeType() == VTTNodeTypeVoice) { 549 VTTNodeType currentType = m_currentNode->isVTTElement() ? toVTTElement(m _currentNode.get())->webVTTNodeType() : VTTNodeTypeNone;
554 child->setAttribute(VTTElement::voiceAttributeName(), m_token.an notation()); 550 // <rt> is only allowed if the current node is <ruby>.
555 } else if (child->webVTTNodeType() == VTTNodeTypeLanguage) { 551 if (nodeType == VTTNodeTypeRubyText && currentType != VTTNodeTypeRuby)
556 m_languageStack.append(m_token.annotation()); 552 break;
557 child->setAttribute(VTTElement::langAttributeName(), m_languageS tack.last()); 553
558 } 554 RefPtr<VTTElement> child = VTTElement::create(nodeType, &document);
559 if (!m_languageStack.isEmpty()) 555 if (!m_token.classes().isEmpty())
560 child->setLanguage(m_languageStack.last()); 556 child->setAttribute(classAttr, m_token.classes());
561 m_currentNode->parserAppendChild(child); 557
562 m_currentNode = child; 558 if (nodeType == VTTNodeTypeVoice) {
559 child->setAttribute(VTTElement::voiceAttributeName(), m_token.annota tion());
560 } else if (nodeType == VTTNodeTypeLanguage) {
561 m_languageStack.append(m_token.annotation());
562 child->setAttribute(VTTElement::langAttributeName(), m_languageStack .last());
563 } 563 }
564 if (!m_languageStack.isEmpty())
565 child->setLanguage(m_languageStack.last());
566 m_currentNode->parserAppendChild(child);
567 m_currentNode = child;
564 break; 568 break;
565 } 569 }
566 case VTTTokenTypes::EndTag: { 570 case VTTTokenTypes::EndTag: {
567 VTTNodeType nodeType = tokenToNodeType(m_token); 571 VTTNodeType nodeType = tokenToNodeType(m_token);
568 if (nodeType == VTTNodeTypeNone) 572 if (nodeType == VTTNodeTypeNone)
569 break; 573 break;
570 574
571 // The only non-VTTElement would be the DocumentFragment root. (Text 575 // The only non-VTTElement would be the DocumentFragment root. (Text
572 // nodes and PIs will never appear as m_currentNode.) 576 // nodes and PIs will never appear as m_currentNode.)
573 if (!m_currentNode->isVTTElement()) 577 if (!m_currentNode->isVTTElement())
(...skipping 30 matching lines...) Expand all
604 } 608 }
605 609
606 void VTTParser::skipWhiteSpace(const String& line, unsigned* position) 610 void VTTParser::skipWhiteSpace(const String& line, unsigned* position)
607 { 611 {
608 while (*position < line.length() && isASpace(line[*position])) 612 while (*position < line.length() && isASpace(line[*position]))
609 (*position)++; 613 (*position)++;
610 } 614 }
611 615
612 } 616 }
613 617
OLDNEW
« no previous file with comments | « LayoutTests/media/track/track-webvtt-tc023-markup.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698