From 4e989805236ce6401bfc7a08913957960bd71887 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Tue, 7 Nov 2023 00:35:56 +0100 Subject: [PATCH] CSS: Fix reliableTrDimensions test for initially hidden iframes (3.x) Also, account for the fact old Firefox (<61) has `null` computed style for elements in such iframes. Closes gh-5359 Ref gh-5317 Ref gh-5358 --- src/css.js | 3 ++ src/css/support.js | 11 ++++- test/data/css/cssComputeStyleTests.html | 11 ++++- test/unit/css.js | 54 ++++++++++++++++++------- 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/css.js b/src/css.js index 1ec1aa8f4..d4866f938 100644 --- a/src/css.js +++ b/src/css.js @@ -153,6 +153,9 @@ function getWidthOrHeight( elem, dimension, extra ) { // IE/Edge misreport `getComputedStyle` of table rows with width/height // set in CSS while `offset*` properties report correct values. // Interestingly, in some cases IE 9 doesn't suffer from this issue. + // Support: Firefox 70+ + // Firefox includes border widths + // in computed dimensions for table rows. (gh-4529) !support.reliableTrDimensions() && nodeName( elem, "tr" ) || // Fall back to offsetWidth/offsetHeight when value is "auto" diff --git a/src/css/support.js b/src/css/support.js index 3057c8c25..8838f0bc1 100644 --- a/src/css/support.js +++ b/src/css/support.js @@ -27,7 +27,10 @@ define( [ documentElement.appendChild( container ).appendChild( div ); var divStyle = window.getComputedStyle( div ); - pixelPositionVal = divStyle.top !== "1%"; + + // Support: Firefox <=48 - 61 only + // Inside hidden iframes computed style is null in old Firefox. + pixelPositionVal = divStyle && divStyle.top !== "1%"; // Don't run until window is visible (https://github.com/jquery/jquery-ui/issues/2176) if ( div.offsetWidth === 0 ) { @@ -141,6 +144,12 @@ define( [ .appendChild( tr ) .appendChild( trChild ); + // Don't run until window is visible + if ( table.offsetWidth === 0 ) { + documentElement.removeChild( table ); + return; + } + trStyle = window.getComputedStyle( tr ); reliableTrDimensionsVal = ( parseInt( trStyle.height, 10 ) + parseInt( trStyle.borderTopWidth, 10 ) + diff --git a/test/data/css/cssComputeStyleTests.html b/test/data/css/cssComputeStyleTests.html index 47a207e5c..9010d70fd 100644 --- a/test/data/css/cssComputeStyleTests.html +++ b/test/data/css/cssComputeStyleTests.html @@ -1,6 +1,7 @@ + Test computeStyleTests for hidden iframe
+ + +
diff --git a/test/unit/css.js b/test/unit/css.js index fc5929b95..a1c5267d7 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1401,20 +1401,46 @@ testIframe( } ); -testIframe( - "Test computeStyleTests for hidden iframe", - "css/cssComputeStyleTests.html", - function( assert, jQuery, window, document, initialHeight ) { - assert.expect( 2 ); - assert.strictEqual( initialHeight === 0 ? 20 : initialHeight, 20, - "hidden-frame content sizes should be zero or accurate" ); - window.parent.jQuery( "#qunit-fixture-iframe" ).css( { "display": "block" } ); - jQuery( "#test" ).width( 600 ); - assert.strictEqual( jQuery( "#test" ).width(), 600, "width should be 600" ); - }, - undefined, - { "display": "none" } -); +( function() { + var supportsFractionalTrWidth, + epsilon = 0.1, + table = jQuery( "
" ), + tr = table.find( "tr" ); + + table + .appendTo( "#qunit-fixture" ) + .css( { + width: "100.7px", + borderSpacing: 0 + } ); + + supportsFractionalTrWidth = Math.abs( tr.width() - 100.7 ) < epsilon; + + testIframe( + "Test computeStyleTests for hidden iframe", + "css/cssComputeStyleTests.html", + function( assert, jQuery, window, document, initialHeight ) { + assert.expect( 3 ); + + assert.strictEqual( initialHeight === 0 ? 20 : initialHeight, 20, + "hidden-frame content sizes should be zero or accurate" ); + + window.parent.jQuery( "#qunit-fixture-iframe" ).css( { "display": "block" } ); + jQuery( "#test" ).width( 600 ); + assert.strictEqual( jQuery( "#test" ).width(), 600, "width should be 600" ); + + if ( supportsFractionalTrWidth ) { + assert.ok( + Math.abs( jQuery( "#test-tr" ).width() - 100.7 ) < epsilon, + "tr width should be fractional" ); + } else { + assert.strictEqual( jQuery( "#test-tr" ).width(), 101, "tr width as expected" ); + } + }, + undefined, + { "display": "none" } + ); +} )(); ( function() { var supportsFractionalGBCR, -- 2.39.5