Bug 69963 - InjectedBundleHitTestResult::imageRect() should return rect in WKView coordinates
Summary: InjectedBundleHitTestResult::imageRect() should return rect in WKView coordin...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Jeff Miller
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2011-10-12 14:24 PDT by Jeff Miller
Modified: 2011-10-14 15:16 PDT (History)
3 users (show)

See Also:


Attachments
Patch (2.27 KB, patch)
2011-10-12 14:30 PDT, Jeff Miller
no flags Details | Formatted Diff | Diff
Patch (9.15 KB, patch)
2011-10-14 13:08 PDT, Jeff Miller
simon.fraser: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Miller 2011-10-12 14:24:13 PDT
Since WebKit2 clients only know about the WKView coordinate space, this rectangle is only useful if it's in that space.
Comment 1 Radar WebKit Bug Importer 2011-10-12 14:24:33 PDT
<rdar://problem/10275376>
Comment 2 Jeff Miller 2011-10-12 14:30:04 PDT
Created attachment 110747 [details]
Patch
Comment 3 Adam Roben (:aroben) 2011-10-12 14:35:59 PDT
Comment on attachment 110747 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=110747&action=review

Is it possible to write a test for this?

> Source/WebKit2/ChangeLog:7
> +        InjectedBundleHitTestResult::imageRect() should return rect in WKView coordinates
> +        https://bugs.webkit.org/show_bug.cgi?id=69963
> +        
> +        Use the confusingly-named ScrollView::contentsToWindow() function to convert the image rect
> +        from frame to WKView coordinates.

Can you give a little justification as to why WKView coordinates are better than whatever coordinates we were previously using?
Comment 4 Sam Weinig 2011-10-12 14:48:38 PDT
In the immortal words of Adam Roben, "this should have an API test."
Comment 5 Adam Roben (:aroben) 2011-10-12 14:49:14 PDT
(In reply to comment #4)
> In the immortal words of Adam Roben, "this should have an API test."

Actually, my words were:

(In reply to comment #3)
> Is it possible to write a test for this?
Comment 6 Jeff Miller 2011-10-12 14:57:49 PDT
Comment on attachment 110747 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=110747&action=review

>> Source/WebKit2/ChangeLog:7
>> +        from frame to WKView coordinates.
> 
> Can you give a little justification as to why WKView coordinates are better than whatever coordinates we were previously using?

The justification is in the comment in the code, but I'll elaborate in the ChangeLog.
Comment 7 Simon Fraser (smfr) 2011-10-12 15:03:00 PDT
Comment on attachment 110747 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=110747&action=review

>>> Source/WebKit2/ChangeLog:7
>>> +        from frame to WKView coordinates.
>> 
>> Can you give a little justification as to why WKView coordinates are better than whatever coordinates we were previously using?
> 
> The justification is in the comment in the code, but I'll elaborate in the ChangeLog.

"ToWindow" really is window coords, not view coords. The coords will be flipped in WK1.
Comment 8 Darin Adler 2011-10-13 09:15:45 PDT
Comment on attachment 110747 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=110747&action=review

>>>> Source/WebKit2/ChangeLog:7
>>>> +        from frame to WKView coordinates.
>>> 
>>> Can you give a little justification as to why WKView coordinates are better than whatever coordinates we were previously using?
>> 
>> The justification is in the comment in the code, but I'll elaborate in the ChangeLog.
> 
> "ToWindow" really is window coords, not view coords. The coords will be flipped in WK1.

This is injected bundle code in WebKit2, so I don’t see how WebKit1 is relevant.
Comment 9 Jeff Miller 2011-10-13 12:51:36 PDT
Comment on attachment 110747 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=110747&action=review

>>>>> Source/WebKit2/ChangeLog:7
>>>>> +        from frame to WKView coordinates.
>>>> 
>>>> Can you give a little justification as to why WKView coordinates are better than whatever coordinates we were previously using?
>>> 
>>> The justification is in the comment in the code, but I'll elaborate in the ChangeLog.
>> 
>> "ToWindow" really is window coords, not view coords. The coords will be flipped in WK1.
> 
> This is injected bundle code in WebKit2, so I don’t see how WebKit1 is relevant.

WebKit1 isn't relevant, but the first part of Simon's comment is correct.  After talking to Simon more, I'm working on a patch to add member functions to Widget and ScrollView to convert between frame view and root view coordinate systems, since there's no way to do this currently. InjectedBundleHitTestResult::imageRect() can use one of these functions, and I also need to write a WK2 API test (as Sam and Adam pointed out).
Comment 10 Jeff Miller 2011-10-14 12:57:48 PDT
I wrote bug 70136 to cover writing the test for this, since I need to land this patch soon.
Comment 11 Jeff Miller 2011-10-14 13:08:19 PDT
Created attachment 111062 [details]
Patch
Comment 12 Simon Fraser (smfr) 2011-10-14 14:15:33 PDT
Comment on attachment 111062 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=111062&action=review

> Source/WebCore/platform/Widget.cpp:106
> +IntRect Widget::convertFromRootView(const IntRect& rootRect) const
> +{
> +    if (const ScrollView* parentScrollView = parent()) {
> +        IntRect parentRect = parentScrollView->convertFromRootView(rootRect);
> +        return convertFromContainingView(parentRect);
> +    }
> +    return rootRect;
> +}
> +
> +IntRect Widget::convertToRootView(const IntRect& localRect) const
> +{
> +    if (const ScrollView* parentScrollView = parent()) {
> +        IntRect parentRect = convertToContainingView(localRect);
> +        return parentScrollView->convertToRootView(parentRect);
> +    }
> +    return localRect;
> +}
> +
> +IntPoint Widget::convertFromRootView(const IntPoint& rootPoint) const
> +{
> +    if (const ScrollView* parentScrollView = parent()) {
> +        IntPoint parentPoint = parentScrollView->convertFromRootView(rootPoint);
> +        return convertFromContainingView(parentPoint);
> +    }
> +    return rootPoint;
> +}
> +
> +IntPoint Widget::convertToRootView(const IntPoint& localPoint) const
> +{
> +    if (const ScrollView* parentScrollView = parent()) {
> +        IntPoint parentPoint = convertToContainingView(localPoint);
> +        return parentScrollView->convertToRootView(parentPoint);
> +    }
> +    return localPoint;
> +}

How about calling these from the existing toWindow/fromWindow calls?
Comment 13 Jeff Miller 2011-10-14 14:34:16 PDT
Comment on attachment 111062 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=111062&action=review

>> Source/WebCore/platform/Widget.cpp:106
>> +}
> 
> How about calling these from the existing toWindow/fromWindow calls?

Good idea, but I'd rather not perturb existing code in this patch. I will file a followup bug to track this.
Comment 14 Jeff Miller 2011-10-14 15:10:22 PDT
Committed r97514: <http://trac.webkit.org/changeset/97514>
Comment 15 Jeff Miller 2011-10-14 15:16:14 PDT
I wrote bug 70152 to track Simon's suggestion.