# encoding: utf-8## Licensed to the Software Freedom Conservancy (SFC) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The SFC licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.moduleSeleniummoduleWebDrivermoduleInteractionsclassPointerInput<InputDeviceKIND={mouse: :mouse,pen: :pen,touch: :touch}.freezeattr_reader:kinddefinitialize(kind,name: nil)super(name)@kind=assert_kind(kind)enddeftypeInteractions::POINTERenddefencodereturnnilifno_actions?output={type: type,id: name,actions: @actions.map(&:encode)}output[:parameters]={pointerType: kind}outputenddefassert_kind(pointer)raiseTypeError,"#{pointer.inspect} is not a valid pointer type"unlessKIND.key?pointerKIND[pointer]enddefcreate_pointer_move(duration: 0,x: 0,y: 0,element: nil,origin: nil)add_action(PointerMove.new(self,duration,x,y,element: element,origin: origin))enddefcreate_pointer_down(button)add_action(PointerPress.new(self,:down,button))enddefcreate_pointer_up(button)add_action(PointerPress.new(self,:up,button))enddefcreate_pointer_canceladd_action(PointerCancel.new(self))endend# PointerInputclassPointerPress<InteractionBUTTONS={left: 0,middle: 1,right: 2}.freezeDIRECTIONS={down: :pointerDown,up: :pointerUp}.freezedefinitialize(source,direction,button)super(source)@direction=assert_direction(direction)@button=assert_button(button)enddeftype@directionenddefassert_button(button)ifbutton.is_a?SymbolraiseTypeError,"#{button.inspect} is not a valid button!"unlessBUTTONS.key?buttonbutton=BUTTONS[button]endraiseArgumentError,'Button number cannot be negative!'unlessbutton>=0buttonenddefassert_direction(direction)raiseTypeError,"#{direction.inspect} is not a valid button direction"unlessDIRECTIONS.key?directionDIRECTIONS[direction]enddefencode{type: type,button: @button}endend# PointerPressclassPointerMove<InteractionVIEWPORT=:viewportPOINTER=:pointerORIGINS=[VIEWPORT,POINTER].freezedefinitialize(source,duration,x,y,element: nil,origin: nil)super(source)@duration=duration*1000@x_offset=x@y_offset=y@origin=element||originenddeftype:pointerMoveenddefencodeoutput={type: type,duration: @duration.to_i,x: @x_offset,y: @y_offset}output[:origin]=@originoutputendend# MoveclassPointerCancel<Interactiondeftype:pointerCancelenddefencode{type: type}endend# Cancelend# Interactionsend# WebDriverend# Selenium