diff options
Diffstat (limited to 'src/com/vaadin/terminal/gwt/client/Util.java')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/Util.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/Util.java b/src/com/vaadin/terminal/gwt/client/Util.java index 6095c35c85..2ee4ba8cbd 100644 --- a/src/com/vaadin/terminal/gwt/client/Util.java +++ b/src/com/vaadin/terminal/gwt/client/Util.java @@ -816,6 +816,11 @@ public class Util { * <literal>element</literal> is not part of any child component, null is * returned. * + * This method returns the immediate child of the parent that contains the + * element. See + * {@link #getPaintableForElement(ApplicationConnection, Container, Element)} + * for the deepest nested paintable of parent that contains the element. + * * @param client * A reference to ApplicationConnection * @param parent @@ -855,6 +860,56 @@ public class Util { } /** + * Locates the nested child component of <literal>parent</literal> which + * contains the element <literal>element</literal>. The child component is + * also returned if "element" is part of its caption. If + * <literal>element</literal> is not part of any child component, null is + * returned. + * + * This method returns the deepest nested Paintable. See + * {@link #getChildPaintableForElement(ApplicationConnection, Container, Element)} + * for the immediate child component of parent that contains the element. + * + * @param client + * A reference to ApplicationConnection + * @param parent + * The widget that contains <literal>element</literal>. + * @param element + * An element that is a sub element of the parent + * @return The Paintable which the element is a part of. Null if the element + * does not belong to a child. + */ + public static Paintable getPaintableForElement( + ApplicationConnection client, Container parent, Element element) { + Element rootElement = ((Widget) parent).getElement(); + while (element != null && element != rootElement) { + Paintable paintable = client.getPaintable(element); + if (paintable == null) { + String ownerPid = VCaption.getCaptionOwnerPid(element); + if (ownerPid != null) { + paintable = client.getPaintable(ownerPid); + } + } + + if (paintable != null) { + // check that inside the rootElement + while (element != null && element != rootElement) { + element = (Element) element.getParentElement(); + } + if (element != rootElement) { + return null; + } else { + return paintable; + } + } + + element = (Element) element.getParentElement(); + } + + return null; + } + + /** * Will (attempt) to focus the given DOM Element. * * @param el |