[M108 Migration][WRTjs][VD] Apply decorator window feature 04/289404/4
authorzhaosy <shiyusy.zhao@samsung.com>
Tue, 7 Mar 2023 06:07:23 +0000 (14:07 +0800)
committerBot Blink <blinkbot@samsung.com>
Wed, 8 Mar 2023 09:30:00 +0000 (09:30 +0000)
1.change border background color
2.apply border auto hide/show
3.modify decorator window border style(Flip model window rounded corners required)

Reference patch:
https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/287771/
https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/287489/
https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/287740/

Change-Id: Ic4dbc3d9b216c06f409ea040e73a5423e1052f2a
Signed-off-by: zhaosy <shiyusy.zhao@samsung.com>
wrt/src/browser/tv/decorator_window.cc
wrt/src/browser/tv/decorator_window.h
wrt/src/browser/tv/native_web_runtime_delegate_tv.cc
wrt/src/browser/tv/wrt_native_window_tv.cc
wrt/src/browser/tv/wrt_native_window_tv.h

index 25c9780..052b6a4 100755 (executable)
@@ -16,7 +16,6 @@
 
 #include "wrt/src/browser/tv/decorator_window.h"
 
-#include <Elementary.h>
 #include <appsvc.h>
 #include <efl_assist_policy.h>
 
@@ -83,9 +82,9 @@ void OnMinimizeClickedCB(void* data, Evas_Object* obj, void* event_info) {
 }  // namespace
 
 // static
