diff options
author | pinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-24 17:41:34 +0000 |
---|---|---|
committer | pinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-24 17:41:34 +0000 |
commit | 044dc48ab959e37a5f9960a46e7ffeeaf201fb54 (patch) | |
tree | 25d3b3fb7ecb5bbcf3836fb293f2265c1d9a7fbb | |
parent | ab6513714d7bd8e5b13d99f89c2bff468b8dcce5 (diff) | |
download | chromium_src-044dc48ab959e37a5f9960a46e7ffeeaf201fb54.zip chromium_src-044dc48ab959e37a5f9960a46e7ffeeaf201fb54.tar.gz chromium_src-044dc48ab959e37a5f9960a46e7ffeeaf201fb54.tar.bz2 |
Hook up mouse events with the correct coordinates. Make sure they are view-local and flipped.
Review URL: http://codereview.chromium.org/8150
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3924 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/event_conversion.cc | 4 | ||||
-rw-r--r-- | webkit/glue/webinputevent.h | 6 | ||||
-rw-r--r-- | webkit/glue/webinputevent_mac.mm | 14 | ||||
-rw-r--r-- | webkit/tools/test_shell/mac/webwidget_host.mm | 4 |
4 files changed, 14 insertions, 14 deletions
diff --git a/webkit/glue/event_conversion.cc b/webkit/glue/event_conversion.cc index 84db42f..517e8c2 100644 --- a/webkit/glue/event_conversion.cc +++ b/webkit/glue/event_conversion.cc @@ -38,11 +38,9 @@ uint32 MakePlatformMouseEvent::last_click_time_ = 0; MakePlatformMouseEvent::MakePlatformMouseEvent(Widget* widget, const WebMouseEvent& e) { -#if defined(OS_WIN) || defined(OS_LINUX) // TODO(mpcomplete): widget is always toplevel, unless it's a popup. We // may be able to get rid of this once we abstract popups into a WebKit API. m_position = widget->convertFromContainingWindow(IntPoint(e.x, e.y)); -#endif m_globalPosition = IntPoint(e.global_x, e.global_y); m_button = static_cast<MouseButton>(e.button); m_shiftKey = (e.modifiers & WebInputEvent::SHIFT_KEY) != 0; @@ -114,9 +112,7 @@ MakePlatformMouseEvent::MakePlatformMouseEvent(Widget* widget, MakePlatformWheelEvent::MakePlatformWheelEvent(Widget* widget, const WebMouseWheelEvent& e) { -#if defined(OS_WIN) || defined(OS_LINUX) m_position = widget->convertFromContainingWindow(IntPoint(e.x, e.y)); -#endif m_globalPosition = IntPoint(e.global_x, e.global_y); m_deltaX = static_cast<float>(e.delta_x); m_deltaY = static_cast<float>(e.delta_y); diff --git a/webkit/glue/webinputevent.h b/webkit/glue/webinputevent.h index 308e75e..45e8af1 100644 --- a/webkit/glue/webinputevent.h +++ b/webkit/glue/webinputevent.h @@ -13,8 +13,10 @@ #include <wtf/RetainPtr.h> #ifdef __OBJC__ @class NSEvent; +@class NSView; #else class NSEvent; +class NSView; #endif // __OBJC__ #elif defined(OS_LINUX) typedef struct _GdkEventButton GdkEventButton; @@ -96,7 +98,7 @@ class WebMouseEvent : public WebInputEvent { #if defined(OS_WIN) WebMouseEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); #elif defined(OS_MACOSX) - WebMouseEvent(NSEvent *event); + WebMouseEvent(NSEvent *event, NSView* view); #elif defined(OS_LINUX) explicit WebMouseEvent(const GdkEventButton* event); explicit WebMouseEvent(const GdkEventMotion* event); @@ -114,7 +116,7 @@ class WebMouseWheelEvent : public WebMouseEvent { #if defined(OS_WIN) WebMouseWheelEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); #elif defined(OS_MACOSX) - WebMouseWheelEvent(NSEvent *event); + WebMouseWheelEvent(NSEvent *event, NSView* view); #elif defined(OS_LINUX) explicit WebMouseWheelEvent(const GdkEventScroll* event); #endif diff --git a/webkit/glue/webinputevent_mac.mm b/webkit/glue/webinputevent_mac.mm index 0355bcc..8fc524d 100644 --- a/webkit/glue/webinputevent_mac.mm +++ b/webkit/glue/webinputevent_mac.mm @@ -17,7 +17,7 @@ static const unsigned long kDefaultScrollLinesPerWheelDelta = 3; // WebMouseEvent -------------------------------------------------------------- -WebMouseEvent::WebMouseEvent(NSEvent *event) { +WebMouseEvent::WebMouseEvent(NSEvent *event, NSView* view) { switch ([event type]) { case NSMouseExited: type = MOUSE_LEAVE; @@ -72,9 +72,10 @@ WebMouseEvent::WebMouseEvent(NSEvent *event) { global_x = location.x; global_y = location.y; - location = [event locationInWindow]; // local (to receiving window) + NSPoint windowLocal = [event locationInWindow]; + location = [view convertPoint:windowLocal fromView:nil]; + y = [view frame].size.height - location.y; // flip y x = location.x; - y = location.y; // set modifiers: @@ -95,7 +96,7 @@ WebMouseEvent::WebMouseEvent(NSEvent *event) { // WebMouseWheelEvent --------------------------------------------------------- -WebMouseWheelEvent::WebMouseWheelEvent(NSEvent *event) { +WebMouseWheelEvent::WebMouseWheelEvent(NSEvent *event, NSView* view) { type = MOUSE_WHEEL; button = BUTTON_NONE; @@ -103,9 +104,10 @@ WebMouseWheelEvent::WebMouseWheelEvent(NSEvent *event) { global_x = location.x; global_y = location.y; - location = [event locationInWindow]; // local (to receiving window) + NSPoint windowLocal = [event locationInWindow]; + location = [view convertPoint:windowLocal fromView:nil]; + y = [view frame].size.height - location.y; // flip y x = location.x; - y = location.y; int wheel_delta = [event deltaY]; const int delta_lines = wheel_delta * kDefaultScrollLinesPerWheelDelta; diff --git a/webkit/tools/test_shell/mac/webwidget_host.mm b/webkit/tools/test_shell/mac/webwidget_host.mm index b62f2fc..9341d03 100644 --- a/webkit/tools/test_shell/mac/webwidget_host.mm +++ b/webkit/tools/test_shell/mac/webwidget_host.mm @@ -213,7 +213,7 @@ void WebWidgetHost::Resize(const gfx::Rect& rect) { } void WebWidgetHost::MouseEvent(NSEvent *event) { - WebMouseEvent web_event(event); + WebMouseEvent web_event(event, view_); switch (web_event.type) { case WebInputEvent::MOUSE_MOVE: TrackMouseLeave(true); @@ -236,7 +236,7 @@ void WebWidgetHost::MouseEvent(NSEvent *event) { } void WebWidgetHost::WheelEvent(NSEvent *event) { - WebMouseWheelEvent web_event(event); + WebMouseWheelEvent web_event(event, view_); webwidget_->HandleInputEvent(&web_event); } |