com.google.gwt.event.dom.client.KeyCodes Java Examples

The following examples show how to use com.google.gwt.event.dom.client.KeyCodes. 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: VContextMenu.java    From context-menu with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleNavigation(int keycode, boolean ctrl, boolean shift) {
    if (keycode == KeyCodes.KEY_TAB) {
        return true;
    }
    if (keycode == getNavigationLeftKey() && (getParentMenu() == null
            || getParentMenu().getParentMenu() == null)) {
        // do not close parent menu by left key
        return true;
    }
    if (keycode == getNavigationRightKey() && getSelected() != null
            && getSelected().getSubMenu() == null) {
        // do not close menu by right key if there is no submenu
        return true;
    }
    return super.handleNavigation(keycode, ctrl, shift);
}
 
Example #2
Source File: EditorEventHandler.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
private boolean handleNavigationKeyEvents(EditorEvent event) {
  editorInteractor.checkpoint(null);
  editorInteractor.clearCaretAnnotations();
  ContentNode node = cachedSelection.getFocus().getContainer();
  logger.trace().log("Navigation event");

  // Not using key combo, because we want to handle left key with
  // any modifiers also applying.
  // TODO(danilatos): MoveUnit, and holding down shift for selection.
  if (event.getKeyCode() == KeyCodes.KEY_LEFT) {
    router.handleLeft(node, event);
    editorInteractor.rebiasSelection(CursorDirection.FROM_RIGHT);
    return !event.shouldAllowBrowserDefault();
  } else if (event.getKeyCode() == KeyCodes.KEY_RIGHT) {
    router.handleRight(node, event);
    editorInteractor.rebiasSelection(CursorDirection.FROM_LEFT);
    return !event.shouldAllowBrowserDefault();
  } else {
    editorInteractor.rebiasSelection(CursorDirection.NEUTRAL);
  }
  return false;
}
 
Example #3
Source File: CubaNotification.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onEventPreview(Event event) {
    int type = DOM.eventGetType(event);

    if ((type == Event.ONCLICK || type == Event.ONTOUCHEND)
            && event.getEventTarget() != null) {
        Element target = Element.as(event.getEventTarget());
        if (containsSubstring(target.getClassName(), CUBA_NOTIFICATION_MODALITY_CURTAIN)) {
            hide();
            return false;
        }
    }

    if (type == Event.ONKEYDOWN && event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
        if (!getElement().getClassName().contains(TRAY_STYLE)) {
            hide();
            return false;
        }
    }

    return super.onEventPreview(event);
}
 
Example #4
Source File: EditorEventHandlerGwtTest.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
public void testDeleteWithRangeSelectedDeletesRange() {
  FakeEditorEvent fakeEvent = FakeEditorEvent.create(KeySignalType.DELETE, KeyCodes.KEY_LEFT);

  //Event event = Document.get().createKeyPressEvent(
  //    false, false, false, false, KeyCodes.KEY_BACKSPACE, 0).cast();

  Text input = Document.get().createTextNode("ABCDE");
  ContentNode node = new ContentTextNode(input, null);

  final Point<ContentNode> start = Point.inText(node, 1);
  final Point<ContentNode> end = Point.inText(node, 4);
  FakeEditorInteractor interactor = setupFakeEditorInteractor(
      new FocusedContentRange(start, end));
  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  EditorEventHandler handler = createEditorEventHandler(interactor, subHandler);

  interactor.call(FakeEditorInteractor.DELETE_RANGE).nOf(1).withArgs(
      start, end, false).returns(start);

  handler.handleEvent(fakeEvent);
  interactor.checkExpectations();
}
 
