summaryrefslogtreecommitdiffstats
path: root/webkit/api
diff options
context:
space:
mode:
authoravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-12 18:20:47 +0000
committeravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-12 18:20:47 +0000
commitcd9694081920898abccbf9e5dcf8624ad8223c63 (patch)
tree9ae5ed2c39d64b432e2b41ed39d3fc25f2e3a3e1 /webkit/api
parent797f5d1d995bd5f31fbb811785b15fbccecafbd4 (diff)
downloadchromium_src-cd9694081920898abccbf9e5dcf8624ad8223c63.zip
chromium_src-cd9694081920898abccbf9e5dcf8624ad8223c63.tar.gz
chromium_src-cd9694081920898abccbf9e5dcf8624ad8223c63.tar.bz2
Implement the triple click for the Mac.
Review URL: http://codereview.chromium.org/99104 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15877 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/api')
-rw-r--r--webkit/api/public/WebInputEvent.h12
-rw-r--r--webkit/api/public/win/WebInputEventFactory.h14
-rw-r--r--webkit/api/src/gtk/WebInputEventFactory.cpp25
-rw-r--r--webkit/api/src/mac/WebInputEventFactory.mm14
-rw-r--r--webkit/api/src/win/WebInputEventFactory.cpp75
5 files changed, 92 insertions, 48 deletions
diff --git a/webkit/api/public/WebInputEvent.h b/webkit/api/public/WebInputEvent.h
index 93350a5..f232ce5 100644
--- a/webkit/api/public/WebInputEvent.h
+++ b/webkit/api/public/WebInputEvent.h
@@ -1,10 +1,10 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -72,8 +72,6 @@ namespace WebKit {
MouseUp,
MouseMove,
MouseLeave,
- MouseDoubleClick,
- MouseTripleClick,
// WebMouseWheelEvent
MouseWheel,
@@ -186,7 +184,7 @@ namespace WebKit {
int globalX;
int globalY;
double timeStampSeconds; // Seconds since epoch.
- int layoutTestClickCount; // Only used during layout tests.
+ int clickCount;
WebMouseEvent()
: button(ButtonNone)
@@ -195,7 +193,7 @@ namespace WebKit {
, globalX(0)
, globalY(0)
, timeStampSeconds(0.0)
- , layoutTestClickCount(0)
+ , clickCount(0)
{
}
};
diff --git a/webkit/api/public/win/WebInputEventFactory.h b/webkit/api/public/win/WebInputEventFactory.h
index c353ed4..b94adbd 100644
--- a/webkit/api/public/win/WebInputEventFactory.h
+++ b/webkit/api/public/win/WebInputEventFactory.h
@@ -1,10 +1,10 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -46,6 +46,14 @@ namespace WebKit {
WEBKIT_API static WebKeyboardEvent keyboardEvent(HWND, UINT, WPARAM, LPARAM);
WEBKIT_API static WebMouseEvent mouseEvent(HWND, UINT, WPARAM, LPARAM);
WEBKIT_API static WebMouseWheelEvent mouseWheelEvent(HWND, UINT, WPARAM, LPARAM);
+
+ // Windows only provides information on whether a click was a single or
+ // double click, while we need to know the click count past two. The
+ // WebInputEventFactory keeps internal state to allow it to synthesize
+ // that information. In some cases, like fast-running tests, that
+ // information is known to be stale and needs to be reset; that is the
+ // function of resetLastClickState().
+ WEBKIT_API static void resetLastClickState();
};
} // namespace WebKit
diff --git a/webkit/api/src/gtk/WebInputEventFactory.cpp b/webkit/api/src/gtk/WebInputEventFactory.cpp
index 7c784d1..17506b2 100644
--- a/webkit/api/src/gtk/WebInputEventFactory.cpp
+++ b/webkit/api/src/gtk/WebInputEventFactory.cpp
@@ -1,10 +1,10 @@
/*
* Copyright (C) 2006-2009 Google Inc. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -108,7 +108,7 @@ WebKeyboardEvent WebInputEventFactory::keyboardEvent(const GdkEventKey* event)
result.setKeyIdentifierFromWindowsKeyCode();
// FIXME: Do we need to set IsAutoRepeat or IsKeyPad?
-
+
return result;
}
@@ -125,17 +125,18 @@ WebMouseEvent WebInputEventFactory::mouseEvent(const GdkEventButton* event)
result.y = static_cast<int>(event->y);
result.globalX = static_cast<int>(event->x_root);
result.globalY = static_cast<int>(event->y_root);
- result.layoutTestClickCount = 0;
+ result.clickCount = 0;
switch (event->type) {
+ case GDK_3BUTTON_PRESS:
+ ++result.clickCount;
+ // fallthrough
+ case GDK_2BUTTON_PRESS:
+ ++result.clickCount;
+ // fallthrough
case GDK_BUTTON_PRESS:
result.type = WebInputEvent::MouseDown;
- break;
- case GDK_2BUTTON_PRESS:
- result.type = WebInputEvent::MouseDoubleClick;
- break;
- case GDK_3BUTTON_PRESS:
- result.type = WebInputEvent::MouseTripleClick;
+ ++result.clickCount;
break;
case GDK_BUTTON_RELEASE:
result.type = WebInputEvent::MouseUp;
@@ -182,7 +183,7 @@ WebMouseEvent WebInputEventFactory::mouseEvent(const GdkEventMotion* event)
result.button = WebMouseEvent::ButtonMiddle;
else if (event->state & GDK_BUTTON3_MASK)
result.button = WebMouseEvent::ButtonRight;
-
+
return result;
}
diff --git a/webkit/api/src/mac/WebInputEventFactory.mm b/webkit/api/src/mac/WebInputEventFactory.mm
index c0afa04..e9a0d59 100644
--- a/webkit/api/src/mac/WebInputEventFactory.mm
+++ b/webkit/api/src/mac/WebInputEventFactory.mm
@@ -908,24 +908,26 @@ WebMouseEvent WebInputEventFactory::mouseEvent(NSEvent* event, NSView* view)
{
WebMouseEvent result;
+ result.clickCount = 0;
+
switch ([event type]) {
case NSMouseExited:
result.type = WebInputEvent::MouseLeave;
result.button = WebMouseEvent::ButtonNone;
break;
case NSLeftMouseDown:
- result.type = [event clickCount] == 2 ? WebInputEvent::MouseDoubleClick
- : WebInputEvent::MouseDown;
+ result.type = WebInputEvent::MouseDown;
+ result.clickCount = [event clickCount];
result.button = WebMouseEvent::ButtonLeft;
break;
case NSOtherMouseDown:
- result.type = [event clickCount] == 2 ? WebInputEvent::MouseDoubleClick
- : WebInputEvent::MouseDown;
+ result.type = WebInputEvent::MouseDown;
+ result.clickCount = [event clickCount];
result.button = WebMouseEvent::ButtonMiddle;
break;
case NSRightMouseDown:
- result.type = [event clickCount] == 2 ? WebInputEvent::MouseDoubleClick
- : WebInputEvent::MouseDown;
+ result.type = WebInputEvent::MouseDown;
+ result.clickCount = [event clickCount];
result.button = WebMouseEvent::ButtonRight;
break;
case NSLeftMouseUp:
diff --git a/webkit/api/src/win/WebInputEventFactory.cpp b/webkit/api/src/win/WebInputEventFactory.cpp
index e5bc34c..d772a54 100644
--- a/webkit/api/src/win/WebInputEventFactory.cpp
+++ b/webkit/api/src/win/WebInputEventFactory.cpp
@@ -1,10 +1,10 @@
/*
* Copyright (C) 2006-2009 Google Inc. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -141,6 +141,9 @@ WebKeyboardEvent WebInputEventFactory::keyboardEvent(HWND hwnd, UINT message,
// WebMouseEvent --------------------------------------------------------------
+static int gLastClickCount;
+static double gLastClickTime;
+
static LPARAM GetRelativeCursorPos(HWND hwnd)
{
POINT pos = {-1, -1};
@@ -149,6 +152,11 @@ static LPARAM GetRelativeCursorPos(HWND hwnd)
return MAKELPARAM(pos.x, pos.y);
}
+void WebInputEventFactory::resetLastClickState()
+{
+ gLastClickTime = gLastClickCount = 0;
+}
+
WebMouseEvent WebInputEventFactory::mouseEvent(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
@@ -174,14 +182,17 @@ WebMouseEvent WebInputEventFactory::mouseEvent(HWND hwnd, UINT message,
lparam = GetRelativeCursorPos(hwnd);
break;
case WM_LBUTTONDOWN:
+ case WM_LBUTTONDBLCLK:
result.type = WebInputEvent::MouseDown;
result.button = WebMouseEvent::ButtonLeft;
break;
case WM_MBUTTONDOWN:
+ case WM_MBUTTONDBLCLK:
result.type = WebInputEvent::MouseDown;
result.button = WebMouseEvent::ButtonMiddle;
break;
case WM_RBUTTONDOWN:
+ case WM_RBUTTONDBLCLK:
result.type = WebInputEvent::MouseDown;
result.button = WebMouseEvent::ButtonRight;
break;
@@ -197,22 +208,16 @@ WebMouseEvent WebInputEventFactory::mouseEvent(HWND hwnd, UINT message,
result.type = WebInputEvent::MouseUp;
result.button = WebMouseEvent::ButtonRight;
break;
- case WM_LBUTTONDBLCLK:
- result.type = WebInputEvent::MouseDoubleClick;
- result.button = WebMouseEvent::ButtonLeft;
- break;
- case WM_MBUTTONDBLCLK:
- result.type = WebInputEvent::MouseDoubleClick;
- result.button = WebMouseEvent::ButtonMiddle;
- break;
- case WM_RBUTTONDBLCLK:
- result.type = WebInputEvent::MouseDoubleClick;
- result.button = WebMouseEvent::ButtonRight;
- break;
default:
ASSERT_NOT_REACHED();
}
+ // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that
+ // GetMessageTime() refers to is the same one that we're passed in? Perhaps
+ // one of the construction parameters should be the time passed by the
+ // caller, who would know for sure.
+ result.timeStampSeconds = GetMessageTime() / 1000.0;
+
// set position fields:
result.x = static_cast<short>(LOWORD(lparam));
@@ -224,6 +229,41 @@ WebMouseEvent WebInputEventFactory::mouseEvent(HWND hwnd, UINT message,
result.globalX = globalPoint.x;
result.globalY = globalPoint.y;
+ // calculate number of clicks:
+
+ // This differs slightly from the WebKit code in WebKit/win/WebView.cpp
+ // where their original code looks buggy.
+ static int lastClickPositionX;
+ static int lastClickPositionY;
+ static WebMouseEvent::Button lastClickButton = WebMouseEvent::ButtonLeft;
+
+ double currentTime = result.timeStampSeconds;
+ bool cancelPreviousClick =
+ (abs(lastClickPositionX - result.x) > (GetSystemMetrics(SM_CXDOUBLECLK) / 2))
+ || (abs(lastClickPositionY - result.y) > (GetSystemMetrics(SM_CYDOUBLECLK) / 2))
+ || ((currentTime - gLastClickTime) * 1000.0 > GetDoubleClickTime());
+
+ if (result.type == WebInputEvent::MouseDown) {
+ if (!cancelPreviousClick && (result.button == lastClickButton))
+ ++gLastClickCount;
+ else {
+ gLastClickCount = 1;
+ lastClickPositionX = result.x;
+ lastClickPositionY = result.y;
+ }
+ gLastClickTime = currentTime;
+ lastClickButton = result.button;
+ } else if (result.type == WebInputEvent::MouseMove
+ || result.type == WebInputEvent::MouseLeave) {
+ if (cancelPreviousClick) {
+ gLastClickCount = 0;
+ lastClickPositionX = 0;
+ lastClickPositionY = 0;
+ gLastClickTime = 0;
+ }
+ }
+ result.clickCount = gLastClickCount;
+
// set modifiers:
if (wparam & MK_CONTROL)
@@ -233,11 +273,6 @@ WebMouseEvent WebInputEventFactory::mouseEvent(HWND hwnd, UINT message,
if (GetKeyState(VK_MENU) & 0x8000)
result.modifiers |= (WebInputEvent::AltKey | WebInputEvent::MetaKey); // FIXME: set META properly
- // TODO(pkasting): http://b/1117926 Instead of using GetTickCount() here, we
- // should use GetMessageTime() on the original Windows message in the browser
- // process, and pass that in the WebMouseEvent.
- result.timeStampSeconds = GetTickCount() / 1000.0;
-
return result;
}