Eliminate viewportToContents and contentsToViewport
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Sep 2006 00:17:01 +0000 (00:17 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Sep 2006 00:17:01 +0000 (00:17 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16630 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/dom/EventTargetNode.cpp
WebCore/page/Frame.cpp
WebCore/page/FrameView.cpp
WebCore/platform/ScrollView.h
WebCore/platform/Widget.cpp
WebCore/platform/Widget.h
WebCore/platform/mac/ScrollViewMac.mm
WebCore/platform/mac/WidgetMac.mm
WebCore/platform/win/ScrollViewWin.cpp
WebCore/rendering/RenderLayer.cpp

index 5b4311614ed685d62abf465cd00413f97feccc9b..0a96ddf2a5e3316c915e6c82ac2057d38d9a80d6 100644 (file)
@@ -1,3 +1,43 @@
+2006-09-28  Dave Hyatt  <hyatt@apple.com>
+
+        This patch eliminates viewportToContents/contentsToViewport in favor of convertTo/FromContainingWindow.
+        ScrollView now subclasses these methods to factor in its scrollOffset and to deal with the document
+        view.
+       
+        Reviewed by mjs (the convertTo/From changes), (I added the elimination of viewportToContents to
+        the patch after review, once I realized that these new functions essentially do the same thing.)
+
+        * dom/EventTargetNode.cpp:
+        (WebCore::EventTargetNode::dispatchMouseEvent):
+        (WebCore::EventTargetNode::dispatchWheelEvent):
+        * page/Frame.cpp:
+        (WebCore::Frame::selectClosestWordFromMouseEvent):
+        (WebCore::Frame::handleMousePressEventTripleClick):
+        (WebCore::Frame::handleMousePressEventSingleClick):
+        (WebCore::Frame::handleMouseMoveEvent):
+        (WebCore::Frame::handleMouseReleaseEvent):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::handleMousePressEvent):
+        (WebCore::selectCursor):
+        (WebCore::FrameView::dispatchDragEvent):
+        (WebCore::FrameView::prepareMouseEvent):
+        (WebCore::FrameView::handleWheelEvent):
+        * platform/ScrollView.h:
+        * platform/Widget.cpp:
+        (WebCore::Widget::convertToContainingWindow):
+        * platform/Widget.h:
+        * platform/mac/ScrollViewMac.mm:
+        (WebCore::ScrollView::convertToContainingWindow):
+        (WebCore::ScrollView::convertFromContainingWindow):
+        * platform/mac/WidgetMac.mm:
+        (WebCore::Widget::convertToContainingWindow):
+        (WebCore::Widget::convertFromContainingWindow):
+        * platform/win/ScrollViewWin.cpp:
+        (WebCore::ScrollView::convertToContainingWindow):
+        (WebCore::ScrollView::convertFromContainingWindow):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::resize):
+
 2006-09-28  Alice Liu  <alice.liu@apple.com>
 
         Build fix by adding missing files for CommandByName
