Add support for HW more/back keys on Javascript popup
authorjunghwan.kang <junghwan.kang@samsung.com>
Thu, 27 Jun 2013 09:27:04 +0000 (18:27 +0900)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Thu, 27 Jun 2013 11:47:29 +0000 (11:47 +0000)
[Title] Add support for HW more/back keys on Javascript popup
[Issue#] N_SE-43128
[Problem] HW keys are not handled by Javascript popup.
[Cause] Not handled.
[Solution] Add support for HW more/back keys on Javascript popup

Change-Id: I1ea1f78b87a5e3c3b563cfb96ed6f0e342fb58cb

Source/WebKit2/UIProcess/API/efl/tizen/JavaScriptPopup.cpp

index efa54d9..9e5e30b 100755 (executable)
@@ -22,6 +22,7 @@
 
 #include "ewk_view.h"
 #include <Elementary.h>
+#include <efl_assist.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -54,6 +55,15 @@ static void alertResponseCallback(void* data, Evas_Object* obj, void* eventInfo)
     ewk_view_javascript_alert_reply(popup->ewkView());
 }
 
+static void alertHwBackKeyCallback(void* data, Evas_Object* obj, void* eventInfo)
+{
+    JavaScriptPopup* popup = static_cast<JavaScriptPopup*>(data);
+    if (!popup)
+        return;
+    popup->close();
+    ewk_view_javascript_alert_reply(popup->ewkView());
+}
+
 bool JavaScriptPopup::setLabelText(const char* message)
 {
     if (!message)
@@ -77,7 +87,7 @@ bool JavaScriptPopup::setLabelText(const char* message)
 
     // Get layout width to set a dynamic label wrap width
     int layoutWidth;
-    evas_object_geometry_get(layout, NULL, NULL, &layoutWidth, NULL);
+    evas_object_geometry_get(layout, 0, 0, &layoutWidth, 0);
 
     Evas_Object* label = elm_label_add(layout);
     elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
@@ -89,13 +99,13 @@ bool JavaScriptPopup::setLabelText(const char* message)
 
     // Get label height for check the length of the character
     int labelHeight;
-    evas_object_geometry_get(label, NULL, NULL, NULL, &labelHeight);
+    evas_object_geometry_get(label, 0, 0, 0, &labelHeight);
 
     // Use the general popup instead of scroll layout when message is a short sentences
     if (labelHeight < 400) {
         evas_object_del(m_popup);
 
-        Evas_Object *parent = getParentWindow();
+        Evas_Objectparent = getParentWindow();
 
         m_popup = elm_popup_add(parent);
         if (!m_popup)
@@ -114,7 +124,7 @@ bool JavaScriptPopup::setLabelText(const char* message)
 
 bool JavaScriptPopup::alert(const char* message)
 {
-    Evas_Object *parent = getParentWindow();
+    Evas_Objectparent = getParentWindow();
 
     if (m_popup)
         return false;
@@ -126,8 +136,10 @@ bool JavaScriptPopup::alert(const char* message)
     if (!setLabelText(message))
         return false;
 
+    ea_object_event_callback_add(m_popup, EA_CALLBACK_BACK, alertHwBackKeyCallback, this);
+
     Evas_Object* okButton = elm_button_add(m_popup);
-    //FIXME: Need to apply i18n for the button label
+    // FIXME: Need to apply i18n for the button label
     elm_object_text_set(okButton, "OK");
     elm_object_part_content_set(m_popup, "button1", okButton);
     evas_object_smart_callback_add(okButton, "clicked", alertResponseCallback, this);
@@ -155,9 +167,18 @@ static void confirmCancelCallback(void* data, Evas_Object* obj, void* eventInfo)
     ewk_view_javascript_confirm_reply(popup->ewkView(), false);
 }
 
+static void confirmHwBackKeyCallback(void* data, Evas_Object* obj, void* eventInfo)
+{
+    JavaScriptPopup* popup = static_cast<JavaScriptPopup*>(data);
+    if (!popup)
+        return;
+    popup->close();
+    ewk_view_javascript_confirm_reply(popup->ewkView(), false);
+}
+
 bool JavaScriptPopup::confirm(const char* message)
 {
-    Evas_Object *parent = getParentWindow();
+    Evas_Objectparent = getParentWindow();
 
     if (m_popup)
         return false;
@@ -169,14 +190,16 @@ bool JavaScriptPopup::confirm(const char* message)
     if (!setLabelText(message))
         return false;
 
+    ea_object_event_callback_add(m_popup, EA_CALLBACK_BACK, confirmHwBackKeyCallback, this);
+
     Evas_Object* okButton = elm_button_add(m_popup);
-    //FIXME: Need to apply i18n for the button label
+    // FIXME: Need to apply i18n for the button label
     elm_object_text_set(okButton, "OK");
     elm_object_part_content_set(m_popup, "button1", okButton);
     evas_object_smart_callback_add(okButton, "clicked", confirmOkCallback, this);
 
     Evas_Object* cancelButton = elm_button_add(m_popup);
-    //FIXME: Need to apply i18n for the button label
+    // FIXME: Need to apply i18n for the button label
     elm_object_text_set(cancelButton, "Cancel");
     elm_object_part_content_set(m_popup, "button2", cancelButton);
     evas_object_smart_callback_add(cancelButton, "clicked", confirmCancelCallback, this);
@@ -215,9 +238,18 @@ static void promptOkCallback(void* data, Evas_Object* obj, void* eventInfo)
         free(result);
 }
 
+static void promptHwBackKeyCallback(void* data, Evas_Object* obj, void* eventInfo)
+{
+    JavaScriptPopup* popup = static_cast<JavaScriptPopup*>(data);
+    if (!popup)
+        return;
+    popup->close();
+    ewk_view_javascript_prompt_reply(popup->ewkView(), 0);
+}
+
 bool JavaScriptPopup::prompt(const char* message, const char* defaultValue)
 {
-    Evas_Object *parent = getParentWindow();
+    Evas_Objectparent = getParentWindow();
 
     if (m_popup)
         return false;
@@ -246,7 +278,7 @@ bool JavaScriptPopup::prompt(const char* message, const char* defaultValue)
 
     m_entry = elm_entry_add(m_popup);
     Ecore_IMF_Context* imfContext = static_cast<Ecore_IMF_Context*>(elm_entry_imf_context_get(m_entry));
-    ecore_imf_context_input_panel_event_callback_add(imfContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, promptEntryChanged, NULL);
+    ecore_imf_context_input_panel_event_callback_add(imfContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, promptEntryChanged, 0);
     elm_entry_scrollable_set(m_entry, EINA_TRUE);
     elm_object_text_set(m_entry, defaultValue);
     elm_entry_cursor_end_set(m_entry);
@@ -254,14 +286,16 @@ bool JavaScriptPopup::prompt(const char* message, const char* defaultValue)
     elm_object_part_content_set(layout, "prompt_container", m_entry);
     elm_object_content_set(m_popup, layout);
 
+    ea_object_event_callback_add(m_popup, EA_CALLBACK_BACK, promptHwBackKeyCallback, this);
+
     Evas_Object* okButton = elm_button_add(m_popup);
-    //FIXME: Need to apply i18n for the button label
+    // FIXME: Need to apply i18n for the button label
     elm_object_text_set(okButton, "OK");
     elm_object_part_content_set(m_popup, "button1", okButton);
     evas_object_smart_callback_add(okButton, "clicked", promptOkCallback, this);
 
     Evas_Object* cancelButton = elm_button_add(m_popup);
-    //FIXME: Need to apply i18n for the button label
+    // FIXME: Need to apply i18n for the button label
     elm_object_text_set(cancelButton, "Cancel");
     elm_object_part_content_set(m_popup, "button2", cancelButton);
     evas_object_smart_callback_add(cancelButton, "clicked", promptCancelCallback, this);
@@ -306,13 +340,13 @@ bool JavaScriptPopup::beforeUnloadConfirmPanel(const char* message)
         return false;
 
     Evas_Object* leaveButton = elm_button_add(m_popup);
-    //FIXME: Need to apply i18n for the button label
+    // FIXME: Need to apply i18n for the button label
     elm_object_text_set(leaveButton, "Leave");
     elm_object_part_content_set(m_popup, "button1", leaveButton);
     evas_object_smart_callback_add(leaveButton, "clicked", beforeUnloadConfirmPanelLeaveCallback, this);
 
     Evas_Object* stayButton = elm_button_add(m_popup);
-    //FIXME: Need to apply i18n for the button label
+    // FIXME: Need to apply i18n for the button label
     elm_object_text_set(stayButton, "Stay");
     elm_object_part_content_set(m_popup, "button2", stayButton);
     evas_object_smart_callback_add(stayButton, "clicked", beforeUnloadConfirmPanelStayCallback, this);