Ejemplo n.º 1
0
 /**
  * Hides the popup and detaches it from the page. This has no effect if it is not currently
  * showing.
  */
 public void hide() {
   hide(false);
 }
Ejemplo n.º 2
0
  /**
   * Preview the {@link NativePreviewEvent}.
   *
   * @param event the {@link NativePreviewEvent}
   */
  private void previewNativeEvent(NativePreviewEvent event) {
    // If the event has been canceled or consumed, ignore it
    if (event.isCanceled() || (!previewAllNativeEvents && event.isConsumed())) {
      // We need to ensure that we cancel the event even if its been consumed so
      // that popups lower on the stack do not auto hide
      if (modal) {
        event.cancel();
      }
      return;
    }

    // Fire the event hook and return if the event is canceled
    onPreviewNativeEvent(event);
    if (event.isCanceled()) {
      return;
    }

    // If the event targets the popup or the partner, consume it
    Event nativeEvent = Event.as(event.getNativeEvent());
    boolean eventTargetsPopupOrPartner =
        eventTargetsPopup(nativeEvent) || eventTargetsPartner(nativeEvent);
    if (eventTargetsPopupOrPartner) {
      event.consume();
    }

    // Cancel the event if it doesn't target the modal popup. Note that the
    // event can be both canceled and consumed.
    if (modal) {
      event.cancel();
    }

    // Switch on the event type
    int type = nativeEvent.getTypeInt();

    if ((type & Event.TOUCHEVENTS) != 0) { // it is a touch event
      CancelEventTimer.touchEventOccured();
    }

    if ((type & Event.MOUSEEVENTS) != 0) {
      if (CancelEventTimer.cancelMouseEvent()) {
        return;
      }
    }

    switch (type) {
      case Event.ONKEYDOWN:
        {
          if (!onKeyDownPreview(
              (char) nativeEvent.getKeyCode(),
              KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
            event.cancel();
          }
          return;
        }
      case Event.ONKEYUP:
        {
          if (!onKeyUpPreview(
              (char) nativeEvent.getKeyCode(),
              KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
            event.cancel();
          }
          return;
        }
      case Event.ONKEYPRESS:
        {
          if (!onKeyPressPreview(
              (char) nativeEvent.getKeyCode(),
              KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
            event.cancel();
          }
          return;
        }

      case Event.ONMOUSEDOWN:
      case Event.ONTOUCHSTART:
        // Don't eat events if event capture is enabled, as this can
        // interfere with dialog dragging, for example.
        if (DOM.getCaptureElement() != null) {
          event.consume();
          return;
        }

        if (!eventTargetsPopupOrPartner && autoHide) {
          hide(true);
          return;
        }
        break;
      case Event.ONMOUSEUP:
      case Event.ONMOUSEMOVE:
      case Event.ONCLICK:
      case Event.ONDBLCLICK:
      case Event.ONTOUCHEND:
        {
          // Don't eat events if event capture is enabled, as this can
          // interfere with dialog dragging, for example.
          if (DOM.getCaptureElement() != null) {
            event.consume();
            return;
          }
          break;
        }

      case Event.ONFOCUS:
        {
          Element target = nativeEvent.getTarget();
          if (modal && !eventTargetsPopupOrPartner && (target != null)) {
            blur(target);
            event.cancel();
            return;
          }
          break;
        }
    }
  }