8
0
Oskar Wróbel 9 лет назад
Родитель
Сommit
e7e56dce52

+ 40 - 0
packages/ckeditor5-engine/src/view/uielement.js

@@ -0,0 +1,40 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/**
+ * @module engine/view/uielement
+ */
+
+import Element from './element';
+
+/**
+ * UIElement class. It is used to represent features of UI not content of the document.
+ * This element can't be split and selection can't be placed inside this element.
+ */
+export default class UIElement extends Element {
+	/**
+	 * Creates new instance of UIElement.
+	 *
+	 * @see module:engine/view/element~Element
+	 */
+	constructor( name, attributes, children ) {
+		super( name, attributes, children );
+
+		/**
+		 * Returns `null` because filler is not needed for EmptyElements.
+		 *
+		 * @method #getFillerOffset
+		 * @returns {null} Always returns null.
+		 */
+		this.getFillerOffset = getFillerOffset;
+	}
+}
+
+// Returns `null` because block filler is not needed for EmptyElements.
+//
+// @returns {null}
+function getFillerOffset() {
+	return null;
+}

+ 39 - 0
packages/ckeditor5-engine/tests/view/uielement.js

@@ -0,0 +1,39 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import UIElement from '../../src/view/uielement';
+import Element from '../../src/view/element';
+
+describe( 'UIElement', () => {
+	let childElement, uiElement;
+
+	beforeEach( () => {
+		childElement = new Element( 'b' );
+		uiElement = new UIElement( 'span', {
+			foo: 'bar',
+			style: 'border: 1px solid red;color: white;',
+			class: 'foo bar'
+		}, [ childElement ] );
+	} );
+
+	describe( 'constructor()', () => {
+		it( 'should create instance', () => {
+			expect( uiElement.name ).to.equal( 'span' );
+			expect( uiElement.getAttribute( 'foo' ) ).to.equal( 'bar' );
+			expect( uiElement.getStyle( 'border' ) ).to.equal( '1px solid red' );
+			expect( uiElement.getStyle( 'color' ) ).to.equal( 'white' );
+			expect( uiElement.hasClass( 'foo' ) ).to.true;
+			expect( uiElement.hasClass( 'bar' ) ).to.true;
+			expect( uiElement.childCount ).to.equal( 1 );
+			expect( uiElement.getChild( 0 ) ).to.equal( childElement )
+		} );
+	} );
+
+	describe( 'getFillerOffset()', () => {
+		it( 'should return null', () => {
+			expect( uiElement.getFillerOffset() ).to.null;
+		} );
+	} );
+} );