Title: [120246] trunk/Source/WebCore
Revision
120246
Author
[email protected]
Date
2012-06-13 14:01:19 -0700 (Wed, 13 Jun 2012)

Log Message

Update range sliders rendering for volume and playback position of new Chrome video controls.
https://bugs.webkit.org/show_bug.cgi?id=88623

Patch by Silvia Pfeiffer <[email protected]> on 2012-06-13
Reviewed by Eric Carlson.

No new tests, final patch will contain the rebaselined tests.

The Chrome video controls are receiving a visual update. This patch contains updates to the
rendering of the range sliders for the playback position and the volume. This includes the
creation of a shadowPseudoId to be able to style the range sliders via CSS, the rendering
of the slider background and the highlighted ranges.

* css/mediaControlsChromium.css:
(input[type="range"]::-webkit-media-slider-container):
Adjust the styling of the slider container backgrounds.
(input[type="range"]::-webkit-media-slider-thumb):
Adjust the styling of the slider thumbs.
* html/shadow/SliderThumbElement.cpp:
(WebCore::sliderThumbShadowPseudoId):
Add an accessor function for the slider thumb shadowPseudoId.
(WebCore::mediaSliderThumbShadowPseudoId):
Add an accessor function for the media slider thumb shadowPseudoId.
(WebCore::SliderThumbElement::shadowPseudoId):
Add a different CSS pseudo-class name to the media slider thumbs.
(WebCore::TrackLimiterElement::shadowPseudoId):
Add a different CSS pseudo-class name to the media slider thumbs.
(WebCore::SliderContainerElement::shadowPseudoId):
Add a different CSS pseudo-class name to the media slider background container.
* rendering/RenderMediaControlsChromium.cpp:
(WebCore::paintRoundedSliderBackground):
Add function to draw rounded background of sliders in a dark color.
(WebCore::paintSliderRangeHighlight):
Add function to draw a highlighted grey region on the sliders, which is rounded only at
its ends.
(WebCore::paintMediaSlider):
Update the background and buffered range renderings on the playback position slider by making
use of the new helper functions.
(WebCore::paintMediaVolumeSlider):
Update the background and buffered range renderings on the volume slider by making
use of the new helper functions.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (120245 => 120246)


--- trunk/Source/WebCore/ChangeLog	2012-06-13 20:56:42 UTC (rev 120245)
+++ trunk/Source/WebCore/ChangeLog	2012-06-13 21:01:19 UTC (rev 120246)
@@ -1,3 +1,46 @@
+2012-06-13  Silvia Pfeiffer  <[email protected]>
+
+        Update range sliders rendering for volume and playback position of new Chrome video controls.
+        https://bugs.webkit.org/show_bug.cgi?id=88623
+
+        Reviewed by Eric Carlson.
+
+        No new tests, final patch will contain the rebaselined tests.
+
+        The Chrome video controls are receiving a visual update. This patch contains updates to the
+        rendering of the range sliders for the playback position and the volume. This includes the
+        creation of a shadowPseudoId to be able to style the range sliders via CSS, the rendering
+        of the slider background and the highlighted ranges.
+
+        * css/mediaControlsChromium.css:
+        (input[type="range"]::-webkit-media-slider-container):
+        Adjust the styling of the slider container backgrounds.
+        (input[type="range"]::-webkit-media-slider-thumb):
+        Adjust the styling of the slider thumbs.
+        * html/shadow/SliderThumbElement.cpp:
+        (WebCore::sliderThumbShadowPseudoId):
+        Add an accessor function for the slider thumb shadowPseudoId.
+        (WebCore::mediaSliderThumbShadowPseudoId):
+        Add an accessor function for the media slider thumb shadowPseudoId.
+        (WebCore::SliderThumbElement::shadowPseudoId):
+        Add a different CSS pseudo-class name to the media slider thumbs.
+        (WebCore::TrackLimiterElement::shadowPseudoId):
+        Add a different CSS pseudo-class name to the media slider thumbs.
+        (WebCore::SliderContainerElement::shadowPseudoId):
+        Add a different CSS pseudo-class name to the media slider background container.
+        * rendering/RenderMediaControlsChromium.cpp:
+        (WebCore::paintRoundedSliderBackground):
+        Add function to draw rounded background of sliders in a dark color.
+        (WebCore::paintSliderRangeHighlight):
+        Add function to draw a highlighted grey region on the sliders, which is rounded only at
+        its ends.
+        (WebCore::paintMediaSlider):
+        Update the background and buffered range renderings on the playback position slider by making
+        use of the new helper functions.
+        (WebCore::paintMediaVolumeSlider):
+        Update the background and buffered range renderings on the volume slider by making
+        use of the new helper functions.
+
 2012-06-13  Christopher Hutten-Czapski  <[email protected]>
 
         2012-06-13  Christopher Hutten-Czapski  <[email protected]>

