isVisible only tells you if visibility was explicitly set on the
widget. If the widget is invisible because it's parent is invisible
then it will not tell you that. This is trait of the DOM in general.
The only way to find out is to walk the DOM tree upwards checking to
see if the computed style at each parent is display:none. I have
written some functions to do this but it isn't too easy because GWT
doesn't support getComputedStyle so I had to write it myself. See code
below.
public class DOMUtils {
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 "";
}-*/;
static public boolean elementIsVisible(Element el) {
while(el != null) {
String vis = DOMUtils.getComputedStyleProperty(el,
"visibility");
if (vis.equalsIgnoreCase("hidden"))
return false;
String dis = DOMUtils.getComputedStyleProperty(el,
"display");
if (dis.equalsIgnoreCase("none"))
return false;
el = el.getParentElement();
}
return true;
}
}
I need to optimize getComputedStyleProperty but haven't had time yet.
It could actually return a Style object which would fit in better with
the GWT model.
On Apr 28, 5:58 pm, bryce l <[email protected]> wrote:
> I submitted this bug yesterday, however I should have posted it in
> groups first to determine if I was doing something wrong.
>
> I think this is a bug in GWT, but I'm not sure. There when I add a
> widget to a panel then add that panel to a TabPanel, calling
> isVisible() on the widget always returns true, however the panel
> correctly returns the visibility.
>
> http://code.google.com/p/google-web-toolkit/issues/detail?id=4892
> Here is the code:
>
> final TabPanel tabPanel = new TabPanel();
>
> final FlowPanel flowPanel = new FlowPanel();
> final Widget html = new HTML("tab1");
> flowPanel.add(html);
>
> final Widget htm2 = new HTML("tab2");
>
> tabPanel.add(flowPanel,"1");
> tabPanel.add(htm2,"2");
> tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {
> �...@override
> public void onSelection(SelectionEvent<Integer> event) {
> GWT.log("panel: "+flowPanel.isVisible(), null);
> GWT.log("child: "+html.isVisible(), null);
> GWT.log("panel2: "+htm2.isVisible(), null);
>
> if (flowPanel.isVisible() != html.isVisible()) {
> GWT.log("error unexpected", null);
> }
> }
> });
>
> I am doing something wrong?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group
> athttp://groups.google.com/group/google-web-toolkit?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.