diff options
author | Derek Sollenberger <djsollen@google.com> | 2009-08-03 15:45:38 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2009-08-03 16:27:57 -0400 |
commit | 5655832af95b56bf25c0183a2d5d2cd909d6c8f4 (patch) | |
tree | 8a04a08cb255e2a90eb5649f3fc6d1dcef9b95e9 | |
parent | 51c0d4c6b1b74fff7336d81451ba7d2fc132e31c (diff) | |
download | external_webkit-5655832af95b56bf25c0183a2d5d2cd909d6c8f4.zip external_webkit-5655832af95b56bf25c0183a2d5d2cd909d6c8f4.tar.gz external_webkit-5655832af95b56bf25c0183a2d5d2cd909d6c8f4.tar.bz2 |
Fixing mouse and touch coordinates inside iframes.
-rw-r--r-- | WebCore/plugins/android/PluginViewAndroid.cpp | 43 | ||||
-rw-r--r-- | WebKit/android/plugins/PluginWidgetAndroid.cpp | 26 | ||||
-rw-r--r-- | WebKit/android/plugins/PluginWidgetAndroid.h | 2 |
3 files changed, 41 insertions, 30 deletions
diff --git a/WebCore/plugins/android/PluginViewAndroid.cpp b/WebCore/plugins/android/PluginViewAndroid.cpp index 54a085d..d88692d 100644 --- a/WebCore/plugins/android/PluginViewAndroid.cpp +++ b/WebCore/plugins/android/PluginViewAndroid.cpp @@ -228,13 +228,11 @@ void PluginView::handleTouchEvent(TouchEvent* event) evt.data.touch.modifiers = 0; // todo - // the event is relative to the window's (0,0), so use convertToContainingWindow - IntPoint winCoordinates = IntPoint(event->x(), event->y()); - IntPoint docCoordinates = parent()->windowToContents(winCoordinates); - - // convert to coordinates that are relative to the plugin - evt.data.touch.x = docCoordinates.x() - m_npWindow.x; - evt.data.touch.y = docCoordinates.y() - m_npWindow.y; + // convert to coordinates that are relative to the plugin. The pageX / pageY + // values are the only values in the event that are consistently in frame + // coordinates despite their misleading name. + evt.data.touch.x = event->pageX() - m_npWindow.x; + evt.data.touch.y = event->pageY() - m_npWindow.y; if (m_plugin->pluginFuncs()->event(m_instance, &evt)) { event->setDefaultPrevented(true); @@ -253,13 +251,11 @@ void PluginView::handleMouseEvent(MouseEvent* event) SkANP::InitEvent(&evt, kMouse_ANPEventType); evt.data.mouse.action = isUp ? kUp_ANPMouseAction : kDown_ANPMouseAction; - // the event is relative to the window's (0,0), so use convertToContainingWindow - IntPoint winCoordinates = IntPoint(event->x(), event->y()); - IntPoint docCoordinates = parent()->windowToContents(winCoordinates); - - // convert to coordinates that are relative to the plugin - evt.data.mouse.x = docCoordinates.x() - m_npWindow.x; - evt.data.mouse.y = docCoordinates.y() - m_npWindow.y; + // convert to coordinates that are relative to the plugin. The pageX / pageY + // values are the only values in the event that are consistently in frame + // coordinates despite their misleading name. + evt.data.mouse.x = event->pageX() - m_npWindow.x; + evt.data.mouse.y = event->pageY() - m_npWindow.y; } else { return; @@ -377,21 +373,16 @@ void PluginView::setNPWindowRect(const IntRect& rect) if (!m_isStarted) return; - const int width = rect.width(); - const int height = rect.height(); - - // the rect is relative to the frameview's (0,0), so use convertToContainingWindow - IntPoint p = parent()->convertToContainingWindow(rect.location()); - m_npWindow.x = p.x(); - m_npWindow.y = p.y(); - - m_npWindow.width = width; - m_npWindow.height = height; + // the rect is relative to the frameview's (0,0) + m_npWindow.x = rect.x(); + m_npWindow.y = rect.y(); + m_npWindow.width = rect.width(); + m_npWindow.height = rect.height(); m_npWindow.clipRect.left = 0; m_npWindow.clipRect.top = 0; - m_npWindow.clipRect.right = width; - m_npWindow.clipRect.bottom = height; + m_npWindow.clipRect.right = rect.width(); + m_npWindow.clipRect.bottom = rect.height(); if (m_plugin->pluginFuncs()->setwindow) { #if USE(JSC) diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp index 30a55cb..96aa74b 100644 --- a/WebKit/android/plugins/PluginWidgetAndroid.cpp +++ b/WebKit/android/plugins/PluginWidgetAndroid.cpp @@ -71,7 +71,8 @@ void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) { if (m_drawingModel == kSurface_ANPDrawingModel) { if (m_surface) { - m_surface->attach(window->x, window->y, window->width, window->height); + IntPoint docPoint = getDocumentCoordinates(window->x, window->y); + m_surface->attach(docPoint.x(), docPoint.y(), window->width, window->height); } } else { m_flipPixelRef->safeUnref(); @@ -292,9 +293,7 @@ void PluginWidgetAndroid::scrollToVisibleFrameRect() { // this requires converting the m_requestedFrameRect from frame to doc coordinates // find the center of the visibleRect in document coordinates - ScrollView* scrollView = m_pluginView->parent(); - IntPoint pluginFramePoint = IntPoint(m_requestedFrameRect.fLeft, m_requestedFrameRect.fTop); - IntPoint pluginDocPoint = scrollView->convertToContainingWindow(pluginFramePoint); + IntPoint pluginDocPoint = getDocumentCoordinates(m_requestedFrameRect.fLeft, m_requestedFrameRect.fTop); int rectCenterX = pluginDocPoint.x() + m_requestedFrameRect.width()/2; int rectCenterY = pluginDocPoint.y() + m_requestedFrameRect.height()/2; @@ -306,6 +305,25 @@ void PluginWidgetAndroid::scrollToVisibleFrameRect() { int deltaX = rectCenterX - screenCenterX; int deltaY = rectCenterY - screenCenterY; + ScrollView* scrollView = m_pluginView->parent(); android::WebViewCore* core = android::WebViewCore::getWebViewCore(scrollView); core->scrollBy(deltaX, deltaY, true); } + +IntPoint PluginWidgetAndroid::getDocumentCoordinates(int frameX, int frameY) { + IntPoint docPoint = IntPoint(frameX, frameY); + + const ScrollView* currentScrollView = m_pluginView->parent(); + if (currentScrollView) { + const ScrollView* parentScrollView = currentScrollView->parent(); + while (parentScrollView) { + + docPoint.move(currentScrollView->x(), currentScrollView->y()); + + currentScrollView = parentScrollView; + parentScrollView = parentScrollView->parent(); + } + } + + return docPoint; +} diff --git a/WebKit/android/plugins/PluginWidgetAndroid.h b/WebKit/android/plugins/PluginWidgetAndroid.h index 1da618f..cc2d206 100644 --- a/WebKit/android/plugins/PluginWidgetAndroid.h +++ b/WebKit/android/plugins/PluginWidgetAndroid.h @@ -27,6 +27,7 @@ #define PluginWidgetAndroid_H #include "android_npapi.h" +#include "IntPoint.h" #include "SkRect.h" #include <wtf/OwnPtr.h> @@ -132,6 +133,7 @@ struct PluginWidgetAndroid { void setVisibleRects(const ANPRectI rects[], int32_t count); private: + WebCore::IntPoint getDocumentCoordinates(int frameX, int frameY); void computeVisibleFrameRect(); void scrollToVisibleFrameRect(); |