// For some reason ONMOUSEOUT events are not always received, so we have
    // to use ONMOUSEMOVE that doesn't target the popup
    @Override
    public boolean onEventPreview(Event event) {
      Element target = DOM.eventGetTarget(event);
      boolean eventTargetsPopup = DOM.isOrHasChild(getElement(), target);
      int type = DOM.eventGetType(event);

      // Catch children that use keyboard, so we can unfocus them when
      // hiding
      if (eventTargetsPopup && type == Event.ONKEYPRESS) {
        activeChildren.add(target);
      }

      if (eventTargetsPopup && type == Event.ONMOUSEMOVE) {
        hasHadMouseOver = true;
      }

      if (!eventTargetsPopup && type == Event.ONMOUSEMOVE) {
        if (hasHadMouseOver && hideOnMouseOut) {
          hide();
          return true;
        }
      }

      // Was the TAB key released outside of our popup?
      if (!eventTargetsPopup && type == Event.ONKEYUP && event.getKeyCode() == KeyCodes.KEY_TAB) {
        // Should we hide on focus out (mouse out)?
        if (hideOnMouseOut) {
          hide();
          return true;
        }
      }

      return super.onEventPreview(event);
    }
Beispiel #2
0
 @Override
 public void onBrowserEvent(Event event) {
   if (cancelled) {
     return;
   }
   super.onBrowserEvent(event);
   assertEquals(KEY_CODE, event.getKeyCode());
   // shouldn't throw:
   event.getCharCode();
 }
Beispiel #3
0
 @Override
 public boolean onEventPreview(Event event) {
   int type = DOM.eventGetType(event);
   // "modal"
   if (delayMsec == -1 || temporaryStyle == STYLE_SYSTEM) {
     if (type == Event.ONCLICK) {
       if (DOM.isOrHasChild(getElement(), DOM.eventGetTarget(event))) {
         fade();
         return false;
       }
     } else if (type == Event.ONKEYDOWN && event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
       fade();
       return false;
     }
     if (temporaryStyle == STYLE_SYSTEM) {
       return true;
     } else {
       return false;
     }
   }
   // default
   switch (type) {
     case Event.ONMOUSEMOVE:
       if (x < 0) {
         x = DOM.eventGetClientX(event);
         y = DOM.eventGetClientY(event);
       } else if (Math.abs(DOM.eventGetClientX(event) - x) > mouseMoveThreshold
           || Math.abs(DOM.eventGetClientY(event) - y) > mouseMoveThreshold) {
         startDelay();
       }
       break;
     case Event.ONMOUSEDOWN:
     case Event.ONMOUSEWHEEL:
     case Event.ONSCROLL:
       startDelay();
       break;
     case Event.ONKEYDOWN:
       if (event.getRepeat()) {
         return true;
       }
       startDelay();
       break;
     default:
       break;
   }
   return true;
 }
Beispiel #4
0
  @Override
  public void onBrowserEvent(Event event) {
    if (disabled || readonly) {
      return;
    }
    final Element targ = DOM.eventGetTarget(event);

    if (DOM.eventGetType(event) == Event.ONMOUSEWHEEL) {
      processMouseWheelEvent(event);
    } else if (dragging || targ == handle) {
      processHandleEvent(event);
    } else if (targ == smaller) {
      decreaseValue(true);
    } else if (targ == bigger) {
      increaseValue(true);
    } else if (DOM.eventGetType(event) == Event.MOUSEEVENTS) {
      processBaseEvent(event);
    } else if ((BrowserInfo.get().isGecko() && DOM.eventGetType(event) == Event.ONKEYPRESS)
        || (!BrowserInfo.get().isGecko() && DOM.eventGetType(event) == Event.ONKEYDOWN)) {

      if (handleNavigation(event.getKeyCode(), event.getCtrlKey(), event.getShiftKey())) {

        feedbackPopup.show();

        delayedValueUpdater.trigger();

        DOM.eventPreventDefault(event);
        DOM.eventCancelBubble(event, true);
      }
    } else if (targ.equals(getElement()) && DOM.eventGetType(event) == Event.ONFOCUS) {
      feedbackPopup.show();
    } else if (targ.equals(getElement()) && DOM.eventGetType(event) == Event.ONBLUR) {
      feedbackPopup.hide();
    } else if (DOM.eventGetType(event) == Event.ONMOUSEDOWN) {
      feedbackPopup.show();
      processBaseEvent(event);
    }
    if (Util.isTouchEvent(event)) {
      event.preventDefault(); // avoid simulated events
      event.stopPropagation();
    }
    if (client != null) {
      client.handleTooltipEvent(event, this);
    }
  }
  private static KeyEvent toKeyEvent(Event e) {
    Key key = KeyCodeMapper.getKey(e.getKeyCode());

    Set<ModifierKey> modifiers = new HashSet<>();
    if (e.getCtrlKey()) {
      modifiers.add(ModifierKey.CONTROL);
    }
    if (e.getAltKey()) {
      modifiers.add(ModifierKey.ALT);
    }
    if (e.getShiftKey()) {
      modifiers.add(ModifierKey.SHIFT);
    }
    if (e.getMetaKey()) {
      modifiers.add(ModifierKey.META);
    }
    return new KeyEvent(key, (char) e.getCharCode(), modifiers);
  }
