Skip to content

Fix the position of the drawings and of the comment popup/dialog after a rotation - #22339

Open
LoukasPap wants to merge 4 commits into
mozilla:masterfrom
LoukasPap:fix/editors-misplaced-after-rotation
Open

LoukasPap wants to merge 4 commits into
mozilla:masterfrom
LoukasPap:fix/editors-misplaced-after-rotation

Conversation

@LoukasPap

@LoukasPap LoukasPap commented Oct 26, 2026 •

Copy link
Copy Markdown

Fixes #22194

After rotating the pages, a drawing in progress and the comment popup/dialog could end up in the wrong place. This happened at zoom values that change on rotation (e.g. page-fit, auto).

  • Drawings: commit the drawing in progress before the layer is rotated, since its points depend on the rotation it has been drawn with.
  • Comment dialog and popup: they live in rotated layers, but their position was computed as if the layer wasn't rotated. Add helpers in dom_utils.js to convert between the client coordinates (rotated layer) and fractions of the unrotated layer, and use them to:
    • place the comment dialog next to its button;
    • store, move and clamp the popup position, so it stays where it was dragged when the pages are rotated.

Integration tests

The pages are rotated by 90°, 180°, 270° and back to 0°, with page-fit:

  • ink_editor_spec.mjs
    • "must keep a drawing in progress in place after rotating the pages"
    • "must keep the drawing in place while the pages are rotated"
  • comment_spec.mjs
    • "must display the popup next to its button when the pages are rotated"
    • "must keep the popup where it has been dragged when the pages are rotated"

Without the fixes, all of them fail except "must keep the drawing in place while the pages are rotated": a committed drawing already stays in place. That test is kept to avoid future regressions.

@LoukasPap
LoukasPap marked this pull request as draft October 26, 2026 15:07
LoukasPap and others added 4 commits October 26, 2026 17:08
Commit the drawing in progress before the layer is rotated, since its points
are in the coordinate system of the previous viewport.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… a layer

The layers are rotated with CSS, hence `getBoundingClientRect()` gives their
rotated (visual) rectangle whereas the `left`/`top` percentages of their
children are relative to their unrotated one.
The new helpers make it possible to switch between those two frames:
 - `clientRectToLayerLeftBottom` converts a client rectangle into the
   left-bottom corner in the unrotated frame (as fractions of the layer);
 - `layerFractionToClientPoint` does the opposite for a point;
 - `getUnrotatedSize` gives the dimensions of a rectangle in the unrotated
   frame.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The position of the comment button and of the popup is relative to the layer,
which can be rotated, whereas the bounding client rects are in the rotated
frame:
 - `commentButtonWidth` is now the width of the button divided by the width of
   the layer, both in the unrotated frame;
 - `commentPopupPosition(InLayer)` is computed from the left-bottom corner of
   the button in the unrotated frame;
 - when there is no popup position, the dialog is anchored to the bottom-left
   corner of the button as it's displayed, otherwise the stored position is
   converted back to the client coordinates;
 - the dialog uses the width of the button in the unrotated frame to align
   itself with the button.
This is done for the editors and for the popups of the existing annotations.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…the comment popup

The popup position is stored as fractions of the unrotated layer:
 - the movement of the pointer, which is in the window frame, is now rotated
   into the axes of the layer before being added to the position;
 - the width of the popup is divided by the width of the layer in the unrotated
   frame;
 - when the popup is kept inside the window, the x-axis of the layer is the
   horizontal axis of the window for 0° and 180°, and the vertical one for 90°
   and 270°, and it's reversed for 180° and 270°.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@LoukasPap
LoukasPap force-pushed the fix/editors-misplaced-after-rotation branch from d87e65e to 46777ea Compare October 26, 2026 15:08
@LoukasPap
LoukasPap marked this pull request as ready for review October 26, 2026 15:14

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: After rotation, the position of the graphics and comemnt is incorrect

2 participants