Closed Bug 548005 Opened 14 years ago Closed 9 years ago

Browser zoom should stay centered when coordinates are available

Categories

(Core :: DOM: Navigation, defect)

x86
All
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1180706

People

(Reporter: Felipe, Unassigned)

References

Details

Attachments

(1 file, 1 obsolete file)

When using Ctrl+Scrollwheel or the pinch gesture in touchscreens/Macbook's trackpad, the zoomed page should remain centered on the mouse position/center of the gesture
Defined how, exactly?  Note that zoom doesn't pixel-zoom but rather performs a relayout.
Hmm, interesting.. conceptually it's easy to define (thinking about a pixel-zoom like in Fennec), but in practice it's tougher indeed.

Maybe just ensuring that the element in the center of the zoom remains visible? Or some other calculations between the ratio distance to the top of the page before and after the zooming occurs.
Well, for a pixel-zoom defining it is trivial.  The whole point is that we're not talking pixel-zoom.
Blocks: 548100
okay, I did some research on this I think I have a plan to try it:

- the events that trigger zoom (such as ctrl + mousewheel or a zoom gesture) already come with target node and coordinates info, which is just ignored. This info needs to be passed to the FullZoom object from browser-fullzoom.js.
- after FullZoom.enlarge is called, if the target node info is available, check to see if the node is still visible using its getBoundingClientRect info
- if the node is not visible, scrollIntoView it (or use window.scrollTo)

This is to make it possible to keep the element visible without having to pass the element's info deep down to the layout code that does the actual zooming 

Ideally, we'd use something better than scrollIntoView or scrollTo, such as presshell's ScrollFrameRectIntoView, because:
 - scrollIntoView provides small control of the positions for the actual function it is calling, ScrollContentIntoView.  Alternatively we can use window.scrollTo and calculate by ourselves the scrolling offsets
 - both scrollIntoView and ScrollTo flushes the layout that has just been flushed by the zooming procedure

If reflushing the layout is not a problem (because nothing probably changed and it will run quickly) we can use one of the two above and see how well (or not) the behavior ends up to be.  Otherwise I might look into exposing ScrollFrameRectIntoView somehow to be called.

Boris, any opinion on this?
Attached patch WIP v1 (obsolete) (deleted) — Splinter Review
First version, work in progress

At the moment it only works with ctrl+mousewhell, but the next step is to make it work with pinch.

I used the concept of a transaction similar to the mousewhell event code because after the page zooms the original element might not be underneath the original point, so the original association is kept for a 1 second (need to fine tune this) 

There's also room to improve. At the moment it only ensures that the element remains visible on screen: if it hides above the viewport it's scrolled to the top, if it goes below it's scrolled to the bottom, but it can be smarter. Also, I plan to use nodesFromRect (from bug 489127) to better determine the element of interest.
Attached patch WIP v2 (deleted) — Splinter Review
Second version, working better now. Works with mousewheel and pinch, tries to find the best candidate element to keep visible.

Next step now is to see if the results are better on trying to keep some scroll ratio on the chosen element, instead of just re-scrolling it into view if it goes beyond the viewport.
Assignee: nobody → felipc
Attachment #437725 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #438027 - Flags: feedback?
Attachment #438027 - Flags: feedback? → feedback?(gavin.sharp)
Attachment #438027 - Flags: feedback?(gavin.sharp) → feedback-
Comment on attachment 438027 [details] [diff] [review]
WIP v2

>+  _recenterTarget: function FullZoom_recenterTarget() {

>+    window.clearTimeout(this._clearZoomTransaction);
>+    window.setTimeout(this._clearZoomTransaction, 1000);

This is a bug :)

I think I would prefer if this code was handled by the back-end rather than having to worry about it in the front end, given that you should be able to use more precise scrolling methods and avoid unnecessary layout flushes that way. I'm not sure what the best API for this is, though - maybe a "centerTargetOnZoom" attribute on nsIMarkupDocumentViewer, whose default value is pref controlled?
This would be superseded by APZ
Assignee: felipc → nobody
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → DUPLICATE
(In reply to :Felipe Gomes from comment #8)
> This would be superseded by APZ

Why is that? Is it because APZ can, in theory, allow pinch-zooming on desktop platforms, and that would that provide a way of zooming that keeps a point on the page fixed on the screen?
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: