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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RWHV_AURA_OFFSCREEN_HELPER_EFL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RWHV_AURA_OFFSCREEN_HELPER_EFL_H_
14 #include <Ecore_Evas.h>
15 #include <Ecore_Input.h>
16 #include <Elementary.h>
17 #include "ecore_x_wayland_wrapper.h"
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"
31 #if BUILDFLAG(IS_TIZEN_TV)
32 #define DEFAULT_MAX_LENGTH std::numeric_limits<int>::max()
36 class EflEventHandler;
42 typedef void (*Screenshot_Captured_Callback)(Evas_Object* image,
44 typedef base::OnceCallback<void()> SnapshotTask;
46 class RenderWidgetHostHelper;
47 class RenderWidgetHostImpl;
48 class RenderWidgetHostViewAura;
49 class ScreenshotCapturedCallback;
51 class WebContentsDelegate;
53 class CONTENT_EXPORT RWHVAuraOffscreenHelperEfl {
56 using OnFocusCallback = base::RepeatingCallback<void(void)>;
58 RWHVAuraOffscreenHelperEfl(RenderWidgetHostViewAura* rwhva,
59 WebContents* web_contents);
60 ~RWHVAuraOffscreenHelperEfl();
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);
68 void OnGetMainFrameScrollbarVisible(int callback_id, bool visible);
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);
76 void SetTouchEventsEnabled(bool enabled);
77 bool TouchEventsEnabled();
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; }
84 #if BUILDFLAG(IS_TIZEN_TV)
85 void DrawLabel(Evas_Object* image, Eina_Rectangle rect);
89 gfx::Rect GetViewBoundsInPix() const;
90 const gfx::Size GetScrollableSize() const;
91 void SetScaledContentSize(const gfx::SizeF& size) {
92 scaled_contents_size_ = size;
94 int GetTopControlsHeight();
96 void Focus(bool focus);
98 void SetPageVisibility(bool visible);
99 void TextInputStateChanged(const ui::mojom::TextInputState& params);
100 void FocusedNodeChanged(bool editable
101 #if BUILDFLAG(IS_TIZEN_TV)
103 bool is_radio_or_checkbox,
104 int password_input_minlength,
108 bool is_content_editable);
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,
114 bool is_magnifier = false);
115 void RequestSnapshotAsync(const gfx::Rect& snapshot_area,
116 Screenshot_Captured_Callback callback,
118 float scale_factor = 1.0);
119 void DidGetContentSnapshot(const SkBitmap& bitmap, int request_id);
121 RenderWidgetHostViewAura* rwhva() { return rwhv_aura_; }
122 void OnMouseOrTouchEvent(ui::Event* event);
123 void DidHandleKeyEvent(blink::WebInputEvent::Type input_event_type,
125 void SelectionChanged(const std::u16string& text,
127 const gfx::Range& range);
128 SelectionControllerEfl* GetSelectionController() const {
129 return selection_controller_.get();
131 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
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_;
138 gfx::Point ConvertPointInViewPix(gfx::Point point);
139 RenderWidgetHostImpl* GetRenderWidgetHostImpl();
140 gfx::NativeView GetNativeView();
141 WebContents* GetWebContents() { return web_contents_; }
143 void SetFocusInOutCallbacks(const OnFocusCallback& on_focus_in,
144 const OnFocusCallback& on_focus_out);
146 bool IsFocusedNodeContentEditable() const { return is_content_editable_; }
148 void MoveCaret(const gfx::Point& point);
149 void SelectClosestWord(const gfx::Point& touch_point);
150 bool HasSelectableText();
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);
162 void InitializeProgram();
163 void PaintTextureToSurface(GLuint texture_id);
167 gfx::Size CreateNativeSurface();
170 void ClearBrowserFrame();
172 void InvalidateForSnapshot();
173 void ProcessSnapshotRequest();
174 void RunGetSnapshotOnMainThread(const gfx::Rect snapshot_area,
178 ui::EflEventHandler* GetEventHandler();
179 ui::IMContextEfl* GetIMContextEfl();
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;
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;
202 float device_scale_factor_ = 1.0f;
203 gfx::SizeF scaled_contents_size_;
204 gfx::Size custom_viewport_size_;
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_;
212 bool is_focused_node_editable_ = false;
213 bool is_scrolling_needed_ = false;
215 ui::IMContextEfl* im_context_efl_ = nullptr;
216 RenderWidgetHostViewAura* rwhv_aura_ = nullptr;
217 WebContents* web_contents_ = nullptr;
218 std::unique_ptr<SelectionControllerEfl> selection_controller_;
220 std::unique_ptr<RenderWidgetHostHelper> rwh_helper_;
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_;
228 bool horizontal_panning_hold_ = false;
229 bool vertical_panning_hold_ = false;
231 OnFocusCallback on_focus_in_callback_;
232 OnFocusCallback on_focus_out_callback_;
234 bool is_content_editable_ = false;
237 } // namespace content