JSValue jsHTMLMediaElementCurrentTime(ExecState* exec, JSValue slotBase, const Identifier&) { JSHTMLMediaElement* castedThis = static_cast<JSHTMLMediaElement*>(asObject(slotBase)); UNUSED_PARAM(exec); HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(castedThis->impl()); JSValue result = jsNumber(imp->currentTime()); return result; }
static bool paintMediaSlider(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; RenderStyle* style = object->style(); GraphicsContext* context = paintInfo.context; paintRoundedSliderBackground(rect, style, context); // Draw the buffered range. Since the element may have multiple buffered ranges and it'd be // distracting/'busy' to show all of them, show only the buffered range containing the current play head. RefPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered(); float duration = mediaElement->duration(); float currentTime = mediaElement->currentTime(); if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan(currentTime)) return true; for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) { float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION); float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION); if (std::isnan(start) || std::isnan(end) || start > currentTime || end < currentTime) continue; int startPosition = int(start * rect.width() / duration); int currentPosition = int(currentTime * rect.width() / duration); int endPosition = int(end * rect.width() / duration); // Add half the thumb width proportionally adjusted to the current painting position. int thumbCenter = mediaSliderThumbWidth / 2; int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width()); currentPosition += addWidth; // Draw white-ish highlight before current time. Color startColor = Color(195, 195, 195); Color endColor = Color(217, 217, 217); if (currentPosition > startPosition) paintSliderRangeHighlight(rect, style, context, startPosition, currentPosition, startColor, endColor); // Draw grey-ish highlight after current time. startColor = Color(60, 60, 60); endColor = Color(76, 76, 76); if (endPosition > currentPosition) paintSliderRangeHighlight(rect, style, context, currentPosition, endPosition, startColor, endColor); return true; } return true; }
bool RenderThemeWinCE::paintSliderThumb(RenderObject* o, const PaintInfo& i, const IntRect& r) { bool rc = RenderTheme::paintSliderThumb(o, i, r); i.context->save(); i.context->setStrokeColor(Color::black, ColorSpaceDeviceRGB); i.context->setFillColor(Color::black, ColorSpaceDeviceRGB); #if ENABLE(VIDEO) HTMLMediaElement* mediaElement = mediaElementParent(o->node()); if (mediaElement) { float pt = (mediaElement->currentTime() - mediaElement->startTime()) / mediaElement->duration(); FloatRect intRect = r; intRect.setX(intRect.x() + intRect.width() * pt - 2); intRect.setWidth(5); i.context->fillRect(intRect); } #endif i.context->restore(); return rc; }
JSValue* JSHTMLMediaElement::getValueProperty(ExecState* exec, int token) const { switch (token) { case ErrorAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return toJS(exec, WTF::getPtr(imp->error())); } case SrcAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsString(exec, imp->src()); } case CurrentSrcAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsString(exec, imp->currentSrc()); } case NetworkStateAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->networkState()); } case BufferingRateAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->bufferingRate()); } case BufferedAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return toJS(exec, WTF::getPtr(imp->buffered())); } case ReadyStateAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->readyState()); } case SeekingAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsBoolean(imp->seeking()); } case CurrentTimeAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->currentTime()); } case DurationAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->duration()); } case PausedAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsBoolean(imp->paused()); } case DefaultPlaybackRateAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->defaultPlaybackRate()); } case PlaybackRateAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->playbackRate()); } case PlayedAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return toJS(exec, WTF::getPtr(imp->played())); } case SeekableAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return toJS(exec, WTF::getPtr(imp->seekable())); } case EndedAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsBoolean(imp->ended()); } case AutoplayAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsBoolean(imp->autoplay()); } case StartAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->start()); } case EndAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->end()); } case LoopStartAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->loopStart()); } case LoopEndAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->loopEnd()); } case PlayCountAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->playCount()); } case CurrentLoopAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->currentLoop()); } case ControlsAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsBoolean(imp->controls()); } case VolumeAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsNumber(exec, imp->volume()); } case MutedAttrNum: { HTMLMediaElement* imp = static_cast<HTMLMediaElement*>(impl()); return jsBoolean(imp->muted()); } case ConstructorAttrNum: return getConstructor(exec); } return 0; }