Bug 133282 - offset* not working as it should
Summary: offset* not working as it should
Status: RESOLVED UNMAINTAINED
Alias: None
Product: konqueror
Classification: Applications
Component: khtml ecma (show other bugs)
Version: 3.5.2
Platform: Slackware Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-30 18:13 UTC by Bryan Elliott
Modified: 2012-06-22 14:53 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bryan Elliott 2006-08-30 18:13:53 UTC
Version:           3.5.2 (using KDE KDE 3.5.2)
Installed from:    Slackware Packages
OS:                Linux

The KHTML/KJS engine does not appear to handle Element.(offset|client)(Width|Height|Top|Left) properly when an element is created and sized within the same function.

Example (test.png has an aspect ratio of 3:2):
<html>
<body>
<script>
function test() {
	var I = document.getElementById("image");
	var imgElem=document.createElement("img");
	imgElem.src="test.png";
	imgElem.style.width=24;
	imgElem.id="image1";
	I.parentNode.replaceChild(imgElem,I);
	// This first alert, under Firefox and IE, pops up as "16"
	// Under Konqy, it pops up as "0"
	alert(imgElem.clientHeight);
}
</script>
<a id="image" href="javascript: test();">Click Me</a><br />
<a href="javascript: alert(document.getElementById('image1').clientHeight);">Click Me next</a>
<!-- The second alert is correctly "16" in FF/IE and Konq. -->
</body>
</html>
Comment 1 Maksim Orlovich 2006-09-26 02:26:18 UTC
I am not quite convinced this is a bug, since at the point you query the size, the image is generally not loaded yet, so the renderer has no reason to know the aspect ratio/the other direction. And I don't see how it's fixable in all cases, since the image may be loading from a very slow server. Do you know what would firefox do in that case by any chance?

What would a real-life use look like?
Comment 2 Bryan Elliott 2006-09-26 03:21:48 UTC
A firefox-only example of real life use is here: http://www.fordi.org/comics.  It's actually what I'm trying to get working in Konqy.  It doesn't yet work in IE, but that's more a w3c compliance issue than an offset* issue.

Your argument doesn't completely explain the failed behavior; an (png/gif/jpeg)'s size can generally be found within its header.  In any case, the above example should work locally (when I'm prototyping), as it does with other browsers.

On very slow servers, I wouldn't expect it to always work, but on a very slow server, you can't really expect much to work properly.
Comment 3 Maksim Orlovich 2006-09-26 04:14:24 UTC
To see the header, one has to start decoding the header. And coincidentally, this testcase doesn't work reliably in firefox either: the first time you open it, it reports clientWidth x clientHeight as 24x24, not 24x16.

Basically, right now you're IMHO relying on pretty subtle implementation details and writing code that has a race condition in it anyway.

Comment 4 Ron Onstenk 2006-11-21 04:12:17 UTC
<a id="image" href="javascript: test();">Click Me</a><br /> 

The height reported by 'alert(imgElem.clientHeight);' should be the
heigth of the content of the <a> tag's value and that is 'Click Me' here.
The font height determine the amount of pixels it need.

Only if no innerTxt/innerHTML for A then the height is 0 (or null) else 
it is the height of the innerTxt/innerHTML (i.e. a image tag to click on).




Comment 5 Bryan Elliott 2006-11-21 05:31:22 UTC
Gotcha.  I think I get now that the offset* params wouldn't work - unless locally - until the image.onload event fires.  I'm modifying my code to fix this race condition.
Comment 6 Michael Zanetti 2008-04-20 17:47:33 UTC
It still behaves the same way in trunk r776286. However it seems to be a site design issue. Close bug as INVALID?
Comment 7 Janek Bevendorff 2012-06-22 14:53:17 UTC
Message from the Bugsquad and Konqueror teams: This bug is closed as outdated, as we do not have the manpower to maintain the KDE3 version anymore. If you still can reproduce this issue with Konqueror 4.8.4 or later, please open a new report. Thank you for your understanding.