Implements orientation lock spec
authorSeungkeun Lee <sngn.lee@samsung.com>
Wed, 8 Apr 2015 02:30:18 +0000 (11:30 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Wed, 8 Apr 2015 10:18:25 +0000 (19:18 +0900)
 http://www.w3.org/TR/screen-orientation/

Change-Id: Iea27c5e8652341ff22b605b9a4b185a68b87cd2b

src/runtime/web_application.cc
src/runtime/web_application.h
src/runtime/web_view.cc
src/runtime/web_view.h

index c77f7c7..500fc82 100755 (executable)
@@ -183,10 +183,33 @@ std::string WebApplication::GetDataPath() const {
 void WebApplication::OnRendered(WebView* view) {
 }
 
+
 void WebApplication::OnReceivedWrtMessage(
     WebView* view,
     const Ewk_IPC_Wrt_Message_Data& message) {
   // TODO(wy80.choi): To be implemented
 }
 
+void WebApplication::OnOrientationLock(WebView* view,
+                                       bool lock,
+                                       int preferred_rotation) {
+  if (view_stack_.size() == 0)
+    return;
+
+  // Only top-most view can set the orientation relate operation
+  if (view_stack_.front() != view)
+    return;
+
+  // TODO(sngn.lee): check the orientaion setting
+  // if allow the auto orientation
+  // if (is not allow orientation) {
+  //   return;
+  // }
+  if ( lock ) {
+    window_->SetRotationLock(preferred_rotation);
+  } else {
+    window_->SetAutoRotation();
+  }
+}
+
 }  // namespace wrt
index d419865..490adc0 100755 (executable)
@@ -34,6 +34,9 @@ class WebApplication : public WebView::EventListener {
   virtual void OnRendered(WebView* view);
   virtual void OnReceivedWrtMessage(WebView* view,
                                     const Ewk_IPC_Wrt_Message_Data& message);
+  virtual void OnOrientationLock(WebView* view,
+                                 bool lock,
+                                 int preferred_rotation);
 
  private:
   void ClearViewStack();
index 3800545..5fa3e32 100755 (executable)
@@ -19,9 +19,6 @@ const char* kKeyNameMenu = "menu";
 
 static int ToWebRotation(int r) {
   switch (r) {
-    case 0:
-    case 180:
-      return r;
     case 90:
       return -90;
     case 270:
@@ -30,6 +27,16 @@ static int ToWebRotation(int r) {
   return r;
 }
 
+static int ToNativeRotation(int r) {
+  switch (r) {
+    case -90:
+      return 90;
+    case 90:
+      return 270;
+  }
+  return r;
+}
+
 }  // namespace
 
 
@@ -273,6 +280,23 @@ void WebView::Initialize() {
                                  wrt_message_callback,
                                  this);
 
+  // Orientation lock callback
+  auto orientation_lock_callback = [](Evas_Object* o,
+                                      Eina_Bool need_lock,
+                                      int orientation,
+                                      void* user_data) -> Eina_Bool {
+    WebView* self = static_cast<WebView*>(user_data);
+    if (self->listener_) {
+      self->listener_->OnOrientationLock(self,
+                                         need_lock,
+                                         ToNativeRotation(orientation));
+    }
+    return EINA_TRUE;
+  };
+  ewk_view_orientation_lock_callback_set(ewk_view_,
+                                         orientation_lock_callback,
+                                         this);
+
   // rotation support
   ewk_view_orientation_send(ewk_view_, ToWebRotation(window_->rotation()));
   rotation_handler_id_ = window_->AddRotationHandler(
index 8ddcd9c..57882bf 100755 (executable)
@@ -35,6 +35,10 @@ class WebView {
         WebView* /*view*/, const std::string& /*keyname*/) {}
     virtual void OnReceivedWrtMessage(
         WebView* /*view*/, const Ewk_IPC_Wrt_Message_Data& /*msg*/) {}
+    virtual void OnOrientationLock(
+        WebView* /*view*/,
+        bool /*lock*/,
+        int /*preferred_rotation*/) {}
   };
 
   WebView(wrt::NativeWindow* window, Ewk_Context* context);