From b1eb31db2cb0b4da2dc60127e721fd4a2e43e307 Mon Sep 17 00:00:00 2001 From: Pin Zhang Date: Sun, 9 Nov 2014 11:45:44 +0800 Subject: [PATCH] Fix LWUIT text editor focus issue. We need to click twice to focus the text editor, because setVisible() is called after setFocus(). --- midp/gfx.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/midp/gfx.js b/midp/gfx.js index e2a38e54..0e45b3eb 100644 --- a/midp/gfx.js +++ b/midp/gfx.js @@ -908,7 +908,8 @@ this.textEditor.style.width = width + "px"; this.textEditor.style.height = height + "px"; this.textEditor.style.position = "absolute"; - this.textEditor.style.visibility = "hidden"; + this.textEditor.style.opacity = 0; + this.textEditor.style.zIndex = -999; this.textEditor.oninput = function(e) { wakeTextEditorThread(this.textEditorId); }.bind(this); @@ -935,9 +936,16 @@ Native.create("com/nokia/mid/ui/CanvasItem.setVisible.(Z)V", function(visible) { if (visible && !this.visible) { - this.textEditor.style.visibility = "visible"; + // Sometimes in Java, setVisible() is called after setFocus(), to make + // sure the native input won't lose focus, we change opacity instead + // of visibility. + this.textEditor.style.opacity = 1; + this.textEditor.style.zIndex = 999; } else if (!visible && this.visible) { - this.textEditor.style.visibility = "hidden"; + this.textEditor.style.opacity = 0; + // To make sure the j2me control could be clicked again to show the + // textEditor, we need to put the textEditor at the bottom. + this.textEditor.style.zIndex = -999; } this.visible = visible; });