Пример #1
0
PassRefPtr<HTMLElement> WebVTTElement::createEquivalentHTMLElement(Document& document)
{
    RefPtr<HTMLElement> htmlElement;

    switch (m_webVTTNodeType) {
    case WebVTTNodeTypeClass:
    case WebVTTNodeTypeLanguage:
    case WebVTTNodeTypeVoice:
        htmlElement = HTMLElementFactory::createElement(HTMLNames::spanTag, document);
        htmlElement->setAttribute(HTMLNames::titleAttr, getAttribute(voiceAttributeName()));
        htmlElement->setAttribute(HTMLNames::langAttr, getAttribute(langAttributeName()));
        break;
    case WebVTTNodeTypeItalic:
        htmlElement = HTMLElementFactory::createElement(HTMLNames::iTag, document);
        break;
    case WebVTTNodeTypeBold:
        htmlElement = HTMLElementFactory::createElement(HTMLNames::bTag, document);
        break;
    case WebVTTNodeTypeUnderline:
        htmlElement = HTMLElementFactory::createElement(HTMLNames::uTag, document);
        break;
    case WebVTTNodeTypeRuby:
        htmlElement = HTMLElementFactory::createElement(HTMLNames::rubyTag, document);
        break;
    case WebVTTNodeTypeRubyText:
        htmlElement = HTMLElementFactory::createElement(HTMLNames::rtTag, document);
        break;
    }

    ASSERT(htmlElement);
    if (htmlElement)
        htmlElement->setAttribute(HTMLNames::classAttr, fastGetAttribute(HTMLNames::classAttr));
    return htmlElement.release();
}
RawPtr<HTMLElement> VTTElement::createEquivalentHTMLElement(Document& document)
{
    RawPtr<HTMLElement> htmlElement = nullptr;
    switch (m_webVTTNodeType) {
    case VTTNodeTypeClass:
    case VTTNodeTypeLanguage:
    case VTTNodeTypeVoice:
        htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::spanTag.localName(), document);
        htmlElement.get()->setAttribute(HTMLNames::titleAttr, getAttribute(voiceAttributeName()));
        htmlElement.get()->setAttribute(HTMLNames::langAttr, getAttribute(langAttributeName()));
        break;
    case VTTNodeTypeItalic:
        htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::iTag.localName(), document);
        break;
    case VTTNodeTypeBold:
        htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::bTag.localName(), document);
        break;
    case VTTNodeTypeUnderline:
        htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::uTag.localName(), document);
        break;
    case VTTNodeTypeRuby:
        htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::rubyTag.localName(), document);
        break;
    case VTTNodeTypeRubyText:
        htmlElement = HTMLElementFactory::createHTMLElement(HTMLNames::rtTag.localName(), document);
        break;
    default:
        ASSERT_NOT_REACHED();
    }

    htmlElement.get()->setAttribute(HTMLNames::classAttr, getAttribute(HTMLNames::classAttr));
    return htmlElement;
}
Пример #3
0
void TextTrackCue::copyWebVTTNodeToDOMTree(ContainerNode* webVTTNode, ContainerNode* parent)
{
    for (Node* node = webVTTNode->firstChild(); node; node = node->nextSibling()) {
        RefPtr<Node> clonedNode;
        // Specs require voice and class WebVTT elements to be spans for DOM trees.
        if (node->hasTagName(voiceElementTagName()) || node->hasTagName(classElementTagName())) {
            clonedNode = HTMLSpanElement::create(spanTag, static_cast<Document*>(m_scriptExecutionContext));
            toElement(clonedNode.get())->setAttribute(classAttr, toElement(node)->getAttribute(classAttr));
            toElement(clonedNode.get())->setAttribute(titleAttr, toElement(node)->getAttribute(voiceAttributeName()));
        } else
            clonedNode = node->cloneNode(false);

        parent->appendChild(clonedNode, ASSERT_NO_EXCEPTION);
        if (node->isContainerNode())
            copyWebVTTNodeToDOMTree(toContainerNode(node), toContainerNode(clonedNode.get()));
    }
}