void VTTCue::setPosition(const DoubleOrAutoKeyword& position, ExceptionState& exceptionState) { // http://dev.w3.org/html5/webvtt/#dfn-vttcue-position // On setting, if the new value is negative or greater than 100, then an // IndexSizeError exception must be thrown. Otherwise, the WebVTT cue // position 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. float floatPosition; if (position.isAutoKeyword()) { if (textPositionIsAuto()) return; floatPosition = std::numeric_limits<float>::quiet_NaN(); } else { ASSERT(position.isDouble()); if (isInvalidPercentage(position.getAsDouble(), exceptionState)) return; floatPosition = narrowPrecisionToFloat(position.getAsDouble()); if (m_textPosition == floatPosition) return; } cueWillChange(); m_textPosition = floatPosition; cueDidChange(); }
static bool isInvalidPercentage(double value, ExceptionState& exceptionState) { if (isInvalidPercentage(value)) { exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::indexOutsideRange<double>("value", value, 0, ExceptionMessages::InclusiveBound, 100, ExceptionMessages::InclusiveBound)); return true; } return false; }
void VTTCue::setSize(int size, ExceptionState& exceptionState) { // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-size // On setting, if the new value is negative or greater than 100, then throw an IndexSizeError // exception. Otherwise, set the text track cue size to the new value. if (isInvalidPercentage(size, exceptionState)) return; // Otherwise, set the text track cue line position to the new value. if (m_cueSize == size) return; cueWillChange(); m_cueSize = size; cueDidChange(); }
void VTTCue::setPosition(int position, ExceptionState& exceptionState) { // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrackcue-position // On setting, if the new value is negative or greater than 100, then throw an IndexSizeError exception. // Otherwise, set the text track cue text position to the new value. if (isInvalidPercentage(position, exceptionState)) return; // Otherwise, set the text track cue line position to the new value. if (m_textPosition == position) return; cueWillChange(); m_textPosition = position; cueDidChange(); }
void VTTCue::setSize(double size, ExceptionState& exceptionState) { // http://dev.w3.org/html5/webvtt/#dfn-vttcue-size // On setting, if the new value is negative or greater than 100, then throw // an IndexSizeError exception. if (isInvalidPercentage(size, exceptionState)) return; // Otherwise, set the WebVTT cue size to the new value. float floatSize = narrowPrecisionToFloat(size); if (m_cueSize == floatSize) return; cueWillChange(); m_cueSize = floatSize; cueDidChange(); }
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; }
static bool scanPercentage(VTTScanner& input, float& number) { // http://dev.w3.org/html5/webvtt/#dfn-parse-a-percentage-string // 1. Let input be the string being parsed. // 2. If input contains any characters other than U+0025 PERCENT SIGN // characters (%), U+002E DOT characters (.) and ASCII digits, then // fail. // 3. If input does not contain at least one ASCII digit, then fail. // 4. If input contains more than one U+002E DOT character (.), then fail. // 5. If any character in input other than the last character is a U+0025 // PERCENT SIGN character (%), then fail. // 6. If the last character in input is not a U+0025 PERCENT SIGN character // (%), then fail. // 7. Ignoring the trailing percent sign, interpret input as a real // number. Let that number be the percentage. // 8. If percentage is outside the range 0..100, then fail. // 9. Return percentage. return input.scanPercentage(number) && !isInvalidPercentage(number); }