Example #5
Source File: CellBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onBrowserEvent2(Event event) {
  super.onBrowserEvent2(event);

  // Handle keyboard navigation between lists.
  String eventType = event.getType();
  if (BrowserEvents.KEYDOWN.equals(eventType) && !isKeyboardNavigationSuppressed()) {
    int keyCode = event.getKeyCode();
    boolean isRtl = LocaleInfo.getCurrentLocale().isRTL();
    keyCode = KeyCodes.maybeSwapArrowKeysForRtl(keyCode, isRtl);
    switch (keyCode) {
      case KeyCodes.KEY_LEFT:
        keyboardNavigateShallow();
        return;
      case KeyCodes.KEY_RIGHT:
        keyboardNavigateDeep();
        return;
    }
  }
}
 
Example #6
Source File: EditorEventHandler.java    From swellrt with Apache License 2.0 6 votes vote down vote up
private boolean handleNavigationKeyEvents(EditorEvent event) {
  editorInteractor.checkpoint(null);
  editorInteractor.clearCaretAnnotations();
  ContentNode node = cachedSelection.getFocus().getContainer();
  logger.trace().log("Navigation event");

  // Not using key combo, because we want to handle left key with
  // any modifiers also applying.
  // TODO(danilatos): MoveUnit, and holding down shift for selection.
  if (event.getKeyCode() == KeyCodes.KEY_LEFT) {
    router.handleLeft(node, event);
    editorInteractor.rebiasSelection(CursorDirection.FROM_RIGHT);
    return !event.shouldAllowBrowserDefault();
  } else if (event.getKeyCode() == KeyCodes.KEY_RIGHT) {
    router.handleRight(node, event);
    editorInteractor.rebiasSelection(CursorDirection.FROM_LEFT);
    return !event.shouldAllowBrowserDefault();
  } else {
    editorInteractor.rebiasSelection(CursorDirection.NEUTRAL);
  }
  return false;
}
 
Example #7
Source File: ToggleTool.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
private KeyUpHandler setRedoHandler() {
	final KeyUpHandler handler = new KeyUpHandler() {
		@Override
		public void onKeyUp(final KeyUpEvent event) {
			if (KeyCodes.KEY_R == event.getNativeEvent().getKeyCode()) {
				for (final Control control : controls) {
					try {
						((DrawFeature) control).redo();
					} catch (Exception e) {
						LOGGER.error("ACTION REDO: "
								+ control.getControlId());
					}
				}
			}
		}
	};
	return handler;
}
 
Example #8
Source File: AutoSizingBase.java    From gwt-traction with Apache License 2.0 6 votes vote down vote up
protected void onKeyCodeEvent(KeyCodeEvent event, String newShadowText) {
// ignore arrow keys
switch (event.getNativeKeyCode()) {
case KeyCodes.KEY_UP:
case KeyCodes.KEY_DOWN:
case KeyCodes.KEY_LEFT:
case KeyCodes.KEY_RIGHT:
    break;
default:
    // don't do this if there's a selection because it will get smaller
    if (box.getSelectionLength() == 0) {
	setShadowText(newShadowText);
	adjustSize();	    
	break;
    }
}	
   }
 
Example #9
Source File: InputSelect.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	boolean mustKillEvent = false;
	if (DOM.eventGetType(event) == Event.ONKEYDOWN) {
		switch (event.getKeyCode()) {
			case KeyCodes.KEY_TAB:
			case KeyCodes.KEY_ESCAPE:
				this.getDropdown().close();
				break;
			default:
				break;
		}
	}
	if (mustKillEvent) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example #10
Source File: EditorImpl.java    From swellrt with Apache License 2.0 6 votes vote down vote up
private boolean shouldTrackCursor(SignalEvent event) {
  if (event.isMouseButtonEvent()) {
    return true;
  }
  if (event.isKeyEvent()) {
    KeySignalType keySignalType = event.getKeySignalType();
    // The cursor location should move if the user either has modified the
    // content (typed or delete), or move the cursor deliberately.  However, page up/down
    // doesn't actually move the cursor, so we don't want to move the view port
    int keyCode = event.getKeyCode();
    return keySignalType == KeySignalType.INPUT ||
          keySignalType == KeySignalType.DELETE ||
          keySignalType == KeySignalType.NAVIGATION && (
             keyCode != KeyCodes.KEY_PAGEDOWN &&
             keyCode != KeyCodes.KEY_PAGEUP);
  }
  return false;
}
 
