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

Internal: Moved most of methods from strategy to the context itself.

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

+ 10 - 6
packages/ckeditor5-widget/src/resizecontext.js

@@ -168,7 +168,7 @@ export default class ResizeContext {
 		this.aspectRatio = this.options.getAspectRatio ?
 			this.options.getAspectRatio( resizeHost ) : clientRect.width / clientRect.height;
 
-		this.resizeStrategy.begin( domResizeHandler );
+		this.redraw();
 	}
 
 	commit( editor ) {
@@ -179,8 +179,6 @@ export default class ResizeContext {
 
 		this.redraw();
 
-		this.resizeStrategy.commit( editor );
-
 		editor.model.change( writer => {
 			writer.setAttribute( WIDTH_ATTRIBUTE_NAME, newWidth, modelEntry );
 		} );
@@ -191,8 +189,6 @@ export default class ResizeContext {
 	cancel() {
 		this._dismissShadow();
 
-		this.resizeStrategy.cancel();
-
 		this._cleanupContext();
 	}
 
@@ -225,9 +221,16 @@ export default class ResizeContext {
 	redraw() {
 		if ( this.domResizeWrapper ) {
 			const widgetWrapper = this.domResizeWrapper.parentElement;
-
 			const resizingHost = this._getResizeHost();
+			const clientRect = resizingHost.getBoundingClientRect();
+
+			this.domResizeWrapper.style.width = clientRect.width + 'px';
+			this.domResizeWrapper.style.height = clientRect.height + 'px';
 
+			// In case a resizing host is not a widget wrapper, we need to compensate
+			// for any additional offsets the resize host might have. E.g. wrapper padding
+			// or simply another editable. By doing that the border and resizers are shown
+			// only around the resize host.
 			if ( !widgetWrapper.isSameNode( resizingHost ) ) {
 				this.domResizeWrapper.style.left = resizingHost.offsetLeft + 'px';
 				this.domResizeWrapper.style.top = resizingHost.offsetTop + 'px';
@@ -263,6 +266,7 @@ export default class ResizeContext {
 	 * will simply follow the image size.
 	 *
 	 * @protected
+	 * @returns {HTMLElement}
 	 */
 	_getResizeHost() {
 		const widgetWrapper = this.domResizeWrapper.parentElement;

+ 2 - 31
packages/ckeditor5-widget/src/resizertopbound.js

@@ -1,6 +1,3 @@
-import {
-	getAbsoluteBoundaryPoint
-} from './utils';
 
 import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
@@ -25,30 +22,6 @@ export default class ResizerTopBound {
 		this.options = options || {};
 	}
 
-	attach() {}
-
-	begin() {
-		this.redrawShadow();
-
-		const resizeHost = this.context._getResizeHost();
-		this.closestReferencePoint = getAbsoluteBoundaryPoint( resizeHost, this.context.referenceHandlerPosition );
-	}
-
-	redrawShadow() {
-		if ( this.context.domResizeWrapper ) {
-			const clientRect = this.context._getResizeHost().getBoundingClientRect();
-
-			this.context.domResizeWrapper.style.width = clientRect.width + 'px';
-			this.context.domResizeWrapper.style.height = clientRect.height + 'px';
-		}
-	}
-
-	commit() {}
-
-	cancel() {}
-
-	destroy() {}
-
 	/**
 	 * Method used to calculate the proposed size as the resize handlers are dragged.
 	 *
@@ -84,8 +57,8 @@ export default class ResizerTopBound {
 			enlargement.x = currentCoordinates.x - ( this.context.referenceCoordinates.x + initialSize.width );
 		}
 
-		// Objects needs to be resized twice as much in horizontal axis if centered, since enlargement is counted from one resized
-		// corner to your cursor. It needs to be duplicated to compensate for the other side too.
+		// Objects needs to be resized twice as much in horizontal axis if centered, since enlargement is counted from
+		// one resized corner to your cursor. It needs to be duplicated to compensate for the other side too.
 		if ( isCentered ) {
 			enlargement.x *= 2;
 		}
@@ -124,8 +97,6 @@ export default class ResizerTopBound {
 
 		return drawnSize;
 	}
-
-	redraw() {}
 }
 
 mix( ResizerTopBound, ObservableMixin );

+ 1 - 1
packages/ckeditor5-widget/src/widgetresizer.js

@@ -75,7 +75,7 @@ export default class WidgetResizer extends Plugin {
 			for ( const context of this.contexts ) {
 				// This check is needed, as there were cases when widget was not yet initialized but layoutChanged happened.
 				if ( context.domResizeWrapper && context.domResizeWrapper.parentElement ) {
-					context.resizeStrategy.redrawShadow();
+					context.redraw();
 				}
 			}
 		} );