[M47_2526] Chromium upversion to m47_2526 branch
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / content / browser / renderer_host / render_widget_host_view_efl.h
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.
5
6 #ifndef RENDER_WIDGET_HOST_VIEW_EFL
7 #define RENDER_WIDGET_HOST_VIEW_EFL
8
9 #include <Evas.h>
10 #include <Ecore_Evas.h>
11 #include <Evas_GL.h>
12 #include <Ecore_IMF_Evas.h>
13
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"
48 #endif
49
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;
56 #else
57 typedef EvasGLint64          GLint64;
58 typedef EvasGLuint64         GLuint64;
59 #endif
60
61 struct ViewHostMsg_TextInputState_Params;
62
63 namespace ui {
64 class Compositor;
65 class GestureEvent;
66 class TouchEvent;
67 }
68
69 namespace blink {
70 struct WebScreenInfo;
71 }
72
73 namespace content {
74
75 typedef void (*Screenshot_Captured_Callback)(Evas_Object* image, void* user_data);
76
77 class DisambiguationPopupEfl;
78 class EdgeEffect;
79 class IMContextEfl;
80 class RenderWidgetHostImpl;
81 class RenderWidgetHostView;
82 class ReadbackYUVInterface;
83 class WebContents;
84 class ScreenshotCapturedCallback;
85
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,
97 #endif
98       public base::SupportsWeakPtr<RenderWidgetHostViewEfl>,
99       public IPC::Sender {
100  public:
101   explicit RenderWidgetHostViewEfl(RenderWidgetHost*, WebContents& web_contents);
102
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;
128
129   // Updates the state of the input method attached to the view.
130   void TextInputStateChanged(
131       const ViewHostMsg_TextInputState_Params& params) override;
132
133   void OnTextInputInFormStateChanged(bool is_in_form_tag);
134   void OnTextInputStateChanged(const ViewHostMsg_TextInputState_Params& params);
135
136   void ImeCancelComposition() override;
137   void ImeCompositionRangeChanged(const gfx::Range&, const std::vector<gfx::Rect>&) override;
138   void FocusedNodeChanged(bool is_editable_node) override;
139
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(
145     const gfx::Rect&,
146     const gfx::Size& /* dst_size */,
147     const ReadbackRequestCallback&,
148     const SkColorType) override;
149
150   void CopyFromCompositingSurfaceToVideoFrame(
151     const gfx::Rect&,
152     const scoped_refptr<media::VideoFrame>&,
153     const base::Callback<void(bool)>&) override;
154
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;
166
167   void OnFilteredMessageReceived(const IPC::Message&);
168
169   void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo&, InputEventAckState) override;
170   void DidStopFlinging() override;
171
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*);
176
177   void OnSwapCompositorFrame(
178       uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) override;
179
180   void ClearCompositorFrame () override;
181
182   // ui::GestureEventHelper implementation.
183   bool CanDispatchToConsumer(ui::GestureConsumer* consumer) override;
184   void DispatchCancelTouchEvent(ui::TouchEvent* event) override;
185   void DispatchGestureEvent(ui::GestureEvent*) override;
186
187   // IPC::Sender implementation:
188   bool Send(IPC::Message*) override;
189
190   void FilterInputMotion(const blink::WebGestureEvent& gesture_event);
191
192   void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
193   void SelectClosestWord(const gfx::Point& touch_point);
194
195   Evas* evas() const {
196     DCHECK(evas_);
197     return evas_;
198   }
199
200   Evas_Object* smart_parent() const { return smart_parent_; }
201
202   void set_magnifier(bool status);
203
204   void Init_EvasGL(int width, int height);
205   void ResizeCompositorLayer(int width, int height);
206   void CreateNativeSurface(int width, int height);
207
208   void SetEvasHandler(scoped_refptr<EvasEventHandler> evas_event_handler);
209
210   void HandleGestureBegin();
211   void HandleGestureEnd();
212   void HandleGesture(ui::GestureEvent*);
213   void HandleGesture(blink::WebGestureEvent&);
214   void HandleTouchEvent(ui::TouchEvent*);
215
216   Evas_GL_API* evasGlApi() { return evas_gl_api_; }
217   gfx::Point ConvertPointInViewPix(gfx::Point point);
218   gfx::Rect GetViewBoundsInPix() const;
219
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);
224
225   void SetTouchEventsEnabled(bool enabled);
226
227   void ScrollFocusedEditableNode();
228
229   bool IsLastAvailableTextEmpty() const;
230
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,
236     void* user_data);
237   void OnSnapshotDataReceived(SkBitmap bitmap, int snapshotId);
238
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;
257
258 #if defined(TIZEN_DISABLE_GPU_THREAD)
259   void DoCompositeNow();
260   bool MakeCurrent();
261 #endif
262
263   SelectionControllerEfl* GetSelectionController() const {
264     return selection_controller_.get();
265   }
266
267  protected:
268   friend class RenderWidgetHostView;
269
270  private:
271   ~RenderWidgetHostViewEfl() override;
272
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*);
278
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*);
282
283   static void OnMultiTouchEvent(void* data, Evas*, Evas_Object*, void*);
284
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);
293
294   void OnOrientationChangeEvent(int);
295   void OnDidHandleKeyEvent(const blink::WebInputEvent* input_event, bool processed);
296
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,
308       bool result);
309   static void ReturnSubscriberTexture(
310       base::WeakPtr<RenderWidgetHostViewEfl> rwhvefl,
311       scoped_refptr<OwnedMailbox> subscriber_texture,
312       uint32 sync_point);
313
314   static void EvasObjectImagePixelsGetCallback(void*, Evas_Object*);
315   void initializeProgram();
316
317   EdgeEffect& EnsureEdgeEffect();
318
319 #if defined(USE_WAYLAND)
320   Ecore_Wl_Window* GetEcoreWlWindow() const;
321 #else
322   Ecore_X_Window GetEcoreXWindow() const;
323 #endif
324
325 #if defined(TIZEN_DISABLE_GPU_THREAD)
326   void PaintToSurface();
327 #endif
328   void PaintTextureToSurface(GLuint texture_id);
329
330   // overrides ContextFactoryDelegate
331   void GetTextureFromMailbox(gpu::Mailbox* mailbox,
332                              gfx::Size surface_size) override;
333
334   RenderWidgetHostImpl* host_;
335   IMContextEfl* im_context_;
336   Evas* evas_;
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_;
343
344 #if defined(USE_WAYLAND)
345   typedef std::map<gfx::PluginWindowHandle, Ecore_Wl_Window*> PluginWindowToWidgetMap;
346 #else
347   typedef std::map<gfx::PluginWindowHandle, Ecore_X_Window> PluginWindowToWidgetMap;
348 #endif
349   PluginWindowToWidgetMap plugin_window_to_widget_map_;
350
351   bool magnifier_;
352
353   // Whether we are currently loading.
354   bool is_loading_;
355
356   scoped_refptr<EvasEventHandler> evas_event_handler_;
357
358   // YUV readback pipeline.
359   scoped_ptr<content::ReadbackYUVInterface>
360       yuv_readback_pipeline_;
361
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_;
366
367   // Stores the current state of the active pointers targeting this
368   // object.
369   ui::MotionEventAura pointer_state_;
370
371   // The gesture recognizer for this view.
372   // In Aura GestureRecognizer is global. Should we follow that?
373   scoped_ptr<ui::GestureRecognizer> gesture_recognizer_;
374
375   scoped_ptr<DisambiguationPopupEfl> disambiguation_popup_;
376   scoped_ptr<EdgeEffect> edge_effect_;
377
378   int current_orientation_;
379
380   Evas_GL* evas_gl_;
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_;
385
386   GLuint program_id_;
387   GLint source_texture_location_;
388   GLuint position_attrib_;
389   GLuint texcoord_attrib_;
390   void* egl_image_;
391   unsigned long current_pixmap_id_;
392   unsigned long next_pixmap_id_;
393   GLuint texture_id_;
394   int surface_id_;
395   gfx::Size surface_size_;
396   bool is_modifier_key_;
397   GLuint vertex_buffer_obj_;
398   GLuint index_buffer_obj_;
399
400   bool touch_events_enabled_;
401
402   // The last scroll offset of the view.
403   gfx::Vector2dF last_scroll_offset_;
404
405   gpu::Mailbox pending_mailbox_;
406
407   WebContents& web_contents_;
408
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_;
414
415   scoped_ptr<SelectionControllerEfl> selection_controller_;
416
417   DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEfl);
418 };
419
420 } // namespace content
421
422 #endif