public static boolean fire(NativeEvent event, HasHandlers target) {
   NativeKeyPressEvent evt = new NativeKeyPressEvent(event);
   target.fireEvent(evt);
   if (evt.isCanceled()) {
     event.preventDefault();
     return true;
   }
   return false;
 }
예제 #2
0
 private static boolean onOpen(NativeEvent e, int idx) {
   if (link.handleAsClick(e.<Event>cast())) {
     PatchSetsBox t = getRevisionBox(e);
     if (t != null) {
       t.onOpenRow(idx);
       e.preventDefault();
       return false;
     }
   }
   return true;
 }
예제 #3
0
  @Override
  public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (allActiveDialogs_.get(allActiveDialogs_.size() - 1) != this) return;

    if (event.getTypeInt() == Event.ONKEYDOWN) {
      NativeEvent nativeEvent = event.getNativeEvent();
      switch (nativeEvent.getKeyCode()) {
        case KeyCodes.KEY_ENTER:
          ThemedButton defaultButton =
              defaultOverrideButton_ == null ? okButton_ : defaultOverrideButton_;
          if ((defaultButton != null) && defaultButton.isEnabled()) {
            nativeEvent.preventDefault();
            nativeEvent.stopPropagation();
            event.cancel();
            defaultButton.click();
          }
          break;
        case KeyCodes.KEY_ESCAPE:
          if (escapeDisabled_) break;
          if (cancelButton_ == null) {
            if ((okButton_ != null) && okButton_.isEnabled()) {
              nativeEvent.preventDefault();
              nativeEvent.stopPropagation();
              event.cancel();
              okButton_.click();
            }
          } else if (cancelButton_.isEnabled()) {
            nativeEvent.preventDefault();
            nativeEvent.stopPropagation();
            event.cancel();
            cancelButton_.click();
          }
          break;
      }
    }
  }
 /* (non-Javadoc)
  * @see com.google.gwt.cell.client.AbstractCell#onBrowserEvent(com.google.gwt.cell.client.Cell.Context, com.google.gwt.dom.client.Element, java.lang.Object, com.google.gwt.dom.client.NativeEvent, com.google.gwt.cell.client.ValueUpdater)
  */
 @Override
 public void onBrowserEvent(
     Context context,
     Element parent,
     CellTreeNode value,
     NativeEvent event,
     ValueUpdater<CellTreeNode> valueUpdater) {
   if (event.getType().equals(BrowserEvents.CONTEXTMENU)) {
     event.preventDefault();
     event.stopPropagation();
     if (MatContext.get().getMeasureLockService().checkForEditPermission()) {
       onRightClick(value, (Event) event, parent);
     }
   } else {
     super.onBrowserEvent(context, parent, value, event, valueUpdater);
   }
 }
예제 #5
0
  private void swallowEvents(Object object) {
    NativeEvent event = (NativeEvent) object;

    // Suppress save / quit events from reaching the browser
    KeyCombination keys = new KeyCombination(event);
    int keyCode = keys.getKeyCode();
    int modifiers = keys.getModifier();

    boolean isSaveQuitKey = keyCode == KeyCodes.KEY_S || keyCode == KeyCodes.KEY_W;

    boolean isSaveQuitModifier =
        BrowseCap.isMacintosh()
            ? modifiers == KeyboardShortcut.META
            : modifiers == KeyboardShortcut.CTRL;

    if (isSaveQuitKey && isSaveQuitModifier) event.preventDefault();
  }
예제 #6
0
  private boolean dispatch(
      KeyboardShortcut shortcut,
      AppCommandBindings bindings,
      NativeEvent event,
      Map<AppCommand, Boolean> maskedCommandsMap) {
    KeySequence keys = shortcut.getKeySequence();

    // If the shortcut manager is disabled, bail
    if (!isEnabled()) return false;

    // If we have no binding, bail
    if (!bindings.containsKey(keys)) return false;

    AppCommand command = bindings.getCommand(keys, editorMode_, maskedCommandsMap);
    if (command == null) return false;

    event.preventDefault();
    command.executeFromShortcut();
    return true;
  }
