Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1099 from atomiks/fix/root
- Loading branch information
Showing
2 changed files
with
30 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,36 @@ | ||
// @flow | ||
import type { Rect } from '../types'; | ||
import getDocumentElement from './getDocumentElement'; | ||
import getComputedStyle from './getComputedStyle'; | ||
import getWindowScrollBarX from './getWindowScrollBarX'; | ||
import getWindowScroll from './getWindowScroll'; | ||
|
||
// Gets the entire size of the scrollable document area, even extending outside | ||
// of the `<html>` and `<body>` rect bounds if horizontally scrollable | ||
export default function getDocumentRect(element: HTMLElement): Rect { | ||
const winScroll = getWindowScroll(element); | ||
const html = getDocumentElement(element); | ||
const winScroll = getWindowScroll(element); | ||
const body = element.ownerDocument.body; | ||
|
||
const width = Math.max(html.clientWidth, body ? body.clientWidth : 0); | ||
const height = Math.max(html.clientHeight, body ? body.clientHeight : 0); | ||
const x = -winScroll.scrollLeft; | ||
const width = Math.max( | ||
html.scrollWidth, | ||
html.clientWidth, | ||
body ? body.scrollWidth : 0, | ||
body ? body.clientWidth : 0 | ||
); | ||
const height = Math.max( | ||
html.scrollHeight, | ||
html.clientHeight, | ||
body ? body.scrollHeight : 0, | ||
body ? body.clientHeight : 0 | ||
); | ||
|
||
let x = -winScroll.scrollLeft + getWindowScrollBarX(element); | ||
const y = -winScroll.scrollTop; | ||
|
||
if (getComputedStyle(body || html).direction === 'rtl') { | ||
x += Math.max(html.clientWidth, body ? body.clientWidth : 0) - width; | ||
} | ||
|
||
return { width, height, x, y }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters