- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / render_widget_host_view_guest.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_RENDER_WIDGET_HOST_VIEW_GUEST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_
7
8 #include <vector>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "content/browser/renderer_host/render_widget_host_view_base.h"
12 #include "content/common/content_export.h"
13 #include "ui/events/event.h"
14 #include "ui/events/gestures/gesture_recognizer.h"
15 #include "ui/events/gestures/gesture_types.h"
16 #include "ui/gfx/native_widget_types.h"
17 #include "ui/gfx/rect.h"
18 #include "ui/gfx/vector2d_f.h"
19 #include "webkit/common/cursors/webcursor.h"
20
21 #if defined(TOOLKIT_GTK)
22 #include "content/browser/renderer_host/gtk_plugin_container_manager.h"
23 #endif  // defined(TOOLKIT_GTK)
24
25 namespace content {
26 class RenderWidgetHost;
27 class RenderWidgetHostImpl;
28 class BrowserPluginGuest;
29 struct NativeWebKeyboardEvent;
30
31 // -----------------------------------------------------------------------------
32 // See comments in render_widget_host_view.h about this class and its members.
33 // This version is for the webview plugin which handles a lot of the
34 // functionality in a diffent place and isn't platform specific.
35 //
36 // Some elements that are platform specific will be deal with by delegating
37 // the relevant calls to the platform view.
38 // -----------------------------------------------------------------------------
39 class CONTENT_EXPORT RenderWidgetHostViewGuest
40     : public RenderWidgetHostViewBase,
41       public ui::GestureConsumer,
42       public ui::GestureEventHelper {
43  public:
44   RenderWidgetHostViewGuest(RenderWidgetHost* widget,
45                             BrowserPluginGuest* guest,
46                             RenderWidgetHostView* platform_view);
47   virtual ~RenderWidgetHostViewGuest();
48
49   // RenderWidgetHostView implementation.
50   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
51   virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
52   virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
53   virtual void SetSize(const gfx::Size& size) OVERRIDE;
54   virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
55   virtual gfx::NativeView GetNativeView() const OVERRIDE;
56   virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
57   virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
58   virtual bool HasFocus() const OVERRIDE;
59   virtual bool IsSurfaceAvailableForCopy() const OVERRIDE;
60   virtual void Show() OVERRIDE;
61   virtual void Hide() OVERRIDE;
62   virtual bool IsShowing() OVERRIDE;
63   virtual gfx::Rect GetViewBounds() const OVERRIDE;
64   virtual void SetBackground(const SkBitmap& background) OVERRIDE;
65 #if defined(OS_WIN) && !defined(USE_AURA)
66   virtual void SetClickthroughRegion(SkRegion* region) OVERRIDE;
67 #endif
68
69   // RenderWidgetHostViewPort implementation.
70   virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
71                            const gfx::Rect& pos) OVERRIDE;
72   virtual void InitAsFullscreen(
73       RenderWidgetHostView* reference_host_view) OVERRIDE;
74   virtual void WasShown() OVERRIDE;
75   virtual void WasHidden() OVERRIDE;
76   virtual void MovePluginWindows(
77       const gfx::Vector2d& scroll_offset,
78       const std::vector<WebPluginGeometry>& moves) OVERRIDE;
79   virtual void Focus() OVERRIDE;
80   virtual void Blur() OVERRIDE;
81   virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
82   virtual void SetIsLoading(bool is_loading) OVERRIDE;
83   virtual void TextInputTypeChanged(ui::TextInputType type,
84                                     ui::TextInputMode input_mode,
85                                     bool can_compose_inline) OVERRIDE;
86   virtual void ImeCancelComposition() OVERRIDE;
87 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
88   virtual void ImeCompositionRangeChanged(
89       const gfx::Range& range,
90       const std::vector<gfx::Rect>& character_bounds) OVERRIDE;
91 #endif
92   virtual void DidUpdateBackingStore(
93       const gfx::Rect& scroll_rect,
94       const gfx::Vector2d& scroll_delta,
95       const std::vector<gfx::Rect>& copy_rects,
96       const ui::LatencyInfo& latency_info) OVERRIDE;
97   virtual void RenderProcessGone(base::TerminationStatus status,
98                                  int error_code) OVERRIDE;
99   virtual void Destroy() OVERRIDE;
100   virtual void WillDestroyRenderWidget(RenderWidgetHost* rwh) {}
101   virtual void SetTooltipText(const string16& tooltip_text) OVERRIDE;
102   virtual void SelectionChanged(const string16& text,
103                                 size_t offset,
104                                 const gfx::Range& range) OVERRIDE;
105   virtual void SelectionBoundsChanged(
106       const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
107   virtual void ScrollOffsetChanged() OVERRIDE;
108   virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
109   virtual void CopyFromCompositingSurface(
110       const gfx::Rect& src_subrect,
111       const gfx::Size& dst_size,
112       const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE;
113   virtual void CopyFromCompositingSurfaceToVideoFrame(
114       const gfx::Rect& src_subrect,
115       const scoped_refptr<media::VideoFrame>& target,
116       const base::Callback<void(bool)>& callback) OVERRIDE;
117   virtual bool CanCopyToVideoFrame() const OVERRIDE;
118   virtual void OnAcceleratedCompositingStateChange() OVERRIDE;
119   virtual void AcceleratedSurfaceBuffersSwapped(
120       const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
121       int gpu_host_id) OVERRIDE;
122   virtual void AcceleratedSurfacePostSubBuffer(
123       const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
124       int gpu_host_id) OVERRIDE;
125   virtual void OnSwapCompositorFrame(
126       uint32 output_surface_id,
127       scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
128   virtual void AcceleratedSurfaceSuspend() OVERRIDE;
129   virtual void AcceleratedSurfaceRelease() OVERRIDE;
130   virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE;
131   virtual void SetHasHorizontalScrollbar(
132       bool has_horizontal_scrollbar) OVERRIDE;
133   virtual void SetScrollOffsetPinning(
134       bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE;
135   virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE;
136   virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE;
137 #if defined(OS_WIN) || defined(USE_AURA)
138   virtual void ProcessAckedTouchEvent(
139       const TouchEventWithLatencyInfo& touch,
140       InputEventAckState ack_result) OVERRIDE;
141 #endif  // defined(OS_WIN) || defined(USE_AURA)
142   virtual bool LockMouse() OVERRIDE;
143   virtual void UnlockMouse() OVERRIDE;
144   virtual void GetScreenInfo(WebKit::WebScreenInfo* results) OVERRIDE;
145   virtual void OnAccessibilityEvents(
146       const std::vector<AccessibilityHostMsg_EventParams>&
147           params) OVERRIDE;
148
149 #if defined(OS_MACOSX)
150   // RenderWidgetHostView implementation.
151   virtual void SetActive(bool active) OVERRIDE;
152   virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE;
153   virtual void SetWindowVisibility(bool visible) OVERRIDE;
154   virtual void WindowFrameChanged() OVERRIDE;
155   virtual void ShowDefinitionForSelection() OVERRIDE;
156   virtual bool SupportsSpeech() const OVERRIDE;
157   virtual void SpeakSelection() OVERRIDE;
158   virtual bool IsSpeaking() const OVERRIDE;
159   virtual void StopSpeaking() OVERRIDE;
160
161   // RenderWidgetHostViewPort implementation.
162   virtual void AboutToWaitForBackingStoreMsg() OVERRIDE;
163   virtual bool PostProcessEventForPluginIme(
164       const NativeWebKeyboardEvent& event) OVERRIDE;
165 #endif  // defined(OS_MACOSX)
166
167 #if defined(OS_ANDROID)
168   // RenderWidgetHostViewPort implementation.
169   virtual void ShowDisambiguationPopup(const gfx::Rect& target_rect,
170                                        const SkBitmap& zoomed_bitmap) OVERRIDE;
171   virtual void HasTouchEventHandlers(bool need_touch_events) OVERRIDE;
172 #endif  // defined(OS_ANDROID)
173
174 #if defined(TOOLKIT_GTK)
175   virtual GdkEventButton* GetLastMouseDown() OVERRIDE;
176   virtual gfx::NativeView BuildInputMethodsGtkMenu() OVERRIDE;
177 #endif  // defined(TOOLKIT_GTK)
178
179 #if defined(OS_WIN) && !defined(USE_AURA)
180   virtual void WillWmDestroy() OVERRIDE;
181 #endif  // defined(OS_WIN) && !defined(USE_AURA)
182
183 #if defined(OS_WIN) && defined(USE_AURA)
184   virtual void SetParentNativeViewAccessible(
185       gfx::NativeViewAccessible accessible_parent) OVERRIDE;
186 #endif
187
188   // Overridden from ui::GestureEventHelper.
189   virtual bool CanDispatchToConsumer(ui::GestureConsumer* consumer) OVERRIDE;
190   virtual void DispatchPostponedGestureEvent(ui::GestureEvent* event) OVERRIDE;
191   virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE;
192
193  protected:
194   friend class RenderWidgetHostView;
195
196  private:
197   // Destroys this view without calling |Destroy| on |platform_view_|.
198   void DestroyGuestView();
199
200   // Builds and forwards a WebKitGestureEvent to the renderer.
201   bool ForwardGestureEventToRenderer(ui::GestureEvent* gesture);
202
203   // Process all of the given gestures (passes them on to renderer)
204   void ProcessGestures(ui::GestureRecognizer::Gestures* gestures);
205
206   // The model object.
207   RenderWidgetHostImpl* host_;
208
209   BrowserPluginGuest *guest_;
210   gfx::Size size_;
211   // The platform view for this RenderWidgetHostView.
212   // RenderWidgetHostViewGuest mostly only cares about stuff related to
213   // compositing, the rest are directly forwared to this |platform_view_|.
214   RenderWidgetHostViewPort* platform_view_;
215 #if defined(OS_WIN) || defined(USE_AURA)
216   scoped_ptr<ui::GestureRecognizer> gesture_recognizer_;
217 #endif  // defined(OS_WIN) || defined(USE_AURA)
218   DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuest);
219 };
220
221 }  // namespace content
222
223 #endif  // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_