Skip to content

Change zoom behaviour so that it maintains the top left position of the document.#1

Open
KiyaDoig wants to merge 1 commit into
LUMIVERO:nvivo-masterfrom
KiyaDoig:zoom
Open

Change zoom behaviour so that it maintains the top left position of the document.#1
KiyaDoig wants to merge 1 commit into
LUMIVERO:nvivo-masterfrom
KiyaDoig:zoom

Conversation

@KiyaDoig

Copy link
Copy Markdown
  • Changes to the setZoomLevel function 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).
  • Tests

@peitschie

@peitschie
peitschie self-requested a review January 20, 2017 01:18
Comment thread webodf/lib/gui/ZoomHelper.js Outdated
var currentOffsetParent = offsetParent;
// Save the scroll ratios and related parent
while (currentOffsetParent) {
scrollRatios.push({ container: currentOffsetParent, scrollTop: currentOffsetParent.scrollTop / zoom,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
});

Comment thread webodf/lib/gui/ZoomHelper.js Outdated
scrollRatios.forEach(function(savedRatio) {
currentOffsetParent.scrollTop = savedRatio.scrollTop * zoom;
currentOffsetParent.scrollLeft = savedRatio.scrollLeft * zoom;
currentOffsetParent = currentOffsetParent.offsetParent;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable shouldn't be required now, as you should be using savedRatio.container

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duh :(

Comment thread webodf/tests/gui/ZoomHelperTests.js Outdated
};

function setupScrollPane(width, height) {
t.scrollPane.style.width = width + "px";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make these stateless factory methods (e.g., createScrollPane) rather than assigning to the test state like this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okies

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree you ought to just inline setupScrollPane into the setUp method 😄

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha ok, thanks.

Comment thread webodf/tests/gui/ZoomHelperTests.js Outdated
var zoom = 2;
t.zoomHelper.setZoomLevel(zoom);

r.shouldBe(t, "t.scrollPane.scrollTop", "100", 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread webodf/tests/gui/ZoomHelperTests.js Outdated
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also verify the top as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread webodf/tests/gui/ZoomHelperTests.js Outdated

r.shouldBe(t, "t.scrollPane.scrollTop", "100", 2);
r.shouldBe(t, "t.scrollPane.scrollLeft", "160", 2);
r.shouldBe(t, "redSquare.getBoundingClientRect().left", "9", 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread webodf/lib/gui/ZoomHelper.js Outdated
* @param {!number} zoomLevel
* @return {undefined}
*/
* Sets the zoom level of the document and maintains the top left position

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indent crept off here a bit?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

@KiyaDoig

Copy link
Copy Markdown
Author

Updated to address review feedback

Comment thread webodf/tests/gui/ZoomHelperTests.js Outdated
}

function setZoomLevel_Maintains_scroll_position_on_zoom_out() {
t.scrollPane.style.width = "100px";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you didn't put this in the setup?

@KiyaDoig KiyaDoig Jan 20, 2017

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah like have it default as that (in the setup) and the ones which need a different width set it there (in their test)?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep 😃

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok :P I'll do that

@KiyaDoig

Copy link
Copy Markdown
Author

Moved the width/height up to the set up

@peitschie peitschie left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍

Looks good to me! Will chat Monday about how this is integrated further into our build chains.

@KiyaDoig

Copy link
Copy Markdown
Author

Ok, thank you 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants