Discussion:
Browser scrollbar position, left or right?
Quicksaver
2014-01-25 13:40:10 UTC
Permalink
Hi everyone, I was hoping someone could help me with a kind of a big
problem I just can't figure out.

I need to know, for my add-on, whether the scrollbar of a tab is on the
right or on the left of the window. If the preference
layout.scrollbar.side is 2 (right) or 3 (left) that is easy of course.

But if it is 1 (content) I'm having doubts about how I'm doing it
currently, as I'm just checking for contentDocument.documentElement.dir
== 'rtl' of each browser and I'm not sure if that gives me reliable
results 100% of the time.

And the biggest problem I have is when the pref is 0 (browser UI,
default). I have no idea of what I should be checking for in this case.
All of the methods in the Services.locale object can somehow be tricked
into returning one of the rtl locales by changing my OS settings, and
still keep the scrollbar on the right. In addition, I can also keep the
scrollbar on the right even when using a rtl localization of firefox.
Thus, pretty much every check I've come up with returns the rtl locale
"correctly", despite the location of the scrollbar still being on the right.

So, does anyone know of any way to always accurately get the location of
the scrollbar? Maybe I'm missing something really simple and obvious,
but like I said, I just can't figure it out. I'd really appreciate any
kind of help with this.

Luís Miguel
Mike Ratcliffe
2014-01-27 10:23:27 UTC
Permalink
You could just get the boundingClientRect of the scrollbar and work it
out from there... there is probably a much more elegant way though, somehow.
Post by Quicksaver
Hi everyone, I was hoping someone could help me with a kind of a big
problem I just can't figure out.
I need to know, for my add-on, whether the scrollbar of a tab is on
the right or on the left of the window. If the preference
layout.scrollbar.side is 2 (right) or 3 (left) that is easy of course.
But if it is 1 (content) I'm having doubts about how I'm doing it
currently, as I'm just checking for
contentDocument.documentElement.dir == 'rtl' of each browser and I'm
not sure if that gives me reliable results 100% of the time.
And the biggest problem I have is when the pref is 0 (browser UI,
default). I have no idea of what I should be checking for in this
case. All of the methods in the Services.locale object can somehow be
tricked into returning one of the rtl locales by changing my OS
settings, and still keep the scrollbar on the right. In addition, I
can also keep the scrollbar on the right even when using a rtl
localization of firefox. Thus, pretty much every check I've come up
with returns the rtl locale "correctly", despite the location of the
scrollbar still being on the right.
So, does anyone know of any way to always accurately get the location
of the scrollbar? Maybe I'm missing something really simple and
obvious, but like I said, I just can't figure it out. I'd really
appreciate any kind of help with this.
Luís Miguel
_______________________________________________
firefox-dev mailing list
https://mail.mozilla.org/listinfo/firefox-dev
Quicksaver
2014-01-27 11:20:45 UTC
Permalink
I don't think there is any actual scrollbar element in the DOM tree that
I can call getBoundingClientRect() on (is there?). At least I've looked
all over, more than once now, and couldn't find anything of the sort.
Post by Mike Ratcliffe
You could just get the boundingClientRect of the scrollbar and work it
out from there... there is probably a much more elegant way though, somehow.
_______________________________________________
firefox-dev mailing list
https://mail.mozilla.org/listinfo/firefox-dev
Ehsan Akhgari
2014-01-27 19:06:13 UTC
Permalink
Post by Quicksaver
Hi everyone, I was hoping someone could help me with a kind of a big
problem I just can't figure out.
I need to know, for my add-on, whether the scrollbar of a tab is on the
right or on the left of the window. If the preference layout.scrollbar.side
is 2 (right) or 3 (left) that is easy of course.
But if it is 1 (content) I'm having doubts about how I'm doing it
currently, as I'm just checking for contentDocument.documentElement.dir
== 'rtl' of each browser and I'm not sure if that gives me reliable results
100% of the time.
And the biggest problem I have is when the pref is 0 (browser UI,
default). I have no idea of what I should be checking for in this case. All
of the methods in the Services.locale object can somehow be tricked into
returning one of the rtl locales by changing my OS settings, and still keep
the scrollbar on the right. In addition, I can also keep the scrollbar on
the right even when using a rtl localization of firefox. Thus, pretty much
every check I've come up with returns the rtl locale "correctly", despite
the location of the scrollbar still being on the right.
So, does anyone know of any way to always accurately get the location of
the scrollbar? Maybe I'm missing something really simple and obvious, but
like I said, I just can't figure it out. I'd really appreciate any kind of
help with this.
The behavior of this pref is implemented in
ScrollFrameHelper::IsScrollbarOnRight (
http://mxr.mozilla.org/mozilla-central/source/layout/generic/nsGfxScrollFrame.cpp#3498).
In short, for non-root scroll frames or for a value of 1, then we determine
the scrollbar side based on the directionality of the element (or the
documentElement for the top-level scrollbar), for a value of 0 we look at
the value of the bidi.direction pref, 2 means always right, and 3 means
always left.

None of this should depend on your system locale direction.

I think the best way to do what you want is to port this behavior in your
add-on JS code.

Cheers,
--
Ehsan
<http://ehsanakhgari.org/>

Loading...