1 // Copyright 2014-2015 Samsung Electronics. All rights reserved.
2 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #ifndef RENDER_WIDGET_HOST_VIEW_EFL
7 #define RENDER_WIDGET_HOST_VIEW_EFL
10 #include <Ecore_Evas.h>
12 #include <Ecore_IMF_Evas.h>
14 #include "base/basictypes.h"
15 #include "base/format_macros.h"
16 #include "base/id_map.h"
17 #include "content/browser/renderer_host/render_widget_host_view_base.h"
18 #include "content/browser/renderer_host/evas_event_handler.h"
19 #include "content/browser/web_contents/web_contents_impl.h"
20 #include "content/browser/web_contents/web_contents_view_efl.h"
21 #include "content/common/content_export.h"
22 #include "cc/layers/delegated_frame_provider.h"
23 #include "cc/layers/delegated_frame_resource_collection.h"
24 #include "cc/output/compositor_frame.h"
25 #include "cc/output/compositor_frame_ack.h"
26 #include "cc/output/copy_output_request.h"
27 #include "cc/output/copy_output_result.h"
28 #include "cc/resources/single_release_callback.h"
29 #include "cc/resources/texture_mailbox.h"
30 #include "content/browser/accessibility/browser_accessibility_manager.h"
31 #include "content/browser/compositor/delegated_frame_host.h"
32 #include "content/browser/compositor/image_transport_factory.h"
33 #include "content/browser/compositor/owned_mailbox.h"
34 #include "content/browser/renderer_host/context_factory_efl.h"
35 #include "content/browser/renderer_host/render_widget_host_view_base.h"
36 #include "content/browser/selection/selection_controller_efl.h"
37 #include "gpu/command_buffer/common/mailbox.h"
38 #include "ui/base/ime/composition_text.h"
39 #include "ui/base/ime/text_input_client.h"
40 #include "ui/compositor/layer_owner.h"
41 #include "ui/events/gestures/gesture_types.h"
42 #include "ui/events/gestures/gesture_recognizer.h"
43 #include "ui/events/gestures/motion_event_aura.h"
44 #include "ipc/ipc_sender.h"
45 #if defined(TIZEN_DISABLE_GPU_THREAD)
46 #include "ui/compositor/compositor.h"
47 #include "ui/gl/gl_shared_context_efl.h"
50 #if (EVAS_GL_API_VERSION == 1)
51 // For desktop build using efl-1.9.x ~ efl-1.11.x
52 // GLsync, GL*64, EvasGL*64 are not defined by Evas_GL.h
53 typedef struct __GLsync* GLsync;
54 typedef signed long long GLint64;
55 typedef unsigned long long GLuint64;
57 typedef EvasGLint64 GLint64;
58 typedef EvasGLuint64 GLuint64;
61 struct ViewHostMsg_TextInputState_Params;
75 typedef void (*Screenshot_Captured_Callback)(Evas_Object* image, void* user_data);
77 class DisambiguationPopupEfl;
80 class RenderWidgetHostImpl;
81 class RenderWidgetHostView;
82 class ReadbackYUVInterface;
84 class ScreenshotCapturedCallback;
86 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
87 class CONTENT_EXPORT RenderWidgetHostViewEfl
88 : public RenderWidgetHostViewBase,
89 public DelegatedFrameHostClient,
90 public ContextFactoryDelegate,
91 public ui::LayerOwner,
92 public ui::GestureConsumer,
93 public ui::GestureEventHelper,
94 #if defined(TIZEN_DISABLE_GPU_THREAD)
95 public ui::CompositorClient,
96 public GLSharedContextDelegate,
98 public base::SupportsWeakPtr<RenderWidgetHostViewEfl>,
101 explicit RenderWidgetHostViewEfl(RenderWidgetHost*, WebContents& web_contents);
103 // RenderWidgetHostViewBase implementation.
104 void InitAsChild(gfx::NativeView) override;
105 void InitAsPopup(content::RenderWidgetHostView*, const gfx::Rect&) override;
106 void InitAsFullscreen(content::RenderWidgetHostView*) override;
107 RenderWidgetHost* GetRenderWidgetHost() const override;
108 void SetSize(const gfx::Size&) override;
109 void SetBounds(const gfx::Rect&) override;
110 gfx::Vector2dF GetLastScrollOffset() const override;
111 gfx::NativeView GetNativeView() const override;
112 gfx::NativeViewId GetNativeViewId() const override;
113 gfx::NativeViewAccessible GetNativeViewAccessible() override;
114 bool IsSurfaceAvailableForCopy() const override;
115 void Show() override;
116 void Hide() override;
117 bool IsShowing() override;
118 gfx::Rect GetViewBounds() const override;
119 bool LockMouse() override;
120 void UnlockMouse() override;
121 void Focus() override;
122 bool HasFocus() const override;
123 void MovePluginContainer(const WebPluginGeometry&);
124 void MovePluginWindows(
125 const std::vector<WebPluginGeometry>&) override;
126 void UpdateCursor(const WebCursor&) override;
127 void SetIsLoading(bool) override;
129 // Updates the state of the input method attached to the view.
130 void TextInputStateChanged(
131 const ViewHostMsg_TextInputState_Params& params) override;
133 void OnTextInputInFormStateChanged(bool is_in_form_tag);
134 void OnTextInputStateChanged(const ViewHostMsg_TextInputState_Params& params);
136 void ImeCancelComposition() override;
137 void ImeCompositionRangeChanged(const gfx::Range&, const std::vector<gfx::Rect>&) override;
138 void FocusedNodeChanged(bool is_editable_node) override;
140 void Destroy() override;
141 void SetTooltipText(const base::string16&) override;
142 void SelectionChanged(const base::string16&, size_t, const gfx::Range&) override;
143 void SelectionBoundsChanged(const ViewHostMsg_SelectionBounds_Params&) override;
144 void CopyFromCompositingSurface(
146 const gfx::Size& /* dst_size */,
147 const ReadbackRequestCallback&,
148 const SkColorType) override;
150 void CopyFromCompositingSurfaceToVideoFrame(
152 const scoped_refptr<media::VideoFrame>&,
153 const base::Callback<void(bool)>&) override;
155 bool CanCopyToVideoFrame() const override;
156 void BeginFrameSubscription(
157 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) override;
158 void EndFrameSubscription() override;
159 void DidOverscroll(const DidOverscrollParams& params) override;
160 bool HasAcceleratedSurface(const gfx::Size&) override;
161 void GetScreenInfo(blink::WebScreenInfo*) override;
162 bool GetScreenColorProfile(std::vector<char>* color_profile) override;
163 gfx::Rect GetBoundsInRootWindow() override;
164 void RenderProcessGone(base::TerminationStatus, int) override;
165 bool OnMessageReceived(const IPC::Message&) override;
167 void OnFilteredMessageReceived(const IPC::Message&);
169 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo&, InputEventAckState) override;
170 void DidStopFlinging() override;
172 void ShowDisambiguationPopup(const gfx::Rect& rect_pixels,
173 const SkBitmap& zoomed_bitmap) override;
174 void HandleDisambiguationPopupMouseDownEvent(Evas_Event_Mouse_Down*);
175 void HandleDisambiguationPopupMouseUpEvent(Evas_Event_Mouse_Up*);
177 void OnSwapCompositorFrame(
178 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) override;
180 void ClearCompositorFrame () override;
182 // ui::GestureEventHelper implementation.
183 bool CanDispatchToConsumer(ui::GestureConsumer* consumer) override;
184 void DispatchCancelTouchEvent(ui::TouchEvent* event) override;
185 void DispatchGestureEvent(ui::GestureEvent*) override;
187 // IPC::Sender implementation:
188 bool Send(IPC::Message*) override;
190 void FilterInputMotion(const blink::WebGestureEvent& gesture_event);
192 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
193 void SelectClosestWord(const gfx::Point& touch_point);
200 Evas_Object* smart_parent() const { return smart_parent_; }
202 void set_magnifier(bool status);
204 void Init_EvasGL(int width, int height);
205 void ResizeCompositorLayer(int width, int height);
206 void CreateNativeSurface(int width, int height);
208 void SetEvasHandler(scoped_refptr<EvasEventHandler> evas_event_handler);
210 void HandleGestureBegin();
211 void HandleGestureEnd();
212 void HandleGesture(ui::GestureEvent*);
213 void HandleGesture(blink::WebGestureEvent&);
214 void HandleTouchEvent(ui::TouchEvent*);
216 Evas_GL_API* evasGlApi() { return evas_gl_api_; }
217 gfx::Point ConvertPointInViewPix(gfx::Point point);
218 gfx::Rect GetViewBoundsInPix() const;
220 void MoveCaret(const gfx::Point& point);
221 void SetComposition(const ui::CompositionText& composition_text);
222 void ConfirmComposition(base::string16& text);
223 void SendGestureEvent(blink::WebGestureEvent& event);
225 void SetTouchEventsEnabled(bool enabled);
227 void ScrollFocusedEditableNode();
229 bool IsLastAvailableTextEmpty() const;
231 bool IsIMEShow() const;
232 gfx::Rect GetIMERect() const;
233 void GetSnapshotAsync(const gfx::Rect& snapshot_area, int request_id);
234 bool RequestSnapshotAsync(const Eina_Rectangle rect,
235 Screenshot_Captured_Callback callback,
237 void OnSnapshotDataReceived(SkBitmap bitmap, int snapshotId);
239 // DelegatedFrameHostClient implementation.
240 ui::Layer* DelegatedFrameHostGetLayer() const override;
241 bool DelegatedFrameHostIsVisible() const override;
242 scoped_ptr<ResizeLock> DelegatedFrameHostCreateResizeLock(
243 bool defer_compositor_lock) override;
244 bool DelegatedFrameCanCreateResizeLock() const override;
245 gfx::Size DelegatedFrameHostDesiredSizeInDIP() const override;
246 void DelegatedFrameHostResizeLockWasReleased() override;
247 void DelegatedFrameHostSendCompositorSwapAck(
248 int output_surface_id,
249 const cc::CompositorFrameAck& ack) override;
250 void DelegatedFrameHostSendReclaimCompositorResources(
251 int output_surface_id,
252 const cc::CompositorFrameAck& ack) override;
253 void DelegatedFrameHostOnLostCompositorResources() override;
254 void DelegatedFrameHostUpdateVSyncParameters(
255 const base::TimeTicks& timebase,
256 const base::TimeDelta& interval) override;
258 #if defined(TIZEN_DISABLE_GPU_THREAD)
259 void DoCompositeNow();
263 SelectionControllerEfl* GetSelectionController() const {
264 return selection_controller_.get();
268 friend class RenderWidgetHostView;
271 ~RenderWidgetHostViewEfl() override;
273 static void OnParentViewResize(void* data, Evas*, Evas_Object*, void*);
274 static void OnFocusIn(void* data, Evas*, Evas_Object*, void*);
275 static void OnFocusOut(void* data, Evas*, Evas_Object*, void*);
276 static void OnHostFocusIn(void* data, Evas_Object*, void*);
277 static void OnHostFocusOut(void* data, Evas_Object*, void*);
279 static void OnMotionEnable(void* data, Evas_Object*, void*);
280 static void OnMotionMove(void* data, Evas_Object*, void*);
281 static void OnMotionZoom(void* data, Evas_Object*, void*);
283 static void OnMultiTouchEvent(void* data, Evas*, Evas_Object*, void*);
285 static void OnMouseDown(void* data, Evas*, Evas_Object*, void*);
286 static void OnMouseUp(void* data, Evas*, Evas_Object*, void*);
287 static void OnMouseMove(void* data, Evas*, Evas_Object*, void*);
288 static void OnMouseWheel(void* data, Evas*, Evas_Object*, void*);
289 static void OnKeyDown(void*, Evas*, Evas_Object*, void*);
290 static void OnKeyUp(void*, Evas*, Evas_Object*, void*);
291 void ProcessTouchEvents();
292 void SetDoubleTapSupportEnabled(bool enabled);
294 void OnOrientationChangeEvent(int);
295 void OnDidHandleKeyEvent(const blink::WebInputEvent* input_event, bool processed);
297 static void CopyFromCompositingSurfaceHasResultForVideo(
298 base::WeakPtr<RenderWidgetHostViewEfl> rwhvefl,
299 scoped_refptr<OwnedMailbox> subscriber_texture,
300 scoped_refptr<media::VideoFrame> video_frame,
301 const base::Callback<void(bool)>& callback,
302 scoped_ptr<cc::CopyOutputResult> result);
303 static void CopyFromCompositingSurfaceFinishedForVideo(
304 base::WeakPtr<RenderWidgetHostViewEfl> rwhvefl,
305 const base::Callback<void(bool)>& callback,
306 scoped_refptr<OwnedMailbox> subscriber_texture,
307 scoped_ptr<cc::SingleReleaseCallback> release_callback,
309 static void ReturnSubscriberTexture(
310 base::WeakPtr<RenderWidgetHostViewEfl> rwhvefl,
311 scoped_refptr<OwnedMailbox> subscriber_texture,
314 static void EvasObjectImagePixelsGetCallback(void*, Evas_Object*);
315 void initializeProgram();
317 EdgeEffect& EnsureEdgeEffect();
319 #if defined(USE_WAYLAND)
320 Ecore_Wl_Window* GetEcoreWlWindow() const;
322 Ecore_X_Window GetEcoreXWindow() const;
325 #if defined(TIZEN_DISABLE_GPU_THREAD)
326 void PaintToSurface();
328 void PaintTextureToSurface(GLuint texture_id);
330 // overrides ContextFactoryDelegate
331 void GetTextureFromMailbox(gpu::Mailbox* mailbox,
332 gfx::Size surface_size) override;
334 RenderWidgetHostImpl* host_;
335 IMContextEfl* im_context_;
337 Evas_Object* parent_view_;
338 Evas_Object* smart_parent_;
339 Evas_Object* content_image_;
340 Evas_Object* content_image_elm_host_;
341 bool evas_gl_initialized_;
342 float device_scale_factor_;
344 #if defined(USE_WAYLAND)
345 typedef std::map<gfx::PluginWindowHandle, Ecore_Wl_Window*> PluginWindowToWidgetMap;
347 typedef std::map<gfx::PluginWindowHandle, Ecore_X_Window> PluginWindowToWidgetMap;
349 PluginWindowToWidgetMap plugin_window_to_widget_map_;
353 // Whether we are currently loading.
356 scoped_refptr<EvasEventHandler> evas_event_handler_;
358 // YUV readback pipeline.
359 scoped_ptr<content::ReadbackYUVInterface>
360 yuv_readback_pipeline_;
362 // Subscriber that listens to frame presentation events.
363 scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_;
364 std::vector<scoped_refptr<OwnedMailbox> > idle_frame_subscriber_textures_;
365 std::set<OwnedMailbox*> active_frame_subscriber_textures_;
367 // Stores the current state of the active pointers targeting this
369 ui::MotionEventAura pointer_state_;
371 // The gesture recognizer for this view.
372 // In Aura GestureRecognizer is global. Should we follow that?
373 scoped_ptr<ui::GestureRecognizer> gesture_recognizer_;
375 scoped_ptr<DisambiguationPopupEfl> disambiguation_popup_;
376 scoped_ptr<EdgeEffect> edge_effect_;
378 int current_orientation_;
381 Evas_GL_API* evas_gl_api_;
382 Evas_GL_Context* evas_gl_context_;
383 Evas_GL_Surface* evas_gl_surface_;
384 Evas_GL_Config* evas_gl_config_;
387 GLint source_texture_location_;
388 GLuint position_attrib_;
389 GLuint texcoord_attrib_;
391 unsigned long current_pixmap_id_;
392 unsigned long next_pixmap_id_;
395 gfx::Size surface_size_;
396 bool is_modifier_key_;
397 GLuint vertex_buffer_obj_;
398 GLuint index_buffer_obj_;
400 bool touch_events_enabled_;
402 // The last scroll offset of the view.
403 gfx::Vector2dF last_scroll_offset_;
405 gpu::Mailbox pending_mailbox_;
407 WebContents& web_contents_;
409 IDMap<ScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
410 ui::Compositor* compositor_;
411 scoped_ptr<ui::Layer> root_layer_;
412 scoped_ptr<DelegatedFrameHost> delegated_frame_host_;
413 ui::ContextFactory* context_factory_;
415 scoped_ptr<SelectionControllerEfl> selection_controller_;
417 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEfl);
420 } // namespace content