8
0
Просмотр исходного кода

Internal: Removed redundant code.

Marek Lewandowski 6 лет назад
Родитель
Сommit
adcd44b70c

+ 14 - 14
packages/ckeditor5-widget/src/resizecontext.js

@@ -52,6 +52,16 @@ export default class ResizeContext {
 
 		this.options = options || {};
 
+		/**
+		 * The size of resize host before current resize process.
+		 *
+		 * This information is only known after DOM was rendered, so it will be updated later.
+		 */
+		this.originalSize = {
+			x: 0,
+			y: 0
+		};
+
 		// @todo: ---- options below seems like a little outside of a scope of a single context ----
 
 		// Reference point of resizer where the dragging started. It is used to measure the distance to user cursor
@@ -62,16 +72,6 @@ export default class ResizeContext {
 			x: 0
 		};
 
-		/**
-		 * Size of an image before resize.
-		 *
-		 * This information is only known after DOM was rendered, so it will be updated later.
-		 */
-		this.originalSize = {
-			x: 0,
-			y: 0
-		};
-
 		this._cleanupContext();
 
 		/**
@@ -140,6 +140,7 @@ export default class ResizeContext {
 	 */
 	begin( domResizeHandler ) {
 		const resizeHost = this._getResizeHost();
+		const clientRect = resizeHost.getBoundingClientRect();
 
 		this.domResizeShadow.classList.add( 'ck-widget__resizer-shadow-active' );
 
@@ -157,14 +158,13 @@ export default class ResizeContext {
 
 		this.referenceCoordinates = getAbsoluteBoundaryPoint( resizeHost, reversedPosition );
 
-		// @todo: this part might be lazy used only in case if getAspectRatio is not given as it might force repaint.
 		this.originalSize = {
-			x: resizeHost.clientWidth,
-			y: resizeHost.clientHeight
+			width: clientRect.width,
+			height: clientRect.height
 		};
 
 		this.aspectRatio = this.options.getAspectRatio ?
-			this.options.getAspectRatio( resizeHost ) : this.originalSize.x / this.originalSize.y;
+			this.options.getAspectRatio( resizeHost ) : clientRect.width / clientRect.height;
 
 		this.resizeStrategy.begin( domResizeHandler );
 	}

+ 10 - 16
packages/ckeditor5-widget/src/resizertopbound.js

@@ -29,14 +29,6 @@ export default class ResizerTopBound {
 	attach() {}
 
 	begin() {
-		const clientRect = this.context._getResizeHost().getBoundingClientRect();
-
-		// Size of resize host before current resizing transaction.
-		this.initialSize = {
-			width: clientRect.width,
-			height: clientRect.height
-		};
-
 		this.redrawShadow();
 
 		const resizeHost = this.context._getResizeHost();
@@ -70,16 +62,17 @@ export default class ResizerTopBound {
 		const context = this.context;
 		const currentCoordinates = context._extractCoordinates( domEventData );
 		const isCentered = this.options.isCentered ? this.options.isCentered( this.context ) : true;
+		const initialSize = this.context.originalSize;
 
 		const enlargement = {
 			// @todo it could be simplified if context.referenceCoordinates was an inverted corner (at least for bottom-left).
-			x: this.context.referenceCoordinates.x - ( currentCoordinates.x + this.initialSize.width ),
-			y: ( currentCoordinates.y - this.initialSize.height ) - this.context.referenceCoordinates.y
+			x: this.context.referenceCoordinates.x - ( currentCoordinates.x + initialSize.width ),
+			y: ( currentCoordinates.y - initialSize.height ) - this.context.referenceCoordinates.y
 		};
 
 		// temp workaround
 		if ( isCentered && this.context.referenceHandlerPosition.endsWith( '-right' ) ) {
-			enlargement.x = currentCoordinates.x - ( this.context.referenceCoordinates.x + this.initialSize.width );
+			enlargement.x = currentCoordinates.x - ( this.context.referenceCoordinates.x + initialSize.width );
 		}
 
 		// @todo: oddly enough, this condition **check** is not needed for tables.
@@ -90,14 +83,15 @@ export default class ResizerTopBound {
 		const resizeHost = this.context._getResizeHost();
 		const clientRect = resizeHost.getBoundingClientRect();
 
-		const originalSize = {
+		// The size of currently visible resize host.
+		const currentSize = {
 			x: clientRect.width,
 			y: clientRect.height
 		};
 
 		const proposedSize = {
-			x: Math.abs( this.initialSize.width + enlargement.x ),
-			y: Math.abs( this.initialSize.height + enlargement.y )
+			x: Math.abs( initialSize.width + enlargement.x ),
+			y: Math.abs( initialSize.height + enlargement.y )
 		};
 
 		// Dominant determination must take the ratio into account.
@@ -142,8 +136,8 @@ export default class ResizerTopBound {
 			const invertedPosition = this.context._invertPosition( context.referenceHandlerPosition );
 
 			const diff2 = {
-				x: parseFloat( originalSize.x ) - drawnSize.x,
-				y: parseFloat( originalSize.y ) - drawnSize.y
+				x: parseFloat( currentSize.x ) - drawnSize.x,
+				y: parseFloat( currentSize.y ) - drawnSize.y
 			};
 
 			context.domResizeShadow.style[ invertedPosition.split( '-' )[ 0 ] ] = '0px';