Path: blob/trunk/rb/lib/selenium/webdriver/common/interactions/pointer_press.rb
1990 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21module Interactions22#23# Actions related to clicking, tapping or pressing the pointer.24#25# @api private26#2728class PointerPress < Interaction29include PointerEventProperties3031BUTTONS = {left: 0,32touch: 0,33pen_contact: 0,34middle: 1,35right: 2,36pen_barrel: 2,37x1: 3,38back: 3,39x2: 4,40forward: 4}.freeze41DIRECTIONS = {down: :pointerDown, up: :pointerUp}.freeze4243def initialize(source, direction, button, **opts)44super(source)45@direction = assert_direction(direction)46@button = assert_button(button)47@type = @direction48@opts = opts49end5051def encode52process_opts.merge('type' => type.to_s, 'button' => @button)53end5455private5657def assert_source(source)58raise TypeError, "#{source.type} is not a valid input type" unless source.is_a? PointerInput59end6061def assert_button(button)62case button63when Symbol64raise ArgumentError, "#{button} is not a valid button!" unless BUTTONS.key? button6566BUTTONS[button]67when Integer68raise ArgumentError, 'Button number cannot be negative!' if button.negative?6970button71else72raise TypeError, "button must be a positive integer or one of #{BUTTONS.keys}, not #{button.class}"73end74end7576def assert_direction(direction)77raise ArgumentError, "#{direction.inspect} is not a valid button direction" unless DIRECTIONS.key? direction7879DIRECTIONS[direction]80end81end # PointerPress82end # Interactions83end # WebDriver84end # Selenium858687