-
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
Fix zoom out UI scale #61265
Changes from 12 commits
9d29a2e
f029d2d
a8c290a
d2b797f
3c3f0db
833f128
c30ca58
add28e3
8b93816
ffc1265
c148197
3ae1db9
2600547
db88df3
04b181a
aaea97f
20d21ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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-zoom-out-scale); | ||
$frame-size: var(--wp-zoom-out-frame-size); | ||
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. Why did you move everything to CSS? We only need 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. Or I wonder if animating these variables will be the same in terms of performance. But still, I don't get why we make all of these variables if it's not needed. 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. We might also want to prefix it with 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.
It was easier to read. I would expect the styling to be done in CSS. And it seemed like performance wouldn't be worse.
Why do you need to animate them in JS? Can't the animations be done with CSS? |
||
$inner-height: var(--wp-zoom-out-inner-height); | ||
$content-height: var(--wp-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; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,70 +207,13 @@ function Iframe( { | |
}; | ||
}, [] ); | ||
|
||
const windowResizeRef = useRefEffect( ( node ) => { | ||
const nodeWindow = node.ownerDocument.defaultView; | ||
|
||
const onResize = () => { | ||
setIframeWindowInnerHeight( nodeWindow.innerHeight ); | ||
}; | ||
nodeWindow.addEventListener( 'resize', onResize ); | ||
return () => { | ||
nodeWindow.removeEventListener( 'resize', onResize ); | ||
}; | ||
}, [] ); | ||
|
||
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 ), | ||
contentRef, | ||
clearerRef, | ||
writingFlowRef, | ||
disabledRef, | ||
// Avoid resize listeners when not needed, these will trigger | ||
// 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 +259,51 @@ function Iframe( { | |
? scale( contentWidth, contentHeight ) | ||
: scale; | ||
|
||
const isZoomedOut = scale !== 1; | ||
|
||
useEffect( () => { | ||
if ( ! iframeDocument || ! isZoomedOut ) { | ||
return; | ||
} | ||
|
||
iframeDocument.documentElement.classList.add( 'is-zoomed-out' ); | ||
|
||
// Needed for calculations in block-list content.scss. | ||
iframeDocument.documentElement.style.setProperty( | ||
'--wp-zoom-out-scale', | ||
`${ scale }` | ||
); | ||
iframeDocument.documentElement.style.setProperty( | ||
'--wp-zoom-out-frame-size', | ||
`${ frameSize }px` | ||
); | ||
iframeDocument.documentElement.style.setProperty( | ||
'--wp-zoom-out-content-height', | ||
`${ contentHeight }px` | ||
); | ||
iframeDocument.documentElement.style.setProperty( | ||
'--wp-zoom-out-inner-height', | ||
`${ iframeDocument.defaultView.innerHeight }px` | ||
); | ||
|
||
return () => { | ||
iframeDocument.documentElement.classList.remove( 'is-zoomed-out' ); | ||
|
||
iframeDocument.documentElement.style.removeProperty( | ||
'--wp-zoom-out-scale' | ||
); | ||
iframeDocument.documentElement.style.removeProperty( | ||
'--wp-zoom-out-frame-size' | ||
); | ||
iframeDocument.documentElement.style.removeProperty( | ||
'--wp-zoom-out-content-height' | ||
); | ||
iframeDocument.documentElement.style.removeProperty( | ||
'--wp-zoom-out-inner-height' | ||
); | ||
}; | ||
}, [ scale, frameSize, iframeDocument, 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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.edit-site-code-editor { | ||
position: relative; | ||
width: 100%; | ||
min-height: 100%; | ||
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. |
||
min-height: min-content; | ||
background-color: $white; | ||
|
||
&__body { | ||
|
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.