1 /* 2 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "config.h" 27 #include "core/html/track/vtt/VTTElement.h" 28 29 #include "HTMLElementFactory.h" 30 31 namespace WebCore { 32 33 static const QualifiedName& nodeTypeToTagName(VTTNodeType nodeType) 34 { 35 DEFINE_STATIC_LOCAL(QualifiedName, cTag, (nullAtom, "c", nullAtom)); 36 DEFINE_STATIC_LOCAL(QualifiedName, vTag, (nullAtom, "v", nullAtom)); 37 DEFINE_STATIC_LOCAL(QualifiedName, langTag, (nullAtom, "lang", nullAtom)); 38 DEFINE_STATIC_LOCAL(QualifiedName, bTag, (nullAtom, "b", nullAtom)); 39 DEFINE_STATIC_LOCAL(QualifiedName, uTag, (nullAtom, "u", nullAtom)); 40 DEFINE_STATIC_LOCAL(QualifiedName, iTag, (nullAtom, "i", nullAtom)); 41 DEFINE_STATIC_LOCAL(QualifiedName, rubyTag, (nullAtom, "ruby", nullAtom)); 42 DEFINE_STATIC_LOCAL(QualifiedName, rtTag, (nullAtom, "rt", nullAtom)); 43 switch (nodeType) { 44 case VTTNodeTypeClass: 45 return cTag; 46 case VTTNodeTypeItalic: 47 return iTag; 48 case VTTNodeTypeLanguage: 49 return langTag; 50 case VTTNodeTypeBold: 51 return bTag; 52 case VTTNodeTypeUnderline: 53 return uTag; 54 case VTTNodeTypeRuby: 55 return rubyTag; 56 case VTTNodeTypeRubyText: 57 return rtTag; 58 case VTTNodeTypeVoice: 59 return vTag; 60 case VTTNodeTypeNone: 61 default: 62 ASSERT_NOT_REACHED(); 63 return cTag; // Make the compiler happy. 64 } 65 } 66 67 VTTElement::VTTElement(VTTNodeType nodeType, Document* document) 68 : Element(nodeTypeToTagName(nodeType), document, CreateElement) 69 , m_isPastNode(0) 70 , m_webVTTNodeType(nodeType) 71 { 72 } 73 74 PassRefPtr<VTTElement> VTTElement::create(VTTNodeType nodeType, Document* document) 75 { 76 return adoptRef(new VTTElement(nodeType, document)); 77 } 78 79 PassRefPtr<Element> VTTElement::cloneElementWithoutAttributesAndChildren() 80 { 81 RefPtr<VTTElement> clone = create(static_cast<VTTNodeType>(m_webVTTNodeType), &document()); 82 clone->setLanguage(m_language); 83 return clone; 84 } 85 86 PassRefPtr<HTMLElement> VTTElement::createEquivalentHTMLElement(Document& document) 87 { 88 RefPtr<HTMLElement> htmlElement; 89 switch (m_webVTTNodeType) { 90 case VTTNodeTypeClass: 91 case VTTNodeTypeLanguage: 92 case VTTNodeTypeVoice: 93 htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::spanTag.localName(), document); 94 htmlElement.get()->setAttribute(HTMLNames::titleAttr, getAttribute(voiceAttributeName())); 95 htmlElement.get()->setAttribute(HTMLNames::langAttr, getAttribute(langAttributeName())); 96 break; 97 case VTTNodeTypeItalic: 98 htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::iTag.localName(), document); 99 break; 100 case VTTNodeTypeBold: 101 htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::bTag.localName(), document); 102 break; 103 case VTTNodeTypeUnderline: 104 htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::uTag.localName(), document); 105 break; 106 case VTTNodeTypeRuby: 107 htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::rubyTag.localName(), document); 108 break; 109 case VTTNodeTypeRubyText: 110 htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::rtTag.localName(), document); 111 break; 112 default: 113 ASSERT_NOT_REACHED(); 114 } 115 116 htmlElement.get()->setAttribute(HTMLNames::classAttr, getAttribute(HTMLNames::classAttr)); 117 return htmlElement; 118 } 119 120 } // namespace WebCore 121 122