summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-26 15:05:02 +0000
committeravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-26 15:05:02 +0000
commit869288c1efa3943226545a6763e066094a16ec74 (patch)
tree6ad07d82e44d9b7dc215214114ec08d9f50f5457
parentb3da408c038bb17c40958c177eb36c65942e035e (diff)
downloadchromium_src-869288c1efa3943226545a6763e066094a16ec74.zip
chromium_src-869288c1efa3943226545a6763e066094a16ec74.tar.gz
chromium_src-869288c1efa3943226545a6763e066094a16ec74.tar.bz2
Mac-ify webinputevent
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1382 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/build/glue/glue.vcproj2
-rw-r--r--webkit/glue/SConscript2
-rw-r--r--webkit/glue/webinputevent.h52
-rw-r--r--webkit/glue/webinputevent_mac.mm166
-rw-r--r--webkit/glue/webinputevent_win.cc (renamed from webkit/glue/webinputevent.cc)0
-rw-r--r--webkit/webkit.xcodeproj/project.pbxproj20
6 files changed, 220 insertions, 22 deletions
diff --git a/webkit/build/glue/glue.vcproj b/webkit/build/glue/glue.vcproj
index 8065e50..9bf3e82 100644
--- a/webkit/build/glue/glue.vcproj
+++ b/webkit/build/glue/glue.vcproj
@@ -537,7 +537,7 @@
>
</File>
<File
- RelativePath="..\..\glue\webinputevent.cc"
+ RelativePath="..\..\glue\webinputevent_win.cc"
>
</File>
<File
diff --git a/webkit/glue/SConscript b/webkit/glue/SConscript
index 760b067..f71cdf5 100644
--- a/webkit/glue/SConscript
+++ b/webkit/glue/SConscript
@@ -93,7 +93,7 @@ input_files = [
'webframe_impl.cc',
'webframeloaderclient_impl.cc',
'webhistoryitem_impl.cc',
- 'webinputevent.cc',
+ 'webinputevent_win.cc',
'webkit_glue.cc',
'webplugin_impl.cc',
'webtextinput_impl.cc',
diff --git a/webkit/glue/webinputevent.h b/webkit/glue/webinputevent.h
index 5658c6a..07e2cab 100644
--- a/webkit/glue/webinputevent.h
+++ b/webkit/glue/webinputevent.h
@@ -2,12 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef WEBKIT_GLUE_WEBINPUTEVENT_H__
-#define WEBKIT_GLUE_WEBINPUTEVENT_H__
+#ifndef WEBKIT_GLUE_WEBINPUTEVENT_H_
+#define WEBKIT_GLUE_WEBINPUTEVENT_H_
-#include <windows.h>
#include "base/basictypes.h"
+#if defined(OS_WIN)
+#include <windows.h>
+#elif defined(OS_MACOSX)
+#include <wtf/RetainPtr.h>
+#ifdef __OBJC__
+@class NSEvent;
+#else
+class NSEvent;
+#endif // __OBJC__
+#endif // OS_MACOSX
+
// The classes defined in this file are intended to be used with WebView's
// HandleInputEvent method. These event types are cross-platform; however,
// there are platform-specific constructors that accept native UI events.
@@ -50,6 +60,11 @@ class WebInputEvent {
Type type;
int modifiers;
+#if defined(OS_MACOSX)
+ // For now, good enough for the test shell. TODO(avi): Revisit when we need
+ // to start sending this over an IPC pipe.
+ RetainPtr<NSEvent> mac_event;
+#endif
};
// WebMouseEvent --------------------------------------------------------------
@@ -73,7 +88,11 @@ class WebMouseEvent : public WebInputEvent {
int layout_test_click_count; // Only used during layout tests.
WebMouseEvent() {}
+#if defined(OS_WIN)
WebMouseEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
+#elif defined(OS_MACOSX)
+ WebMouseEvent(NSEvent *event);
+#endif
};
// WebMouseWheelEvent ---------------------------------------------------------
@@ -84,28 +103,41 @@ class WebMouseWheelEvent : public WebMouseEvent {
int delta_y;
WebMouseWheelEvent() {}
+#if defined(OS_WIN)
WebMouseWheelEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
+#elif defined(OS_MACOSX)
+ WebMouseWheelEvent(NSEvent *event);
+#endif
};
// WebKeyboardEvent -----------------------------------------------------------
class WebKeyboardEvent : public WebInputEvent {
public:
- bool system_key; // Set if we receive a SYSKEYDOWN/WM_SYSKEYUP message.
- MSG actual_message; // Set to the current keyboard message.
int key_code;
int key_data;
+#if defined(OS_WIN)
+ bool system_key; // Set if we receive a SYSKEYDOWN/WM_SYSKEYUP message.
+ MSG actual_message; // Set to the current keyboard message.
+#endif
WebKeyboardEvent()
- : system_key(false),
- key_code(0),
- key_data(0) {
+ : key_code(0),
+ key_data(0)
+#if defined(OS_WIN)
+ , system_key(false) {
memset(&actual_message, 0, sizeof(actual_message));
}
+#else
+ {}
+#endif
+#if defined(OS_WIN)
WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
+#elif defined(OS_MACOSX)
+ WebKeyboardEvent(NSEvent *event);
+#endif
};
-#endif // WEBKIT_GLUE_WEBINPUTEVENT_H__
-
+#endif // WEBKIT_GLUE_WEBINPUTEVENT_H_
diff --git a/webkit/glue/webinputevent_mac.mm b/webkit/glue/webinputevent_mac.mm
new file mode 100644
index 0000000..08da30f
--- /dev/null
+++ b/webkit/glue/webinputevent_mac.mm
@@ -0,0 +1,166 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Cocoa/Cocoa.h>
+
+#include "config.h"
+
+#include "webkit/glue/webinputevent.h"
+
+#include "webkit/glue/event_conversion.h"
+
+#undef LOG
+#include "base/logging.h"
+
+static const unsigned long kDefaultScrollLinesPerWheelDelta = 3;
+
+// WebMouseEvent --------------------------------------------------------------
+
+WebMouseEvent::WebMouseEvent(NSEvent *event) {
+ switch ([event type]) {
+ case NSMouseExited:
+ type = MOUSE_LEAVE;
+ button = BUTTON_NONE;
+ break;
+ case NSLeftMouseDown:
+ type = [event clickCount] == 2 ? MOUSE_DOUBLE_CLICK : MOUSE_DOWN;
+ button = BUTTON_LEFT;
+ break;
+ case NSOtherMouseDown:
+ type = [event clickCount] == 2 ? MOUSE_DOUBLE_CLICK : MOUSE_DOWN;
+ button = BUTTON_MIDDLE;
+ break;
+ case NSRightMouseDown:
+ type = [event clickCount] == 2 ? MOUSE_DOUBLE_CLICK : MOUSE_DOWN;
+ button = BUTTON_RIGHT;
+ break;
+ case NSLeftMouseUp:
+ type = MOUSE_UP;
+ button = BUTTON_LEFT;
+ break;
+ case NSOtherMouseUp:
+ type = MOUSE_UP;
+ button = BUTTON_MIDDLE;
+ break;
+ case NSRightMouseUp:
+ type = MOUSE_UP;
+ button = BUTTON_RIGHT;
+ break;
+ case NSMouseMoved:
+ case NSMouseEntered:
+ type = MOUSE_MOVE;
+ break;
+ case NSLeftMouseDragged:
+ type = MOUSE_MOVE;
+ button = BUTTON_LEFT;
+ break;
+ case NSOtherMouseDragged:
+ type = MOUSE_MOVE;
+ button = BUTTON_MIDDLE;
+ break;
+ case NSRightMouseDragged:
+ type = MOUSE_MOVE;
+ button = BUTTON_RIGHT;
+ break;
+ default:
+ NOTREACHED() << "unexpected native message";
+ }
+
+ // set position fields:
+ NSPoint location = [NSEvent mouseLocation]; // global coordinates
+ global_x = location.x;
+ global_y = location.y;
+
+ location = [event locationInWindow]; // local (to receiving window)
+ x = location.x;
+ y = location.y;
+
+ // set modifiers:
+
+ modifiers = 0;
+ if ([event modifierFlags] & NSControlKeyMask)
+ modifiers |= CTRL_KEY;
+ if ([event modifierFlags] & NSShiftKeyMask)
+ modifiers |= SHIFT_KEY;
+ if ([event modifierFlags] & NSAlternateKeyMask)
+ modifiers |= (ALT_KEY | META_KEY); // TODO(darin): set META properly
+
+ timestamp_sec = [event timestamp];
+
+ layout_test_click_count = 0;
+
+ mac_event.adoptNS(event);
+}
+
+// WebMouseWheelEvent ---------------------------------------------------------
+
+WebMouseWheelEvent::WebMouseWheelEvent(NSEvent *event) {
+ type = MOUSE_WHEEL;
+ button = BUTTON_NONE;
+
+ NSPoint location = [NSEvent mouseLocation]; // global coordinates
+ global_x = location.x;
+ global_y = location.y;
+
+ location = [event locationInWindow]; // local (to receiving window)
+ x = location.x;
+ y = location.y;
+
+ int wheel_delta = [event deltaY];
+ const int delta_lines = wheel_delta * kDefaultScrollLinesPerWheelDelta;
+
+ // Scroll horizontally if shift is held. WebKit's WebKit/win/WebView.cpp
+ // does the equivalent.
+ // TODO(jackson): Support WM_MOUSEHWHEEL = 0x020E event as well.
+ // (Need a mouse with horizontal scrolling capabilities to test it.)
+ if ([event modifierFlags] & NSShiftKeyMask) {
+ // Scrolling up should move left, scrolling down should move right
+ delta_x = -delta_lines;
+ delta_y = 0;
+ } else {
+ delta_x = 0;
+ delta_y = delta_lines;
+ }
+
+ modifiers = 0;
+ if ([event modifierFlags] & NSControlKeyMask)
+ modifiers |= CTRL_KEY;
+ if ([event modifierFlags] & NSShiftKeyMask)
+ modifiers |= SHIFT_KEY;
+ if ([event modifierFlags] & NSAlternateKeyMask)
+ modifiers |= ALT_KEY;
+
+ mac_event.adoptNS(event);
+}
+
+// WebKeyboardEvent -----------------------------------------------------------
+
+WebKeyboardEvent::WebKeyboardEvent(NSEvent *event) {
+ switch ([event type]) {
+ case NSKeyDown:
+ type = KEY_DOWN;
+ break;
+ case NSKeyUp:
+ type = KEY_UP;
+ break;
+ default:
+ NOTREACHED() << "unexpected native message";
+ }
+
+ modifiers = 0;
+ if ([event modifierFlags] & NSControlKeyMask)
+ modifiers |= CTRL_KEY;
+ if ([event modifierFlags] & NSShiftKeyMask)
+ modifiers |= SHIFT_KEY;
+ if ([event modifierFlags] & NSAlternateKeyMask)
+ modifiers |= ALT_KEY;
+
+ if ([event isARepeat])
+ modifiers |= IS_AUTO_REPEAT;
+
+ key_code = [event keyCode];
+ key_data = [[event characters] characterAtIndex:0];
+
+ mac_event.adoptNS(event);
+}
diff --git a/webkit/glue/webinputevent.cc b/webkit/glue/webinputevent_win.cc
index 93f5da7..93f5da7 100644
--- a/webkit/glue/webinputevent.cc
+++ b/webkit/glue/webinputevent_win.cc
diff --git a/webkit/webkit.xcodeproj/project.pbxproj b/webkit/webkit.xcodeproj/project.pbxproj
index fadbaba..7a2625b 100644
--- a/webkit/webkit.xcodeproj/project.pbxproj
+++ b/webkit/webkit.xcodeproj/project.pbxproj
@@ -833,7 +833,7 @@
7B42A30D0DE204F200659DE0 /* weburlrequest_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825405560D92E3DB0006B936 /* weburlrequest_impl.cc */; };
7B42A30E0DE204F200659DE0 /* webdatasource_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825405320D92E3DA0006B936 /* webdatasource_impl.cc */; };
7B42A30F0DE204F200659DE0 /* webtextinput_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825405530D92E3DB0006B936 /* webtextinput_impl.cc */; };
- 7B42A3100DE204F200659DE0 /* webinputevent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 825405440D92E3DA0006B936 /* webinputevent.mm */; };
+ 7B42A3100DE204F200659DE0 /* webinputevent_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 825405440D92E3DA0006B936 /* webinputevent_mac.mm */; };
7B42A3110DE204F200659DE0 /* cpp_variant.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825404FD0D92E3DA0006B936 /* cpp_variant.cc */; };
7B42A3120DE204F200659DE0 /* cpp_bound_class.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825404FA0D92E3DA0006B936 /* cpp_bound_class.cc */; };
7B42A3130DE204F200659DE0 /* webframeloaderclient_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8254053F0D92E3DA0006B936 /* webframeloaderclient_impl.cc */; };
@@ -5879,7 +5879,7 @@
ABC8C2EA0DC7E45B00B59C21 /* SkGraphicsContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 822B1BFD0DC77A08005C9A96 /* SkGraphicsContext.h */; };
ABCF2EE50E075FD900763F29 /* RenderThemeMacSkia.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABCF2EE40E075FD900763F29 /* RenderThemeMacSkia.mm */; };
ABCF2EE60E075FD900763F29 /* RenderThemeMacSkia.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABCF2EE40E075FD900763F29 /* RenderThemeMacSkia.mm */; };
- ABD16FA80DC6D4CF0013D3AA /* webinputevent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 825405440D92E3DA0006B936 /* webinputevent.mm */; };
+ ABD16FA80DC6D4CF0013D3AA /* webinputevent_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 825405440D92E3DA0006B936 /* webinputevent_mac.mm */; };
ABD16FA90DC6D4D70013D3AA /* webinputevent.h in Headers */ = {isa = PBXBuildFile; fileRef = 825405450D92E3DA0006B936 /* webinputevent.h */; };
ABDBD0F70E07611E005DDFD1 /* ScrollViewMacSkia.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF5263F0E075D17005EECE5 /* ScrollViewMacSkia.mm */; };
ABDBD0F80E076121005DDFD1 /* ScrollViewMacSkia.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF5263F0E075D17005EECE5 /* ScrollViewMacSkia.mm */; };
@@ -7573,7 +7573,7 @@
E45627020E268F03005E4685 /* weburlrequest_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825405560D92E3DB0006B936 /* weburlrequest_impl.cc */; };
E45627030E268F03005E4685 /* webdatasource_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825405320D92E3DA0006B936 /* webdatasource_impl.cc */; };
E45627040E268F03005E4685 /* webtextinput_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825405530D92E3DB0006B936 /* webtextinput_impl.cc */; };
- E45627050E268F03005E4685 /* webinputevent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 825405440D92E3DA0006B936 /* webinputevent.mm */; };
+ E45627050E268F03005E4685 /* webinputevent_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 825405440D92E3DA0006B936 /* webinputevent_mac.mm */; };
E45627060E268F03005E4685 /* cpp_variant.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825404FD0D92E3DA0006B936 /* cpp_variant.cc */; };
E45627070E268F03005E4685 /* cpp_bound_class.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825404FA0D92E3DA0006B936 /* cpp_bound_class.cc */; };
E45627080E268F03005E4685 /* webframeloaderclient_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8254053F0D92E3DA0006B936 /* webframeloaderclient_impl.cc */; };
@@ -7687,7 +7687,7 @@
isa = PBXContainerItemProxy;
containerPortal = 7B12F9060D8F463700CB6E8F /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 82C262C30DCF9411005CFE91 /* icudata */;
+ remoteGlobalIDString = 82C262C30DCF9411005CFE91;
remoteInfo = icudata;
};
7B0E5AF80DB3DC51007D4907 /* PBXContainerItemProxy */ = {
@@ -7834,7 +7834,7 @@
isa = PBXContainerItemProxy;
containerPortal = 7B12F9060D8F463700CB6E8F /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 82C262C30DCF9411005CFE91 /* icudata */;
+ remoteGlobalIDString = 82C262C30DCF9411005CFE91;
remoteInfo = icudata;
};
7B12FA330D8F496600CB6E8F /* PBXContainerItemProxy */ = {
@@ -12933,7 +12933,7 @@
825405410D92E3DA0006B936 /* webhistoryitem_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = webhistoryitem_impl.cc; path = glue/webhistoryitem_impl.cc; sourceTree = "<group>"; };
825405420D92E3DA0006B936 /* webhistoryitem_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = webhistoryitem_impl.h; path = glue/webhistoryitem_impl.h; sourceTree = "<group>"; };
825405430D92E3DA0006B936 /* webhistoryitem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = webhistoryitem.h; path = glue/webhistoryitem.h; sourceTree = "<group>"; };
- 825405440D92E3DA0006B936 /* webinputevent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = webinputevent.mm; path = glue/webinputevent.mm; sourceTree = "<group>"; };
+ 825405440D92E3DA0006B936 /* webinputevent_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = webinputevent_mac.mm; path = glue/webinputevent_mac.mm; sourceTree = "<group>"; };
825405450D92E3DA0006B936 /* webinputevent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = webinputevent.h; path = glue/webinputevent.h; sourceTree = "<group>"; };
825405460D92E3DA0006B936 /* webkit_glue.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = webkit_glue.mm; path = glue/webkit_glue.mm; sourceTree = "<group>"; };
825405470D92E3DB0006B936 /* webkit_glue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = webkit_glue.h; path = glue/webkit_glue.h; sourceTree = "<group>"; };
@@ -18624,7 +18624,7 @@
825405410D92E3DA0006B936 /* webhistoryitem_impl.cc */,
825405420D92E3DA0006B936 /* webhistoryitem_impl.h */,
825405430D92E3DA0006B936 /* webhistoryitem.h */,
- 825405440D92E3DA0006B936 /* webinputevent.mm */,
+ 825405440D92E3DA0006B936 /* webinputevent_mac.mm */,
825405450D92E3DA0006B936 /* webinputevent.h */,
825405460D92E3DA0006B936 /* webkit_glue.mm */,
825405470D92E3DB0006B936 /* webkit_glue.h */,
@@ -23616,7 +23616,7 @@
7B42A30D0DE204F200659DE0 /* weburlrequest_impl.cc in Sources */,
7B42A30E0DE204F200659DE0 /* webdatasource_impl.cc in Sources */,
7B42A30F0DE204F200659DE0 /* webtextinput_impl.cc in Sources */,
- 7B42A3100DE204F200659DE0 /* webinputevent.mm in Sources */,
+ 7B42A3100DE204F200659DE0 /* webinputevent_mac.mm in Sources */,
7B42A3110DE204F200659DE0 /* cpp_variant.cc in Sources */,
7B42A3120DE204F200659DE0 /* cpp_bound_class.cc in Sources */,
7B42A3130DE204F200659DE0 /* webframeloaderclient_impl.cc in Sources */,
@@ -26270,7 +26270,7 @@
824656B20DC696B5007C2BAA /* weburlrequest_impl.cc in Sources */,
824656D20DC6974B007C2BAA /* webdatasource_impl.cc in Sources */,
AB7934480DC66C9B00BC58F3 /* webtextinput_impl.cc in Sources */,
- ABD16FA80DC6D4CF0013D3AA /* webinputevent.mm in Sources */,
+ ABD16FA80DC6D4CF0013D3AA /* webinputevent_mac.mm in Sources */,
AB86655F0DC78AAC002CE06A /* cpp_variant.cc in Sources */,
AB8665610DC78AB9002CE06A /* cpp_bound_class.cc in Sources */,
AB1ED95D0DC7960A0006CBDE /* webframeloaderclient_impl.cc in Sources */,
@@ -27098,7 +27098,7 @@
E45627020E268F03005E4685 /* weburlrequest_impl.cc in Sources */,
E45627030E268F03005E4685 /* webdatasource_impl.cc in Sources */,
E45627040E268F03005E4685 /* webtextinput_impl.cc in Sources */,
- E45627050E268F03005E4685 /* webinputevent.mm in Sources */,
+ E45627050E268F03005E4685 /* webinputevent_mac.mm in Sources */,
E45627060E268F03005E4685 /* cpp_variant.cc in Sources */,
E45627070E268F03005E4685 /* cpp_bound_class.cc in Sources */,
E45627080E268F03005E4685 /* webframeloaderclient_impl.cc in Sources */,