Modified: trunk/Source/WebCore/css/mediaControlsChromium.css (120245 => 120246)


--- trunk/Source/WebCore/css/mediaControlsChromium.css	2012-06-13 20:56:42 UTC (rev 120245)
+++ trunk/Source/WebCore/css/mediaControlsChromium.css	2012-06-13 21:01:19 UTC (rev 120246)
@@ -143,3 +143,29 @@
     background-color: transparent;
     min-width: 15px;
 }
+
+/* FIXME these shouldn't use special pseudoShadowIds, but nicer rules.
+   https://code.google.com/p/chromium/issues/detail?id=112508
+   https://bugs.webkit.org/show_bug.cgi?id=62218
+*/
+input[type="range"]::-webkit-media-slider-container {
+    display: -webkit-box;
+    -webkit-box-align: center;
+    -webkit-box-orient: horizontal; /* This property is updated by C++ code. */
+    -webkit-box-sizing: border-box;
+    height: 100%;
+    width: 100%;
+    border: 1px solid rgb(130, 130, 130);
+    border-radius: 4px;
+    background-color: transparent; /* Background drawing is managed by C++ code to draw ranges. */
+}
+
+input[type="range"]::-webkit-media-slider-thumb {
+    display: block;
+    -webkit-appearance: sliderthumb-horizontal;
+    -webkit-box-sizing: border-box;
+    position: relative;
+    bottom: 1px;
+    margin-left: -7px;
+    margin-right: -7px;
+}

Modified: trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp (120245 => 120246)


--- trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp	2012-06-13 20:56:42 UTC (rev 120245)
+++ trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp	2012-06-13 21:01:19 UTC (rev 120246)
@@ -327,12 +327,38 @@
     return shadowAncestorNode()->toInputElement();
 }
 
-const AtomicString& SliderThumbElement::shadowPseudoId() const
+static const AtomicString& sliderThumbShadowPseudoId()
 {
-    DEFINE_STATIC_LOCAL(AtomicString, sliderThumb, ("-webkit-slider-thumb"));
+    DEFINE_STATIC_LOCAL(const AtomicString, sliderThumb, ("-webkit-slider-thumb"));
     return sliderThumb;
 }
 
+static const AtomicString& mediaSliderThumbShadowPseudoId()
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderThumb, ("-webkit-media-slider-thumb"));
+    return mediaSliderThumb;
+}
+
+const AtomicString& SliderThumbElement::shadowPseudoId() const
+{
+    HTMLInputElement* input = hostInput();
+    if (!input)
+        return sliderThumbShadowPseudoId();
+
+    RenderStyle* sliderStyle = input->renderer()->style();
+    switch (sliderStyle->appearance()) {
+    case MediaSliderPart:
+    case MediaSliderThumbPart:
+    case MediaVolumeSliderPart:
+    case MediaVolumeSliderThumbPart:
+    case MediaFullScreenVolumeSliderPart:
+    case MediaFullScreenVolumeSliderThumbPart:
+        return mediaSliderThumbShadowPseudoId();
+    default:
+        return sliderThumbShadowPseudoId();
+    }
+}
+
 // --------------------------------
 
 inline TrackLimiterElement::TrackLimiterElement(Document* document)
@@ -357,8 +383,22 @@
 
 const AtomicString& TrackLimiterElement::shadowPseudoId() const
 {
-    DEFINE_STATIC_LOCAL(AtomicString, sliderThumb, ("-webkit-slider-thumb"));
-    return sliderThumb;
+    HTMLInputElement* input = shadowAncestorNode()->toInputElement();
+    if (!input)
+        return sliderThumbShadowPseudoId();
+
+    RenderStyle* sliderStyle = input->renderer()->style();
+    switch (sliderStyle->appearance()) {
+    case MediaSliderPart:
+    case MediaSliderThumbPart:
+    case MediaVolumeSliderPart:
+    case MediaVolumeSliderThumbPart:
+    case MediaFullScreenVolumeSliderPart:
+    case MediaFullScreenVolumeSliderThumbPart:
+        return mediaSliderThumbShadowPseudoId();
+    default:
+        return sliderThumbShadowPseudoId();
+    }
 }
 
 TrackLimiterElement* trackLimiterElementOf(Node* node)
