[M120 Migration] Show the context menu and settings menu 74/306274/7
authorAkshay Kanagali <a.kanagali@partner.samsung.com>
Mon, 19 Feb 2024 09:05:20 +0000 (14:35 +0530)
committerBot Blink <blinkbot@samsung.com>
Mon, 26 Feb 2024 09:23:01 +0000 (09:23 +0000)
This patch includes below to show the context menu and settings menu.

- Set the type of each window
- Focus on evas objects
- Implement event capture
- Separation of header and source file of ElfWindowManager
- Implement |EflWindow::IsVisible|
- Convert event location for submenu

References :
https://review.tizen.org/gerrit/c/platform/framework/web/chromium-efl/+/302447
https://review.tizen.org/gerrit/c/platform/framework/web/chromium-efl/+/302577
https://review.tizen.org/gerrit/c/platform/framework/web/chromium-efl/+/302685
https://review.tizen.org/gerrit/c/platform/framework/web/chromium-efl/+/302811
https://review.tizen.org/gerrit/c/platform/framework/web/chromium-efl/+/302528

Change-Id: I32bf5fadb2fcd78a9cce6f7d8ad74d0c6e4fb542
Signed-off-by: Akshay Kanagali <a.kanagali@partner.samsung.com>
tizen_src/chromium_impl/ui/ozone/platform/efl/BUILD.gn
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_event_handler.cc
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_event_handler.h
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_window.cc
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_window.h
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_window_manager.cc [new file with mode: 0644]
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_window_manager.h

index 6bfe089..84d19a4 100644 (file)
@@ -22,6 +22,7 @@ source_set("efl") {
     "efl_surface_factory.h",
     "efl_window.cc",
     "efl_window.h",
+    "efl_window_manager.cc",
     "efl_window_manager.h",
     "im_context_efl.cc",
     "im_context_efl.h",
index 6a33c98..6687966 100644 (file)
@@ -790,6 +790,13 @@ bool EflEventHandler::FilterIMEKeyUpEvent(Evas_Event_Key_Up* key_up) {
   return false;
 }
 
+void EflEventHandler::ConvertOriginToTarget(const EflWindow* new_target,
+                                            LocatedEvent* event) const {
+  gfx::Vector2d diff = window_->GetBoundsInDIP().origin() -
+                       new_target->GetBoundsInDIP().origin();
+  event->set_location_f(event->location_f() + diff);
+}
+
 // New requirement from tizen 6.5:
 // press "up" key on the top of IME panel should handled as same behavior as
 // press "Return Back" key on IME panel behavior:
index 27d9e81..7bda5e8 100644 (file)
@@ -21,6 +21,7 @@ class EflWindow;
 class EflPlatformEventSource;
 class IMContextEfl;
 class KeyEvent;
+class LocatedEvent;
 class TouchEvent;
 
 // Keyboard
@@ -60,6 +61,9 @@ class EflEventHandler {
   }
   IMContextEfl* GetIMContextEfl() { return im_context_efl_; }
 
+  void ConvertOriginToTarget(const EflWindow* new_target,
+                             LocatedEvent* event) const;
+
 #if BUILDFLAG(IS_TIZEN_TV)
    void SetKeyEventChecker(
        const base::RepeatingCallback<bool(void*, bool)>& checker);
index 2cc3995..d72b443 100644 (file)
@@ -31,10 +31,37 @@ namespace ui {
 
 namespace {
 
-Ecore_Evas* prepared_ee = nullptr;
+#if defined(USE_WAYLAND)
+Ecore_Wl2_Window_Type GetEcoreWl2WindowType(PlatformWindowType type) {
+  Ecore_Wl2_Window_Type window_type = ECORE_WL2_WINDOW_TYPE_NONE;
+
+  switch (type) {
+    case PlatformWindowType::kWindow:
+      window_type = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
+      break;
+    case PlatformWindowType::kPopup:
+    case PlatformWindowType::kMenu:
+    case PlatformWindowType::kTooltip:
+    case PlatformWindowType::kBubble:
+      window_type = ECORE_WL2_WINDOW_TYPE_UTILITY;
+      break;
+    case PlatformWindowType::kDrag:
+      window_type = ECORE_WL2_WINDOW_TYPE_DND;
+      break;
+    default:
+      window_type = ECORE_WL2_WINDOW_TYPE_NONE;
+  }
+
+  return window_type;
+}
+#endif
+
+bool g_evas_init = false;
 
 }  // namespace
 
+Ecore_Evas* prepared_ee = nullptr;
+
 #if BUILDFLAG(IS_TIZEN_TV)
 bool EflWindow::is_cursor_initialized_ = false;
 #endif
@@ -93,22 +120,11 @@ void EflWindow::Show(bool inactive) {
           switches::kEnableOffscreenRendering))
     return;
 
-#if defined(ENABLE_WRT_JS)
-  // For now, only show kWindow and kSplashScreen, ignore other types : kMenu,
-  // kTootltip etc.
-  if (type_ != PlatformWindowType::kWindow &&
-      type_ != PlatformWindowType::kSplashScreen) {
-    return;
-  }
-#else
-  // For now, only show kWindow and ignore other types : kMenu, kTootltip etc.
-  if (type_ != PlatformWindowType::kWindow)
-    return;
-#endif
-
   if (events_overlay_)
     evas_object_show(events_overlay_);
-
+#if defined(USE_WAYLAND)
+  ecore_wl2_window_show(wl_window_);
+#endif
   ecore_evas_show(ee_);
 
   // Request to redraw window surface when showing. If not, a black screen will
@@ -121,12 +137,11 @@ void EflWindow::Hide() {
           switches::kEnableOffscreenRendering))
     return;
 
