diff --git a/java/custom/com/nokia/mid/ui/TextEditor.java b/java/custom/com/nokia/mid/ui/TextEditor.java index f8ec09ce..2358e8cc 100644 --- a/java/custom/com/nokia/mid/ui/TextEditor.java +++ b/java/custom/com/nokia/mid/ui/TextEditor.java @@ -3,29 +3,22 @@ package com.nokia.mid.ui; import javax.microedition.lcdui.Font; import java.util.Hashtable; -class TextEditorThread implements Runnable { +class TextEditorThread extends Thread { // We need a thread to be able to wake from js when there is an async js keyboard event. - native void sleep(); - native int getNextDirtyEditor(); - - Hashtable listeners; + native TextEditor getNextDirtyEditor(); TextEditorThread() { - listeners = new Hashtable(); + setPriority(Thread.MAX_PRIORITY); } public void run() { while (true) { - sleep(); - int dirty = getNextDirtyEditor(); - TextEditor t = (TextEditor)listeners.get("" + dirty); - t.myListener.inputAction(t, TextEditorListener.ACTION_CONTENT_CHANGE); + TextEditor dirty = getNextDirtyEditor(); + if (dirty.myListener != null) { + dirty.myListener.inputAction(dirty, TextEditorListener.ACTION_CONTENT_CHANGE); + } } } - - void register(int id, TextEditor t) { - listeners.put("" + id, t); - } } public class TextEditor extends CanvasItem { @@ -35,22 +28,20 @@ public class TextEditor extends CanvasItem { protected TextEditorListener myListener; private boolean multiline = false; - private int myId; private static TextEditorThread textEditorThread; private Font font = Font.getDefaultFont(); protected TextEditor(String text, int maxSize, int constraints, int width, int height) { - myId = init(text, maxSize, constraints, width, height); + init(text, maxSize, constraints, width, height); if (textEditorThread == null) { textEditorThread = new TextEditorThread(); - Thread t = new Thread(textEditorThread); - t.start(); + textEditorThread.start(); } } // Initialize the native representation. - native private int init(String text, int maxSize, int constraints, int width, int height); + native private void init(String text, int maxSize, int constraints, int width, int height); // Creates a new TextEditor object with the given initial contents, maximum size in characters, constraints and editor size in pixels. public static TextEditor createTextEditor(String text, int maxSize, int constraints, int width, int height) { @@ -186,7 +177,6 @@ public class TextEditor extends CanvasItem { // Sets a listener for content changes in this TextEditor, replacing any previous TextEditorListener. public void setTextEditorListener(TextEditorListener listener) { myListener = listener; - textEditorThread.register(myId, this); } // Returns the multiline state of the TextEditor. diff --git a/jit/analyze.ts b/jit/analyze.ts index 952e1d23..2aec959d 100644 --- a/jit/analyze.ts +++ b/jit/analyze.ts @@ -42,7 +42,7 @@ module J2ME { "com/ibm/oti/connection/file/FCOutputStream.openOffsetImpl.([BJ)I": YieldReason.Root, "com/sun/midp/io/j2me/storage/RandomAccessStream.open.(Ljava/lang/String;I)I": YieldReason.Root, "javax/microedition/lcdui/ImageDataFactory.createImmutableImageDecodeImage.(Ljavax/microedition/lcdui/ImageData;[BII)V": YieldReason.Root, - "com/nokia/mid/ui/TextEditorThread.sleep.()V": YieldReason.Root, + "com/nokia/mid/ui/TextEditorThread.getNextDirtyEditor.()Lcom/nokia/mid/ui/TextEditor;": YieldReason.Root, "com/nokia/mid/ui/TextEditor.setFocus.(Z)V": YieldReason.Root, "com/nokia/mid/ui/VKVisibilityNotificationRunnable.sleepUntilVKVisibilityChange.()Z": YieldReason.Root, "com/nokia/mid/s40/bg/BGUtils.waitUserInteraction.()V": YieldReason.Root, diff --git a/midp/gfx.js b/midp/gfx.js index 666ba4f4..ed41c583 100644 --- a/midp/gfx.js +++ b/midp/gfx.js @@ -1494,15 +1494,15 @@ var currentlyFocusedTextEditor; textEditorResolve = null, dirtyEditors = []; - function wakeTextEditorThread(id) { - dirtyEditors.push(id); + function wakeTextEditorThread(textEditor) { + dirtyEditors.push(textEditor); if (textEditorResolve) { textEditorResolve(); textEditorResolve = null; } } - Native["com/nokia/mid/ui/TextEditor.init.(Ljava/lang/String;IIII)I"] = + Native["com/nokia/mid/ui/TextEditor.init.(Ljava/lang/String;IIII)V"] = function(text, maxSize, constraints, width, height) { if (constraints != 0) { console.warn("TextEditor.constraints not implemented"); @@ -1542,9 +1542,8 @@ var currentlyFocusedTextEditor; this.setCaretPosition(this.textEditor.getContentSize()); this.textEditor.oninput(function(e) { - wakeTextEditorThread(this.textEditorId); + wakeTextEditorThread(this); }.bind(this)); - return textEditorId; }; Native["com/nokia/mid/ui/CanvasItem.attachNativeImpl.()V"] = function() { @@ -1719,23 +1718,16 @@ var currentlyFocusedTextEditor; this.textEditor.setFont(font); }; - Native["com/nokia/mid/ui/TextEditorThread.sleep.()V"] = function() { - asyncImpl("V", new Promise(function(resolve, reject) { - if (!dirtyEditors.length) { - textEditorResolve = resolve; - } else { - resolve(); - } - })); - }; - - Native["com/nokia/mid/ui/TextEditorThread.getNextDirtyEditor.()I"] = function() { - if (!dirtyEditors.length) { - console.error("ERROR: getNextDirtyEditor called but no dirty editors"); - return 0; + Native["com/nokia/mid/ui/TextEditorThread.getNextDirtyEditor.()Lcom/nokia/mid/ui/TextEditor;"] = function() { + if (dirtyEditors.length) { + return dirtyEditors.shift(); } - return dirtyEditors.shift(); + asyncImpl("I", new Promise(function(resolve, reject) { + textEditorResolve = function() { + resolve(dirtyEditors.shift()); + } + })); }; var curDisplayableId = 0;