[M120 Migration][NUI] Add internal mouse event API for NUI.
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / content / browser / renderer_host / rwhv_aura_common_helper_efl.h
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef CONTENT_BROWSER_RENDERER_HOST_RWHV_AURA_COMMON_HELPER_EFL_H_
18 #define CONTENT_BROWSER_RENDERER_HOST_RWHV_AURA_COMMON_HELPER_EFL_H_
19
20 #include <Evas.h>
21
22 #include "base/containers/id_map.h"
23 #include "content/common/cursors/webcursor.h"
24 #include "third_party/blink/public/common/input/web_gesture_event.h"
25 #include "third_party/blink/public/common/input/web_input_event.h"
26 #include "ui/base/ime/mojom/text_input_state.mojom-forward.h"
27 #include "ui/events/event.h"
28 #include "ui/gfx/geometry/size_f.h"
29 #include "ui/gfx/range/range.h"
30
31 #if BUILDFLAG(IS_TIZEN_TV)
32 #define DEFAULT_MAX_LENGTH std::numeric_limits<int>::max()
33 #endif
34
35 namespace ui {
36 class EflEventHandler;
37 class IMContextEfl;
38 struct DidOverscrollParams;
39 } // namespace ui
40
41 namespace content {
42
43 typedef void (*Screenshot_Captured_Callback)(Evas_Object* image,
44                                              void* user_data);
45
46 class ScreenshotCapturedCallback {
47  public:
48   ScreenshotCapturedCallback(Screenshot_Captured_Callback func, void* user_data)
49       : func_(func), user_data_(user_data) {}
50   void Run(void* image) {
51     if (func_ != NULL)
52       (func_)((Evas_Object*)image, user_data_);
53   }
54
55  private:
56   Screenshot_Captured_Callback func_;
57   void* user_data_;
58 };
59
60 class RenderWidgetHostHelper;
61 class RenderWidgetHostImpl;
62 class RenderWidgetHostViewAura;
63 class SelectionControllerEfl;
64 class WebContents;
65 class WebContentsDelegate;
66
67 class CONTENT_EXPORT RWHVAuraCommonHelperEfl {
68  public:
69   RWHVAuraCommonHelperEfl(
70       RenderWidgetHostViewAura* rwhva, WebContents* web_contents);
71   virtual ~RWHVAuraCommonHelperEfl();
72
73   virtual void SetAuraParentWindow(gfx::NativeView parent_view) {}
74   virtual void AuraChildWindowAdded() {}
75   virtual void NotifySwap(const size_t texture_id) {}
76   virtual void DidGetContentSnapshot(const SkBitmap& bitmap, int request_id);
77   virtual void Show() {}
78   virtual void Hide() {}
79   virtual void Focus(bool focus) {}
80   virtual bool HasFocus() { return false; }
81   virtual gfx::Size GetVisibleViewportSize() { return gfx::Size(); }
82   virtual gfx::Size GetPhysicalBackingSize() const { return gfx::Size(); }
83   virtual void HandleGestureBegin() {}
84   virtual void HandleGestureEnd() {}
85   virtual void HandleGesture(blink::WebGestureEvent& event);
86   virtual void DidOverscroll(const ui::DidOverscrollParams& params);
87   virtual gfx::Rect GetViewBounds() { return gfx::Rect(); }
88
89   bool IsOffscreenMode() { return is_offscreen_mode_; }
90   Evas_Object* ewk_view() const;
91   SelectionControllerEfl* GetSelectionController() const {
92     return selection_controller_.get();
93   }
94   RenderWidgetHostImpl* GetRenderWidgetHostImpl();
95   gfx::NativeView GetNativeView();
96   WebContents* GetWebContents() { return web_contents_; }
97   void SetPageVisibility(bool visible);
98   Evas* GetEvas();
99   void RequestSnapshotAsyncOnscreen(const gfx::Rect& snapshot_area,
100                                     Screenshot_Captured_Callback callback,
101                                     void* user_data,
102                                     float scale_factor = 1.0);
103
104
105   void MoveCaret(const gfx::Point& point);
106   void SetScaledContentSize(const gfx::SizeF& size) {
107     scaled_contents_size_ = size;
108   }
109   gfx::Point ConvertPointInViewPix(gfx::Point point);
110   void SetCustomViewportSize(const gfx::Size& size);
111   bool HasSelectableText();
112   void set_magnifier(bool status) { magnifier_ = status; }
113   bool IsTouchstartConsumed() const { return touchstart_consumed_; }
114   bool IsTouchendConsumed() const { return touchend_consumed_; }
115   void SetTouchStartConsumed(bool touchstart_consumed) {
116     touchstart_consumed_ = touchstart_consumed;
117   }
118   void SetTouchEndConsumed(bool touchend_consumed) {
119     touchend_consumed_ = touchend_consumed;
120   }
121   void SetTouchEventsEnabled(bool enabled);
122   bool TouchEventsEnabled();
123   void SendMouseDown(int button, int x, int y);
124   void SendMouseUp(int button, int x, int y);
125   void SendMouseMove(int x, int y);
126   void SendMouseWheel(bool y_direction, int step, int x, int y);
127   void SendMouseOut();
128   bool IsFocusedNodeContentEditable() const { return is_content_editable_; }
129
130   void SetKeyEventsEnabled(bool enabled);
131   void SendKeyEvent(Evas_Object* ewk_view, void* key_event, bool is_press);
132
133   void OnMouseOrTouchEvent(ui::Event* event);
134   void FocusedNodeChanged(bool editable,
135 #if BUILDFLAG(IS_TIZEN_TV)
136       bool is_radio_or_checkbox,
137       int password_input_minlength,
138       int input_maxlength,
139 #endif
140       bool is_content_editable);
141
142 #if BUILDFLAG(IS_TIZEN_TV)
143   //Browser edge scroll
144   void DidEdgeScrollBy(const gfx::Point& offset, bool handled);
145   void MoveFocusToBrowser(int direction);
146   void SetPopupMenuVisible(const bool visible);
147   void SetPopupMenuBounds(const gfx::Rect& popup_bounds);
148   void SetCursorByClient(bool enable) { cursor_set_by_client_ = enable; }
149   // notify track info to browser process
150   void NotifyTrackInfoToBrowser(int active_track_id,
151                                 const std::string& url,
152                                 const std::string& lang);
153   void SetPreferSubtitleLang(std::string lang_list);
154   void SetIMERecommendedWords(const std::string& recommended_words);
155   void SetIMERecommendedWordsType(bool should_enable);
156   void SetMouseEventsEnabled(bool enabled);
157   void SetTranslatedURL(const std::string& url);
158   void SetParentalRatingResult(const std::string& url, bool is_pass);
159   // notify web browser video playing status
160   void RequestVideoPlaying(int callback_id);
161   void VideoPlayingStatusReceived(bool is_playing, int callback_id);
162   void SetMouseEventCallbacks(
163       const base::RepeatingCallback<void(int, int)>& on_mouse_down,
164       const base::RepeatingCallback<bool(void)>& on_mouse_up,
165       const base::RepeatingCallback<void(void)>& on_mouse_move);
166   void MouseDownCallback(int x, int y);
167   bool MouseUpCallback();
168   void MouseMoveCallback();
169 #endif
170
171   void CompositingCompleteSwapWithNewSize(const gfx::Size& size) {
172     frame_data_output_size_ = size;
173   }
174   gfx::Size GetFrameDateOutputSize() { return frame_data_output_size_; }
175   void SetOrientation(int orientation) { rotation_ = orientation; }
176   int GetOrientation() { return rotation_; }
177
178   void OnGestureEvent(ui::GestureEvent* event);
179   void DidChangeInputType(bool is_password_field);
180   void BackgroundColorReceived(int callback_id, SkColor bg_color);
181   void OnGetFocusedNodeBounds(const gfx::RectF& rect);
182   void DidHandleKeyEvent(
183         blink::WebInputEvent::Type input_event_type, bool processed);
184   void SelectionChanged(
185       const std::u16string& text, size_t offset, const gfx::Range& range);
186   void OnGetMainFrameScrollbarVisible(int callback_id, bool visible);
187   void TextInputStateChanged(const ui::mojom::TextInputState& params);
188   void OnSelectionRectReceived(const gfx::Rect& selection_rect);
189   void UpdateTooltipUnderCursor(const std::u16string&);
190
191  protected:
192   void SetOffscreenMode() { is_offscreen_mode_ = true; }
193   RenderWidgetHostViewAura* rwhva() { return rwhv_aura_; }
194   ui::IMContextEfl* GetIMContextEfl();
195   void FocusRWHVA();
196   void SendGestureEvent(blink::WebGestureEvent& event);
197
198   float device_scale_factor_ = 1.0f;
199   gfx::SizeF scaled_contents_size_;
200   gfx::Size custom_viewport_size_;
201   base::IDMap<std::unique_ptr<ScreenshotCapturedCallback>>
202       screen_capture_cb_map_;
203   int rotation_ = 0;
204   gfx::Size frame_data_output_size_;
205
206  private:
207   ui::EflEventHandler* GetEventHandler();
208
209   bool is_focused_node_editable_ = false;
210   bool is_scrolling_needed_ = false;
211   bool touchstart_consumed_ = false;
212   bool touchend_consumed_ = false;
213
214   ui::IMContextEfl* im_context_efl_ = nullptr;
215   RenderWidgetHostViewAura* rwhv_aura_ = nullptr;
216   WebContents* web_contents_ = nullptr;
217   std::unique_ptr<SelectionControllerEfl> selection_controller_;
218
219   bool magnifier_ = false;
220   bool is_content_editable_ = false;
221   bool is_offscreen_mode_ = false;
222
223 #if BUILDFLAG(IS_TIZEN_TV)
224   bool radio_or_checkbox_focused_ = false;
225   int password_input_minlength_ = -1;
226   int input_maxlength_ = DEFAULT_MAX_LENGTH;
227
228   // When WebBrowser sets their own cursor, set the flag
229   // not to set the WebPage cursor
230   bool cursor_set_by_client_ = false;
231   base::RepeatingCallback<void(int, int)> on_mouse_down_callback_;
232   base::RepeatingCallback<bool(void)> on_mouse_up_callback_;
233   base::RepeatingCallback<void(void)> on_mouse_move_callback_;
234 #endif
235
236   std::unique_ptr<RenderWidgetHostHelper> rwh_helper_;
237
238   RWHVAuraCommonHelperEfl(const RWHVAuraCommonHelperEfl&) = delete;
239   RWHVAuraCommonHelperEfl& operator=(const RWHVAuraCommonHelperEfl&) = delete;
240 };
241
242 } // namespace content
243
244 #endif  // CONTENT_BROWSER_RENDERER_HOST_RWHV_AURA_COMMON_HELPER_EFL_H_