@@ -391,8 +431,25 @@
 
 const AtomicString& SliderContainerElement::shadowPseudoId() const
 {
-    DEFINE_STATIC_LOCAL(AtomicString, sliderThumb, ("-webkit-slider-container"));
-    return sliderThumb;
+    DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderContainer, ("-webkit-media-slider-container"));
+    DEFINE_STATIC_LOCAL(const AtomicString, sliderContainer, ("-webkit-slider-container"));
+
+    HTMLInputElement* input = shadowAncestorNode()->toInputElement();
+    if (!input)
+        return sliderContainer;
+
+    RenderStyle* sliderStyle = input->renderer()->style();
+    switch (sliderStyle->appearance()) {
+    case MediaSliderPart:
+    case MediaSliderThumbPart:
+    case MediaVolumeSliderPart:
+    case MediaVolumeSliderThumbPart:
+    case MediaFullScreenVolumeSliderPart:
+    case MediaFullScreenVolumeSliderThumbPart:
+        return mediaSliderContainer;
+    default:
+        return sliderContainer;
+    }
 }
 
 }

Modified: trunk/Source/WebCore/rendering/RenderMediaControlsChromium.cpp (120245 => 120246)


--- trunk/Source/WebCore/rendering/RenderMediaControlsChromium.cpp	2012-06-13 20:56:42 UTC (rev 120245)
+++ trunk/Source/WebCore/rendering/RenderMediaControlsChromium.cpp	2012-06-13 21:01:19 UTC (rev 120246)
@@ -113,6 +113,71 @@
     return mediaSliderThumb;
 }
 
+static void paintRoundedSliderBackground(const IntRect& rect, const RenderStyle* style, GraphicsContext* context)
+{
+    int borderRadius = rect.height() / 2;
+    IntSize radii(borderRadius, borderRadius);
+    Color sliderBackgroundColor = Color(29, 29, 29);
+    context->save();
+    context->fillRoundedRect(rect, radii, radii, radii, radii, sliderBackgroundColor, ColorSpaceDeviceRGB);
+    context->restore();
+}
+
+static void paintSliderRangeHighlight(const IntRect& rect, const RenderStyle* style, GraphicsContext* context, float startFraction, float widthFraction)
+{
+    if (startFraction < 0)
+        startFraction = 0;
+    if (widthFraction > 1)
+        widthFraction = 1;
+    float endFraction = startFraction + widthFraction;
+    if (endFraction > 1) {
+        widthFraction = widthFraction - startFraction;
+        endFraction = startFraction + widthFraction;
+    }
+
+    // Set rectangle to highlight range.
+    IntRect highlightRect = rect;
+    int startOffset = startFraction * rect.width();
+    int endOffset = rect.width() - endFraction * rect.width();
+    int rangeWidth = widthFraction * rect.width();
+    highlightRect.move(startOffset, 0);
+    highlightRect.setWidth(rangeWidth);
+
+    // Don't bother drawing an empty area.
+    if (highlightRect.isEmpty())
+        return;
+
+    // Calculate border radius; need to avoid being smaller than half the slider height
+    // because of https://bugs.webkit.org/show_bug.cgi?id=30143.
+    int borderRadius = rect.height() / 2;
+    IntSize radii(borderRadius, borderRadius);
+
+    // Calculate white-grey gradient.
+    IntPoint sliderTopLeft = highlightRect.location();
+    IntPoint sliderBottomLeft = sliderTopLeft;
+    sliderBottomLeft.move(0, highlightRect.height());
+    Color startColor = Color(220, 220, 220);
+    Color endColor = Color(240, 240, 240);
+    RefPtr<Gradient> gradient = Gradient::create(sliderTopLeft, sliderBottomLeft);
+    gradient->addColorStop(0.0, startColor);
+    gradient->addColorStop(1.0, endColor);
+
+    // Fill highlight rectangle with gradient, potentially rounded if on left or right edge.
+    context->save();
+    context->setFillGradient(gradient);
+
+    if (startOffset < borderRadius && endOffset < borderRadius)
+        context->fillRoundedRect(highlightRect, radii, radii, radii, radii, startColor, ColorSpaceDeviceRGB);
+    else if (startOffset < borderRadius)
+        context->fillRoundedRect(highlightRect, radii, IntSize(0, 0), radii, IntSize(0, 0), startColor, ColorSpaceDeviceRGB);
+    else if (endOffset < borderRadius)
+        context->fillRoundedRect(highlightRect, IntSize(0, 0), radii, IntSize(0, 0), radii, startColor, ColorSpaceDeviceRGB);
+    else
+        context->fillRect(highlightRect);
+
+    context->restore();
+}
+
 static bool paintMediaSlider(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
 {
     HTMLMediaElement* mediaElement = toParentMediaElement(object);
@@ -122,23 +187,10 @@
     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->setShouldAntialias(true);
-    context->setStrokeStyle(SolidStroke);
-    context->setStrokeColor(style->visitedDependentColor(CSSPropertyBorderLeftColor), ColorSpaceDeviceRGB);
-    context->setStrokeThickness(style->borderLeftWidth());
-    context->setFillColor(style->visitedDependentColor(CSSPropertyBackgroundColor), ColorSpaceDeviceRGB);
-    context->drawRect(rect);
-    context->restore();
+    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.
-    IntRect bufferedRect = rect;
-    bufferedRect.inflate(-style->borderLeftWidth());
-
     RefPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered();
     float duration = mediaElement->duration();
     float currentTime = mediaElement->currentTime();
@@ -153,27 +205,8 @@
         float startFraction = start / duration;
         float endFraction = end / duration;
         float widthFraction = endFraction - startFraction;
-        bufferedRect.move(startFraction * bufferedRect.width(), 0);
-        bufferedRect.setWidth(widthFraction * bufferedRect.width());
 
-        // Don't bother drawing an empty area.
-        if (bufferedRect.isEmpty())
-            return true;
-
-        IntPoint sliderTopLeft = bufferedRect.location();
-        IntPoint sliderBottomLeft = sliderTopLeft;
-        sliderBottomLeft.move(0, bufferedRect.height());
-
-        RefPtr<Gradient> gradient = Gradient::create(sliderTopLeft, sliderBottomLeft);
-        Color startColor = object->style()->visitedDependentColor(CSSPropertyColor);
-        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->fillRect(bufferedRect);
-        context->restore();
+        paintSliderRangeHighlight(rect, style, context, startFraction, widthFraction);
         return true;
     }
 
@@ -196,6 +229,8 @@
     return paintMediaButton(paintInfo.context, rect, mediaSliderThumb);
 }
 
