+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
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(),
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(),
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);
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);
// 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;
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.
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);
}
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;
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();
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(),
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);
}
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);
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);
return false;
}
+IntRect Widget::convertToContainingWindow(const IntRect& rect) const
+{
+ IntRect convertedRect = rect;
+ convertedRect.setLocation(convertToContainingWindow(convertedRect.location()));
+ return convertedRect;
+}
+
}
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;
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;
return IntPoint();
}
-IntPoint ScrollView::viewportToContents(const IntPoint& viewportPoint)
+IntPoint ScrollView::convertFromContainingWindow(const IntPoint& point) const
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
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);
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();
+}
+
}
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
// 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;