Path: blob/trunk/rb/lib/selenium/webdriver/common/interactions/pointer_event_properties.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 Interactions22module PointerEventProperties23VALID = {width: {'width' => {min: 0.0}},24height: {'height' => {min: 0.0}},25pressure: {'pressure' => {min: 0.0, max: 1.0}},26tangential_pressure: {'tangentialPressure' => {min: -1.0, max: 1.0}},27tilt_x: {'tiltX' => {min: -90, max: 90}},28tilt_y: {'tiltY' => {min: -90, max: 90}},29twist: {'twist' => {min: 0, max: 359}},30altitude_angle: {'altitudeAngle' => {min: 0.0, max: (Math::PI / 2)}},31azimuth_angle: {'azimuthAngle' => {min: 0.0, max: (Math::PI * 2)}}}.freeze3233def process_opts34raise ArgumentError, "Unknown options found: #{@opts.inspect}" unless (@opts.keys - VALID.keys).empty?3536VALID.each_with_object({}) do |(key, val), hash|37next unless @opts.key?(key)3839name = val.keys.first40values = val.values.first41hash[name] = assert_number(@opts[key], values[:min], values[:max])42end43end4445private4647def assert_number(num, min, max = nil)48return if num.nil?4950klass = min.is_a?(Integer) ? Integer : Numeric51raise TypeError, "#{num} is not a #{klass}" unless num.is_a?(klass)5253raise ArgumentError, "#{num} is not greater than or equal to #{min}" if num < min5455raise ArgumentError, "#{num} is not less than or equal to #{max}" if max && num > max5657num58end59end # PointerEventProperties60end # Interactions61end # WebDriver62end # Selenium636465