From 47e4a93863e5f482f4eb13518d1207a09659eb31 Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Thu, 14 Jun 2012 12:40:12 -0500 Subject: [PATCH] Bug 764355 - Add a new edge swipe simple gesture and add a click count value to existing tap gestures for Win8. r=felipe --- .../content/test/browser_gestureSupport.js | 34 +++++++++++++++++-- content/base/src/nsGkAtomList.h | 1 + content/events/public/nsEventNameList.h | 4 +++ content/events/src/nsDOMEvent.cpp | 4 +++ content/events/src/nsDOMEvent.h | 1 + .../events/src/nsDOMSimpleGestureEvent.cpp | 13 ++++++- dom/base/nsDOMWindowUtils.cpp | 6 +++- dom/interfaces/base/nsIDOMWindowUtils.idl | 8 +++-- .../events/nsIDOMSimpleGestureEvent.idl | 12 +++++-- mobile/xul/chrome/content/browser.js | 4 +-- widget/nsGUIEvent.h | 6 ++-- widget/windows/nsWinGesture.cpp | 2 ++ 12 files changed, 81 insertions(+), 14 deletions(-) diff --git a/browser/base/content/test/browser_gestureSupport.js b/browser/base/content/test/browser_gestureSupport.js index 32bf9d640df..845ab2ecbc1 100644 --- a/browser/base/content/test/browser_gestureSupport.js +++ b/browser/base/content/test/browser_gestureSupport.js @@ -45,6 +45,7 @@ let test_expectedType; let test_expectedDirection; let test_expectedDelta; let test_expectedModifiers; +let test_expectedClickCount; function test_gestureListener(evt) { @@ -75,6 +76,10 @@ function test_gestureListener(evt) is(evt.metaKey, (test_expectedModifiers & Components.interfaces.nsIDOMNSEvent.META_MASK) != 0, "evt.metaKey did not match expected value"); + if (evt.type == "MozTapGesture") { + is(evt.clickCount, test_expectedClickCount, "evt.clickCount does not match"); + } + test_eventCount++; } @@ -95,6 +100,24 @@ function test_helper1(type, direction, delta, modifiers) is(expectedEventCount, test_eventCount, "Event (" + type + ") was never received by event listener"); } +function test_clicks(type, clicks) +{ + // Setup the expected values + test_expectedType = type; + test_expectedDirection = 0; + test_expectedDelta = 0; + test_expectedModifiers = 0; + test_expectedClickCount = clicks; + + let expectedEventCount = test_eventCount + 1; + + document.addEventListener(type, test_gestureListener, true); + test_utils.sendSimpleGestureEvent(type, 20, 20, 0, 0, 0, clicks); + document.removeEventListener(type, test_gestureListener, true); + + is(expectedEventCount, test_eventCount, "Event (" + type + ") was never received by event listener"); +} + function test_TestEventListeners() { let e = test_helper1; // easier to type this name @@ -126,8 +149,13 @@ function test_TestEventListeners() e("MozRotateGesture", SimpleGestureEvent.ROTATION_CLOCKWISE, 33.0, 0); // Tap and presstap gesture events - e("MozTapGesture", 0, 0.0, 0); - e("MozPressTapGesture", 0, 0.0, 0); + test_clicks("MozTapGesture", 1); + test_clicks("MozTapGesture", 2); + test_clicks("MozTapGesture", 3); + test_clicks("MozPressTapGesture", 1); + + // simple delivery test for edgeui gesture + e("MozEdgeUIGesture", 0, 0, 0); // event.shiftKey let modifier = Components.interfaces.nsIDOMNSEvent.SHIFT_MASK; @@ -171,7 +199,7 @@ function test_helper2(type, direction, delta, altKey, ctrlKey, shiftKey, metaKey 10, 10, 10, 10, ctrlKey, altKey, shiftKey, metaKey, 1, window, - direction, delta); + direction, delta, 0); successful = true; } catch (ex) { diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index 5001a54daeb..a1e9269bd58 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -1643,6 +1643,7 @@ GK_ATOM(onMozRotateGestureUpdate, "onMozRotateGestureUpdate") GK_ATOM(onMozRotateGesture, "onMozRotateGesture") GK_ATOM(onMozTapGesture, "onMozTapGesture") GK_ATOM(onMozPressTapGesture, "onMozPressTapGesture") +GK_ATOM(onMozEdgeUIGesture, "onMozEdgeUIGesture") // Touch events GK_ATOM(onMozTouchDown, "onMozTouchDown") diff --git a/content/events/public/nsEventNameList.h b/content/events/public/nsEventNameList.h index 76adc57899b..10e7f68fe42 100644 --- a/content/events/public/nsEventNameList.h +++ b/content/events/public/nsEventNameList.h @@ -712,6 +712,10 @@ NON_IDL_EVENT(MozPressTapGesture, NS_SIMPLE_GESTURE_PRESSTAP, EventNameType_None, NS_SIMPLE_GESTURE_EVENT) +NON_IDL_EVENT(MozEdgeUIGesture, + NS_SIMPLE_GESTURE_EDGEUI, + EventNameType_None, + NS_SIMPLE_GESTURE_EVENT) NON_IDL_EVENT(MozTouchDown, NS_MOZTOUCH_DOWN, diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 0c11f4f7b07..351bd95d81d 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -77,6 +77,7 @@ static const char* const sEventNames[] = { "MozRotateGesture", "MozTapGesture", "MozPressTapGesture", + "MozEdgeUIGesture", "MozTouchDown", "MozTouchMove", "MozTouchUp", @@ -839,6 +840,7 @@ nsDOMEvent::DuplicatePrivateData() isInputEvent = true; simpleGestureEvent->direction = oldSimpleGestureEvent->direction; simpleGestureEvent->delta = oldSimpleGestureEvent->delta; + simpleGestureEvent->clickCount = oldSimpleGestureEvent->clickCount; newEvent = simpleGestureEvent; break; } @@ -1503,6 +1505,8 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return sEventNames[eDOMEvents_MozTapGesture]; case NS_SIMPLE_GESTURE_PRESSTAP: return sEventNames[eDOMEvents_MozPressTapGesture]; + case NS_SIMPLE_GESTURE_EDGEUI: + return sEventNames[eDOMEvents_MozEdgeUIGesture]; case NS_MOZTOUCH_DOWN: return sEventNames[eDOMEvents_MozTouchDown]; case NS_MOZTOUCH_MOVE: diff --git a/content/events/src/nsDOMEvent.h b/content/events/src/nsDOMEvent.h index 06490189c5a..25b10725300 100644 --- a/content/events/src/nsDOMEvent.h +++ b/content/events/src/nsDOMEvent.h @@ -160,6 +160,7 @@ public: eDOMEvents_MozRotateGesture, eDOMEvents_MozTapGesture, eDOMEvents_MozPressTapGesture, + eDOMEvents_MozEdgeUIGesture, eDOMEvents_MozTouchDown, eDOMEvents_MozTouchMove, eDOMEvents_MozTouchUp, diff --git a/content/events/src/nsDOMSimpleGestureEvent.cpp b/content/events/src/nsDOMSimpleGestureEvent.cpp index f7894c9e88a..dc0ad66cb12 100644 --- a/content/events/src/nsDOMSimpleGestureEvent.cpp +++ b/content/events/src/nsDOMSimpleGestureEvent.cpp @@ -59,6 +59,15 @@ nsDOMSimpleGestureEvent::GetDelta(PRFloat64 *aDelta) return NS_OK; } +/* readonly attribute unsigned long clickCount; */ +NS_IMETHODIMP +nsDOMSimpleGestureEvent::GetClickCount(PRUint32 *aClickCount) +{ + NS_ENSURE_ARG_POINTER(aClickCount); + *aClickCount = static_cast(mEvent)->clickCount; + return NS_OK; +} + NS_IMETHODIMP nsDOMSimpleGestureEvent::InitSimpleGestureEvent(const nsAString& aTypeArg, bool aCanBubbleArg, @@ -76,7 +85,8 @@ nsDOMSimpleGestureEvent::InitSimpleGestureEvent(const nsAString& aTypeArg, PRUint16 aButton, nsIDOMEventTarget* aRelatedTarget, PRUint32 aDirectionArg, - PRFloat64 aDeltaArg) + PRFloat64 aDeltaArg, + PRUint32 aClickCountArg) { nsresult rv = nsDOMMouseEvent::InitMouseEvent(aTypeArg, aCanBubbleArg, @@ -98,6 +108,7 @@ nsDOMSimpleGestureEvent::InitSimpleGestureEvent(const nsAString& aTypeArg, nsSimpleGestureEvent* simpleGestureEvent = static_cast(mEvent); simpleGestureEvent->direction = aDirectionArg; simpleGestureEvent->delta = aDeltaArg; + simpleGestureEvent->clickCount = aClickCountArg; return NS_OK; } diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index c9b9dd61aaf..346deb715b3 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -1005,7 +1005,8 @@ nsDOMWindowUtils::SendSimpleGestureEvent(const nsAString& aType, float aY, PRUint32 aDirection, PRFloat64 aDelta, - PRInt32 aModifiers) + PRInt32 aModifiers, + PRUint32 aClickCount) { if (!IsUniversalXPConnectCapable()) { return NS_ERROR_DOM_SECURITY_ERR; @@ -1036,11 +1037,14 @@ nsDOMWindowUtils::SendSimpleGestureEvent(const nsAString& aType, msg = NS_SIMPLE_GESTURE_TAP; else if (aType.EqualsLiteral("MozPressTapGesture")) msg = NS_SIMPLE_GESTURE_PRESSTAP; + else if (aType.EqualsLiteral("MozEdgeUIGesture")) + msg = NS_SIMPLE_GESTURE_EDGEUI; else return NS_ERROR_FAILURE; nsSimpleGestureEvent event(true, msg, widget, aDirection, aDelta); event.modifiers = GetWidgetModifiers(aModifiers); + event.clickCount = aClickCount; event.time = PR_IntervalNow(); nsPresContext* presContext = GetPresContext(); diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 8d9d146bd52..7cba92f288e 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -490,8 +490,8 @@ interface nsIDOMWindowUtils : nsISupports { /** Synthesize a simple gesture event for a window. The event types * supported are: MozSwipeGesture, MozMagnifyGestureStart, * MozMagnifyGestureUpdate, MozMagnifyGesture, MozRotateGestureStart, - * MozRotateGestureUpdate, MozRotateGesture, MozPressTapGesture, and - * MozTapGesture. + * MozRotateGestureUpdate, MozRotateGesture, MozPressTapGesture, + * MozTapGesture, and MozEdgeUIGesture. * * Cannot be accessed from unprivileged context (not * content-accessible) Will throw a DOM security error if called @@ -503,13 +503,15 @@ interface nsIDOMWindowUtils : nsISupports { * @param aDirection direction, using constants defined in nsIDOMSimpleGestureEvent * @param aDelta amount of magnification or rotation for magnify and rotation events * @param aModifiers modifiers pressed, using constants defined in nsIDOMNSEvent + * @param aClickCount For tap gestures, the number of taps. */ void sendSimpleGestureEvent(in AString aType, in float aX, in float aY, in unsigned long aDirection, in double aDelta, - in long aModifiers); + in long aModifiers, + [optional] in unsigned long aClickCount); /** * Retrieve the element at point aX, aY in the window's document. diff --git a/dom/interfaces/events/nsIDOMSimpleGestureEvent.idl b/dom/interfaces/events/nsIDOMSimpleGestureEvent.idl index a486f1d4bd4..0c8c61bfbd6 100644 --- a/dom/interfaces/events/nsIDOMSimpleGestureEvent.idl +++ b/dom/interfaces/events/nsIDOMSimpleGestureEvent.idl @@ -57,6 +57,10 @@ * Client coordinates contain the center pivot point of the action. * (XXX Not implemented on Mac) * + * MozEdgeUIGesture - Generated when the user swipes the display to + * invoke edge ui. + * (XXX Win8 only) + * * Default behavior: * * Some operating systems support default behaviors for gesture events @@ -65,7 +69,7 @@ * consuming events. */ -[scriptable, builtinclass, uuid(2827efac-40c1-44af-82b9-3ad92f04d7ac)] +[scriptable, builtinclass, uuid(5e2a88ce-5032-4758-8578-37c6d7f87d7b)] interface nsIDOMSimpleGestureEvent : nsIDOMMouseEvent { /* Swipe direction constants */ @@ -113,6 +117,9 @@ interface nsIDOMSimpleGestureEvent : nsIDOMMouseEvent */ readonly attribute double delta; + /* Click count value for taps. */ + readonly attribute unsigned long clickCount; + void initSimpleGestureEvent(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, @@ -129,5 +136,6 @@ interface nsIDOMSimpleGestureEvent : nsIDOMMouseEvent in unsigned short buttonArg, in nsIDOMEventTarget relatedTargetArg, in unsigned long directionArg, - in double deltaArg); + in double deltaArg, + in unsigned long clickCount); }; diff --git a/mobile/xul/chrome/content/browser.js b/mobile/xul/chrome/content/browser.js index 23d5e542a2c..a247dad8cb7 100644 --- a/mobile/xul/chrome/content/browser.js +++ b/mobile/xul/chrome/content/browser.js @@ -55,7 +55,7 @@ function onDebugKeyPress(aEvent) { let evt = document.createEvent("SimpleGestureEvent"); evt.initSimpleGestureEvent("MozSwipeGesture", true, true, window, null, 0, 0, 0, 0, false, false, false, false, 0, null, - aDirection, 0); + aDirection, 0, 0); Browser.selectedTab.inputHandler.dispatchEvent(evt); } @@ -79,7 +79,7 @@ function onDebugKeyPress(aEvent) { function dispatchMagnifyEvent(aName, aDelta) { let evt = document.createEvent("SimpleGestureEvent"); evt.initSimpleGestureEvent("MozMagnifyGesture" + aName, true, true, window, null, - 0, 0, 0, 0, false, false, false, false, 0, null, 0, aDelta); + 0, 0, 0, 0, false, false, false, false, 0, null, 0, aDelta, 0); Browser.selectedTab.inputHandler.dispatchEvent(evt); } dispatchMagnifyEvent("Start", 0); diff --git a/widget/nsGUIEvent.h b/widget/nsGUIEvent.h index d2fc64655e4..8b65626913e 100644 --- a/widget/nsGUIEvent.h +++ b/widget/nsGUIEvent.h @@ -431,6 +431,7 @@ class nsHashKey; #define NS_SIMPLE_GESTURE_ROTATE (NS_SIMPLE_GESTURE_EVENT_START+6) #define NS_SIMPLE_GESTURE_TAP (NS_SIMPLE_GESTURE_EVENT_START+7) #define NS_SIMPLE_GESTURE_PRESSTAP (NS_SIMPLE_GESTURE_EVENT_START+8) +#define NS_SIMPLE_GESTURE_EDGEUI (NS_SIMPLE_GESTURE_EVENT_START+9) // These are used to send native events to plugins. #define NS_PLUGIN_EVENT_START 3600 @@ -1697,19 +1698,20 @@ public: nsSimpleGestureEvent(bool isTrusted, PRUint32 msg, nsIWidget* w, PRUint32 directionArg, PRFloat64 deltaArg) : nsMouseEvent_base(isTrusted, msg, w, NS_SIMPLE_GESTURE_EVENT), - direction(directionArg), delta(deltaArg) + direction(directionArg), delta(deltaArg), clickCount(0) { } nsSimpleGestureEvent(const nsSimpleGestureEvent& other) : nsMouseEvent_base((other.flags & NS_EVENT_FLAG_TRUSTED) != 0, other.message, other.widget, NS_SIMPLE_GESTURE_EVENT), - direction(other.direction), delta(other.delta) + direction(other.direction), delta(other.delta), clickCount(0) { } PRUint32 direction; // See nsIDOMSimpleGestureEvent for values PRFloat64 delta; // Delta for magnify and rotate events + PRUint32 clickCount; // The number of taps for tap events }; class nsTransitionEvent : public nsEvent diff --git a/widget/windows/nsWinGesture.cpp b/widget/windows/nsWinGesture.cpp index 7e98cdb6a56..46ae6786a76 100644 --- a/widget/windows/nsWinGesture.cpp +++ b/widget/windows/nsWinGesture.cpp @@ -390,6 +390,7 @@ nsWinGesture::ProcessGestureMessage(HWND hWnd, WPARAM wParam, LPARAM lParam, nsS // Normally maps to "restore" from whatever you may have recently changed. A simple // double click. evt.message = NS_SIMPLE_GESTURE_TAP; + evt.clickCount = 1; } break; @@ -397,6 +398,7 @@ nsWinGesture::ProcessGestureMessage(HWND hWnd, WPARAM wParam, LPARAM lParam, nsS { // Two finger right click. Defaults to right click if it falls through. evt.message = NS_SIMPLE_GESTURE_PRESSTAP; + evt.clickCount = 1; } break; }