index 4eaa0c36261848977b4f4eabb8d953c4f54d60ed..dbc2f00e04930117898edbd09ecc0704e4c06174 100644 (file)
@@ -368,7 +368,7 @@ bool EventTargetNode::dispatchMouseEvent(const PlatformMouseEvent& _mouse, const
     
     IntPoint contentsPos;
     if (FrameView* view = document()->view())
-        contentsPos = view->viewportToContents(_mouse.pos());
+        contentsPos = view->convertFromContainingWindow(_mouse.pos());
     
     return dispatchMouseEvent(eventType, _mouse.button(), detail,
                               contentsPos.x(), contentsPos.y(), _mouse.globalX(), _mouse.globalY(),
@@ -453,7 +453,7 @@ void EventTargetNode::dispatchWheelEvent(PlatformWheelEvent& e)
     if (!view)
         return;
     
-    IntPoint pos = view->viewportToContents(e.pos());
+    IntPoint pos = view->convertFromContainingWindow(e.pos());
     
     RefPtr<WheelEvent> we = new WheelEvent(e.deltaX(), e.deltaY(),
                                            document()->defaultView(), e.globalX(), e.globalY(), pos.x(), pos.y(),
index 1dc7f08cd7311ae1156844386a3f48b3a2ff2342..4ab09fc1129f16efdbec33044a8e1d2eb33b09eb 100644 (file)
@@ -1814,7 +1814,7 @@ void Frame::selectClosestWordFromMouseEvent(const PlatformMouseEvent& mouse, Nod
     Selection newSelection;
 
     if (innerNode && innerNode->renderer() && mouseDownMayStartSelect() && innerNode->renderer()->shouldSelect()) {
-        IntPoint vPoint = view()->viewportToContents(mouse.pos());
+        IntPoint vPoint = view()->convertFromContainingWindow(mouse.pos());
         VisiblePosition pos(innerNode->renderer()->positionForPoint(vPoint));
         if (pos.isNotNull()) {
             newSelection = Selection(pos);
@@ -1853,7 +1853,7 @@ void Frame::handleMousePressEventTripleClick(const MouseEventWithHitTestResults&
     if (event.event().button() == LeftButton && innerNode && innerNode->renderer() &&
         mouseDownMayStartSelect() && innerNode->renderer()->shouldSelect()) {
         Selection newSelection;
-        IntPoint vPoint = view()->viewportToContents(event.event().pos());
+        IntPoint vPoint = view()->convertFromContainingWindow(event.event().pos());
         VisiblePosition pos(innerNode->renderer()->positionForPoint(vPoint));
         if (pos.isNotNull()) {
             newSelection = Selection(pos);
@@ -1882,7 +1882,7 @@ void Frame::handleMousePressEventSingleClick(const MouseEventWithHitTestResults&
 
             // Don't restart the selection when the mouse is pressed on an
             // existing selection so we can allow for text dragging.
-            IntPoint vPoint = view()->viewportToContents(event.event().pos());
+            IntPoint vPoint = view()->convertFromContainingWindow(event.event().pos());
             if (!extendSelection && isPointInsideSelection(vPoint))
                 return;
 
@@ -1954,7 +1954,7 @@ void Frame::handleMouseMoveEvent(const MouseEventWithHitTestResults& event)
         return;
 
     // handle making selection
-    IntPoint vPoint = view()->viewportToContents(event.event().pos());
+    IntPoint vPoint = view()->convertFromContainingWindow(event.event().pos());
     VisiblePosition pos(innerNode->renderer()->positionForPoint(vPoint));
 
     // Don't modify the selection if we're not on a node.
@@ -1996,7 +1996,7 @@ void Frame::handleMouseReleaseEvent(const MouseEventWithHitTestResults& event)
         Selection newSelection;
         Node *node = event.targetNode();
         if (node && node->isContentEditable() && node->renderer()) {
-            IntPoint vPoint = view()->viewportToContents(event.event().pos());
+            IntPoint vPoint = view()->convertFromContainingWindow(event.event().pos());
             VisiblePosition pos = node->renderer()->positionForPoint(vPoint);
             newSelection = Selection(pos);
         }
index 2be880b05e48cd30ef24914729c952861599d85f..45e9510d420604a418978f30181e3f38af2b279b 100644 (file)
@@ -584,7 +584,7 @@ void FrameView::handleMousePressEvent(const PlatformMouseEvent& mouseEvent)
     d->clickNode = mev.targetNode();
     
     RenderLayer* layer = d->clickNode->renderer()? d->clickNode->renderer()->enclosingLayer() : 0;
-    IntPoint p =  viewportToContents(mouseEvent.pos());
+    IntPoint p =  convertFromContainingWindow(mouseEvent.pos());
     if (layer && layer->isPointInResizeControl(p)) {
         layer->setInResizeMode(true);
         d->m_resizeLayer = layer;
@@ -691,7 +691,7 @@ static Cursor selectCursor(const MouseEventWithHitTestResults& event, Frame* fra
                 return handCursor();
             RenderLayer* layer = renderer ? renderer->enclosingLayer() : 0;
             bool inResizer = false;
-            if (frame->view() && layer && layer->isPointInResizeControl(frame->view()->viewportToContents(event.event().pos())))
+            if (frame->view() && layer && layer->isPointInResizeControl(frame->view()->convertFromContainingWindow(event.event().pos())))
                 inResizer = true;
             if ((editable || (renderer && renderer->isText() && renderer->canSelect())) && !inResizer && !RenderLayer::gScrollBar)
                 return iBeamCursor();
@@ -843,7 +843,7 @@ void FrameView::handleMouseReleaseEvent(const PlatformMouseEvent& mouseEvent)
 
 bool FrameView::dispatchDragEvent(const AtomicString& eventType, Node *dragTarget, const PlatformMouseEvent& event, Clipboard* clipboard)
 {
-    IntPoint contentsPos = viewportToContents(event.pos());
+    IntPoint contentsPos = convertFromContainingWindow(event.pos());
     
     RefPtr<MouseEvent> me = new MouseEvent(eventType,
         true, true, m_frame->document()->defaultView(),
@@ -1138,7 +1138,7 @@ MouseEventWithHitTestResults FrameView::prepareMouseEvent(bool readonly, bool ac
     ASSERT(m_frame);
     ASSERT(m_frame->document());
     
-    IntPoint vPoint = viewportToContents(mev.pos());
+    IntPoint vPoint = convertFromContainingWindow(mev.pos());
     return m_frame->document()->prepareMouseEvent(readonly, active, mouseMove, vPoint, mev);
 }
 
@@ -1222,7 +1222,7 @@ void FrameView::handleWheelEvent(PlatformWheelEvent& e)
     if (doc) {
         RenderObject *docRenderer = doc->renderer();
         if (docRenderer) {
-            IntPoint vPoint = viewportToContents(e.pos());
+            IntPoint vPoint = convertFromContainingWindow(e.pos());
 
             RenderObject::NodeInfo hitTestResult(true, false);
             doc->renderer()->layer()->hitTest(hitTestResult, vPoint); 
index aa89de1c2f28906619447da0f73d95816046d2c8..4615eb6cd1c68b22d732b5ad59d0ea51b0dfbd32 100644 (file)
@@ -71,8 +71,8 @@ namespace WebCore {
         virtual void resizeContents(int w, int h);
         void updateContents(const IntRect&, bool now = false);
 
-        IntPoint contentsToViewport(const IntPoint&);
-        IntPoint viewportToContents(const IntPoint&);
+        virtual IntPoint convertToContainingWindow(const IntPoint&) const;
+        virtual IntPoint convertFromContainingWindow(const IntPoint&) const;
 
         void setStaticBackground(bool);
 
index 1de54827ab088c1a04463f9d46a7b4b457f92341..7df98527633756c0c8dee26e1b022a83d206414b 100644 (file)
@@ -100,4 +100,11 @@ bool Widget::isFrameView() const
     return false;
 }
 
+IntRect Widget::convertToContainingWindow(const IntRect& rect) const
+{
+    IntRect convertedRect = rect;
+    convertedRect.setLocation(convertToContainingWindow(convertedRect.location()));
+    return convertedRect;
+}
+
 }
index c107a094064793b8d808933263dfdff79900290c..bc74a741e0adebb06d789c26f64992eb6419590b 100644 (file)
@@ -128,11 +128,20 @@ namespace WebCore {
 
         virtual bool isFrameView() const;
 
-#if PLATFORM(WIN)
+        // 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.)
+        //
+        // Note that for scrollable widgets, the points and rects given will be converted to and
+        // from the document coordinate space inside the scrollable widget.  Therefore
+        // for conversion to a containing window coordinate space, the argument should be in the
+        // scrollable widget's document coordinate space.  When converting from the containing window
+        // coordinate space, the result will be in the scrollable widget's document coordinate space.
         IntRect convertToContainingWindow(const IntRect&) const;
-        IntPoint convertToContainingWindow(const IntPoint&) const;
-        IntPoint convertFromContainingWindow(const IntPoint&) const;
+        virtual IntPoint convertToContainingWindow(const IntPoint&) const;
+        virtual IntPoint convertFromContainingWindow(const IntPoint&) const;
 
+#if PLATFORM(WIN)
         void setContainingWindow(HWND);
         HWND containingWindow() const;
 
index 21a530dd4c12773849794ef127d739a11f2b2a13..adc3befe15126e211e6ae306c2873469c1884fc9 100644 (file)
@@ -353,9 +353,9 @@ void ScrollView::updateContents(const IntRect &rect, bool now)
     END_BLOCK_OBJC_EXCEPTIONS;
 }
 
-// NB, for us "viewport" means the NSWindow's coord system, which is origin lower left
+// "Containing Window" means the NSWindow's coord system, which is origin lower left
 
-IntPoint ScrollView::contentsToViewport(const IntPoint& contentsPoint)
+IntPoint ScrollView::convertToContainingWindow(const IntPoint& contentsPoint) const
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
@@ -375,7 +375,7 @@ IntPoint ScrollView::contentsToViewport(const IntPoint& contentsPoint)
     return IntPoint();
 }
 
-IntPoint ScrollView::viewportToContents(const IntPoint& viewportPoint)
+IntPoint ScrollView::convertFromContainingWindow(const IntPoint& point) const
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
@@ -386,7 +386,7 @@ IntPoint ScrollView::viewportToContents(const IntPoint& viewportPoint)
     if (docView)
         view = docView;
     
-    NSPoint tempPoint = { viewportPoint.x(), viewportPoint.y() }; // workaround for 4213314
+    NSPoint tempPoint = { point.x(), point.y() }; // workaround for 4213314
     NSPoint np = [view convertPoint:tempPoint fromView: nil];
 
     return IntPoint(np);
index 9cfd62a3c260fe521905b6afbaf7b70243e4673d..6320f1e34cfd990acaa60d27eb2c8f5bf830617c 100644 (file)
@@ -452,4 +452,34 @@ WidgetClient* Widget::client() const
     return data->client;
 }
 
+// "Containing Window" means the NSWindow's coord system, which is origin lower left
+
+IntPoint Widget::convertToContainingWindow(const IntPoint& point) const
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    NSView *view = getView();    
+    NSPoint tempPoint = { point.x(), point.y() }; // workaround for 4213314
+    NSPoint np = [view convertPoint:tempPoint toView: nil];
+    return IntPoint(np);
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+    
+    return IntPoint();
+}
+
+IntPoint Widget::convertFromContainingWindow(const IntPoint& point) const
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+    NSView *view = getView();        
+    NSPoint tempPoint = { point.x(), point.y() }; // workaround for 4213314
+    NSPoint np = [view convertPoint:tempPoint fromView: nil];
+
+    return IntPoint(np);
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+
+    return IntPoint();
+}
+
 }
index 4d9c089e7a22df0e7f47998ab87e9ea35453e639..a51dfbe7822c7124c09d76bd6da4fc8e85037297 100644 (file)
@@ -139,14 +139,14 @@ int ScrollView::contentsHeight() const
     return m_data->contentsSize.height();
 }
 
-IntPoint ScrollView::viewportToContents(const IntPoint& viewportPoint)
+IntPoint ScrollView::convertToContainingWindow(const IntPoint& point) const
 {
-    return IntPoint(viewportPoint) + scrollOffset();
+    return contentsPoint - scrollOffset();
 }
 
-IntPoint ScrollView::contentsToViewport(const IntPoint& contentsPoint)
+IntPoint ScrollView::convertFromContainingWindow(const IntPoint& point) const
 {
-    return contentsPoint - scrollOffset();
+    return IntPoint(point) + scrollOffset();
 }
 
 IntSize ScrollView::scrollOffset() const
index d8c2ab8f943128649c140938790b8051cfff0878..cf5e5b63dbe2710d0b18510080ac43e55e0f30f6 100644 (file)
@@ -812,7 +812,7 @@ void RenderLayer::resize(const PlatformMouseEvent& evt, const IntSize& offsetFro
     // FIXME Radar 4118564: ideally we'd autoscroll the window as necessary to keep the point under
     // the cursor in view.
 
-    IntPoint currentPoint = m_object->document()->view()->viewportToContents(evt.pos());
+    IntPoint currentPoint = m_object->document()->view()->convertFromContainingWindow(evt.pos());
     currentPoint += offsetFromResizeCorner;
 
     int x;