Closed Bug 1502074 Opened 6 years ago Closed 6 years ago

offsetWidth is 0 if the IMG element does not have any "src" attribute

Categories

(Core :: Layout, defect, P3)

63 Branch
defect

Tracking

()

RESOLVED DUPLICATE of bug 1196668
Tracking Status
firefox63 --- affected
firefox64 --- affected
firefox65 --- affected

People

(Reporter: xavophonic, Unassigned)

Details

Attachments

(1 file)

Attached file test-offsetwidth.html
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0

Steps to reproduce:

Open a HTML page with an IMG element that does not have any attribute "src". 
Open the debugger. Read the property offsetWidth of the IMG.
Open the attached file to view the test case.


Actual results:

The offsetWidth is "0".


Expected results:

It should be the value returned by the css style "width" converted in pixels.
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0 (20181030100414)

I have tested this report on Windows 10 x64 and Ubuntu 18.04 x64 using the latest Nightly and Firefox release build. I'm able to reproduce the mentioned behavior. When loading the provided attachment the "width" property is '0'. When "src" attribute is added the browser display the correct width. The same behavior is not reproduced in the competitor browsers where the width property is correctly displayed.
Status: UNCONFIRMED → NEW
Component: Untriaged → Layout
Ever confirmed: true
Product: Firefox → Core
Moving, as this seems like it belongs in CSS Object Model.
Component: Layout → DOM: CSS Object Model
Priority: -- → P3
This belongs to layout. The conditions for which an <img> element generates an actual image frame are the following:

  https://searchfox.org/mozilla-central/rev/eac6295c397133b7346822ad31867197e30d7e94/layout/generic/nsImageFrame.cpp#584

We're probably returning false from that function...

Spec is at https://html.spec.whatwg.org/#the-img-element:

> If the src attribute is not set and either the alt attribute is set to the empty string or the alt attribute is not set at all
>
>   The element represents nothing.


But unlike other parts of that section there's no note about omitting it from the rendering or not... Boris, do you happen to have some thoughts on this? I remember you commenting on other similar bugs, this may even be a dupe :


I need to dig up the logic Blink and WebKit use, I guess they're doing the equivalent of another HasSpecifiedSize bit after checking the alt attribute, or something...
Component: DOM: CSS Object Model → Layout
Flags: needinfo?(bzbarsky)
This looks like a duplicate of bug 1196668, which has discussion explaining what's going on.  Long story short, we're following the spec, WebKit/Blink are not, bug 1196668 comment 10 has my proposal for a spec change (and a  behavior change in our code) that would fix this specific case, basically to make people's spacer gifs work even in standards mode, since people seem to like them so much.
Flags: needinfo?(bzbarsky)
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: