Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/bidi/clipRectangle.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
/**
19
* Represents a clip rectangle.
20
* Described in https://w3c.github.io/webdriver-bidi/#command-browsingContext-captureScreenshot.
21
*/
22
class ClipRectangle {
23
clipType
24
25
/**
26
* Constructs a new ClipRectangle object.
27
* @param {string} type - The type of the clip rectangle.
28
*/
29
constructor(type) {
30
this.clipType = type
31
}
32
33
/**
34
* Gets the type of the clip rectangle.
35
* @returns {string} The type of the clip rectangle.
36
*/
37
get type() {
38
return this.clipType
39
}
40
41
asMap() {}
42
}
43
44
/**
45
* Represents a clip rectangle for an element.
46
* @extends ClipRectangle
47
*/
48
class ElementClipRectangle extends ClipRectangle {
49
#sharedId
50
#handleId
51
52
/**
53
* Constructs a new ElementClipRectangle instance.
54
* @param {string} sharedId - The shared ID of the element.
55
* @param {string} [handleId] - The handle ID of the element (optional).
56
*/
57
constructor(sharedId, handleId = undefined) {
58
super('element')
59
this.#sharedId = sharedId
60
61
if (handleId !== undefined) {
62
this.#handleId = handleId
63
}
64
}
65
66
/**
67
* Converts the ElementClipRectangle instance to a map.
68
* @returns {Map} - The converted map.
69
*/
70
asMap() {
71
const map = new Map()
72
map.set('type', super.type)
73
74
const sharedReference = new Map()
75
sharedReference.set('sharedId', this.#sharedId)
76
if (this.#handleId !== undefined) {
77
sharedReference.set('handleId', this.#handleId)
78
}
79
80
map.set('element', Object.fromEntries(sharedReference))
81
82
return map
83
}
84
}
85
86
/**
87
* Represents a box-shaped clip rectangle.
88
* @extends ClipRectangle
89
*/
90
class BoxClipRectangle extends ClipRectangle {
91
#x
92
#y
93
#width
94
#height
95
96
/**
97
* Constructs a new BoxClipRectangle object.
98
* @param {number} x - The x-coordinate of the top-left corner of the rectangle.
99
* @param {number} y - The y-coordinate of the top-left corner of the rectangle.
100
* @param {number} width - The width of the rectangle.
101
* @param {number} height - The height of the rectangle.
102
*/
103
constructor(x, y, width, height) {
104
super('box')
105
this.#x = x
106
this.#y = y
107
this.#width = width
108
this.#height = height
109
}
110
111
/**
112
* Converts the BoxClipRectangle object to a Map.
113
* @returns {Map<string, any>} - The Map representation of the BoxClipRectangle object.
114
*/
115
asMap() {
116
const map = new Map()
117
map.set('type', super.type)
118
map.set('x', this.#x)
119
map.set('y', this.#y)
120
map.set('width', this.#width)
121
map.set('height', this.#height)
122
123
return map
124
}
125
}
126
127
module.exports = { BoxClipRectangle, ElementClipRectangle }
128
129