Java Code Examples for com.google.gwt.dom.client.NativeEvent#getEventTarget()
The following examples show how to use
com.google.gwt.dom.client.NativeEvent#getEventTarget() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VLayoutDragDropMouseHandler.java From cuba with Apache License 2.0 | 5 votes |
private boolean isChildOfRoot(NativeEvent event) { EventTarget eventTarget = event.getEventTarget(); Element targetElement = Element.as(eventTarget); if (root.getElement() != targetElement && root.getElement().isOrHasChild(targetElement)) { return true; } return false; }
Example 2
Source File: VLayoutDragDropMouseHandler.java From cuba with Apache License 2.0 | 5 votes |
private boolean isElementNode(NativeEvent event) { EventTarget eventTarget = event.getEventTarget(); if (Element.is(eventTarget)) { return true; } return false; }
Example 3
Source File: VSliderPanel.java From vaadin-sliderpanel with MIT License | 5 votes |
/** * checks whether the event comes from an element within the slider dom tree * * @param event NativeEvent * @return true when events comes from within */ private boolean eventTargetsPopup(NativeEvent event) { EventTarget target = event.getEventTarget(); if (Element.is(target)) { return getElement().isOrHasChild(Element.as(target)); } return false; }
Example 4
Source File: VSliderPanel.java From vaadin-sliderpanel with MIT License | 5 votes |
/** * checks whether the event come's from a elements that lays visually within the slider<br> * it doesn't lay directly in the dom tree - for example dropdown popups * * @param event NativeEvent * @return true when events comes from within */ private boolean eventTargetsInnerElementsPopover(NativeEvent event) { EventTarget target = event.getEventTarget(); if (Element.is(target)) { Element targetElement = Element.as(target); int absoluteLeft = targetElement.getAbsoluteLeft(); int absoluteTop = targetElement.getAbsoluteTop(); return contentNode.getAbsoluteLeft() <= absoluteLeft && contentNode.getAbsoluteRight() >= absoluteLeft && contentNode.getAbsoluteTop() <= absoluteTop && contentNode.getAbsoluteBottom() >= absoluteTop; } return false; }
Example 5
Source File: VLayoutDragDropMouseHandler.java From cuba with Apache License 2.0 | 4 votes |
/** * Initiates the drag only on the first move event * * @param originalEvent * the original Mouse Down event. Only events on elements are * passed in here (Element.as() is safe without check here) */ protected void initiateDragOnMove(final NativeEvent originalEvent) { EventTarget eventTarget = originalEvent.getEventTarget(); boolean stopEventPropagation = false; Element targetElement = Element.as(eventTarget); Widget target = WidgetUtil.findWidget(targetElement, null); Widget targetParent = target.getParent(); // Stop event propagation and prevent default behaviour if // - target is *not* a VTabsheet.TabCaption or // - drag mode is caption mode and widget is caption boolean isTabCaption = WidgetUtil.findWidget(target.getElement(), TabCaption.class) != null; boolean isCaption = VDragDropUtil.isCaptionOrCaptionless(targetParent); if (dragMode == LayoutDragMode.CLONE && isTabCaption == false) { stopEventPropagation = true; // overwrite stopEventPropagation flag again if // - root implements VHasDragFilter but // - target is not part of its drag filter and // - target is not a GWT Label based widget if (root instanceof VHasDragFilter) { if (((VHasDragFilter) root).getDragFilter() .isDraggable(target) == false && (target instanceof LabelBase) == false) { stopEventPropagation = false; } } if (root instanceof VHasGrabFilter) { VGrabFilter grabFilter = ((VHasGrabFilter) root).getGrabFilter(); if (grabFilter != null && !grabFilter.canBeGrabbed(root, target)) { return; } } } if (dragMode == LayoutDragMode.CAPTION && isCaption) { stopEventPropagation = true; } if (isElementNotDraggable(targetElement)) { stopEventPropagation = false; } if (stopEventPropagation) { originalEvent.stopPropagation(); originalEvent.preventDefault(); // Manually focus as preventDefault() will also cancel focus targetElement.focus(); } mouseDownHandlerReg = Event .addNativePreviewHandler(new NativePreviewHandler() { @Override public void onPreviewNativeEvent(NativePreviewEvent event) { int type = event.getTypeInt(); if (type == Event.ONMOUSEUP || type == Event.ONTOUCHCANCEL || type == Event.ONTOUCHEND) { mouseDownHandlerReg.removeHandler(); mouseDownHandlerReg = null; } else if (type == Event.ONMOUSEMOVE || type == Event.ONTOUCHMOVE) { mouseDownHandlerReg.removeHandler(); mouseDownHandlerReg = null; initiateDrag(originalEvent); } } }); }
Example 6
Source File: WidgetComboBox.java From consulo with Apache License 2.0 | 4 votes |
/** * See class docs */ @Override public void onPreviewNativeEvent(Event.NativePreviewEvent event) { NativeEvent nativeEvent = event.getNativeEvent(); EventTarget eventTarget = nativeEvent.getEventTarget(); if (!Element.is(eventTarget)) //chrome fix { return; } Element target = (Element)Element.as(eventTarget); int type = event.getTypeInt(); if (type == Event.ONKEYDOWN) { setKeyPressed(true); if (DOM.getCaptureElement() != null) return; boolean eventTargetsPopup = (target != null) && DOM.isOrHasChild(getElement(), target); int button = nativeEvent.getKeyCode(); boolean alt = nativeEvent.getAltKey(); boolean ctrl = nativeEvent.getCtrlKey(); boolean shift = nativeEvent.getShiftKey(); boolean hasModifiers = alt || ctrl || shift; if (eventTargetsPopup && isListPanelOpened()) { if (button == KeyCodes.KEY_UP && !hasModifiers) { moveCursor(-1); cancelAndPrevent(event); } else if (button == KeyCodes.KEY_DOWN && !hasModifiers) { moveCursor(1); cancelAndPrevent(event); } else if (button == KeyCodes.KEY_ENTER && !hasModifiers) { select(getHighlightRow()); getChoiceButton().setFocus(false); ChangeEvent changeEvent = new ComboBoxChangeEvent(getHighlightRow(), ComboBoxChangeEvent.ChangeEventInputDevice.KEYBOARD); fireEvent(changeEvent); setKeyPressed(false); } else if (button == KeyCodes.KEY_ESCAPE && !hasModifiers) { hideList(); setKeyPressed(false); } else if (button == KeyCodes.KEY_TAB && (!hasModifiers || !alt && !ctrl && shift)) { hideList(); setKeyPressed(false); } } else if (eventTargetsPopup && !hasModifiers && button == KeyCodes.KEY_ENTER && getModel().getCount() > 0) { showList(true); } } else if (type == Event.ONKEYUP) { setKeyPressed(false); } }