Skip to content

Commit

Permalink
the window scroller now supports iframes
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianDavideConte committed Jan 9, 2024
1 parent b41c2ca commit 0b070a8
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 73 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/calcBordersDimensions-tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("calcBordersDimensions", function() {
const _windowBordersDimensions = uss.calcBordersDimensions(win, true);
expect(constants.arraysAreEqual(
_windowBordersDimensions,
uss.calcBordersDimensions(uss.getWindowScroller(true))
uss.calcBordersDimensions(uss.getWindowScroller(win, true))
)
).to.be.true;

Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/calcScrollbarsDimensions-tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("calcScrollbarsDimensions", function() {
const _windowScrollbarsDimensions = uss.calcScrollbarsDimensions(win, true);
expect(constants.arraysAreEqual(
_windowScrollbarsDimensions,
uss.calcScrollbarsDimensions(uss.getWindowScroller(true))
uss.calcScrollbarsDimensions(uss.getWindowScroller(win, true))
)
).to.be.true;

Expand Down Expand Up @@ -74,7 +74,7 @@ describe("calcScrollbarsDimensions", function() {
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXAxis), [_maxDim,0])).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheYAxis), [0,_maxDim])).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes), [_maxDim,_maxDim])).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(uss.getWindowScroller()),
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(uss.getWindowScroller(win)),
uss.calcScrollbarsDimensions(win))
).to.be.true;

Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/calcXScrollbarDimension-tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("calcXScrollbarDimension", function() {

//Test the window's x-scrollbar.
const _windowXScrollbarDimension = uss.calcXScrollbarDimension(win, true);
expect(_windowXScrollbarDimension).to.equal(uss.calcXScrollbarDimension(uss.getWindowScroller(true)));
expect(_windowXScrollbarDimension).to.equal(uss.calcXScrollbarDimension(uss.getWindowScroller(win, true)));

const _windowXScrollbarCachedDimension = uss._containersData.get(win)[constants.K_VSB];
expect(_windowXScrollbarDimension).to.equal(_windowXScrollbarCachedDimension);
Expand Down Expand Up @@ -63,7 +63,7 @@ describe("calcXScrollbarDimension", function() {
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXAxis)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheYAxis)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(uss.getWindowScroller())).to.equal(uss.calcXScrollbarDimension(win));
expect(uss.calcXScrollbarDimension(uss.getWindowScroller(win))).to.equal(uss.calcXScrollbarDimension(win));

//Test if the scroll positions have changed due to the measuring (they should not).
expect(constants.arraysAreEqual(_getCurrentScrollPos(win), _windowOriginalPos)).to.be.true;
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/calcYScrollbarDimension-tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("calcYScrollbarDimension", function() {

//Test the window's y-scrollbar.
const _windowYScrollbarDimension = uss.calcYScrollbarDimension(win, true);
expect(_windowYScrollbarDimension).to.equal(uss.calcYScrollbarDimension(uss.getWindowScroller(true)));
expect(_windowYScrollbarDimension).to.equal(uss.calcYScrollbarDimension(uss.getWindowScroller(win, true)));

const _windowYScrollbarCachedDimension = uss._containersData.get(win)[constants.K_HSB];
expect(_windowYScrollbarDimension).to.equal(_windowYScrollbarCachedDimension);
Expand Down Expand Up @@ -63,7 +63,7 @@ describe("calcYScrollbarDimension", function() {
expect(uss.calcYScrollbarDimension(_elementWithScrollbarOnTheXAxis)).to.equal(0);
expect(uss.calcYScrollbarDimension(_elementWithScrollbarOnTheYAxis)).to.equal(_maxDim);
expect(uss.calcYScrollbarDimension(_elementWithScrollbarOnTheXYAxes)).to.equal(_maxDim);
expect(uss.calcYScrollbarDimension(uss.getWindowScroller())).to.equal(uss.calcYScrollbarDimension(win));
expect(uss.calcYScrollbarDimension(uss.getWindowScroller(win))).to.equal(uss.calcYScrollbarDimension(win));

//Test if the scroll positions have changed due to the measuring (they should not).
expect(constants.arraysAreEqual(_getCurrentScrollPos(win), _windowOriginalPos)).to.be.true;
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/getMaxScrollX-tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe("getMaxScrollX", function() {
const _expectedMaxScrollX = 0.5 * _testElement.scrollWidth + uss.getScrollbarsMaxDimension();

//Test the Window
expect(uss.getMaxScrollX(win, false)).to.equal(uss.getMaxScrollX(uss.getWindowScroller(), false));
expect(uss.getMaxScrollX(win, true)).to.equal(uss.getMaxScrollX(uss.getWindowScroller(), true));
expect(uss.getMaxScrollX(win, false)).to.equal(uss.getMaxScrollX(uss.getWindowScroller(win), false));
expect(uss.getMaxScrollX(win, true)).to.equal(uss.getMaxScrollX(uss.getWindowScroller(win), true));

expect(Number.isFinite(uss.getMaxScrollX(_testElement, true))).to.be.true;
expect(Number.isFinite(uss.getMaxScrollX(_testElement, false))).to.be.true;
Expand All @@ -47,8 +47,8 @@ describe("getMaxScrollX", function() {
uss.stopScrolling(_testElement);
uss.stopScrollingAll();
expect(uss.getMaxScrollX(_testElement, false)).to.be.closeTo(_expectedMaxScrollX, 1);
expect(uss.getMaxScrollX(win, false)).to.equal(uss.getMaxScrollX(uss.getWindowScroller(), false));
expect(uss.getMaxScrollX(win, true)).to.equal(uss.getMaxScrollX(uss.getWindowScroller(), true));
expect(uss.getMaxScrollX(win, false)).to.equal(uss.getMaxScrollX(uss.getWindowScroller(win), false));
expect(uss.getMaxScrollX(win, true)).to.equal(uss.getMaxScrollX(uss.getWindowScroller(win), true));
});
});
});
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/getMaxScrollY-tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe("getMaxScrollY", function() {
const _expectedMaxScrollY = 0.5 * _testElement.scrollHeight + uss.getScrollbarsMaxDimension();

//Test the Window
expect(uss.getMaxScrollY(win, false)).to.equal(uss.getMaxScrollY(uss.getWindowScroller(), false));
expect(uss.getMaxScrollY(win, true)).to.equal(uss.getMaxScrollY(uss.getWindowScroller(), true));
expect(uss.getMaxScrollY(win, false)).to.equal(uss.getMaxScrollY(uss.getWindowScroller(win), false));
expect(uss.getMaxScrollY(win, true)).to.equal(uss.getMaxScrollY(uss.getWindowScroller(win), true));

expect(Number.isFinite(uss.getMaxScrollY(_testElement), true)).to.be.true;
expect(Number.isFinite(uss.getMaxScrollY(_testElement), false)).to.be.true;
Expand All @@ -47,8 +47,8 @@ describe("getMaxScrollY", function() {
uss.stopScrolling(_testElement);
uss.stopScrollingAll();
expect(uss.getMaxScrollY(_testElement, false)).to.be.closeTo(_expectedMaxScrollY, 1);
expect(uss.getMaxScrollY(win, false)).to.equal(uss.getMaxScrollY(uss.getWindowScroller(), false));
expect(uss.getMaxScrollY(win, true)).to.equal(uss.getMaxScrollY(uss.getWindowScroller(), true));
expect(uss.getMaxScrollY(win, false)).to.equal(uss.getMaxScrollY(uss.getWindowScroller(win), false));
expect(uss.getMaxScrollY(win, true)).to.equal(uss.getMaxScrollY(uss.getWindowScroller(win), true));
});
});
});
Expand Down
16 changes: 8 additions & 8 deletions cypress/e2e/getMaxScrolls-tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ describe("getMaxScrolls", function() {
const _expectedMaxScrollY = 0.5 * _testElement.scrollHeight + uss.getScrollbarsMaxDimension();

//Test the Window
expect(uss.getMaxScrolls(win, false)[0]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(), false)[0]);
expect(uss.getMaxScrolls(win, false)[1]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(), false)[1]);
expect(uss.getMaxScrolls(win, true)[0]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(), true)[0]);
expect(uss.getMaxScrolls(win, true)[1]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(), true)[1]);
expect(uss.getMaxScrolls(win, false)[0]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(win), false)[0]);
expect(uss.getMaxScrolls(win, false)[1]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(win), false)[1]);
expect(uss.getMaxScrolls(win, true)[0]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(win), true)[0]);
expect(uss.getMaxScrolls(win, true)[1]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(win), true)[1]);