Example #11
Source File: InputMultiSelect.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	boolean mustKillEvent = false;
	if (DOM.eventGetType(event) == Event.ONKEYDOWN) {
		switch (event.getKeyCode()) {
			case KeyCodes.KEY_ENTER:
				if (this.getDropdown().isOpen()) {
					((MultiSelectionHandler) this.getSelectionHandler()).onEnterKeyDown();
					mustKillEvent = true;
				}
				break;
			case KeyCodes.KEY_TAB:
			case KeyCodes.KEY_ESCAPE:
				this.getDropdown().close();
				break;
			default:
				break;
		}
	}
	if (mustKillEvent) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example #12
Source File: SinglePageLayout.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	int key = event.getNativeKeyCode();
	if (event.isControlKeyDown()) {
		if (key == KEY_PLUS || key == KEY_MINUS) {
			app.getToolbar().zoomChangeClicked(key == KEY_PLUS ? 1 : -1);
			event.preventDefault();
		}
	} else if (!event.isShiftKeyDown()) {
		boolean handled = true;
		switch (key) {
		case KeyCodes.KEY_HOME:
			changePage(0, -1, -1);
			break;
		case KeyCodes.KEY_END:
			changePage(dataStore.getPageCount() - 1, 1, 1);
			break;
		default:
			handled = false;
		}
		if (handled)
			event.preventDefault();
	}
}
 
Example #13
Source File: ZoomInTool.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
private KeyUpHandler createKeyHandler() {
	KeyUpHandler handler=  new KeyUpHandler() {
		@Override
		public void onKeyUp(final KeyUpEvent event) {
			if (KeyCodes.KEY_PAGEDOWN == event.getNativeEvent().getKeyCode()) {
				onRelease();
			}
		}
	};
	
	return handler;
}
 
Example #14
Source File: ApplicationRootView.java    From bitcoin-transaction-explorer with MIT License 5 votes vote down vote up
@UiHandler("lookupField")
public void onLookupKeyUp(final KeyUpEvent event) {
  if (event.getNativeKeyCode() != KeyCodes.KEY_ENTER) {
    return;
  }

  final ApplicationPlace place = PlaceTokenParseUtil.parseToken(lookupField.getText());
  if (place == null) {
    // Do something, like show a mild error.
    return;
  }

  placeController.goTo(place);
}
 
Example #15
Source File: OffPageSelector.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (Event.ONKEYDOWN == event.getTypeInt()) {
        if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
            // Dismiss when escape is pressed
            hide();
        }
    }
}
 
Example #16
Source File: EditorEventHandler.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Parameterised to allow testing different browser/os permuations
 * @param event
 * @param isMac
 * @param quirksHasOldSchoolClipboardShortcuts
 */
@VisibleForTesting
static boolean isAcceleratorInner(SignalEvent event, boolean isMac,
    boolean quirksHasOldSchoolClipboardShortcuts) {
  switch (event.getKeySignalType()) {
    case INPUT:
      // Alt on its own is a simple modifier, like shift, on OSX
      boolean maybeAltKey = !isMac && event.getAltKey();

      // NOTE(user): Perhaps we should create a registry in
      // EditorEventSubHandler of non-metesque like command keys such as TAB.
      // For now TAB is our only special case, but we may need to allow
      // implementers to define arbitrary keys as accelerators.
      return event.getCtrlKey() || event.getMetaKey() || event.getKeyCode() == KeyCodes.KEY_TAB
          || maybeAltKey;
    case DELETE:
      if (quirksHasOldSchoolClipboardShortcuts &&
          event.getKeyCode() == KeyCodes.KEY_DELETE && KeyModifier.SHIFT.check(event)) {

        // shift+delete on windows/linux is cut
        // (shift+insert and ctrl+insert are other clipboard alternatives,
        // but that's handled below).

        return true;
      } else {
        return false;
      }
    case NAVIGATION:
      // All navigation does not count
      return false;
    case NOEFFECT:
      // Random special keys like ESC, F7, TAB, INS, etc count
      return true;
  }
  throw new RuntimeException("Unknown KeySignal type");
}
 
