[WRTjs] Refactor popup
[platform/framework/web/chromium-efl.git] / wrt / src / browser / wrt_web_contents.h
1 #ifndef BROWSER_WRT_WEB_CONTENTS_H_
2 #define BROWSER_WRT_WEB_CONTENTS_H_
3
4 #include <Evas.h>
5 #include <map>
6
7 #include "base/threading/thread.h"
8 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
9 #include "content/public/browser/context_menu_params.h"
10 #include "content/public/browser/render_frame_host_receiver_set.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "mojo/public/cpp/bindings/associated_remote.h"
13 #include "third_party/blink/public/mojom/choosers/popup_menu.mojom.h"
14 #include "wrt/src/common/wrt.mojom.h"
15
16 namespace content {
17 class SelectionControllerEfl;
18 class WebContents;
19 class WebContentsViewAura;
20 class WebContentsViewAuraHelperEfl;
21 }
22
23 class SelectPickerBase;
24
25 namespace wrt {
26
27 class WRTNativeWindow;
28 class WRTContextMenuController;
29 class WRTWebViewDelegate;
30
31 class WRTWebContents
32     : public content::WebContentsObserver,
33       public mojom::WRTBrowser {
34  public:
35   static void WebContentsCreated(content::WebContents* web_contents);
36   static void WebContentsDeleted(content::WebContents* web_contents);
37   static bool IsObservedWebContents(content::WebContents* web_contents);
38   static WRTWebContents* FromWebContents(content::WebContents* web_contents);
39   static WRTWebContents* FromNativeWindow(WRTNativeWindow* window);
40   static content::WebContents* GetWebContents();
41   static void BindBrowser(
42         mojo::PendingAssociatedReceiver<mojom::WRTBrowser> receiver,
43         content::RenderFrameHost* render_frame_host);
44
45   virtual ~WRTWebContents();
46
47   WRTWebContents(const WRTWebContents&) = delete;
48   WRTWebContents& operator=(const WRTWebContents&) = delete;
49
50   mojom::WRTRenderer* GetRendererInterface();
51
52   // ContextMenuController or SelectionController related methods
53   void ShowContextMenu(const content::ContextMenuParams& params);
54   void OnSelectionRectReceived(const gfx::Rect& selection_rect) const;
55   void ExecuteEditCommand(const char* command, const char* value);
56   void HideContextMenu();
57   void ResetControllers();
58
59   void ShowPopupMenuImpl(std::vector<blink::mojom::MenuItemPtr> items,
60                          int selectedIndex,
61                          bool multiple,
62                          const gfx::Rect& bounds,
63                          double item_font_size);
64   bool IsPopupShowing() { return is_popup_showing_; }
65   void HidePopupMenuImpl();
66   void AdjustViewPortHeightToPopupMenu(bool is_popup_menu_visible);
67   void ScrollFocusedNodeIntoView();
68
69   bool ImePanelEnabled() { return show_ime_panel_; }
70   bool UseFloatingUI() { return ime_is_floating_; }
71   bool UseKeyPadWithoutUserAction() { return use_keypad_without_user_action_; }
72
73  private:
74   WRTWebContents(content::WebContents* web_contents);
75
76   // content::WebContentsObserver
77   void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
78   void RenderViewReady() override;
79   void OnPageScaleFactorChanged(float page_scale_factor) override;
80   void DidFinishNavigation(content::NavigationHandle* navigation_handle) override;
81   void DidFinishLoad(content::RenderFrameHost* render_frame_host,
82                      const GURL& validated_url) override;
83
84   void SetScaledContentSize();
85
86   content::RenderWidgetHostViewAura* rwhva() const;
87   Evas_Object* evas_object();
88   content::SelectionControllerEfl* GetSelectionController() const;
89   void UpdateContextMenuWithParams(const content::ContextMenuParams& params);
90   void ShowContextMenuInternal(const content::ContextMenuParams& params);
91   void HandleLongPressGesture(const content::ContextMenuParams& params);
92
93   content::WebContentsViewAura* GetWebContentsViewAura() const;
94   content::WebContentsViewAuraHelperEfl* GetWebContentsViewAuraHelper();
95
96 #if BUILDFLAG(IS_TIZEN_TV)
97   content::RWHVAuraCommonHelperEfl* GetRWHVAEflHelper();
98 #endif
99
100   void SetExtraCommandLineSwitches(content::RenderFrameHost* render_frame_host);
101   void SetLongPollingTimeout();
102
103   // mojom::WRTBrowser:
104   void StartService(
105       const std::string& internal_id,
106       mojo::PendingRemote<mojom::WRTServiceMessageListener> remote,
107       StartServiceCallback callback) override;
108   void StopService(const std::string& internal_id,
109                    StopServiceCallback callback) override;
110   void PlayLinkEffect() override;
111   void DidChangeContentsSize(const gfx::Size& size) override;
112   void DidHandleGestureEventWithContext(bool is_content_editable) override;
113
114   static std::map<content::WebContents*, std::unique_ptr<WRTWebContents>> map_;
115
116   content::RenderFrameHostReceiverSet<mojom::WRTBrowser> receivers_;
117   mojo::AssociatedRemote<mojom::WRTRenderer> renderer_interface_;
118
119   gfx::Size contents_size_;
120   double page_scale_factor_;
121   std::unique_ptr<WRTContextMenuController> context_menu_;
122   std::unique_ptr<SelectPickerBase> select_picker_;
123   std::unique_ptr<WRTWebViewDelegate> web_view_delegate_;
124   base::Thread thread_;
125
126   bool show_ime_panel_;
127   bool ime_is_floating_;
128   bool use_keypad_without_user_action_;
129   bool is_popup_showing_ = false;
130 };
131
132 }  // namespace wrt
133
134 #endif  // BROWSER_WRT_WEB_CONTENTS_H_