From e743cbd28553267f955f71ea7248377915613fd9 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Wed, 20 Jun 2018 22:09:29 -0700 Subject: [PATCH] Dimensions: fix computing outerWidth on SVGs Fixes gh-3964 Closes gh-4096 --- src/css.js | 5 +++- test/unit/dimensions.js | 60 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/css.js b/src/css.js index 19c2f79d1..c3afb0ab7 100644 --- a/src/css.js +++ b/src/css.js @@ -107,7 +107,10 @@ function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computed delta - extra - 0.5 - ) ); + + // If offsetWidth/offsetHeight is unknown, then we can't determine content-box scroll gutter + // Use an explicit zero to avoid NaN (gh-3964) + ) ) || 0; } return delta; diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js index d7e553369..8c7f0752f 100644 --- a/test/unit/dimensions.js +++ b/test/unit/dimensions.js @@ -352,6 +352,66 @@ QUnit.test( "table dimensions", function( assert ) { assert.equal( colElem.width(), 300, "col elements have width(), see #12243" ); } ); +QUnit.test( "SVG dimensions (basic content-box)", function( assert ) { + assert.expect( 8 ); + + var svg = jQuery( "" ).appendTo( "#qunit-fixture" ); + + assert.equal( svg.width(), 100 ); + assert.equal( svg.height(), 100 ); + + assert.equal( svg.innerWidth(), 100 ); + assert.equal( svg.innerHeight(), 100 ); + + assert.equal( svg.outerWidth(), 100 ); + assert.equal( svg.outerHeight(), 100 ); + + assert.equal( svg.outerWidth( true ), 100 ); + assert.equal( svg.outerHeight( true ), 100 ); + + svg.remove(); +} ); + +QUnit.test( "SVG dimensions (content-box)", function( assert ) { + assert.expect( 8 ); + + var svg = jQuery( "" ).appendTo( "#qunit-fixture" ); + + assert.equal( svg.width(), 100 ); + assert.equal( svg.height(), 100 ); + + assert.equal( svg.innerWidth(), 104 ); + assert.equal( svg.innerHeight(), 104 ); + + assert.equal( svg.outerWidth(), 106 ); + assert.equal( svg.outerHeight(), 106 ); + + assert.equal( svg.outerWidth( true ), 112 ); + assert.equal( svg.outerHeight( true ), 112 ); + + svg.remove(); +} ); + +QUnit.test( "SVG dimensions (border-box)", function( assert ) { + assert.expect( 8 ); + + var svg = jQuery( "" ).appendTo( "#qunit-fixture" ); + + assert.equal( svg.width(), 94 ); + assert.equal( svg.height(), 94 ); + + assert.equal( svg.innerWidth(), 98 ); + assert.equal( svg.innerHeight(), 98 ); + + assert.equal( svg.outerWidth(), 100 ); + assert.equal( svg.outerHeight(), 100 ); + + assert.equal( svg.outerWidth( true ), 106 ); + assert.equal( svg.outerHeight( true ), 106 ); + + svg.remove(); +} ); + QUnit.test( "box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function( assert ) { assert.expect( 16 ); -- 2.39.5