Commit 40f54733 authored by eric@webkit.org's avatar eric@webkit.org

2009-10-07 Andrew Scherkus <scherkus@chromium.org>

        Reviewed by Eric Carlson.

        Refactor RenderThemeChromiumMac and RenderThemeChromiumSkia to render media controls using GraphicsContext.

        Design was based on existing RenderMediaControls.cpp used by RenderThemeSafari/Win.

        https://bugs.webkit.org/show_bug.cgi?id=29987

        Covered by existing layout tests as no new functionality was introduced.

        * WebCore.gypi: Added RenderMediaControlsChromium.cpp/h.
        * css/mediaControlsChromium.css: Tweaked media slider position and border style.
        * rendering/MediaControlElements.cpp:
        (WebCore::toParentMediaElement): Taken from RenderMediaControls.
        (WebCore::MediaControlElement::rendererIsNeeded): Don't call shouldRenderMediaControlPart() if element has no appearance.
        (WebCore::MediaControlInputElement::rendererIsNeeded): Ditto.
        * rendering/RenderMediaControls.cpp: Moved parentMediaElement() to MediaControlElements.
        * rendering/RenderMediaControlsChromium.cpp: Added.
        (WebCore::platformResource): Helper to load and cache media control image resources.
        (WebCore::mediaSliderThumbImage): Implementation refactored from RenderThemeChromiumMac/Skia.
        (WebCore::mediaVolumeSliderThumbImage): Ditto.
        (WebCore::paintMediaButton): Ditto.
        (WebCore::paintMediaMuteButton): Ditto.
        (WebCore::paintMediaPlayButton): Ditto.
        (WebCore::paintMediaSlider): Ditto.
        (WebCore::paintMediaSliderThumb): Ditto.
        (WebCore::paintMediaVolumeSlider): Ditto.
        (WebCore::paintMediaVolumeSliderThumb): Ditto.
        (WebCore::paintMediaTimelineContainer): Ditto.
        (WebCore::RenderMediaControlsChromium::shouldRenderMediaControlPart): Ditto.
        (WebCore::RenderMediaControlsChromium::paintMediaControlsPart): Same
        (WebCore::RenderMediaControlsChromium::adjustMediaSliderThumbSize):
        * rendering/RenderMediaControlsChromium.h: Added.
        * rendering/RenderThemeChromiumMac.h:
        * rendering/RenderThemeChromiumMac.mm:
        (WebCore::RenderThemeChromiumMac::adjustSliderThumbSize): Implementation delegated to RenderMediaControlsChromium.
        (WebCore::RenderThemeChromiumMac::shouldRenderMediaControlPart): Ditto.
        (WebCore::RenderThemeChromiumMac::paintMediaPlayButton): Ditto.
        (WebCore::RenderThemeChromiumMac::paintMediaMuteButton): Ditto.
        (WebCore::RenderThemeChromiumMac::paintMediaSliderTrack): Ditto.
        (WebCore::RenderThemeChromiumMac::paintMediaVolumeSliderTrack): Ditto.
        (WebCore::RenderThemeChromiumMac::paintMediaSliderThumb): Ditto.
        (WebCore::RenderThemeChromiumMac::paintMediaVolumeSliderThumb): Ditto.
        (WebCore::RenderThemeChromiumMac::paintMediaControlsBackground): Ditto.
        * rendering/RenderThemeChromiumSkia.cpp:
        (WebCore::RenderThemeChromiumSkia::paintMediaControlsBackground): Implementation delegated to RenderMediaControlsChromium.
        (WebCore::RenderThemeChromiumSkia::paintMediaSliderTrack): Ditto.
        (WebCore::RenderThemeChromiumSkia::paintMediaVolumeSliderTrack): Ditto.
        (WebCore::RenderThemeChromiumSkia::adjustSliderThumbSize): Ditto.
        (WebCore::RenderThemeChromiumSkia::paintMediaSliderThumb): Ditto.
        (WebCore::RenderThemeChromiumSkia::paintMediaVolumeSliderThumb): Ditto.
        (WebCore::RenderThemeChromiumSkia::paintMediaPlayButton): Ditto.
        (WebCore::RenderThemeChromiumSkia::paintMediaMuteButton): Ditto.
        (WebCore::RenderThemeChromiumSkia::shouldRenderMediaControlPart): Ditto.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49259 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9bdf0fc8
