Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / content / port / browser / render_widget_host_view_port.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_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_
6 #define CONTENT_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_
7
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/process/kill.h"
12 #include "base/strings/string16.h"
13 #include "cc/output/compositor_frame.h"
14 #include "content/common/content_export.h"
15 #include "content/port/browser/event_with_latency_info.h"
16 #include "content/port/common/input_event_ack_state.h"
17 #include "content/public/browser/render_widget_host_view.h"
18 #include "ipc/ipc_listener.h"
19 #include "third_party/WebKit/public/web/WebPopupType.h"
20 #include "third_party/WebKit/public/web/WebTextDirection.h"
21 #include "ui/base/ime/text_input_mode.h"
22 #include "ui/base/ime/text_input_type.h"
23 #include "ui/gfx/range/range.h"
24 #include "ui/surface/transport_dib.h"
25
26 class SkBitmap;
27
28 struct AccessibilityHostMsg_EventParams;
29 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
30 struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params;
31 struct ViewHostMsg_TextInputState_Params;
32 struct ViewHostMsg_SelectionBounds_Params;
33
34 namespace media {
35 class VideoFrame;
36 }
37
38 namespace blink {
39 struct WebScreenInfo;
40 }
41
42 namespace content {
43 class BackingStore;
44 class RenderWidgetHostViewFrameSubscriber;
45 class SyntheticGesture;
46 class SyntheticGestureTarget;
47 class WebCursor;
48 struct WebPluginGeometry;
49 struct NativeWebKeyboardEvent;
50
51 // This is the larger RenderWidgetHostView interface exposed only
52 // within content/ and to embedders looking to port to new platforms.
53 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
54 class CONTENT_EXPORT RenderWidgetHostViewPort : public RenderWidgetHostView,
55                                                 public IPC::Listener {
56  public:
57   virtual ~RenderWidgetHostViewPort() {}
58
59   // Does the cast for you.
60   static RenderWidgetHostViewPort* FromRWHV(RenderWidgetHostView* rwhv);
61
62   // Like RenderWidgetHostView::CreateViewForWidget, with cast.
63   static RenderWidgetHostViewPort* CreateViewForWidget(
64       RenderWidgetHost* widget);
65
66   static void GetDefaultScreenInfo(blink::WebScreenInfo* results);
67
68   // Perform all the initialization steps necessary for this object to represent
69   // a popup (such as a <select> dropdown), then shows the popup at |pos|.
70   virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
71                            const gfx::Rect& pos) = 0;
72
73   // Perform all the initialization steps necessary for this object to represent
74   // a full screen window.
75   // |reference_host_view| is the view associated with the creating page that
76   // helps to position the full screen widget on the correct monitor.
77   virtual void InitAsFullscreen(
78       RenderWidgetHostView* reference_host_view) = 0;
79
80   // Notifies the View that it has become visible.
81   virtual void WasShown() = 0;
82
83   // Notifies the View that it has been hidden.
84   virtual void WasHidden() = 0;
85
86   // Moves all plugin windows as described in the given list.
87   // |scroll_offset| is the scroll offset of the render view.
88   virtual void MovePluginWindows(
89       const gfx::Vector2d& scroll_offset,
90       const std::vector<WebPluginGeometry>& moves) = 0;
91
92   // Take focus from the associated View component.
93   virtual void Blur() = 0;
94
95   // Sets the cursor to the one associated with the specified cursor_type
96   virtual void UpdateCursor(const WebCursor& cursor) = 0;
97
98   // Indicates whether the page has finished loading.
99   virtual void SetIsLoading(bool is_loading) = 0;
100
101   // Updates the type of the input method attached to the view.
102   virtual void TextInputTypeChanged(ui::TextInputType type,
103                                     ui::TextInputMode mode,
104                                     bool can_compose_inline) = 0;
105
106   // Cancel the ongoing composition of the input method attached to the view.
107   virtual void ImeCancelComposition() = 0;
108
109   // Informs that the focused DOM node has changed.
110   virtual void FocusedNodeChanged(bool is_editable_node) = 0;
111
112 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
113   // Updates the range of the marked text in an IME composition.
114   virtual void ImeCompositionRangeChanged(
115       const gfx::Range& range,
116       const std::vector<gfx::Rect>& character_bounds) = 0;
117 #endif
118
119   // Informs the view that a portion of the widget's backing store was scrolled
120   // and/or painted.  The view should ensure this gets copied to the screen.
121   //
122   // If the scroll_rect is non-empty, then a portion of the widget's backing
123   // store was scrolled by dx pixels horizontally and dy pixels vertically.
124   // The exposed rect from the scroll operation is included in copy_rects.
125   //
126   // There are subtle performance implications here.  The RenderWidget gets sent
127   // a paint ack after this returns, so if the view only ever invalidates in
128   // response to this, then on Windows, where WM_PAINT has lower priority than
129   // events which can cause renderer resizes/paint rect updates, e.g.
130   // drag-resizing can starve painting; this function thus provides the view its
131   // main chance to ensure it stays painted and not just invalidated.  On the
132   // other hand, if this always blindly paints, then if we're already in the
133   // midst of a paint on the callstack, we can double-paint unnecessarily.
134   // (Worse, we might recursively call RenderWidgetHost::GetBackingStore().)
135   // Thus implementers should generally paint as much of |rect| as possible
136   // synchronously with as little overpainting as possible.
137   virtual void DidUpdateBackingStore(
138       const gfx::Rect& scroll_rect,
139       const gfx::Vector2d& scroll_delta,
140       const std::vector<gfx::Rect>& copy_rects,
141       const std::vector<ui::LatencyInfo>& latency_info) = 0;
142
143   // Notifies the View that the renderer has ceased to exist.
144   virtual void RenderProcessGone(base::TerminationStatus status,
145                                  int error_code) = 0;
146
147   // Tells the View to destroy itself.
148   virtual void Destroy() = 0;
149
150   // Tells the View that the tooltip text for the current mouse position over
151   // the page has changed.
152   virtual void SetTooltipText(const base::string16& tooltip_text) = 0;
153
154   // Notifies the View that the renderer text selection has changed.
155   virtual void SelectionChanged(const base::string16& text,
156                                 size_t offset,
157                                 const gfx::Range& range) = 0;
158
159   // Notifies the View that the renderer selection bounds has changed.
160   // |start_rect| and |end_rect| are the bounds end of the selection in the
161   // coordinate system of the render view. |start_direction| and |end_direction|
162   // indicates the direction at which the selection was made on touch devices.
163   virtual void SelectionBoundsChanged(
164       const ViewHostMsg_SelectionBounds_Params& params) = 0;
165
166 #if defined(OS_ANDROID)
167   // Notifies the View that the renderer selection root bounds has changed.
168   virtual void SelectionRootBoundsChanged(const gfx::Rect& bounds) = 0;
169 #endif
170
171   // Notifies the view that the scroll offset has changed.
172   virtual void ScrollOffsetChanged() = 0;
173
174   // Allocate a backing store for this view.
175   virtual BackingStore* AllocBackingStore(const gfx::Size& size) = 0;
176
177   // Copies the contents of the compositing surface into the given
178   // (uninitialized) PlatformCanvas if any.
179   // The rectangle region specified with |src_subrect| is copied from the
180   // contents, scaled to |dst_size|, and written to |output|.
181   // |callback| is invoked with true on success, false otherwise. |output| can
182   // be initialized even on failure.
183   // A smaller region than |src_subrect| may be copied if the underlying surface
184   // is smaller than |src_subrect|.
185   // NOTE: |callback| is called asynchronously.
186   virtual void CopyFromCompositingSurface(
187       const gfx::Rect& src_subrect,
188       const gfx::Size& dst_size,
189       const base::Callback<void(bool, const SkBitmap&)>& callback,
190       const SkBitmap::Config config) = 0;
191
192   // Instructs the view to not drop the surface even when the view is hidden.
193   virtual void LockCompositingSurface() = 0;
194   virtual void UnlockCompositingSurface() = 0;
195
196   // Copies a given subset of the compositing surface's content into a YV12
197   // VideoFrame, and invokes a callback with a success/fail parameter. |target|
198   // must contain an allocated, YV12 video frame of the intended size. If the
199   // copy rectangle does not match |target|'s size, the copied content will be
200   // scaled and letterboxed with black borders. The copy will happen
201   // asynchronously. This operation will fail if there is no available
202   // compositing surface.
203   virtual void CopyFromCompositingSurfaceToVideoFrame(
204       const gfx::Rect& src_subrect,
205       const scoped_refptr<media::VideoFrame>& target,
206       const base::Callback<void(bool)>& callback) = 0;
207
208   // Returns true if CopyFromCompositingSurfaceToVideoFrame() is likely to
209   // succeed.
210   //
211   // TODO(nick): When VideoFrame copies are broadly implemented, this method
212   // should be renamed to HasCompositingSurface(), or unified with
213   // IsSurfaceAvailableForCopy() and HasAcceleratedSurface().
214   virtual bool CanCopyToVideoFrame() const = 0;
215
216   // Return true if frame subscription is supported on this platform.
217   virtual bool CanSubscribeFrame() const = 0;
218
219   // Begin subscribing for presentation events and captured frames.
220   // |subscriber| is now owned by this object, it will be called only on the
221   // UI thread.
222   virtual void BeginFrameSubscription(
223       scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) = 0;
224
225   // End subscribing for frame presentation events. FrameSubscriber will be
226   // deleted after this call.
227   virtual void EndFrameSubscription() = 0;
228
229   // Called when accelerated compositing state changes.
230   virtual void OnAcceleratedCompositingStateChange() = 0;
231   // Called when an accelerated compositing surface is initialized.
232   virtual void AcceleratedSurfaceInitialized(int host_id, int route_id) = 0;
233   // |params.window| and |params.surface_id| indicate which accelerated
234   // surface's buffers swapped. |params.renderer_id| and |params.route_id|
235   // are used to formulate a reply to the GPU process to prevent it from getting
236   // too far ahead. They may all be zero, in which case no flow control is
237   // enforced; this case is currently used for accelerated plugins.
238   virtual void AcceleratedSurfaceBuffersSwapped(
239       const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
240       int gpu_host_id) = 0;
241   // Similar to above, except |params.(x|y|width|height)| define the region
242   // of the surface that changed.
243   virtual void AcceleratedSurfacePostSubBuffer(
244       const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
245       int gpu_host_id) = 0;
246
247   // Release the accelerated surface temporarily. It will be recreated on the
248   // next swap buffers or post sub buffer.
249   virtual void AcceleratedSurfaceSuspend() = 0;
250
251   virtual void AcceleratedSurfaceRelease() = 0;
252
253   // Return true if the view has an accelerated surface that contains the last
254   // presented frame for the view. If |desired_size| is non-empty, true is
255   // returned only if the accelerated surface size matches.
256   virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) = 0;
257
258   virtual void OnSwapCompositorFrame(
259       uint32 output_surface_id,
260       scoped_ptr<cc::CompositorFrame> frame) = 0;
261
262   virtual void GetScreenInfo(blink::WebScreenInfo* results) = 0;
263
264   // The size of the view's backing surface in non-DPI-adjusted pixels.
265   virtual gfx::Size GetPhysicalBackingSize() const = 0;
266
267   // The height of the physical backing surface that is overdrawn opaquely in
268   // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
269   virtual float GetOverdrawBottomHeight() const = 0;
270
271   // Gets the bounds of the window, in screen coordinates.
272   virtual gfx::Rect GetBoundsInRootWindow() = 0;
273
274   virtual gfx::GLSurfaceHandle GetCompositingSurface() = 0;
275
276   // Resize compositing surface.
277   virtual void ResizeCompositingSurface(const gfx::Size&) = 0;
278
279   // Because the associated remote WebKit instance can asynchronously
280   // prevent-default on a dispatched touch event, the touch events are queued in
281   // the GestureRecognizer until invocation of ProcessAckedTouchEvent releases
282   // it to be consumed (when |ack_result| is NOT_CONSUMED OR NO_CONSUMER_EXISTS)
283   // or ignored (when |ack_result| is CONSUMED).
284   virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
285                                       InputEventAckState ack_result) = 0;
286
287   virtual void SetHasHorizontalScrollbar(bool has_horizontal_scrollbar) = 0;
288   virtual void SetScrollOffsetPinning(
289       bool is_pinned_to_left, bool is_pinned_to_right) = 0;
290
291   // Called when a mousewheel event was not processed by the renderer.
292   virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) = 0;
293
294   // Called prior to forwarding input event messages to the renderer, giving
295   // the view a chance to perform in-process event filtering or processing.
296   // Return values of |NOT_CONSUMED| or |UNKNOWN| will result in |input_event|
297   // being forwarded.
298   virtual InputEventAckState FilterInputEvent(
299       const blink::WebInputEvent& input_event) = 0;
300
301   // Called by the host when it requires an input flush; the flush call should
302   // by synchronized with BeginFrame.
303   virtual void OnSetNeedsFlushInput() = 0;
304
305   // Called by the host when the input flush has completed.
306   virtual void OnDidFlushInput() = 0;
307
308   // Create a platform specific SyntheticGestureTarget implementation that will
309   // be used to inject synthetic input events.
310   virtual scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget() = 0;
311
312   virtual void GestureEventAck(const blink::WebGestureEvent& event,
313                                InputEventAckState ack_result) = 0;
314
315   virtual void OnOverscrolled(gfx::Vector2dF accumulated_overscroll,
316                               gfx::Vector2dF current_fling_velocity) = 0;
317
318   virtual void DidStopFlinging() = 0;
319
320   virtual void SetPopupType(blink::WebPopupType popup_type) = 0;
321   virtual blink::WebPopupType GetPopupType() = 0;
322
323   // Get the BrowserAccessibilityManager if it exists, may return NULL.
324   virtual BrowserAccessibilityManager*
325       GetBrowserAccessibilityManager() const = 0;
326   // Create a BrowserAccessibilityManager for this view if it's possible to
327   // create one and if one doesn't exist already. Some ports may not create
328   // one depending on the current state.
329   virtual void CreateBrowserAccessibilityManagerIfNeeded() = 0;
330
331   // Return a value that is incremented each time the renderer swaps a new frame
332   // to the view.
333   virtual uint32 RendererFrameNumber() = 0;
334   // Called each time the RenderWidgetHost receives a new frame for display from
335   // the renderer.
336   virtual void DidReceiveRendererFrame() = 0;
337
338   virtual SkBitmap::Config PreferredReadbackFormat() = 0;
339
340 #if defined(OS_MACOSX)
341   // Does any event handling necessary for plugin IME; should be called after
342   // the plugin has already had a chance to process the event. If plugin IME is
343   // not enabled, this is a no-op, so it is always safe to call.
344   // Returns true if the event was handled by IME.
345   virtual bool PostProcessEventForPluginIme(
346       const NativeWebKeyboardEvent& event) = 0;
347 #endif
348
349 #if defined(OS_ANDROID)
350   virtual void ShowDisambiguationPopup(const gfx::Rect& target_rect,
351                                        const SkBitmap& zoomed_bitmap) = 0;
352 #endif
353
354 #if defined(OS_WIN)
355   virtual void SetParentNativeViewAccessible(
356       gfx::NativeViewAccessible accessible_parent) = 0;
357
358   // Returns an HWND that's given as the parent window for windowless Flash to
359   // workaround crbug.com/301548.
360   virtual gfx::NativeViewId GetParentForWindowlessPlugin() const = 0;
361 #endif
362 };
363
364 }  // namespace content
365
366 #endif  // CONTENT_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_