Bug 21870

Summary: [Transforms] event.offsetX and offsetY are wrong for transformed elements
Product: WebKit Reporter: Simon Fraser (smfr) <simon.fraser>
Component: Layout and RenderingAssignee: Simon Fraser (smfr) <simon.fraser>
Status: RESOLVED FIXED    
Severity: Normal CC: hyatt, mitz
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.5   
Bug Depends on: 21941    
Bug Blocks:    
Attachments:
Description Flags
Testcase
none
WIP patch
none
Patch
hyatt: review-
Implement absoluteToLocal, fix event.offsetX/offsetY
hyatt: review+
Testcase in the patch none

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)