Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/client/core/utils/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,35 @@ export function getIframeClientCoordinates (iframe: HTMLIFrameElement): Boundary
iframeRectangleLeft);
}

export function containsOffset (el: HTMLElement, offsetX?: number, offsetY?: number): boolean {
function isImageMapArea (el: HTMLElement): boolean {
if (domUtils.getTagName(el) !== 'area')
return false;

const map = domUtils.closest(el, 'map');
const container = map && domUtils.getMapContainer(map);

return !!container && domUtils.isImgElement(container);
}

function getMaxOffset (el: HTMLElement): AxisValuesData<number> {
if (hammerhead.utils.browser.isFirefox && isImageMapArea(el)) {
const { width, height } = getElementRectangle(el);

return { x: width, y: height };
}

const dimensions = getClientDimensions(el);
const width = Math.max(el.scrollWidth, dimensions.width);
const height = Math.max(el.scrollHeight, dimensions.height);
const maxX = dimensions.scrollbar.right + dimensions.border.left + dimensions.border.right + width;
const maxY = dimensions.scrollbar.bottom + dimensions.border.top + dimensions.border.bottom + height;

return {
x: dimensions.scrollbar.right + dimensions.border.left + dimensions.border.right + width,
y: dimensions.scrollbar.bottom + dimensions.border.top + dimensions.border.bottom + height,
};
}

export function containsOffset (el: HTMLElement, offsetX?: number, offsetY?: number): boolean {
const { x: maxX, y: maxY } = getMaxOffset(el);

return (typeof offsetX === 'undefined' || offsetX >= 0 && maxX >= offsetX) &&
(typeof offsetY === 'undefined' || offsetY >= 0 && maxY >= offsetY);
Expand Down
26 changes: 24 additions & 2 deletions test/client/fixtures/automation/click-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const browserUtils = hammerhead.utils.browser;
const featureDetection = hammerhead.utils.featureDetection;
const Promise = hammerhead.Promise;

const testCafeCore = window.getTestCafeModule('testCafeCore');
const styleUtils = testCafeCore.styleUtils;
const testCafeCore = window.getTestCafeModule('testCafeCore');
const styleUtils = testCafeCore.styleUtils;
const positionUtils = testCafeCore.positionUtils;

const testCafeAutomation = window.getTestCafeModule('testCafeAutomation');
const getOffsetOptions = testCafeAutomation.getOffsetOptions;
Expand Down Expand Up @@ -1183,6 +1184,27 @@ $(document).ready(function () {
}, TEST_RESULT_TIMEOUT + 200);
});

(browserUtils.isFirefox ? test : QUnit.skip)('Offsets of an image map area should be checked against its coords', function () {
const $map = $('<map name="map"></map>')
.appendTo('body')
.addClass(TEST_ELEMENT_CLASS);

const $area = $('<area shape="rect" coords="0,0,50,100" title="Area"/>').appendTo($map);

$('<img usemap="#map"/>')
.css({
width: '200px',
height: '200px',
})
.appendTo('body')
.addClass(TEST_ELEMENT_CLASS);

ok(positionUtils.containsOffset($area[0], 10, 10));
ok(positionUtils.containsOffset($area[0], 50, 100));
notOk(positionUtils.containsOffset($area[0], 60, 10));
notOk(positionUtils.containsOffset($area[0], 10, 110));
});

module('touch devices test');
if (featureDetection.isTouchDevice) {
asyncTest('touch event on click', function () {
Expand Down
Loading