Use smart class 52/41152/9
authorSeungkeun Lee <sngn.lee@samsung.com>
Thu, 11 Jun 2015 09:56:46 +0000 (18:56 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Mon, 10 Aug 2015 02:14:14 +0000 (11:14 +0900)
 - To enable orientation lock API

Change-Id: I3c6213b364155da7f4e4e3aba4890f7b7ef1b500

src/runtime/web_view_impl.cc
src/runtime/web_view_impl.h

index f817339..9653340 100755 (executable)
@@ -32,6 +32,7 @@ namespace {
 const char* kKeyNameBack = "back";
 const char* kKeyNameMenu = "menu";
 const char* kDefaultEncoding = "UTF-8";
+const char* kSmartClassUserDataKey = "__SC_USERDATA__";
 
 static int ToWebRotation(int r) {
   switch (r) {
@@ -66,13 +67,16 @@ WebViewImpl::WebViewImpl(WebView* view,
       ewk_view_(NULL),
       listener_(NULL),
       view_(view),
-      fullscreen_(false) {
+      fullscreen_(false),
+      evas_smart_class_(NULL) {
   Initialize();
 }
 
 WebViewImpl::~WebViewImpl() {
   Deinitialize();
   evas_object_del(ewk_view_);
+  if (evas_smart_class_ != NULL)
+    evas_smart_free(evas_smart_class_);
 }
 
 void WebViewImpl::LoadUrl(const std::string& url, const std::string& mime) {
@@ -118,7 +122,45 @@ bool WebViewImpl::EvalJavascript(const std::string& script) {
 }
 
 void WebViewImpl::Initialize() {
-  ewk_view_ = ewk_view_add_with_context(window_->evas_object(), context_);
+  ewk_smart_class_ = EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION("WebView");
+  ewk_view_smart_class_set(&ewk_smart_class_);
+  ewk_smart_class_.orientation_lock = [](Ewk_View_Smart_Data *sd,
+                                         int orientation) {
+    WebViewImpl* self = static_cast<WebViewImpl*>(
+        evas_object_data_get(sd->self, kSmartClassUserDataKey));
+    if (self == NULL || self->listener_ == NULL)
+      return EINA_FALSE;
+    self->listener_->OnOrientationLock(self->view_,
+                                       true,
+                                       ToNativeRotation(orientation));
+    return EINA_TRUE;
+  };
+
+  ewk_smart_class_.orientation_unlock = [](Ewk_View_Smart_Data *sd) {
+    WebViewImpl* self = static_cast<WebViewImpl*>(
+        evas_object_data_get(sd->self, kSmartClassUserDataKey));
+    if (self == NULL || self->listener_ == NULL)
+      return;
+    self->listener_->OnOrientationLock(
+        self->view_,
+        false,
+        NativeWindow::ScreenOrientation::PORTRAIT_PRIMARY);
+  };
+
+  if (evas_smart_class_ != NULL)
+    evas_smart_free(evas_smart_class_);
+  evas_smart_class_ = evas_smart_class_new(&ewk_smart_class_.sc);
+  if (evas_smart_class_ == NULL) {
+    LOGGER(ERROR) << "Can't create evas smart class";
+    return;
+  }
+
+  Ewk_Page_Group* page_group = ewk_page_group_create("");
+  ewk_view_ = ewk_view_smart_add(evas_object_evas_get(window_->evas_object()),
+                                 evas_smart_class_,
+                                 context_,
+                                 page_group);
+  evas_object_data_set(ewk_view_, kSmartClassUserDataKey, this);
 
   InitKeyCallback();
   InitLoaderCallback();
index 0142593..d56cfd2 100755 (executable)
@@ -18,7 +18,7 @@
 #ifndef WRT_RUNTIME_WEB_VIEW_IMPL_H_
 #define WRT_RUNTIME_WEB_VIEW_IMPL_H_
 
-
+#include <ewk_chromium.h>
 #include <Elementary.h>
 #include <efl_extension.h>
 #include <string>
@@ -27,8 +27,6 @@
 #include "runtime/web_view.h"
 #include "common/url.h"
 
-class Ewk_Context;
-
 namespace wrt {
 class NativeWindow;
 class WebViewImpl {
@@ -84,6 +82,8 @@ class WebViewImpl {
   std::map<const std::string, Evas_Smart_Cb> smart_callbacks_;
   bool fullscreen_;
   std::string mime_;
+  Evas_Smart* evas_smart_class_;
+  Ewk_View_Smart_Class ewk_smart_class_;
 };
 }  // namespace wrt