Fix getting orientation for splash screen
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 14 Jul 2016 11:34:11 +0000 (13:34 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 26 Jul 2016 13:53:33 +0000 (15:53 +0200)
Screen orientation should not be based on natural orientation.

Change-Id: Iba0b7c6954c94205d5695b125c7a311a69e07a0f

common/arraysize.h [new file with mode: 0644]
extensions/renderer/xwalk_extension_module.cc
runtime/browser/native_window.cc
runtime/browser/native_window.h
runtime/browser/splash_screen.cc
runtime/browser/web_application.cc

diff --git a/common/arraysize.h b/common/arraysize.h
new file mode 100644 (file)
index 0000000..5e4f626
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef XWALK_COMMON_ARRAYSIZE_H_
+#define XWALK_COMMON_ARRAYSIZE_H_
+
+// The ARRAYSIZE(arr) macro returns the # of elements in an array arr.
+// The expression is a compile-time constant, and therefore can be
+// used in defining new arrays, for example.  If you use arraysize on
+// a pointer by mistake, you will get a compile-time error.
+//
+// One caveat is that ARRAYSIZE() doesn't accept any array of an
+// anonymous type or a type defined inside a function.  In these rare
+// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below.  This is
+// due to a limitation in C++'s template system.  The limitation might
+// eventually be removed, but it hasn't happened yet.
+
+// This template function declaration is used in defining arraysize.
+// Note that the function doesn't need an implementation, as we only
+// use its type.
+template <typename T, size_t N>
+char (&ArraySizeHelper(T (&array)[N]))[N];
+
+#define ARRAYSIZE(array) (sizeof(ArraySizeHelper(array)))
+
+#endif  // XWALK_COMMON_ARRAYSIZE_H_
+
index 4294ec6..147b417 100644 (file)
 
 #include <vector>
 
+#include "common/arraysize.h"
 #include "common/logger.h"
 #include "common/profiler.h"
 #include "extensions/renderer/runtime_ipc_client.h"
 #include "extensions/renderer/xwalk_extension_client.h"
 #include "extensions/renderer/xwalk_module_system.h"
 
-// The arraysize(arr) macro returns the # of elements in an array arr.
-// The expression is a compile-time constant, and therefore can be
-// used in defining new arrays, for example.  If you use arraysize on
-// a pointer by mistake, you will get a compile-time error.
-//
-// One caveat is that arraysize() doesn't accept any array of an
-// anonymous type or a type defined inside a function.  In these rare
-// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below.  This is
-// due to a limitation in C++'s template system.  The limitation might
-// eventually be removed, but it hasn't happened yet.
-
-// This template function declaration is used in defining arraysize.
-// Note that the function doesn't need an implementation, as we only
-// use its type.
-template <typename T, size_t N>
-char (&ArraySizeHelper(T (&array)[N]))[N];
-
-#define arraysize(array) (sizeof(ArraySizeHelper(array)))
-
 namespace extensions {
 
 namespace {
@@ -146,17 +128,17 @@ static void StringAppendVT(StringType* dst,
   va_list ap_copy;
   va_copy(ap_copy, ap);
 
-  int result = vsnprintf(stack_buf, arraysize(stack_buf), format, ap_copy);
+  int result = vsnprintf(stack_buf, ARRAYSIZE(stack_buf), format, ap_copy);
   va_end(ap_copy);
 
-  if (result >= 0 && result < static_cast<int>(arraysize(stack_buf))) {
+  if (result >= 0 && result < static_cast<int>(ARRAYSIZE(stack_buf))) {
     // It fit.
     dst->append(stack_buf, result);
     return;
   }
 
   // Repeatedly increase buffer size until it fits.
-  int mem_length = arraysize(stack_buf);
+  int mem_length = ARRAYSIZE(stack_buf);
   while (true) {
     if (result < 0) {
       if (errno != 0 && errno != EOVERFLOW)
index 47d6730..8709672 100755 (executable)
 #include <ewk_chromium.h>
 #include <cstdint>
 
+#include "common/arraysize.h"
 #include "common/logger.h"
 
 namespace runtime {
 
 namespace {
-  const char* kEdjePath = "/usr/share/edje/xwalk/xwalk_tizen.edj";
-  const char* kWinowRotationEventKey = "wm,rotation,changed";
-  const char* kWinowFocusedEventKey = "focused";
-  const char* kWinowUnfocusedEventKey = "unfocused";
+const char* kEdjePath = "/usr/share/edje/xwalk/xwalk_tizen.edj";
+const char* kWinowRotationEventKey = "wm,rotation,changed";
+const char* kWinowFocusedEventKey = "focused";
+const char* kWinowUnfocusedEventKey = "unfocused";
+
+const int kPortraitNaturalAngle[] = {
+  0,  // PORTRAIT_PRIMARY
+  180,  // PORTRAIT_SECONDARY
+  270,  // LANDSCAPE_PRIMARY
+  90,  // LANDSCAPE_SECONDARY
+  0,  // NATURAL
+  -1  // ANY
+};
+const int kLandscapeNaturalAngle[] = {
+  270,  // PORTRAIT_PRIMARY
+  90,  // PORTRAIT_SECONDARY
+  0,  // LANDSCAPE_PRIMARY
+  180,  // LANDSCAPE_SECONDARY
+  0,  // NATURAL
+  -1,  // ANY
+};
+
+NativeWindow::ScreenOrientation NativeAngleToOrientation(
+    int angle, NativeWindow::ScreenOrientation natural_orientation) {
+  auto& convert_table =
+      natural_orientation == NativeWindow::ScreenOrientation::PORTRAIT_PRIMARY ?
+          kPortraitNaturalAngle :
+          kLandscapeNaturalAngle;
+  unsigned index = ARRAYSIZE(convert_table) - 1;
+  for (unsigned i = 0; i < ARRAYSIZE(convert_table); ++i) {
+    if (convert_table[i] == angle) {
+      index = i;
+      break;
+    }
+  }
+  return static_cast<NativeWindow::ScreenOrientation>(index);
+}
+
 }  // namespace
 
 
@@ -204,6 +239,10 @@ void NativeWindow::RemoveRotationHandler(int id) {
   handler_table_.erase(id);
 }
 
+NativeWindow::ScreenOrientation NativeWindow::orientation() const {
+  return NativeAngleToOrientation(rotation_, natural_orientation_);
+}
+
 void NativeWindow::SetRotationLock(int degree) {
   if (degree != -1)
     rotation_ = degree % 360;
@@ -211,26 +250,10 @@ void NativeWindow::SetRotationLock(int degree) {
 }
 
 void NativeWindow::SetRotationLock(ScreenOrientation orientation) {
-  int portrait_natural_angle[] = {
-    0,  // PORTRAIT_PRIMARY
-    180,  // PORTRAIT_SECONDARY
-    270,  // LANDSCAPE_PRIMARY
-    90,  // LANDSCAPE_SECONDARY
-    0,  // NATURAL
-    -1  // ANY
-  };
-  int landscape_natural_angle[] = {
-    270,  // PORTRAIT_PRIMARY
-    90,  // PORTRAIT_SECONDARY
-    0,  // LANDSCAPE_PRIMARY
-    180,  // LANDSCAPE_SECONDARY
-    0,  // NATURAL
-    -1,  // ANY
-  };
   auto& convert_table =
       natural_orientation_ == ScreenOrientation::PORTRAIT_PRIMARY ?
-          portrait_natural_angle :
-          landscape_natural_angle;
+          kPortraitNaturalAngle :
+          kLandscapeNaturalAngle;
   SetRotationLock(convert_table[static_cast<int>(orientation)]);
 }
 
index 4be1753..e939a01 100755 (executable)
@@ -53,6 +53,7 @@ class NativeWindow {
   int AddRotationHandler(RotationHandler handler);
   void RemoveRotationHandler(int id);
   int rotation() const { return rotation_; }
+  ScreenOrientation orientation() const;
   void Show();
   void Active();
   void InActive();
index 935673c..9a4cd4f 100644 (file)
@@ -40,8 +40,10 @@ wgt::parse::ScreenOrientation ChooseOrientation(
   auto orientation_pair = splash_map.end();
 
   if (screen_orientation ==
-      runtime::NativeWindow::ScreenOrientation::PORTRAIT_PRIMARY) {
-     orientation_pair =
+      runtime::NativeWindow::ScreenOrientation::PORTRAIT_PRIMARY ||
+      screen_orientation ==
+      runtime::NativeWindow::ScreenOrientation::PORTRAIT_SECONDARY) {
+    orientation_pair =
          splash_map.find(wgt::parse::ScreenOrientation::PORTRAIT);
   } else {
     orientation_pair =
@@ -106,7 +108,7 @@ SplashScreen::SplashScreen(
   if (ss_info == nullptr) return;
   auto splash_map = ss_info->splash_screen_data();
   auto used_orientation =
-      ChooseOrientation(splash_map, window->natural_orientation());
+      ChooseOrientation(splash_map, window->orientation());
   if (used_orientation == wgt::parse::ScreenOrientation::NONE) return;
 
   auto dimensions = GetDimensions();
index ef09759..26f2f80 100644 (file)
@@ -266,6 +266,24 @@ bool WebApplication::Initialize() {
                                                    std::free};
   app_data_path_ = path.get();
   LOGGER(DEBUG) << "path is " << path.get();
+
+  if (app_data_->setting_info() != NULL &&
+      app_data_->setting_info()->screen_orientation() ==
+          wgt::parse::SettingInfo::ScreenOrientation::AUTO) {
+    ewk_context_tizen_extensible_api_string_set(ewk_context_,
+                                                kRotationLockFeature, true);
+    window_->SetAutoRotation();
+  } 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);
+  }
+
   splash_screen_.reset(new SplashScreen(
       window_, app_data_->splash_screen_info(), app_data_->application_path()));
   resource_manager_.reset(
@@ -327,22 +345,6 @@ bool WebApplication::Initialize() {
                                               kMediastreamRecordFeature, true);
   ewk_context_tizen_extensible_api_string_set(ewk_context_,
                                               kEncryptedDatabaseFeature, true);
-  if (app_data_->setting_info() != NULL &&
-      app_data_->setting_info()->screen_orientation() ==
-          wgt::parse::SettingInfo::ScreenOrientation::AUTO) {
-    ewk_context_tizen_extensible_api_string_set(ewk_context_,
-                                                kRotationLockFeature, true);
-    window_->SetAutoRotation();
-  } 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 &&
       app_data_->setting_info()->sound_mode() ==