Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to find the absolute screen position of an element on a webpage.
I'm working on support for a video overlay on an embedded target. As this is an overlay, the video driver works with absolute screen positions. Webkit's underlying media player's paint method is called with coordinates that are relative to the web page. How can I take those relative coordinates and find the absolute screen coordinates?
Any help or direction is greatly appreciated.
@grheard QWebPageClient::mapToOwnerWindow() converts point from page coordinate system to coordinate system of QWindow where page belongs, then you can use QWindow::mapToGlobal to get it in absolute screen coordinates.
To use this approach you will have to add interface in WebCore (e.g. I named it PlatformPlayerClient), call it from your MediaPlayerPrivate implementation, and implement it in WebKit layer.
In Qt4 times I used simpler approach of accessing QWebView inside MediaPlayerPrivate via Document pointer (Document -> Frame -> FrameView -> HostWindow -> QWebPageClient -> ownerWidget), but I got rid if that because
- this is ugly layering violation
- it is not really compatible with separation of QtWebKitWidgets and QtWebKit libraries in Qt5
- it is principally incompatible with WebKit2
Thanks for the reply.
In Qt 5.5.1 qtwebkit, MediaPlayer->FrameView->HostWindow->screenToRootView(IntPoint) appears to return the absolute IntPoint on the screen. I'll need to perform a few more tests to be certain. It doesn't seem to violate the layering you mention because the call stays within WebCore and does not reach the webkit widget layer.
In Qt 5.5.1 qtwebkit, MediaPlayer->FrameView->HostWindow->screenToRootView(IntPoint) appears to return the absolute IntPoint on the screen.
Nevermind. This gives the absolute position on the page, but not the screen.
@grheard BTW, you may want to use QtWebKit TP5 with Qt 5.5.1. It may require you to adjust your player code, but it is much better compatible with modern web sites
@grheard BTW, simply accessing Document from MediaPlayer is considered a layering violation in modern WebKit (i.e. WebCore/platform and rest of WebCore are different layers). You should work with MediaPlayerClient only.