Closed Bug 1676952 Opened 5 years ago Closed 3 years ago

HTMLImageElement x and y coordinates are 0 if its parent container has position: relative

Categories

(Core :: DOM: Core & HTML, defect)

Firefox 84
Desktop
Unspecified
defect

Tracking

()

VERIFIED FIXED
104 Branch
Webcompat Priority P3
Tracking Status
firefox84 --- wontfix
firefox104 --- verified

People

(Reporter: ksenia, Assigned: mrobinson)

References

()

Details

Attachments

(4 files)

Attached file 52738.html

As reported in https://github.com/webcompat/web-bugs/issues/52738

STR:

  1. Visit https://chintglobal.com/products/nm8n-moulded-case-circuit-breaker-8-1057 in Firefox and try to hover over the image

Expected:
Can hover over the top part of the product image to see the details

Actual:
Can't hover over the top part of the image

One of the properties the site is relying on for calculations is the y coordinate of the image:

i = u.clientY - this.main_image.y - this.mengban.clientHeight / 2;

I've attached a reduced test case, it seems that the fact that a parent container of the image has position: relative is affecting the coordinates, however that doesn't happen in Chrome.

Yeah, that's wrong per spec, https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlimageelement-interface:

The x attribute, on getting, must return the x-coordinate of the left border edge of the first CSS layout box associated with the element, relative to the initial containing block origin, ignoring any transforms that apply to the element and its ancestors, or zero if there is no CSS layout box.

That being said it seems like the page is also super clunky in Chrome, it doesn't seem to behave as expected either.

Does PresShell()->GetRootFrame() returns the "initial containing block", or should it be obtained from nsCSSFrameConstructor?

Flags: needinfo?(emilio)
Severity: -- → S3

Per https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlimageelement-interface:

The x attribute, on getting, must return the x-coordinate of the left
border edge of the first CSS layout box associated with the element,
relative to the initial containing block origin, ignoring any
transforms that apply to the element and its ancestors, or zero if
there is no CSS layout box.

But we were using GetClosestLayer which stops at the first abspos
containing block or scroll frame.

Yeah, I had a patch doing just that that I posted. But it's not clear whether that matches other browsers in presence of transforms etc, and there's no wpt that started passing / failing with it.

Depending on what other browsers do we might want to use GetRootScrollableFrame or something instead.

Flags: needinfo?(emilio)

I was looking at content-visibility failures and I noticed that this change now fixes tests/css/css-contain/content-visibility/content-visibility-img.html in the css-contain suite. I also verified that this has the same behavior as Chromium and WebKit when there is a transform between the image and the ICB.

Webcompat Priority: ? → P3

I've uploaded an updated version of the fix for this.

Assignee: nobody → mrobinson

Per https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlimageelement-interface:

The x attribute, on getting, must return the x-coordinate of the left
border edge of the first CSS layout box associated with the element,
relative to the initial containing block origin, ignoring any
transforms that apply to the element and its ancestors, or zero if
there is no CSS layout box.

But we were using GetClosestLayer which stops at the first abspos
containing block or scroll frame.

Attachment #9284519 - Attachment description: WIP: Bug 1676952 - Fix HTMLImageElement.x/y to match the spec. → Bug 1676952 - Fix HTMLImageElement.x/y to match the spec.
Pushed by mrobinson@igalia.com: https://hg.mozilla.org/integration/autoland/rev/3f4cb7139d71 Fix HTMLImageElement.x/y to match the spec. r=emilio
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 104 Branch
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/34783 for changes under testing/web-platform/tests
Upstream PR merged by moz-wptsync-bot

Reproduced the issue with Firefox 84.0a1 (20201112212842) on Windows 10x64 using the webpage link from comment 0. The image hover selection cannot be moved on the top side of the image.
The issue is verified fixed with Firefox 104.0b2 (20220726185717) on Windows 10x64, Ubuntu 20.04 and macOS 11. The image can be hovered as expected.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: