Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js

Issue 1879323003: Add IntersectionObserverEntry.intersectionRatio attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@2704
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/intersection-observer/multiple-thresholds.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Some of the js-test.js boilerplate will add stuff to the top of the document early 1 // Some of the js-test.js boilerplate will add stuff to the top of the document early
2 // enough to screw with frame offsets that are measured by the test. Delay all that 2 // enough to screw with frame offsets that are measured by the test. Delay all that
3 // jazz until the actual test code is finished. 3 // jazz until the actual test code is finished.
4 setPrintTestResultsLazily(); 4 setPrintTestResultsLazily();
5 self.jsTestIsAsync = true; 5 self.jsTestIsAsync = true;
6 6
7 function rectArea(rect) {
8 return (rect.left - rect.right) * (rect.bottom - rect.top);
9 }
10
7 function rectToString(rect) { 11 function rectToString(rect) {
8 return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bot tom + "]"; 12 return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bot tom + "]";
9 } 13 }
10 14
11 function entryToString(entry) { 15 function entryToString(entry) {
12 var ratio = ((entry.intersectionRect.width * entry.intersectionRect.height) / 16 var ratio = ((entry.intersectionRect.width * entry.intersectionRect.height) /
13 (entry.boundingClientRect.width * entry.boundingClientRect.height )); 17 (entry.boundingClientRect.width * entry.boundingClientRect.height ));
14 return ( 18 return (
15 "boundingClientRect=" + rectToString(entry.boundingClientRect) + "\n" + 19 "boundingClientRect=" + rectToString(entry.boundingClientRect) + "\n" +
16 "intersectionRect=" + rectToString(entry.intersectionRect) + "\n" + 20 "intersectionRect=" + rectToString(entry.intersectionRect) + "\n" +
17 "visibleRatio=" + ratio + "\n" + 21 "visibleRatio=" + ratio + "\n" +
18 "rootBounds=" + rectToString(entry.rootBounds) + "\n" + 22 "rootBounds=" + rectToString(entry.rootBounds) + "\n" +
19 "target=" + entry.target + "\n" + 23 "target=" + entry.target + "\n" +
20 "time=" + entry.time); 24 "time=" + entry.time);
21 } 25 }
26
27 function intersectionRatio(entry) {
28 var targetArea = rectArea(entry.boundingClientRect);
29 if (!targetArea)
30 return 0;
31 return rectArea(entry.intersectionRect) / targetArea;
32 }
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/intersection-observer/multiple-thresholds.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698