MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / getClientRect

Function getClientRect

javascript/atoms/typescript/is-displayed.ts:134–171  ·  view source on GitHub ↗
(elem: Element)

Source from the content-addressed store, hash-verified

132 }
133
134 function getClientRect(elem: Element): Rect {
135 var cachedRect = clientRectCache.get(elem);
136 if (cachedRect) {
137 return cachedRect;
138 }
139
140 var rect: Rect;
141 var imageMap = maybeFindImageMap(elem);
142 if (imageMap) {
143 rect = imageMap.rect;
144 } else {
145 var elemTagName = typeof (elem as Element).tagName === 'string' ? (elem as Element).tagName : '';
146 if (elemTagName.toUpperCase() === 'HTML') {
147 var doc = (elem as Element).ownerDocument;
148 // In quirks mode (no DOCTYPE), viewport dimensions come from document.body;
149 // documentElement.clientWidth/Height is unreliable and can be 0.
150 var sizeElem = doc.compatMode === 'CSS1Compat' ? doc.documentElement : (doc.body || doc.documentElement);
151 rect = createRect(0, 0, sizeElem.clientWidth, sizeElem.clientHeight);
152 } else {
153 try {
154 var nativeRect = (elem as Element).getBoundingClientRect();
155 rect = {
156 left: nativeRect.left,
157 top: nativeRect.top,
158 right: nativeRect.right,
159 bottom: nativeRect.bottom,
160 width: nativeRect.right - nativeRect.left,
161 height: nativeRect.bottom - nativeRect.top,
162 };
163 } catch (_error) {
164 rect = createRect(0, 0, 0, 0);
165 }
166 }
167 }
168
169 clientRectCache.set(elem, rect);
170 return rect;
171 }
172
173 function getAreaRelativeRect(area: HTMLAreaElement): Rect {
174 var shape = area.shape.toLowerCase();

Callers 4

maybeFindImageMapFunction · 0.70
getClientRegionFunction · 0.70
getOverflowStateFunction · 0.70
positiveSizeFunction · 0.70

Calls 4

maybeFindImageMapFunction · 0.85
createRectFunction · 0.85
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected