Commits

Anonymous committed 46a1b01

Fix for RT-16621: Selected text is blue even focus is on another control.

The fix is simply to style the TextArea such that it appears gray instead of blue when not focused. This required a fix to the css file, as well as to the TextInputControlSkin class. There was a bug there where it wouldn't notify the TextAreaSkin (via protected methods) when the highlight fill, or highlight text fill changed, and as a result, the CSS wasn't being applied to the TextAreaSkin.

Comments (0)

Files changed (6)

javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java

 
 package com.sun.javafx.scene.control.behavior;
 
+import java.util.ArrayList;
+import java.util.List;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
-import javafx.event.EventHandler;
+import javafx.geometry.Bounds;
 import javafx.geometry.Point2D;
+import javafx.geometry.Rectangle2D;
 import javafx.scene.Scene;
 import javafx.scene.control.ContextMenu;
 import javafx.scene.control.IndexRange;
 import javafx.scene.control.TextArea;
 import javafx.scene.input.MouseButton;
 import javafx.scene.input.MouseEvent;
-import javafx.scene.input.TouchEvent;
 import javafx.stage.Screen;
 import javafx.stage.Window;
+import com.sun.javafx.PlatformUtil;
+import com.sun.javafx.css.StyleManager;
+import com.sun.javafx.geom.transform.Affine3D;
+import com.sun.javafx.scene.control.skin.TextAreaSkin;
+import com.sun.javafx.scene.text.HitInfo;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import com.sun.javafx.PlatformUtil;
-import com.sun.javafx.scene.control.skin.TextAreaSkin;
-import com.sun.javafx.css.StyleManager;
-import com.sun.javafx.scene.control.skin.Utils;
-import com.sun.javafx.scene.text.HitInfo;
 import static javafx.scene.input.KeyCode.*;
 import static javafx.scene.input.KeyEvent.*;
 import static com.sun.javafx.PlatformUtil.*;
-import javafx.geometry.Rectangle2D;
-import com.sun.javafx.geom.transform.Affine3D;
-import javafx.geometry.Bounds;
 
 
 /**
         textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
             @Override
             public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
-                TextArea textArea = getControl();
+                // NOTE: The code in this method is *almost* and exact copy of what is in TextFieldBehavior.
+                // The only real difference is that TextFieldBehavior selects all the text when the control
+                // receives focus (when not gained by mouse click), whereas TextArea doesn't, and also the
+                // TextArea doesn't lose selection on focus lost, whereas the TextField does.
+                final TextArea textArea = getControl();
                 if (textArea.isFocused()) {
                     if (PlatformUtil.isIOS()) {
-                        // special handling of focus on iOS is required to allow to
-                        // control native keyboard, because nat. keyboard is poped-up only when native 
+                        // Special handling of focus on iOS is required to allow to
+                        // control native keyboard, because native keyboard is popped-up only when native
                         // text component gets focus. When we have JFX keyboard we can remove this code
-                        Bounds bnds = textArea.getBoundsInParent();
-                        double w = bnds.getWidth();
-                        double h = bnds.getHeight();
+                        final Bounds bounds = textArea.getBoundsInParent();
+                        double w = bounds.getWidth();
+                        double h = bounds.getHeight();
                         Affine3D trans = TextFieldBehavior.calculateNodeToSceneTransform(textArea);
                         String text = textArea.getText();
 

javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextFieldBehavior.java

 
 package com.sun.javafx.scene.control.behavior;
 
-import com.sun.javafx.PlatformUtil;
+import java.util.List;
 import javafx.animation.KeyFrame;
 import javafx.animation.Timeline;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
+import javafx.geometry.Bounds;
 import javafx.geometry.HorizontalDirection;
 import javafx.geometry.Point2D;
+import javafx.geometry.Rectangle2D;
+import javafx.scene.Node;
 import javafx.scene.Scene;
 import javafx.scene.control.ContextMenu;
 import javafx.scene.control.IndexRange;
 import javafx.scene.input.KeyEvent;
 import javafx.scene.input.MouseButton;
 import javafx.scene.input.MouseEvent;
-import javafx.scene.input.TouchEvent;
 import javafx.stage.Screen;
 import javafx.stage.Window;
 import javafx.util.Duration;
-import java.util.List;
-
 import com.sun.javafx.PlatformUtil;
+import com.sun.javafx.css.StyleManager;
+import com.sun.javafx.geom.transform.Affine3D;
 import com.sun.javafx.scene.control.skin.TextFieldSkin;
-import com.sun.javafx.css.StyleManager;
-import com.sun.javafx.scene.control.skin.Utils;
 import com.sun.javafx.scene.text.HitInfo;
 
 import static com.sun.javafx.PlatformUtil.*;
 
-import com.sun.javafx.geom.transform.Affine3D;
-import javafx.scene.Node;
-import javafx.scene.text.Font;
-
-import javafx.geometry.Rectangle2D;
-import javafx.geometry.Bounds;
-import javafx.geometry.Insets;
-
 /**
  * Text field behavior.
  */
                 } else if (textField.getClass().equals(com.sun.javafx.scene.control.FocusableTextField.class)) {
                     type = TextInputTypes.EDITABLE_COMBO;
                 }
