../WebCore: InjectedBundleHitTestResult::imageRect() should return rect in WKView...
authorjeffm@apple.com <jeffm@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Oct 2011 22:11:12 +0000 (22:11 +0000)
committerjeffm@apple.com <jeffm@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Oct 2011 22:11:12 +0000 (22:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=69963

Add infrastructure to convert from any frame view's coordinate system to the
root view's coordinate system.

Reviewed by Simon Fraser.

No new tests (yet), this is covered by <https://bugs.webkit.org/show_bug.cgi?id=70136>.

* WebCore.exp.in: Exported WebCore::ScrollView::contentsToRootView(), used by InjectedBundleHitTestResult.cpp.

* platform/ScrollView.cpp:
(WebCore::ScrollView::rootViewToContents): Added (both point and rect versions).
(WebCore::ScrollView::contentsToRootView): Ditto.

* platform/ScrollView.h: Added member functions to convert to/from root view coordinates.

* platform/Widget.cpp:
(WebCore::Widget::convertFromRootView): Added (both point and rect versions).
(WebCore::Widget::convertToRootView): Ditto.

* platform/Widget.h: Added member functions to convert to/from root view coordinates.

../WebKit2: InjectedBundleHitTestResult::imageRect() should return rect in WKView coordinates
https://bugs.webkit.org/show_bug.cgi?id=69963

WebKit2 clients only have knowledge of the WKView's coordinate system, they have no way to
convert from subframe view coordinates , so any rect that we expose through WK2 APIs should
be in WKView coordinates.

Reviewed by Simon Fraser.

* WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
(WebKit::InjectedBundleHitTestResult::imageRect): Use WebCore::FrameView::contentsToRootView() to convert the image rect to WKView coordinates.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@97514 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/platform/ScrollView.cpp
Source/WebCore/platform/ScrollView.h
Source/WebCore/platform/Widget.cpp
Source/WebCore/platform/Widget.h
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp

index f8b3796..f0daa39 100644 (file)
@@ -1,3 +1,29 @@
+2011-10-14  Jeff Miller  <jeffm@apple.com>
+
+        InjectedBundleHitTestResult::imageRect() should return rect in WKView coordinates
+        https://bugs.webkit.org/show_bug.cgi?id=69963
+        
+        Add infrastructure to convert from any frame view's coordinate system to the
+        root view's coordinate system.
+
+        Reviewed by Simon Fraser.
+
+        No new tests (yet), this is covered by <https://bugs.webkit.org/show_bug.cgi?id=70136>.
+
+        * WebCore.exp.in: Exported WebCore::ScrollView::contentsToRootView(), used by InjectedBundleHitTestResult.cpp.
+        
+        * platform/ScrollView.cpp:
+        (WebCore::ScrollView::rootViewToContents): Added (both point and rect versions).
+        (WebCore::ScrollView::contentsToRootView): Ditto.
+        
+        * platform/ScrollView.h: Added member functions to convert to/from root view coordinates.
+        
+        * platform/Widget.cpp:
+        (WebCore::Widget::convertFromRootView): Added (both point and rect versions).
+        (WebCore::Widget::convertToRootView): Ditto.
+        
+        * platform/Widget.h: Added member functions to convert to/from root view coordinates.
+
 2011-10-14  Andreas Kling  <kling@webkit.org>
 
         CSSParser: Remove StyleBase usage.
index 407450b..06cbe8f 100644 (file)
@@ -1105,6 +1105,7 @@ __ZNK7WebCore10ScrollView16windowToContentsERKNS_7IntRectE
 __ZNK7WebCore10ScrollView16contentsToWindowERKNS_8IntPointE
 __ZNK7WebCore10ScrollView16windowToContentsERKNS_8IntPointE
 __ZNK7WebCore10ScrollView18visibleContentRectEb
+__ZNK7WebCore10ScrollView18contentsToRootViewERKNS_7IntRectE
 __ZN7WebCore11CachedImage5imageEv
 __ZNK7WebCore11FrameLoader10isCompleteEv
 __ZNK7WebCore11FrameLoader14cancelledErrorERKNS_15ResourceRequestE
index 2205b2e..8aebb00 100644 (file)
@@ -681,6 +681,32 @@ void ScrollView::scrollContentsSlowPath(const IntRect& updateRect)
     hostWindow()->invalidateContentsForSlowScroll(updateRect, false);
 }
 