예제 #7
0
  private boolean dispatch(
      KeyboardShortcut shortcut,
      Map<KeyboardShortcut, ArrayList<AppCommand>> bindings,
      NativeEvent event,
      Map<AppCommand, Boolean> maskedCommandsMap) {
    if (!bindings.containsKey(shortcut) || bindings.get(shortcut) == null) return false;

    AppCommand command = null;
    for (int i = 0; i < bindings.get(shortcut).size(); i++) {
      command = bindings.get(shortcut).get(i);
      if (command != null) {
        boolean enabled = isEnabled() && command.isEnabled();

        // some commands want their keyboard shortcut to pass through
        // to the browser when they are disabled (e.g. Cmd+W)
        if (!enabled && !command.preventShortcutWhenDisabled()) return false;

        // if we've remapped an AppCommand to a new binding, it's
        // implicitly disabled
        if (maskedCommandsMap != null && maskedCommandsMap.containsKey(command)) {
          command = null;
          continue;
        }

        event.preventDefault();

        // if this command is enabled, execute it and stop looking
        if (enabled) {
          command.executeFromShortcut();
          break;
        }
      }
    }

    return command != null;
  }
예제 #8
0
 @Override
 public boolean onBrowserEvent(
     Cell.Context context,
     Element parent,
     C value,
     NativeEvent event,
     ValueUpdater<C> cValueUpdater) {
   resizer = cell.getResizeElement().cast();
   if (event.getEventTarget().equals(resizer)) {
     String eventType = event.getType();
     if (BrowserEvents.MOUSEDOWN.equals(eventType)) {
       startPosition = positionController.getPosition(Event.getCurrentEvent());
       int events =
           Event.getTypeInt(BrowserEvents.MOUSEMOVE) | Event.getTypeInt(BrowserEvents.MOUSEUP);
       DOM.setEventListener(resizer, eventListener);
       DOM.sinkEvents(resizer, events);
       DOM.setCapture(resizer);
       startSize = cell.getSize(parent);
       event.preventDefault();
       return true;
     }
   }
   return false;
 }
예제 #9
0
 private boolean cancel(NativeEvent event, boolean returnValue) {
   event.stopPropagation();
   event.preventDefault();
   return returnValue;
 }
