Apply to softkeyboardchange event
authorJongHeon Choi <j-h.choi@samsung.com>
Fri, 22 Apr 2016 05:32:23 +0000 (14:32 +0900)
committerJongHeon Choi <j-h.choi@samsung.com>
Fri, 22 Apr 2016 06:26:55 +0000 (15:26 +0900)
runtime/browser/web_application.cc
runtime/browser/web_application.h
runtime/browser/web_view.h
runtime/browser/web_view_impl.cc
runtime/browser/web_view_impl.h

index 0ebce7aff456c205404053ab461dc7e52a52259e..4e052da68c4637b2a2d9a33cff937e5f5656cec7 100644 (file)
@@ -670,6 +670,28 @@ void WebApplication::OnLowMemory() {
   ewk_context_notify_low_memory(ewk_context_);
 }
 
+void WebApplication::OnSoftKeyboardChangeEvent(WebView* /*view*/,
+                               SoftKeyboardChangeEventValue softkeyboard_value) {
+  LOGGER(DEBUG) << "OnSoftKeyboardChangeEvent";
+  std::stringstream script;
+  script
+    << "(function(){"
+    << "var __event = document.createEvent(\"CustomEvent\");\n"
+    << "var __detail = {};\n"
+    << "__event.initCustomEvent(\"softkeyboardchange\",true,true,__detail);\n"
+    << "__event.state = \"" << softkeyboard_value.state << "\";\n"
+    << "__event.width = " << softkeyboard_value.width << ";\n"
+    << "__event.height = " << softkeyboard_value.height << ";\n"
+    << "document.dispatchEvent(__event);\n"
+    << "\n"
+    << "for (var i=0; i < window.frames.length; i++)\n"
+    << "{ window.frames[i].document.dispatchEvent(__event); }"
+    << "})()";
+  std::string kSoftKeyboardScript = script.str();
+  if (view_stack_.size() > 0 && view_stack_.front() != NULL)
+    view_stack_.front()->EvalJavascript(kSoftKeyboardScript.c_str());
+}
+
 #ifdef PROFILE_WEARABLE
 void WebApplication::OnRotaryEvent(WebView* /*view*/,
                                    RotaryEventType type) {
index 9249b7fabac6ad98b3af2b5bc9b991ed83fdc2d6..f3c398905163376c43fc33ccbe8be6a30850bc33 100755 (executable)
@@ -89,9 +89,11 @@ class WebApplication : public WebView::EventListener {
   virtual void OnUsermediaPermissionRequest(
       WebView* view, const std::string& url,
       std::function<void(bool)> result_handler);
+  virtual void OnSoftKeyboardChangeEvent(
+      WebView* view, SoftKeyboardChangeEventValue softkeyboard_value);
 #ifdef PROFILE_WEARABLE
-  virtual void OnRotaryEvent(WebView* view,
-      RotaryEventType type);
+  virtual void OnRotaryEvent(
+      WebView* view, RotaryEventType type);
 #endif  // PROFILE_WEARABLE
 
  private:
index 00ba0038d6b9fad362bbc8df61c4734909f40cdf..64566500794bf3860a7a8c11ff44bb7aeeee65c2 100644 (file)
@@ -34,6 +34,13 @@ enum class RotaryEventType {
   COUNTER_CLOCKWISE  // Rotary is rotated counter clockwise direction
 };
 
+class SoftKeyboardChangeEventValue {
+ public:
+  std::string state;
+  int width;
+  int height;
+};
+
 class WebView {
  public:
   class EventListener {
@@ -92,6 +99,9 @@ class WebView {
         WebView* /*view*/,
         const std::string& /*url*/,
         std::function<void(bool)> /*result_handler*/) {}
+    virtual void OnSoftKeyboardChangeEvent(
+        WebView* /*view*/,
+        SoftKeyboardChangeEventValue /*softkeyboard_value*/) {}
 #ifdef PROFILE_WEARABLE
     virtual void OnRotaryEvent(
         WebView* /*view*/,
index 6c7629f3cd24656f3cd4b4d7427e2f8d100983af..2d3a7dce0bcd731010eab12e51a69d2c44303df2 100644 (file)
@@ -80,7 +80,9 @@ WebViewImpl::WebViewImpl(WebView* view,
       view_(view),
       fullscreen_(false),
       evas_smart_class_(NULL),
-      internal_popup_opened_(false) {
+      internal_popup_opened_(false),
+      ime_width_(0),
+      ime_height_(0) {
   Initialize();
 }
 
@@ -199,6 +201,7 @@ void WebViewImpl::Initialize() {
   InitCertificateAllowCallback();
   InitPopupWaitCallback();
   InitUsermediaCallback();
+  InitEditorClientImeCallback();
 #ifdef PROFILE_WEARABLE
   InitRotaryEventCallback();
 #endif  // PROFILE_WEARABLE
@@ -828,6 +831,57 @@ void WebViewImpl::InitUsermediaCallback() {
   ewk_view_user_media_permission_callback_set(ewk_view_, callback, this);
 }
 
+void WebViewImpl::InitEditorClientImeCallback() {
+  auto ime_changed_callback = [](void* user_data,
+                           Evas_Object*,
+                           void* event_info) {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+
+    Eina_Rectangle *rect = static_cast<Eina_Rectangle *>(event_info);
+    self->ime_width_ = rect->w;
+    self->ime_height_ = rect->h;
+  };
+
+  auto ime_opened_callback = [](void* user_data,
+                           Evas_Object*,
+                           void* event_info) {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+
+    SoftKeyboardChangeEventValue softkeyboard_value;
+    softkeyboard_value.state = "on";
+    softkeyboard_value.width = self->ime_width_;
+    softkeyboard_value.height = self->ime_height_;
+
+    self->listener_->OnSoftKeyboardChangeEvent(self->view_, softkeyboard_value);
+  };
+
+  auto ime_closed_callback = [](void* user_data,
+                           Evas_Object*,
+                           void* event_info) {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+
+    SoftKeyboardChangeEventValue softkeyboard_value;
+    softkeyboard_value.state = "off";
+
+    self->listener_->OnSoftKeyboardChangeEvent(self->view_, softkeyboard_value);
+  };
+  evas_object_smart_callback_add(ewk_view_,
+                                 "inputmethod,changed",
+                                 ime_changed_callback,
+                                 this);
+  evas_object_smart_callback_add(ewk_view_,
+                                 "editorclient,ime,opened",
+                                 ime_opened_callback,
+                                 this);
+  evas_object_smart_callback_add(ewk_view_,
+                                 "editorclient,ime,closed",
+                                 ime_closed_callback,
+                                 this);
+  smart_callbacks_["inputmethod,changed"] = ime_changed_callback;
+  smart_callbacks_["editorclient,ime,opened"] = ime_opened_callback;
+  smart_callbacks_["editorclient,ime,closed"] = ime_closed_callback;
+}
+
 #ifdef PROFILE_WEARABLE
 void WebViewImpl::InitRotaryEventCallback() {
   auto rotary_callback = [](void* user_data,
index c3d0551f7c9a786eb04ce6467a6cb57a1733247c..9b6b3b11657731c894a0bbfb51b32334ce1e11f3 100644 (file)
@@ -75,6 +75,7 @@ class WebViewImpl {
   void InitCertificateAllowCallback();
   void InitPopupWaitCallback();
   void InitUsermediaCallback();
+  void InitEditorClientImeCallback();
 #ifdef PROFILE_WEARABLE
   void InitRotaryEventCallback();
 #endif  // PROFILE_WEARABLE
@@ -91,6 +92,8 @@ class WebViewImpl {
   Evas_Smart* evas_smart_class_;
   Ewk_View_Smart_Class ewk_smart_class_;
   bool internal_popup_opened_;
+  size_t ime_width_;
+  size_t ime_height_;
 };
 }  // namespace runtime