As with everywhere else we should be using the document rather than the window's viewports. Fixes #6467