Bug 630811 part.3 Improve nsDOMWindowUtils::send*Event() for new modifiers r=smaug

This commit is contained in:
Masayuki Nakano 2012-04-25 12:00:02 +09:00
parent e089b336f8
commit cea6824fb9
4 changed files with 110 additions and 36 deletions

View File

@ -92,6 +92,7 @@
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "sampler.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::layers;
using namespace mozilla::widget;
@ -420,6 +421,47 @@ nsDOMWindowUtils::GetIsFirstPaint(bool *aIsFirstPaint)
return NS_ERROR_FAILURE;
}
/* static */
mozilla::widget::Modifiers
nsDOMWindowUtils::GetWidgetModifiers(PRInt32 aModifiers)
{
widget::Modifiers result = 0;
if (aModifiers & nsIDOMWindowUtils::MODIFIER_SHIFT) {
result |= widget::MODIFIER_SHIFT;
}
if (aModifiers & nsIDOMWindowUtils::MODIFIER_CONTROL) {
result |= widget::MODIFIER_CONTROL;
}
if (aModifiers & nsIDOMWindowUtils::MODIFIER_ALT) {
result |= widget::MODIFIER_ALT;
}
if (aModifiers & nsIDOMWindowUtils::MODIFIER_META) {
result |= widget::MODIFIER_META;
}
if (aModifiers & nsIDOMWindowUtils::MODIFIER_ALTGRAPH) {
result |= widget::MODIFIER_ALTGRAPH;
}
if (aModifiers & nsIDOMWindowUtils::MODIFIER_CAPSLOCK) {
result |= widget::MODIFIER_CAPSLOCK;
}
if (aModifiers & nsIDOMWindowUtils::MODIFIER_FN) {
result |= widget::MODIFIER_FN;
}
if (aModifiers & nsIDOMWindowUtils::MODIFIER_NUMLOCK) {
result |= widget::MODIFIER_NUMLOCK;
}
if (aModifiers & nsIDOMWindowUtils::MODIFIER_SCROLL) {
result |= widget::MODIFIER_SCROLL;
}
if (aModifiers & nsIDOMWindowUtils::MODIFIER_SYMBOLLOCK) {
result |= widget::MODIFIER_SYMBOLLOCK;
}
if (aModifiers & nsIDOMWindowUtils::MODIFIER_WIN) {
result |= widget::MODIFIER_WIN;
}
return result;
}
NS_IMETHODIMP
nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
float aX,
@ -487,10 +529,7 @@ nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
nsMouseEvent event(true, msg, widget, nsMouseEvent::eReal,
contextMenuKey ?
nsMouseEvent::eContextMenuKey : nsMouseEvent::eNormal);
event.isShift = (aModifiers & nsIDOMNSEvent::SHIFT_MASK) ? true : false;
event.isControl = (aModifiers & nsIDOMNSEvent::CONTROL_MASK) ? true : false;
event.isAlt = (aModifiers & nsIDOMNSEvent::ALT_MASK) ? true : false;
event.isMeta = (aModifiers & nsIDOMNSEvent::META_MASK) ? true : false;
event.modifiers = GetWidgetModifiers(aModifiers);
event.button = aButton;
event.widget = widget;
@ -557,10 +596,7 @@ nsDOMWindowUtils::SendMouseScrollEvent(const nsAString& aType,
return NS_ERROR_UNEXPECTED;
nsMouseScrollEvent event(true, msg, widget);
event.isShift = (aModifiers & nsIDOMNSEvent::SHIFT_MASK) ? true : false;
event.isControl = (aModifiers & nsIDOMNSEvent::CONTROL_MASK) ? true : false;
event.isAlt = (aModifiers & nsIDOMNSEvent::ALT_MASK) ? true : false;
event.isMeta = (aModifiers & nsIDOMNSEvent::META_MASK) ? true : false;
event.modifiers = GetWidgetModifiers(aModifiers);
event.button = aButton;
event.widget = widget;
event.delta = aDelta;
@ -622,10 +658,7 @@ nsDOMWindowUtils::SendTouchEvent(const nsAString& aType,
return NS_ERROR_UNEXPECTED;
}
nsTouchEvent event(true, msg, widget);
event.isShift = (aModifiers & nsIDOMNSEvent::SHIFT_MASK) ? true : false;
event.isControl = (aModifiers & nsIDOMNSEvent::CONTROL_MASK) ? true : false;
event.isAlt = (aModifiers & nsIDOMNSEvent::ALT_MASK) ? true : false;
event.isMeta = (aModifiers & nsIDOMNSEvent::META_MASK) ? true : false;
event.modifiers = GetWidgetModifiers(aModifiers);
event.widget = widget;
event.time = PR_Now();
@ -685,10 +718,7 @@ nsDOMWindowUtils::SendKeyEvent(const nsAString& aType,
return NS_ERROR_FAILURE;
nsKeyEvent event(true, msg, widget);
event.isShift = (aModifiers & nsIDOMNSEvent::SHIFT_MASK) ? true : false;
event.isControl = (aModifiers & nsIDOMNSEvent::CONTROL_MASK) ? true : false;
event.isAlt = (aModifiers & nsIDOMNSEvent::ALT_MASK) ? true : false;
event.isMeta = (aModifiers & nsIDOMNSEvent::META_MASK) ? true : false;
event.modifiers = GetWidgetModifiers(aModifiers);
event.keyCode = aKeyCode;
event.charCode = aCharCode;
@ -942,10 +972,7 @@ nsDOMWindowUtils::SendSimpleGestureEvent(const nsAString& aType,
return NS_ERROR_FAILURE;
nsSimpleGestureEvent event(true, msg, widget, aDirection, aDelta);
event.isShift = (aModifiers & nsIDOMNSEvent::SHIFT_MASK) ? true : false;
event.isControl = (aModifiers & nsIDOMNSEvent::CONTROL_MASK) ? true : false;
event.isAlt = (aModifiers & nsIDOMNSEvent::ALT_MASK) ? true : false;
event.isMeta = (aModifiers & nsIDOMNSEvent::META_MASK) ? true : false;
event.modifiers = GetWidgetModifiers(aModifiers);
event.time = PR_IntervalNow();
nsPresContext* presContext = GetPresContext();

View File

@ -39,6 +39,7 @@
#include "nsWeakReference.h"
#include "nsIDOMWindowUtils.h"
#include "nsEvent.h"
class nsGlobalWindow;
class nsIPresShell;
@ -73,4 +74,6 @@ protected:
PRInt32 aModifiers,
bool aIgnoreRootScrollFrame,
bool aToWindow);
static mozilla::widget::Modifiers GetWidgetModifiers(PRInt32 aModifiers);
};

View File

@ -198,6 +198,24 @@ interface nsIDOMWindowUtils : nsISupports {
*/
attribute boolean isFirstPaint;
/**
* Following modifiers are for sent*Event() except sendNative*Event().
* NOTE: MODIFIER_ALT, MODIFIER_CONTROL, MODIFIER_SHIFT and MODIFIER_META
* are must be same values as nsIDOMNSEvent::*_MASK for backward
* compatibility.
*/
const long MODIFIER_ALT = 0x0001;
const long MODIFIER_CONTROL = 0x0002;
const long MODIFIER_SHIFT = 0x0004;
const long MODIFIER_META = 0x0008;
const long MODIFIER_ALTGRAPH = 0x0010;
const long MODIFIER_CAPSLOCK = 0x0020;
const long MODIFIER_FN = 0x0040;
const long MODIFIER_NUMLOCK = 0x0080;
const long MODIFIER_SCROLL = 0x0100;
const long MODIFIER_SYMBOLLOCK = 0x0200;
const long MODIFIER_WIN = 0x0400;
/** Synthesize a mouse event. The event types supported are:
* mousedown, mouseup, mousemove, mouseover, mouseout, contextmenu
*
@ -225,7 +243,7 @@ interface nsIDOMWindowUtils : nsISupports {
* @param aY y offset in CSS pixels
* @param aButton button to synthesize
* @param aClickCount number of clicks that have been performed
* @param aModifiers modifiers pressed, using constants defined in nsIDOMNSEvent
* @param aModifiers modifiers pressed, using constants defined as MODIFIER_*
* @param aIgnoreRootScrollFrame whether the event should ignore viewport bounds
* during dispatch
*/
@ -258,7 +276,7 @@ interface nsIDOMWindowUtils : nsISupports {
* @param rotationAngles array of angles in degrees for each touch to be sent
* @param forces array of forces (floats from 0 to 1) for each touch to be sent
* @param count number of touches in this set
* @param aModifiers modifiers pressed, using constants defined in nsIDOMNSEvent
* @param aModifiers modifiers pressed, using constants defined as MODIFIER_*
* @param aIgnoreRootScrollFrame whether the event should ignore viewport bounds
* during dispatch
*
@ -305,7 +323,7 @@ interface nsIDOMWindowUtils : nsISupports {
* @param aScrollFlags flag bits --- see nsMouseScrollFlags in nsGUIEvent.h
* @param aDelta the direction and amount to scroll (in lines or pixels,
* depending on the event type)
* @param aModifiers modifiers pressed, using constants defined in nsIDOMNSEvent
* @param aModifiers modifiers pressed, using constants defined as MODIFIER_*
*/
void sendMouseScrollEvent(in AString aType,
in float aX,
@ -328,7 +346,7 @@ interface nsIDOMWindowUtils : nsISupports {
* @param aType event type
* @param aKeyCode key code
* @param aCharCode character code
* @param aModifiers modifiers pressed, using constants defined in nsIDOMNSEvent
* @param aModifiers modifiers pressed, using constants defined as MODIFIER_*
* @param aPreventDefault if true, preventDefault() the event before dispatch
*
* @return false if the event had preventDefault() called on it,

View File

@ -116,19 +116,45 @@ function sendKey(aKey, aWindow) {
*/
function _parseModifiers(aEvent)
{
const masks = Components.interfaces.nsIDOMNSEvent;
const nsIDOMWindowUtils = Components.interfaces.nsIDOMWindowUtils;
var mval = 0;
if (aEvent.shiftKey)
mval |= masks.SHIFT_MASK;
if (aEvent.ctrlKey)
mval |= masks.CONTROL_MASK;
if (aEvent.altKey)
mval |= masks.ALT_MASK;
if (aEvent.metaKey)
mval |= masks.META_MASK;
if (aEvent.accelKey)
mval |= (navigator.platform.indexOf("Mac") >= 0) ? masks.META_MASK :
masks.CONTROL_MASK;
if (aEvent.shiftKey) {
mval |= nsIDOMWindowUtils.MODIFIER_SHIFT;
}
if (aEvent.ctrlKey) {
mval |= nsIDOMWindowUtils.MODIFIER_CONTROL;
}
if (aEvent.altKey) {
mval |= nsIDOMWindowUtils.MODIFIER_ALT;
}
if (aEvent.metaKey) {
mval |= nsIDOMWindowUtils.MODIFIER_META;
}
if (aEvent.accelKey) {
mval |= (navigator.platform.indexOf("Mac") >= 0) ?
nsIDOMWindowUtils.MODIFIER_META : nsIDOMWindowUtils.MODIFIER_CONTROL;
}
if (aEvent.altGrKey) {
mval |= nsIDOMWindowUtils.MODIFIER_ALTGRAPH;
}
if (aEvent.capsLockKey) {
mval |= nsIDOMWindowUtils.MODIFIER_CAPSLOCK;
}
if (aEvent.fnKey) {
mval |= nsIDOMWindowUtils.MODIFIER_FN;
}
if (aEvent.numLockKey) {
mval |= nsIDOMWindowUtils.MODIFIER_NUMLOCK;
}
if (aEvent.scrollLockKey) {
mval |= nsIDOMWindowUtils.MODIFIER_SCROLL;
}
if (aEvent.symbolLockKey) {
mval |= nsIDOMWindowUtils.MODIFIER_SYMBOLLOCK;
}
if (aEvent.winKey) {
mval |= nsIDOMWindowUtils.MODIFIER_WIN;
}
return mval;
}