Example #17
Source File: AbstractDropdown.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onKeyPress(KeyPressEvent event) {
	if (event.getCharCode() == KeyCodes.KEY_ENTER) {
		this.toggleOpen();
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example #18
Source File: EditorEventHandlerGwtTest.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Test that handleLeft/Right are triggered on the correct node.
 */
public void testHandleLeftRightTriggeredOnNode() {
  FakeEditorEvent fakeEvent = FakeEditorEvent.create(KeySignalType.NAVIGATION, KeyCodes.KEY_LEFT);
  FakeRouter router = new FakeRouter();
  ContentElement fakeContentElement = newElement();
  final Point<ContentNode> caret = Point.<ContentNode> end(fakeContentElement);

  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  FakeEditorInteractor interactor = setupFakeEditorInteractor(new FocusedContentRange(caret));
  EditorEventHandler handler = createEditorEventHandler(router, interactor, subHandler);

  router.ctx.call(FakeRouter.HANDLE_LEFT).nOf(1).withArgs(fakeEvent).returns(
      true);
  interactor.call(FakeEditorInteractor.CLEAR_ANNOTATIONS).nOf(1);

  boolean cancel1 = handler.handleEvent(fakeEvent);

  router.ctx.checkExpectations();
  assertEquals(!fakeEvent.shouldAllowBrowserDefault(), cancel1);


  router.ctx.reset();

  FakeEditorEvent fakeEvent2 =
      FakeEditorEvent.create(KeySignalType.NAVIGATION, KeyCodes.KEY_RIGHT);
  router.ctx.call(FakeRouter.HANDLE_RIGHT).nOf(1).withArgs(fakeEvent2)
      .returns(true);
  boolean cancel2 = handler.handleEvent(fakeEvent2);

  assertEquals(!fakeEvent.shouldAllowBrowserDefault(), cancel2);
  router.ctx.checkExpectations();
}
 
Example #19
Source File: DefaultPopup.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (Event.ONKEYDOWN == event.getTypeInt()) {
        if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
            // Dismiss when escape is pressed
            hide();
        }
    }
}
 
Example #20
Source File: EditorEventHandlerGwtTest.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private void testBackspaceDeleteHelper(boolean isBackspace, boolean handled,
    boolean isShiftDown) {
  EditorEvent signal = FakeSignalEvent.createKeyPress(FakeEditorEvent.ED_FACTORY,
      KeySignalType.DELETE, isBackspace ? KeyCodes.KEY_BACKSPACE : KeyCodes.KEY_DELETE,
      isShiftDown ? EnumSet.of(KeyModifier.SHIFT) : null);

  FakeRouter router = new FakeRouter();
  ContentElement fakeContentElement = newElement();
  final Point<ContentNode> caret = Point.<ContentNode> end(fakeContentElement);

  FakeEditorInteractor interactor = setupFakeEditorInteractor(new FocusedContentRange(caret));
  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  EditorEventHandler handler = createEditorEventHandler(router, interactor, subHandler);

  // Because we cannot override handleBackspace in ContentElement, we test at
  // handleBackspaceAtBeginning instead. We have to be sure that the caret is
  // at beginning or it wouldn't work, so this is a bit fragile.
  assertTrue(ContentPoint.fromPoint(caret).isAtBeginning());
  if (isBackspace) {
    router.ctx.call(FakeRouter.HANDLE_BACKSPACE_AT_BEGINNING).nOf(1)
        .withArgs(signal).returns(handled);
  } else {
    router.ctx.call(FakeRouter.HANDLE_DELETE).nOf(1).withArgs(signal)
        .returns(handled);
  }
  boolean cancel = handler.handleEvent(signal);
  router.ctx.checkExpectations();
  assertEquals("Backspace should be cancelled if handled", handled, cancel);
}
 
