[WRTjs] Refactor popup
[platform/framework/web/chromium-efl.git] / wrt / src / browser / wrt_window_tree_host.cc
1 #include "wrt/src/browser/wrt_window_tree_host.h"
2
3 #include <tizen-extension-client-protocol.h>
4
5 #include "tizen_src/chromium_impl/ui/ozone/platform/efl/efl_window.h"
6 #include "ui/display/screen.h"
7
8 namespace wrt {
9
10 namespace {
11
12 const struct tizen_policy_listener policy_listener = {
13   [](void*, struct tizen_policy*, struct wl_surface*, uint32_t is_conformant) {
14     LOG(INFO) << "Conformant - " << is_conformant;
15   },
16   [](void*, struct tizen_policy*, struct wl_surface*, uint32_t conformant_part,
17      uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h) {
18     gfx::Rect rect(x, y, w, h);
19     LOG(INFO) << "Conformant Area - part:" << conformant_part << " state:"
20               << state << ") rect:" << rect.ToString();
21   },
22   [](void*, struct tizen_policy*, struct wl_surface*, int32_t, uint32_t) {},
23   [](void*, struct tizen_policy*, uint32_t) {},
24   [](void*, struct tizen_policy*, struct wl_surface*, uint32_t, uint32_t) {},
25   [](void*, struct tizen_policy*, struct wl_surface*, uint32_t, uint32_t) {},
26   [](void*, struct tizen_policy*, struct wl_surface*, struct wl_array*,
27      uint32_t) {},
28   [](void*, struct tizen_policy*, struct wl_surface*, int) {},
29   [](void*, struct tizen_policy*, struct wl_surface*, const char*, const char*,
30      struct wl_array*) {},
31   [](void*, struct tizen_policy*, struct wl_surface*, uint32_t, uint32_t,
32      int32_t, int32_t, int32_t, int32_t, uint32_t) {}
33 };
34
35 }  // namespace
36
37 WRTWindowTreeHost::WRTWindowTreeHost(
38     ui::PlatformWindowInitProperties properties,
39     std::unique_ptr<aura::Window> window)
40     : aura::WindowTreeHostPlatform(std::move(properties), std::move(window)) {
41 #if defined(USE_WAYLAND)
42   auto display = ecore_wl2_connected_display_get(nullptr);
43   auto* globals = ecore_wl2_display_globals_get(display);
44   if (globals) {
45     auto* registry = ecore_wl2_display_registry_get(display);
46     Ecore_Wl2_Global* global;
47     EINA_ITERATOR_FOREACH(globals, global) {
48       if (strcmp(global->interface, tizen_policy_interface.name) == 0) {
49         tizen_policy_ = static_cast<tizen_policy*>(wl_registry_bind(
50             registry, global->id, &tizen_policy_interface, global->version));
51       }
52     }
53   }
54   if (tizen_policy_)
55     tizen_policy_add_listener(tizen_policy_, &policy_listener, this);
56   else
57     LOG(ERROR) << "wl_registry_bind(tizen_policy_interface) is failed.";
58 #endif
59
60   InitHost();
61
62   auto* root_window = this->window();
63   root_window->Show();
64
65   aura::client::SetWindowParentingClient(root_window, this);
66
67   OnActivationChanged(true);
68 }
69
70 WRTWindowTreeHost::~WRTWindowTreeHost() {
71   auto* root_window = window();
72   aura::client::SetWindowParentingClient(root_window, nullptr);
73
74 #if defined(USE_WAYLAND)
75   if (tizen_policy_)
76     tizen_policy_destroy(tizen_policy_);
77 #endif
78 }
79
80 // static
81 WRTWindowTreeHost* WRTWindowTreeHost::Create(ui::PlatformWindowType type) {
82   ui::PlatformWindowInitProperties properties;
83   properties.bounds =
84       display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
85   properties.type = type;
86   auto window = std::make_unique<aura::Window>(
87                     nullptr, aura::client::WINDOW_TYPE_UNKNOWN);
88   return new WRTWindowTreeHost(std::move(properties), std::move(window));
89 }
90
91 void WRTWindowTreeHost::Hide() {
92   platform_window()->Hide();
93 }
94
95 Evas_Object* WRTWindowTreeHost::GetEvasObject() const {
96   auto* efl_window = static_cast<const ui::EflWindow*>(platform_window());
97   return efl_window->native_view();
98 }
99
100 void WRTWindowTreeHost::OnClosed() {
101   SetPlatformWindow(nullptr);
102 }
103
104 void WRTWindowTreeHost::OnActivationChanged(bool active) {
105   if (is_active_ == active)
106     return;
107   is_active_ = active;
108   aura::WindowTreeHostPlatform::OnActivationChanged(active);
109 }
110
111 gfx::Rect WRTWindowTreeHost::GetTransformedRootWindowBoundsFromPixelSize(
112     const gfx::Size& size_in_pixels) const {
113   return gfx::Rect(size_in_pixels);
114 }
115
116 void WRTWindowTreeHost::DispatchEvent(ui::Event* event) {
117   aura::WindowTreeHostPlatform::DispatchEvent(event);
118 }
119
120 aura::Window* WRTWindowTreeHost::GetDefaultParent(
121     aura::Window* window, const gfx::Rect& bounds, const int64_t display_id) {
122   return this->window();
123 }
124
125 }  // namespace wrt