Java Code Examples for com.google.gwt.user.client.DOM#getCaptureElement()

The following examples show how to use com.google.gwt.user.client.DOM#getCaptureElement() . 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: Wizard.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEventPreview(Event event) {
  // Always allow event if capturing is enabled
  if (DOM.getCaptureElement() != null) {
    return true;
  }

  // If this is a modal wizard then only allow it if the target element is a child of this wizard
  if (modal) {
    Element target = DOM.eventGetTarget(event);
    return (target != null && DOM.isOrHasChild(getElement(), target));
  } else {
    return super.onEventPreview(event);
  }
}
 
Example 2
Source File: WidgetComboBox.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
  }
}