Closed
Bug 919437
Opened 11 years ago
Closed 11 years ago
js window.innerWidth doesn't update when zooming on Nexus 10
Categories
(Core :: Layout, defect)
Tracking
()
RESOLVED
FIXED
mozilla27
People
(Reporter: ray.shanley, Assigned: kats)
References
Details
Attachments
(3 files, 1 obsolete file)
(deleted),
text/html
|
Details | |
(deleted),
patch
|
roc
:
review+
tnikkel
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
roc
:
review+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36
Steps to reproduce:
I wrote some JavaScript to calculate the current zoom factor. The code is as follows:
var zoomFactor = window.devicePixelRatio * screen.width / window.innerWidth;
Tested with Firefox 25 beta.
Actual results:
window.innerWidth stays the same all the time - 980px
Expected results:
The more you zoom the lower the value for window.innerWidth. Works in other browsers on Nexus 10 (Chrome, Opera, ...).
Reporter | ||
Updated•11 years ago
|
Severity: normal → major
OS: Windows 7 → Android
Hardware: x86_64 → ARM
Comment 1•11 years ago
|
||
Please test against trunk. htts://nightly.mozilla.org
Flags: needinfo?(ray.shanley)
Assignee | ||
Comment 2•11 years ago
|
||
I can repro as well. Is there a spec that you can point to as to what window.innerWidth is actually supposed to be in this case? I was under the impression it's the CSS viewport width so in that case what we return for that is correct.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Reporter | ||
Comment 3•11 years ago
|
||
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #2)
> Is there a spec that you can point to
Not really a spec as such but take a look at the section "Calculate zoom level" on this page: http://www.quirksmode.org/mobile/tableViewport.html
Flags: needinfo?(ray.shanley)
Reporter | ||
Comment 4•11 years ago
|
||
(In reply to Kevin Brosnan [:kbrosnan] from comment #1)
> Please test against trunk. htts://nightly.mozilla.org
I have now done so. It is the same behaviour. Whether I have maximum zoom or minimum zoom (or anywhere in between) the values are as follows:
window.devicePixelRatio -> 2
screen.width -> 1280
window.innerWidth -> 980
Assignee | ||
Comment 5•11 years ago
|
||
Matt, do you know if window.innerWidth is specced anywhere? According to the quirksmode article in comment 3 most browsers seem to return the size of the visual viewport whereas we return the layout viewport. Not sure which is more correct, and what will break if we switch.
Flags: needinfo?(mbrubeck)
Comment 6•11 years ago
|
||
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #5)
> Matt, do you know if window.innerWidth is specced anywhere?
As far as I know it is not specified anywhere. PPK has collected some info on how various mobile browsers behave:
http://www.quirksmode.org/mobile/tableViewport.html#t01
http://www.quirksmode.org/blog/archives/2012/10/mobile_viewport.html
Flags: needinfo?(mbrubeck)
Reporter | ||
Comment 7•11 years ago
|
||
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #5)
> Not sure which is more correct, and what will break if we switch.
If you do not want to change window.innerWidth can you make available a different way to calculate the current zoom factor?
Assignee | ||
Comment 8•11 years ago
|
||
(In reply to Ray Shanley from comment #7)
> If you do not want to change window.innerWidth can you make available a
> different way to calculate the current zoom factor?
I would rather try to change window.innerWidth first, so that we are consistent with the de-facto standard. This bug probably is more appropriate in Layout since it affects the GetInnerWidth and GetInnerHeight functions that are implemented in layout. They should return the size of the scroll-clamping scroll-port size if there is one.
We will also need to audit all uses of window.innerWidth in our own code to make sure they do not break.
Component: Graphics, Panning and Zooming → Layout
Product: Firefox for Android → Core
Version: Firefox 25 → 25 Branch
Assignee | ||
Comment 9•11 years ago
|
||
Btw, I think this bug will also affect B2G and Metro.
Assignee | ||
Comment 10•11 years ago
|
||
So the current implementation of GetInnerWidth and GetInnerHeight end up returning the size as obtained by nsPresContext->GetVisibleArea. The docs for that function sound like they should match the desired behaviour in this bug, but clearly the function is not actually returning that value.
:tn, do you know if it makes sense to change what GetVisibleArea returns to take into account the resolution, or if it's better to just change nsGlobalWindow::GetInnerSize() to also check the ScrollPositionClampingScrollPortSize if there is one?
Flags: needinfo?(tnikkel)
Comment 11•11 years ago
|
||
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #10)
> So the current implementation of GetInnerWidth and GetInnerHeight end up
> returning the size as obtained by nsPresContext->GetVisibleArea. The docs
> for that function sound like they should match the desired behaviour in this
> bug, but clearly the function is not actually returning that value.
The docs were written before mobile stuff came around (or the docs didn't take that into account). The visible area is the layout size of the document, the css viewport size. It is the size that the document will be reflowed into. I think the visible area has the correct value, just the description of it is not clear.
> :tn, do you know if it makes sense to change what GetVisibleArea returns to
> take into account the resolution, or if it's better to just change
> nsGlobalWindow::GetInnerSize() to also check the
> ScrollPositionClampingScrollPortSize if there is one?
So probably changing the inner size getter is the way to go given what I said above.
Flags: needinfo?(tnikkel)
Assignee | ||
Comment 12•11 years ago
|
||
Zooming in and clicking the button should report different sizes. If you zoom it so that exactly three boxes fit on the screen then the alert dialog should report 300.
Assignee | ||
Comment 13•11 years ago
|
||
This makes the test case work correctly, but will probably break a bunch of stuff because of how we use innerWidth and innerHeight in our code.
https://tbpl.mozilla.org/?tree=Try&rev=d6a200ca51d2
Assignee | ||
Comment 14•11 years ago
|
||
That was a surprisingly clean try run. And it turns out Fennec code only uses innerWidth in a couple of places in reader mode. I exercised those pieces of code and they behave fine. And in B2G the only presshell that will (at least right now) have the ScrollPositionClampingScrollPortSize set will the browser content presshell, and that also seems to be ok. So this patch might actually not break much (fingers crossed).
Assignee | ||
Updated•11 years ago
|
Attachment #810977 -
Flags: review?(tnikkel)
Attachment #810977 -
Flags: review?(roc)
Comment 15•11 years ago
|
||
Comment on attachment 810977 [details] [diff] [review]
Patch
The FlushDelayedResize call there is only to make sure that the visible area on the prescontext is up to date. So I would do that only if we are using the visible area. Otherwise looks good.
Assignee | ||
Comment 16•11 years ago
|
||
Updated per :tn's comment above
Assignee: nobody → bugmail.mozilla
Attachment #810977 -
Attachment is obsolete: true
Attachment #810977 -
Flags: review?(tnikkel)
Attachment #810977 -
Flags: review?(roc)
Attachment #811269 -
Flags: review?(tnikkel)
Attachment #811269 -
Flags: review?(roc)
Updated•11 years ago
|
Attachment #811269 -
Flags: review?(tnikkel) → review+
Comment on attachment 811269 [details] [diff] [review]
Patch v2
Review of attachment 811269 [details] [diff] [review]:
-----------------------------------------------------------------
Could use a test
Attachment #811269 -
Flags: review?(roc) → review+
Assignee | ||
Comment 18•11 years ago
|
||
One Linux reinstall later, I have a test! Works locally on my Android device, pending try run at https://tbpl.mozilla.org/?tree=Try&rev=a2071162265f
Attachment #812371 -
Flags: review?(roc)
Comment on attachment 812371 [details] [diff] [review]
Test
Review of attachment 812371 [details] [diff] [review]:
-----------------------------------------------------------------
!
Attachment #812371 -
Flags: review?(roc) → review+
Assignee | ||
Comment 20•11 years ago
|
||
I see bustage on inbound so flagging as checkin-needed rather than piling on top.
Keywords: checkin-needed
Assignee | ||
Comment 21•11 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/7e8f946d0d1a
https://hg.mozilla.org/integration/mozilla-inbound/rev/47451aa820b8
Keywords: checkin-needed
Comment 22•11 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/7e8f946d0d1a
https://hg.mozilla.org/mozilla-central/rev/47451aa820b8
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla27
Reporter | ||
Comment 23•11 years ago
|
||
I've tried it out on the Nexus 10 with the nightly build (27.0a1 2013-10-02) but the value for window.innerWidth is still 980 same as before. Is the change already in that nightly build?
Assignee | ||
Comment 24•11 years ago
|
||
It should be in today's nightly build (Oct 03).
Reporter | ||
Comment 25•11 years ago
|
||
Thank you - I've now tested it and 'window.innerWidth' works perfectly. 'window.innerHeight' also works better but there still seems to be a small problem with innerHeight as follows. When the zoom is greater than the minimum and the address bar is visible, 'window.innerHeight' is too large i.e. the height of the address bar is not subtracted from the total height. I've opened a new bug for that: bug 923663.
Updated•6 years ago
|
You need to log in
before you can comment on or make changes to this bug.
Description
•