[M120 Migration][VD] Fix some focus issues for offscreen mode
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / ui / ozone / platform / efl / efl_window.h
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.
4
5 #ifndef UI_OZONE_PLATFORM_EFL_EFL_WINDOW_H_
6 #define UI_OZONE_PLATFORM_EFL_EFL_WINDOW_H_
7
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"
13
14 #include <Ecore_Evas.h>
15
16 #if defined(USE_WAYLAND)
17 #include <Ecore_Wl2.h>
18 #endif
19
20 namespace ui {
21
22 class EflEventHandler;
23 class EflInputMethodContext;
24 class EflWindowManager;
25
26 class EflWindow : public PlatformWindow, public PlatformEventDispatcher {
27  public:
28   static Ecore_Evas* CreateEvasObject(const gfx::Rect& bounds);
29   static void SetPreparedEvasObject(Ecore_Evas* ee);
30
31   EflWindow(PlatformWindowDelegate* delegate,
32             PlatformWindowInitProperties properties,
33             EflWindowManager* manager);
34
35   EflWindow(const EflWindow&) = delete;
36   EflWindow& operator=(const EflWindow&) = delete;
37
38   ~EflWindow() override;
39
40   // PlatformWindow implementation.
41   void Show(bool inactive = false) override;
42   void Hide() 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;
71
72   // PlatformEventDispatcher implementation.
73   bool CanDispatchEvent(const PlatformEvent& event) override;
74   uint32_t DispatchEvent(const PlatformEvent& event) override;
75
76   // Called only in case of offscreen rendering
77   void SetEventsOverlayForOffscreen(Evas_Object* events_overlay) override;
78
79   void UpdateFocus(bool focused) override;
80   void SetFocus(bool focused) { has_focus_ = focused; }
81
82   void OnWindowLostCapture();
83
84   Evas* evas() const { return evas_; }
85   Evas_Object* native_view() const { return events_overlay_; }
86
87   void SetEflInputMethodContext(EflInputMethodContext* context) {
88     efl_input_method_context_ = context;
89   }
90
91   EflEventHandler* GetEventHandler() override {
92     return efl_event_handler_.get();
93   }
94
95  private:
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_;
104 #endif
105   bool IsFullscreen();
106
107   // Stores current state of this window.
108   PlatformWindowState state_ = PlatformWindowState::kUnknown;
109
110   PlatformWindowDelegate* delegate_;
111
112   EflWindowManager* window_manager_ = nullptr;
113
114   // Current bounds of the platform window.
115   gfx::Rect bounds_;
116   // The bounds of the platform window before it went maximized or fullscreen.
117   gfx::Rect restored_bounds_;
118
119   // Stores current opacity of the window. Set on ::Initialize call.
120   ui::PlatformWindowOpacity opacity_;
121
122   // The type of the current WaylandWindow object.
123   ui::PlatformWindowType type_ = ui::PlatformWindowType::kWindow;
124
125   bool has_focus_ = false;
126
127   Ecore_Evas* ee_ = nullptr;
128   Evas* evas_ = nullptr;
129
130   // Overlay for events
131   Evas_Object* events_overlay_ = nullptr;
132
133 #if defined(USE_WAYLAND)
134   Ecore_Wl2_Window* wl_window_ = nullptr;
135   Ecore_Wl2_Egl_Window* wl2_egl_window_ = nullptr;
136 #endif
137
138   EflInputMethodContext* efl_input_method_context_ = nullptr;
139   std::unique_ptr<EflEventHandler> efl_event_handler_;
140 };
141
142 }  // namespace ui
143
144 #endif  // UI_OZONE_PLATFORM_EFL_EFL_WINDOW_H_