예제 #10
0
파일: GwtInput.java 프로젝트: QiXi/vtm
  private void handleEvent(NativeEvent e) {

    if (e.getType().equals("contextmenu")) {
      e.preventDefault();
      e.stopPropagation();
      return;
    }

    if (e.getType().equals("mousedown")) {
      if (!e.getEventTarget().equals(canvas) || touched[0]) {
        float mouseX = (int) getRelativeX(e, canvas);
        float mouseY = (int) getRelativeY(e, canvas);
        if (mouseX < 0
            || mouseX > Gdx.graphics.getWidth()
            || mouseY < 0
            || mouseY > Gdx.graphics.getHeight()) {
          hasFocus = false;
        }
        return;
      }
      hasFocus = true;
      this.justTouched = true;
      this.touched[0] = true;
      this.pressedButtons.add(getButton(e.getButton()));
      this.deltaX[0] = 0;
      this.deltaY[0] = 0;
      if (isCursorCatched()) {
        this.touchX[0] += getMovementXJSNI(e);
        this.touchY[0] += getMovementYJSNI(e);
      } else {
        this.touchX[0] = (int) getRelativeX(e, canvas);
        this.touchY[0] = (int) getRelativeY(e, canvas);
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      if (processor != null)
        if (processor.touchDown(touchX[0], touchY[0], 0, getButton(e.getButton()))) {
          e.preventDefault();
          e.stopPropagation();
        }
    }

    if (e.getType().equals("mousemove")) {
      if (isCursorCatched()) {
        this.deltaX[0] = (int) getMovementXJSNI(e);
        this.deltaY[0] = (int) getMovementYJSNI(e);
        this.touchX[0] += getMovementXJSNI(e);
        this.touchY[0] += getMovementYJSNI(e);
      } else {
        this.deltaX[0] = (int) getRelativeX(e, canvas) - touchX[0];
        this.deltaY[0] = (int) getRelativeY(e, canvas) - touchY[0];
        this.touchX[0] = (int) getRelativeX(e, canvas);
        this.touchY[0] = (int) getRelativeY(e, canvas);
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      if (processor != null) {
        if (touched[0]) processor.touchDragged(touchX[0], touchY[0], 0);
        else processor.mouseMoved(touchX[0], touchY[0]);
      }
    }

    if (e.getType().equals("mouseup")) {
      if (!touched[0]) return;
      this.pressedButtons.remove(getButton(e.getButton()));
      this.touched[0] = pressedButtons.size() > 0;
      if (isCursorCatched()) {
        this.deltaX[0] = (int) getMovementXJSNI(e);
        this.deltaY[0] = (int) getMovementYJSNI(e);
        this.touchX[0] += getMovementXJSNI(e);
        this.touchY[0] += getMovementYJSNI(e);
      } else {
        this.deltaX[0] = (int) getRelativeX(e, canvas) - touchX[0];
        this.deltaY[0] = (int) getRelativeY(e, canvas) - touchY[0];
        this.touchX[0] = (int) getRelativeX(e, canvas);
        this.touchY[0] = (int) getRelativeY(e, canvas);
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      this.touched[0] = false;
      if (processor != null) processor.touchUp(touchX[0], touchY[0], 0, getButton(e.getButton()));
    }

    if (e.getType().equals("keydown") && hasFocus) {
      // System.out.println("keydown");
      int code = keyForCode(e.getKeyCode());
      if (code == 67) {
        e.preventDefault();
        if (processor != null) {
          processor.keyDown(code);
          processor.keyTyped('\b');
        }
      } else {
        this.pressedKeys.add(code);
        if (processor != null) processor.keyDown(code);
      }
    }

    if (e.getType().equals("keypress") && hasFocus) {
      // System.out.println("keypress");
      char c = (char) e.getCharCode();
      if (processor != null) processor.keyTyped(c);
    }

    if (e.getType().equals("keyup") && hasFocus) {
      // System.out.println("keyup");
      int code = keyForCode(e.getKeyCode());
      this.pressedKeys.remove(code);
      if (processor != null) processor.keyUp(code);
    }

    if (e.getType().equals("touchstart")) {
      this.justTouched = true;
      JsArray<Touch> touches = e.getChangedTouches();
      for (int i = 0, j = touches.length(); i < j; i++) {
        Touch touch = touches.get(i);
        int touchId = touch.getIdentifier();
        touched[touchId] = true;
        double r = GwtGraphics.getDevicePixelRatioJSNI();
        int x = (int) (touch.getRelativeX(canvas) * r);
        int y = (int) (touch.getRelativeY(canvas) * r);
        touchX[touchId] = x;
        touchY[touchId] = y;
        deltaX[touchId] = 0;
        deltaY[touchId] = 0;
        if (processor != null) {
          processor.touchDown(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT);
        }
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      e.preventDefault();
    }
    if (e.getType().equals("touchmove")) {
      JsArray<Touch> touches = e.getChangedTouches();
      for (int i = 0, j = touches.length(); i < j; i++) {
        Touch touch = touches.get(i);
        int touchId = touch.getIdentifier();
        double r = GwtGraphics.getDevicePixelRatioJSNI();
        int x = (int) (touch.getRelativeX(canvas) * r);
        int y = (int) (touch.getRelativeY(canvas) * r);
        deltaX[touchId] = x - touchX[touchId];
        deltaY[touchId] = y - touchY[touchId];
        touchX[touchId] = x;
        touchY[touchId] = y;
        if (processor != null) {
          processor.touchDragged(touchX[touchId], touchY[touchId], touchId);
        }
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      e.preventDefault();
    }
    if (e.getType().equals("touchcancel")) {
      JsArray<Touch> touches = e.getChangedTouches();
      for (int i = 0, j = touches.length(); i < j; i++) {
        Touch touch = touches.get(i);
        int touchId = touch.getIdentifier();
        touched[touchId] = false;
        double r = GwtGraphics.getDevicePixelRatioJSNI();
        int x = (int) (touch.getRelativeX(canvas) * r);
        int y = (int) (touch.getRelativeY(canvas) * r);
        deltaX[touchId] = x - touchX[touchId];
        deltaY[touchId] = y - touchY[touchId];
        touchX[touchId] = x;
        touchY[touchId] = y;
        if (processor != null) {
          processor.touchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT);
        }
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      e.preventDefault();
    }
    if (e.getType().equals("touchend")) {
      JsArray<Touch> touches = e.getChangedTouches();
      for (int i = 0, j = touches.length(); i < j; i++) {
        Touch touch = touches.get(i);
        int touchId = touch.getIdentifier();
        touched[touchId] = false;
        double r = GwtGraphics.getDevicePixelRatioJSNI();
        int x = (int) (touch.getRelativeX(canvas) * r);
        int y = (int) (touch.getRelativeY(canvas) * r);
        deltaX[touchId] = x - touchX[touchId];
        deltaY[touchId] = y - touchY[touchId];
        touchX[touchId] = x;
        touchY[touchId] = y;
        if (processor != null) {
          processor.touchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT);
        }
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      e.preventDefault();
    } else if (e.getType().equals("mousewheel") || e.getType().equals("DOMMouseScroll")) {
      float dir = getMouseWheelVelocity(e);

      if (dir != 0 && processor != null) processor.scrolled(dir > 0 ? 1 : -1);
    }
    // if(hasFocus) e.preventDefault();
  }
예제 #11
0
  /** Prevents the browser from taking its default action for the given event. */
  public final void preventDefault() {

    if (nativeEvent == null) return;

    nativeEvent.preventDefault();
  }