Skip to content

Commit 87f8d67

Browse files
authored
Bidi: Touchscreen support (#3015)
* Bidi: Touchscreen support * fix
1 parent e9815cd commit 87f8d67

File tree

2 files changed

+69
-15
lines changed

2 files changed

+69
-15
lines changed

lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,21 +1252,7 @@
12521252
"FAIL"
12531253
]
12541254
},
1255-
{
1256-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
1257-
"testIdPattern": "[touchscreen.spec] *",
1258-
"platforms": [
1259-
"darwin",
1260-
"linux",
1261-
"win32"
1262-
],
1263-
"parameters": [
1264-
"webDriverBiDi"
1265-
],
1266-
"expectations": [
1267-
"FAIL"
1268-
]
1269-
},
1255+
12701256
{
12711257
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
12721258
"testIdPattern": "[tracing.spec] *",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using PuppeteerSharp.Helpers;
4+
using PuppeteerSharp.Input;
5+
using WebDriverBiDi.Input;
6+
7+
namespace PuppeteerSharp.Bidi;
8+
9+
internal class BidiTouchscreen(BidiPage page) : Touchscreen, IDisposable
10+
{
11+
private readonly PointerSourceActions _touchSource = new()
12+
{
13+
Parameters = new PointerParameters
14+
{
15+
PointerType = WebDriverBiDi.Input.PointerType.Touch,
16+
},
17+
};
18+
19+
private readonly TaskQueue _actionsQueue = new();
20+
21+
public override Task TouchStartAsync(decimal x, decimal y)
22+
{
23+
return _actionsQueue.Enqueue(async () =>
24+
{
25+
_touchSource.Actions.Add(new PointerMoveAction
26+
{
27+
X = (long)Math.Round(x),
28+
Y = (long)Math.Round(y),
29+
});
30+
_touchSource.Actions.Add(new PointerDownAction(0));
31+
32+
await page.BidiMainFrame.BrowsingContext.PerformActionsAsync([_touchSource]).ConfigureAwait(false);
33+
_touchSource.Actions.Clear();
34+
});
35+
}
36+
37+
public override Task TouchMoveAsync(decimal x, decimal y)
38+
{
39+
return _actionsQueue.Enqueue(async () =>
40+
{
41+
_touchSource.Actions.Add(new PointerMoveAction
42+
{
43+
X = (long)Math.Round(x),
44+
Y = (long)Math.Round(y),
45+
});
46+
47+
await page.BidiMainFrame.BrowsingContext.PerformActionsAsync([_touchSource]).ConfigureAwait(false);
48+
_touchSource.Actions.Clear();
49+
});
50+
}
51+
52+
public override Task TouchEndAsync()
53+
{
54+
return _actionsQueue.Enqueue(async () =>
55+
{
56+
_touchSource.Actions.Add(new PointerUpAction(0));
57+
58+
await page.BidiMainFrame.BrowsingContext.PerformActionsAsync([_touchSource]).ConfigureAwait(false);
59+
_touchSource.Actions.Clear();
60+
});
61+
}
62+
63+
public void Dispose()
64+
{
65+
_actionsQueue.Dispose();
66+
GC.SuppressFinalize(this);
67+
}
68+
}

0 commit comments

Comments
 (0)