-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix zoom out UI scale #61265
Merged
Merged
Fix zoom out UI scale #61265
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9d29a2e
Fix crash when switching to code editor
ajlende f029d2d
Fix typo
ajlende a8c290a
Remove unused eslint ignore
ajlende d2b797f
Add isZoomedOut variable
ajlende 3c3f0db
Remove load callback that isn't needed
ajlende 833f128
Fix zoomed out code editor background
ajlende c30ca58
Fix UI elements in zoom-out mode
ajlende add28e3
Move all calculations to CSS
ajlende 8b93816
Move iframe styles into own file
ajlende ffc1265
Merge branch 'trunk' into fix/iframe-zoom-out-ui-scale
ajlende c148197
Revert unrelated changes
ajlende 3ae1db9
Fix CSS lint
ajlende 2600547
Remove comment
ajlende db88df3
Revert to 100%
ajlende 04b181a
Recalculate height on rerender
ajlende aaea97f
Update variable prefix for package and block
ajlende 20d21ae
Merge branch 'trunk' into fix/iframe-zoom-out-ui-scale
ajlende File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
.block-editor-iframe__html { | ||
transform-origin: top center; | ||
transition: transform 0.3s; | ||
@include reduce-motion("transition"); | ||
} | ||
|
||
.block-editor-iframe__html.is-zoomed-out { | ||
$scale: var(--wp-block-editor-iframe-zoom-out-scale); | ||
$frame-size: var(--wp-block-editor-iframe-zoom-out-frame-size); | ||
$inner-height: var(--wp-block-editor-iframe-zoom-out-inner-height); | ||
$content-height: var(--wp-block-editor-iframe-zoom-out-content-height); | ||
|
||
transform: scale(#{$scale}); | ||
|
||
background-color: $gray-300; | ||
|
||
// Firefox and Safari don't render margin-bottom here and margin-bottom is needed for Chrome | ||
// layout, so we use border matching the background instead of margins. | ||
border: calc(#{$frame-size} / #{$scale}) solid $gray-300; | ||
|
||
// Chrome seems to respect that transform scale shouldn't affect the layout size of the element, | ||
// so we need to adjust the height of the content to match the scale by using negative margins. | ||
$extra-content-height: calc(#{$content-height} * (1 - #{$scale})); | ||
$total-frame-height: calc(2 * #{$frame-size}); | ||
$total-height: calc(#{$extra-content-height} + #{$total-frame-height}); | ||
margin-bottom: calc(-1 * #{$total-height}); | ||
|
||
body { | ||
min-height: calc((#{$inner-height} - #{$total-frame-height}) / #{$scale}); | ||
display: flex; | ||
flex-direction: column; | ||
|
||
> .is-root-container { | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
height: 100%; | ||
|
||
> main { | ||
flex: 1; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,44 +221,6 @@ function Iframe( { | |
|
||
const [ iframeWindowInnerHeight, setIframeWindowInnerHeight ] = useState(); | ||
|
||
const scaleRef = useRefEffect( | ||
( body ) => { | ||
// Hack to get proper margins when scaling the iframe document. | ||
const bottomFrameSize = frameSize - contentHeight * ( 1 - scale ); | ||
|
||
const { documentElement } = body.ownerDocument; | ||
|
||
body.classList.add( 'is-zoomed-out' ); | ||
|
||
documentElement.style.transform = `scale( ${ scale } )`; | ||
documentElement.style.marginTop = `${ frameSize }px`; | ||
// TODO: `marginBottom` doesn't work in Firefox. We need another way | ||
// to do this. | ||
documentElement.style.marginBottom = `${ bottomFrameSize }px`; | ||
if ( iframeWindowInnerHeight > contentHeight * scale ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's see in a follow-up if this is still needed |
||
iframeDocument.body.style.minHeight = `${ Math.floor( | ||
( iframeWindowInnerHeight - 2 * frameSize ) / scale | ||
) }px`; | ||
} | ||
|
||
return () => { | ||
body.classList.remove( 'is-zoomed-out' ); | ||
documentElement.style.transform = ''; | ||
documentElement.style.marginTop = ''; | ||
documentElement.style.marginBottom = ''; | ||
body.style.minHeight = ''; | ||
}; | ||
}, | ||
[ | ||
scale, | ||
frameSize, | ||
iframeDocument, | ||
contentHeight, | ||
iframeWindowInnerHeight, | ||
contentWidth, | ||
] | ||
); | ||
|
||
const disabledRef = useDisabled( { isDisabled: ! readonly } ); | ||
const bodyRef = useMergeRefs( [ | ||
useBubbleEvents( iframeDocument ), | ||
|
@@ -270,7 +232,6 @@ function Iframe( { | |
// unnecessary re-renders when animating the iframe width, or when | ||
// expanding preview iframes. | ||
scale === 1 ? null : windowResizeRef, | ||
scale === 1 ? null : scaleRef, | ||
] ); | ||
|
||
// Correct doctype is required to enable rendering in standards | ||
|
@@ -316,6 +277,57 @@ function Iframe( { | |
? scale( contentWidth, contentHeight ) | ||
: scale; | ||
|
||
const isZoomedOut = scale !== 1; | ||
|
||
useEffect( () => { | ||
if ( ! iframeDocument || ! isZoomedOut ) { | ||
return; | ||
} | ||
|
||
iframeDocument.documentElement.classList.add( 'is-zoomed-out' ); | ||
|
||
iframeDocument.documentElement.style.setProperty( | ||
'--wp-block-editor-iframe-zoom-out-scale', | ||
`${ scale }` | ||
); | ||
iframeDocument.documentElement.style.setProperty( | ||
'--wp-block-editor-iframe-zoom-out-frame-size', | ||
`${ frameSize }px` | ||
); | ||
iframeDocument.documentElement.style.setProperty( | ||
'--wp-block-editor-iframe-zoom-out-content-height', | ||
`${ contentHeight }px` | ||
); | ||
iframeDocument.documentElement.style.setProperty( | ||
'--wp-block-editor-iframe-zoom-out-inner-height', | ||
`${ iframeWindowInnerHeight }px` | ||
); | ||
|
||
return () => { | ||
iframeDocument.documentElement.classList.remove( 'is-zoomed-out' ); | ||
|
||
iframeDocument.documentElement.style.removeProperty( | ||
'--wp-block-editor-iframe-zoom-out-scale' | ||
); | ||
iframeDocument.documentElement.style.removeProperty( | ||
'--wp-block-editor-iframe-zoom-out-frame-size' | ||
); | ||
iframeDocument.documentElement.style.removeProperty( | ||
'--wp-block-editor-iframe-zoom-out-content-height' | ||
); | ||
iframeDocument.documentElement.style.removeProperty( | ||
'--wp-block-editor-iframe-zoom-out-inner-height' | ||
); | ||
}; | ||
}, [ | ||
scale, | ||
frameSize, | ||
iframeDocument, | ||
iframeWindowInnerHeight, | ||
contentHeight, | ||
isZoomedOut, | ||
] ); | ||
|
||
// Make sure to not render the before and after focusable div elements in view | ||
// mode. They're only needed to capture focus in edit mode. | ||
const shouldRenderFocusCaptureElements = tabIndex >= 0 && ! isPreviewMode; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we changing these rules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It provides exact sizing instead of using the hack that is sometimes wrong.