bool MediaControlsPainter::paintMediaCastButton(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& rect) { const HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; static Image* mediaCastOn = platformResource("mediaplayerCastOn", "mediaplayerCastOnNew"); static Image* mediaCastOff = platformResource("mediaplayerCastOff", "mediaplayerCastOffNew"); // To ensure that the overlaid cast button is visible when overlaid on pale videos we use a // different version of it for the overlaid case with a semi-opaque background. static Image* mediaOverlayCastOff = platformResource( "mediaplayerOverlayCastOff", "mediaplayerOverlayCastOffNew"); bool isEnabled = mediaElement->hasRemoteRoutes(); switch (mediaControlElementType(object.node())) { case MediaCastOnButton: return paintMediaButton(paintInfo.context, rect, mediaCastOn, isEnabled); case MediaOverlayCastOnButton: return paintMediaButton(paintInfo.context, rect, mediaCastOn); case MediaCastOffButton: return paintMediaButton(paintInfo.context, rect, mediaCastOff, isEnabled); case MediaOverlayCastOffButton: return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff); default: ASSERT_NOT_REACHED(); return false; } }
static bool paintMediaMuteButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3"); static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2"); static Image* soundLevel1 = platformResource("mediaplayerSoundLevel1"); static Image* soundLevel0 = platformResource("mediaplayerSoundLevel0"); static Image* soundDisabled = platformResource("mediaplayerSoundDisabled"); if (!hasSource(mediaElement) || !mediaElement->hasAudio()) return paintMediaButton(paintInfo.context, rect, soundDisabled); if (mediaElement->muted() || mediaElement->volume() <= 0) return paintMediaButton(paintInfo.context, rect, soundLevel0); if (mediaElement->volume() <= 0.33) return paintMediaButton(paintInfo.context, rect, soundLevel1); if (mediaElement->volume() <= 0.66) return paintMediaButton(paintInfo.context, rect, soundLevel2); return paintMediaButton(paintInfo.context, rect, soundLevel3); }
bool MediaControlsPainter::paintMediaMuteButton(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& rect) { const HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; // The new UI uses "muted" and "not muted" only. static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3", "mediaplayerSoundLevel3New"); static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2", "mediaplayerSoundLevel3New"); static Image* soundLevel1 = platformResource("mediaplayerSoundLevel1", "mediaplayerSoundLevel3New"); static Image* soundLevel0 = platformResource("mediaplayerSoundLevel0", "mediaplayerSoundLevel0New"); static Image* soundDisabled = platformResource("mediaplayerSoundDisabled", "mediaplayerSoundLevel0New"); if (!hasSource(mediaElement) || !mediaElement->hasAudio()) return paintMediaButton(paintInfo.context, rect, soundDisabled, false); if (mediaElement->muted() || mediaElement->volume() <= 0) return paintMediaButton(paintInfo.context, rect, soundLevel0); if (mediaElement->volume() <= 0.33) return paintMediaButton(paintInfo.context, rect, soundLevel1); if (mediaElement->volume() <= 0.66) return paintMediaButton(paintInfo.context, rect, soundLevel2); return paintMediaButton(paintInfo.context, rect, soundLevel3); }
void MediaControlsPainter::adjustMediaSliderThumbSize(ComputedStyle& style) { static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb", "mediaplayerSliderThumbNew"); static Image* mediaVolumeSliderThumb = platformResource( "mediaplayerVolumeSliderThumb", "mediaplayerVolumeSliderThumbNew"); int width = 0; int height = 0; Image* thumbImage = 0; if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { // Volume and time sliders are the same. thumbImage = mediaSliderThumb; width = mediaSliderThumbTouchWidthNew; height = mediaSliderThumbTouchHeightNew; } else if (style.appearance() == MediaSliderThumbPart) { thumbImage = mediaSliderThumb; width = mediaSliderThumbWidth; height = mediaSliderThumbHeight; } else if (style.appearance() == MediaVolumeSliderThumbPart) { thumbImage = mediaVolumeSliderThumb; width = mediaVolumeSliderThumbWidth; height = mediaVolumeSliderThumbHeight; } float zoomLevel = style.effectiveZoom(); if (thumbImage) { style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); } }
static bool paintMediaToggleClosedCaptionsButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; static Image* mediaClosedCaptionButton = platformResource("mediaplayerClosedCaption"); static Image* mediaClosedCaptionButtonDisabled = platformResource("mediaplayerClosedCaptionDisabled"); if (mediaElement->closedCaptionsVisible()) return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButton); return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButtonDisabled); }
static bool paintMediaMuteButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; static Image* soundFull = platformResource("mediaSoundFull"); static Image* soundNone = platformResource("mediaSoundNone"); static Image* soundDisabled = platformResource("mediaSoundDisabled"); if (!hasSource(mediaElement) || !mediaElement->hasAudio()) return paintMediaButton(paintInfo.context, rect, soundDisabled); return paintMediaButton(paintInfo.context, rect, mediaElement->muted() ? soundNone: soundFull); }
static bool paintMediaPlayButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; static Image* mediaPlay = platformResource("mediaPlay"); static Image* mediaPause = platformResource("mediaPause"); static Image* mediaPlayDisabled = platformResource("mediaPlayDisabled"); if (!hasSource(mediaElement)) return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled); return paintMediaButton(paintInfo.context, rect, mediaElement->canPlay() ? mediaPlay : mediaPause); }
bool MediaControlsPainter::paintMediaOverlayPlayButton(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& rect) { const HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; if (!hasSource(mediaElement) || !mediaElement->paused()) return false; static Image* mediaOverlayPlay = platformResource("mediaplayerOverlayPlay", "mediaplayerOverlayPlayNew"); IntRect buttonRect(rect); if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { // Overlay play button covers the entire player, so center and draw a // smaller button. Center in the entire element. const LayoutBox* box = mediaElement->layoutObject()->enclosingBox(); if (!box) return false; int mediaHeight = box->pixelSnappedHeight(); buttonRect.setX(rect.center().x() - mediaOverlayPlayButtonWidthNew / 2); buttonRect.setY(rect.center().y() - mediaOverlayPlayButtonHeightNew / 2 + (mediaHeight - rect.height()) / 2); buttonRect.setWidth(mediaOverlayPlayButtonWidthNew); buttonRect.setHeight(mediaOverlayPlayButtonHeightNew); } return paintMediaButton(paintInfo.context, buttonRect, mediaOverlayPlay); }
static bool paintMediaPlayButton(RenderObject* object, const RenderObject::PaintInfo& paintInfo, const IntRect& rect) { HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; static Image* mediaPlay = platformResource("mediaPlay"); static Image* mediaPause = platformResource("mediaPause"); static Image* mediaPlayDisabled = platformResource("mediaPlayDisabled"); if (mediaElement->networkState() == HTMLMediaElement::NETWORK_EMPTY || mediaElement->networkState() == HTMLMediaElement::NETWORK_NO_SOURCE) return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled); return paintMediaButton(paintInfo.context, rect, mediaElement->paused() ? mediaPlay : mediaPause); }
static bool paintMediaVolumeSliderThumb(RenderObject* object, const RenderObject::PaintInfo& paintInfo, const IntRect& rect) { if (!object->parent()->isSlider()) return false; static Image* mediaVolumeSliderThumb = platformResource("mediaVolumeSliderThumb"); return paintMediaButton(paintInfo.context, rect, mediaVolumeSliderThumb); }
void RenderMediaControlsChromium::adjustMediaSliderThumbSize(RenderStyle* style) { static Image* mediaSliderThumb = platformResource("mediaSliderThumb"); static Image* mediaVolumeSliderThumb = platformResource("mediaVolumeSliderThumb"); Image* thumbImage = 0; if (style->appearance() == MediaSliderThumbPart) thumbImage = mediaSliderThumb; else if (style->appearance() == MediaVolumeSliderThumbPart) thumbImage = mediaVolumeSliderThumb; float zoomLevel = style->effectiveZoom(); if (thumbImage) { style->setWidth(Length(static_cast<int>(thumbImage->width() * zoomLevel), Fixed)); style->setHeight(Length(static_cast<int>(thumbImage->height() * zoomLevel), Fixed)); } }
static bool paintMediaFullscreenButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; static Image* mediaFullscreenButton = platformResource("mediaplayerFullscreen"); return paintMediaButton(paintInfo.context, rect, mediaFullscreenButton); }
bool MediaControlsPainter::paintMediaPlayButton(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& rect) { const HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; static Image* mediaPlay = platformResource("mediaplayerPlay", "mediaplayerPlayNew"); static Image* mediaPause = platformResource("mediaplayerPause", "mediaplayerPauseNew"); // For this case, the new UI draws the normal icon, but the entire panel // grays out. static Image* mediaPlayDisabled = platformResource("mediaplayerPlayDisabled", "mediaplayerPlayNew"); if (!hasSource(mediaElement)) return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled, false); Image * image = !object.node()->isMediaControlElement() || mediaControlElementType(object.node()) == MediaPlayButton ? mediaPlay : mediaPause; return paintMediaButton(paintInfo.context, rect, image); }
static bool paintMediaFullscreenButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; DEFINE_STATIC_LOCAL(Image*, mediaFullscreen, (platformResource("mediaFullscreen"))); return paintMediaButton(paintInfo.context, rect, mediaFullscreen); }
bool MediaControlsPainter::paintMediaToggleClosedCaptionsButton(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& rect) { const HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; static Image* mediaClosedCaptionButton = platformResource( "mediaplayerClosedCaption", "mediaplayerClosedCaptionNew"); static Image* mediaClosedCaptionButtonDisabled = platformResource( "mediaplayerClosedCaptionDisabled", "mediaplayerClosedCaptionDisabledNew"); bool isEnabled = mediaElement->hasClosedCaptions(); if (mediaElement->closedCaptionsVisible()) return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButton, isEnabled); return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButtonDisabled, isEnabled); }
bool MediaControlsPainter::paintMediaFullscreenButton(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& rect) { const HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; // With the new player UI, we have separate assets for enter / exit // fullscreen mode. static Image* mediaEnterFullscreenButton = platformResource( "mediaplayerFullscreen", "mediaplayerEnterFullscreen"); static Image* mediaExitFullscreenButton = platformResource( "mediaplayerFullscreen", "mediaplayerExitFullscreen"); bool isEnabled = hasSource(mediaElement); if (mediaControlElementType(object.node()) == MediaExitFullscreenButton) return paintMediaButton(paintInfo.context, rect, mediaExitFullscreenButton, isEnabled); return paintMediaButton(paintInfo.context, rect, mediaEnterFullscreenButton, isEnabled); }
static bool paintMediaOverlayPlayButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; if (!hasSource(mediaElement) || !mediaElement->canPlay()) return false; static Image* mediaOverlayPlay = platformResource("mediaplayerOverlayPlay"); return paintMediaButton(paintInfo.context, rect, mediaOverlayPlay); }
static bool paintMediaVolumeSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { ASSERT(object->node()); HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadowHost()); if (!mediaElement) return false; if (!hasSource(mediaElement) || !mediaElement->hasAudio()) return true; static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSliderThumb"); return paintMediaButton(paintInfo.context, rect, mediaVolumeSliderThumb); }
static bool paintMediaSliderThumb(RenderObject* object, const RenderObject::PaintInfo& paintInfo, const IntRect& rect) { if (!object->parent()->isSlider()) return false; HTMLMediaElement* mediaElement = toParentMediaElement(object->parent()); if (!mediaElement) return false; if (!hasSource(mediaElement)) return true; static Image* mediaSliderThumb = platformResource("mediaSliderThumb"); return paintMediaButton(paintInfo.context, rect, mediaSliderThumb); }
void RenderMediaControls::adjustMediaSliderThumbSize(RenderStyle* style) { static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb"); static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSliderThumb"); int width = 0; int height = 0; Image* thumbImage = 0; if (style->appearance() == MediaSliderThumbPart) { thumbImage = mediaSliderThumb; width = mediaSliderThumbWidth; height = mediaSliderThumbHeight; } else if (style->appearance() == MediaVolumeSliderThumbPart) { thumbImage = mediaVolumeSliderThumb; width = mediaVolumeSliderThumbWidth; height = mediaVolumeSliderThumbHeight; } float zoomLevel = style->effectiveZoom(); if (thumbImage) { style->setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); style->setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); } }
bool MediaControlsPainter::paintMediaVolumeSliderThumb(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& rect) { if (!object.node()) return false; const HTMLMediaElement* mediaElement = toParentMediaElement(object.node()->shadowHost()); if (!mediaElement) return false; if (!hasSource(mediaElement) || !mediaElement->hasAudio()) return true; static Image* mediaVolumeSliderThumb = platformResource( "mediaplayerVolumeSliderThumb", "mediaplayerVolumeSliderThumbNew"); IntRect paintRect; const ComputedStyle& style = object.styleRef(); adjustMediaSliderThumbPaintSize(rect, style, paintRect); return paintMediaButton(paintInfo.context, paintRect, mediaVolumeSliderThumb); }
static bool paintMediaVolumeSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { static Image* mediaVolumeSliderThumb = platformResource("mediaVolumeSliderThumb"); return paintMediaButton(paintInfo.context, rect, mediaVolumeSliderThumb); }
static Image* getMediaSliderThumb() { static Image* mediaSliderThumb = platformResource("mediaSliderThumb"); return mediaSliderThumb; }
static Image* platformResource(const char* currentName, const char* newName) { // Return currentName or newName based on current or new playback. return platformResource(RuntimeEnabledFeatures::newMediaPlaybackUiEnabled() ? newName : currentName); }