[WRTjs][VD] Add GetScreenOrientation / ScreenOrientation API of widget 47/292447/5 accepted/tizen/7.0/unified/20230516.110427
authorzhaosy <shiyusy.zhao@samsung.com>
Mon, 8 May 2023 08:31:58 +0000 (16:31 +0800)
committerBot Blink <blinkbot@samsung.com>
Mon, 15 May 2023 01:15:35 +0000 (01:15 +0000)
TV window app need to GetScreenOrientation / ScreenOrientation API,
so add these apis.

Note:
1.In portrait mode, launch app, elm_win_rotation_get return 0,
  so use ecore_evas_rotation_get to get ScreenOrientation
2.If not resize window and view in SetScreenOrientation,
  app layout is strange

Change-Id: Id71d35dd50c67dee1f04750cc665e8082ac60d18
Signed-off-by: zhaosy <shiyusy.zhao@samsung.com>
wrt/src/browser/tv/wrt_native_window_tv.cc
wrt/src/browser/tv/wrt_native_window_tv.h [changed mode: 0755->0644]
wrt/xwalk_extensions/browser/tv/xwalk_extension_manager_tv.cc
wrt/xwalk_extensions/internal/widget/widget_api.js

index bbc36c3356146f5e3b8b9a9952fd20500e5d309a..dd70307cd5c219b66ac74b0d1699a63bb21ed9fb 100644 (file)
@@ -1613,4 +1613,34 @@ void WRTNativeWindowTV::SetZoomLevel(double level) {
       nullptr);
 }
 
+int WRTNativeWindowTV::GetScreenOrientation() {
+  auto* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(top_window_));
+  int degree = ecore_evas_rotation_get(ee);
+  LOG(INFO) << "GetScreenOrientation degree:" << degree;
+  return degree;
+}
+
+bool WRTNativeWindowTV::SetScreenOrientation(const std::string& degree) {
+  LOG(INFO) << "SetScreenOrientation degree: " << degree;
+  if (degree.empty())
+    return false;
+
+  int screen_degree = 0;
+  base::StringToInt(degree, &screen_degree);
+  if (screen_degree < 0 || screen_degree % 90 != 0)
+    return false;
+
+  int screen_width = 1920, screen_height = 1080;
+  GetScreenResolution(screen_width, screen_height);
+  elm_win_rotation_set(top_window_, screen_degree);
+  if (screen_degree == 90 || screen_degree == 270) {
+    evas_object_resize(top_window_, screen_height, screen_width);
+    evas_object_resize(view_evas(), screen_height, screen_width);
+  } else {
+    evas_object_resize(top_window_, screen_width, screen_height);
+    evas_object_resize(view_evas(), screen_width, screen_height);
+  }
+  return true;
+}
+
 }  // namespace wrt
old mode 100755 (executable)
new mode 100644 (file)
index e3a5291..a3ff4bf
@@ -77,6 +77,9 @@ class WRTNativeWindowTV : public WRTNativeWindow {
 
   void BeforeWindowQuit() override;
 
+  int GetScreenOrientation();
+  bool SetScreenOrientation(const std::string& degree);
+
  private:
   // NativeWindow:
   void Hide() override;
index 88788f35eaf5eeb0a5c84ddb4f0ceb969b9ce8fb..85d1bb03dca9ef5f8cc7e13de4e5d2a75a2307dc 100644 (file)
@@ -240,6 +240,15 @@ std::string XWalkExtensionManagerTV::HandleRuntimeMessageInternal(
     return "failed";
   } else if (type == "tizen://getGlobalResourceId") {
     return std::to_string(WRTNativeWindowTV::GetGlobalResourceId());
+  } else if (type == "tizen://getScreenOrientation") {
+    if (auto native_window_tv = wrt::WRTNativeWindowTV::GetMainNativeWindow())
+      return std::to_string(native_window_tv->GetScreenOrientation());
+    return "failed";
+  } else if (type == "tizen://setScreenOrientation") {
+    auto native_window_tv = wrt::WRTNativeWindowTV::GetMainNativeWindow();
+    return (native_window_tv && native_window_tv->SetScreenOrientation(value))
+               ? "success"
+               : "failed";
   } else {
     return XWalkExtensionManager::HandleRuntimeMessageInternal(type, value);
   }
index 259a0f29270964943f130aec4ccc37ec06c796af..0d0b662f1c73d973bd2e9f48f8ad2aebd4ea7d4a 100644 (file)
@@ -143,6 +143,14 @@ Widget.prototype.getGlobalResourceId = function() {
   return parseInt(sendRuntimeSyncMessage("tizen://getGlobalResourceId"), 10);
 };
 
+Widget.prototype.getScreenOrientation = function() {
+  return parseInt(sendRuntimeSyncMessage("tizen://getScreenOrientation"), 10);
+}
+
+Widget.prototype.setScreenOrientation = function(orientation) {
+  return sendRuntimeSyncMessage("tizen://setScreenOrientation", orientation);
+}
+
 var MDE = function() {};
 var localPortCallbackId = null;