expect(Number.isFinite(uss.getMaxScrolls(_testElement, true)[0])).to.be.true;
expect(Number.isFinite(uss.getMaxScrolls(_testElement, true)[1])).to.be.true;
Expand Down Expand Up @@ -63,10 +63,10 @@ describe("getMaxScrolls", function() {
uss.stopScrollingAll();
expect(uss.getMaxScrolls(_testElement, false)[0]).to.be.closeTo(_expectedMaxScrollX, 1);
expect(uss.getMaxScrolls(_testElement, false)[1]).to.be.closeTo(_expectedMaxScrollY, 1);
expect(uss.getMaxScrolls(win, false)[0]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(), false)[0]);
expect(uss.getMaxScrolls(win, false)[1]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(), false)[1]);
expect(uss.getMaxScrolls(win, true)[0]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(), true)[0]);
expect(uss.getMaxScrolls(win, true)[1]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(), true)[1]);
expect(uss.getMaxScrolls(win, false)[0]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(win), false)[0]);
expect(uss.getMaxScrolls(win, false)[1]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(win), false)[1]);
expect(uss.getMaxScrolls(win, true)[0]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(win), true)[0]);
expect(uss.getMaxScrolls(win, true)[1]).to.equal(uss.getMaxScrolls(uss.getWindowScroller(win), true)[1]);
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/getWindowScroller-tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ describe("getWindowScroller", function() {
win.scroll(100, 100);

if(_htmlResetCorrectly && _hasSameCoordinatesAsWindow(_html)) {
expect(uss.getWindowScroller()).to.equal(_html);
expect(uss.getWindowScroller(win)).to.equal(_html);
} else if(_bodyResetCorrectly && _hasSameCoordinatesAsWindow(_body)) {
expect(uss.getWindowScroller()).to.equal(_body);
expect(uss.getWindowScroller(win)).to.equal(_body);
} else {
expect(uss.getWindowScroller()).to.equal(win);
expect(uss.getWindowScroller(win)).to.equal(win);
}
});
});
Expand Down
6 changes: 6 additions & 0 deletions src/main/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ export const K_MCBQ = 32;
*/
export const K_FGS = 33;

/**
* Key to get the element that scrolls a window (its window scroller).
*/
export const K_WDS = 34;




/**
Expand Down
Loading

0 comments on commit 0b070a8

Please sign in to comment.