[WRTjs] Refactor popup
[platform/framework/web/chromium-efl.git] / wrt / src / browser / wrt_native_window.h
1 // Copyright 2020 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 BROWSER_WRT_NATIVE_WINDOW_H_
6 #define BROWSER_WRT_NATIVE_WINDOW_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "content/public/browser/web_contents_delegate.h"
12 #include "electron/shell/browser/native_window.h"
13 #include "wrt/src/browser/wrt_javascript_dialog_manager.h"
14
15 namespace content {
16
17 class RenderFrameHost;
18 class RenderWidgetHostViewAura;
19 class WebContents;
20 class WebContentsViewAura;
21
22 } // namespace content
23
24 namespace ui {
25 class CompositorObserver;
26 }
27
28 class EWebAccessibility;
29 typedef struct _Ecore_Evas Ecore_Evas;
30 typedef struct _Eo_Opaque Evas_Object;
31
32 namespace wrt {
33
34 class WRTNativeWindowDelegate;
35 class WRTProfileDelegate;
36 class WRTWindowTreeHost;
37
38 enum class RotaryEventType {
39   CLOCKWISE,         // Rotary is rotated clockwise direction
40   COUNTER_CLOCKWISE  // Rotary is rotated counter clockwise direction
41 };
42
43 class WRTNativeWindow : public electron::NativeWindow {
44  public:
45   explicit WRTNativeWindow(const gin_helper::Dictionary& options,
46                            electron::NativeWindow* parent);
47   ~WRTNativeWindow() override;
48
49   WRTNativeWindow(const WRTNativeWindow&) = delete;
50   WRTNativeWindow& operator=(const WRTNativeWindow&) = delete;
51
52   enum class ScreenOrientation {
53     PORTRAIT_PRIMARY = 0,
54     PORTRAIT_SECONDARY = 1,
55     LANDSCAPE_PRIMARY = 2,
56     LANDSCAPE_SECONDARY = 3,
57     NATURAL = 4,
58     ANY = 5,
59     NONE = 6
60   };
61
62   static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
63   static Evas_Object* GetTopWindow();
64   static Evas_Object* GetConformant();
65   static Ecore_Evas* GetPlatformCanvas();
66   static WRTNativeWindow* FromWebContents(const content::WebContents*);
67   static WRTNativeWindow* GetMainNativeWindow();
68   static WRTNativeWindow* GetActiveNativeWindow();
69   static void EnsurePlatformWindow();
70   static void RotationCallback();
71   static bool UseOnscreenRendering();
72
73   Evas_Object* view_evas() { return GetTopWindow(); }
74   content::RenderWidgetHostViewAura* GetRenderWidgetHostView();
75   content::WebContents* GetWebContents();
76   bool is_main_native_window() { return is_main_native_window_; }
77
78   // NativeWindow:
79   void SetContentView(views::View* view) override;
80   void Close() override;
81   void CloseImmediately() override;
82   void Focus(bool focus) override;
83   bool IsFocused() override;
84   void Show() override;
85   void ShowInactive() override;
86   void Hide() override;
87   bool IsVisible() override;
88   bool IsEnabled() override;
89   void SetEnabled(bool enable) override;
90   void Maximize() override;
91   void Unmaximize() override;
92   bool IsMaximized() override;
93   void Minimize() override;
94   void Restore() override;
95   bool IsMinimized() override;
96   void SetFullScreen(bool fullscreen) override;
97   bool IsFullscreen() const override;
98   void SetBounds(const gfx::Rect& bounds, bool animate = false) override;
99   gfx::Rect GetBounds() override;
100   gfx::Rect GetNormalBounds() override;
101   void SetResizable(bool resizable) override;
102   bool MoveAbove(const std::string& sourceId) override;
103   void MoveTop() override;
104   bool IsResizable() override;
105   void SetMovable(bool movable) override;
106   bool IsMovable() override;
107   void SetMinimizable(bool minimizable) override;
108   bool IsMinimizable() override;
109   void SetMaximizable(bool maximizable) override;
110   bool IsMaximizable() override;
111   void SetFullScreenable(bool fullscreenable) override;
112   bool IsFullScreenable() override;
113   void SetClosable(bool closable) override;
114   bool IsClosable() override;
115   void SetAlwaysOnTop(ui::ZOrderLevel z_order,
116                       const std::string& level = "floating",
117                       int relativeLevel = 0) override;
118   ui::ZOrderLevel GetZOrderLevel() override;
119   void Center() override;
120   void Invalidate() override;
121   void SetTitle(const std::string& title) override;
122   std::string GetTitle() override;
123   void FlashFrame(bool flash) override;
124   void SetSkipTaskbar(bool skip) override;
125   void SetExcludedFromShownWindowsMenu(bool excluded) override;
126   bool IsExcludedFromShownWindowsMenu() override;
127   void SetSimpleFullScreen(bool simple_fullscreen) override;
128   bool IsSimpleFullScreen() override;
129   void SetKiosk(bool kiosk) override;
130   bool IsKiosk() override;
131   void SetBackgroundColor(SkColor color) override;
132   SkColor GetBackgroundColor() override;
133   void SetHasShadow(bool has_shadow) override;
134   bool HasShadow() override;
135   void SetOpacity(const double opacity) override;
136   double GetOpacity() override;
137   void SetIgnoreMouseEvents(bool ignore, bool forward) override;
138   void SetContentProtection(bool enable) override;
139   void AddBrowserView(electron::NativeBrowserView* browser_view) override;
140   void RemoveBrowserView(electron::NativeBrowserView* browser_view) override;
141   void SetTopBrowserView(electron::NativeBrowserView* browser_view) override;
142   content::DesktopMediaID GetDesktopMediaID() const override;
143   gfx::NativeView GetNativeView() const override;
144   gfx::NativeWindow GetNativeWindow() const override;
145   gfx::AcceleratedWidget GetAcceleratedWidget() const override;
146   electron::NativeWindowHandle GetNativeWindowHandle() const override;
147
148   void SetProgressBar(double progress,
149                       const ProgressState state) override;
150   void SetOverlayIcon(const gfx::Image& overlay,
151                       const std::string& description) override;
152
153   // Workspace APIs.
154   void SetVisibleOnAllWorkspaces(bool visible,
155                                  bool visibleOnFullScreen = false,
156                                  bool skipTransformProcessType = false) override;
157   bool IsVisibleOnAllWorkspaces() override;
158
159   // Converts between content bounds and window bounds.
160   gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
161   gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;
162
163   virtual bool IsSameWindowId(const unsigned int window_id) { return true; }
164   virtual void LowerWindow();
165   virtual void SetPageVisibility(bool visibility);
166   virtual bool WillHandleConformantChange() { return true; }
167   virtual bool ShouldHandleConformantChange() { return true; }
168
169  protected:
170   static bool SetRotation() { return false; }
171   static void SetRotationState(bool is_auto, int degree = -1);
172
173   static WRTNativeWindowDelegate* GetNativeWindowDelegate();
174
175   virtual void SetWebContents(content::WebContents* web_contents);
176   virtual bool IsRunningAsBackground() { return false; }
177   virtual void OnRotation(int degree);
178
179   void SetScheduledTasks(bool enable);
180
181   WRTWindowTreeHost* GetWindowTreeHost();
182
183   content::RenderFrameHost* GetRenderFrameHost();
184   content::WebContentsViewAura* GetWebContentsViewAura();
185   WRTJavaScriptDialogManager* GetJavaScriptDialogManager();
186
187   bool is_main_native_window_;
188   bool is_enabled_ = true;
189   content::WebContents* web_contents_;
190
191  private:
192   static void InitializePlatformEventListeners();
193   static void CleanupPlatformEventListeners();
194   static void HidePlatformWindow();
195
196   static void AddEditorClientEventListeners();
197   static void AddRotaryEventListener();
198   static void InitRotation();
199
200   static void OnHWBackKey(void*, Evas_Object*, void*);
201   static void OnHWMoreKey(void*, Evas_Object*, void*);
202
203   void OnSoftKeyboardChangeEvent(bool value);
204   void OnRotaryEvent(RotaryEventType type);
205
206   // views::WidgetDelegate:
207   std::unique_ptr<views::NonClientFrameView> CreateNonClientFrameView(
208       views::Widget* widget) override;
209
210   std::string title_;
211   bool fullscreenable_;
212   bool visibility_status_;
213
214   std::unique_ptr<EWebAccessibility> wrt_accessibility_;
215   std::unique_ptr<ui::CompositorObserver> compositor_observer_;
216 };
217
218 }  // namespace wrt
219
220 #endif  // BROWSER_WRT_NATIVE_WINDOW_H_