+const int mediaVolumeSliderThumbWidth = 24;
+
 static bool paintMediaVolumeSlider(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
 {
     HTMLMediaElement* mediaElement = toParentMediaElement(object);
@@ -203,15 +238,25 @@
         return false;
 
     GraphicsContext* context = paintInfo.context;
-    Color originalColor = context->strokeColor();
-    if (originalColor != Color::white)
-        context->setStrokeColor(Color::white, ColorSpaceDeviceRGB);
+    RenderStyle* style = object->style();
 
-    int y = rect.y() + rect.height() / 2;
-    context->drawLine(IntPoint(rect.x(), y),  IntPoint(rect.x() + rect.width(), y));
+    paintRoundedSliderBackground(rect, style, context);
 
-    if (originalColor != Color::white)
-        context->setStrokeColor(originalColor, ColorSpaceDeviceRGB);
+    // Calculate volume position for white background rectangle.
+    float volume = mediaElement->volume();
+    if (isnan(volume) || volume < 0)
+        return true;
+    if (volume > 1)
+        volume = 1;
+
+    // Calculate the position relative to the center of the thumb.
+    float thumbCenter = mediaVolumeSliderThumbWidth / 2;
+    float zoomLevel = style->effectiveZoom();
+    float positionWidth = volume * (rect.width() - (zoomLevel * thumbCenter));
+    float fillWidth = positionWidth + (zoomLevel * thumbCenter / 2);
+
+    paintSliderRangeHighlight(rect, style, context, 0.0, fillWidth / rect.width());
+
     return true;
 }
 
@@ -276,7 +321,6 @@
 
 const int mediaSliderThumbWidth = 32;
 const int mediaSliderThumbHeight = 24;
-const int mediaVolumeSliderThumbWidth = 24;
 const int mediaVolumeSliderThumbHeight = 24;
 
 void RenderMediaControlsChromium::adjustMediaSliderThumbSize(RenderStyle* style)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to