Package com.google.gwt.dom.client

Examples of com.google.gwt.dom.client.NativeEvent


                - getElement().getOwnerDocument().getScrollLeft()
                + Util.getRequiredWidth(getElement()) / 2;
        int y = getElement().getAbsoluteTop() - getElement().getScrollTop()
                - getElement().getOwnerDocument().getScrollTop()
                + Util.getRequiredHeight(getElement()) / 2;
        NativeEvent evt = Document.get().createClickEvent(1, 0, 0, x, y, false,
                false, false, false);
        getElement().dispatchEvent(evt);
    }
View Full Code Here


    private final class DefaultDragAndDropEventHandler implements
            NativePreviewHandler {

        @Override
        public void onPreviewNativeEvent(NativePreviewEvent event) {
            NativeEvent nativeEvent = event.getNativeEvent();

            int typeInt = event.getTypeInt();
            if (typeInt == Event.ONKEYDOWN) {
                int keyCode = event.getNativeEvent().getKeyCode();
                if (keyCode == KeyCodes.KEY_ESCAPE) {
                    // end drag if ESC is hit
                    interruptDrag();
                    event.cancel();
                    event.getNativeEvent().preventDefault();
                }
                // no use for handling for any key down event
                return;
            }

            currentDrag.setCurrentGwtEvent(nativeEvent);
            updateDragImagePosition();

            Node targetNode = Node.as(nativeEvent.getEventTarget());
            Element targetElement;
            if (Element.is(targetNode)) {
                targetElement = Element.as(targetNode);
            } else {
                targetElement = targetNode.getParentElement();
            }

            if (Util.isTouchEvent(nativeEvent) || dragElement != null) {
                // to detect the "real" target, hide dragelement temporary and
                // use elementFromPoint
                String display = dragElement.getStyle().getDisplay();
                dragElement.getStyle().setDisplay(Display.NONE);
                try {
                    int x = Util.getTouchOrMouseClientX(nativeEvent);
                    int y = Util.getTouchOrMouseClientY(nativeEvent);
                    // Util.browserDebugger();
                    targetElement = Util.getElementFromPoint(x, y);
                    if (targetElement == null) {
                        // ApplicationConnection.getConsole().log(
                        // "Event on dragImage, ignored");
                        event.cancel();
                        nativeEvent.stopPropagation();
                        return;

                    } else {
                        // ApplicationConnection.getConsole().log(
                        // "Event on dragImage, target changed");
                        // special handling for events over dragImage
                        // pretty much all events are mousemove althout below
                        // kind of happens mouseover
                        switch (typeInt) {
                        case Event.ONMOUSEOVER:
                        case Event.ONMOUSEOUT:
                            // ApplicationConnection
                            // .getConsole()
                            // .log(
                            // "IGNORING proxy image event, fired because of hack or not significant");
                            return;
                        case Event.ONMOUSEMOVE:
                        case Event.ONTOUCHMOVE:
                            VDropHandler findDragTarget = findDragTarget(targetElement);
                            if (findDragTarget != currentDropHandler) {
                                // dragleave on old
                                if (currentDropHandler != null) {
                                    currentDropHandler.dragLeave(currentDrag);
                                    currentDrag.getDropDetails().clear();
                                    serverCallback = null;
                                }
                                // dragenter on new
                                currentDropHandler = findDragTarget;
                                if (findDragTarget != null) {
                                    // ApplicationConnection.getConsole().log(
                                    // "DropHandler now"
                                    // + currentDropHandler
                                    // .getPaintable());
                                }

                                if (currentDropHandler != null) {
                                    currentDrag.setElementOver(targetElement);
                                    currentDropHandler.dragEnter(currentDrag);
                                }
                            } else if (findDragTarget != null) {
                                currentDrag.setElementOver(targetElement);
                                currentDropHandler.dragOver(currentDrag);
                            }
                            // prevent text selection on IE
                            nativeEvent.preventDefault();
                            return;
                        default:
                            // just update element over and let the actual
                            // handling code do the thing
                            // ApplicationConnection.getConsole().log(
                            // "Target just modified on "
                            // + event.getType());
                            currentDrag.setElementOver(targetElement);
                            break;
                        }

                    }
                } catch (RuntimeException e) {
                    // ApplicationConnection.getConsole().log(
                    // "ERROR during elementFromPoint hack.");
                    throw e;
                } finally {
                    dragElement.getStyle().setProperty("display", display);
                }
            }

            switch (typeInt) {
            case Event.ONMOUSEOVER:
                VDropHandler target = findDragTarget(targetElement);

                if (target != null && target != currentDropHandler) {
                    if (currentDropHandler != null) {
                        currentDropHandler.dragLeave(currentDrag);
                        currentDrag.getDropDetails().clear();
                    }

                    currentDropHandler = target;
                    // ApplicationConnection.getConsole().log(
                    // "DropHandler now"
                    // + currentDropHandler.getPaintable());
                    currentDrag.setElementOver(targetElement);
                    target.dragEnter(currentDrag);
                } else if (target == null && currentDropHandler != null) {
                    // ApplicationConnection.getConsole().log("Invalid state!?");
                    currentDropHandler.dragLeave(currentDrag);
                    currentDrag.getDropDetails().clear();
                    currentDropHandler = null;
                }
                break;
            case Event.ONMOUSEOUT:
                Element relatedTarget = Element.as(nativeEvent
                        .getRelatedEventTarget());
                VDropHandler newDragHanler = findDragTarget(relatedTarget);
                if (dragElement != null
                        && dragElement.isOrHasChild(relatedTarget)) {
                    // ApplicationConnection.getConsole().log(
                    // "Mouse out of dragImage, ignored");
                    return;
                }

                if (currentDropHandler != null
                        && currentDropHandler != newDragHanler) {
                    currentDropHandler.dragLeave(currentDrag);
                    currentDrag.getDropDetails().clear();
                    currentDropHandler = null;
                    serverCallback = null;
                }
                break;
            case Event.ONMOUSEMOVE:
            case Event.ONTOUCHMOVE:
                if (currentDropHandler != null) {
                    currentDrag.setElementOver(targetElement);
                    currentDropHandler.dragOver(currentDrag);
                }
                nativeEvent.preventDefault();

                break;

            case Event.ONTOUCHEND:
                /* Avoid simulated event on drag end */
 
View Full Code Here

        // Handlers to Prevent tab to leave the window
        // and backspace to cause browser navigation
        topEventBlocker = new NativePreviewHandler() {
            @Override
            public void onPreviewNativeEvent(NativePreviewEvent event) {
                NativeEvent nativeEvent = event.getNativeEvent();
                if (nativeEvent.getEventTarget().cast() == topTabStop
                        && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB
                        && nativeEvent.getShiftKey()) {
                    nativeEvent.preventDefault();
                }
                if (nativeEvent.getEventTarget().cast() == topTabStop
                        && nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) {
                    nativeEvent.preventDefault();
                }
            }
        };

        bottomEventBlocker = new NativePreviewHandler() {
            @Override
            public void onPreviewNativeEvent(NativePreviewEvent event) {
                NativeEvent nativeEvent = event.getNativeEvent();
                if (nativeEvent.getEventTarget().cast() == bottomTabStop
                        && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB
                        && !nativeEvent.getShiftKey()) {
                    nativeEvent.preventDefault();
                }
                if (nativeEvent.getEventTarget().cast() == bottomTabStop
                        && nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) {
                    nativeEvent.preventDefault();
                }
            }
        };
    }
View Full Code Here

            }
        });
        getWidget().setListener(new MouseEventListener() {
            @Override
            public void contextMenu(ContextMenuEvent event, final Widget widget) {
                final NativeEvent ne = event.getNativeEvent();
                int left = ne.getClientX();
                int top = ne.getClientY();
                top += Window.getScrollTop();
                left += Window.getScrollLeft();
                getClient().getContextMenu().showAt(new ActionOwner() {
                    @Override
                    public String getPaintableId() {
                        return CalendarConnector.this.getPaintableId();
                    }

                    @Override
                    public ApplicationConnection getClient() {
                        return CalendarConnector.this.getClient();
                    }

                    @Override
                    @SuppressWarnings("deprecation")
                    public Action[] getActions() {
                        if (widget instanceof SimpleDayCell) {
                            /*
                             * Month view
                             */
                            SimpleDayCell cell = (SimpleDayCell) widget;
                            Date start = new Date(cell.getDate().getYear(),
                                    cell.getDate().getMonth(), cell.getDate()
                                            .getDate(), 0, 0, 0);

                            Date end = new Date(cell.getDate().getYear(), cell
                                    .getDate().getMonth(), cell.getDate()
                                    .getDate(), 23, 59, 59);

                            return CalendarConnector.this.getActionsBetween(
                                    start, end);

                        } else if (widget instanceof MonthEventLabel) {
                            MonthEventLabel mel = (MonthEventLabel) widget;
                            CalendarEvent event = mel.getCalendarEvent();
                            Action[] actions = CalendarConnector.this
                                    .getActionsBetween(event.getStartTime(),
                                            event.getEndTime());
                            for (Action action : actions) {
                                ((VCalendarAction) action).setEvent(event);
                            }
                            return actions;

                        } else if (widget instanceof DateCell) {
                            /*
                             * Week and Day view
                             */
                            DateCell cell = (DateCell) widget;
                            int slotIndex = DOM.getChildIndex(
                                    cell.getElement(), (Element) ne
                                            .getEventTarget().cast());
                            DateCellSlot slot = cell.getSlot(slotIndex);
                            return CalendarConnector.this.getActionsBetween(
                                    slot.getFrom(), slot.getTo());
                        } else if (widget instanceof DateCellDayEvent) {
View Full Code Here

        }
    }

    public void onTouchStart(TouchStartEvent event) {
        if (activeScrollDelegate == null && event.getTouches().length() == 1) {
            NativeEvent nativeEvent = event.getNativeEvent();
            doTouchStart(nativeEvent);
        } else {
            /*
             * Touch scroll is currenly on (possibly bouncing). Ignore.
             */
 
View Full Code Here

     * com.google.gwt.event.dom.client.KeyPressHandler#onKeyPress(com.google
     * .gwt.event.dom.client.KeyPressEvent)
     */
    @Override
    public void onKeyPress(KeyPressEvent event) {
        NativeEvent nativeEvent = event.getNativeEvent();
        int keyCode = nativeEvent.getKeyCode();
        if (keyCode == 0 && nativeEvent.getCharCode() == ' ') {
            // Provide a keyCode for space to be compatible with FireFox
            // keypress event
            keyCode = CHARCODE_SPACE;
        }
        if (handleKeyNavigation(keyCode,
View Full Code Here

    }

    public static void simulateClickFromTouchEvent(Event touchevent,
            Widget widget) {
        Touch touch = touchevent.getChangedTouches().get(0);
        final NativeEvent createMouseUpEvent = Document.get()
                .createMouseUpEvent(0, touch.getScreenX(), touch.getScreenY(),
                        touch.getClientX(), touch.getClientY(), false, false,
                        false, false, NativeEvent.BUTTON_LEFT);
        final NativeEvent createMouseDownEvent = Document.get()
                .createMouseDownEvent(0, touch.getScreenX(),
                        touch.getScreenY(), touch.getClientX(),
                        touch.getClientY(), false, false, false, false,
                        NativeEvent.BUTTON_LEFT);
        final NativeEvent createMouseClickEvent = Document.get()
                .createClickEvent(0, touch.getScreenX(), touch.getScreenY(),
                        touch.getClientX(), touch.getClientY(), false, false,
                        false, false);

        /*
 
View Full Code Here

    public ButtonStateHandler state() {
        return buttonStateHandler;
    }

    public void click() {
        final NativeEvent event = Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);
        DomEvent.fireNativeEvent(event, this);
    }
View Full Code Here

     * @param popup    Popup to operate on
     * @param preview  Preview event passed to popup's onPreviewNativeEvent method
     */
    public void closeOnEnterOrEscape(PopupPanel popup, NativePreviewEvent preview) {
        if (popup != null && preview != null) {
            NativeEvent event = preview.getNativeEvent();
            if (event != null) {
                if (NativeEventType.KEYDOWN.equals(NativeEventType.convert(event.getType()))) {
                    switch (event.getKeyCode()) {
                    case KeyCodes.KEY_ENTER:
                    case KeyCodes.KEY_ESCAPE:
                        popup.hide();
                        break;
                    }
View Full Code Here

     * @param preview  Preview event passed to popup's onPreviewNativeEvent method
     * @param button   Button to click.
     */
    public void clickButtonOnEscape(NativePreviewEvent preview, Button button) {
        if (preview != null) {
            NativeEvent event = preview.getNativeEvent();
            if (event != null) {
                if (NativeEventType.KEYDOWN.equals(NativeEventType.convert(event.getType()))) {
                    switch (event.getKeyCode()) {
                    case KeyCodes.KEY_ESCAPE:
                        button.click();
                        break;
                    }
                }
View Full Code Here

TOP

Related Classes of com.google.gwt.dom.client.NativeEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.