[cssom-view] scrollMaxX/Y

Web authors want to detect when scrollable elements can be scrolled in a
given direction,
e.g.http://stackoverflow.com/questions/2059743/detect-elements-overflow-using-jquery
http://stackoverflow.com/questions/4369990/scrollheight-property-in-firefox
Often this means knowing what the maximum value is for
scrollLeft/scrollTop. You can estimate this using scrollWidth - clientWidth
and scrollHeight - clientHeight, but that can give a slightly wrong answer
due to rounding if you're doing subpixel layout. For example, an element
whose unrounded clientHeight is 1.4px and unrounded scrollHeight is 1.6px
would compute scrollWidth - clientWidth = 1 although in fact scrollTop's
maximum value is 0 (actually, whether scrollTop's maximum value is 0 or 1
depends on how the UA handles scrolling with subpixel rendering, but 0 is a
reasonable choice).

It would be simpler and less error-prone to simply have a DOM attribute
that returns the maximum values for scrollLeft/scrollTop. For the viewport,
Gecko has supported window.scrollMaxX/Y for a long time, but no-one else
has this as far as I know.

I propose adding scrollMaxX and scrollMaxY as read-only DOM attributes on
Element, returning the maximum possible values for scrollLeft and scrollTop
respectively. They would of course be 0 for non-scrollable elements.

For the bikeshedders out there, I think scrollLeftMax and scrollTopMax
would also be acceptable names.

Rob
-- 
“You have heard that it was said, ‘Love your neighbor and hate your enemy.’
But I tell you, love your enemies and pray for those who persecute you,
that you may be children of your Father in heaven. ... If you love those
who love you, what reward will you get? Are not even the tax collectors
doing that? And if you greet only your own people, what are you doing more
than others?" [Matthew 5:43-47]

Received on Thursday, 21 June 2012 23:54:40 UTC