Example #21
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
/**
 * Triggered when a key was depressed.
 *
 * @param event
 *            The KeyUpEvent of the key depressed
 */
@Override
public void onKeyUp(KeyUpEvent event) {
	debug("VComboBoxMultiselect: onKeyUp(" + event.getNativeKeyCode() + ")");

	if (this.enabled && !this.readonly) {
		switch (event.getNativeKeyCode()) {
		case KeyCodes.KEY_ENTER:
		case KeyCodes.KEY_TAB:
		case KeyCodes.KEY_SHIFT:
		case KeyCodes.KEY_CTRL:
		case KeyCodes.KEY_ALT:
		case KeyCodes.KEY_DOWN:
		case KeyCodes.KEY_UP:
		case KeyCodes.KEY_PAGEDOWN:
		case KeyCodes.KEY_PAGEUP:
		case KeyCodes.KEY_ESCAPE:
			// NOP
			break;
		default:
			if (this.textInputEnabled) {
				// when filtering, we always want to see the results on the
				// first page first.
				filterOptions(0);
			}
			break;
		}
	}
}
 
Example #22
Source File: ZoomOutTool.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
private KeyUpHandler createKeyHandler() {
	return new KeyUpHandler() {
		@Override
		public void onKeyUp(final KeyUpEvent event) {
			if (KeyCodes.KEY_PAGEUP == event.getNativeEvent().getKeyCode()) {
				onRelease();
			}
		}
	};
}
 
Example #23
Source File: AttributeSearchDialog.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
private void addKeyShortcuts() {
	KeyShortcutHandler keyShortcut = new KeyShortcutHandler(searchButton,
			KeyCodes.KEY_ENTER);

	layerNameField.addKeyDownHandler(keyShortcut);
	valueAttributeField.addKeyDownHandler(keyShortcut);
	attributeCombo.addKeyDownHandler(keyShortcut);
}
 
Example #24
Source File: UTCTimeBoxImplHtml4.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    switch (event.getNativeKeyCode()) {
    case KeyCodes.KEY_UP:
        menu.adjustHighlight(-1);
        break;
    case KeyCodes.KEY_DOWN:
        menu.adjustHighlight(1);
        break;
    case KeyCodes.KEY_ENTER:
    case KeyCodes.KEY_TAB:
        // accept current value
        if (menu.isShowing()) {
            menu.acceptHighlighted();
            hideMenu();
            clearInvalidStyle();
        } 
        else {
            
            // added a sync here because this is when we
            // accept the value we've typed if we're typing in
            // a new value.
            syncValueToText();
            
            validate();
        }
        break;
    case KeyCodes.KEY_ESCAPE:
        validate();
        hideMenu();
        break;
    default:
        hideMenu();
        clearInvalidStyle();
        break;
    }
}
 
Example #25
Source File: AbstractInputSelect.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	boolean mustKillEvent = false;
	switch (DOM.eventGetType(event)) {
		case Event.ONKEYDOWN:
			switch (event.getKeyCode()) {
				case KeyCodes.KEY_HOME:
					this.selectionHandler.onHomeKeyDown();
					mustKillEvent = true;
					break;
				case KeyCodes.KEY_END:
					this.selectionHandler.onEndKeyDown();
					mustKillEvent = true;
					break;
				case KeyCodes.KEY_UP:
					this.selectionHandler.onUpKeyDown();
					mustKillEvent = true;
					break;
				case KeyCodes.KEY_DOWN:
					this.selectionHandler.onDownKeyDown();
					mustKillEvent = true;
					break;
				default:
					break;
			}
			break;
		case Event.ONKEYPRESS:
			this.keyPressHandler.handleKeyPress(event.getCharCode());
			break;
		default:
			break;
	}

	if (mustKillEvent) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example #26
