コード例 #1
0
WebVTTParser::ParseState WebVTTParser::collectTimingsAndSettings(const String& line)
{
    // 4.8.10.13.3 Collect WebVTT cue timings and settings.
    // 1-3 - Let input be the string being parsed and position be a pointer into input
    unsigned position = 0;
    skipWhiteSpace(line, &position);

    // 4-5 - Collect a WebVTT timestamp. If that fails, then abort and return failure. Otherwise, let cue's text track cue start time be the collected time.
    m_currentStartTime = collectTimeStamp(line, &position);
    if (m_currentStartTime == malformedTime)
        return BadCue;
    if (position >= line.length())
        return BadCue;

    skipWhiteSpace(line, &position);

    // 6-9 - If the next three characters are not "-->", abort and return failure.
    if (line.find("-->", position) == kNotFound)
        return BadCue;
    position += 3;
    if (position >= line.length())
        return BadCue;

    skipWhiteSpace(line, &position);

    // 10-11 - Collect a WebVTT timestamp. If that fails, then abort and return failure. Otherwise, let cue's text track cue end time be the collected time.
    m_currentEndTime = collectTimeStamp(line, &position);
    if (m_currentEndTime == malformedTime)
        return BadCue;
    skipWhiteSpace(line, &position);

    // 12 - Parse the WebVTT settings for the cue (conducted in TextTrackCue).
    m_currentSettings = line.substring(position, line.length()-1);
    return CueText;
}
コード例 #2
0
VTTParser::ParseState VTTParser::collectTimingsAndSettings(const String& line)
{
    VTTScanner input(line);

    // Collect WebVTT cue timings and settings. (5.3 WebVTT cue timings and settings parsing.)
    // Steps 1 - 3 - Let input be the string being parsed and position be a pointer into input.
    input.skipWhile<isASpace>();

    // Steps 4 - 5 - Collect a WebVTT timestamp. If that fails, then abort and return failure. Otherwise, let cue's text track cue start time be the collected time.
    if (!collectTimeStamp(input, m_currentStartTime))
        return BadCue;
    input.skipWhile<isASpace>();

    // Steps 6 - 9 - If the next three characters are not "-->", abort and return failure.
    if (!input.scan("-->"))
        return BadCue;
    input.skipWhile<isASpace>();

    // Steps 10 - 11 - Collect a WebVTT timestamp. If that fails, then abort and return failure. Otherwise, let cue's text track cue end time be the collected time.
    if (!collectTimeStamp(input, m_currentEndTime))
        return BadCue;
    input.skipWhile<isASpace>();

    // Step 12 - Parse the WebVTT settings for the cue (conducted in TextTrackCue).
    m_currentSettings = input.restOfInputAsString();
    return CueText;
}
コード例 #3
0
ファイル: WebVTTParser.cpp プロジェクト: CannedFish/webkit
bool WebVTTParser::collectTimeStamp(const String& line, double& timeStamp)
{
    if (line.isEmpty())
        return false;

    VTTScanner input(line);
    return collectTimeStamp(input, timeStamp);
}
コード例 #4
0
void WebVTTParser::constructTreeFromToken(Document& document)
{
    QualifiedName tagName(nullAtom, AtomicString(m_token.name()), xhtmlNamespaceURI);

    // http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules

    switch (m_token.type()) {
    case WebVTTTokenTypes::Character: {
        String content(m_token.characters()); // FIXME: This should be 8bit if possible.
        RefPtr<Text> child = Text::create(document, content);
        m_currentNode->parserAppendChild(child);
        break;
    }
    case WebVTTTokenTypes::StartTag: {
        RefPtr<WebVTTElement> child;
        WebVTTNodeType nodeType = tokenToNodeType(m_token);
        if (nodeType != WebVTTNodeTypeNone)
            child = WebVTTElement::create(nodeType, &document);
        if (child) {
            if (m_token.classes().size() > 0)
                child->setAttribute(classAttr, AtomicString(m_token.classes()));

            if (child->webVTTNodeType() == WebVTTNodeTypeVoice)
                child->setAttribute(WebVTTElement::voiceAttributeName(), AtomicString(m_token.annotation()));
            else if (child->webVTTNodeType() == WebVTTNodeTypeLanguage) {
                m_languageStack.append(AtomicString(m_token.annotation()));
                child->setAttribute(WebVTTElement::langAttributeName(), m_languageStack.last());
            }
            if (!m_languageStack.isEmpty())
                child->setLanguage(m_languageStack.last());
            m_currentNode->parserAppendChild(child);
            m_currentNode = child;
        }
        break;
    }
    case WebVTTTokenTypes::EndTag: {
        WebVTTNodeType nodeType = tokenToNodeType(m_token);
        if (nodeType != WebVTTNodeTypeNone) {
            if (nodeType == WebVTTNodeTypeLanguage && m_currentNode->isWebVTTElement() && toWebVTTElement(m_currentNode.get())->webVTTNodeType() == WebVTTNodeTypeLanguage)
                m_languageStack.removeLast();
            if (m_currentNode->parentNode())
                m_currentNode = m_currentNode->parentNode();
        }
        break;
    }
    case WebVTTTokenTypes::TimestampTag: {
        unsigned position = 0;
        String charactersString(StringImpl::create8BitIfPossible(m_token.characters()));
        double time = collectTimeStamp(charactersString, &position);
        if (time != malformedTime)
            m_currentNode->parserAppendChild(ProcessingInstruction::create(document, "timestamp", charactersString));
        break;
    }
    default:
        break;
    }
    m_token.clear();
}
コード例 #5
0
ファイル: WebVTTParser.cpp プロジェクト: sysrqb/chromium-src
void WebVTTParser::constructTreeFromToken(Document* document)
{
    AtomicString tokenTagName(m_token.name().data(), m_token.name().size());
    QualifiedName tagName(nullAtom, tokenTagName, xhtmlNamespaceURI);

    switch (m_token.type()) {
    case WebVTTTokenTypes::Character: {
        String content(m_token.characters().data(), m_token.characters().size());
        RefPtr<Text> child = Text::create(document, content);
        m_currentNode->parserAddChild(child);
        break;
    }
    case WebVTTTokenTypes::StartTag: {
        RefPtr<HTMLElement> child;
        if (isRecognizedTag(tokenTagName))
            child = HTMLElement::create(tagName, document);
        else if (m_token.name().size() == 1 && m_token.name()[0] == 'c')
            child = HTMLElement::create(spanTag, document);
        else if (m_token.name().size() == 1 && m_token.name()[0] == 'v')
            child = HTMLElement::create(qTag, document);

        if (child) {
            if (m_token.classes().size() > 0) {
                RefPtr<NamedNodeMap> attributeMap = NamedNodeMap::create();
                attributeMap->addAttribute(Attribute::createMapped(classAttr, AtomicString(m_token.classes().data(), m_token.classes().size())));
                child->setAttributeMap(attributeMap.release());
            }
            if (child->hasTagName(qTag))
                child->setAttribute(titleAttr, String(m_token.annotation().data(), m_token.annotation().size()));
            m_currentNode->parserAddChild(child);
            m_currentNode = child;
        }
        break;
    }
    case WebVTTTokenTypes::EndTag:
        if (isRecognizedTag(tokenTagName)
            || (m_token.name().size() == 1 && m_token.name()[0] == 'c')
            || (m_token.name().size() == 1 && m_token.name()[0] == 'v')) {
            if (m_currentNode->parentNode())
                m_currentNode = m_currentNode->parentNode();
        }
        break;
    case WebVTTTokenTypes::TimestampTag: {
        unsigned position = 0;
        double time = collectTimeStamp(m_token.characters().data(), &position);
        if (time != malformedTime)
            m_currentNode->parserAddChild(ProcessingInstruction::create(document, "timestamp", String(m_token.characters().data(), m_token.characters().size())));
        break;
    }
    default:
        break;
    }
    m_token.clear();
}
コード例 #6
0
bool VTTParser::collectTimeStamp(const String& line, double& timeStamp)
{
    VTTScanner input(line);
    return collectTimeStamp(input, timeStamp);
}
コード例 #7
0
void WebVTTParser::constructTreeFromToken(Document* document)
{
    AtomicString tokenTagName(m_token.name().data(), m_token.name().size());
    QualifiedName tagName(nullAtom, tokenTagName, xhtmlNamespaceURI);

    // http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules

    switch (m_token.type()) {
    case WebVTTTokenTypes::Character: {
        String content(m_token.characters().data(), m_token.characters().size());
        RefPtr<Text> child = Text::create(document, content);
        m_currentNode->parserAppendChild(child);
        break;
    }
    case WebVTTTokenTypes::StartTag: {
        RefPtr<WebVTTElement> child;
        if (isRecognizedTag(tokenTagName))
            child = WebVTTElement::create(tagName, document);
        else if (m_token.name().size() == 1 && m_token.name()[0] == 'c')
            child = WebVTTElement::create(TextTrackCue::classElementTagName(), document);
        else if (m_token.name().size() == 1 && m_token.name()[0] == 'v')
            child = WebVTTElement::create(TextTrackCue::voiceElementTagName(), document);
        else if (isLangToken(m_token))
            child = WebVTTElement::create(TextTrackCue::langElementTagName(), document);

        if (child) {
            if (m_token.classes().size() > 0)
                child->setAttribute(classAttr, AtomicString(m_token.classes().data(), m_token.classes().size()));
            if (child->hasTagName(TextTrackCue::voiceElementTagName()))
                child->setAttribute(TextTrackCue::voiceAttributeName(), AtomicString(m_token.annotation().data(), m_token.annotation().size()));
            if (child->hasTagName(TextTrackCue::langElementTagName()))
                m_languageStack.append(AtomicString(m_token.annotation().data(), m_token.annotation().size()));
            if (!m_languageStack.isEmpty())
                child->setAttribute(TextTrackCue::langAttributeName(), m_languageStack.last());
            m_currentNode->parserAppendChild(child);
            m_currentNode = child;
        }
        break;
    }
    case WebVTTTokenTypes::EndTag:
        if (isRecognizedTag(tokenTagName)
                || (m_token.name().size() == 1 && m_token.name()[0] == 'c')
                || (m_token.name().size() == 1 && m_token.name()[0] == 'v')) {
            if (m_currentNode->parentNode())
                m_currentNode = m_currentNode->parentNode();
        }
        if (isLangToken(m_token)) {
            if (m_currentNode->hasTagName(TextTrackCue::langElementTagName()))
                m_languageStack.removeLast();
            if (m_currentNode->parentNode())
                m_currentNode = m_currentNode->parentNode();
        }
        break;
    case WebVTTTokenTypes::TimestampTag: {
        unsigned position = 0;
        double time = collectTimeStamp(m_token.characters().data(), &position);
        if (time != malformedTime)
            m_currentNode->parserAppendChild(ProcessingInstruction::create(document, "timestamp", String(m_token.characters().data(), m_token.characters().size())));
        break;
    }
    default:
        break;
    }
    m_token.clear();
}