我在我的程序中使用Geckofx。我只想将触摸事件(如touchstart,touchmove,touchend)发送到Geckobrowser的文档。我试图在“Gecko-core”的“WindowUtils.cs”中添加该方法。 dll“,就像那样:
public Boolean SendTouchEvent(string aType, uint[] aIdentifiers, int[] aXs, int[] aYs, uint[] aRxs, uint[] aRys, float[] aRotationAngles, float[] aForces, uint count, int aModifiers, bool aIgnoreRootScrollFrame)
{
using (nsAString type = new nsAString(aType))
{
return _windowUtils.Instance.SendTouchEvent(type, aIdentifiers, aXs, aYs, aRxs, aRys, aRotationAngles, aForces, count, aModifiers, aIgnoreRootScrollFrame);
}
}
此方法使用“nsIDOMWindowUtils.cs”中的方法“SendTouchEvent”,如下所示:
/// <summary>
///Synthesize a touch event. The event types supported are:
/// touchstart, touchend, touchmove, and touchcancel
///
/// Events are sent in coordinates offset by aX and aY from the window.
///
/// Cannot be accessed from unprivileged context (not content-accessible)
/// Will throw a DOM security error if called without chrome privileges.
///
/// The event is dispatched via the toplevel window, so it could go to any
/// window under the toplevel window, in some cases it could never reach this
/// window at all.
///
/// @param aType event type
/// @param xs array of offsets in CSS pixels for each touch to be sent
/// @param ys array of offsets in CSS pixels for each touch to be sent
/// @param rxs array of radii in CSS pixels for each touch to be sent
/// @param rys array of radii in CSS pixels for each touch to be sent
/// @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 as MODIFIER_*
/// @param aIgnoreRootScrollFrame whether the event should ignore viewport bounds
/// during dispatch
///
/// returns true if the page called prevent default on this touch event
/// </summary>
[return: MarshalAs(UnmanagedType.U1)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
bool SendTouchEvent([MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "Gecko.CustomMarshalers.AStringMarshaler")] nsAStringBase aType, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=8)] uint[] aIdentifiers, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=8)] int[] aXs, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=8)] int[] aYs, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=8)] uint[] aRxs, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=8)] uint[] aRys, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=8)] float[] aRotationAngles, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=8)] float[] aForces, uint count, int aModifiers, [MarshalAs(UnmanagedType.U1)] bool aIgnoreRootScrollFrame);
然后,我测试我的方法:
private void button2_Click(object sender, EventArgs e)
{
uint[] ident ={1};
int[] ax={200};
int[] ay={200};
uint[] rx ={2};
uint[] ry ={2};
float[] ro ={20};
float[] force={(float)0.8};
bool r = browser.Window.WindowUtils.SendTouchEvent("touchstart", ident, ax, ay, rx, ry, ro, force, (uint)1, 0, true);
Application.DoEvents();
for (int i = 0; i < 100; i++)
{
ay[0]+=10;
r = browser.Window.WindowUtils.SendTouchEvent("touchmove", ident, ax, ay, rx, ry, ro, force, (uint)1, 0, true);
Application.DoEvents();
Thread.Sleep(10);
}
r = browser.Window.WindowUtils.SendTouchEvent("touchend", ident, ax, ay, rx, ry, ro, force, (uint)1, 0, true);
}
但是,它总是返回错误;任何人都可以帮助我吗?提前谢谢。