Skip to content

Commit

Permalink
8207759: VK_ENTER not consumed by TextField when default Button exists
Browse files Browse the repository at this point in the history
Reviewed-by: aghaisas, kcr
  • Loading branch information
Jeanette Winzenburg authored and aghaisas committed Dec 17, 2019
1 parent fc539b5 commit d2d44b4
Show file tree
Hide file tree
Showing 8 changed files with 681 additions and 25 deletions.
Expand Up @@ -25,7 +25,16 @@

package com.sun.javafx.scene.control.behavior;


import com.sun.javafx.PlatformUtil;
import com.sun.javafx.geom.transform.Affine3D;
import com.sun.javafx.scene.NodeHelper;
import com.sun.javafx.scene.control.Properties;
import com.sun.javafx.scene.control.skin.Utils;
import com.sun.javafx.stage.WindowHelper;

import static com.sun.javafx.PlatformUtil.*;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.WeakChangeListener;
import javafx.event.ActionEvent;
Expand All @@ -35,23 +44,14 @@
import javafx.geometry.Rectangle2D;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.TextField;
import javafx.scene.control.skin.TextFieldSkin;
import com.sun.javafx.scene.control.skin.Utils;
import javafx.scene.input.ContextMenuEvent;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.HitInfo;
import javafx.stage.Screen;
import javafx.stage.Window;
import com.sun.javafx.PlatformUtil;
import com.sun.javafx.geom.transform.Affine3D;

import static com.sun.javafx.PlatformUtil.isMac;
import static com.sun.javafx.PlatformUtil.isWindows;
import com.sun.javafx.scene.NodeHelper;
import com.sun.javafx.stage.WindowHelper;

/**
* Text field behavior.
Expand Down Expand Up @@ -183,9 +183,10 @@ public void setTextFieldSkin(TextFieldSkin skin) {

textField.commitValue();
textField.fireEvent(actionEvent);

if (onAction == null && !actionEvent.isConsumed()) {
forwardToParent(event);
// fix of JDK-8207759: reverted logic
// mapping not auto-consume and consume if handled by action
if (onAction != null || actionEvent.isConsumed()) {
event.consume();
}
}

Expand Down
Expand Up @@ -124,6 +124,7 @@ public TextInputControlBehavior(T c) {
final Predicate<KeyEvent> validOnLinux = e -> !PlatformUtil.isLinux();

KeyMapping cancelEditMapping;
KeyMapping fireMapping;
KeyMapping consumeMostPressedEventsMapping;

// create a child input map for mappings which are applicable on all
Expand All @@ -136,7 +137,7 @@ public TextInputControlBehavior(T c) {
keyMapping(HOME, e -> c.home()),
keyMapping(DOWN, e -> c.end()),
keyMapping(END, e -> c.end()),
keyMapping(ENTER, this::fire),
fireMapping = keyMapping(ENTER, this::fire),

keyMapping(new KeyBinding(HOME).shortcut(), e -> c.home()),
keyMapping(new KeyBinding(END).shortcut(), e -> c.end()),
Expand Down Expand Up @@ -213,6 +214,8 @@ public TextInputControlBehavior(T c) {
);

cancelEditMapping.setAutoConsume(false);
// fix of JDK-8207759: don't auto-consume
fireMapping.setAutoConsume(false);
consumeMostPressedEventsMapping.setAutoConsume(false);

// mac os specific mappings
Expand Down Expand Up @@ -620,18 +623,7 @@ private void rightWord() {
}

protected void fire(KeyEvent event) { } // TODO move to TextFieldBehavior
protected void cancelEdit(KeyEvent event) { forwardToParent(event);} // not autoconsumed

protected void forwardToParent(KeyEvent event) {
// fix for JDK-8145515
if (getNode().getProperties().containsKey(DISABLE_FORWARD_TO_PARENT)) {
return;
}

if (getNode().getParent() != null) {
getNode().getParent().fireEvent(event);
}
}
protected void cancelEdit(KeyEvent event) { };

protected void selectHome() {
getNode().selectHome();
Expand Down

0 comments on commit d2d44b4

Please sign in to comment.