Opened 9 years ago

Closed 9 years ago

#12492 closed defect (wontfix)

dojo.contentBox and dojo.marginBox return 0/negative if node hidden

Reported by: xMartin Owned by: Eugene Lazutkin
Priority: high Milestone: tbd
Component: HTML Version: 1.6.0
Keywords: Cc:
Blocked By: Blocking:

Description

dojo.contentBox and dojo.marginBox return wrong, even negative values if there's padding or margin set and the DOM node is either not appended to the DOM or it is display: none. This is because clientHeight or offsetHeight are zero in these cases but Dojo calculates values respecting the styling which is still there.

Attached is a simple test file.

I think these functions should return {0, 0, 0, 0}. Is there a way to check if the node is visibly rendered? Should Dojo's function even return null or something in these cases?

Attachments (1)

html_box_hidden.html (2.1 KB) - added by xMartin 9 years ago.

Download all attachments as: .zip

Change History (9)

Changed 9 years ago by xMartin

Attachment: html_box_hidden.html added

comment:1 Changed 9 years ago by xMartin

Please fix the subject! It's broken if node is NOT visibly rendered!

comment:2 Changed 9 years ago by bill

Component: CoreHTML
Owner: changed from anonymous to Eugene Lazutkin
Summary: dojo.contentBox and dojo.marginBox broken if node is visibly rendereddojo.contentBox and dojo.marginBox return 0/negative if node hidden

I think this is expected behavior that we don't want to change, see #3798, Eugene?

comment:3 in reply to:  2 Changed 9 years ago by Eugene Lazutkin

Replying to bill:

I think this is expected behavior that we don't want to change, see #3798, Eugene?

I think you right. As an optimization almost all browsers do not "size" invisible elements, and not much we can do there.

OTOH, like stadler suggests, we can provide a simple function to test if an element in fact hidden or not. I hesitate to add it to exiting functions dojo.contentBox() and dojo.marginBox()` because it is more bytes, and some slow-down. But it may be a good candidate for a stand-alone function in Dojo Core --- if you want to be extra sure, include and call it before "sizing".

comment:4 Changed 9 years ago by bill

Resolution: wontfix
Status: newclosed

Not sure what that function would do, whether just checking the specified node for computed style of display:none, or checking every ancestor too. In any case if we want that method it should be another ticket.

comment:5 in reply to:  4 Changed 9 years ago by Eugene Lazutkin

Replying to bill:

In any case if we want that method it should be another ticket.

Agreed.

comment:6 Changed 9 years ago by xMartin

Resolution: wontfix
Status: closedreopened

I understand that you don't want to handle the hidden case explicitly in these functions but I don't get how this is expected behavior. Returning -20 for the width of a node that's hidden seems plane wrong to me. As the browsers don't size it I'd expect it to return 0.

comment:7 Changed 9 years ago by bill

Would you feel better if we said that "the behavior is undefined when called on hidden nodes" rather than that it's expected behavior?

comment:8 Changed 9 years ago by bill

Resolution: wontfix
Status: reopenedclosed

Anyway, to answer your question, IIRC the reason it behaves that way (and the reason it's expected) is that a hidden node's border-box size is 0, and content-box size is calculated as border-box size minus the padding and border.

Note: See TracTickets for help on using tickets.