-DecoratorWindow& DecoratorWindow::GetInstance() {
-  static DecoratorWindow* decorator_window = new DecoratorWindow();
-  return *decorator_window;
+DecoratorWindow* DecoratorWindow::GetInstance() {
+  static DecoratorWindow decorator_window;
+  return &decorator_window;
 }
 
 void DecoratorWindow::SetDecoratorWindow(Evas_Object* top_window) {
@@ -103,6 +102,9 @@ void DecoratorWindow::SetDecoratorWindow(Evas_Object* top_window) {
                         (edje_dir.value() + "/" + kDecoratorEdjeFile).c_str());
   ea_policy_handle_desktop_mode(top_window_, EINA_TRUE);
 
+  elm_win_alpha_set(top_window_, EINA_TRUE);
+  SetWindowBorderColor();
+
   Evas_Object* layout_border = AddLayout(kBorderContent);
   AddRectangle(layout_border);
   Evas_Object* box = AddBox(layout_border, 1.0, 0.5);
@@ -121,11 +123,15 @@ void DecoratorWindow::SetDecoratorWindow(Evas_Object* top_window) {
     AddFunctionButton(box, "border-max", false, OnMaximizeClickedCB);
     AddCornerButton(kLeftCornerButton, kResizeBottomLeft);
     AddCornerButton(kRightCornerButton, kResizeBottomRight);
+    elm_win_maximized_set(top_window_, false);
   } else {
     AddFunctionButton(box, "border-restore-dimmed", true, nullptr);
+    elm_win_maximized_set(top_window_, true);
+    ShowWindowBorder();
   }
 
   AddFunctionButton(box, "border-close", false, OnCloseClickedCB);
+  ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,  MouseEventCB, nullptr);
 #else
   LOG(ERROR) << "This version does not support window decorator";
 #endif
@@ -180,7 +186,6 @@ Evas_Object* DecoratorWindow::AddLayout(const char* part) {
 Evas_Object* DecoratorWindow::AddRectangle(Evas_Object* parent) {
   Evas_Object* rect = evas_object_rectangle_add(evas_object_evas_get(parent));
   evas_object_size_hint_min_set(rect, 0, 50);
-  evas_object_color_set(rect, 100, 100, 100, 255);
   evas_object_show(rect);
   elm_object_part_content_set(parent, "border.height", rect);
   return rect;
@@ -200,12 +205,12 @@ void DecoratorWindow::AddTitleHeader(bundle* bundle) {
       GetBundleValueToString(bundle, kIconPath) + kHeaderIconName;
   Evas_Object* icon = elm_image_add(box);
   elm_image_file_set(icon, iconPath.c_str(), nullptr);
-  evas_object_size_hint_min_set(icon, 20, 20);
+  evas_object_size_hint_min_set(icon, 30, 30);
   elm_box_pack_end(box, icon);
   evas_object_show(icon);
 
   std::string app_title = GetBundleValueToString(bundle, kAppTitle);
-  std::string windowTitle = "<font_size=25>" + app_title + "</font_size>";
+  std::string windowTitle = "<font_size=30 color=#000000>" + app_title + "</font_size>";
   Evas_Object* label = elm_label_add(box);
   elm_object_text_set(label, windowTitle.c_str());
   elm_box_pack_end(box, label);
@@ -245,4 +250,69 @@ std::string DecoratorWindow::GetBundleValueToString(bundle* bundle,
   auto value = appsvc_get_data(bundle, key);
   return value ? std::string(value) : std::string();
 }
+
+void DecoratorWindow::SetWindowBorderColor() {
+#if TIZEN_VERSION_AT_LEAST(7, 0, 0)
+  Evas_Object* frameObj = elm_win_frame_edje_get(top_window_);
+  LOG(INFO) << "SetWindowBorderColor start " << frameObj;
+  Edje_Message_Int_Set* message =
+      (Edje_Message_Int_Set*)(alloca(sizeof(*message) + ((3) * sizeof(int))));
+  if (!message)
+    return;
+
+  message->count = 4;
+  message->val[0] = 225;  // R
+  message->val[1] = 224;  // G
+  message->val[2] = 224;  // B
+  message->val[3] = 255;  // A
+
+  edje_object_message_send(frameObj, EDJE_MESSAGE_INT_SET, 1, message);
+  edje_object_message_send(frameObj, EDJE_MESSAGE_INT_SET, 2, message);
+  edje_object_message_send(frameObj, EDJE_MESSAGE_INT_SET, 3, message);
+  edje_object_message_send(frameObj, EDJE_MESSAGE_INT_SET, 4, message);
+  LOG(INFO) << "SetWindowBorderColor end";
+#else
+  LOG(ERROR) << "This version does not support window decorator";
+#endif
+  return;
+}
+
+// static
+Eina_Bool DecoratorWindow::MouseEventCB(void* data, int event_type, void* event_info) {
+  LOG(INFO) << "MouseEventCallback type = " << event_type;
+  if (event_type != ECORE_EVENT_MOUSE_BUTTON_DOWN)
+    return ECORE_CALLBACK_PASS_ON;
+
+  auto self = GetInstance();
+  self->ShowWindowBorder();
+  LOG(INFO) << "MouseEventCallback end";
+  return ECORE_CALLBACK_PASS_ON;
+}
+
+void DecoratorWindow::ShowWindowBorder()
+{
+  LOG(INFO) << "ShowWindowBorder called";
+  if (elm_win_borderless_get(top_window_))
+    elm_win_borderless_set(top_window_, EINA_FALSE);
+
+  if (hide_timer_) {
+    LOG(INFO) << "timer_del " << hide_timer_;
+    ecore_timer_del(hide_timer_);
+  }
+  hide_timer_ = ecore_timer_add(10, HideBorderCallback, nullptr);
+    LOG(INFO) << "ShowWindowBorder end " << hide_timer_;
+}
+
+// static
+Eina_Bool DecoratorWindow::HideBorderCallback(void* data) {
+  auto self = GetInstance();
+  LOG(INFO) << "HideBorderCallback called " << self->hide_timer_;
+  if (elm_win_maximized_get(self->top_window_)) {
+    LOG(INFO) << "Hide Window Border!!";
+    elm_win_borderless_set(self->top_window_, EINA_TRUE);
+  }
+  self->hide_timer_ = nullptr;
+  LOG(INFO) << "HideBorderCallback end";
+  return ECORE_CALLBACK_DONE;
+}
 }  // namespace wrt
index a4079e6..120374b 100755 (executable)
@@ -19,6 +19,7 @@
 
 #include <string>
 
+#include <Elementary.h>
 #include <Evas.h>
 #include <bundle.h>
 
@@ -26,7 +27,7 @@ namespace wrt {
 
 class DecoratorWindow {
  public:
-  static DecoratorWindow& GetInstance();
+  static DecoratorWindow* GetInstance();
   void AddTitleHeader(bundle* bundle);
   void SetDecoratorWindow(Evas_Object* top_window);
   void SetWindowPosition(bundle* bundle);
@@ -47,10 +48,15 @@ class DecoratorWindow {
   Evas_Object* AddRectangle(Evas_Object* parent);
   int GetBundleValueToInt(bundle* bundle, const char* key);
   std::string GetBundleValueToString(bundle* bundle, const char* key);
+  void SetWindowBorderColor();
+  static Eina_Bool MouseEventCB(void*, int, void*);
+  static Eina_Bool HideBorderCallback(void* data);
+  void ShowWindowBorder();
 
   Evas_Object* top_window_ = nullptr;
   bool initialized_header_ = false;
   bool window_resize_supported_ = false;
+  Ecore_Timer* hide_timer_ = nullptr;
 };
 
 }  // namespace wrt
index 36dae7a..e8b3808 100644 (file)
@@ -270,6 +270,8 @@ NativeWebRuntimeDelegateTV::NativeWebRuntimeDelegateTV() {
 }
 
 void NativeWebRuntimeDelegateTV::Initialize(void* data) {
+  if (GetProductType() == "IWB")
+    WRTNativeWindowTV::SetWindowBorderAlpha();
   ApplicationData::GetInstance().Initialize();
   app_id_ = ApplicationData::GetInstance().app_id();
   auto extension_manager = XWalkExtensionManager::GetInstance();
@@ -406,8 +408,8 @@ void NativeWebRuntimeDelegateTV::AfterAppControlEvent(
   }
 
   if (GetProductType() == "IWB") {
-    DecoratorWindow::GetInstance().AddTitleHeader(bundle);
-    DecoratorWindow::GetInstance().SetWindowPosition(bundle);
+    DecoratorWindow::GetInstance()->AddTitleHeader(bundle);
+    DecoratorWindow::GetInstance()->SetWindowPosition(bundle);
   }
 }
 
index 2ea84b1..5ec48be 100644 (file)
@@ -304,6 +304,13 @@ void WRTNativeWindowTV::MoveWindowForeground() {
     ecore_evas_layer_set(ee, foreground_layer);
 }
 
+// static
+void WRTNativeWindowTV::SetWindowBorderAlpha() {
+#if TIZEN_VERSION_AT_LEAST(7, 0, 0)
+  elm_config_window_border_alpha_set(EINA_TRUE);
+#endif
+}
+
 unsigned int WRTNativeWindowTV::GetGlobalResourceId() {
   return global_resource_id;
 }
@@ -354,7 +361,7 @@ void WRTNativeWindowTV::SetWebContents(content::WebContents* web_contents) {
   EWebAccessibilityUtil::GetInstance();
 #endif
   if (GetProductType() == "IWB")
-    DecoratorWindow::GetInstance().SetDecoratorWindow(top_window_);
+    DecoratorWindow::GetInstance()->SetDecoratorWindow(top_window_);
   TvWindowManager::GetInstance()->Initialize(top_window_);
   SetDisplayRotatorCallback();
   CreateMouseCursor(ewk_view);
index 0687715..c296818 100644 (file)
@@ -45,6 +45,7 @@ class WRTNativeWindowTV : public WRTNativeWindow {
   static void SetMenuZoomFill(const std::string& enable);
   static void SetGlobalResourceId(Evas_Object* top_window);
   static bool SetRotation();
+  static void SetWindowBorderAlpha();
 
   explicit WRTNativeWindowTV(const gin_helper::Dictionary& options,
                              electron::NativeWindow* parent);