Implement natural orientation to support landscape natural device 86/39786/13
authorSeungkeun Lee <sngn.lee@samsung.com>
Fri, 22 May 2015 08:38:57 +0000 (17:38 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Mon, 1 Jun 2015 02:03:21 +0000 (19:03 -0700)
Change-Id: I2d5dc47c92f04c99a60a6248b5d12296f9e90576

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

index d4394d9..3512fce 100755 (executable)
@@ -142,6 +142,12 @@ void NativeWindow::Initialize() {
                                  rotation_callback,
                                  this);
 
+  if (w > h) {
+    natural_orientation_ = ScreenOrientation::LANDSCAPE_PRIMARY;
+  } else {
+    natural_orientation_ = ScreenOrientation::PORTRAIT_PRIMARY;
+  }
+
   initialized_ = true;
 }
 
@@ -201,8 +207,30 @@ void NativeWindow::RemoveRotationHandler(int id) {
 void NativeWindow::SetRotationLock(int degree) {
   rotation_ = degree%360;
   elm_win_wm_rotation_preferred_rotation_set(window_, rotation_);
+  elm_win_rotation_set(window_, rotation_);
 }
 
+void NativeWindow::SetRotationLock(ScreenOrientation orientation) {
+  int portrait_natural_angle[] = {
+    0,  // PORTRAIT_PRIMARY
+    180,  // PORTRAIT_SECONDARY
+    270,  // LANDSCAPE_PRIMARY
+    90  // LANDSCAPE_SECONDARY
+  };
+  int landscape_natural_angle[] = {
+    270,  // PORTRAIT_PRIMARY
+    90,  // PORTRAIT_SECONDARY
+    0,  // LANDSCAPE_PRIMARY
+    180  // LANDSCAPE_SECONDARY
+  };
+  auto& convert_table =
+      natural_orientation_ == ScreenOrientation::PORTRAIT_PRIMARY ?
+          portrait_natural_angle :
+          landscape_natural_angle;
+  SetRotationLock(convert_table[static_cast<int>(orientation)]);
+}
+
+
 void NativeWindow::SetAutoRotation() {
   elm_win_wm_rotation_preferred_rotation_set(window_, -1);
   if (elm_win_wm_rotation_supported_get(window_)) {
index 120d1e9..291b138 100755 (executable)
@@ -25,6 +25,12 @@ namespace wrt {
 
 class NativeWindow {
  public:
+  enum class ScreenOrientation {
+    PORTRAIT_PRIMARY = 0,
+    PORTRAIT_SECONDARY = 1,
+    LANDSCAPE_PRIMARY = 2,
+    LANDSCAPE_SECONDARY = 3
+  };
   typedef std::function<void(int)> RotationHandler;
   NativeWindow();
   virtual ~NativeWindow();
@@ -35,6 +41,7 @@ class NativeWindow {
   Evas_Object* evas_object() const;
   void SetContent(Evas_Object* content);
   void SetRotationLock(int degree);
+  void SetRotationLock(ScreenOrientation orientation);
   void SetAutoRotation();
   int AddRotationHandler(RotationHandler handler);
   void RemoveRotationHandler(int id);
@@ -43,6 +50,7 @@ class NativeWindow {
   void Active();
   void InActive();
   void FullScreen(bool enable);
+  ScreenOrientation natural_orientation() const { return natural_orientation_;}
 
  protected:
   virtual Evas_Object* CreateWindowInternal() = 0;
@@ -61,6 +69,7 @@ class NativeWindow {
   Evas_Object* content_;
   int rotation_;
   int handler_id_;
+  ScreenOrientation natural_orientation_;
   std::map<int, RotationHandler> handler_table_;
 };
 
index 6556c91..4ce003e 100755 (executable)
@@ -278,6 +278,16 @@ bool WebApplication::Initialize() {
     ewk_context_tizen_extensible_api_string_set(ewk_context_,
                                                 kRotationLockFeature,
                                                 true);
+  } else if (app_data_->setting_info() != NULL &&
+             app_data_->setting_info()->screen_orientation()
+             == wgt::parse::SettingInfo::ScreenOrientation::PORTRAIT) {
+    window_->SetRotationLock(
+        NativeWindow::ScreenOrientation::PORTRAIT_PRIMARY);
+  } else if (app_data_->setting_info() != NULL &&
+             app_data_->setting_info()->screen_orientation()
+             == wgt::parse::SettingInfo::ScreenOrientation::LANDSCAPE) {
+    window_->SetRotationLock(
+        NativeWindow::ScreenOrientation::LANDSCAPE_PRIMARY);
   }
 
   if (app_data_->setting_info() != NULL &&
@@ -570,9 +580,10 @@ void WebApplication::OnReceivedWrtMessage(
   eina_stringshare_del(msg_id);
 }
 
-void WebApplication::OnOrientationLock(WebView* view,
-                                       bool lock,
-                                       int preferred_rotation) {
+void WebApplication::OnOrientationLock(
+    WebView* view,
+    bool lock,
+    NativeWindow::ScreenOrientation preferred_rotation) {
   if (view_stack_.size() == 0)
     return;
 
index 0729ba0..588d187 100755 (executable)
@@ -55,9 +55,10 @@ class WebApplication : public WebView::EventListener {
   virtual void OnClosedWebView(WebView * view);
   virtual void OnReceivedWrtMessage(WebView* view,
                                     Ewk_IPC_Wrt_Message_Data* msg);
-  virtual void OnOrientationLock(WebView* view,
-                                 bool lock,
-                                 int preferred_rotation);
+  virtual void OnOrientationLock(
+      WebView* view,
+      bool lock,
+      NativeWindow::ScreenOrientation preferred_rotation);
   virtual void OnHardwareKey(WebView* view, const std::string& keyname);
   virtual void OnConsoleMessage(const std::string& msg, int level);
 
index 679c446..96efa98 100755 (executable)
 #include <string>
 #include <functional>
 
+#include "runtime/native_window.h"
+
+
 class Ewk_Context;
 
 namespace wrt {
-class NativeWindow;
 class WebViewImpl;
 
 class WebView {
@@ -52,7 +54,7 @@ class WebView {
     virtual void OnOrientationLock(
         WebView* /*view*/,
         bool /*lock*/,
-        int /*preferred_rotation*/) {}
+        NativeWindow::ScreenOrientation /*preferred_rotation*/) {}
     virtual void OnConsoleMessage(const std::string& /*msg*/, int /*level*/) {}
     virtual bool OnContextMenuDisabled(WebView* /*view*/) { return false; }
 
index 510c0d2..07ebd9f 100755 (executable)
@@ -41,16 +41,19 @@ static int ToWebRotation(int r) {
   return r;
 }
 
-static int ToNativeRotation(int r) {
-  switch (r) {
-    case -90:
-      return 90;
-    case 90:
-      return 270;
+static NativeWindow::ScreenOrientation ToNativeRotation(int r) {
+  if (r & EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY) {
+    return NativeWindow::ScreenOrientation::PORTRAIT_PRIMARY;
+  } else if (r & EWK_SCREEN_ORIENTATION_PORTRAIT_SECONDARY) {
+    return NativeWindow::ScreenOrientation::PORTRAIT_SECONDARY;
+  } else if (r & EWK_SCREEN_ORIENTATION_LANDSCAPE_PRIMARY) {
+    return NativeWindow::ScreenOrientation::LANDSCAPE_PRIMARY;
+  } else {
+    return NativeWindow::ScreenOrientation::LANDSCAPE_SECONDARY;
   }
-  return r;
 }
 
+
 }  // namespace
 
 WebViewImpl::WebViewImpl(WebView* view,