-                Bounds bnds = textField.getBoundsInParent();
-                double w = bnds.getWidth();
-                double h = bnds.getHeight();
+                final Bounds bounds = textField.getBoundsInParent();
+                double w = bounds.getWidth();
+                double h = bounds.getHeight();
                 Affine3D trans = calculateNodeToSceneTransform(textField);
 //                Insets insets = skin.getInsets();
 //                w -= insets.getLeft() + insets.getRight();

javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextAreaSkin.java

 
 package com.sun.javafx.scene.control.skin;
 
+import java.util.List;
 import javafx.animation.KeyFrame;
 import javafx.animation.Timeline;
 import javafx.application.Platform;
 import javafx.beans.Observable;
 import javafx.beans.binding.BooleanBinding;
 import javafx.beans.binding.IntegerBinding;
-import javafx.beans.binding.ObjectBinding;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableBooleanValue;
 import javafx.beans.value.ObservableIntegerValue;
 import javafx.scene.input.MouseEvent;
 import javafx.scene.input.ScrollEvent;
 import javafx.scene.layout.Region;
-import javafx.scene.paint.Paint;
 import javafx.scene.shape.MoveTo;
 import javafx.scene.shape.Path;
 import javafx.scene.shape.PathElement;
 import javafx.scene.text.Text;
 import javafx.scene.text.TextAlignment;
 import javafx.util.Duration;
-import java.util.List;
-
 import com.sun.javafx.PlatformUtil;
 import com.sun.javafx.scene.control.behavior.TextAreaBehavior;
 import com.sun.javafx.scene.text.HitInfo;

javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextFieldSkin.java

 
 package com.sun.javafx.scene.control.skin;
 
+import java.util.List;
 import javafx.beans.InvalidationListener;
 import javafx.beans.Observable;
 import javafx.beans.binding.BooleanBinding;
 import javafx.beans.binding.DoubleBinding;
-import javafx.beans.binding.IntegerBinding;
 import javafx.beans.binding.ObjectBinding;
 import javafx.beans.binding.StringBinding;
-import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.DoubleProperty;
 import javafx.beans.property.SimpleDoubleProperty;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableBooleanValue;
 import javafx.beans.value.ObservableDoubleValue;
-import javafx.beans.value.ObservableIntegerValue;
 import javafx.beans.value.ObservableValue;
 import javafx.event.EventHandler;
 import javafx.geometry.Bounds;
 import javafx.scene.layout.Pane;
 import javafx.scene.paint.Color;
 import javafx.scene.paint.Paint;
-import javafx.scene.shape.MoveTo;
 import javafx.scene.shape.Path;
 import javafx.scene.shape.PathElement;
 import javafx.scene.shape.Rectangle;
 import javafx.scene.text.Text;
-import java.util.List;
-
 import com.sun.javafx.PlatformUtil;
 import com.sun.javafx.scene.control.behavior.TextFieldBehavior;
 import com.sun.javafx.scene.text.HitInfo;

javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextInputControlSkin.java

 
 package com.sun.javafx.scene.control.skin;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import javafx.animation.KeyFrame;
 import javafx.animation.Timeline;
-import javafx.application.Platform;
 import javafx.beans.InvalidationListener;
 import javafx.beans.Observable;
 import javafx.beans.binding.BooleanBinding;
 import javafx.beans.binding.ObjectBinding;
 import javafx.beans.property.BooleanProperty;
-import javafx.beans.property.BooleanPropertyBase;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleBooleanProperty;
 import javafx.beans.value.ObservableBooleanValue;
 import javafx.scene.shape.VLineTo;
 import javafx.scene.text.Font;
 import javafx.stage.Window;
-import javafx.stage.WindowEvent;
 import javafx.util.Duration;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
 import com.sun.javafx.PlatformUtil;
 import com.sun.javafx.css.StyleableBooleanProperty;
 import com.sun.javafx.css.StyleableObjectProperty;
     protected final ObjectProperty<Paint> highlightFill = 
         new StyleableObjectProperty<Paint>(Color.DODGERBLUE) {
 
+        @Override protected void invalidated() {
+            updateHighlightFill();
+        }
+
         @Override
         public Object getBean() {
             return TextInputControlSkin.this;
     protected final ObjectProperty<Paint> highlightTextFill = 
         new StyleableObjectProperty<Paint>(Color.WHITE) {
 
+        @Override protected void invalidated() {
+            updateHighlightTextFill();
+        }
+
         @Override
         public Object getBean() {
             return TextInputControlSkin.this;

javafx-ui-controls/src/com/sun/javafx/scene/control/skin/caspian/caspian.css

 
 .text-input {
     -fx-text-fill: -fx-text-inner-color;
+    -fx-highlight-fill: derive(-fx-control-inner-background,-20%);
+    -fx-highlight-text-fill: -fx-text-inner-color;
+}
+
+.text-input:focused {
     -fx-highlight-fill: -fx-accent;
     -fx-highlight-text-fill: white;
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.