Open Bug 397351 Opened 17 years ago Updated 2 years ago

layerX/layerY wrong when mouse is over scrollbar

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

1.9.2 Branch
x86
Linux
defect

Tracking

()

UNCONFIRMED

People

(Reporter: k, Unassigned)

References

()

Details

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9a9pre) Gecko/2007092404 Minefield/3.0a9pre
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9a9pre) Gecko/2007092404 Minefield/3.0a9pre

When you have a DIV with scrollbars (overflow:scroll or overflow:auto) and connect a mouse handler like "onmousemove" to the div then event.layerX must contain the X mouse position relative to the upper left corner of the DIV. But this doesn't work in Firefox when the mouse is over the scrollbar. Firefox "wraps" the mouse position so it begins with X=0 at the left edge of the scrollbar. This is bad because in this way Javascript cannot determine if the mouse is over the scrollbar or if the mouse is on the left side of the DIV. Here is a demo:

http://www.ailis.de/~k/permdata/20070903/scrollbar.html

Move the mouse over the div and then move it to the right over the scrollbar and watch the displayed X coordinate wrapping from 186 to 1. Other browsers behave correctly. Tested it in IE, Safari, Konqueror and Opera. In my opinion the mouse events should not fire at all when the mouse pointer is over the scrollbar but my opinion is not important. So I think this should be fixed so Firefox behaves like all other browsers and don't "wrap" the mouse position.

This problem occurs in current nightly build and current stable version on Linux and Windows.

Reproducible: Always

Steps to Reproduce:
1. Open 
http://www.ailis.de/~k/permdata/20070903/scrollbar.html
2. Move mouse cursor over scrollbar
3. Notice the wrong mouse position 
Actual Results:  
Mouse position which can be retrieved with layerX/layerY is wrong. X and Y should be somewhere between 180 and 200 but they are between 0 and 20.

Expected Results:  
X and Y position between 180 and 200 when mouse cursor is over scrollbar
By the way: This bug is still present in Firefox 3 Beta. Maybe this is a good time to finally fix it?
Does this still happen in firefox 3.6.6 or later in a fresh profile?
Whiteboard: [CLOSEME 2010-07-30]
Version: unspecified → 3.0 Branch
Yes, still happens in Firefox 3.6.6 with a fresh profile. The bug demo page is still online so everyone can try it out easily. Just click the link and move the mouse cursor over the scrollbars of the DIV and see the mouse position which is then not relative to the top/left corner of the DIV but instead relative to the top/left corner of the scrollbar.

I tried it now in Chrome, too: Works perfectly. Just to clarify: I don't know if there is any spec how a browser should work in this situation. So I don't know if this can be called a "bug". But the fact is that ALL browsers EXCEPT Firefox works the same. The mouse-position is always relative to the top/left corner, doesn't matter if mouse cursor is over the div, the scrollbars or the small square between the scrollbars. Firefox is the only browser which has a different opinion how mouse coordinates should be calculated.
Component: General → Event Handling
Product: Firefox → Core
QA Contact: general → events
Whiteboard: [CLOSEME 2010-07-30]
Version: 3.0 Branch → 1.9.2 Branch
This bug persists, lol. :\
This bug is still present in Firefox 20, and
http://www.ailis.de/~k/permdata/20070903/scrollbar.html
If you change the boder width, and put the mouse cursor on border-left and padding-left, the x will both be 0.
Component: Event Handling → User events and focus handling
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.