Пример #1
0
void VTTCue::line(DoubleOrAutoKeyword& result) const
{
    if (lineIsAuto())
        result.setAutoKeyword(autoKeyword());
    else
        result.setDouble(m_linePosition);
}
Пример #2
0
float VTTCue::calculateComputedLinePosition() const
{
    // http://dev.w3.org/html5/webvtt/#dfn-text-track-cue-computed-line-position
    // A text track cue has a text track cue computed line position whose value
    // is that returned by the following algorithm, which is defined in terms
    // of the other aspects of the cue:

    // 1. If the text track cue line position is numeric, the text track cue
    //    snap-to-lines flag of the text track cue is not set, and the text
    //    track cue line position is negative or greater than 100, then return
    //    100 and abort these steps.
    if (!lineIsAuto() && !m_snapToLines && isInvalidPercentage(m_linePosition))
        return 100;

    // 2. If the text track cue line position is numeric, return the value of
    //    the text track cue line position and abort these steps. (Either the
    //    text track cue snap-to-lines flag is set, so any value, not just
    //    those in the range 0..100, is valid, or the value is in the range
    //    0..100 and is thus valid regardless of the value of that flag.)
    if (!lineIsAuto())
        return m_linePosition;

    // 3. If the text track cue snap-to-lines flag of the text track cue is not
    //    set, return the value 100 and abort these steps. (The text track cue
    //    line position is the special value auto.)
    if (!m_snapToLines)
        return 100;

    // 4. Let cue be the text track cue.
    // 5. If cue is not in a list of cues of a text track, or if that text
    //    track is not in the list of text tracks of a media element, return -1
    //    and abort these steps.
    if (!track())
        return -1;

    // 6. Let track be the text track whose list of cues the cue is in.
    // 7. Let n be the number of text tracks whose text track mode is showing
    //    and that are in the media element's list of text tracks before track.
    int n = track()->trackIndexRelativeToRenderedTracks();

    // 8. Increment n by one. / 9. Negate n. / 10. Return n.
    n++;
    n = -n;
    return n;
}
Пример #3
0
void VTTCue::updateDisplay(HTMLDivElement& container)
{
    ASSERT(track() && track()->isRendered() && isActive());

    UseCounter::count(document(), UseCounter::VTTCueRender);

    if (m_writingDirection != Horizontal)
        UseCounter::count(document(), UseCounter::VTTCueRenderVertical);

    if (!m_snapToLines)
        UseCounter::count(document(), UseCounter::VTTCueRenderSnapToLinesFalse);

    if (!lineIsAuto())
        UseCounter::count(document(), UseCounter::VTTCueRenderLineNotAuto);

    if (textPositionIsAuto())
        UseCounter::count(document(), UseCounter::VTTCueRenderPositionNot50);

    if (m_cueSize != 100)
        UseCounter::count(document(), UseCounter::VTTCueRenderSizeNot100);

    if (m_cueAlignment != Middle)
        UseCounter::count(document(), UseCounter::VTTCueRenderAlignNotMiddle);

    VTTCueBox* displayBox = getDisplayTree();
    VTTRegion* region = 0;
    if (track()->regions())
        region = track()->regions()->getRegionById(regionId());

    if (!region) {
        // If cue has an empty region identifier or there is no WebVTT region
        // whose region identifier is identical to cue's region identifier, run
        // the following substeps:
        if (displayBox->hasChildren() && !container.contains(displayBox)) {
            // Note: the display tree of a cue is removed when the active flag of the cue is unset.
            container.appendChild(displayBox);
        }
    } else {
        // Let region be the WebVTT region whose region identifier matches the
        // region identifier of cue.
        HTMLDivElement* regionNode = region->getDisplayTree(document());

        // Append the region to the viewport, if it was not already.
        if (!container.contains(regionNode))
            container.appendChild(regionNode);

        region->appendVTTCueBox(displayBox);
    }
}
Пример #4
0
void VTTCue::setLine(const DoubleOrAutoKeyword& position)
{
    // http://dev.w3.org/html5/webvtt/#dfn-vttcue-line
    // On setting, the WebVTT cue line must be set to the new value; if the new
    // value is the string "auto", then it must be interpreted as the special
    // value auto.  ("auto" is translated to NaN.)
    float floatPosition;
    if (position.isAutoKeyword()) {
        if (lineIsAuto())
            return;
        floatPosition = std::numeric_limits<float>::quiet_NaN();
    } else {
        ASSERT(position.isDouble());
        floatPosition = narrowPrecisionToFloat(position.getAsDouble());
        if (m_linePosition == floatPosition)
            return;
    }

    cueWillChange();
    m_linePosition = floatPosition;
    cueDidChange();
}
Пример #5
0
void VTTCue::parseSettings(const String& inputString)
{
    VTTScanner input(inputString);

    while (!input.isAtEnd()) {

        // The WebVTT cue settings part of a WebVTT cue consists of zero or more of the following components, in any order,
        // separated from each other by one or more U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characters.
        input.skipWhile<VTTParser::isValidSettingDelimiter>();

        if (input.isAtEnd())
            break;

        // When the user agent is to parse the WebVTT settings given by a string input for a text track cue cue,
        // the user agent must run the following steps:
        // 1. Let settings be the result of splitting input on spaces.
        // 2. For each token setting in the list settings, run the following substeps:
        //    1. If setting does not contain a U+003A COLON character (:), or if the first U+003A COLON character (:)
        //       in setting is either the first or last character of setting, then jump to the step labeled next setting.
        //    2. Let name be the leading substring of setting up to and excluding the first U+003A COLON character (:) in that string.
        CueSetting name = settingName(input);

        // 3. Let value be the trailing substring of setting starting from the character immediately after the first U+003A COLON character (:) in that string.
        VTTScanner::Run valueRun = input.collectUntil<VTTParser::isValidSettingDelimiter>();

        // 4. Run the appropriate substeps that apply for the value of name, as follows:
        switch (name) {
        case Vertical: {
            // If name is a case-sensitive match for "vertical"
            // 1. If value is a case-sensitive match for the string "rl", then
            //    let cue's WebVTT cue writing direction be vertical
            //    growing left.
            if (input.scanRun(valueRun, verticalGrowingLeftKeyword()))
                m_writingDirection = VerticalGrowingLeft;

            // 2. Otherwise, if value is a case-sensitive match for the string
            //    "lr", then let cue's WebVTT cue writing direction be
            //    vertical growing right.
            else if (input.scanRun(valueRun, verticalGrowingRightKeyword()))
                m_writingDirection = VerticalGrowingRight;
            break;
        }
        case Line: {
            // If name is a case-sensitive match for "line"
            // Steps 1 - 2 skipped.
            float number;
            // 3. If linepos does not contain at least one ASCII digit, then
            //    jump to the step labeled next setting.
            // 4. If the last character in linepos is a U+0025 PERCENT SIGN character (%)
            //
            //    If parse a percentage string from linepos doesn't fail, let
            //    number be the returned percentage, otherwise jump to the step
            //    labeled next setting.
            bool isPercentage = scanPercentage(input, number);
            if (!isPercentage) {
                // Otherwise
                //
                // 1. If linepos contains any characters other than U+002D
                //    HYPHEN-MINUS characters (-) and ASCII digits, then jump to
                //    the step labeled next setting.
                // 2. If any character in linepos other than the first character is
                //    a U+002D HYPHEN-MINUS character (-), then jump to the step
                //    labeled next setting.
                bool isNegative = input.scan('-');
                int intLinePosition;
                if (!input.scanDigits(intLinePosition))
                    break;
                // 3. Interpret linepos as a (potentially signed) integer, and let
                //    number be that number.
                number = isNegative ? -intLinePosition : intLinePosition;
            }
            if (!input.isAt(valueRun.end()))
                break;
            // 5. Let cue's WebVTT cue line be number.
            m_linePosition = number;
            // 6. If the last character in linepos is a U+0025 PERCENT SIGN
            //    character (%), then let cue's WebVTT cue snap-to-lines
            //    flag be false. Otherwise, let it be true.
            m_snapToLines = !isPercentage;
            // Steps 7 - 9 skipped.
            break;
        }
        case Position: {
            // If name is a case-sensitive match for "position".
            float number;
            // Steps 1 - 2 skipped.
            // 3. If parse a percentage string from colpos doesn't fail, let
            //    number be the returned percentage, otherwise jump to the step
            //    labeled next setting (text track cue text position's value
            //    remains the special value auto).
            if (!scanPercentage(input, number))
                break;
            if (!input.isAt(valueRun.end()))
                break;
            // 4. Let cue's cue position be number.
            m_textPosition = number;
            // Steps 5 - 7 skipped.
            break;
        }
        case Size: {
            // If name is a case-sensitive match for "size"
            float number;
            // 1. If parse a percentage string from value doesn't fail, let
            //    number be the returned percentage, otherwise jump to the step
            //    labeled next setting.
            if (!scanPercentage(input, number))
                break;
            if (!input.isAt(valueRun.end()))
                break;
            // 2. Let cue's WebVTT cue size be number.
            m_cueSize = number;
            break;
        }
        case Align: {
            // If name is a case-sensitive match for "align"
            // 1. If value is a case-sensitive match for the string "start",
            //    then let cue's WebVTT cue text alignment be start alignment.
            if (input.scanRun(valueRun, startKeyword()))
                m_cueAlignment = Start;

            // 2. If value is a case-sensitive match for the string "middle",
            //    then let cue's WebVTT cue text alignment be middle alignment.
            else if (input.scanRun(valueRun, middleKeyword()))
                m_cueAlignment = Middle;

            // 3. If value is a case-sensitive match for the string "end", then
            //    let cue's WebVTT cue text alignment be end alignment.
            else if (input.scanRun(valueRun, endKeyword()))
                m_cueAlignment = End;

            // 4. If value is a case-sensitive match for the string "left",
            //    then let cue's WebVTT cue text alignment be left alignment.
            else if (input.scanRun(valueRun, leftKeyword()))
                m_cueAlignment = Left;

            // 5. If value is a case-sensitive match for the string "right",
            //    then let cue's WebVTT cue text alignment be right alignment.
            else if (input.scanRun(valueRun, rightKeyword()))
                m_cueAlignment = Right;
            break;
        }
        case RegionId:
            m_regionId = input.extractString(valueRun);
            break;
        case None:
            break;
        }

        // Make sure the entire run is consumed.
        input.skipRun(valueRun);
    }

    // If cue's line position is not auto or cue's size is not 100 or cue's
    // writing direction is not horizontal, but cue's region identifier is not
    // the empty string, let cue's region identifier be the empty string.
    if (m_regionId.isEmpty())
        return;

    if (!lineIsAuto() || m_cueSize != 100 || m_writingDirection != Horizontal)
        m_regionId = emptyString();
}