Bug 8087 - REGRESSION: Image width & height not valid on generated elements
Summary: REGRESSION: Image width & height not valid on generated elements
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 417.x
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-30 11:05 PST by Niels Meersschaert
Modified: 2022-07-06 13:39 PDT (History)
3 users (show)

See Also:


Attachments
test 1 (1.03 KB, application/xhtml+xml)
2006-03-30 20:46 PST, Alexey Proskuryakov
no flags Details
test 2 (1.12 KB, application/xhtml+xml)
2006-03-30 20:47 PST, Alexey Proskuryakov
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Niels Meersschaert 2006-03-30 11:05:28 PST
If an image is generated in the DOM, either manually or thru an XMLHttpRequest, querying that image for it's height & width no longer works (it did earlier).

Here's a test case:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>Image bug</title> <script type="text/javascript">
	function test() {
	var srcImage = document.createElement("img");	srcImage.setAttribute("src","http://images.apple.com/macosx/images/indextop20060109.jpg");
	//Source image is 670x275
	var image = new Image();
		image.src=srcImage.getAttribute("src");
		image.onload=testImage(image);
	}
	function testImage(image) {
	//The image object should return a width of 670 since the image has been loaded
	alert("Image " + image.src+" width:"+image.width);
	//It actually returns 0
	}
	</script> 
</head>
<body onload="test();">

</body>
</html>

The alert box returns width: 0.

The alert box should have returned width: 670.

If the image is loaded already such as:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>Image bug</title> <script type="text/javascript">
	function test() {
	var srcImage = document.createElement("img");	srcImage.setAttribute("src","http://images.apple.com/macosx/images/indextop20060109.jpg");
	//Source image is 670x275
	var image = new Image();
		image.src=srcImage.getAttribute("src");
		image.onload=testImage(image);
	}
	function testImage(image) {
	//The image object should return a width of 670 since the image has been loaded
	alert("Image " + image.src+" width:"+image.width);
	//It actually returns 0
	}
	</script> 
</head>
<body onload="test();">
<img id="testSubject" src="http://images.apple.com/macosx/images/indextop20060109.jpg" alt="OS X" />
</body>
</html>

The alert box returns width: 670.

Since the script is explicitedly displaying the alert only after the onload of the image, it should display properly.
Comment 1 Alexey Proskuryakov 2006-03-30 20:46:52 PST
Created attachment 7410 [details]
test 1
Comment 2 Alexey Proskuryakov 2006-03-30 20:47:10 PST
Created attachment 7411 [details]
test 2
Comment 3 Alexey Proskuryakov 2006-03-30 20:53:41 PST
Reporter, do you know when the behavior has changed? I'm getting identical results from stock 10.4.5 and ToT. Actually, Firefox also reports zero width once after a relaunch.
Comment 4 Niels Meersschaert 2006-03-31 05:06:44 PST
I was using this code in a widget developed and released under 10.4.4.  Thus, I believe the change occurred with 10.4.5 and it's update to the safari webkit.
Comment 5 Mark Rowe (bdash) 2006-07-02 07:24:20 PDT
My brief testing shows that Camino demonstrates identical behaviour to WebKit in always returning zero for the width, while Firefox returns zero when first run and then the correct value thereafter.  I'm not sure if this should be considered a bug.
Comment 6 Mark Rowe (bdash) 2006-07-06 05:35:17 PDT
Joost has convinced me this is a bug.
Comment 7 Gavin Sherlock 2008-08-01 06:44:52 PDT
Both tests now report an image width of 670 with r35417, so this may be fixed.