Skip to content

Commit

Permalink
Factor scale into adjustment of bubbled mouse events
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Oct 5, 2024
1 parent f32bed2 commit eddd3f8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ function bubbleEvent( event, Constructor, frame ) {
init[ key ] = event[ key ];
}

// Check if the event is a MouseEvent generated within the iframe.
// If so, adjust the coordinates to be relative to the position of
// the iframe. This ensures that components such as Draggable
// receive coordinates relative to the window, instead of relative
// to the iframe. Without this, the Draggable event handler would
// result in components "jumping" position as soon as the user
// drags over the iframe.
// Check if the event is a MouseEvent generated within the iframe. If so,
// adjust the coordinates by the iframe’s position and scale. This ensures
// that components such as Draggable receive coordinates relative to the
// window, instead of relative to the iframe. Without this, such component’s
// would have to deal with "jumps" in the coordinates whenever the pointer
// enters or exits the iframe.
if ( event instanceof frame.contentDocument.defaultView.MouseEvent ) {
const rect = frame.getBoundingClientRect();
const scale = rect.width / frame.offsetWidth;
init.clientX *= scale;
init.clientY *= scale;
init.clientX += rect.left;
init.clientY += rect.top;
}
Expand Down

0 comments on commit eddd3f8

Please sign in to comment.