[CherryPick] thumb doesn't match click position for rtl input type=range
authorJiyeon Kim <jiyeon0402.kim@samsung.com>
Thu, 18 Apr 2013 04:42:02 +0000 (13:42 +0900)
committerGerrit Code Review <gerrit2@kim11>
Tue, 4 Jun 2013 05:24:07 +0000 (14:24 +0900)
[Title] [CherryPick] thumb doesn't match click position for rtl input type=range
[Problem] N/A
[Cause] N/A
[Solution] N/A
[Cherry-Picker] Jiyeon Kim

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

Change-Id: Ifb02014b86b960e1f559fbbd925be0366456e5db

LayoutTests/fast/forms/range/range-hit-test-with-padding-expected.txt
LayoutTests/fast/forms/range/range-hit-test-with-padding.html
Source/WebCore/html/shadow/SliderThumbElement.cpp

index 664c8ba..a787dc3 100644 (file)
@@ -1,6 +1,10 @@
 Clicking middle of input type=range with padding should set the value to middle.
 
-PASS input.value is "500"
+PASS input_ltr.value is "25"
+PASS input_rtl.value is "25"
+PASS input_vertical_ltr.value is "25"
+PASS input_vertical_rtl.value is "25"
+
 PASS successfullyParsed is true
 
 TEST COMPLETE
index b987600..3701287 100644 (file)
@@ -14,19 +14,31 @@ input::before {
 <body>
 <p id="description">Clicking middle of input type=range with padding should set the value to middle.</p>
 <div id="console"></div>
-<input id="input" type=range min=0 max=1000 step=1 value="0" style="width: 100px; padding: 0 20px;">
+<input id="ltr" type=range min=0 max=50 step=1 value="0" style="width: 100px; padding: 0 40px;">
+<input id="rtl" dir="rtl" type=range min=0 max=50 step=1 value="0" style="width: 100px; padding: 0 40px;">
+<input id="vertical_ltr" type=range min=0 max=50 step=1 value="0" style="-webkit-appearance:slider-vertical; width: 20px; height: 100px; padding: 40px 0;">
+<input id="vertical_rtl" dir="rtl" type=range min=0 max=50 step=1 value="0" style="-webkit-appearance:slider-vertical; width: 20px; height: 100px; padding: 40px 0;">
 <script>
-var input = document.getElementById("input");
-function clickSlider(offsetLeft) {
+function clickHorizontalSlider(input, offsetLeft) {
     var centerY = input.offsetTop + input.offsetHeight / 2;
+    if (!window.eventSender)
+        return;
     eventSender.mouseMoveTo(input.offsetLeft + offsetLeft, centerY);
     eventSender.mouseDown();
     eventSender.mouseUp();
 }
 
-clickSlider(70); // left padding (20px) + middle (50px)
-shouldBe('input.value', '"500"');
+var input_ltr = document.getElementById("ltr");
+clickHorizontalSlider(input_ltr, 90); // left padding (40px) + middle (50px)
+shouldBe('input_rtl.value', '"25"');
 
+var input_vertical_ltr = document.getElementById("vertical_rtl");
+clickVerticalSlider(input_vertical_ltr, 90); // top padding (40px) + middle (50px)
+shouldBe('input_vertical_ltr.value', '"25"');
+
+var input_vertical_rtl = document.getElementById("vertical_rtl");
+clickVerticalSlider(input_vertical_rtl, 90); // top padding (40px) + middle (50px)
+shouldBe('input_vertical_rtl.value', '"25"');
 </script>
 
 <script src="../../js/resources/js-test-post.js"></script>
index 967b48a..aa94a81 100644 (file)
@@ -251,6 +251,7 @@ void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point)
     input->setTextAsOfLastFormControlChangeEvent(input->value());
     LayoutPoint offset = roundedLayoutPoint(input->renderer()->absoluteToLocal(point, false, true));
     bool isVertical = hasVerticalAppearance(input);
+    bool isLeftToRightDirection = renderBox()->style()->isLeftToRightDirection();
     LayoutUnit trackSize;
     LayoutUnit position;
     LayoutUnit currentPosition;
@@ -269,6 +270,8 @@ void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point)
     } else {
         trackSize = trackElement->renderBox()->contentWidth();
         position = offset.x() - renderBox()->width() / 2 - trackBoundingBox.x() + inputBoundingBox.x();
+        if (!isLeftToRightDirection)
+            position += renderBox()->width();
         currentPosition = absoluteThumbOrigin.x() - absoluteSliderContentOrigin.x();
     }
     position = max<LayoutUnit>(0, min(position, trackSize));
@@ -276,7 +279,7 @@ void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point)
         return;
 
     const Decimal ratio = Decimal::fromDouble(static_cast<double>(position) / trackSize);
-    const Decimal fraction = isVertical || !renderBox()->style()->isLeftToRightDirection() ? Decimal(1) - ratio : ratio;
+    const Decimal fraction = isVertical || !isLeftToRightDirection ? Decimal(1) - ratio : ratio;
     StepRange stepRange(input->createStepRange(RejectAny));
     const Decimal value = stepRange.clampValue(stepRange.valueFromProportion(fraction));