changeset 1659:73aed3d884dd

Automated merge with ssh://javafxsrc.us.oracle.com//javafx/3.0/scrum/graphics/jfx//rt
author David Hill
date Wed, 15 Aug 2012 11:10:44 -0400
parents bc226eac8e88 279df74040c4
children 9041e7dbf755
files
diffstat 5 files changed, 110 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/com/sun/javafx/tk/TKStage.java	Tue Aug 14 10:25:57 2012 -0700
+++ b/javafx-ui-common/src/com/sun/javafx/tk/TKStage.java	Wed Aug 15 11:10:44 2012 -0400
@@ -179,4 +179,28 @@
      * @see #grabFocus
      */
     public void ungrabFocus();
+
+    /**
+     * Requests text input in form of native keyboard for text component
+     * contained by this Window. Native text input component is drawn on the place
+     * of JavaFX component to cover it completely and to provide native text editing
+     * techniques. Any change of text is immediately reflected in JavaFX text component.
+     *
+     * @param text text to be shown in the native text input component
+     * @param type type of text input component @see com.sun.javafx.scene.control.behavior.TextInputTypes
+     * @param width width of JavaFX text input component
+     * @param height height of JavaFX text input component
+     * @param M standard transformation matrix for drawing the native text component derived from JavaFX component
+     */
+    void requestInput(String text, int type, double width, double height,
+                        double Mxx, double Mxy, double Mxz, double Mxt,
+                        double Myx, double Myy, double Myz, double Myt,
+                        double Mzx, double Mzy, double Mzz, double Mzt);
+
+    /**
+     * Native keyboard for text input is no longer necessary.
+     * Keyboard will be hidden and native text input component too.
+     */
+    void releaseInput();
+
 }
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java	Tue Aug 14 10:25:57 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java	Wed Aug 15 11:10:44 2012 -0400
@@ -49,6 +49,8 @@
 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;
 
 
 /**
@@ -148,11 +150,26 @@
             public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                 TextArea textArea = getControl();
                 if (textArea.isFocused()) {
+                    if (PlatformUtil.isIOS()) {
+                        Bounds bnds = textArea.getBoundsInParent();
+                        double w = bnds.getWidth();
+                        double h = bnds.getHeight();
+                        Affine3D trans = TextFieldBehavior.calculateNodeToSceneTransform(textArea);
+                        String text = textArea.getText();
+
+                        textArea.getScene().getWindow().impl_getPeer().requestInput(text, TextFieldBehavior.TextInputTypes.TEXT_AREA.ordinal(), w, h, 
+                                trans.getMxx(), trans.getMxy(), trans.getMxz(), trans.getMxt(),
+                                trans.getMyx(), trans.getMyy(), trans.getMyz(), trans.getMyt(),
+                                trans.getMzx(), trans.getMzy(), trans.getMzz(), trans.getMzt());
+                    }
                     if (!focusGainedByMouseClick) {
                         setCaretAnimating(true);
                     }
                 } else {
 //                    skin.hideCaret();
+                    if (PlatformUtil.isIOS() && textArea.getScene() != null) {
+                        textArea.getScene().getWindow().impl_getPeer().releaseInput();
+                    }
                     focusGainedByMouseClick = false;
                     setCaretAnimating(false);
                 }
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextFieldBehavior.java	Tue Aug 14 10:25:57 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextFieldBehavior.java	Wed Aug 15 11:10:44 2012 -0400
@@ -25,6 +25,7 @@
 
 package com.sun.javafx.scene.control.behavior;
 
+import com.sun.javafx.PlatformUtil;
 import javafx.animation.KeyFrame;
 import javafx.animation.Timeline;
 import javafx.beans.value.ChangeListener;
@@ -51,7 +52,14 @@
 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.
@@ -125,17 +133,51 @@
         TextField textField = getControl();
 
         if (textField.isFocused()) {
+            if (PlatformUtil.isIOS()) {
+                TextInputTypes type = TextInputTypes.TEXT_FIELD;
+                if (textField.getClass().equals(javafx.scene.control.PasswordField.class)) {
+                    type = TextInputTypes.PASSWORD_FIELD;
+                } 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();
+                Affine3D trans = calculateNodeToSceneTransform(textField);
+//                Insets insets = skin.getInsets();
+//                w -= insets.getLeft() + insets.getRight();
+//                h -= insets.getTop() + insets.getBottom();
+                String text = textField.getText();
+                
+                textField.getScene().getWindow().impl_getPeer().requestInput(text, type.ordinal(), w, h, 
+                        trans.getMxx(), trans.getMxy(), trans.getMxz(), trans.getMxt(),// + insets.getLeft(),
+                        trans.getMyx(), trans.getMyy(), trans.getMyz(), trans.getMyt(),// + insets.getTop(),
+                        trans.getMzx(), trans.getMzy(), trans.getMzz(), trans.getMzt());
+            }
             if (!focusGainedByMouseClick) {
                 textField.selectRange(textField.getLength(), 0);
                 setCaretAnimating(true);
             }
         } else {
+            if (PlatformUtil.isIOS() && textField.getScene() != null) {
+                textField.getScene().getWindow().impl_getPeer().releaseInput();
+            }
             textField.selectRange(0, 0);
             focusGainedByMouseClick = false;
             setCaretAnimating(false);
         }
     }
 
+    static Affine3D calculateNodeToSceneTransform(Node node) {
+        final Affine3D transform = new Affine3D();
+        do {
+            transform.preConcatenate(node.impl_getLeafTransform());
+            node = node.getParent();
+        } while (node != null);
+        
+        return transform;
+    }
+    
     // An unholy back-reference!
     public void setTextFieldSkin(TextFieldSkin skin) {
         this.skin = skin;
@@ -377,4 +419,12 @@
     protected void mouseTripleClick(HitInfo hit) {
         getControl().selectAll();
     }
+    
+    public enum TextInputTypes {
+        TEXT_FIELD,
+        PASSWORD_FIELD,
+        EDITABLE_COMBO,
+        TEXT_AREA;
+    }
+    
 }
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextInputControlSkin.java	Tue Aug 14 10:25:57 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextInputControlSkin.java	Wed Aug 15 11:10:44 2012 -0400
@@ -480,6 +480,12 @@
         final TextInputControl textInput = getSkinnable();
         if (textInput.isEditable() && !textInput.textProperty().isBound() && !textInput.isDisabled()) {
 
+            // just replace the text on iOS
+            if (PlatformUtil.isIOS()) {
+               textInput.setText(event.getCommitted());
+               return;
+            }
+            
             // remove previous input method text (if any) or selected text
             if (imlength != 0) {
                 removeHighlight(imattrs);
--- a/test-stub-toolkit/src/com/sun/javafx/pgstub/StubStage.java	Tue Aug 14 10:25:57 2012 -0700
+++ b/test-stub-toolkit/src/com/sun/javafx/pgstub/StubStage.java	Wed Aug 15 11:10:44 2012 -0400
@@ -238,6 +238,19 @@
         return notificationSender;
     }
 
+    @Override
+    public void requestInput(String text, int type, double width, double height, 
+                                double Mxx, double Mxy, double Mxz, double Mxt,
+                                double Myx, double Myy, double Myz, double Myt, 
+                                double Mzx, double Mzy, double Mzz, double Mzt) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public void releaseInput() {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
     private interface Notification {
         void execute(TKStageListener listener);
     }