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
9 #include <Ecore_Evas.h>
11 #include <Ecore_IMF_Evas.h>
13 #include "base/callback.h"
14 #include "base/format_macros.h"
15 #include "base/id_map.h"
16 #include "content/browser/compositor/evasgl_delegated_frame_host.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/renderer_host/event_resampler.h"
20 #include "content/browser/web_contents/web_contents_impl.h"
21 #include "content/browser/web_contents/web_contents_view_efl.h"
22 #include "content/common/content_export.h"
23 #include "content/public/common/browser_controls_state.h"
24 #include "cc/output/compositor_frame.h"
25 #include "cc/output/copy_output_request.h"
26 #include "cc/output/copy_output_result.h"
27 #include "cc/resources/single_release_callback.h"
28 #include "cc/resources/texture_mailbox.h"
29 #include "content/browser/accessibility/browser_accessibility_manager.h"
30 #include "content/browser/selection/selection_controller_efl.h"
31 #include "content/browser/swipe_to_refresh/swipe_to_refresh_controller.h"
32 #include "gpu/command_buffer/client/gles2_implementation_efl.h"
33 #include "ui/base/ime/composition_text.h"
34 #include "ui/base/ime/text_input_client.h"
35 #include "ui/events/gestures/gesture_types.h"
36 #include "ui/events/gestures/gesture_recognizer.h"
37 #include "ui/events/gestures/motion_event_aura.h"
38 #include "ipc/ipc_sender.h"
40 // Before, it was separated by EVAS_GL_API_VERSION and each value was;
41 // TV/DESKTOP = 1, MOBILE/WEARABLE = 4
43 // After Desktop build EFL upversion to 1.18,
44 // EVAS_GL_API_VERSION of DESKTOP is 5 and
45 // it would be more legible to seperate by profiles.
47 typedef EvasGLint64 GLint64;
48 typedef EvasGLuint64 GLuint64;
50 typedef struct __GLsync* GLsync;
51 typedef signed long GLint64;
52 typedef unsigned long GLuint64;
55 struct TextInputState;
60 class GestureProviderAura;
70 typedef void (*Screenshot_Captured_Callback)(Evas_Object* image, void* user_data);
71 typedef base::Closure SnapshotTask;
72 typedef base::Callback<void(int, int, const long&)> SetSmoothScrollCallBackType;
73 typedef base::Callback<bool(int*, int*)> GetScrollPositionCallbackType;
75 class DisambiguationPopupEfl;
78 class RenderWidgetHostImpl;
79 class RenderWidgetHostView;
81 class ScreenshotCapturedCallback;
83 #if defined(TIZEN_ATK_SUPPORT)
84 class BrowserAccessibilityDelegate;
85 class BrowserAccessibilityManager;
89 FRAME_STATUS_NONE = 0,
90 FRAME_STATUS_NEED_INVALIDATION = 1,
91 FRAME_STATUS_NEED_COMPOSITING = 1 << 1,
92 FRAME_STATUS_NEED_COMPOSITING_WHEN_SWAP = 1 << 2
95 typedef unsigned FrameStatusMask;
97 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
98 class CONTENT_EXPORT RenderWidgetHostViewEfl
99 : public RenderWidgetHostViewBase,
100 public EvasGLDelegatedFrameHostClient,
101 public EventResamplerClient,
102 public ui::GestureConsumer,
103 public ui::GestureEventHelper,
104 public base::SupportsWeakPtr<RenderWidgetHostViewEfl>,
107 explicit RenderWidgetHostViewEfl(RenderWidgetHost*, WebContents& web_contents);
109 // RenderWidgetHostViewBase implementation.
110 void InitAsChild(gfx::NativeView) override;
111 void InitAsPopup(content::RenderWidgetHostView*, const gfx::Rect&) override;
112 void InitAsFullscreen(content::RenderWidgetHostView*) override;
113 RenderWidgetHost* GetRenderWidgetHost() const override;
114 void SetSize(const gfx::Size&) override;
115 void SetBounds(const gfx::Rect&) override;
116 gfx::Vector2dF GetLastScrollOffset() const override;
117 gfx::NativeView GetNativeView() const override;
118 gfx::NativeViewAccessible GetNativeViewAccessible() override;
119 bool IsSurfaceAvailableForCopy() const override;
120 void Show() override;
121 void Hide() override;
122 bool IsShowing() override;
123 gfx::Rect GetViewBounds() const override;
124 gfx::Size GetPhysicalBackingSize() const override;
125 // Returns view size unless |custom_viewport_size_| is set.
126 gfx::Size GetVisibleViewportSize() const override;
127 bool LockMouse() override;
128 void UnlockMouse() override;
129 void Focus() override;
131 bool HasFocus() const override;
132 void UpdateCursor(const WebCursor&) override;
133 void SetIsLoading(bool) override;
134 bool DoBrowserControlsShrinkBlinkSize() const override;
135 float GetTopControlsHeight() const override;
136 float GetBottomControlsHeight() const override;
137 void TextInputStateChanged(const TextInputState& params) override;
138 void UpdateIMELayoutVariation(bool is_minimum_negative, bool is_step_integer);
139 void ImeCancelComposition() override;
140 void ImeCompositionRangeChanged(const gfx::Range&, const std::vector<gfx::Rect>&) override;
141 void FocusedNodeChanged(bool is_editable_node,
142 const gfx::Rect& node_bounds_in_screen
143 #if defined(OS_TIZEN_TV_PRODUCT)
145 bool is_radio_or_checkbox
149 void Destroy() override;
150 void SetTooltipText(const base::string16&) override;
151 void SelectionChanged(const base::string16&, size_t, const gfx::Range&) override;
152 void SelectionBoundsChanged(const ViewHostMsg_SelectionBounds_Params&) override;
153 void CopyFromCompositingSurface(
155 const gfx::Size& /* dst_size */,
156 const ReadbackRequestCallback&,
157 const SkColorType) override;
159 void CopyFromCompositingSurfaceToVideoFrame(
161 const scoped_refptr<media::VideoFrame>&,
162 const base::Callback<void(const gfx::Rect&, bool)>&) override;
164 bool CanCopyToVideoFrame() const override;
165 void BeginFrameSubscription(
166 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) override;
167 void EndFrameSubscription() override;
168 void SetNeedsBeginFrames(bool needs_begin_frames) override;
169 void DidOverscroll(const ui::DidOverscrollParams& params) override;
170 bool HasAcceleratedSurface(const gfx::Size&) override;
171 gfx::Rect GetBoundsInRootWindow() override;
172 void RenderProcessGone(base::TerminationStatus, int) override;
173 bool OnMessageReceived(const IPC::Message&) override;
175 void OnFilteredMessageReceived(const IPC::Message&);
177 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo&, InputEventAckState) override;
178 void DidStopFlinging() override;
180 void ShowDisambiguationPopup(const gfx::Rect& rect_pixels,
181 const SkBitmap& zoomed_bitmap) override;
182 void DisambiguationPopupDismissed();
183 void HandleDisambiguationPopupMouseDownEvent(Evas_Event_Mouse_Down*);
184 void HandleDisambiguationPopupMouseUpEvent(Evas_Event_Mouse_Up*);
185 void LockCompositingSurface() override;
186 void UnlockCompositingSurface() override;
188 void OnSwapCompositorFrame(uint32_t compositor_frame_sink_id,
189 cc::CompositorFrame frame) override;
191 void ClearCompositorFrame () override;
193 // ui::GestureEventHelper implementation.
194 bool CanDispatchToConsumer(ui::GestureConsumer* consumer) override;
195 void DispatchSyntheticTouchEvent(ui::TouchEvent* event) override;
196 void DispatchGestureEvent(GestureConsumer* raw_input_consumer,
197 ui::GestureEvent*) override;
199 #if defined(TIZEN_ATK_SUPPORT)
200 BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
201 BrowserAccessibilityDelegate*,
202 bool for_root_frame) override;
205 // IPC::Sender implementation:
206 bool Send(IPC::Message*) override;
208 void FilterInputMotion(const blink::WebGestureEvent& gesture_event);
210 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
211 void SelectClosestWord(const gfx::Point& touch_point);
212 void SetTileCoverAreaMultiplier(float cover_area_multiplier);
218 Evas_Object* ewk_view() const;
219 Evas_Object* smart_parent() const { return smart_parent_; }
220 Evas_Object* content_image() const { return content_image_; }
221 WebContents* web_contents() const { return &web_contents_; }
223 void set_magnifier(bool status);
225 void Init_EvasGL(int width, int height);
226 void ResizeCompositorLayer(int width, int height);
227 void CreateNativeSurface(int width, int height);
229 void SetEvasHandler(scoped_refptr<EvasEventHandler> evas_event_handler);
231 #if defined(OS_TIZEN_TV_PRODUCT)
232 void DidNavigateMainFrame();
233 void SetLayerInverted(bool inverted);
234 void OnDidInitializeRenderer();
237 void HandleGestureBegin();
238 void HandleGestureEnd();
239 void HandleGesture(ui::GestureEvent*);
240 void HandleGesture(blink::WebGestureEvent&);
241 void HandleTouchEvent(ui::TouchEvent*);
243 size_t visible_top_controls_height() const {
244 return visible_top_controls_height_;
247 Evas_GL_API* evasGlApi() { return evas_gl_api_; }
248 gfx::Point ConvertPointInViewPix(gfx::Point point);
249 gfx::Rect GetViewBoundsInPix() const;
250 void SetCustomViewportSize(const gfx::Size& size);
252 const gfx::Size GetScrollableSize() const;
253 void SetScaledContentSize(const gfx::Size& size) {
254 scaled_contents_size_ = size; }
256 void MoveCaret(const gfx::Point& point);
257 void SetComposition(const ui::CompositionText& composition_text);
258 void ConfirmComposition(base::string16& text);
259 void SendGestureEvent(blink::WebGestureEvent& event);
261 void SetTouchEventsEnabled(bool enabled);
263 void ScrollFocusedEditableNode();
265 bool HasSelectableText() const;
267 // Returns selected text with some additional characters surrounding it,
268 // both before and after selected text. If all text in a control is selected,
269 // returned value equals selected text.
270 const base::string16& SelectionTextWithSurroundingCharacters() const {
271 return selection_text_;
274 void SetClearTilesOnHide(bool enable);
275 // |snapshot_area| is relative coordinate system based on Webview.
276 // (0,0) is top left corner.
277 Evas_Object* GetSnapshot(const gfx::Rect& snapshot_area,
279 bool is_magnifier = false);
280 bool RequestSnapshotAsync(const gfx::Rect& snapshot_area,
281 Screenshot_Captured_Callback callback,
283 float scale_factor = 1.0);
284 void RequestMagnifierSnapshotAsync(const Eina_Rectangle rect,
285 Screenshot_Captured_Callback callback,
287 float scale_factor = 1.0f);
288 void SetGetCustomEmailViewportRectCallback(
289 const base::Callback<const gfx::Rect&(void)>& callback);
290 gfx::Rect GetCustomEmailViewportRect() const;
291 void SetScrollCallbacks(
292 const SetSmoothScrollCallBackType& set_smooth_scroll_callback,
293 const GetScrollPositionCallbackType& get_scroll_callback);
294 gfx::Point GetScrollPosition();
295 void SetSmoothScroll(const gfx::Point& offset, const long& duration);
296 void OnSnapshotDataReceived(SkBitmap bitmap, int snapshotId);
297 void OnSnapshotPainted(const SkBitmap& bitmap, int callback_id);
298 void OnEditableContentChanged();
299 #if defined(OS_TIZEN)
300 void OnEdgeEffectONSCROLLTizenUIF(bool, bool, bool, bool);
303 void CopyOutputCallback(int request_id,
304 std::unique_ptr<cc::CopyOutputResult> result);
308 bool MakeCurrent() override;
311 void SetTopControlsHeight(size_t top_height, size_t bottom_height);
312 bool SetTopControlsState(BrowserControlsState constraint,
313 BrowserControlsState current,
315 bool TopControlsAnimationScheduled();
316 void ResizeIfNeededByTopControls();
317 void TopControlsOffsetChanged();
319 int GetVisibleBottomControlsHeightInPix() const;
321 SelectionControllerEfl* GetSelectionController() const {
322 return selection_controller_.get();
325 unsigned PointerStatePointerCount() const {
326 return pointer_state_.GetPointerCount();
329 // Sets rotation degrees. Expected values are one of { 0, 90, 180, 270 }.
330 void UpdateRotationDegrees(int rotation_degrees);
332 // EvasGLDelegatedFrameHostClient implementation.
333 Evas_GL_API* GetEvasGLAPI() override;
334 void DelegatedFrameHostSendReclaimCompositorResources(
335 int compositor_frame_sink_id,
337 const cc::ReturnedResourceArray& resources) override;
338 int DelegatedFrameHostGetGpuMemoryBufferClientId() const override;
339 Evas_GL* GetEvasGL() override;
341 void ClearBrowserFrame(SkColor) override;
343 void DidMoveWebView();
345 // EventResamplerClient implementation.
346 void ForwardTouchEvent(ui::TouchEvent*) override;
347 void ForwardGestureEvent(const blink::WebGestureEvent&) override;
348 void OnAnimatorCallback() override;
349 unsigned TouchPointCount() const override;
351 template <typename EVT>
352 void ConvertEnterToSpaceIfNeeded(EVT* evt);
354 void SetIMERecommendedWords(const std::string& recommended_words);
355 void SetIMERecommendedWordsType(bool should_enable);
356 #if defined(OS_TIZEN_TV_PRODUCT)
357 void ClearAllTilesResources();
358 void SendKeyEvent(Evas_Object* ewk_view, void* event_info, bool is_press);
359 void SetCursorByClient(bool enable) { cursor_set_by_client_ = enable; }
360 void SetKeyEventsEnabled(bool enabled);
361 void SetMouseEventCallbacks(
362 const base::Callback<void(int, int)>& on_mouse_down,
363 const base::Callback<bool(void)>& on_mouse_up,
364 const base::Callback<void(void)>& on_mouse_move);
367 #if defined(TIZEN_VIDEO_HOLE)
368 void SetWebViewMovedCallback(const base::Closure& on_webview_moved);
370 IMContextEfl* GetIMContext() const { return im_context_; }
371 Evas_Object* content_image_elm_host() const {
372 return content_image_elm_host_;
375 void SetFocusInOutCallbacks(const base::Callback<void(void)>& on_focus_in,
376 const base::Callback<void(void)>& on_focus_out);
378 void RequestSelectionRect() const;
379 void OnSelectionRectReceived(const gfx::Rect& selection_rect) const;
380 bool IsFocusedNodeEditable() const { return is_focused_node_editable_; }
381 void UpdateSpatialNavigationStatus(bool enable);
382 void UpdateHwKeyboardStatus(bool status) {
383 is_hw_keyboard_connected_ = status;
385 bool IsTouchstartConsumed() const { return touchstart_consumed_; }
386 bool IsTouchendConsumed() const { return touchend_consumed_; }
388 void InitSwipeToRefreshController();
389 void ResetSwipeToRefreshController();
390 bool IsTopControlFullyVisible() const;
391 const gfx::Vector2dF& last_scroll_offset() const {
392 return last_scroll_offset_;
396 friend class RenderWidgetHostView;
399 ~RenderWidgetHostViewEfl() override;
401 void EnsureDeviceDisplayInfoInitialized();
402 gfx::NativeViewId GetNativeViewId() const;
404 static void OnParentViewResize(void* data, Evas*, Evas_Object*, void*);
405 static void OnMove(void* data, Evas*, Evas_Object*, void*);
406 static void OnFocusIn(void* data, Evas*, Evas_Object*, void*);
407 static void OnFocusOut(void* data, Evas*, Evas_Object*, void*);
408 static void OnHostFocusIn(void* data, Evas_Object*, void*);
409 static void OnHostFocusOut(void* data, Evas_Object*, void*);
411 static void OnMotionEnable(void* data, Evas_Object*, void*);
412 static void OnMotionMove(void* data, Evas_Object*, void*);
413 static void OnMotionZoom(void* data, Evas_Object*, void*);
415 static void OnMultiTouchDownEvent(void* data, Evas*, Evas_Object*, void*);
416 static void OnMultiTouchMoveEvent(void* data, Evas*, Evas_Object*, void*);
417 static void OnMultiTouchUpEvent(void* data, Evas*, Evas_Object*, void*);
419 static void OnMouseDown(void* data, Evas*, Evas_Object*, void*);
420 static void OnMouseUp(void* data, Evas*, Evas_Object*, void*);
421 static void OnMouseMove(void* data, Evas*, Evas_Object*, void*);
422 static void OnMouseOut(void* data, Evas*, Evas_Object*, void*);
423 static void OnMouseWheel(void* data, Evas*, Evas_Object*, void*);
424 static void OnKeyDown(void*, Evas*, Evas_Object*, void*);
425 static void OnKeyUp(void*, Evas*, Evas_Object*, void*);
427 void ProcessTouchEvents(unsigned int timestamp, bool is_multi_touch = false);
429 ui::GestureProviderAura* GetGestureProvider();
430 void SetDoubleTapSupportForPageEnabled(bool enabled);
431 void SetDoubleTapSupportForPlatformEnabled(bool enabled);
433 void OnOrientationChangeEvent(int);
434 void OnDidHandleKeyEvent(const blink::WebInputEvent* input_event, bool processed);
435 bool IsIMEShow() const;
437 // With immediate = true, it calls evas_render().
438 void Invalidate(bool immediate);
439 // TODO(prashant.n): Implement delegate to handle multiple frame_hosts.
440 void SwapBrowserFrame(uint32_t output_surface_id, cc::CompositorFrame frame);
441 void RenderBrowserFrame();
442 void RunGetSnapshotOnMainThread(const gfx::Rect snapshot_area,
445 static void EvasObjectImagePixelsGetCallback(void*, Evas_Object*);
446 void ProcessSnapshotRequest();
447 void GetMagnifierSnapshot(gfx::Rect snapshot_area,
449 std::unique_ptr<ScreenshotCapturedCallback> cb);
451 EdgeEffect& EnsureEdgeEffect();
452 void UpdateEdgeEffect();
454 #if defined(USE_WAYLAND)
455 Ecore_Wl_Window* GetEcoreWlWindow() const;
457 Ecore_X_Window GetEcoreXWindow() const;
460 base::Callback<void(void)> on_focus_in_callback_;
461 base::Callback<void(void)> on_focus_out_callback_;
462 #if defined(OS_TIZEN_TV_PRODUCT)
463 base::Callback<void(int, int)> on_mouse_down_callback_;
464 base::Callback<bool(void)> on_mouse_up_callback_;
465 base::Callback<void(void)> on_mouse_move_callback_;
467 base::Callback<const gfx::Rect&(void)>
468 get_custom_email_viewport_rect_callback_;
469 GetScrollPositionCallbackType get_scroll_callback_;
470 SetSmoothScrollCallBackType set_smooth_scroll_callback_;
472 #if defined(TIZEN_VIDEO_HOLE)
473 base::Closure on_webview_moved_callback_;
475 RenderWidgetHostImpl* host_;
476 std::unique_ptr<EvasGLDelegatedFrameHost> evasgl_delegated_frame_host_;
477 IMContextEfl* im_context_;
479 Evas_Object* main_layout_;
480 Evas_Object* smart_parent_;
481 Evas_Object* content_image_;
482 Evas_Object* content_image_elm_host_;
483 bool evas_gl_initialized_;
484 float device_scale_factor_;
488 // Whether we are currently loading.
491 // If set, it's usually smaller than the view size not to allow top Elm widgets
492 // (select picker) to overlap web content.
493 gfx::Size custom_viewport_size_;
495 scoped_refptr<EvasEventHandler> evas_event_handler_;
497 // Stores the current state of the active pointers targeting this
499 ui::MotionEventAura pointer_state_;
501 // The gesture recognizer for this view.
502 // In Aura GestureRecognizer is global. Should we follow that?
503 std::unique_ptr<ui::GestureRecognizer> gesture_recognizer_;
505 std::unique_ptr<DisambiguationPopupEfl> disambiguation_popup_;
506 std::unique_ptr<EdgeEffect> edge_effect_;
508 gfx::Size scaled_contents_size_;
510 int current_orientation_;
513 Evas_GL_API* evas_gl_api_;
514 Evas_GL_Config* evas_gl_config_;
515 Evas_GL_Context* evas_gl_context_;
516 Evas_GL_Surface* evas_gl_surface_;
518 bool handling_disambiguation_popup_gesture_;
519 bool touch_events_enabled_;
521 bool radio_or_checkbox_focused_;
523 int frame_data_output_rect_width_;
524 bool was_keydown_filtered_by_platform_;
526 bool was_return_keydown_filtered_by_platform_;
527 #if defined(OS_TIZEN_TV_PRODUCT)
528 // When WebBrowser sets their own cursor, set the flag
529 // not to set the WebPage cursor
530 bool cursor_set_by_client_;
531 bool layer_inverted_;
532 bool renderer_initialized_;
535 // The last scroll offset of the view.
536 gfx::Vector2dF last_scroll_offset_;
538 WebContents& web_contents_;
540 int top_controls_height_;
541 int visible_top_controls_height_;
542 int visible_top_controls_height_in_pix_;
543 int top_controls_offset_correction_;
545 int bottom_controls_height_;
546 int visible_bottom_controls_height_;
547 int visible_bottom_controls_height_in_pix_;
549 int last_resized_visible_top_controls_height_;
550 float top_controls_shown_ratio_;
552 int touch_start_top_controls_offset_;
553 bool defer_showing_selection_controls_;
555 bool touchstart_consumed_;
556 bool touchend_consumed_;
557 bool is_scrolling_needed_;
559 FrameStatusMask frame_status_;
561 std::list<SnapshotTask> snapshot_task_list_;
562 // Magnifier snapshot requests are not added to snapshot_task_list_, because
563 // we only care about the last one if they piled up - we can only display
565 SnapshotTask magnifier_snapshot_request_;
567 IDMap<ScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
569 std::unique_ptr<SelectionControllerEfl> selection_controller_;
571 std::unique_ptr<EventResampler> event_resampler_;
573 std::unique_ptr<base::OneShotTimer> snapshot_timer_;
574 std::unique_ptr<SwipeToRefreshController> swipe_to_refresh_controller_;
575 base::Closure process_snapshot_request_callback_;
577 bool is_focused_node_editable_;
578 bool is_hw_keyboard_connected_;
580 base::WeakPtrFactory<RenderWidgetHostViewEfl> weak_factory_;
582 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEfl);
585 } // namespace content