1+ <?php
2+ // Copyright 2004-present Facebook. All Rights Reserved.
3+ //
4+ // Licensed under the Apache License, Version 2.0 (the "License");
5+ // you may not use this file except in compliance with the License.
6+ // You may obtain a copy of the License at
7+ //
8+ // http://www.apache.org/licenses/LICENSE-2.0
9+ //
10+ // Unless required by applicable law or agreed to in writing, software
11+ // distributed under the License is distributed on an "AS IS" BASIS,
12+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ // See the License for the specific language governing permissions and
14+ // limitations under the License.
15+
16+ /**
17+ * WebDriver action builder for touch events
18+ */
19+ class WebDriverTouchActions {
20+
21+ /**
22+ * @var WebDriverTouchScreen
23+ */
24+ protected $ touchScreen ;
25+
26+ /**
27+ * @var WebDriver
28+ */
29+ protected $ driver ;
30+
31+ /**
32+ * @var WebDriverKeyboard
33+ */
34+ protected $ keyboard ;
35+
36+ /**
37+ * @var WebDriverMouse
38+ */
39+ protected $ mouse ;
40+
41+ /**
42+ * @var WebDriverCompositeAction
43+ */
44+ protected $ action ;
45+
46+ public function __construct (WebDriver $ driver ) {
47+ $ this ->driver = $ driver ;
48+ $ this ->keyboard = $ driver ->getKeyboard ();
49+ $ this ->mouse = $ driver ->getMouse ();
50+ $ this ->touchScreen = $ driver ->getTouch ();
51+ $ this ->action = new WebDriverCompositeAction ();
52+ }
53+
54+ public function tap (WebDriverElement $ element ) {
55+ $ this ->action ->addAction (
56+ new WebDriverTapAction ($ this ->touchScreen , $ element )
57+ );
58+ return $ this ;
59+ }
60+
61+ public function down ($ x , $ y ) {
62+ $ this ->action ->addAction (
63+ new WebDriverDownAction ($ this ->touchScreen , $ x , $ y )
64+ );
65+ return $ this ;
66+ }
67+
68+ public function up ($ x , $ y ) {
69+ $ this ->action ->addAction (
70+ new WebDriverUpAction ($ this ->touchScreen , $ x , $ y )
71+ );
72+ return $ this ;
73+ }
74+
75+ public function move ($ x , $ y ) {
76+ $ this ->action ->addAction (
77+ new WebDriverMoveAction ($ this ->touchScreen , $ x , $ y )
78+ );
79+ return $ this ;
80+ }
81+
82+ public function scroll ($ x , $ y ) {
83+ $ this ->action ->addAction (
84+ new WebDriverScrollAction ($ this ->touchScreen , $ x , $ y )
85+ );
86+ return $ this ;
87+ }
88+
89+ public function scrollFromElement (WebDriverElement $ element , $ x , $ y ) {
90+ $ this ->action ->addAction (
91+ new WebDriverScrollFromElementAction ($ this ->touchScreen , $ element , $ x , $ y )
92+ );
93+ return $ this ;
94+ }
95+
96+ public function doubleTap (WebDriverElement $ element ) {
97+ $ this ->action ->addAction (
98+ new WebDriverDoubleTapAction ($ this ->touchScreen , $ element )
99+ );
100+ return $ this ;
101+ }
102+
103+ public function longPress (WebDriverElement $ element ) {
104+ $ this ->action ->addAction (
105+ new WebDriverLongPressAction ($ this ->touchScreen , $ element )
106+ );
107+ return $ this ;
108+ }
109+
110+ public function flick ($ x , $ y ) {
111+ $ this ->action ->addAction (
112+ new WebDriverFlickAction ($ this ->touchScreen , $ x , $ y )
113+ );
114+ return $ this ;
115+ }
116+
117+ public function flickFromElement (WebDriverElement $ element , $ x , $ y , $ speed ) {
118+ $ this ->action ->addAction (
119+ new WebDriverFlickFromElementAction ($ this ->touchScreen , $ element , $ x , $ y , $ speed )
120+ );
121+ return $ this ;
122+ }
123+
124+ }
0 commit comments