Beispiel #6
0
  private boolean keyupChecker(Event e) {
    int stroke = e.getKeyCode();

    searchFieldScale();

    switch (stroke) {
      case 8: // backspace
        if (isMultiple && backstrokeLength < 1 && choices > 0) {
          keydownBackstroke();
        } else if (pendingBackstroke == null) {
          resultClearHighlight();
          resultsSearch();
        }
        break;

      case 13: // enter
        e.preventDefault();
        if (resultsShowing) {
          resultSelect(e);
        }
        return false;
      case 27: // escape
        if (resultsShowing) {
          resultsHide();
        }
        return false;
      case 9:
      case 38:
      case 40:
      case 16:
      case 91:
      case 17:
        // do nothing
        break;
      default:
        resultsSearch();
        break;
    }

    return true;
  }
Beispiel #7
0
  private boolean keydownChecker(Event e) {
    int stroke = e.getKeyCode();
    searchFieldScale();

    if (stroke != 8 && pendingBackstroke != null) {
      clearBackstroke();
    }

    switch (stroke) {
      case 8: // backspace
        backstrokeLength = searchField.val().length();
        break;

      case 9: // tab
        if (resultsShowing && !isMultiple) {
          resultSelect(e);
        }
        mouseOnContainer = false;
        break;

      case 13: // enter
        e.preventDefault();
        return false;

      case 38: // up arrow
        e.preventDefault();
        keyupArrow();
        return false;

      case 40: // down arrow
        this.keydownArrow();
        return false;
    }

    return true;
  }
  @Override
  public void onBrowserEvent(Event event) {
    if (!isEnabled()) return;

    super.onBrowserEvent(event);

    if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
      int type = DOM.eventGetType(event);
      char keyCode = (char) event.getKeyCode();
      switch (type) {
        case Event.ONKEYDOWN:
          if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') {
            if (iDown != null) setResource(iDown);
          }
          break;
        case Event.ONKEYUP:
          if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') {
            setResource(iUp);
            onClick();
          }
          break;
      }
    }
  }
Beispiel #9
0
    @Override
    public void onKeyDown(Event event) {

      if (SliderView.this.isDisabled()) {
        return;
      }

      double oldValue = getValue();

      int keyCode = event.getKeyCode();

      if (isVertical()) {

        switch (keyCode) {
          case KeyCodes.KEY_UP:
            {
              double newValue = getValue() + step;
              if (newValue <= getMaxValue()) {
                setValue(newValue);
              }
            }
            break;
          case KeyCodes.KEY_DOWN:
            {
              double newValue = getValue() - step;
              if (newValue >= getMinValue()) {
                setValue(newValue);
              }
            }
            break;
        }
      } else {
        switch (keyCode) {
          case KeyCodes.KEY_RIGHT:
            {
              double newValue = getValue() + step;
              if (newValue <= getMaxValue()) {
                setValue(newValue);
              }
            }
            break;
          case KeyCodes.KEY_LEFT:
            {
              double newValue = getValue() - step;
              if (newValue >= getMinValue()) {
                setValue(newValue);
              }
            }
            break;
        }
      }

      if (oldValue != getValue()) {
        if (showValueTooltip()) {

          if (valueTooltipShowTimer != null) {
            valueTooltipShowTimer.cancel();
          }

          valueTooltipShowTimer =
              new Timer() {
                @Override
                public void run() {
                  valueTooltip.setVisible(false);
                }
              };

          valueTooltipShowTimer.schedule(1000);
        }

        ActionEvent.fire(SliderView.this, SliderView.this);
      }
    }
Beispiel #10
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;
        }
    }
  }