From 821bf34353a6baf97f7944379a6459afb16badae Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 7 May 2018 09:28:18 -0400 Subject: [PATCH] CSS: Correctly detect scrollbox support with non-default zoom Fixes gh-4029 Closes gh-4030 --- src/css.js | 16 +++++++++------- src/css/support.js | 4 +++- test/data/css/cssWidthBrowserZoom.html | 6 +++++- test/unit/css.js | 7 ++++--- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/css.js b/src/css.js index ea730201..e936c8f3 100644 --- a/src/css.js +++ b/src/css.js @@ -352,13 +352,15 @@ jQuery.each( [ "height", "width" ], function( i, dimension ) { boxSizingNeeded = scrollBoxSize || extra, isBorderBox = boxSizingNeeded && jQuery.css( elem, "boxSizing", false, styles ) === "border-box", - subtract = extra && boxModelAdjustment( - elem, - dimension, - extra, - isBorderBox, - styles - ); + subtract = extra ? + boxModelAdjustment( + elem, + dimension, + extra, + isBorderBox, + styles + ) : + 0; // Account for unreliable border-box dimensions by comparing offset* to computed and // faking a content-box to get border and padding (gh-3699) diff --git a/src/css/support.js b/src/css/support.js index dbb7ef7c..12706f7e 100644 --- a/src/css/support.js +++ b/src/css/support.js @@ -43,8 +43,10 @@ define( [ // Support: IE 9 only // Detect overflow:scroll screwiness (gh-3699) + // Support: Chrome <=64 + // Don't get tricked when zoom affects offsetWidth (gh-4029) div.style.position = "absolute"; - scrollboxSizeVal = div.offsetWidth === 36 || "absolute"; + scrollboxSizeVal = roundPixelMeasures( div.offsetWidth / 3 ) === 12 || "absolute"; documentElement.removeChild( container ); diff --git a/test/data/css/cssWidthBrowserZoom.html b/test/data/css/cssWidthBrowserZoom.html index 99f87ea2..133daf62 100644 --- a/test/data/css/cssWidthBrowserZoom.html +++ b/test/data/css/cssWidthBrowserZoom.html @@ -7,6 +7,7 @@ zoom: 1.1; } #test { + position: absolute; width: 100px; height: 100px; padding: 10px; @@ -20,7 +21,10 @@ diff --git a/test/unit/css.js b/test/unit/css.js index fbb42c30..626981b7 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1167,9 +1167,10 @@ testIframe( testIframe( "css('width') should work correctly with browser zooming", "css/cssWidthBrowserZoom.html", - function( assert, jQuery, window, document, cssWidthBrowserZoom ) { - assert.expect( 1 ); - assert.strictEqual( cssWidthBrowserZoom, "100px", "elem.css('width') works correctly with browser zoom" ); + function( assert, jQuery, window, document, widthBeforeSet, widthAfterSet ) { + assert.expect( 2 ); + assert.strictEqual( widthBeforeSet, "100px", "elem.css('width') works correctly with browser zoom" ); + assert.strictEqual( widthAfterSet, "100px", "elem.css('width', val) works correctly with browser zoom" ); } ); -- 2.11.4.GIT