2009-03-25 Simon Fraser <simon.fraser@apple.com>
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Mar 2009 22:11:47 +0000 (22:11 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Mar 2009 22:11:47 +0000 (22:11 +0000)
        Reviewed by Darin Adler

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

        When the slider range is zero, avoid a divide by zero, which caused the
        thumb to be positioned off in the weeds, which broke painting.

        Test: media/video-empty-source.html

        * rendering/RenderSlider.cpp:
        (WebCore::SliderRange::proportionFromValue):
        (WebCore::SliderRange::valueFromProportion):
        (WebCore::sliderPosition):
        (WebCore::RenderSlider::setValueForPosition):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@41987 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/media/video-empty-source.html [new file with mode: 0644]
LayoutTests/platform/mac/media/video-empty-source-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/media/video-empty-source-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/media/video-empty-source-expected.txt [new file with mode: 0644]
WebCore/ChangeLog
WebCore/rendering/RenderSlider.cpp

index 509e737..127cdc0 100644 (file)
@@ -1,3 +1,16 @@
+2009-03-25  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Darin Adler
+        
+        https://bugs.webkit.org/show_bug.cgi?id=24817
+        
+        Pixel test for a video element with an empty source attribute.
+
+        * media/video-empty-source.html: Added.
+        * platform/mac/media/video-empty-source-expected.checksum: Added.
+        * platform/mac/media/video-empty-source-expected.png: Added.
+        * platform/mac/media/video-empty-source-expected.txt: Added.
+
 2009-03-25  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Dave Hyatt.
diff --git a/LayoutTests/media/video-empty-source.html b/LayoutTests/media/video-empty-source.html
new file mode 100644 (file)
index 0000000..a06ec45
--- /dev/null
@@ -0,0 +1,5 @@
+<body>
+<p>Slider drawing with no source. The controls should render correctly.</p>
+<video src="" controls style="border:1px solid black"></video>
+</div>
+</body>
diff --git a/LayoutTests/platform/mac/media/video-empty-source-expected.checksum b/LayoutTests/platform/mac/media/video-empty-source-expected.checksum
new file mode 100644 (file)
index 0000000..bc8cd7c
--- /dev/null
@@ -0,0 +1 @@
+33b5966a02b796fbf89f0638ea86585a
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/media/video-empty-source-expected.png b/LayoutTests/platform/mac/media/video-empty-source-expected.png
new file mode 100644 (file)
index 0000000..8df3bd5
Binary files /dev/null and b/LayoutTests/platform/mac/media/video-empty-source-expected.png differ
diff --git a/LayoutTests/platform/mac/media/video-empty-source-expected.txt b/LayoutTests/platform/mac/media/video-empty-source-expected.txt
new file mode 100644 (file)
index 0000000..047540f
--- /dev/null
@@ -0,0 +1,31 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 430x18
+          text run at (0,0) width 430: "Slider drawing with no source. The controls should render correctly."
+      RenderBlock (anonymous) at (0,34) size 784x152
+        RenderVideo {VIDEO} at (0,0) size 302x152 [border: (1px solid #000000)]
+        RenderText {#text} at (0,0) size 0x0
+        RenderText {#text} at (0,0) size 0x0
+        RenderText {#text} at (0,0) size 0x0
+layer at (9,43) size 300x150
+  RenderBlock (relative positioned) {DIV} at (1,1) size 300x150
+layer at (9,43) size 300x150
+  RenderBlock (positioned) {DIV} at (0,0) size 300x150
+    RenderButton {INPUT} at (0,0) size 300x18
+layer at (9,177) size 17x16
+  RenderButton {INPUT} at (0,134) size 17x16
+layer at (25,177) size 17x16
+  RenderButton {INPUT} at (16,134) size 17x16
+layer at (41,177) size 236x16
+  RenderBlock (positioned) {DIV} at (32,134) size 236x16
+layer at (41,177) size 236x16
+  RenderSlider {INPUT} at (0,0) size 236x16
+    RenderBlock {DIV} at (2,1) size 13x14
+layer at (276,177) size 17x16
+  RenderButton {INPUT} at (267,134) size 17x16
+layer at (292,177) size 17x16
+  RenderButton {INPUT} at (283,134) size 17x16
index eb81432..92bb47f 100644 (file)
@@ -1,3 +1,20 @@
+2009-03-25  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Darin Adler
+        
+        https://bugs.webkit.org/show_bug.cgi?id=24817
+        
+        When the slider range is zero, avoid a divide by zero, which caused the
+        thumb to be positioned off in the weeds, which broke painting.
+
+        Test: media/video-empty-source.html
+
+        * rendering/RenderSlider.cpp:
+        (WebCore::SliderRange::proportionFromValue):
+        (WebCore::SliderRange::valueFromProportion):
+        (WebCore::sliderPosition):
+        (WebCore::RenderSlider::setValueForPosition):
+
 2009-03-24  Eric Seidel  <eric@webkit.org>
 
         Reviewed by Simon Fraser.
index f54ccb8..b30faad 100644 (file)
@@ -54,6 +54,22 @@ struct SliderRange {
 
     explicit SliderRange(HTMLInputElement*);
     double clampValue(double value);
+
+    // Map value into 0-1 range
+    double proportionFromValue(double value)
+    {
+        if (minimum == maximum)
+            return 0;
+
+        return (value - minimum) / (maximum - minimum);
+    }
+    
+    // Map from 0-1 range to value
+    double valueFromProportion(double proportion)
+    {
+        return minimum + proportion * (maximum - minimum);
+    }
+    
     double valueFromElement(HTMLInputElement*, bool* wasClamped = 0);
 };
 
@@ -95,8 +111,7 @@ double SliderRange::valueFromElement(HTMLInputElement* element, bool* wasClamped
 static double sliderPosition(HTMLInputElement* element)
 {
     SliderRange range(element);
-    double value = range.valueFromElement(element);
-    return (value - range.minimum) / (range.maximum - range.minimum);
+    return range.proportionFromValue(range.valueFromElement(element));
 }
 
 class SliderThumbElement : public HTMLDivElement {
@@ -384,7 +399,7 @@ void RenderSlider::setValueForPosition(int position)
     double fraction = static_cast<double>(position) / trackSize();
     if (style()->appearance() == SliderVerticalPart)
         fraction = 1 - fraction;
-    double value = range.clampValue(range.minimum + fraction * (range.maximum - range.minimum));
+    double value = range.clampValue(range.valueFromProportion(fraction));
     element->setValueFromRenderer(String::number(value));
 
     // Also update the position if appropriate.