コード例 #1
0
  private boolean handleKeyDown(NativeEvent e) {
    // Don't dispatch on bare modifier keypresses.
    if (KeyboardHelper.isModifierKey(e.getKeyCode())) return false;

    keyBuffer_.add(e);
    KeyboardShortcut shortcut = new KeyboardShortcut(keyBuffer_);

    // Check for disabled modal shortcuts if we're modal
    if (editorMode_ > 0) {
      for (KeyboardShortcut modalShortcut : modalShortcuts_) {
        if (modalShortcut.equals(shortcut) && modalShortcut.isModeDisabled(editorMode_)) {
          return false;
        }
      }
    }

    // Check for user-defined commands.
    if (userCommands_.dispatch(shortcut)) return true;

    // Check for custom bindings for RStudio AppCommands.
    if (dispatch(shortcut, customBindings_, e)) return true;

    // Check for RStudio AppCommands.
    if (dispatch(shortcut, commands_, e, maskedCommands_)) return true;

    return false;
  }
コード例 #2
0
  private boolean handleKeyDown(NativeEvent e) {
    // Don't dispatch on bare modifier keypresses.
    if (KeyboardHelper.isModifierKey(e.getKeyCode())) return false;

    keyBuffer_.add(e);
    KeyboardShortcut shortcut = new KeyboardShortcut(keyBuffer_.clone());

    // If this matches a prefix key, return false early.
    if (prefixes_.contains(shortcut.getKeySequence())) return false;

    // Clear the key buffer (we've reached a 'leaf' for the
    // key sequence chain; there may or may not be a command)
    keyBuffer_.clear();

    // Check for user-defined commands.
    if (userCommands_.dispatch(shortcut)) return true;

    // Check for custom bindings for RStudio AppCommands.
    if (dispatch(shortcut, customBindings_, e)) return true;

    // Check for RStudio AppCommands.
    if (dispatch(shortcut, commands_, e, maskedCommands_)) return true;

    return false;
  }
コード例 #3
0
 @Override
 public void onBrowserEvent(
     Context context,
     Element parent,
     String value,
     NativeEvent event,
     ValueUpdater<String> valueUpdater) {
   Object key = context.getKey();
   ViewData viewData = getViewData(key);
   if (viewData != null && viewData.isEditing()) {
     // Handle the edit event.
     editEvent(context, parent, value, viewData, event, valueUpdater);
   } else {
     String type = event.getType();
     int keyCode = event.getKeyCode();
     boolean enterPressed = KEYUP.equals(type) && keyCode == KeyCodes.KEY_ENTER;
     if (CLICK.equals(type) || enterPressed) {
       // Go into edit mode.
       if (viewData == null) {
         viewData = new ViewData(value);
         setViewData(key, viewData);
       } else {
         viewData.setEditing(true);
       }
       edit(context, parent, value);
     }
   }
 }
コード例 #4
0
ファイル: LoginDialog.java プロジェクト: childers/Apollo
 @Override
 public void onPreviewNativeEvent(NativePreviewEvent e) {
   NativeEvent nativeEvent = e.getNativeEvent();
   if ("keydown".equals(nativeEvent.getType())) {
     if (nativeEvent.getKeyCode() == KeyCodes.KEY_ENTER) {
       doLogin(userBox.getText().trim(), passBox.getText(), rememberBox.getValue());
     }
   }
 }
コード例 #5
0
ファイル: AceEditor.java プロジェクト: Rogaven/rstudio
    public boolean shouldComplete(NativeEvent event) {
      // Never complete if there's an active selection
      Range range = getSession().getSelection().getRange();
      if (!range.isEmpty()) return false;

      // Don't consider Tab to be a completion if we're at the start of a
      // line (e.g. only zero or more whitespace characters between the
      // beginning of the line and the cursor)

      if (event != null && event.getKeyCode() != KeyCodes.KEY_TAB) return true;

      int col = range.getStart().getColumn();
      if (col == 0) return false;

      String row = getSession().getLine(range.getStart().getRow());
      return row.substring(0, col).trim().length() != 0;
    }
コード例 #6
0
 private void editEvent(
     Context context,
     Element parent,
     String value,
     ViewData viewData,
     NativeEvent event,
     ValueUpdater<String> valueUpdater) {
   String type = event.getType();
   boolean keyUp = KEYUP.equals(type);
   boolean keyDown = KEYDOWN.equals(type);
   if (keyUp || keyDown) {
     int keyCode = event.getKeyCode();
     if (keyUp
         && keyCode == KeyCodes.KEY_ENTER
         && (event.getCtrlKey() || event.getAltKey() || event.getShiftKey())) {
       // Commit the change.
       commit(context, parent, viewData, valueUpdater);
     } else if (keyUp && keyCode == KeyCodes.KEY_ESCAPE) {
       // Cancel edit mode.
       String originalText = viewData.getOriginal();
       if (viewData.isEditingAgain()) {
         viewData.setText(originalText);
         viewData.setEditing(false);
       } else {
         setViewData(context.getKey(), null);
       }
       cancel(context, parent, value);
     } else {
       // Update the text in the view data on each key.
       updateViewData(parent, viewData, true);
     }
   } else if (BLUR.equals(type)) {
     // Commit the change. Ensure that we are blurring the input element and
     // not the parent element itself.
     EventTarget eventTarget = event.getEventTarget();
     if (Element.is(eventTarget)) {
       Element target = Element.as(eventTarget);
       if ("input".equals(target.getTagName().toLowerCase())) {
         commit(context, parent, viewData, valueUpdater);
       }
     }
   }
 }
コード例 #7
0
ファイル: ModalDialogBase.java プロジェクト: vwendy/rstudio
  @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;
      }
    }
  }
コード例 #8
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();
  }