Changeset 154832 in webkit


Ignore:
Timestamp:
Aug 29, 2013, 12:15:33 PM (13 years ago)
Author:
Simon Fraser
Message:

Fix slider thumb event handling to use local, not absolute coordinates
https://bugs.webkit.org/show_bug.cgi?id=120480

Reviewed by Darin Adler.

SliderThumbElement::setPositionFromPoint() did all of its coordinate
math by mapping renderer rects into absolute coordinates, which was
unnecessary and expensive.

Fix by doing all the math in the coordinate space of the input's
renderer. This simplified the code. Also, currentPosition
was computed but unused, so was removed.

No behavior change. Tested by fast/forms/range/slider-transformed.html

  • html/shadow/SliderThumbElement.cpp:

(WebCore::SliderThumbElement::setPositionFromPoint):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r154830 r154832  
     12013-08-29  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Fix slider thumb event handling to use local, not absolute coordinates
     4        https://bugs.webkit.org/show_bug.cgi?id=120480
     5
     6        Reviewed by Darin Adler.
     7       
     8        SliderThumbElement::setPositionFromPoint() did all of its coordinate
     9        math by mapping renderer rects into absolute coordinates, which was
     10        unnecessary and expensive.
     11       
     12        Fix by doing all the math in the coordinate space of the input's
     13        renderer. This simplified the code. Also, currentPosition
     14        was computed but unused, so was removed.
     15
     16        No behavior change. Tested by fast/forms/range/slider-transformed.html
     17
     18        * html/shadow/SliderThumbElement.cpp:
     19        (WebCore::SliderThumbElement::setPositionFromPoint):
     20
    1212013-08-29  Zan Dobersek  <zdobersek@igalia.com>
    222
  • trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp

    r154308 r154832  
    257257}
    258258
    259 void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point)
     259void SliderThumbElement::setPositionFromPoint(const LayoutPoint& absolutePoint)
    260260{
    261261    RefPtr<HTMLInputElement> input(hostInput());
     
    266266
    267267    input->setTextAsOfLastFormControlChangeEvent(input->value());
    268     LayoutPoint offset = roundedLayoutPoint(input->renderer()->absoluteToLocal(point, UseTransforms));
     268
     269    // Do all the tracking math relative to the input's renderer's box.
     270    RenderBox& inputRenderer = *toRenderBox(input->renderer());
     271    RenderBox& trackRenderer = *trackElement->renderBox();
     272
    269273    bool isVertical = hasVerticalAppearance(input.get());
    270274    bool isLeftToRightDirection = renderBox()->style()->isLeftToRightDirection();
    271     LayoutUnit trackSize;
     275   
     276    LayoutPoint offset = roundedLayoutPoint(inputRenderer.absoluteToLocal(absolutePoint, UseTransforms));
     277    FloatRect trackBoundingBox = trackRenderer.localToContainerQuad(FloatRect(0, 0, trackRenderer.width(), trackRenderer.height()), &inputRenderer).enclosingBoundingBox();
     278
     279    LayoutUnit trackLength;
    272280    LayoutUnit position;
    273     LayoutUnit currentPosition;
    274     // We need to calculate currentPosition from absolute points becaue the
    275     // renderer for this node is usually on a layer and renderBox()->x() and
    276     // y() are unusable.
    277     // FIXME: This should probably respect transforms.
    278     LayoutPoint absoluteThumbOrigin = renderBox()->absoluteBoundingBoxRectIgnoringTransforms().location();
    279     LayoutPoint absoluteSliderContentOrigin = roundedLayoutPoint(input->renderer()->localToAbsolute());
    280     IntRect trackBoundingBox = trackElement->renderer()->absoluteBoundingBoxRectIgnoringTransforms();
    281     IntRect inputBoundingBox = input->renderer()->absoluteBoundingBoxRectIgnoringTransforms();
    282281    if (isVertical) {
    283         trackSize = trackElement->renderBox()->contentHeight() - renderBox()->height();
    284         position = offset.y() - renderBox()->height() / 2 - trackBoundingBox.y() + inputBoundingBox.y() - renderBox()->marginBottom();
    285         currentPosition = absoluteThumbOrigin.y() - absoluteSliderContentOrigin.y();
     282        trackLength = trackRenderer.contentHeight() - renderBox()->height();
     283        position = offset.y() - renderBox()->height() / 2 - trackBoundingBox.y() - renderBox()->marginBottom();
    286284    } else {
    287         trackSize = trackElement->renderBox()->contentWidth() - renderBox()->width();
    288         position = offset.x() - renderBox()->width() / 2 - trackBoundingBox.x() + inputBoundingBox.x();
     285        trackLength = trackRenderer.contentWidth() - renderBox()->width();
     286        position = offset.x() - renderBox()->width() / 2 - trackBoundingBox.x();
    289287        position -= isLeftToRightDirection ? renderBox()->marginLeft() : renderBox()->marginRight();
    290         currentPosition = absoluteThumbOrigin.x() - absoluteSliderContentOrigin.x();
    291     }
    292     position = max<LayoutUnit>(0, min(position, trackSize));
    293     const Decimal ratio = Decimal::fromDouble(static_cast<double>(position) / trackSize);
     288    }
     289
     290    position = max<LayoutUnit>(0, min(position, trackLength));
     291    const Decimal ratio = Decimal::fromDouble(static_cast<double>(position) / trackLength);
    294292    const Decimal fraction = isVertical || !isLeftToRightDirection ? Decimal(1) - ratio : ratio;
    295293    StepRange stepRange(input->createStepRange(RejectAny));
     
    303301            double closestFraction = stepRange.proportionFromValue(closest).toDouble();
    304302            double closestRatio = isVertical || !isLeftToRightDirection ? 1.0 - closestFraction : closestFraction;
    305             LayoutUnit closestPosition = trackSize * closestRatio;
     303            LayoutUnit closestPosition = trackLength * closestRatio;
    306304            if ((closestPosition - position).abs() <= snappingThreshold)
    307305                value = closest;
Note: See TracChangeset for help on using the changeset viewer.