Fix firing serveral times of ime js event when ime shows or hides
authorYunchan Cho <yunchan.cho@samsung.com>
Wed, 5 Dec 2012 05:26:07 +0000 (14:26 +0900)
committerYunchan Cho <yunchan.cho@samsung.com>
Thu, 13 Dec 2012 10:43:55 +0000 (19:43 +0900)
[Issue#]       N/A
[Bug]          ime js event is fired several times when ime shows or hides
[Cause]        "inputmethod,changed" webview smart event is fired serveral time when ime show or hides
[Solution]     "inputmethod,changed" event is used just for getting width/height of ime, and
               wrt fires once ime js event to web contents when "editorclient,ime,opened" event is emitted by webkit

Change-Id: I1ddc353297513bd4004d4b9bbccfc1eab44e3f8f

src/view/webkit/view_logic.cpp
src/view/webkit/view_logic.h

index 9a8f331..2712554 100644 (file)
@@ -114,6 +114,7 @@ const char * const EWK_FULLSCREEN_EXIT = "fullscreen,exitfullscreen";
 
 // IME Callback
 const char * const EWK_INPUTMETHOD_CHANGED = "inputmethod,changed";
+const char * const EWK_EDITORCLIENT_IME_OPENED = "editorclient,ime,opened";
 const char * const EWK_EDITORCLIENT_IME_CLOSED = "editorclient,ime,closed";
 
 // Custom handlers
@@ -652,12 +653,12 @@ void ViewLogic::ewkClientInit(Evas_Object *wkView) {
         this);
 
 
-     // when ime start to be showed on the webview,
-     // this callback will be called
+    // when ime start to be showed on the webview,
+    // this callback will be called
     evas_object_smart_callback_add(
         wkView,
         EWK_INPUTMETHOD_CHANGED,
-        imeOpenCallback,
+        imeChangedCallback,
         this);
 
     // this callback will be called
@@ -666,18 +667,18 @@ void ViewLogic::ewkClientInit(Evas_Object *wkView) {
     // if web content should know size of ime,
     //  use "inputmethod,changed" instead of this.
     //
-    //evas_object_smart_callback_add(
-    //        wkView,
-    //        "editorclient,ime,opened",
-    //        imeSomethingCallback,
-    //        this);
+    evas_object_smart_callback_add(
+        wkView,
+        EWK_EDITORCLIENT_IME_OPENED,
+        imeOpenedCallback,
+        this);
 
     // when ime finished to be hidden,
     // this callback will be called
     evas_object_smart_callback_add(
         wkView,
         EWK_EDITORCLIENT_IME_CLOSED,
-        imeCloseCallback,
+        imeClosedCallback,
         this);
 
     // custom content/scheme handlers
@@ -825,15 +826,19 @@ void ViewLogic::ewkClientDeinit(Evas_Object *wkView) {
         NULL,
         NULL);
 
-    // ime show/hide callback
+    // ime change/show/hide callback
     evas_object_smart_callback_del(
         wkView,
         EWK_INPUTMETHOD_CHANGED,
-        imeOpenCallback);
+        imeChangedCallback);
+    evas_object_smart_callback_del(
+        wkView,
+        EWK_EDITORCLIENT_IME_OPENED,
+        imeOpenedCallback);
     evas_object_smart_callback_del(
         wkView,
         EWK_EDITORCLIENT_IME_CLOSED,
-        imeCloseCallback);
+        imeClosedCallback);
 
     // custom content/scheme handlers
     evas_object_smart_callback_del(
@@ -1629,7 +1634,7 @@ void ViewLogic::exitFullscreenCallback(
     }
 }
 
-void ViewLogic::imeOpenCallback(
+void ViewLogic::imeChangedCallback(
         void* data,
         Evas_Object* /*obj*/,
         void* eventInfo)
@@ -1639,18 +1644,30 @@ void ViewLogic::imeOpenCallback(
     Assert(eventInfo);
     ViewLogic* This = static_cast<ViewLogic*>(data);
     Eina_Rectangle *rect = static_cast<Eina_Rectangle *>(eventInfo);
+    This->m_imeWidth = rect->w;
+    This->m_imeHeight = rect->h;
+}
+
+void ViewLogic::imeOpenedCallback(
+        void* data,
+        Evas_Object* /*obj*/,
+        void* /*eventInfo*/)
+{
+    LogDebug("enter");
+    Assert(data);
+    ViewLogic* This = static_cast<ViewLogic*>(data);
 
     using namespace WrtPlugins::W3C;
     SoftKeyboardChangeArgs args;
     args.state = IME_STATE_ON;
-    args.width = rect->w;
-    args.height = rect->h;
+    args.width = This->m_imeWidth;
+    args.height = This->m_imeHeight;
     This->fireJavascriptEvent(
             static_cast<int>(SoftKeyboardChangeCustomEvent),
             &args);
 }
 
-void ViewLogic::imeCloseCallback(
+void ViewLogic::imeClosedCallback(
         void* data,
         Evas_Object* /*obj*/,
         void* /*eventInfo*/)
index b48e524..bf7f7af 100644 (file)
@@ -205,12 +205,16 @@ class ViewLogic : public ViewModule::IViewModule
             Evas_Object* obj,
             void* eventInfo);
 
-    // EWK IME Show/Hide Callback
-    static void imeOpenCallback(
+    // EWK IME Change/Show/Hide Callback
+    static void imeChangedCallback(
             void* data,
             Evas_Object* obj,
             void* eventInfo);
-    static void imeCloseCallback(
+    static void imeOpenedCallback(
+            void* data,
+            Evas_Object* obj,
+            void* eventInfo);
+    static void imeClosedCallback(
             void* data,
             Evas_Object* obj,
             void* eventInfo);
@@ -287,6 +291,8 @@ class ViewLogic : public ViewModule::IViewModule
     std::string m_theme;
     std::string m_startUrl;
     WRT::UserDelegatesPtr m_cbs;
+    size_t m_imeWidth;
+    size_t m_imeHeight;
 
     std::unique_ptr<SchemeSupport> m_schemeSupport;
     std::unique_ptr<ViewModule::AppsSupport> m_appsSupport;