Closed Bug 375519 Opened 17 years ago Closed 17 years ago

window.innerWidth/Height units

Categories

(Core :: DOM: Core & HTML, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: mpgritti, Assigned: sharparrow1)

References

Details

Attachments

(1 file, 1 obsolete file)

window.innerWidth/Height are currently returned in device pixels rather than in CSS pixels.

On high DPI screens this breaks sites like google maps or gtalk which use window.innerWidth/Height to adapt divs position/size to the browser window.

Is there a reason for this behavior or is it just a bug?

(screen.width and screen.height are returned in CSS pixels)
Just a bug; high DPI hasn't been getting much testing.

Probably just need to add a bit of code to nsGlobalWindow::Get/SetInnerWidth/Height to grab a prescontext and do something like presContext::AppUnitsToIntCSSPixels(presContext->DevPixelsToAppUnits(width)); it's a bit messy, but pretty straightforward.  The prescontext can be obtained from nsIDocShell.

I'll put together a patch soon.
Assignee: general → sharparrow1
Something like this?
Attachment #259996 - Flags: review?
Attachment #259996 - Flags: review? → review?(sharparrow1)
(In reply to comment #3)
> Created an attachment (id=259996) [details]
> Convert between device and css pixels for window.InnerWidth/Height
> 
> Something like this?

Looks good.  Just to be on the safe side, though, I'd null-check mDocShell. I'm not quite sure when it can be null.
Attachment #259996 - Attachment is obsolete: true
Attachment #259996 - Flags: review?(sharparrow1)
I used NS_ENSURE_STATE(mDocShell)... From what I can tell looking at nsDocShell.cpp this is an unexpected state. Also we are doing the same in GlobalWindow::Prompt. Make sense?
Attachment #260139 - Flags: review?(sharparrow1)
Comment on attachment 260139 [details] [diff] [review]
Checks for mDocShell

NS_ENSURE_STATE is fine.
Attachment #260139 - Flags: superreview?(roc)
Attachment #260139 - Flags: review?(sharparrow1)
Attachment #260139 - Flags: review+
Attachment #260139 - Flags: superreview?(roc) → superreview+
[marco@localhost mozilla]$ cvs commit dom/src/base/nsGlobalWindow.cpp
Checking in dom/src/base/nsGlobalWindow.cpp;
/cvsroot/mozilla/dom/src/base/nsGlobalWindow.cpp,v  <--  nsGlobalWindow.cpp
new revision: 1.919; previous revision: 1.918
done
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
For the record, this caused bug 400204.
Component: DOM: Core → DOM: Core & HTML
QA Contact: ian → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: