зеркало из https://github.com/mozilla/pluotsorbet.git
Merge pull request #1004 from marco-c/texteditor_listener_improvements
Some improvements for TextEditor listeners
This commit is contained in:
Коммит
95cdc7a246
|
@ -3,28 +3,21 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
32
midp/gfx.js
32
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,25 +1718,18 @@ 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.()Lcom/nokia/mid/ui/TextEditor;"] = function() {
|
||||
if (dirtyEditors.length) {
|
||||
return dirtyEditors.shift();
|
||||
}
|
||||
|
||||
asyncImpl("I", new Promise(function(resolve, reject) {
|
||||
textEditorResolve = function() {
|
||||
resolve(dirtyEditors.shift());
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
Native["com/nokia/mid/ui/TextEditorThread.getNextDirtyEditor.()I"] = function() {
|
||||
if (!dirtyEditors.length) {
|
||||
console.error("ERROR: getNextDirtyEditor called but no dirty editors");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return dirtyEditors.shift();
|
||||
};
|
||||
|
||||
var curDisplayableId = 0;
|
||||
var nextMidpDisplayableId = 1;
|
||||
var PLAIN = 0;
|
||||
|
|
Загрузка…
Ссылка в новой задаче