w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.35k stars 639 forks source link

[cssom-view] window.innerScreenX windows.innerScreenY #809

Open JanNorden opened 7 years ago

JanNorden commented 7 years ago

For the browser as such it is possible to obtain both the dimensions and the positon on the (operating system) screen area:

https://drafts.csswg.org/cssom-view/#dom-window-outerwidth https://drafts.csswg.org/cssom-view/#dom-window-outerheight https://drafts.csswg.org/cssom-view/#dom-window-screenx https://drafts.csswg.org/cssom-view/#dom-window-screenx

However, for the viewport it is only possible to obtain the dimensions, not the position:

https://drafts.csswg.org/cssom-view/#dom-window-innerwidth https://drafts.csswg.org/cssom-view/#dom-window-innerheight

The fact that the position is not available makes it impossible to translate coordinates on the screen to coordinates in the viewport.

I therefore propose the addition of corresponding innerScreenX and innerScreenY properties.

Since this translation is already performed by e.g. window.onMouseMove(), implementing the properties should not present any new technical or conceptual challenges.

The need arises when you get (OS) screen coordinates from some non-mouse source (in our particular case an gaze-tracking device), and want to relate them to the corresponding position in the displayed document.

There are non-standard implementations, e.g. mozInnerScreenX https://developer.mozilla.org/en-US/docs/Web/API/Window/mozInnerScreenX.

A previous request for another vendor-specific implementation was declined awaiting standardization https://bugs.chromium.org/p/chromium/issues/detail?id=151983 .

pbi-qfs commented 6 years ago

@frivoal Which kind of help is wanted for the proposal?

xckai commented 3 years ago

Same question, there is no "bridge" between HTML element's CSS position and system virtual screen position in chrome. In some scenery ,such as web automation, get HTML element's system virtual screen position is very usefull.

muodov commented 3 years ago

Just stumbled upon this problem, I described my use case here

@frivoal could you point in the direction of how to push this forward? Should I try to write some prose draft, or start with seeking implementers' attention first? 🙏🏻

ArkadiuszMichalski commented 3 years ago

Lack of this solution is extremely irritating, and from what I can see it takes years. I have had the same problem again https://github.com/w3c/csswg-drafts/issues/5814. What can we do to push it a little bit forward?

muodov commented 3 years ago

Note that in IE11 window.screenTop and window.screenLeft seem to be doing exactly this.

However, in modern engines (as well as the spec), those are just aliases to screenX/screenY, e.g. these commits (1, 2) in Blink/WebKit.

xfq commented 3 years ago

I think you can draft some text to explain:

The initial draft doesn't have to be super formal, and can be used to gather implementers' interest and guide spec writing.

muodov commented 3 years ago

@xfq Thank you for these pointers, it clarifies the process a bit :) I'll sketch something out

caoimhinsmo commented 2 years ago

I have been tearing my hair out looking for this feature too and eventually my searches led me to here. Specifically, I just want to be able to open a popup window (using window.open and hence using OS coordinates) above a particular empty box in the underlying document (hence identified by particular CSS coordinates) so that it will not block anything important from view. I am amazed that such a commonplace requirement is so complicated to implement. I need this for Multidict, a facility which I wrote at multidict.net which lets the user swop easily between various online dictionaries, putting the dictionary results in an iframe. More and more dictionaries though are setting HTTP SAMEORIGIN which prevents their results from appearing an iframe, so for these dictionaries I need to send the results to a popup window appearing above the div which would normally hold the iframe.

andreineculau commented 2 years ago

FWIW this is the best guessing game that I know of https://github.com/rokmoln/browser-coords

Somnium7 commented 3 months ago

Are there any plans for this? We need this too. Still can't be reliably detected in 2024...

killaragorn commented 2 months ago

+1

MatmaRex commented 1 month ago

Despite the deficiency in the spec, which I would also love to see fixed, there is actually a fairly reliable way to obtain the position of the viewport, which no one has mentioned so far in this thread. I found it mentioned in a few of the StackOverflow questions linked in #5814 (e.g. https://stackoverflow.com/a/28136985):

innerScreenX = mouseEvent.screenX - mouseEvent.clientX;
innerScreenY = mouseEvent.screenY - mouseEvent.clientY;

One obvious downside is that you need to obtain a MouseEvent to do this (e.g. from a click event), so for keyboard-only users, you'll need to fall back to window.screenX/window.screenY.

A less obvious downside is that on Chromium, the coordinate space of MouseEvent#screenX/Y uses device pixels, while MouseEvent#clientX/Y uses CSS pixels, so if the user has zoomed in or out, the result will be incorrect. On Firefox and in the draft spec they're both using CSS pixels. It is possible to work around this with a bit of additional effort though: please see my bug report at https://issues.chromium.org/issues/343009010 and the demo there for an example.