瀏覽代碼

Round sizes.

Piotrek Koszuliński 6 年之前
父節點
當前提交
384acc1018

+ 10 - 5
packages/ckeditor5-widget/src/widgetresize/resizer.js

@@ -243,7 +243,12 @@ export default class Resizer {
 			targetSize.width = targetSize.height * state.aspectRatio;
 		}
 
-		return targetSize;
+		return {
+			// TODO I couldn't find an automated TC for that, but rounding must be done here.
+			// Do not move it above.
+			width: Math.round( targetSize.width ),
+			height: Math.round( targetSize.height )
+		};
 	}
 
 	/**
@@ -344,11 +349,11 @@ class SizeView extends View {
 	}
 
 	bindToState( resizerState ) {
-		this.bind( 'isVisible' ).to( resizerState, 'proposedWidth', resizerState, 'proposedHeight', ( x, y ) =>
-			x !== null && y !== null );
+		this.bind( 'isVisible' ).to( resizerState, 'proposedWidth', resizerState, 'proposedHeight', ( width, height ) =>
+			width !== null && height !== null );
 
-		this.bind( 'label' ).to( resizerState, 'proposedWidth', resizerState, 'proposedHeight', ( x, y ) =>
-			`${ Math.round( x ) }×${ Math.round( y ) }` );
+		this.bind( 'label' ).to( resizerState, 'proposedWidth', resizerState, 'proposedHeight', ( width, height ) =>
+			`${ width }×${ height }` );
 
 		this.bind( 'activeHandlePosition' ).to( resizerState );
 	}

+ 6 - 2
packages/ckeditor5-widget/src/widgetresize/resizerstate.js

@@ -115,10 +115,14 @@ export default class ResizeState {
 	 * @param {HTMLElement} domElement
 	 */
 	fetchSizeFromElement( domElement ) {
+		// TODO the logic from this method should be moved to resizer.js.
+		// Search for other places where we do rounding – it's all in resizer.js.
+		// TODO this needs an automated test – currently it only affects the SizeView
+		// which we don't test.
 		const rect = new Rect( domElement );
 
-		this.proposedWidth = rect.width;
-		this.proposedHeight = rect.height;
+		this.proposedWidth = Math.round( rect.width );
+		this.proposedHeight = Math.round( rect.height );
 	}
 }