Changeset 154832 in webkit
- Timestamp:
- Aug 29, 2013, 12:15:33 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
html/shadow/SliderThumbElement.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r154830 r154832 1 2013-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 1 21 2013-08-29 Zan Dobersek <zdobersek@igalia.com> 2 22 -
trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp
r154308 r154832 257 257 } 258 258 259 void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point)259 void SliderThumbElement::setPositionFromPoint(const LayoutPoint& absolutePoint) 260 260 { 261 261 RefPtr<HTMLInputElement> input(hostInput()); … … 266 266 267 267 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 269 273 bool isVertical = hasVerticalAppearance(input.get()); 270 274 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; 272 280 LayoutUnit position; 273 LayoutUnit currentPosition;274 // We need to calculate currentPosition from absolute points becaue the275 // renderer for this node is usually on a layer and renderBox()->x() and276 // 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();282 281 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(); 286 284 } else { 287 track Size = 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(); 289 287 position -= isLeftToRightDirection ? renderBox()->marginLeft() : renderBox()->marginRight(); 290 currentPosition = absoluteThumbOrigin.x() - absoluteSliderContentOrigin.x();291 } 292 position = max<LayoutUnit>(0, min(position, track Size));293 const Decimal ratio = Decimal::fromDouble(static_cast<double>(position) / track Size);288 } 289 290 position = max<LayoutUnit>(0, min(position, trackLength)); 291 const Decimal ratio = Decimal::fromDouble(static_cast<double>(position) / trackLength); 294 292 const Decimal fraction = isVertical || !isLeftToRightDirection ? Decimal(1) - ratio : ratio; 295 293 StepRange stepRange(input->createStepRange(RejectAny)); … … 303 301 double closestFraction = stepRange.proportionFromValue(closest).toDouble(); 304 302 double closestRatio = isVertical || !isLeftToRightDirection ? 1.0 - closestFraction : closestFraction; 305 LayoutUnit closestPosition = track Size* closestRatio;303 LayoutUnit closestPosition = trackLength * closestRatio; 306 304 if ((closestPosition - position).abs() <= snappingThreshold) 307 305 value = closest;
Note:
See TracChangeset
for help on using the changeset viewer.