c807f9ecd677a64d3581def91b3e98a50ddf572e
[platform/framework/web/crosswalk.git] / src / content / browser / frame_host / render_widget_host_view_guest.h
1 // Copyright 2014 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_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_
7
8 #include <vector>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
12 #include "content/common/content_export.h"
13 #include "content/common/cursors/webcursor.h"
14 #include "ui/events/event.h"
15 #include "ui/events/gestures/gesture_recognizer.h"
16 #include "ui/events/gestures/gesture_types.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/gfx/rect.h"
19 #include "ui/gfx/vector2d_f.h"
20
21 struct ViewHostMsg_TextInputState_Params;
22
23 namespace content {
24 class BrowserPluginGuest;
25 class RenderWidgetHost;
26 class RenderWidgetHostImpl;
27 struct NativeWebKeyboardEvent;
28
29 // See comments in render_widget_host_view.h about this class and its members.
30 // This version is for the BrowserPlugin which handles a lot of the
31 // functionality in a diffent place and isn't platform specific.
32 // The BrowserPlugin is currently a special case for out-of-process rendered
33 // content and therefore inherits from RenderWidgetHostViewChildFrame.
34 // Eventually all RenderWidgetHostViewGuest code will be subsumed by
35 // RenderWidgetHostViewChildFrame and this class will be removed.
36 //
37 // Some elements that are platform specific will be deal with by delegating
38 // the relevant calls to the platform view.
39 class CONTENT_EXPORT RenderWidgetHostViewGuest
40     : public RenderWidgetHostViewChildFrame,
41       public ui::GestureConsumer,
42       public ui::GestureEventHelper {
43  public:
44   RenderWidgetHostViewGuest(RenderWidgetHost* widget,
45                             BrowserPluginGuest* guest,
46                             RenderWidgetHostViewBase* platform_view);
47   virtual ~RenderWidgetHostViewGuest();
48
49   bool OnMessageReceivedFromEmbedder(const IPC::Message& message,
50                                      RenderWidgetHostImpl* embedder);
51
52   // RenderWidgetHostView implementation.
53   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
54   virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
55   virtual void SetSize(const gfx::Size& size) OVERRIDE;
56   virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
57   virtual void Focus() OVERRIDE;
58   virtual bool HasFocus() const OVERRIDE;
59   virtual gfx::NativeView GetNativeView() const OVERRIDE;
60   virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
61   virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
62   virtual gfx::Rect GetViewBounds() const OVERRIDE;
63   virtual void SetBackgroundOpaque(bool opaque) OVERRIDE;
64   virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE;
65   virtual base::string16 GetSelectedText() const OVERRIDE;
66
67   // RenderWidgetHostViewBase implementation.
68   virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
69                            const gfx::Rect& pos) OVERRIDE;
70   virtual void InitAsFullscreen(
71       RenderWidgetHostView* reference_host_view) OVERRIDE;
72   virtual void WasShown() OVERRIDE;
73   virtual void WasHidden() OVERRIDE;
74   virtual void MovePluginWindows(
75       const std::vector<WebPluginGeometry>& moves) OVERRIDE;
76   virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
77   virtual void SetIsLoading(bool is_loading) OVERRIDE;
78   virtual void TextInputStateChanged(
79       const ViewHostMsg_TextInputState_Params& params) OVERRIDE;
80   virtual void ImeCancelComposition() OVERRIDE;
81 #if defined(OS_MACOSX) || defined(USE_AURA)
82   virtual void ImeCompositionRangeChanged(
83       const gfx::Range& range,
84       const std::vector<gfx::Rect>& character_bounds) OVERRIDE;
85 #endif
86   virtual void RenderProcessGone(base::TerminationStatus status,
87                                  int error_code) OVERRIDE;
88   virtual void Destroy() OVERRIDE;
89   virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE;
90   virtual void SelectionChanged(const base::string16& text,
91                                 size_t offset,
92                                 const gfx::Range& range) OVERRIDE;
93   virtual void SelectionBoundsChanged(
94       const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
95   virtual void CopyFromCompositingSurface(
96       const gfx::Rect& src_subrect,
97       const gfx::Size& dst_size,
98       CopyFromCompositingSurfaceCallback& callback,
99       const SkColorType color_type) OVERRIDE;
100   virtual void AcceleratedSurfaceBuffersSwapped(
101       const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
102       int gpu_host_id) OVERRIDE;
103   virtual void AcceleratedSurfacePostSubBuffer(
104       const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
105       int gpu_host_id) OVERRIDE;
106   virtual void OnSwapCompositorFrame(
107       uint32 output_surface_id,
108       scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
109 #if defined(USE_AURA)
110   virtual void ProcessAckedTouchEvent(
111       const TouchEventWithLatencyInfo& touch,
112       InputEventAckState ack_result) OVERRIDE;
113 #endif
114   virtual bool LockMouse() OVERRIDE;
115   virtual void UnlockMouse() OVERRIDE;
116   virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE;
117
118 #if defined(OS_MACOSX)
119   // RenderWidgetHostView implementation.
120   virtual void SetActive(bool active) OVERRIDE;
121   virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE;
122   virtual void SetWindowVisibility(bool visible) OVERRIDE;
123   virtual void WindowFrameChanged() OVERRIDE;
124   virtual void ShowDefinitionForSelection() OVERRIDE;
125   virtual bool SupportsSpeech() const OVERRIDE;
126   virtual void SpeakSelection() OVERRIDE;
127   virtual bool IsSpeaking() const OVERRIDE;
128   virtual void StopSpeaking() OVERRIDE;
129
130   // RenderWidgetHostViewBase implementation.
131   virtual bool PostProcessEventForPluginIme(
132       const NativeWebKeyboardEvent& event) OVERRIDE;
133 #endif  // defined(OS_MACOSX)
134
135 #if defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
136   // RenderWidgetHostViewBase implementation.
137   virtual void ShowDisambiguationPopup(const gfx::Rect& rect_pixels,
138                                        const SkBitmap& zoomed_bitmap) OVERRIDE;
139 #endif  // defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
140
141 #if defined(OS_ANDROID)
142   virtual void LockCompositingSurface() OVERRIDE;
143   virtual void UnlockCompositingSurface() OVERRIDE;
144 #endif  // defined(OS_ANDROID)
145
146 #if defined(OS_WIN)
147   virtual void SetParentNativeViewAccessible(
148       gfx::NativeViewAccessible accessible_parent) OVERRIDE;
149   virtual gfx::NativeViewId GetParentForWindowlessPlugin() const OVERRIDE;
150 #endif
151
152   // Overridden from ui::GestureEventHelper.
153   virtual bool CanDispatchToConsumer(ui::GestureConsumer* consumer) OVERRIDE;
154   virtual void DispatchGestureEvent(ui::GestureEvent* event) OVERRIDE;
155   virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE;
156
157   virtual SkColorType PreferredReadbackFormat() OVERRIDE;
158
159  protected:
160   friend class RenderWidgetHostView;
161
162  private:
163   // Destroys this view without calling |Destroy| on |platform_view_|.
164   void DestroyGuestView();
165
166   // Builds and forwards a WebKitGestureEvent to the renderer.
167   bool ForwardGestureEventToRenderer(ui::GestureEvent* gesture);
168
169   // Process all of the given gestures (passes them on to renderer)
170   void ProcessGestures(ui::GestureRecognizer::Gestures* gestures);
171
172   RenderWidgetHostViewBase* GetGuestRenderWidgetHostView() const;
173
174   void OnHandleInputEvent(RenderWidgetHostImpl* embedder,
175                           int browser_plugin_instance_id,
176                           const gfx::Rect& guest_window_rect,
177                           const blink::WebInputEvent* event);
178
179   // BrowserPluginGuest and RenderWidgetHostViewGuest's lifetimes are not tied
180   // to one another, therefore we access |guest_| through WeakPtr.
181   base::WeakPtr<BrowserPluginGuest> guest_;
182   gfx::Size size_;
183   // The platform view for this RenderWidgetHostView.
184   // RenderWidgetHostViewGuest mostly only cares about stuff related to
185   // compositing, the rest are directly forwared to this |platform_view_|.
186   RenderWidgetHostViewBase* platform_view_;
187 #if defined(USE_AURA)
188   scoped_ptr<ui::GestureRecognizer> gesture_recognizer_;
189 #endif
190   DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuest);
191 };
192
193 }  // namespace content
194
195 #endif  // CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_