[M67 Dev][Tizen] Replace display specific API with public API
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / content / browser / renderer_host / render_widget_host_view_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 RENDER_WIDGET_HOST_VIEW_EFL
6 #define RENDER_WIDGET_HOST_VIEW_EFL
7
8 #include <Ecore_Evas.h>
9 #include <Ecore_IMF_Evas.h>
10 #include <Evas.h>
11 #include <Evas_GL.h>
12
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"
33
34 // Before, it was separated by EVAS_GL_API_VERSION and each value was;
35 // TV/DESKTOP = 1, MOBILE/WEARABLE = 4
36
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.
40 #if defined(OS_TIZEN)
41 typedef EvasGLint64 GLint64;
42 typedef EvasGLuint64 GLuint64;
43 #else
44 typedef struct __GLsync* GLsync;
45 typedef signed long GLint64;
46 typedef unsigned long GLuint64;
47 #endif
48
49 struct TextInputState;
50
51 namespace ui {
52 class GestureEvent;
53 class TouchEvent;
54 struct DidOverscrollParams;
55 }  // namespace ui
56
57 namespace blink {
58 struct WebScreenInfo;
59 }
60
61 namespace content {
62
63 typedef void (*Screenshot_Captured_Callback)(Evas_Object* image,
64                                              void* user_data);
65
66 class DisambiguationPopupEfl;
67 class EdgeEffect;
68 class IMContextEfl;
69 class RenderWidgetHostImpl;
70 class RenderWidgetHostView;
71 class WebContents;
72 class ScreenshotCapturedCallback;
73
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>,
81       public IPC::Sender {
82  public:
83   explicit RenderWidgetHostViewEfl(RenderWidgetHost*,
84                                    WebContents& web_contents);
85
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;
95   void Show() override;
96   void Hide() 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;
110
111   void UpdateBackgroundColorFromRenderer(SkColor color);
112
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);
120 #endif
121
122   void OnTextInputInFormStateChanged(bool is_in_form_tag);
123
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;
129
130   void Destroy() override;
131   void SetTooltipText(const base::string16&) override;
132   void SelectionChanged(const base::string16&,
133                         size_t,
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;
143
144   void OnFilteredMessageReceived(const IPC::Message&);
145
146   void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo&,
147                               InputEventAckState) override;
148   void DidStopFlinging() override;
149
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*);
155
156   void DidCreateNewRendererCompositorFrameSink(
157       viz::mojom::CompositorFrameSinkClient* renderer_compositor_frame_sink)
158       override;
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;
164
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;
170
171   // IPC::Sender implementation:
172   bool Send(IPC::Message*) override;
173
174   void FilterInputMotion(const blink::WebGestureEvent& gesture_event);
175
176   void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
177   void SelectClosestWord(const gfx::Point& touch_point);
178
179   Evas* evas() const {
180     DCHECK(evas_);
181     return evas_;
182   }
183
184   Evas_Object* smart_parent() const { return smart_parent_; }
185
186   void set_magnifier(bool status);
187
188   void Init_EvasGL(int width, int height);
189   void CreateNativeSurface(int width, int height);
190
191   void SetEvasHandler(scoped_refptr<EvasEventHandler> evas_event_handler);
192
193   void HandleGestureBegin();
194   void HandleGestureEnd();
195   void HandleGesture(ui::GestureEvent*);
196   void HandleGesture(blink::WebGestureEvent&);
197   void HandleTouchEvent(ui::TouchEvent*);
198
199   Evas_GL_API* evasGlApi() { return evas_gl_api_; }
200   gfx::Point ConvertPointInViewPix(gfx::Point point);
201   gfx::Rect GetViewBoundsInPix() const;
202
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);
207
208   void SetTouchEventsEnabled(bool enabled);
209
210   void ScrollFocusedEditableNode();
211
212   bool IsLastAvailableTextEmpty() const;
213
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,
219                             void* user_data);
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);
224 #endif
225   bool MakeCurrent();
226   bool ClearCurrent();
227
228   SelectionControllerEfl* GetSelectionController() const {
229     return selection_controller_.get();
230   }
231
232   unsigned PointerStatePointerCount() const {
233     return pointer_state_.GetPointerCount();
234   }
235
236   // Sets rotation degrees. Expected values are one of { 0, 90, 180, 270 }.
237   void UpdateRotationDegrees(int rotation_degrees);
238
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;
245
246  private:
247   ~RenderWidgetHostViewEfl() override;
248
249   void InitializeDeviceDisplayInfo();
250   gfx::NativeViewId GetNativeViewId() const;
251
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*);
257
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*);
261
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*);
265
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*);
274 #endif
275
276   void ProcessTouchEvents(unsigned int timestamp);
277   void SetDoubleTapSupportEnabled(bool enabled);
278
279   void OnOrientationChangeEvent(int);
280   void OnDidHandleKeyEvent(const blink::WebInputEvent* input_event,
281                            bool processed);
282
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*);
291
292   EdgeEffect& EnsureEdgeEffect();
293
294 #if defined(USE_WAYLAND)
295   Ecore_Wl_Window* GetEcoreWlWindow() const;
296 #else
297   Ecore_X_Window GetEcoreXWindow() const;
298 #endif
299
300   std::unique_ptr<EvasGLDelegatedFrameHost> evasgl_delegated_frame_host_;
301   IMContextEfl* im_context_;
302   Evas* evas_;
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_;
309
310   bool magnifier_;
311
312   // Whether we are currently loading.
313   bool is_loading_;
314
315   scoped_refptr<EvasEventHandler> evas_event_handler_;
316
317   // Stores the current state of the active pointers targeting this
318   // object.
319   ui::MotionEventAura pointer_state_;
320
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_;
324
325   std::unique_ptr<DisambiguationPopupEfl> disambiguation_popup_;
326   std::unique_ptr<EdgeEffect> edge_effect_;
327
328   int current_orientation_;
329
330   Evas_GL* evas_gl_;
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_;
335
336   bool handling_disambiguation_popup_gesture_;
337   bool touch_events_enabled_;
338   // The background color of the web content.
339   SkColor background_color_;
340
341   // The last scroll offset of the view.
342   gfx::Vector2dF last_scroll_offset_;
343
344   WebContents& web_contents_;
345
346   base::IDMap<std::unique_ptr<ScreenshotCapturedCallback>>
347       screen_capture_cb_map_;
348
349   std::unique_ptr<SelectionControllerEfl> selection_controller_;
350
351   viz::mojom::CompositorFrameSinkClient* renderer_compositor_frame_sink_ =
352       nullptr;
353
354   base::WeakPtrFactory<RenderWidgetHostViewEfl> weak_factory_;
355
356   DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEfl);
357 };
358
359 }  // namespace content
360
361 #endif