Thursday, September 23, 2010

Re: GetOffsetWidth and css

You need to get the computed style property. GWT doesn't support this.
I wrote a function to get the value

static public native String getComputedStyleProperty(Element el,
String property) /*-{
if (window['getComputedStyle']) { // W3C DOM method
if (property === 'float')
property = 'cssFloat';

var value = el.style[property], computed;

if (!value) {
computed = el['ownerDocument']['defaultView']
['getComputedStyle'](el, null);
if (computed) { // test computed before touching for
safari
value = computed[property];
}
}
return value;

} else if (el['currentStyle']) {
var value;

switch(property) {
case 'opacity' :// IE opacity uses filter
value = 100;
try { // will error if no DXImageTransform
value =
el.filters['DXImageTransform.Microsoft.Alpha'].opacity;

} catch(e) {
try { // make sure its in the document
value = el.filters('alpha').opacity;
} catch(err) {
}
}
return value / 100;
case 'float': // fix reserved word
property = 'styleFloat'; // fall through
default:
value = el['currentStyle'] ? el['currentStyle']
[property] : null;
return ( el.style[property] || value );
}
}
return "";
}-*/;

With some more time it could be written in a more GWT friendly manor
but it works currently. Ideally GWT should implement this.


On Sep 23, 9:13 am, Christophe <christophe.devri...@gmail.com> wrote:
> (I'm using GWT 2.1.0M3)
>
> I'm putting an element in an AbsolutePanel, which has some css classes
> (injected classes). One of the things these classes change is the
> width and height of the element.
>
> The code needs to know the element's width and height, and so it tries
> to get them with the getOffsetWidth and getOffsetHeight methods.
> However these give the width and height of the element before the css
> adjustments, not the real on-screen ones, and as a result all sorts of
> things get misplaced.
>
> Is there a way to get the "real" width and height of an element,
> whether or not these have been adjusted with css ?
>
> Cheers,
>
> Christophe

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment