Bladeren bron

Updated getBorderWidths helper to use computed styles provided by element's #ownerDocument.

Aleksander Nowodzinski 8 jaren geleden
bovenliggende
commit
955e7261e7

+ 2 - 3
packages/ckeditor5-utils/src/dom/getborderwidths.js

@@ -7,8 +7,6 @@
  * @module utils/dom/getborderwidths
  */
 
-import global from './global';
-
 /**
  * Returns an object containing CSS border widths of a specified HTML element.
  *
@@ -17,7 +15,8 @@ import global from './global';
  * with numerical values of the `border-[top,left,right,bottom]-width` CSS styles.
  */
 export default function getBorderWidths( element ) {
-	const style = global.window.getComputedStyle( element );
+	// Call getComputedStyle on the window the element document belongs to.
+	const style = element.ownerDocument.defaultView.getComputedStyle( element );
 
 	return {
 		top: parseInt( style.borderTopWidth, 10 ),

+ 14 - 9
packages/ckeditor5-utils/tests/dom/getborderwidths.js

@@ -3,7 +3,6 @@
  * For licensing, see LICENSE.md.
  */
 
-import global from '../../src/dom/global';
 import getBorderWidths from '../../src/dom/getborderwidths';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
@@ -11,14 +10,20 @@ testUtils.createSinonSandbox();
 
 describe( 'getBorderWidths()', () => {
 	it( 'returns CSS border widths', () => {
-		testUtils.sinon.stub( global.window, 'getComputedStyle' ).returns( {
-			borderTopWidth: '10px',
-			borderRightWidth: '20px',
-			borderBottomWidth: '30px',
-			borderLeftWidth: '40px'
-		} );
-
-		const elementMock = {};
+		const elementMock = {
+			ownerDocument: {
+				defaultView: {
+					getComputedStyle: () => {
+						return {
+							borderTopWidth: '10px',
+							borderRightWidth: '20px',
+							borderBottomWidth: '30px',
+							borderLeftWidth: '40px'
+						};
+					}
+				}
+			}
+		};
 
 		expect( getBorderWidths( elementMock ) ).to.deep.equal( {
 			top: 10,