-  if (type_ != PlatformWindowType::kWindow)
-    return;
-
   if (events_overlay_)
     evas_object_hide(events_overlay_);
-
+#if defined(USE_WAYLAND)
+  ecore_wl2_window_hide(wl_window_);
+#endif
   ecore_evas_hide(ee_);
 }
 
@@ -135,8 +150,7 @@ void EflWindow::Close() {
 }
 
 bool EflWindow::IsVisible() const {
-  NOTIMPLEMENTED();
-  return false;
+  return ecore_evas_visibility_get(ee_);
 }
 
 void EflWindow::PrepareForShutdown() {
@@ -153,7 +167,14 @@ void EflWindow::SetBoundsInPixels(const gfx::Rect& bounds) {
     return;
   }
 
+  int rotation = ecore_evas_rotation_get(ee_);
+  LOG(INFO) << " bounds " << bounds.ToString() << " rotation " << rotation;
+
 #if defined(USE_WAYLAND)
+  ecore_wl2_window_rotation_geometry_set(wl_window_, rotation, bounds.x(),
+                                         bounds.y(), bounds.width(),
+                                         bounds.height());
+
   if (wl2_egl_window_) {
     ecore_wl2_egl_window_resize_with_rotation(wl2_egl_window_, bounds.x(),
                                               bounds.y(), bounds.width(),
@@ -182,16 +203,19 @@ void EflWindow::SetTitle(const std::u16string& title) {
 }
 
 void EflWindow::SetCapture() {
-  NOTIMPLEMENTED();
+  if (!HasCapture()) {
+    window_manager_->GrabLocatedEvents(this);
+  }
 }
 
 void EflWindow::ReleaseCapture() {
-  NOTIMPLEMENTED();
+  if (HasCapture()) {
+    window_manager_->UngrabLocatedEvents(this);
+  }
 }
 
 bool EflWindow::HasCapture() const {
-  NOTIMPLEMENTED();
-  return false;
+  return window_manager_->located_events_grabber() == this;
 }
 
 void EflWindow::SetFullscreen(bool fullscreen, int64_t target_display_id) {
@@ -211,7 +235,6 @@ void EflWindow::Restore() {
 }
 
 PlatformWindowState EflWindow::GetPlatformWindowState() const {
-  NOTIMPLEMENTED();
   return PlatformWindowState::kNormal;
 }
 
@@ -270,6 +293,11 @@ void EflWindow::UpdateFocus(bool focused) {
     return;
 
   has_focus_ = focused;
+
+  if (events_overlay_) {
+    evas_object_focus_set(events_overlay_, focused);
+  }
+
   if (!focused)
     return;
 
@@ -278,7 +306,28 @@ void EflWindow::UpdateFocus(bool focused) {
   window_manager_->UpdateWindowFocus(this, focused);
 }
 
-uint32_t EflWindow::DispatchEvent(const PlatformEvent& event) {
+uint32_t EflWindow::DispatchEvent(const PlatformEvent& native_event) {
+  Event* event = static_cast<Event*>(native_event);
+
+  if (event->IsLocatedEvent()) {
+    auto* event_grabber = window_manager_->located_events_grabber();
+    if (event_grabber) {
+      // The origin of the submenu event needs to be changed to the root menu.
+      efl_event_handler_->ConvertOriginToTarget(event_grabber,
+                                                event->AsLocatedEvent());
+      event_grabber->DispatchEventToDelegate(event);
+      return POST_DISPATCH_STOP_PROPAGATION;
+    }
+  }
+
+  return DispatchEventToDelegate(event);
+}
+
+void EflWindow::OnWindowLostCapture() {
+  delegate_->OnLostCapture();
+}
+
+uint32_t EflWindow::DispatchEventToDelegate(const PlatformEvent& event) {
   bool handled = DispatchEventFromNativeUiEvent(
       event, base::BindOnce(&PlatformWindowDelegate::DispatchEvent,
                             base::Unretained(delegate_)));
@@ -296,8 +345,11 @@ void EflWindow::Initialize(const PlatformWindowInitProperties& properties) {
     return;
   }
 
-  ecore_evas_init();
-  evas_init();
+  if (!g_evas_init) {
+    ecore_evas_init();
+    evas_init();
+    g_evas_init = true;
+  }
 
   if (prepared_ee) {
     LOG(INFO) << "Use prepared ee instance";
@@ -319,14 +371,13 @@ void EflWindow::Initialize(const PlatformWindowInitProperties& properties) {
   ecore_evas_manual_render_set(ee_, EINA_TRUE);
 
 #if defined(USE_WAYLAND)
-  Ecore_Wl2_Window* ww = ecore_evas_wayland2_window_get(ee_);
-  if (!ww) {
+  wl_window_ = ecore_evas_wayland2_window_get(ee_);
+  if (!wl_window_) {
     LOG(ERROR) << "Failed to get Wl2 window";
     return;
   }
-
-  wl2_egl_window_ =
-      ecore_wl2_egl_window_create(ww, bounds_.width(), bounds_.height());
+  wl2_egl_window_ = ecore_wl2_egl_window_create(wl_window_, bounds_.width(),
+                                                bounds_.height());
   if (!wl2_egl_window_) {
     LOG(ERROR) << "Failed to create wl2 egl window";
     return;
@@ -335,7 +386,7 @@ void EflWindow::Initialize(const PlatformWindowInitProperties& properties) {
 #if defined(TIZEN_VIDEO_HOLE)
   // Hand a window handle to enable video hole in OnscreenRendering mode.
   media::VideoPlaneController::SetSharedVideoWindowHandle(
-      ww, media::VideoPlaneController::RenderingMode::ONSCREEN);
+      wl_window_, media::VideoPlaneController::RenderingMode::ONSCREEN);
 #endif
 
   void* egl_window = ecore_wl2_egl_window_native_get(wl2_egl_window_);
@@ -346,13 +397,15 @@ void EflWindow::Initialize(const PlatformWindowInitProperties& properties) {
 
   delegate_->OnAcceleratedWidgetAvailable(
       reinterpret_cast<uintptr_t>(egl_window));
+
+  if (type_ != PlatformWindowType::kWindow) {
+    ecore_wl2_window_type_set(wl_window_, GetEcoreWl2WindowType(type_));
+    ecore_wl2_window_position_set(wl_window_, bounds_.x(), bounds_.y());
+  }
 #else
   delegate_->OnAcceleratedWidgetAvailable(ecore_evas_window_get(ee_));
 #endif
 
-  if (type_ != PlatformWindowType::kWindow)
-    return;
-
   // Initialize efl event handler for main window
   events_overlay_ = evas_object_rectangle_add(ecore_evas_get(ee_));
   evas_object_color_set(events_overlay_, 0, 0, 0, 255);
@@ -360,11 +413,15 @@ void EflWindow::Initialize(const PlatformWindowInitProperties& properties) {
 
   InitializeEventHandler();
 
+  window_manager_->AddWindow(this, events_overlay_);
+
 #if BUILDFLAG(IS_TIZEN_TV)
   CreateMouseCursor();
 #endif
 
-  EflScreen::UpdateDisplayInfo(ee_);
+  if (type_ == PlatformWindowType::kWindow) {
+    EflScreen::UpdateDisplayInfo(ee_);
+  }
 }
 
 #if BUILDFLAG(IS_TIZEN_TV)
@@ -405,9 +462,6 @@ void EflWindow::InitializeEventHandler() {
   // Set activation true on window to capture key events.
   delegate_->OnActivationChanged(true /*active*/);
 
-  // Set focus active for a newly opened window.
-  UpdateFocus(true);
-
   efl_event_handler_ = std::make_unique<EflEventHandler>(this);
   PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
 }
@@ -452,6 +506,8 @@ void EflWindow::SetEventsOverlayForOffscreen(Evas_Object* events_overlay) {
 
   InitializeEventHandler();
 
+  window_manager_->AddWindow(this, events_overlay_);
+
 #if BUILDFLAG(IS_TIZEN)
   // Create IMContextEfl only after event handler is instantiated, because
   // content layer gets IMContextEfl through EflEventHandler.
index 4fb6d34..d1c0d06 100644 (file)
@@ -79,6 +79,8 @@ class EflWindow : public PlatformWindow, public PlatformEventDispatcher {
   void UpdateFocus(bool focused);
   void SetFocus(bool focused) { has_focus_ = focused; }
 
+  void OnWindowLostCapture();
+
   Evas* evas() const { return evas_; }
   Evas_Object* native_view() const { return events_overlay_; }
 
@@ -95,6 +97,7 @@ class EflWindow : public PlatformWindow, public PlatformEventDispatcher {
   void InitializeEventHandler();
   void ResetEventHandler();
   void EnsureIMContextEfl();
+  uint32_t DispatchEventToDelegate(const PlatformEvent& event);
 #if BUILDFLAG(IS_TIZEN_TV)
   void CreateMouseCursor();
   static bool is_cursor_initialized_;
@@ -124,6 +127,7 @@ class EflWindow : public PlatformWindow, public PlatformEventDispatcher {
   Evas_Object* events_overlay_ = nullptr;
 
 #if defined(USE_WAYLAND)
+  Ecore_Wl2_Window* wl_window_ = nullptr;
   Ecore_Wl2_Egl_Window* wl2_egl_window_ = nullptr;
 #endif
 
diff --git a/tizen_src/chromium_impl/ui/ozone/platform/efl/efl_window_manager.cc b/tizen_src/chromium_impl/ui/ozone/platform/efl/efl_window_manager.cc
new file mode 100644 (file)
index 0000000..76012a1
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (c) 2021 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/ozone/platform/efl/efl_window_manager.h"
+
+#include "ui/ozone/platform/efl/efl_window.h"
+
+namespace ui {
+
+EflWindowManager::EflWindowManager() = default;
+EflWindowManager::~EflWindowManager() = default;
+
+void EflWindowManager::AddWindow(EflWindow* window, Evas_Object* eo) {
+  window_map_[eo] = window;
+}
+
+EflWindow* EflWindowManager::GetWindow(Evas_Object* eo) const {
+  auto it = window_map_.find(eo);
+  return it == window_map_.end() ? nullptr : it->second;
+}
+
+void EflWindowManager::RemoveWindow(Evas_Object* eo) {
+  auto* window = window_map_[eo];
+  DCHECK(window);
+  window_map_.erase(eo);
+}
+
+void EflWindowManager::UpdateWindowFocus(EflWindow* window, bool focused) {
+  for (const auto& item : window_map_) {
+    if (item.second != window) {
+      item.second->SetFocus(false);
+    }
+  }
+}
+
+std::vector<EflWindow*> EflWindowManager::GetAllOpenWindows() const {
+  std::vector<EflWindow*> all_windows;
+  for (const auto& item : window_map_) {
+    all_windows.push_back(item.second);
+  }
+  return all_windows;
+}
+
+void EflWindowManager::GrabLocatedEvents(EflWindow* window) {
+  DCHECK_NE(located_events_grabber_, window);
+  auto* old_grabber = located_events_grabber_;
+  located_events_grabber_ = window;
+  if (old_grabber) {
+    old_grabber->OnWindowLostCapture();
+  }
+}
+
+void EflWindowManager::UngrabLocatedEvents(EflWindow* window) {
+  DCHECK_EQ(located_events_grabber_, window);
+  auto* old_grabber = located_events_grabber_;
+  located_events_grabber_ = nullptr;
+  old_grabber->OnWindowLostCapture();
+}
+
+}  // namespace ui
index 7de95a1..39dff10 100644 (file)
@@ -2,55 +2,46 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef UI_OZONE_PLATFORM_EFL_EFL_WINDOW_MANAGER_
-#define UI_OZONE_PLATFORM_EFL_EFL_WINDOW_MANAGER_
+#ifndef UI_OZONE_PLATFORM_EFL_EFL_WINDOW_MANAGER_H_
+#define UI_OZONE_PLATFORM_EFL_EFL_WINDOW_MANAGER_H_
+
+#include <Ecore_Evas.h>
 
 #include "base/containers/flat_map.h"
-#include "ui/ozone/platform/efl/efl_window.h"
 
 namespace ui {
 
+class EflWindow;
+
 class EflWindowManager {
  public:
-  EflWindowManager() {}
-  ~EflWindowManager() {}
+  EflWindowManager();
+  ~EflWindowManager();
 
   EflWindowManager(const EflWindowManager&) = delete;
   EflWindowManager& operator=(const EflWindowManager&) = delete;
 
-  void AddWindow(EflWindow* window, Evas_Object* eo) {
-    window_map_[eo] = window;
-  }
-
-  EflWindow* GetWindow(Evas_Object* eo) const {
-    auto it = window_map_.find(eo);
-    return it == window_map_.end() ? nullptr : it->second;
-  }
-
-  void RemoveWindow(Evas_Object* eo) {
-    auto* window = window_map_[eo];
-    DCHECK(window);
-    window_map_.erase(eo);
-  }
-
-  void UpdateWindowFocus(EflWindow* window, bool focused) {
-    for (const auto& item : window_map_) {
-      if (item.second != window)
-        item.second->SetFocus(false);
-    }
-  }
-
-  std::vector<EflWindow*> GetAllOpenWindows() const {
-    std::vector<EflWindow*> all_windows;
-    for (const auto& item : window_map_)
-      all_windows.push_back(item.second);
-    return all_windows;
-  }
+  void AddWindow(EflWindow* window, Evas_Object* eo);
+
+  EflWindow* GetWindow(Evas_Object* eo) const;
+
+  void RemoveWindow(Evas_Object* eo);
+
+  void UpdateWindowFocus(EflWindow* window, bool focused);
+
+  std::vector<EflWindow*> GetAllOpenWindows() const;
+
+  void GrabLocatedEvents(EflWindow* window);
+
+  void UngrabLocatedEvents(EflWindow* window);
+
+  EflWindow* located_events_grabber() const { return located_events_grabber_; }
 
  private:
   base::flat_map<Evas_Object*, EflWindow*> window_map_;
+  EflWindow* located_events_grabber_ = nullptr;
 };
 
 }  // namespace ui
 
-#endif  // UI_OZONE_PLATFORM_EFL_EFL_WINDOW_MANAGER_
+#endif  // UI_OZONE_PLATFORM_EFL_EFL_WINDOW_MANAGER_H_