Screen orientation should not be based on natural orientation.
Change-Id: Iba0b7c6954c94205d5695b125c7a311a69e07a0f
--- /dev/null
+/*
+ * 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_
+
#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 {
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)
#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
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;
}
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)]);
}
int AddRotationHandler(RotationHandler handler);
void RemoveRotationHandler(int id);
int rotation() const { return rotation_; }
+ ScreenOrientation orientation() const;
void Show();
void Active();
void InActive();
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 =
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();
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(
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() ==