Commit 97c694f0 authored by hyatt's avatar hyatt

Eliminate viewportToContents and contentsToViewport

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@16630 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 82b0749c
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
......@@ -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(),
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
}
......@@ -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;
......
......@@ -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);
......
......@@ -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();
}
}
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment