Bug 21870 - [Transforms] event.offsetX and offsetY are wrong for transformed elements
Summary: [Transforms] event.offsetX and offsetY are wrong for transformed elements
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Simon Fraser (smfr)
URL:
Keywords:
Depends on: 21941
Blocks:
  Show dependency treegraph
 
Reported: 2008-10-24 14:32 PDT by Simon Fraser (smfr)
Modified: 2008-11-06 10:42 PST (History)
2 users (show)

See Also:


Attachments
Testcase (1.21 KB, text/html)
2008-10-24 14:33 PDT, Simon Fraser (smfr)
no flags Details
WIP patch (14.09 KB, patch)
2008-10-24 21:30 PDT, Simon Fraser (smfr)
no flags Details | Formatted Diff | Diff
Patch (14.62 KB, patch)
2008-10-24 23:03 PDT, Simon Fraser (smfr)
hyatt: review-
Details | Formatted Diff | Diff
Implement absoluteToLocal, fix event.offsetX/offsetY (21.23 KB, patch)
2008-11-05 18:03 PST, Simon Fraser (smfr)
hyatt: review+
Details | Formatted Diff | Diff
Testcase in the patch (6.91 KB, text/html)
2008-11-05 18:04 PST, Simon Fraser (smfr)
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2008-10-24 14:32:41 PDT
event.offsetX and offsetY (which are supposed to be relative to the target element are not computed correctly for transformed elements.
Comment 1 Simon Fraser (smfr) 2008-10-24 14:33:02 PDT
Created attachment 24653 [details]
Testcase
Comment 2 Simon Fraser (smfr) 2008-10-24 14:34:09 PDT
Note that this breaks some event handling on transformed sliders.
Comment 3 Simon Fraser (smfr) 2008-10-24 21:30:34 PDT
Created attachment 24668 [details]
WIP patch

Here's a first cut that adds two new methods to RenderObject:

+    virtual bool objectPointToAbsoluteCoords(FloatPoint&, bool fixed = false) const;
+    virtual bool absolutePointToObjectCoords(FloatPoint&, bool fixed = false) const;

to map points to and from absolute coords, taking transforms into account.

Dave, does this look like a reasonable approach?

I should note that with this patch, a rotated <input type="range"> works perfectly!
Comment 4 Simon Fraser (smfr) 2008-10-24 23:03:37 PDT
Created attachment 24670 [details]
Patch

Add two new methods to RenderObject:
+    virtual bool objectPointToAbsoluteCoords(FloatPoint&, bool fixed = false) const;
+    virtual bool absolutePointToObjectCoords(FloatPoint&, bool fixed = false) const;

which map points between RenderObject and absolute coords taking transforms into account.

Factor some RenderBox code into a new offsetFromContainer() method, now called in 3 places.

Call absolutePointToObjectCoords() when setting offsetX, offsetY in mouse events.

Add some comments, and a convenience expand() method on IntSize.
Comment 5 Simon Fraser (smfr) 2008-10-24 23:05:01 PDT
Hmm, I think offsetX/offsetY will be wrong when there is shadow content
Comment 6 Simon Fraser (smfr) 2008-10-24 23:05:46 PDT
(In reply to comment #5)
> Hmm, I think offsetX/offsetY will be wrong when there is shadow content

No, it's OK. MouseRelatedEvent::receivedTarget() gets the renderer from the target element.
Comment 7 Dave Hyatt 2008-10-27 12:08:33 PDT
Comment on attachment 24670 [details]
Patch

It seems like absolutePosition could just be patched rather than adding new code...
Comment 8 Simon Fraser (smfr) 2008-11-05 18:03:55 PST
Created attachment 24928 [details]
Implement absoluteToLocal, fix event.offsetX/offsetY
Comment 9 Simon Fraser (smfr) 2008-11-05 18:04:31 PST
Created attachment 24929 [details]
Testcase in the patch
Comment 10 Dave Hyatt 2008-11-06 10:12:40 PST
Comment on attachment 24928 [details]
Implement absoluteToLocal, fix event.offsetX/offsetY

r=me (comments given on IRC).
Comment 11 Simon Fraser (smfr) 2008-11-06 10:15:26 PST
TODO: assert about LayoutState in absoluteToLocal()
Comment 12 Simon Fraser (smfr) 2008-11-06 10:42:47 PST
Committed r38186
	M	WebCore/rendering/RenderObject.cpp
	M	WebCore/rendering/RenderTableCell.cpp
	M	WebCore/rendering/RenderBox.h
	M	WebCore/rendering/RenderObject.h
	M	WebCore/rendering/RenderBox.cpp
	M	WebCore/rendering/RenderView.cpp
	M	WebCore/rendering/RenderView.h
	M	WebCore/rendering/RenderTableCell.h
	M	WebCore/dom/MouseRelatedEvent.cpp
	M	WebCore/ChangeLog
	M	LayoutTests/ChangeLog
	A	LayoutTests/fast/events/offsetX-offsetY.html
	A	LayoutTests/fast/events/offsetX-offsetY-expected.txt
r38186 = 845c2633f46b1eaecab8595b53b2a1cdfb06b7e2 (trunk)