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 RENDER_WIDGET_HOST_VIEW_EFL
6 #define RENDER_WIDGET_HOST_VIEW_EFL
8 #include <Ecore_Evas.h>
9 #include <Ecore_IMF_Evas.h>
13 #include "base/containers/id_map.h"
14 #include "base/format_macros.h"
15 #include "components/viz/common/frame_sinks/copy_output_request.h"
16 #include "components/viz/common/frame_sinks/copy_output_result.h"
17 #include "components/viz/common/quads/compositor_frame.h"
18 #include "components/viz/common/resources/single_release_callback.h"
19 #include "content/browser/accessibility/browser_accessibility_manager.h"
20 #include "content/browser/compositor/evasgl_delegated_frame_host.h"
21 #include "content/browser/renderer_host/evas_event_handler.h"
22 #include "content/browser/renderer_host/render_widget_host_view_base.h"
23 #include "content/browser/selection/selection_controller_efl.h"
24 #include "content/browser/web_contents/web_contents_impl.h"
25 #include "content/browser/web_contents/web_contents_view_efl.h"
26 #include "content/common/content_export.h"
27 #include "ipc/ipc_sender.h"
28 #include "ui/base/ime/composition_text.h"
29 #include "ui/base/ime/text_input_client.h"
30 #include "ui/events/gestures/gesture_recognizer.h"
31 #include "ui/events/gestures/gesture_types.h"
32 #include "ui/events/gestures/motion_event_aura.h"
34 // Before, it was separated by EVAS_GL_API_VERSION and each value was;
35 // TV/DESKTOP = 1, MOBILE/WEARABLE = 4
37 // After Desktop build EFL upversion to 1.18,
38 // EVAS_GL_API_VERSION of DESKTOP is 5 and
39 // it would be more legible to seperate by profiles.
41 typedef EvasGLint64 GLint64;
42 typedef EvasGLuint64 GLuint64;
44 typedef struct __GLsync* GLsync;
45 typedef signed long GLint64;
46 typedef unsigned long GLuint64;
49 struct TextInputState;
54 struct DidOverscrollParams;
63 typedef void (*Screenshot_Captured_Callback)(Evas_Object* image,
66 class DisambiguationPopupEfl;
69 class RenderWidgetHostImpl;
70 class RenderWidgetHostView;
72 class ScreenshotCapturedCallback;
74 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
75 class CONTENT_EXPORT RenderWidgetHostViewEfl
76 : public RenderWidgetHostViewBase,
77 public EvasGLDelegatedFrameHostClient,
78 public ui::GestureConsumer,
79 public ui::GestureEventHelper,
80 public base::SupportsWeakPtr<RenderWidgetHostViewEfl>,
83 explicit RenderWidgetHostViewEfl(RenderWidgetHost*,
84 WebContents& web_contents);
86 // RenderWidgetHostViewBase implementation.
87 void InitAsChild(gfx::NativeView) override;
88 void InitAsPopup(RenderWidgetHostView*, const gfx::Rect&) override;
89 void InitAsFullscreen(RenderWidgetHostView*) override;
90 void SetSize(const gfx::Size&) override;
91 void SetBounds(const gfx::Rect&) override;
92 gfx::NativeView GetNativeView() const override;
93 gfx::NativeViewAccessible GetNativeViewAccessible() override;
94 bool IsSurfaceAvailableForCopy() const override;
97 bool IsShowing() override;
98 gfx::Rect GetViewBounds() const override;
99 bool LockMouse() override;
100 void UnlockMouse() override;
101 void Focus() override;
102 bool HasFocus() const override;
103 void UpdateCursor(const WebCursor&) override;
104 void SetIsLoading(bool) override;
105 void SetBackgroundColor(SkColor color) override;
106 SkColor background_color() const override;
107 void TakeFallbackContentFrom(RenderWidgetHostView* view) override;
108 viz::SurfaceId GetCurrentSurfaceId() const override;
109 gfx::Vector2d GetOffsetFromRootSurface() override;
111 void UpdateBackgroundColorFromRenderer(SkColor color);
113 #if defined(EWK_BRINGUP)
114 // [M51_2704] TextInputStateChanged() should be removed and its functionality
115 // should be moved/implemented in appropriate place based on
116 // upstream commit : https://codereview.chromium.org/1652483002,
117 // as it may introduce regression.
118 // Updates the state of the input method attached to the view.
119 void TextInputStateChanged(const TextInputState& params);
122 void OnTextInputInFormStateChanged(bool is_in_form_tag);
124 void ImeCancelComposition() override;
125 void ImeCompositionRangeChanged(const gfx::Range&,
126 const std::vector<gfx::Rect>&) override;
127 void FocusedNodeChanged(bool is_editable_node,
128 const gfx::Rect& node_bounds_in_screen) override;
130 void Destroy() override;
131 void SetTooltipText(const base::string16&) override;
132 void SelectionChanged(const base::string16&,
134 const gfx::Range&) override;
135 void SelectionBoundsChanged(
136 const ViewHostMsg_SelectionBounds_Params&) override;
137 void SetWantsAnimateOnlyBeginFrames() override;
138 void SetNeedsBeginFrames(bool needs_begin_frames) override;
139 void DidOverscroll(const ui::DidOverscrollParams& params) override;
140 gfx::Rect GetBoundsInRootWindow() override;
141 void RenderProcessGone(base::TerminationStatus, int) override;
142 bool OnMessageReceived(const IPC::Message&) override;
144 void OnFilteredMessageReceived(const IPC::Message&);
146 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo&,
147 InputEventAckState) override;
148 void DidStopFlinging() override;
150 void ShowDisambiguationPopup(const gfx::Rect& rect_pixels,
151 const SkBitmap& zoomed_bitmap) override;
152 void DisambiguationPopupDismissed();
153 void HandleDisambiguationPopupMouseDownEvent(Evas_Event_Mouse_Down*);
154 void HandleDisambiguationPopupMouseUpEvent(Evas_Event_Mouse_Up*);
156 void DidCreateNewRendererCompositorFrameSink(
157 viz::mojom::CompositorFrameSinkClient* renderer_compositor_frame_sink)
159 void SubmitCompositorFrame(
160 const viz::LocalSurfaceId& local_surface_id,
161 viz::CompositorFrame frame,
162 viz::mojom::HitTestRegionListPtr hit_test_region_list) override;
163 void ClearCompositorFrame() override;
165 // ui::GestureEventHelper implementation.
166 bool CanDispatchToConsumer(ui::GestureConsumer* consumer) override;
167 void DispatchSyntheticTouchEvent(ui::TouchEvent* event) override;
168 void DispatchGestureEvent(GestureConsumer* raw_input_consumer,
169 ui::GestureEvent*) override;
171 // IPC::Sender implementation:
172 bool Send(IPC::Message*) override;
174 void FilterInputMotion(const blink::WebGestureEvent& gesture_event);
176 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
177 void SelectClosestWord(const gfx::Point& touch_point);
184 Evas_Object* smart_parent() const { return smart_parent_; }
186 void set_magnifier(bool status);
188 void Init_EvasGL(int width, int height);
189 void CreateNativeSurface(int width, int height);
191 void SetEvasHandler(scoped_refptr<EvasEventHandler> evas_event_handler);
193 void HandleGestureBegin();
194 void HandleGestureEnd();
195 void HandleGesture(ui::GestureEvent*);
196 void HandleGesture(blink::WebGestureEvent&);
197 void HandleTouchEvent(ui::TouchEvent*);
199 Evas_GL_API* evasGlApi() { return evas_gl_api_; }
200 gfx::Point ConvertPointInViewPix(gfx::Point point);
201 gfx::Rect GetViewBoundsInPix() const;
203 void MoveCaret(const gfx::Point& point);
204 void SetComposition(const ui::CompositionText& composition_text);
205 void ConfirmComposition(base::string16& text);
206 void SendGestureEvent(blink::WebGestureEvent& event);
208 void SetTouchEventsEnabled(bool enabled);
210 void ScrollFocusedEditableNode();
212 bool IsLastAvailableTextEmpty() const;
214 bool IsIMEShow() const;
215 gfx::Rect GetIMERect() const;
216 void GetSnapshotAsync(const gfx::Rect& snapshot_area, int request_id);
217 bool RequestSnapshotAsync(const Eina_Rectangle rect,
218 Screenshot_Captured_Callback callback,
220 void OnSnapshotDataReceived(SkBitmap bitmap, int snapshotId);
221 #if !defined(EWK_BRINGUP)
222 void CopyOutputCallback(int request_id,
223 std::unique_ptr<viz::CopyOutputResult> result);
228 SelectionControllerEfl* GetSelectionController() const {
229 return selection_controller_.get();
232 unsigned PointerStatePointerCount() const {
233 return pointer_state_.GetPointerCount();
236 // Sets rotation degrees. Expected values are one of { 0, 90, 180, 270 }.
237 void UpdateRotationDegrees(int rotation_degrees);
239 // EvasGLDelegatedFrameHostClient implementation.
240 Evas_GL_API* GetEvasGLAPI() override;
241 void DelegatedFrameHostSendReclaimCompositorResources(
242 const viz::LocalSurfaceId& local_surface_id,
243 const std::vector<viz::ReturnedResource>& resources) override;
244 Evas_GL* GetEvasGL() override;
247 ~RenderWidgetHostViewEfl() override;
249 void InitializeDeviceDisplayInfo();
250 gfx::NativeViewId GetNativeViewId() const;
252 static void OnParentViewResize(void* data, Evas*, Evas_Object*, void*);
253 static void OnFocusIn(void* data, Evas*, Evas_Object*, void*);
254 static void OnFocusOut(void* data, Evas*, Evas_Object*, void*);
255 static void OnHostFocusIn(void* data, Evas_Object*, void*);
256 static void OnHostFocusOut(void* data, Evas_Object*, void*);
258 static void OnMotionEnable(void* data, Evas_Object*, void*);
259 static void OnMotionMove(void* data, Evas_Object*, void*);
260 static void OnMotionZoom(void* data, Evas_Object*, void*);
262 static void OnMultiTouchDownEvent(void* data, Evas*, Evas_Object*, void*);
263 static void OnMultiTouchMoveEvent(void* data, Evas*, Evas_Object*, void*);
264 static void OnMultiTouchUpEvent(void* data, Evas*, Evas_Object*, void*);
266 static void OnMouseDown(void* data, Evas*, Evas_Object*, void*);
267 static void OnMouseUp(void* data, Evas*, Evas_Object*, void*);
268 static void OnMouseMove(void* data, Evas*, Evas_Object*, void*);
269 static void OnMouseWheel(void* data, Evas*, Evas_Object*, void*);
270 static void OnKeyDown(void*, Evas*, Evas_Object*, void*);
271 static void OnKeyUp(void*, Evas*, Evas_Object*, void*);
272 #if defined(OS_TIZEN)
273 static void OnHWBackEvent(void*, Evas_Object*, void*);
276 void ProcessTouchEvents(unsigned int timestamp);
277 void SetDoubleTapSupportEnabled(bool enabled);
279 void OnOrientationChangeEvent(int);
280 void OnDidHandleKeyEvent(const blink::WebInputEvent* input_event,
283 // With immediate = true, it calls evas_render().
284 void Invalidate(bool immediate);
285 // TODO(prashant.n): Implement delegate to handle multiple frame_hosts.
286 void SwapBrowserFrame(const viz::LocalSurfaceId& local_surface_id,
287 viz::CompositorFrame frame);
288 void ClearBrowserFrame();
289 void RenderBrowserFrame();
290 static void EvasObjectImagePixelsGetCallback(void*, Evas_Object*);
292 EdgeEffect& EnsureEdgeEffect();
294 #if defined(USE_WAYLAND)
295 Ecore_Wl_Window* GetEcoreWlWindow() const;
297 Ecore_X_Window GetEcoreXWindow() const;
300 std::unique_ptr<EvasGLDelegatedFrameHost> evasgl_delegated_frame_host_;
301 IMContextEfl* im_context_;
303 Evas_Object* parent_view_;
304 Evas_Object* smart_parent_;
305 Evas_Object* content_image_;
306 Evas_Object* content_image_elm_host_;
307 bool evas_gl_initialized_;
308 float device_scale_factor_;
312 // Whether we are currently loading.
315 scoped_refptr<EvasEventHandler> evas_event_handler_;
317 // Stores the current state of the active pointers targeting this
319 ui::MotionEventAura pointer_state_;
321 // The gesture recognizer for this view.
322 // In Aura GestureRecognizer is global. Should we follow that?
323 std::unique_ptr<ui::GestureRecognizer> gesture_recognizer_;
325 std::unique_ptr<DisambiguationPopupEfl> disambiguation_popup_;
326 std::unique_ptr<EdgeEffect> edge_effect_;
328 int current_orientation_;
331 Evas_GL_API* evas_gl_api_;
332 Evas_GL_Config* evas_gl_config_;
333 Evas_GL_Context* evas_gl_context_;
334 Evas_GL_Surface* evas_gl_surface_;
336 bool handling_disambiguation_popup_gesture_;
337 bool touch_events_enabled_;
338 // The background color of the web content.
339 SkColor background_color_;
341 // The last scroll offset of the view.
342 gfx::Vector2dF last_scroll_offset_;
344 WebContents& web_contents_;
346 base::IDMap<std::unique_ptr<ScreenshotCapturedCallback>>
347 screen_capture_cb_map_;
349 std::unique_ptr<SelectionControllerEfl> selection_controller_;
351 viz::mojom::CompositorFrameSinkClient* renderer_compositor_frame_sink_ =
354 base::WeakPtrFactory<RenderWidgetHostViewEfl> weak_factory_;
356 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEfl);
359 } // namespace content