c6be69c4680609b8dff720ad6e04d4762126ad97
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / content / browser / renderer_host / rwhv_aura_offscreen_helper_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 CONTENT_BROWSER_RENDERER_HOST_RWHV_AURA_OFFSCREEN_HELPER_EFL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RWHV_AURA_OFFSCREEN_HELPER_EFL_H_
7
8 #include <list>
9
10 #include <Evas_GL.h>
11
12 #include <Ecore.h>
13 #include <Ecore_Evas.h>
14 #include <Ecore_Input.h>
15 #include <Elementary.h>
16
17 #include "base/timer/timer.h"
18 #include "content/browser/renderer_host/rwhv_aura_common_helper_efl.h"
19 #include "ui/gfx/native_widget_types.h"
20
21 namespace content {
22
23 typedef base::OnceCallback<void()> SnapshotTask;
24
25 class ScreenshotCapturedCallback;
26 class EdgeEffect;
27
28 class CONTENT_EXPORT RWHVAuraOffscreenHelperEfl
29     : public RWHVAuraCommonHelperEfl {
30  public:
31
32   using OnFocusCallback = base::RepeatingCallback<void(void)>;
33
34   RWHVAuraOffscreenHelperEfl(RenderWidgetHostViewAura* rwhva,
35                              WebContents* web_contents);
36   ~RWHVAuraOffscreenHelperEfl() override;
37
38   // RWHVAuraCommonHelperEfl overrides
39   void SetAuraParentWindow(gfx::NativeView parent_window) override {
40     aura_parent_window_ = parent_window;
41   }
42   void AuraChildWindowAdded() override;
43   void NotifySwap(const size_t texture_id) override;
44   void Show() override;
45   void Hide() override;
46   gfx::Size GetVisibleViewportSize() override;
47   gfx::Rect GetViewBounds() override;
48   gfx::Size GetPhysicalBackingSize() const override;
49   void HandleGestureBegin() override;
50   void HandleGestureEnd() override;
51   void HandleGesture(blink::WebGestureEvent& event) override;
52   void DidOverscroll(const ui::DidOverscrollParams& params) override;
53   void Focus(bool focus) override;
54   bool HasFocus() override;
55
56   void SetCustomViewportSize(const gfx::Size& size);
57   bool GetHorizontalPanningHold() const { return horizontal_panning_hold_; }
58   void SetHorizontalPanningHold(bool hold) { horizontal_panning_hold_ = hold; }
59   bool GetVerticalPanningHold() const { return vertical_panning_hold_; }
60   void SetVerticalPanningHold(bool hold) { vertical_panning_hold_ = hold; }
61
62 #if BUILDFLAG(IS_TIZEN_TV)
63   void DrawLabel(Evas_Object* image, Eina_Rectangle rect);
64   void ClearLabels();
65 #endif
66
67   gfx::Rect GetViewBoundsInPix() const;
68   const gfx::Size GetScrollableSize() const;
69   void SetScaledContentSize(const gfx::SizeF& size) {
70     scaled_contents_size_ = size;
71   }
72   int GetTopControlsHeight();
73
74 #if BUILDFLAG(IS_TIZEN)
75   void OnEdgeEffectForUIF(bool, bool, bool, bool);
76 #endif
77
78   // |snapshot_area| is relative coordinate system based on Webview.
79   // (0,0) is top left corner.
80   Evas_Object* GetSnapshot(const gfx::Rect& snapshot_area,
81                            float scale_factor,
82                            bool is_magnifier = false);
83   void RequestSnapshotAsync(const gfx::Rect& snapshot_area,
84                             Screenshot_Captured_Callback callback,
85                             void* user_data,
86                             float scale_factor = 1.0);
87
88   EdgeEffect& EnsureEdgeEffect();
89   void UpdateEdgeEffect();
90   void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
91
92   Evas_Object* content_image() const { return content_image_; }
93   Evas_Object* content_image_elm_host() const {
94     return content_image_elm_host_;
95   }
96   gfx::Point ConvertPointInViewPix(gfx::Point point);
97
98   void SetFocusInOutCallbacks(const OnFocusCallback& on_focus_in,
99                               const OnFocusCallback& on_focus_out);
100   void MoveCaret(const gfx::Point& point);
101   void SelectClosestWord(const gfx::Point& touch_point);
102   void RequestMagnifierSnapshotAsync(const Eina_Rectangle rect,
103                                      Screenshot_Captured_Callback callback,
104                                      void* user_data,
105                                      float scale_factor = 1.0f);
106
107  private:
108   static void OnParentViewResize(void* data, Evas*, Evas_Object*, void*);
109   static void EvasObjectImagePixelsGetCallback(void*, Evas_Object*);
110   static void OnFocusIn(void* data, Evas*, Evas_Object*, void*);
111   static void OnFocusOut(void* data, Evas*, Evas_Object*, void*);
112   static void OnHostFocusIn(void* data, Evas_Object*, void*);
113   static void OnHostFocusOut(void* data, Evas_Object*, void*);
114   static void OnEvasRenderFlushPre(void* data, Evas* evas, void* event_info);
115
116   void Initialize();
117   void InitializeProgram();
118   void PaintTextureToSurface(GLuint texture_id);
119
120   void InitEvasGL();
121   gfx::Size CreateNativeSurface();
122   bool ClearCurrent();
123   bool MakeCurrent();
124   void ClearBrowserFrame();
125
126   void InvalidateForSnapshot();
127   void ProcessSnapshotRequest();
128   void RunGetSnapshotOnMainThread(const gfx::Rect snapshot_area,
129                                   int request_id,
130                                   float scale_factor);
131   void GetMagnifierSnapshot(gfx::Rect snapshot_area,
132                             float scale_factor,
133                             std::unique_ptr<ScreenshotCapturedCallback> cb);
134
135   Evas* evas_ = nullptr;
136   Evas_GL* evas_gl_ = nullptr;
137   Evas_GL_API* evas_gl_api_ = nullptr;
138   Evas_GL_Config* evas_gl_config_ = nullptr;
139   Evas_GL_Context* evas_gl_context_ = nullptr;
140   Evas_GL_Surface* evas_gl_surface_ = nullptr;
141   Evas_Object* content_image_ = nullptr;
142   Evas_Object* efl_main_layout_ = nullptr;
143   Evas_Object* content_image_elm_host_ = nullptr;
144
145   GLuint program_id_;
146   GLint source_texture_location_;
147   GLuint position_attrib_;
148   GLuint rotate_position_attrib_;
149   GLuint texcoord_attrib_;
150   GLuint texture_id_ = 0;
151   GLuint vertex_buffer_obj_;
152   GLuint index_buffer_obj_;
153   gfx::NativeView aura_parent_window_ = nullptr;
154
155   int rotation_ = 0;
156   gfx::SizeF scaled_contents_size_;
157   gfx::Size custom_viewport_size_;
158
159 #if BUILDFLAG(IS_TIZEN_TV)
160   bool radio_or_checkbox_focused_ = false;
161   int password_input_minlength_ = -1;
162   int input_maxlength_ = DEFAULT_MAX_LENGTH;
163   std::vector<Evas_Object*> voice_manager_labels_;
164 #endif
165
166   std::unique_ptr<RenderWidgetHostHelper> rwh_helper_;
167
168   bool frame_rendered_ = false;
169   std::list<SnapshotTask> snapshot_task_list_;
170   std::unique_ptr<base::OneShotTimer> snapshot_timer_;
171
172   bool horizontal_panning_hold_ = false;
173   bool vertical_panning_hold_ = false;
174
175   OnFocusCallback on_focus_in_callback_;
176   OnFocusCallback on_focus_out_callback_;
177
178   std::unique_ptr<EdgeEffect> edge_effect_;
179   // Magnifier snapshot requests are not added to snapshot_task_list_, because
180   // we only care about the last one if they piled up - we can only display
181   // one anyway.
182   SnapshotTask magnifier_snapshot_request_;
183 };
184
185 }  // namespace content
186
187 #endif