Change zoom behaviour so that it maintains the top left position of the document.#1
Change zoom behaviour so that it maintains the top left position of the document.#1KiyaDoig wants to merge 1 commit into
Conversation
| var currentOffsetParent = offsetParent; | ||
| // Save the scroll ratios and related parent | ||
| while (currentOffsetParent) { | ||
| scrollRatios.push({ container: currentOffsetParent, scrollTop: currentOffsetParent.scrollTop / zoom, |
There was a problem hiding this comment.
Minor, would generally have a line for each new container property when they don't all fit on the same line. And would do just a single indent. E.g.:
scrollRatios.push({
container: currentOffsetParent,
scrollTop: currentOffsetParent.scrollTop / zoom,
scrollLeft: currentOffsetParent.scrollLeft / zoom
});
| scrollRatios.forEach(function(savedRatio) { | ||
| currentOffsetParent.scrollTop = savedRatio.scrollTop * zoom; | ||
| currentOffsetParent.scrollLeft = savedRatio.scrollLeft * zoom; | ||
| currentOffsetParent = currentOffsetParent.offsetParent; |
There was a problem hiding this comment.
This variable shouldn't be required now, as you should be using savedRatio.container
| }; | ||
|
|
||
| function setupScrollPane(width, height) { | ||
| t.scrollPane.style.width = width + "px"; |
There was a problem hiding this comment.
I'd make these stateless factory methods (e.g., createScrollPane) rather than assigning to the test state like this.
There was a problem hiding this comment.
@peitschie so I have done this for the others like this:
function createInnerScrollPane(width, height) {
var innerScrollPane = document.createElement("div");
innerScrollPane.id = "innerScrollPane";
innerScrollPane.style.transformOrigin = "top left";
innerScrollPane.style.width = width + "px";
innerScrollPane.style.height = height + "px";
innerScrollPane.style.position = "relative";
innerScrollPane.style.overflow = "auto";
innerScrollPane.style.border = "1px solid green";
return innerScrollPane;
}
Is that what you meant?
But with this one (createScrollPane) would I remove the scrollPane from the setUp method or?
There was a problem hiding this comment.
I agree you ought to just inline setupScrollPane into the setUp method 😄
| var zoom = 2; | ||
| t.zoomHelper.setZoomLevel(zoom); | ||
|
|
||
| r.shouldBe(t, "t.scrollPane.scrollTop", "100", 2); |
There was a problem hiding this comment.
I'd suggest a class const for 2 in this test file, as it seems on initial glance like this is somehow related to the zoom levels.
| t.zoomHelper.setZoomLevel(zoom); | ||
|
|
||
| r.shouldBe(t, "t.scrollPane.scrollTop", "12", 2); | ||
| r.shouldBe(t, "redSquare.getBoundingClientRect().left", "28", 2); // Zoomed out such that horizontal scroll is removed. |
|
|
||
| r.shouldBe(t, "t.scrollPane.scrollTop", "100", 2); | ||
| r.shouldBe(t, "t.scrollPane.scrollLeft", "160", 2); | ||
| r.shouldBe(t, "redSquare.getBoundingClientRect().left", "9", 2); |
There was a problem hiding this comment.
Might I suggest checking this in relation to the scroll BCR (bounding client rect), as you really want to assert that this is close to the top-left-most visible region of the scroll BCR in all cases, right? Applies to all other tests below
| * @param {!number} zoomLevel | ||
| * @return {undefined} | ||
| */ | ||
| * Sets the zoom level of the document and maintains the top left position |
|
Updated to address review feedback |
| } | ||
|
|
||
| function setZoomLevel_Maintains_scroll_position_on_zoom_out() { | ||
| t.scrollPane.style.width = "100px"; |
There was a problem hiding this comment.
Any reason you didn't put this in the setup?
There was a problem hiding this comment.
Ah like have it default as that (in the setup) and the ones which need a different width set it there (in their test)?
|
Moved the width/height up to the set up |
peitschie
left a comment
There was a problem hiding this comment.
👍 👍
Looks good to me! Will chat Monday about how this is integrated further into our build chains.
|
Ok, thank you 😸 |
setZoomLevelfunction to maintain the scroll position in the document (meaning the line of content at the top of the page is maintained at the top when you zoom).@peitschie