1 // Copyright 2021 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_OZONE_PLATFORM_EFL_EFL_WINDOW_H_
6 #define UI_OZONE_PLATFORM_EFL_EFL_WINDOW_H_
8 #include "ui/events/platform/platform_event_dispatcher.h"
9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/platform_window/platform_window.h"
11 #include "ui/platform_window/platform_window_delegate.h"
12 #include "ui/platform_window/platform_window_init_properties.h"
14 #include <Ecore_Evas.h>
16 #if defined(USE_WAYLAND)
17 #include <Ecore_Wl2.h>
22 class EflEventHandler;
23 class EflInputMethodContext;
24 class EflWindowManager;
26 class EflWindow : public PlatformWindow, public PlatformEventDispatcher {
28 static Ecore_Evas* CreateEvasObject(const gfx::Rect& bounds);
29 static void SetPreparedEvasObject(Ecore_Evas* ee);
31 EflWindow(PlatformWindowDelegate* delegate,
32 PlatformWindowInitProperties properties,
33 EflWindowManager* manager);
35 EflWindow(const EflWindow&) = delete;
36 EflWindow& operator=(const EflWindow&) = delete;
38 ~EflWindow() override;
40 // PlatformWindow implementation.
41 void Show(bool inactive = false) override;
43 void Close() override;
44 bool IsVisible() const override;
45 void PrepareForShutdown() override;
46 void SetBoundsInPixels(const gfx::Rect& bounds) override;
47 gfx::Rect GetBoundsInPixels() const override;
48 void SetBoundsInDIP(const gfx::Rect& bounds) override;
49 gfx::Rect GetBoundsInDIP() const override;
50 void SetTitle(const std::u16string& title) override;
51 void SetCapture() override;
52 void ReleaseCapture() override;
53 bool HasCapture() const override;
54 void SetFullscreen(bool fullscreen, int64_t target_display_id) override;
55 void Maximize() override;
56 void Minimize() override;
57 void Restore() override;
58 PlatformWindowState GetPlatformWindowState() const override;
59 void Activate() override;
60 void Deactivate() override;
61 void SetUseNativeFrame(bool use_native_frame) override;
62 bool ShouldUseNativeFrame() const override;
63 void SetCursor(scoped_refptr<PlatformCursor> cursor) override;
64 void MoveCursorTo(const gfx::Point& location) override;
65 void ConfineCursorToBounds(const gfx::Rect& bounds) override;
66 void SetRestoredBoundsInDIP(const gfx::Rect& bounds) override;
67 gfx::Rect GetRestoredBoundsInDIP() const override;
68 void SetWindowIcons(const gfx::ImageSkia& window_icon,
69 const gfx::ImageSkia& app_icon) override;
70 void SizeConstraintsChanged() override;
72 // PlatformEventDispatcher implementation.
73 bool CanDispatchEvent(const PlatformEvent& event) override;
74 uint32_t DispatchEvent(const PlatformEvent& event) override;
76 // Called only in case of offscreen rendering
77 void SetEventsOverlayForOffscreen(Evas_Object* events_overlay) override;
79 void UpdateFocus(bool focused) override;
80 void SetFocus(bool focused) { has_focus_ = focused; }
82 void OnWindowLostCapture();
84 Evas* evas() const { return evas_; }
85 Evas_Object* native_view() const { return events_overlay_; }
87 void SetEflInputMethodContext(EflInputMethodContext* context) {
88 efl_input_method_context_ = context;
91 EflEventHandler* GetEventHandler() override {
92 return efl_event_handler_.get();
96 void Initialize(const PlatformWindowInitProperties& properties);
97 void InitializeEventHandler();
98 void ResetEventHandler();
99 void EnsureIMContextEfl();
100 uint32_t DispatchEventToDelegate(const PlatformEvent& event);
101 #if BUILDFLAG(IS_TIZEN_TV)
102 void CreateMouseCursor();
103 static bool is_cursor_initialized_;
107 // Stores current state of this window.
108 PlatformWindowState state_ = PlatformWindowState::kUnknown;
110 PlatformWindowDelegate* delegate_;
112 EflWindowManager* window_manager_ = nullptr;
114 // Current bounds of the platform window.
116 // The bounds of the platform window before it went maximized or fullscreen.
117 gfx::Rect restored_bounds_;
119 // Stores current opacity of the window. Set on ::Initialize call.
120 ui::PlatformWindowOpacity opacity_;
122 // The type of the current WaylandWindow object.
123 ui::PlatformWindowType type_ = ui::PlatformWindowType::kWindow;
125 bool has_focus_ = false;
127 Ecore_Evas* ee_ = nullptr;
128 Evas* evas_ = nullptr;
130 // Overlay for events
131 Evas_Object* events_overlay_ = nullptr;
133 #if defined(USE_WAYLAND)
134 Ecore_Wl2_Window* wl_window_ = nullptr;
135 Ecore_Wl2_Egl_Window* wl2_egl_window_ = nullptr;
138 EflInputMethodContext* efl_input_method_context_ = nullptr;
139 std::unique_ptr<EflEventHandler> efl_event_handler_;
144 #endif // UI_OZONE_PLATFORM_EFL_EFL_WINDOW_H_