Search in sources :

Example 51 with Element

use of com.google.gwt.dom.client.Element in project rstudio by rstudio.

the class FastSelectTable method getEventTargetCell.

protected Element getEventTargetCell(Event event) {
    Element td = DOM.eventGetTarget(event);
    for (; td != null; td = DOM.getParent(td)) {
        // If it's a TD, it might be the one we're looking for.
        if (td.getPropertyString("tagName").equalsIgnoreCase("td")) {
            // Make sure it's directly a part of this table before returning
            // it.
            Element tr = td.getParentElement();
            Element body = tr.getParentElement();
            Element table = body.getParentElement();
            if (table == getElement()) {
                return td;
            }
        }
        // If we run into this table's body, we're out of options.
        if (td == getElement()) {
            return null;
        }
    }
    return null;
}
Also used : Element(com.google.gwt.dom.client.Element)

Example 52 with Element

use of com.google.gwt.dom.client.Element in project rstudio by rstudio.

the class DomUtils method leftRelativeTo.

public static int leftRelativeTo(Element parent, Element child) {
    int left = 0;
    Element el = child;
    while (el != null && el != parent) {
        left += el.getOffsetLeft();
        el = el.getOffsetParent();
    }
    return left;
}
Also used : Element(com.google.gwt.dom.client.Element) Point(org.rstudio.core.client.Point)

Example 53 with Element

use of com.google.gwt.dom.client.Element in project rstudio by rstudio.

the class NodeRelativePosition method toPositionHelper.

private static NodeRelativePosition toPositionHelper(Node here, int[] counter) {
    switch(here.getNodeType()) {
        case Node.TEXT_NODE:
            Text text = (Text) here;
            if (counter[0] <= text.getLength())
                return new NodeRelativePosition(here, counter[0]);
            counter[0] -= text.getLength();
            return null;
        case Node.ELEMENT_NODE:
            Element el = (Element) here;
            String tagName = el.getTagName().toLowerCase();
            if (tagName.equals("br")) {
                if (counter[0] <= 0)
                    return new NodeRelativePosition(here, 0);
                counter[0] -= 1;
                return null;
            } else if (tagName.equals("script") || tagName.equals("style"))
                return null;
            break;
    }
    NodeList<Node> children = here.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        NodeRelativePosition result = toPositionHelper(children.getItem(i), counter);
        if (result != null)
            return result;
    }
    return null;
}
Also used : Element(com.google.gwt.dom.client.Element) Node(com.google.gwt.dom.client.Node) Text(com.google.gwt.dom.client.Text)

Example 54 with Element

use of com.google.gwt.dom.client.Element in project rstudio by rstudio.

the class DomUtils method preventBackspaceCausingBrowserBack.

public static final boolean preventBackspaceCausingBrowserBack(NativeEvent event) {
    if (Desktop.isDesktop())
        return false;
    if (event.getKeyCode() != KeyCodes.KEY_BACKSPACE)
        return false;
    EventTarget target = event.getEventTarget();
    if (target == null)
        return false;
    Element elementTarget = Element.as(target);
    if (!elementTarget.getNodeName().equals("BODY"))
        return false;
    event.preventDefault();
    return true;
}
Also used : Element(com.google.gwt.dom.client.Element)

Example 55 with Element

use of com.google.gwt.dom.client.Element in project rstudio by rstudio.

the class DomUtils method getInnerText.

private static void getInnerText(Node node, StringBuilder out, boolean pasteMode) {
    if (node == null)
        return;
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        switch(child.getNodeType()) {
            case Node.TEXT_NODE:
                out.append(child.getNodeValue());
                break;
            case Node.ELEMENT_NODE:
                Element childEl = (Element) child;
                String tag = childEl.getTagName().toLowerCase();
                // the _moz_dirty breaks are just spurious.
                if (tag.equals("br") && (pasteMode || !childEl.hasAttribute("_moz_dirty")))
                    out.append("\n");
                else if (tag.equals("script") || tag.equals("style"))
                    continue;
                getInnerText(child, out, pasteMode);
                break;
        }
    }
}
Also used : Element(com.google.gwt.dom.client.Element) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

Element (com.google.gwt.dom.client.Element)340 DivElement (com.google.gwt.dom.client.DivElement)19 TableRowElement (com.google.gwt.dom.client.TableRowElement)19 NativeEvent (com.google.gwt.dom.client.NativeEvent)16 Test (org.junit.Test)14 EventTarget (com.google.gwt.dom.client.EventTarget)11 SVGSVGElement (elemental.svg.SVGSVGElement)11 InputElement (com.google.gwt.dom.client.InputElement)10 Node (com.google.gwt.dom.client.Node)9 TableCellElement (com.google.gwt.dom.client.TableCellElement)9 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)8 AnchorElement (com.google.gwt.dom.client.AnchorElement)8 ImageElement (com.google.gwt.dom.client.ImageElement)8 LabelElement (com.google.gwt.dom.client.LabelElement)8 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)8 Image (com.google.gwt.user.client.ui.Image)8 SpanElement (com.google.gwt.dom.client.SpanElement)7 Style (com.google.gwt.dom.client.Style)7 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)7 Widget (com.google.gwt.user.client.ui.Widget)7