2009-10-07 Andrew Scherkus <scherkus@chromium.org>
Reviewed by Eric Carlson.
Refactor RenderThemeChromiumMac and RenderThemeChromiumSkia to render media controls using GraphicsContext.
Design was based on existing RenderMediaControls.cpp used by RenderThemeSafari/Win.
https://bugs.webkit.org/show_bug.cgi?id=29987
Covered by existing layout tests as no new functionality was introduced.
* WebCore.gypi: Added RenderMediaControlsChromium.cpp/h.
* css/mediaControlsChromium.css: Tweaked media slider position and border style.
* rendering/MediaControlElements.cpp:
(WebCore::toParentMediaElement): Taken from RenderMediaControls.
(WebCore::MediaControlElement::rendererIsNeeded): Don't call shouldRenderMediaControlPart() if element has no appearance.
(WebCore::MediaControlInputElement::rendererIsNeeded): Ditto.
* rendering/RenderMediaControls.cpp: Moved parentMediaElement() to MediaControlElements.
* rendering/RenderMediaControlsChromium.cpp: Added.
(WebCore::platformResource): Helper to load and cache media control image resources.
(WebCore::mediaSliderThumbImage): Implementation refactored from RenderThemeChromiumMac/Skia.
(WebCore::mediaVolumeSliderThumbImage): Ditto.
(WebCore::paintMediaButton): Ditto.
(WebCore::paintMediaMuteButton): Ditto.
(WebCore::paintMediaPlayButton): Ditto.
(WebCore::paintMediaSlider): Ditto.
(WebCore::paintMediaSliderThumb): Ditto.
(WebCore::paintMediaVolumeSlider): Ditto.
(WebCore::paintMediaVolumeSliderThumb): Ditto.
(WebCore::paintMediaTimelineContainer): Ditto.
(WebCore::RenderMediaControlsChromium::shouldRenderMediaControlPart): Ditto.
(WebCore::RenderMediaControlsChromium::paintMediaControlsPart): Same
(WebCore::RenderMediaControlsChromium::adjustMediaSliderThumbSize):
* rendering/RenderMediaControlsChromium.h: Added.
* rendering/RenderThemeChromiumMac.h:
* rendering/RenderThemeChromiumMac.mm:
(WebCore::RenderThemeChromiumMac::adjustSliderThumbSize): Implementation delegated to RenderMediaControlsChromium.
(WebCore::RenderThemeChromiumMac::shouldRenderMediaControlPart): Ditto.
(WebCore::RenderThemeChromiumMac::paintMediaPlayButton): Ditto.
(WebCore::RenderThemeChromiumMac::paintMediaMuteButton): Ditto.
(WebCore::RenderThemeChromiumMac::paintMediaSliderTrack): Ditto.
(WebCore::RenderThemeChromiumMac::paintMediaVolumeSliderTrack): Ditto.
(WebCore::RenderThemeChromiumMac::paintMediaSliderThumb): Ditto.
(WebCore::RenderThemeChromiumMac::paintMediaVolumeSliderThumb): Ditto.
(WebCore::RenderThemeChromiumMac::paintMediaControlsBackground): Ditto.
* rendering/RenderThemeChromiumSkia.cpp:
(WebCore::RenderThemeChromiumSkia::paintMediaControlsBackground): Implementation delegated to RenderMediaControlsChromium.
(WebCore::RenderThemeChromiumSkia::paintMediaSliderTrack): Ditto.
(WebCore::RenderThemeChromiumSkia::paintMediaVolumeSliderTrack): Ditto.
(WebCore::RenderThemeChromiumSkia::adjustSliderThumbSize): Ditto.
(WebCore::RenderThemeChromiumSkia::paintMediaSliderThumb): Ditto.
(WebCore::RenderThemeChromiumSkia::paintMediaVolumeSliderThumb): Ditto.
(WebCore::RenderThemeChromiumSkia::paintMediaPlayButton): Ditto.
(WebCore::RenderThemeChromiumSkia::paintMediaMuteButton): Ditto.
(WebCore::RenderThemeChromiumSkia::shouldRenderMediaControlPart): Ditto.
2009-10-07 Dave Hyatt <hyatt@apple.com>
Reviewed by Adam Roben.
......@@ -2941,6 +2941,8 @@
'rendering/RenderMarquee.h',
'rendering/RenderMedia.cpp',
'rendering/RenderMedia.h',
'rendering/RenderMediaControlsChromium.cpp',
'rendering/RenderMediaControlsChromium.h',
'rendering/RenderMenuList.cpp',
'rendering/RenderMenuList.h',
'rendering/RenderObject.cpp',
......
......@@ -83,8 +83,8 @@ audio::-webkit-media-controls-timeline-container, video::-webkit-media-controls-
width: auto;
height: 32px;
border-left-color: rgba(255, 255, 255, 0.2);
border-right-color: rgba(255, 255, 255, 0.2);
border-left: 1px solid rgba(255, 255, 255, 0.2);
border-right: 1px solid rgba(255, 255, 255, 0.2);
}
audio::-webkit-media-controls-current-time-display, video::-webkit-media-controls-current-time-display {
......@@ -141,7 +141,7 @@ audio::-webkit-media-controls-timeline, video::-webkit-media-controls-timeline {
-webkit-appearance: media-slider;
position: absolute;
top: auto;
bottom: 8px;
bottom: 7px;
left: 6px;
right: 65px;
height: 16px;
......
......@@ -46,6 +46,16 @@ namespace WebCore {
using namespace HTMLNames;
HTMLMediaElement* toParentMediaElement(RenderObject* o)
{
Node* node = o->node();
Node* mediaNode = node ? node->shadowAncestorNode() : 0;
if (!mediaNode || (!mediaNode->hasTagName(HTMLNames::videoTag) && !mediaNode->hasTagName(HTMLNames::audioTag)))
return 0;
return static_cast<HTMLMediaElement*>(mediaNode);
}
// FIXME: These constants may need to be tweaked to better match the seeking in the QuickTime plug-in.
static const float cSeekRepeatDelay = 0.1f;
static const float cStepTime = 0.07f;
......@@ -138,7 +148,7 @@ bool MediaControlElement::rendererIsNeeded(RenderStyle* style)
ASSERT(document()->page());
return HTMLDivElement::rendererIsNeeded(style) && parent() && parent()->renderer()
&& document()->page()->theme()->shouldRenderMediaControlPart(style->appearance(), m_mediaElement);
&& (!style->hasAppearance() || document()->page()->theme()->shouldRenderMediaControlPart(style->appearance(), m_mediaElement));
}
void MediaControlElement::attach()
......@@ -366,7 +376,7 @@ bool MediaControlInputElement::rendererIsNeeded(RenderStyle* style)
ASSERT(document()->page());
return HTMLInputElement::rendererIsNeeded(style) && parent() && parent()->renderer()
&& document()->page()->theme()->shouldRenderMediaControlPart(style->appearance(), m_mediaElement);
&& (!style->hasAppearance() || document()->page()->theme()->shouldRenderMediaControlPart(style->appearance(), m_mediaElement));
}
void MediaControlInputElement::attach()
......
......@@ -66,6 +66,8 @@ enum MediaControlElementType {
MediaVolumeSliderThumb
};
HTMLMediaElement* toParentMediaElement(RenderObject*);
class MediaControlShadowRootElement : public HTMLDivElement {
public:
MediaControlShadowRootElement(Document*, HTMLMediaElement*);
......
......@@ -82,16 +82,6 @@ void RenderMediaControls::adjustMediaSliderThumbSize(RenderObject* o)
o->style()->setHeight(Length(static_cast<int>(mediaSliderThumbHeight * zoomLevel), Fixed));
}
static HTMLMediaElement* parentMediaElement(RenderObject* o)
{
Node* node = o->node();
Node* mediaNode = node ? node->shadowAncestorNode() : 0;
if (!mediaNode || (!mediaNode->hasTagName(HTMLNames::videoTag) && !mediaNode->hasTagName(HTMLNames::audioTag)))
return 0;
return static_cast<HTMLMediaElement*>(mediaNode);
}
bool RenderMediaControls::paintMediaControlsPart(MediaControlElementType part, RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
ASSERT(SafariThemeLibrary());
......@@ -121,7 +111,7 @@ bool RenderMediaControls::paintMediaControlsPart(MediaControlElementType part, R
paintThemePart(SafariTheme::MediaSeekForwardButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
break;
case MediaSlider: {
if (HTMLMediaElement* mediaElement = parentMediaElement(o))
if (HTMLMediaElement* mediaElement = toParentMediaElement(o))
STPaintProgressIndicator(SafariTheme::MediaType, paintInfo.context->platformContext(), r, NSRegularControlSize, 0, mediaElement->percentLoaded());
break;
}
......@@ -159,4 +149,3 @@ bool RenderMediaControls::paintMediaControlsPart(MediaControlElementType part, R
#endif // #if ENABLE(VIDEO)
} // namespace WebCore
/*
* Copyright (C) 2009 Apple Inc.
* Copyright (C) 2009 Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "RenderMediaControlsChromium.h"
#include "Gradient.h"
#include "GraphicsContext.h"
#include "HTMLMediaElement.h"
#include "HTMLNames.h"
namespace WebCore {
#if ENABLE(VIDEO)
typedef WTF::HashMap<const char*, Image*> MediaControlImageMap;
static MediaControlImageMap* gMediaControlImageMap = 0;
static Image* platformResource(const char* name)
{
if (!gMediaControlImageMap)
gMediaControlImageMap = new MediaControlImageMap();
if (Image* image = gMediaControlImageMap->get(name))
return image;
if (Image* image = Image::loadPlatformResource(name).releaseRef()) {
gMediaControlImageMap->set(name, image);
return image;
}
ASSERT_NOT_REACHED();
return 0;
}
static bool paintMediaButton(GraphicsContext* context, const IntRect& rect, Image* image)
{
// Create a destination rectangle for the image that is centered in the drawing rectangle, rounded left, and down.
IntRect imageRect = image->rect();
imageRect.setY(rect.y() + (rect.height() - image->height() + 1) / 2);
imageRect.setX(rect.x() + (rect.width() - image->width() + 1) / 2);
context->drawImage(image, imageRect);
return true;
}
static bool paintMediaMuteButton(RenderObject* object, const RenderObject::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 (mediaElement->networkState() == HTMLMediaElement::NETWORK_NO_SOURCE || !mediaElement->hasAudio())
return paintMediaButton(paintInfo.context, rect, soundDisabled);
return paintMediaButton(paintInfo.context, rect, mediaElement->muted() ? soundNone: soundFull);
}
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_NO_SOURCE)
return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled);
return paintMediaButton(paintInfo.context, rect, mediaElement->paused() ? mediaPlay : mediaPause);
}
static bool paintMediaSlider(RenderObject* object, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
{
HTMLMediaElement* mediaElement = toParentMediaElement(object);
if (!mediaElement)
return false;
RenderStyle* style = object->style();
GraphicsContext* context = paintInfo.context;
// Draw the border of the time bar.
// FIXME: this should be a rounded rect but need to fix GraphicsContextSkia first.
// https://bugs.webkit.org/show_bug.cgi?id=30143
context->save();
context->setStrokeStyle(SolidStroke);
context->setStrokeColor(style->borderLeftColor());
context->setStrokeThickness(style->borderLeftWidth());
context->setFillColor(style->backgroundColor());
context->drawRect(rect);
context->restore();
// Draw the buffered ranges.
// FIXME: Draw multiple ranges if there are multiple buffered ranges.
// FIXME: percentLoaded() doesn't always hit 1.0 so we're using round().
IntRect bufferedRect = rect;
bufferedRect.inflate(-style->borderLeftWidth());
bufferedRect.setWidth(round((bufferedRect.width() * mediaElement->percentLoaded())));
// Don't bother drawing an empty area.
if (!bufferedRect.isEmpty()) {
IntPoint sliderTopLeft = bufferedRect.location();
IntPoint sliderTopRight = sliderTopLeft;
sliderTopRight.move(0, bufferedRect.height());
RefPtr<Gradient> gradient = Gradient::create(sliderTopLeft, sliderTopRight);
Color startColor = object->style()->color();
gradient->addColorStop(0.0, startColor);
gradient->addColorStop(1.0, Color(startColor.red() / 2, startColor.green() / 2, startColor.blue() / 2, startColor.alpha()));
context->save();
context->setStrokeStyle(NoStroke);
context->setFillGradient(gradient);
context->drawRect(bufferedRect);
context->restore();
}
return true;
}
static bool paintMediaSliderThumb(RenderObject* object, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
{
if (!object->parent()->isSlider())
return false;
static Image* mediaSliderThumb = platformResource("mediaSliderThumb");
return paintMediaButton(paintInfo.context, rect, mediaSliderThumb);
}
static bool paintMediaVolumeSlider(RenderObject* object, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
{
HTMLMediaElement* mediaElement = toParentMediaElement(object);
if (!mediaElement)
return false;
GraphicsContext* context = paintInfo.context;
Color originalColor = context->strokeColor();
if (originalColor != Color::white)
context->setStrokeColor(Color::white);
int x = rect.x() + rect.width() / 2;
context->drawLine(IntPoint(x, rect.y()), IntPoint(x, rect.y() + rect.height()));
if (originalColor != Color::white)
context->setStrokeColor(originalColor);
return true;
}
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);
}
static bool paintMediaTimelineContainer(RenderObject* object, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
{
HTMLMediaElement* mediaElement = toParentMediaElement(object);
if (!mediaElement)
return false;
if (!rect.isEmpty()) {
GraphicsContext* context = paintInfo.context;
Color originalColor = context->strokeColor();
float originalThickness = context->strokeThickness();
StrokeStyle originalStyle = context->strokeStyle();
context->setStrokeStyle(SolidStroke);
// Draw the left border using CSS defined width and color.
context->setStrokeThickness(object->style()->borderLeftWidth());
context->setStrokeColor(object->style()->borderLeftColor().rgb());
context->drawLine(IntPoint(rect.x() + 1, rect.y()),
IntPoint(rect.x() + 1, rect.y() + rect.height()));
// Draw the right border using CSS defined width and color.
context->setStrokeThickness(object->style()->borderRightWidth());
context->setStrokeColor(object->style()->borderRightColor().rgb());
context->drawLine(IntPoint(rect.x() + rect.width() - 1, rect.y()),
IntPoint(rect.x() + rect.width() - 1, rect.y() + rect.height()));
context->setStrokeColor(originalColor);
context->setStrokeThickness(originalThickness);
context->setStrokeStyle(originalStyle);
}
return true;
}
bool RenderMediaControlsChromium::shouldRenderMediaControlPart(ControlPart part, Element* e)
{
UNUSED_PARAM(e);
switch (part) {
case MediaMuteButtonPart:
case MediaPlayButtonPart:
case MediaSliderPart:
case MediaSliderThumbPart:
case MediaVolumeSliderContainerPart:
case MediaVolumeSliderPart:
case MediaVolumeSliderThumbPart:
case MediaControlsBackgroundPart:
case MediaCurrentTimePart:
case MediaTimeRemainingPart:
return true;
}
return false;
}
bool RenderMediaControlsChromium::paintMediaControlsPart(MediaControlElementType part, RenderObject* object, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
{
switch (part) {
case MediaMuteButton:
case MediaUnMuteButton:
return paintMediaMuteButton(object, paintInfo, rect);
case MediaPauseButton:
case MediaPlayButton:
return paintMediaPlayButton(object, paintInfo, rect);
case MediaSlider:
return paintMediaSlider(object, paintInfo, rect);
case MediaSliderThumb:
return paintMediaSliderThumb(object, paintInfo, rect);
case MediaVolumeSlider:
return paintMediaVolumeSlider(object, paintInfo, rect);
case MediaVolumeSliderThumb:
return paintMediaVolumeSliderThumb(object, paintInfo, rect);
case MediaTimelineContainer:
return paintMediaTimelineContainer(object, paintInfo, rect);
case MediaFullscreenButton:
case MediaSeekBackButton:
case MediaSeekForwardButton:
case MediaVolumeSliderContainer:
case MediaCurrentTimeDisplay:
case MediaTimeRemainingDisplay:
case MediaControlsPanel:
ASSERT_NOT_REACHED();
break;
}
return false;
}
void RenderMediaControlsChromium::adjustMediaSliderThumbSize(RenderObject* object)
{
static Image* mediaSliderThumb = platformResource("mediaSliderThumb");
static Image* mediaVolumeSliderThumb = platformResource("mediaVolumeSliderThumb");
Image* thumbImage = 0;
if (object->style()->appearance() == MediaSliderThumbPart)
thumbImage = mediaSliderThumb;
else if (object->style()->appearance() == MediaVolumeSliderThumbPart)
thumbImage = mediaVolumeSliderThumb;
if (thumbImage) {
object->style()->setWidth(Length(thumbImage->width(), Fixed));
object->style()->setHeight(Length(thumbImage->height(), Fixed));
}
}
#endif // #if ENABLE(VIDEO)
} // namespace WebCore
/*
* Copyright (C) 2009 Apple Inc.
* Copyright (C) 2009 Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef RenderMediaControlsChromium_h
#define RenderMediaControlsChromium_h
#include "RenderObject.h"
#include "MediaControlElements.h"
namespace WebCore {
class HTMLMediaElement;
class RenderMediaControlsChromium {
public:
static bool shouldRenderMediaControlPart(ControlPart, Element*);
static bool paintMediaControlsPart(MediaControlElementType, RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
static void adjustMediaSliderThumbSize(RenderObject*);
};
} // namespace WebCore
#endif // RenderMediaControlsChromium_h
......@@ -121,6 +121,7 @@ protected:
virtual bool paintSearchFieldResultsButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
#if ENABLE(VIDEO)
virtual bool shouldRenderMediaControlPart(ControlPart, Element*);
virtual bool paintMediaPlayButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
virtual bool paintMediaMuteButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
virtual bool paintMediaSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
......
......@@ -29,7 +29,6 @@
#import "Document.h"
#import "Element.h"
#import "FrameView.h"
#import "Gradient.h"
#import "GraphicsContext.h"
#import "HTMLInputElement.h"
#import "HTMLMediaElement.h"
......@@ -38,6 +37,7 @@
#import "LocalCurrentGraphicsContext.h"
#import "MediaControlElements.h"
#import "RenderMedia.h"
#import "RenderMediaControlsChromium.h"
#import "RenderSlider.h"
#import "RenderView.h"
#import "SharedBuffer.h"
......@@ -1251,20 +1251,6 @@ bool RenderThemeChromiumMac::paintSliderThumb(RenderObject* o, const RenderObjec
return false;
}
#if ENABLE(VIDEO)
static Image* mediaSliderThumbImage()
{
static Image* mediaSliderThumb = Image::loadPlatformResource("mediaSliderThumb").releaseRef();
return mediaSliderThumb;
}
static Image* mediaVolumeSliderThumbImage()
{
static Image* mediaVolumeSliderThumb = Image::loadPlatformResource("mediaVolumeSliderThumb").releaseRef();
return mediaVolumeSliderThumb;
}
#endif
void RenderThemeChromiumMac::adjustSliderThumbSize(RenderObject* o) const
{
static const int sliderThumbWidth = 15;
......@@ -1277,16 +1263,7 @@ void RenderThemeChromiumMac::adjustSliderThumbSize(RenderObject* o) const
}
#if ENABLE(VIDEO)
Image* thumbImage = 0;
if (o->style()->appearance() == MediaSliderThumbPart)
thumbImage = mediaSliderThumbImage();
else if (o->style()->appearance() == MediaVolumeSliderThumbPart)
thumbImage = mediaVolumeSliderThumbImage();
if (thumbImage) {
o->style()->setWidth(Length(thumbImage->width(), Fixed));
o->style()->setHeight(Length(thumbImage->height(), Fixed));
}
RenderMediaControlsChromium::adjustMediaSliderThumbSize(o);
#endif
}
......@@ -1537,173 +1514,44 @@ bool RenderThemeChromiumMac::paintSearchFieldResultsButton(RenderObject* o, cons
}
#if ENABLE(VIDEO)
// Attempt to retrieve a HTMLMediaElement from a Node. Returns 0 if one cannot be found.
static HTMLMediaElement* mediaElementParent(Node* node)
{
if (!node)
return 0;
Node* mediaNode = node->shadowAncestorNode();
if (!mediaNode || (!mediaNode->hasTagName(HTMLNames::videoTag) && !mediaNode->hasTagName(HTMLNames::audioTag)))
return 0;
return static_cast<HTMLMediaElement*>(mediaNode);
}
bool RenderThemeChromiumMac::paintMediaButtonInternal(GraphicsContext* context, const IntRect& rect, Image* image)
bool RenderThemeChromiumMac::shouldRenderMediaControlPart(ControlPart part, Element* e)
{
// Create a destination rectangle for the image that is centered in the drawing rectangle, rounded left, and down.
IntRect imageRect = image->rect();
imageRect.setY(rect.y() + (rect.height() - image->height() + 1) / 2);
imageRect.setX(rect.x() + (rect.width() - image->width() + 1) / 2);
context->drawImage(image, imageRect);
return true;
return RenderMediaControlsChromium::shouldRenderMediaControlPart(part, e);
}
bool RenderThemeChromiumMac::paintMediaPlayButton(RenderObject* object, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
{
HTMLMediaElement* mediaElement = mediaElementParent(object->node());
if (!mediaElement)
return false;
static Image* mediaPlay = Image::loadPlatformResource("mediaPlay").releaseRef();
static Image* mediaPause = Image::loadPlatformResource("mediaPause").releaseRef();
static Image* mediaPlayDisabled = Image::loadPlatformResource("mediaPlayDisabled").releaseRef();
if (mediaElement->networkState() == HTMLMediaElement::NETWORK_NO_SOURCE)
return paintMediaButtonInternal(paintInfo.context, rect, mediaPlayDisabled);
return paintMediaButtonInternal(paintInfo.context, rect, mediaElement->paused() ? mediaPlay : mediaPause);
return RenderMediaControlsChromium::paintMediaControlsPart(MediaPlayButton, object, paintInfo, rect);
}
bool RenderThemeChromiumMac::paintMediaMuteButton(RenderObject* object, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
{
HTMLMediaElement* mediaElement = mediaElementParent(object->node());
if (!mediaElement)