15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
21e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * Copyright (C) 2009 Apple Inc.
31e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * Copyright (C) 2009 Google Inc.
41e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * All rights reserved.
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met:
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderMediaControls.h"
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
31197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ExceptionStatePlaceholder.h"
321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/html/HTMLMediaElement.h"
331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/html/TimeRanges.h"
341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/rendering/PaintInfo.h"
35a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/Gradient.h"
36a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/GraphicsContext.h"
3702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
38c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)typedef WTF::HashMap<const char*, Image*> MediaControlImageMap;
411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static MediaControlImageMap* gMediaControlImageMap = 0;
421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static Image* platformResource(const char* name)
441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!gMediaControlImageMap)
461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        gMediaControlImageMap = new MediaControlImageMap();
471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (Image* image = gMediaControlImageMap->get(name))
481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return image;
491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (Image* image = Image::loadPlatformResource(name).leakRef()) {
501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        gMediaControlImageMap->set(name, image);
511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return image;
521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ASSERT_NOT_REACHED();
541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return 0;
551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool hasSource(const HTMLMediaElement* mediaElement)
581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return mediaElement->networkState() != HTMLMediaElement::NETWORK_EMPTY
601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        && mediaElement->networkState() != HTMLMediaElement::NETWORK_NO_SOURCE;
611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool paintMediaButton(GraphicsContext* context, const IntRect& rect, Image* image)
641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    context->drawImage(image, rect);
661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return true;
671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool paintMediaMuteButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    HTMLMediaElement* mediaElement = toParentMediaElement(object);
721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!mediaElement)
731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return false;
741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3");
761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2");
771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* soundLevel1 = platformResource("mediaplayerSoundLevel1");
781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* soundLevel0 = platformResource("mediaplayerSoundLevel0");
791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* soundDisabled = platformResource("mediaplayerSoundDisabled");
801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!hasSource(mediaElement) || !mediaElement->hasAudio())
821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaButton(paintInfo.context, rect, soundDisabled);
831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
841e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (mediaElement->muted() || mediaElement->volume() <= 0)
851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaButton(paintInfo.context, rect, soundLevel0);
861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (mediaElement->volume() <= 0.33)
881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaButton(paintInfo.context, rect, soundLevel1);
891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (mediaElement->volume() <= 0.66)
911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaButton(paintInfo.context, rect, soundLevel2);
921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return paintMediaButton(paintInfo.context, rect, soundLevel3);
941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool paintMediaPlayButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    HTMLMediaElement* mediaElement = toParentMediaElement(object);
991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!mediaElement)
1001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return false;
1011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaPlay = platformResource("mediaplayerPlay");
1031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaPause = platformResource("mediaplayerPause");
1041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaPlayDisabled = platformResource("mediaplayerPlayDisabled");
1051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!hasSource(mediaElement))
1071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled);
1081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
10910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    return paintMediaButton(paintInfo.context, rect, mediaControlElementType(object->node()) == MediaPlayButton ? mediaPlay : mediaPause);
1101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
1111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool paintMediaOverlayPlayButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
1131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
1141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    HTMLMediaElement* mediaElement = toParentMediaElement(object);
1151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!mediaElement)
1161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return false;
1171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
11807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    if (!hasSource(mediaElement) || !mediaElement->togglePlayStateWillPlay())
1191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return false;
1201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaOverlayPlay = platformResource("mediaplayerOverlayPlay");
1221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return paintMediaButton(paintInfo.context, rect, mediaOverlayPlay);
12353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
1241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static Image* getMediaSliderThumb()
1261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
1271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb");
1281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return mediaSliderThumb;
1291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
1301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static void paintRoundedSliderBackground(const IntRect& rect, const RenderStyle* style, GraphicsContext* context)
1321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
1331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int borderRadius = rect.height() / 2;
1341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    IntSize radii(borderRadius, borderRadius);
1351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    Color sliderBackgroundColor = Color(11, 11, 11);
1361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    context->fillRoundedRect(rect, radii, radii, radii, radii, sliderBackgroundColor);
1371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
1381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static void paintSliderRangeHighlight(const IntRect& rect, const RenderStyle* style, GraphicsContext* context, int startPosition, int endPosition, Color startColor, Color endColor)
1401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
1411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Calculate border radius; need to avoid being smaller than half the slider height
1421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // because of https://bugs.webkit.org/show_bug.cgi?id=30143.
1431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int borderRadius = rect.height() / 2;
1441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    IntSize radii(borderRadius, borderRadius);
1451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Calculate highlight rectangle and edge dimensions.
1471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int startOffset = startPosition;
1481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int endOffset = rect.width() - endPosition;
1491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int rangeWidth = endPosition - startPosition;
1501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (rangeWidth <= 0)
1521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return;
1531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Make sure the range width is bigger than border radius at the edges to retain rounded corners.
1551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (startOffset < borderRadius && rangeWidth < borderRadius)
1561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        rangeWidth = borderRadius;
15709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (endOffset < borderRadius && rangeWidth < borderRadius)
1581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        rangeWidth = borderRadius;
1591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Set rectangle to highlight range.
1611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    IntRect highlightRect = rect;
1621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    highlightRect.move(startOffset, 0);
1631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    highlightRect.setWidth(rangeWidth);
1641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Don't bother drawing an empty area.
1661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (highlightRect.isEmpty())
1671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return;
1681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Calculate white-grey gradient.
1701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    IntPoint sliderTopLeft = highlightRect.location();
1711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    IntPoint sliderBottomLeft = sliderTopLeft;
1721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    sliderBottomLeft.move(0, highlightRect.height());
1731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    RefPtr<Gradient> gradient = Gradient::create(sliderTopLeft, sliderBottomLeft);
1741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    gradient->addColorStop(0.0, startColor);
1751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    gradient->addColorStop(1.0, endColor);
1761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Fill highlight rectangle with gradient, potentially rounded if on left or right edge.
1781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    context->save();
1791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    context->setFillGradient(gradient);
1801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (startOffset < borderRadius && endOffset < borderRadius)
1821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        context->fillRoundedRect(highlightRect, radii, radii, radii, radii, startColor);
1831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    else if (startOffset < borderRadius)
1841e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        context->fillRoundedRect(highlightRect, radii, IntSize(0, 0), radii, IntSize(0, 0), startColor);
1851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    else if (endOffset < borderRadius)
1861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        context->fillRoundedRect(highlightRect, IntSize(0, 0), radii, IntSize(0, 0), radii, startColor);
1871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    else
1881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        context->fillRect(highlightRect);
1891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    context->restore();
1911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
1921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)const int mediaSliderThumbWidth = 32;
1941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool paintMediaSlider(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
1961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
1971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    HTMLMediaElement* mediaElement = toParentMediaElement(object);
1981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!mediaElement)
1991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return false;
2001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    RenderStyle* style = object->style();
2021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    GraphicsContext* context = paintInfo.context;
2031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    paintRoundedSliderBackground(rect, style, context);
2051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Draw the buffered range. Since the element may have multiple buffered ranges and it'd be
2071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // distracting/'busy' to show all of them, show only the buffered range containing the current play head.
208197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    RefPtrWillBeRawPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered();
2091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    float duration = mediaElement->duration();
2101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    float currentTime = mediaElement->currentTime();
2111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan(currentTime))
2121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return true;
2131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) {
2151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION);
2161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION);
2171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (std::isnan(start) || std::isnan(end) || start > currentTime || end < currentTime)
2181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            continue;
2191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        int startPosition = int(start * rect.width() / duration);
2201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        int currentPosition = int(currentTime * rect.width() / duration);
2211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        int endPosition = int(end * rect.width() / duration);
2221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        // Add half the thumb width proportionally adjusted to the current painting position.
2241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        int thumbCenter = mediaSliderThumbWidth / 2;
2251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width());
2261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        currentPosition += addWidth;
2271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        // Draw white-ish highlight before current time.
2291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        Color startColor = Color(195, 195, 195);
2301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        Color endColor = Color(217, 217, 217);
2311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (currentPosition > startPosition)
2321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            paintSliderRangeHighlight(rect, style, context, startPosition, currentPosition, startColor, endColor);
2331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        // Draw grey-ish highlight after current time.
2351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        startColor = Color(60, 60, 60);
2361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        endColor = Color(76, 76, 76);
2371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (endPosition > currentPosition)
2391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            paintSliderRangeHighlight(rect, style, context, currentPosition, endPosition, startColor, endColor);
2401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return true;
2421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
2431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return true;
2451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
2461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool paintMediaSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
2481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
2497242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (!object->node())
2507242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        return false;
2517242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
2521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadowHost());
2531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!mediaElement)
2541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return false;
2551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!hasSource(mediaElement))
2571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return true;
2581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    Image* mediaSliderThumb = getMediaSliderThumb();
2601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return paintMediaButton(paintInfo.context, rect, mediaSliderThumb);
2611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
2621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)const int mediaVolumeSliderThumbWidth = 24;
2641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool paintMediaVolumeSlider(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
2661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
2671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    HTMLMediaElement* mediaElement = toParentMediaElement(object);
2681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!mediaElement)
2691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return false;
2701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    GraphicsContext* context = paintInfo.context;
2721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    RenderStyle* style = object->style();
2731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    paintRoundedSliderBackground(rect, style, context);
2751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Calculate volume position for white background rectangle.
2771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    float volume = mediaElement->volume();
2781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (std::isnan(volume) || volume < 0)
2791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return true;
2801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (volume > 1)
2811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        volume = 1;
2821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!hasSource(mediaElement) || !mediaElement->hasAudio() || mediaElement->muted())
2831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        volume = 0;
2841e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Calculate the position relative to the center of the thumb.
2861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    float fillWidth = 0;
2871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (volume > 0) {
2881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        float thumbCenter = mediaVolumeSliderThumbWidth / 2;
2891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        float zoomLevel = style->effectiveZoom();
2901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        float positionWidth = volume * (rect.width() - (zoomLevel * thumbCenter));
2911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        fillWidth = positionWidth + (zoomLevel * thumbCenter / 2);
2921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
2931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    Color startColor = Color(195, 195, 195);
2951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    Color endColor = Color(217, 217, 217);
2961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    paintSliderRangeHighlight(rect, style, context, 0.0, fillWidth, startColor, endColor);
2981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return true;
3001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
3011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool paintMediaVolumeSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
3031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
3047242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (!object->node())
3057242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        return false;
3067242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
3071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadowHost());
3081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!mediaElement)
3091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return false;
3101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!hasSource(mediaElement) || !mediaElement->hasAudio())
3121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return true;
3131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSliderThumb");
3151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return paintMediaButton(paintInfo.context, rect, mediaVolumeSliderThumb);
3161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
3171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool paintMediaFullscreenButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
3191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
3201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    HTMLMediaElement* mediaElement = toParentMediaElement(object);
3211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!mediaElement)
3221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return false;
3231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaFullscreenButton = platformResource("mediaplayerFullscreen");
3251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return paintMediaButton(paintInfo.context, rect, mediaFullscreenButton);
3261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
3271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static bool paintMediaToggleClosedCaptionsButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
3291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
3301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    HTMLMediaElement* mediaElement = toParentMediaElement(object);
3311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!mediaElement)
3321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return false;
3331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaClosedCaptionButton = platformResource("mediaplayerClosedCaption");
3351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaClosedCaptionButtonDisabled = platformResource("mediaplayerClosedCaptionDisabled");
3361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (mediaElement->closedCaptionsVisible())
3381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButton);
3391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButtonDisabled);
3411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
3427242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccistatic bool paintMediaCastButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
3437242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{
3447242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    HTMLMediaElement* mediaElement = toParentMediaElement(object);
3457242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (!mediaElement)
3467242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        return false;
3477242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
3487242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    static Image* mediaCastOnButton = platformResource("mediaplayerCastOn");
3497242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    static Image* mediaCastOffButton = platformResource("mediaplayerCastOff");
3507242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
3517242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (mediaElement->isPlayingRemotely()) {
3527242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        return paintMediaButton(paintInfo.context, rect, mediaCastOnButton);
3537242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    }
3547242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
3557242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    return paintMediaButton(paintInfo.context, rect, mediaCastOffButton);
3561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3577242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci}
3581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)bool RenderMediaControls::paintMediaControlsPart(MediaControlElementType part, RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
3601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
3611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    switch (part) {
3621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaMuteButton:
3631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaUnMuteButton:
3641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaMuteButton(object, paintInfo, rect);
3651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaPauseButton:
3661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaPlayButton:
3671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaPlayButton(object, paintInfo, rect);
3681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaShowClosedCaptionsButton:
3691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaToggleClosedCaptionsButton(object, paintInfo, rect);
3701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaSlider:
3711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaSlider(object, paintInfo, rect);
3721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaSliderThumb:
3731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaSliderThumb(object, paintInfo, rect);
3741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaVolumeSlider:
3751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaVolumeSlider(object, paintInfo, rect);
3761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaVolumeSliderThumb:
3771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaVolumeSliderThumb(object, paintInfo, rect);
3781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaEnterFullscreenButton:
3791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaExitFullscreenButton:
3801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaFullscreenButton(object, paintInfo, rect);
3811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaOverlayPlayButton:
3821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return paintMediaOverlayPlayButton(object, paintInfo, rect);
3837242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    case MediaCastOffButton:
3847242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    case MediaCastOnButton:
3857242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    case MediaOverlayCastOffButton:
3867242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    case MediaOverlayCastOnButton:
3877242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        return paintMediaCastButton(object, paintInfo, rect);
3881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaVolumeSliderContainer:
3891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaTimelineContainer:
3901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaCurrentTimeDisplay:
3911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaTimeRemainingDisplay:
3921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaControlsPanel:
3931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaStatusDisplay:
3941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaHideClosedCaptionsButton:
3951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaTextTrackDisplayContainer:
3961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaTextTrackDisplay:
3971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaFullScreenVolumeSlider:
3981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case MediaFullScreenVolumeSliderThumb:
3991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        ASSERT_NOT_REACHED();
4001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        break;
4011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
4021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return false;
4031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
4041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)const int mediaSliderThumbHeight = 24;
4061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)const int mediaVolumeSliderThumbHeight = 24;
4071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)void RenderMediaControls::adjustMediaSliderThumbSize(RenderStyle* style)
4091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
4101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb");
4111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSliderThumb");
4121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int width = 0;
4131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int height = 0;
4141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    Image* thumbImage = 0;
4161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (style->appearance() == MediaSliderThumbPart) {
4171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        thumbImage = mediaSliderThumb;
4181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        width = mediaSliderThumbWidth;
4191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        height = mediaSliderThumbHeight;
4201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    } else if (style->appearance() == MediaVolumeSliderThumbPart) {
4211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        thumbImage = mediaVolumeSliderThumb;
4221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        width = mediaVolumeSliderThumbWidth;
4231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        height = mediaVolumeSliderThumbHeight;
4241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
4251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    float zoomLevel = style->effectiveZoom();
4271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (thumbImage) {
4281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        style->setWidth(Length(static_cast<int>(width * zoomLevel), Fixed));
4291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        style->setHeight(Length(static_cast<int>(height * zoomLevel), Fixed));
4301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
4311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
4321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)static String formatChromiumMediaControlsTime(float time, float duration)
4341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
4351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!std::isfinite(time))
4361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        time = 0;
4371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (!std::isfinite(duration))
4381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        duration = 0;
4391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int seconds = static_cast<int>(fabsf(time));
4401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int hours = seconds / (60 * 60);
4411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int minutes = (seconds / 60) % 60;
4421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    seconds %= 60;
4431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // duration defines the format of how the time is rendered
4451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int durationSecs = static_cast<int>(fabsf(duration));
4461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int durationHours = durationSecs / (60 * 60);
4471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int durationMins = (durationSecs / 60) % 60;
4481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (durationHours || hours)
4501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
4511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (durationMins > 9)
4521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
4531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return String::format("%s%01d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
4551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
4561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)String RenderMediaControls::formatMediaControlsTime(float time)
4581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
4591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return formatChromiumMediaControlsTime(time, time);
4601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
4611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)String RenderMediaControls::formatMediaControlsCurrentTime(float currentTime, float duration)
4631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
4641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return formatChromiumMediaControlsTime(currentTime, duration);
4651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
4661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
467c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
468