Source File: ClientUtils.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a {@link KeyPressHandler} to the specified widget which calls {@link Button#click()} on <code>targetButton</code>
 * when the Enter key is pressed.
 * @param widget       widget to add the key handler to
 * @param targetButton target button to activate when the enter key is pressed
 */
public static void addEnterTarget( final HasKeyPressHandlers widget, final Button targetButton ) {
	widget.addKeyPressHandler( new KeyPressHandler() {
		@Override
		public void onKeyPress( final KeyPressEvent event ) {
			if ( event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER )
				targetButton.click();
		}
	} );
}
 
Example #27
Source File: StatusDisplayMixin.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
protected void registerHandlers() {
    MaterialWidget widget = (MaterialWidget) uiObject;
    statusIcon.getHandlerRegistry().clearHandlers();
    statusIcon.registerHandler(statusIcon.addMouseOverHandler(event -> showStatus()));
    statusIcon.registerHandler(statusIcon.addMouseOutHandler(event -> hideStatus()));

    widget.getHandlerRegistry().clearHandlers();
    widget.registerHandler(widget.addFocusHandler(event -> showStatus()));
    widget.registerHandler(widget.addBlurHandler(event -> hideStatus()));
    widget.registerHandler(widget.addKeyUpHandler(event -> {
        if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
            hideStatus();
        }
    }));
}
 
Example #28
Source File: NavRootNodeEditorView.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
@EventHandler("itemNameInput")
public void onItemNameChanged(KeyPressEvent keyEvent) {
    if (keyEvent.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
        presenter.onChangesOk();
    } else {
        presenter.onItemNameChanged();
    }
}
 
Example #29
Source File: ViewClientCriterion.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks if the origin of the given event is a pressed ESC key.
 *
 * @param event
 *            the event to analyze
 * @return <code>true</code> if the origin of the event is a pressed ESC
 *         key, otherwise <code>false</code>.
 */
private static boolean isEscKey(final NativePreviewEvent event) {
    final int typeInt = event.getTypeInt();
    if (typeInt == Event.ONKEYDOWN) {
        final int keyCode = event.getNativeEvent().getKeyCode();
        if (KeyCodes.KEY_ESCAPE == keyCode) {
            return true;
        }
    }
    return false;
}
 
Example #30
Source File: EditorEventHandlerGwtTest.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Test that handleLeft/Right are triggered on the correct node.
 */
public void testHandleLeftRightTriggeredOnNode() {
  FakeEditorEvent fakeEvent = FakeEditorEvent.create(KeySignalType.NAVIGATION, KeyCodes.KEY_LEFT);
  FakeRouter router = new FakeRouter();
  ContentElement fakeContentElement = newElement();
  final Point<ContentNode> caret = Point.<ContentNode> end(fakeContentElement);

  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  FakeEditorInteractor interactor = setupFakeEditorInteractor(new FocusedContentRange(caret));
  EditorEventHandler handler = createEditorEventHandler(router, interactor, subHandler);

  router.ctx.call(FakeRouter.HANDLE_LEFT).nOf(1).withArgs(fakeEvent).returns(
      true);
  interactor.call(FakeEditorInteractor.CLEAR_ANNOTATIONS).nOf(1);

  boolean cancel1 = handler.handleEvent(fakeEvent);

  router.ctx.checkExpectations();
  assertEquals(!fakeEvent.shouldAllowBrowserDefault(), cancel1);


  router.ctx.reset();

  FakeEditorEvent fakeEvent2 =
      FakeEditorEvent.create(KeySignalType.NAVIGATION, KeyCodes.KEY_RIGHT);
  router.ctx.call(FakeRouter.HANDLE_RIGHT).nOf(1).withArgs(fakeEvent2)
      .returns(true);
  boolean cancel2 = handler.handleEvent(fakeEvent2);

  assertEquals(!fakeEvent.shouldAllowBrowserDefault(), cancel2);
  router.ctx.checkExpectations();
}