[M108 Migration][Text Selection] Selection handles & Caret Selection
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / content / browser / renderer_host / rwhv_aura_offscreen_helper_efl.h
1 // Copyright (c) 2012 The Chromium Authors. 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 CONTENT_BROWSER_RENDERER_HOST_RWHV_AURA_OFFSCREEN_HELPER_EFL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RWHV_AURA_OFFSCREEN_HELPER_EFL_H_
7
8 #include <list>
9
10 #include <Evas.h>
11 #include <Evas_GL.h>
12
13 #include <Ecore.h>
14 #include <Ecore_Evas.h>
15 #include <Ecore_Input.h>
16 #include <Elementary.h>
17 #include "ecore_x_wayland_wrapper.h"
18
19 #include "base/callback.h"
20 #include "base/containers/id_map.h"
21 #include "base/timer/timer.h"
22 #include "content/browser/selection/selection_controller_efl.h"
23 #include "content/common/cursors/webcursor.h"
24 #include "third_party/blink/public/common/input/web_input_event.h"
25 #include "ui/base/ime/mojom/text_input_state.mojom-forward.h"
26 #include "ui/events/event.h"
27 #include "ui/gfx/geometry/size_f.h"
28 #include "ui/gfx/native_widget_types.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 }  // namespace ui
39
40 namespace content {
41
42 typedef void (*Screenshot_Captured_Callback)(Evas_Object* image,
43                                              void* user_data);
44 typedef base::OnceCallback<void()> SnapshotTask;
45
46 class RenderWidgetHostHelper;
47 class RenderWidgetHostImpl;
48 class RenderWidgetHostViewAura;
49 class ScreenshotCapturedCallback;
50 class WebContents;
51 class WebContentsDelegate;
52
53 class CONTENT_EXPORT RWHVAuraOffscreenHelperEfl {
54  public:
55
56   using OnFocusCallback = base::RepeatingCallback<void(void)>;
57
58   RWHVAuraOffscreenHelperEfl(RenderWidgetHostViewAura* rwhva,
59                              WebContents* web_contents);
60   ~RWHVAuraOffscreenHelperEfl();
61
62   void SetAuraParentWindow(gfx::NativeView parent_window);
63   void AuraChildWindowAdded();
64   void NotifySwap(const uint32_t texture_id);
65   void BackgroundColorReceived(int callback_id, SkColor bg_color);
66   void Show();
67   void Hide();
68   void OnGetMainFrameScrollbarVisible(int callback_id, bool visible);
69
70   gfx::Size GetVisibleViewportSize();
71   gfx::Rect GetViewBounds();
72   void SetCustomViewportSize(const gfx::Size& size);
73   gfx::Size GetPhysicalBackingSize() const;
74   void OnGetFocusedNodeBounds(const gfx::RectF& rect);
75
76   void SetTouchEventsEnabled(bool enabled);
77   bool TouchEventsEnabled();
78
79   bool GetHorizontalPanningHold() const { return horizontal_panning_hold_; }
80   void SetHorizontalPanningHold(bool hold) { horizontal_panning_hold_ = hold; }
81   bool GetVerticalPanningHold() const { return vertical_panning_hold_; }
82   void SetVerticalPanningHold(bool hold) { vertical_panning_hold_ = hold; }
83
84 #if BUILDFLAG(IS_TIZEN_TV)
85   void DrawLabel(Evas_Object* image, Eina_Rectangle rect);
86   void ClearLabels();
87 #endif
88
89   gfx::Rect GetViewBoundsInPix() const;
90   const gfx::Size GetScrollableSize() const;
91   void SetScaledContentSize(const gfx::SizeF& size) {
92     scaled_contents_size_ = size;
93   }
94   int GetTopControlsHeight();
95
96   void Focus(bool focus);
97   bool HasFocus();
98   void SetPageVisibility(bool visible);
99   void TextInputStateChanged(const ui::mojom::TextInputState& params);
100   void FocusedNodeChanged(bool editable
101 #if BUILDFLAG(IS_TIZEN_TV)
102                           ,
103                           bool is_radio_or_checkbox,
104                           int password_input_minlength,
105                           int input_maxlength
106 #endif
107                           ,
108                           bool is_content_editable);
109
110   // |snapshot_area| is relative coordinate system based on Webview.
111   // (0,0) is top left corner.
112   Evas_Object* GetSnapshot(const gfx::Rect& snapshot_area,
113                            float scale_factor,
114                            bool is_magnifier = false);
115   void RequestSnapshotAsync(const gfx::Rect& snapshot_area,
116                             Screenshot_Captured_Callback callback,
117                             void* user_data,
118                             float scale_factor = 1.0);
119   void DidGetContentSnapshot(const SkBitmap& bitmap, int request_id);
120
121   RenderWidgetHostViewAura* rwhva() { return rwhv_aura_; }
122   void OnMouseOrTouchEvent(ui::Event* event);
123   void DidHandleKeyEvent(blink::WebInputEvent::Type input_event_type,
124                          bool processed);
125   void SelectionChanged(const std::u16string& text,
126                         size_t offset,
127                         const gfx::Range& range);
128   SelectionControllerEfl* GetSelectionController() const {
129     return selection_controller_.get();
130   }
131   void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
132
133   Evas_Object* ewk_view() const;
134   Evas_Object* content_image() const { return content_image_; }
135   Evas_Object* content_image_elm_host() const {
136     return content_image_elm_host_;
137   }
138   gfx::Point ConvertPointInViewPix(gfx::Point point);
139   RenderWidgetHostImpl* GetRenderWidgetHostImpl();
140   gfx::NativeView GetNativeView();
141   WebContents* GetWebContents() { return web_contents_; }
142
143   void SetFocusInOutCallbacks(const OnFocusCallback& on_focus_in,
144                               const OnFocusCallback& on_focus_out);
145
146   bool IsFocusedNodeContentEditable() const { return is_content_editable_; }
147
148   void MoveCaret(const gfx::Point& point);
149   void SelectClosestWord(const gfx::Point& touch_point);
150   bool HasSelectableText();
151
152  private:
153   static void OnParentViewResize(void* data, Evas*, Evas_Object*, void*);
154   static void EvasObjectImagePixelsGetCallback(void*, Evas_Object*);
155   static void OnFocusIn(void* data, Evas*, Evas_Object*, void*);
156   static void OnFocusOut(void* data, Evas*, Evas_Object*, void*);
157   static void OnHostFocusIn(void* data, Evas_Object*, void*);
158   static void OnHostFocusOut(void* data, Evas_Object*, void*);
159   static void OnEvasRenderFlushPre(void* data, Evas* evas, void* event_info);
160
161   void Initialize();
162   void InitializeProgram();
163   void PaintTextureToSurface(GLuint texture_id);
164   void FocusRWHVA();
165
166   void InitEvasGL();
167   gfx::Size CreateNativeSurface();
168   bool ClearCurrent();
169   bool MakeCurrent();
170   void ClearBrowserFrame();
171
172   void InvalidateForSnapshot();
173   void ProcessSnapshotRequest();
174   void RunGetSnapshotOnMainThread(const gfx::Rect snapshot_area,
175                                   int request_id,
176                                   float scale_factor);
177
178   ui::EflEventHandler* GetEventHandler();
179   ui::IMContextEfl* GetIMContextEfl();
180
181   Evas* evas_ = nullptr;
182   Evas_GL* evas_gl_ = nullptr;
183   Evas_GL_API* evas_gl_api_ = nullptr;
184   Evas_GL_Config* evas_gl_config_ = nullptr;
185   Evas_GL_Context* evas_gl_context_ = nullptr;
186   Evas_GL_Surface* evas_gl_surface_ = nullptr;
187   Evas_Object* content_image_ = nullptr;
188   Evas_Object* parent_view_ = nullptr;
189   Evas_Object* content_image_elm_host_ = nullptr;
190
191   GLuint program_id_;
192   GLint source_texture_location_;
193   GLuint position_attrib_;
194   GLuint rotate_position_attrib_;
195   GLuint texcoord_attrib_;
196   GLuint texture_id_ = 0;
197   GLuint vertex_buffer_obj_;
198   GLuint index_buffer_obj_;
199   gfx::NativeView aura_parent_window_ = nullptr;
200
201   int rotation_ = 0;
202   float device_scale_factor_ = 1.0f;
203   gfx::SizeF scaled_contents_size_;
204   gfx::Size custom_viewport_size_;
205
206 #if BUILDFLAG(IS_TIZEN_TV)
207   bool radio_or_checkbox_focused_ = false;
208   int password_input_minlength_ = -1;
209   int input_maxlength_ = DEFAULT_MAX_LENGTH;
210   std::vector<Evas_Object*> voice_manager_labels_;
211 #endif
212   bool is_focused_node_editable_ = false;
213   bool is_scrolling_needed_ = false;
214
215   ui::IMContextEfl* im_context_efl_ = nullptr;
216   RenderWidgetHostViewAura* rwhv_aura_ = nullptr;
217   WebContents* web_contents_ = nullptr;
218   std::unique_ptr<SelectionControllerEfl> selection_controller_;
219
220   std::unique_ptr<RenderWidgetHostHelper> rwh_helper_;
221
222   bool frame_rendered_ = false;
223   std::list<SnapshotTask> snapshot_task_list_;
224   std::unique_ptr<base::OneShotTimer> snapshot_timer_;
225   base::IDMap<std::unique_ptr<ScreenshotCapturedCallback>>
226       screen_capture_cb_map_;
227
228   bool horizontal_panning_hold_ = false;
229   bool vertical_panning_hold_ = false;
230
231   OnFocusCallback on_focus_in_callback_;
232   OnFocusCallback on_focus_out_callback_;
233
234   bool is_content_editable_ = false;
235 };
236
237 }  // namespace content
238
239 #endif