Commit aa3fabce authored by Mike Sherov's avatar Mike Sherov Committed by Dave Methvin

Fix #12088, Safari 5 and more percentages in getComputedStyle

In particular, min-width and max-width are taunting the awesome hack. Closes gh-865.
parent ff7a4345
...@@ -276,7 +276,7 @@ jQuery.extend({ ...@@ -276,7 +276,7 @@ jQuery.extend({
// and getComputedStyle here to produce a better gzip size // and getComputedStyle here to produce a better gzip size
if ( window.getComputedStyle ) { if ( window.getComputedStyle ) {
curCSS = function( elem, name ) { curCSS = function( elem, name ) {
var ret, width, var ret, width, minWidth, maxWidth,
computed = getComputedStyle( elem, null ), computed = getComputedStyle( elem, null ),
style = elem.style; style = elem.style;
...@@ -288,13 +288,20 @@ if ( window.getComputedStyle ) { ...@@ -288,13 +288,20 @@ if ( window.getComputedStyle ) {
} }
// A tribute to the "awesome hack by Dean Edwards" // A tribute to the "awesome hack by Dean Edwards"
// WebKit uses "computed value (percentage if specified)" instead of "used value" for margins // Chrome < 17 and Safari 5.0 uses "computed value" instead of "used value" for margin-right
// which is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values // Safari 5.1.7 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
if ( !jQuery.support.pixelMargin && rmargin.test( name ) && rnumnonpx.test( ret ) ) { // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
if ( rnumnonpx.test( ret ) && !rposition.test( name ) ) {
width = style.width; width = style.width;
style.width = ret; minWidth = style.minWidth;
maxWidth = style.maxWidth;
style.minWidth = style.maxWidth = style.width = ret;
ret = computed.width; ret = computed.width;
style.width = width; style.width = width;
style.minWidth = minWidth;
style.maxWidth = maxWidth;
} }
} }
......
...@@ -91,7 +91,6 @@ jQuery.support = (function() { ...@@ -91,7 +91,6 @@ jQuery.support = (function() {
inlineBlockNeedsLayout: false, inlineBlockNeedsLayout: false,
shrinkWrapBlocks: false, shrinkWrapBlocks: false,
reliableMarginRight: true, reliableMarginRight: true,
pixelMargin: true,
boxSizingReliable: true, boxSizingReliable: true,
pixelPosition: false pixelPosition: false
}; };
...@@ -220,7 +219,6 @@ jQuery.support = (function() { ...@@ -220,7 +219,6 @@ jQuery.support = (function() {
// The difference between window.getComputedStyle and getComputedStyle is // The difference between window.getComputedStyle and getComputedStyle is
// 7 bytes // 7 bytes
if ( window.getComputedStyle ) { if ( window.getComputedStyle ) {
support.pixelMargin = ( window.getComputedStyle( div, null ) || {} ).marginTop !== "1%";
support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%"; support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";
support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px"; support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px";
......
...@@ -641,6 +641,15 @@ test("marginRight computed style (bug #3333)", function() { ...@@ -641,6 +641,15 @@ test("marginRight computed style (bug #3333)", function() {
equal($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block"); equal($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block");
}); });
test("box model properties incorrectly returning % instead of px, see #10639 and #12088", function() {
var container = jQuery("<div/>").width( 400 ).appendTo("#qunit-fixture"),
el = jQuery("<div/>").css({ "width": "50%", "marginRight": "50%" }).appendTo( container ),
el2 = jQuery("<div/>").css({ "width": "50%", "minWidth": "300px", "marginLeft": "25%" }).appendTo( container );
equal( el.css("marginRight"), "200px", "css('marginRight') returning % instead of px, see #10639" );
equal( el2.css("marginLeft"), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" );
});
test("jQuery.cssProps behavior, (bug #8402)", function() { test("jQuery.cssProps behavior, (bug #8402)", function() {
var div = jQuery( "<div>" ).appendTo(document.body).css({ var div = jQuery( "<div>" ).appendTo(document.body).css({
"position": "absolute", "position": "absolute",
......
...@@ -292,13 +292,6 @@ test("getting dimensions shouldnt modify runtimeStyle see #9233", function() { ...@@ -292,13 +292,6 @@ test("getting dimensions shouldnt modify runtimeStyle see #9233", function() {
$div.remove(); $div.remove();
}); });
test("outerWidth(true) returning % instead of px in Webkit, see #10639", function() {
var container = jQuery( "<div/>" ).width(400).appendTo( "#qunit-fixture" ),
el = jQuery( "<div/>" ).css({ "width": "50%", "marginRight": "50%" }).appendTo( container );
equal( el.outerWidth(true), 400, "outerWidth(true) and css('margin') returning % instead of px in Webkit, see #10639" );
});
test( "getting dimensions of zero width/height table elements shouldn't alter dimensions", function() { test( "getting dimensions of zero width/height table elements shouldn't alter dimensions", function() {
expect( 1 ); expect( 1 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment