Path: blob/trunk/javascript/selenium-webdriver/bidi/clipRectangle.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* Represents a clip rectangle.19* Described in https://w3c.github.io/webdriver-bidi/#command-browsingContext-captureScreenshot.20*/21class ClipRectangle {22clipType2324/**25* Constructs a new ClipRectangle object.26* @param {string} type - The type of the clip rectangle.27*/28constructor(type) {29this.clipType = type30}3132/**33* Gets the type of the clip rectangle.34* @returns {string} The type of the clip rectangle.35*/36get type() {37return this.clipType38}3940asMap() {}41}4243/**44* Represents a clip rectangle for an element.45* @extends ClipRectangle46*/47class ElementClipRectangle extends ClipRectangle {48#sharedId49#handleId5051/**52* Constructs a new ElementClipRectangle instance.53* @param {string} sharedId - The shared ID of the element.54* @param {string} [handleId] - The handle ID of the element (optional).55*/56constructor(sharedId, handleId = undefined) {57super('element')58this.#sharedId = sharedId5960if (handleId !== undefined) {61this.#handleId = handleId62}63}6465/**66* Converts the ElementClipRectangle instance to a map.67* @returns {Map} - The converted map.68*/69asMap() {70const map = new Map()71map.set('type', super.type)7273const sharedReference = new Map()74sharedReference.set('sharedId', this.#sharedId)75if (this.#handleId !== undefined) {76sharedReference.set('handleId', this.#handleId)77}7879map.set('element', Object.fromEntries(sharedReference))8081return map82}83}8485/**86* Represents a box-shaped clip rectangle.87* @extends ClipRectangle88*/89class BoxClipRectangle extends ClipRectangle {90#x91#y92#width93#height9495/**96* Constructs a new BoxClipRectangle object.97* @param {number} x - The x-coordinate of the top-left corner of the rectangle.98* @param {number} y - The y-coordinate of the top-left corner of the rectangle.99* @param {number} width - The width of the rectangle.100* @param {number} height - The height of the rectangle.101*/102constructor(x, y, width, height) {103super('box')104this.#x = x105this.#y = y106this.#width = width107this.#height = height108}109110/**111* Converts the BoxClipRectangle object to a Map.112* @returns {Map<string, any>} - The Map representation of the BoxClipRectangle object.113*/114asMap() {115const map = new Map()116map.set('type', super.type)117map.set('x', this.#x)118map.set('y', this.#y)119map.set('width', this.#width)120map.set('height', this.#height)121122return map123}124}125126module.exports = { BoxClipRectangle, ElementClipRectangle }127128129