+IntPoint ScrollView::rootViewToContents(const IntPoint& rootViewPoint) const
+{
+    IntPoint viewPoint = convertFromRootView(rootViewPoint);
+    return viewPoint + scrollOffset();
+}
+
+IntPoint ScrollView::contentsToRootView(const IntPoint& contentsPoint) const
+{
+    IntPoint viewPoint = contentsPoint - scrollOffset();
+    return convertToRootView(viewPoint);  
+}
+
+IntRect ScrollView::rootViewToContents(const IntRect& rootViewRect) const
+{
+    IntRect viewRect = convertFromRootView(rootViewRect);
+    viewRect.move(scrollOffset());
+    return viewRect;
+}
+
+IntRect ScrollView::contentsToRootView(const IntRect& contentsRect) const
+{
+    IntRect viewRect = contentsRect;
+    viewRect.move(-scrollOffset());
+    return convertToRootView(viewRect);
+}
+
 IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const
 {
     IntPoint viewPoint = convertFromContainingWindow(windowPoint);
index 92cb924..068d84a 100644 (file)
@@ -197,6 +197,11 @@ public:
     void setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress = false);
     bool scrollbarsSuppressed() const { return m_scrollbarsSuppressed; }
 
+    IntPoint rootViewToContents(const IntPoint&) const;
+    IntPoint contentsToRootView(const IntPoint&) const;
+    IntRect rootViewToContents(const IntRect&) const;
+    IntRect contentsToRootView(const IntRect&) const;
+
     // Event coordinates are assumed to be in the coordinate space of a window that contains
     // the entire widget hierarchy. It is up to the platform to decide what the precise definition
     // of containing window is. (For example on Mac it is the containing NSWindow.)
index 77560ff..613c473 100644 (file)
@@ -69,6 +69,42 @@ void Widget::removeFromParent()
         parent()->removeChild(this);
 }
 
+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;
+}
+
 IntRect Widget::convertFromContainingWindow(const IntRect& windowRect) const
 {
     if (const ScrollView* parentScrollView = parent()) {
index 5900ced..896426a 100644 (file)
@@ -177,6 +177,12 @@ public:
 
     virtual void notifyWidget(WidgetNotification) { }
 
+    IntRect convertToRootView(const IntRect&) const;
+    IntRect convertFromRootView(const IntRect&) const;
+
+    IntPoint convertToRootView(const IntPoint&) const;
+    IntPoint convertFromRootView(const IntPoint&) const;
+
     // It is important for cross-platform code to realize that Mac has flipped coordinates.  Therefore any code
     // that tries to convert the location of a rect using the point-based convertFromContainingWindow will end
     // up with an inaccurate rect.  Always make sure to use the rect-based convertFromContainingWindow method
index 01a109b..629edd2 100644 (file)
@@ -1,3 +1,17 @@
+2011-10-14  Jeff Miller  <jeffm@apple.com>
+
+        InjectedBundleHitTestResult::imageRect() should return rect in WKView coordinates
+        https://bugs.webkit.org/show_bug.cgi?id=69963
+        
+        WebKit2 clients only have knowledge of the WKView's coordinate system, they have no way to
+        convert from subframe view coordinates , so any rect that we expose through WK2 APIs should
+        be in WKView coordinates.
+        
+        Reviewed by Simon Fraser.
+
+        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
+        (WebKit::InjectedBundleHitTestResult::imageRect): Use WebCore::FrameView::contentsToRootView() to convert the image rect to WKView coordinates.
+
 2011-10-14  Mark Hahnenberg  <mhahnenberg@apple.com>
 
         Rename virtual deleteProperty to deletePropertyVirtual
index c359b42..b326e9b 100644 (file)
@@ -32,6 +32,7 @@
 #include <WebCore/Document.h>
 #include <WebCore/Frame.h>
 #include <WebCore/FrameLoader.h>
+#include <WebCore/FrameView.h>
 #include <WebCore/KURL.h>
 #include <wtf/text/WTFString.h>
 
@@ -102,7 +103,25 @@ String InjectedBundleHitTestResult::linkTitle() const
 
 WebCore::IntRect InjectedBundleHitTestResult::imageRect() const
 {
-    return m_hitTestResult.imageRect();
+    WebCore::IntRect imageRect = m_hitTestResult.imageRect();
+    if (imageRect.isEmpty())
+        return imageRect;
+        
+    // The image rect in WebCore::HitTestResult is in frame coordinates, but we need it in WKView
+    // coordinates since WebKit2 clients don't have enough context to do the conversion themselves.
+    WebFrame* webFrame = frame();
+    if (!webFrame)
+        return imageRect;
+    
+    WebCore::Frame* coreFrame = webFrame->coreFrame();
+    if (!coreFrame)
+        return imageRect;
+    
+    WebCore::FrameView* view = coreFrame->view();
+    if (!view)
+        return imageRect;
+    
+    return view->contentsToRootView(imageRect);
 }
 
 bool InjectedBundleHitTestResult::isSelected() const