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 CONTENT_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_
6 #define CONTENT_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_
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"
29 struct AccessibilityHostMsg_EventParams
;
30 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params
;
31 struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params
;
32 struct ViewHostMsg_TextInputState_Params
;
33 struct ViewHostMsg_SelectionBounds_Params
;
45 class RenderWidgetHostViewFrameSubscriber
;
46 class SyntheticGesture
;
47 class SyntheticGestureTarget
;
48 struct WebPluginGeometry
;
49 struct NativeWebKeyboardEvent
;
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
{
57 virtual ~RenderWidgetHostViewPort() {}
59 // Does the cast for you.
60 static RenderWidgetHostViewPort
* FromRWHV(RenderWidgetHostView
* rwhv
);
62 // Like RenderWidgetHostView::CreateViewForWidget, with cast.
63 static RenderWidgetHostViewPort
* CreateViewForWidget(
64 RenderWidgetHost
* widget
);
66 static void GetDefaultScreenInfo(blink::WebScreenInfo
* results
);
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;
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;
80 // Notifies the View that it has become visible.
81 virtual void WasShown() = 0;
83 // Notifies the View that it has been hidden.
84 virtual void WasHidden() = 0;
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;
92 // Take focus from the associated View component.
93 virtual void Blur() = 0;
95 // Sets the cursor to the one associated with the specified cursor_type
96 virtual void UpdateCursor(const WebCursor
& cursor
) = 0;
98 // Indicates whether the page has finished loading.
99 virtual void SetIsLoading(bool is_loading
) = 0;
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;
106 // Cancel the ongoing composition of the input method attached to the view.
107 virtual void ImeCancelComposition() = 0;
109 // Informs that the focused DOM node has changed.
110 virtual void FocusedNodeChanged(bool is_editable_node
) = 0;
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;
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.
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.
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;
143 // Notifies the View that the renderer has ceased to exist.
144 virtual void RenderProcessGone(base::TerminationStatus status
,
147 // Tells the View to destroy itself.
148 virtual void Destroy() = 0;
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;
154 // Notifies the View that the renderer text selection has changed.
155 virtual void SelectionChanged(const base::string16
& text
,
157 const gfx::Range
& range
) = 0;
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;
166 // Notifies the view that the scroll offset has changed.
167 virtual void ScrollOffsetChanged() = 0;
169 // Allocate a backing store for this view.
170 virtual BackingStore
* AllocBackingStore(const gfx::Size
& size
) = 0;
172 // Copies the contents of the compositing surface into the given
173 // (uninitialized) PlatformCanvas if any.
174 // The rectangle region specified with |src_subrect| is copied from the
175 // contents, scaled to |dst_size|, and written to |output|.
176 // |callback| is invoked with true on success, false otherwise. |output| can
177 // be initialized even on failure.
178 // A smaller region than |src_subrect| may be copied if the underlying surface
179 // is smaller than |src_subrect|.
180 // NOTE: |callback| is called asynchronously.
181 virtual void CopyFromCompositingSurface(
182 const gfx::Rect
& src_subrect
,
183 const gfx::Size
& dst_size
,
184 const base::Callback
<void(bool, const SkBitmap
&)>& callback
,
185 const SkBitmap::Config config
) = 0;
187 // Copies a given subset of the compositing surface's content into a YV12
188 // VideoFrame, and invokes a callback with a success/fail parameter. |target|
189 // must contain an allocated, YV12 video frame of the intended size. If the
190 // copy rectangle does not match |target|'s size, the copied content will be
191 // scaled and letterboxed with black borders. The copy will happen
192 // asynchronously. This operation will fail if there is no available
193 // compositing surface.
194 virtual void CopyFromCompositingSurfaceToVideoFrame(
195 const gfx::Rect
& src_subrect
,
196 const scoped_refptr
<media::VideoFrame
>& target
,
197 const base::Callback
<void(bool)>& callback
) = 0;
199 // Returns true if CopyFromCompositingSurfaceToVideoFrame() is likely to
202 // TODO(nick): When VideoFrame copies are broadly implemented, this method
203 // should be renamed to HasCompositingSurface(), or unified with
204 // IsSurfaceAvailableForCopy() and HasAcceleratedSurface().
205 virtual bool CanCopyToVideoFrame() const = 0;
207 // Return true if frame subscription is supported on this platform.
208 virtual bool CanSubscribeFrame() const = 0;
210 // Begin subscribing for presentation events and captured frames.
211 // |subscriber| is now owned by this object, it will be called only on the
213 virtual void BeginFrameSubscription(
214 scoped_ptr
<RenderWidgetHostViewFrameSubscriber
> subscriber
) = 0;
216 // End subscribing for frame presentation events. FrameSubscriber will be
217 // deleted after this call.
218 virtual void EndFrameSubscription() = 0;
220 // Called when accelerated compositing state changes.
221 virtual void OnAcceleratedCompositingStateChange() = 0;
222 // Called when an accelerated compositing surface is initialized.
223 virtual void AcceleratedSurfaceInitialized(int host_id
, int route_id
) = 0;
224 // |params.window| and |params.surface_id| indicate which accelerated
225 // surface's buffers swapped. |params.renderer_id| and |params.route_id|
226 // are used to formulate a reply to the GPU process to prevent it from getting
227 // too far ahead. They may all be zero, in which case no flow control is
228 // enforced; this case is currently used for accelerated plugins.
229 virtual void AcceleratedSurfaceBuffersSwapped(
230 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params
& params_in_pixel
,
231 int gpu_host_id
) = 0;
232 // Similar to above, except |params.(x|y|width|height)| define the region
233 // of the surface that changed.
234 virtual void AcceleratedSurfacePostSubBuffer(
235 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params
& params_in_pixel
,
236 int gpu_host_id
) = 0;
238 // Release the accelerated surface temporarily. It will be recreated on the
239 // next swap buffers or post sub buffer.
240 virtual void AcceleratedSurfaceSuspend() = 0;
242 virtual void AcceleratedSurfaceRelease() = 0;
244 // Return true if the view has an accelerated surface that contains the last
245 // presented frame for the view. If |desired_size| is non-empty, true is
246 // returned only if the accelerated surface size matches.
247 virtual bool HasAcceleratedSurface(const gfx::Size
& desired_size
) = 0;
249 virtual void OnSwapCompositorFrame(
250 uint32 output_surface_id
,
251 scoped_ptr
<cc::CompositorFrame
> frame
) = 0;
253 virtual void GetScreenInfo(blink::WebScreenInfo
* results
) = 0;
255 // The size of the view's backing surface in non-DPI-adjusted pixels.
256 virtual gfx::Size
GetPhysicalBackingSize() const = 0;
258 // The height of the physical backing surface that is overdrawn opaquely in
259 // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
260 virtual float GetOverdrawBottomHeight() const = 0;
262 // Gets the bounds of the window, in screen coordinates.
263 virtual gfx::Rect
GetBoundsInRootWindow() = 0;
265 virtual gfx::GLSurfaceHandle
GetCompositingSurface() = 0;
267 // Resize compositing surface.
268 virtual void ResizeCompositingSurface(const gfx::Size
&) = 0;
270 // Because the associated remote WebKit instance can asynchronously
271 // prevent-default on a dispatched touch event, the touch events are queued in
272 // the GestureRecognizer until invocation of ProcessAckedTouchEvent releases
273 // it to be consumed (when |ack_result| is NOT_CONSUMED OR NO_CONSUMER_EXISTS)
274 // or ignored (when |ack_result| is CONSUMED).
275 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo
& touch
,
276 InputEventAckState ack_result
) = 0;
278 virtual void SetHasHorizontalScrollbar(bool has_horizontal_scrollbar
) = 0;
279 virtual void SetScrollOffsetPinning(
280 bool is_pinned_to_left
, bool is_pinned_to_right
) = 0;
282 // Called when a mousewheel event was not processed by the renderer.
283 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent
& event
) = 0;
285 // Called prior to forwarding input event messages to the renderer, giving
286 // the view a chance to perform in-process event filtering or processing.
287 // Return values of |NOT_CONSUMED| or |UNKNOWN| will result in |input_event|
289 virtual InputEventAckState
FilterInputEvent(
290 const blink::WebInputEvent
& input_event
) = 0;
292 // Called by the host when it requires an input flush; the flush call should
293 // by synchronized with BeginFrame.
294 virtual void OnSetNeedsFlushInput() = 0;
296 // Called by the host when the input flush has completed.
297 virtual void OnDidFlushInput() = 0;
299 // Create a platform specific SyntheticGestureTarget implementation that will
300 // be used to inject synthetic input events.
301 virtual scoped_ptr
<SyntheticGestureTarget
> CreateSyntheticGestureTarget() = 0;
303 virtual void GestureEventAck(const blink::WebGestureEvent
& event
,
304 InputEventAckState ack_result
) = 0;
306 virtual void OnOverscrolled(gfx::Vector2dF accumulated_overscroll
,
307 gfx::Vector2dF current_fling_velocity
) = 0;
309 virtual void DidStopFlinging() = 0;
311 virtual void SetPopupType(blink::WebPopupType popup_type
) = 0;
312 virtual blink::WebPopupType
GetPopupType() = 0;
314 // Get the BrowserAccessibilityManager if it exists, may return NULL.
315 virtual BrowserAccessibilityManager
*
316 GetBrowserAccessibilityManager() const = 0;
317 // Create a BrowserAccessibilityManager for this view if it's possible to
318 // create one and if one doesn't exist already. Some ports may not create
319 // one depending on the current state.
320 virtual void CreateBrowserAccessibilityManagerIfNeeded() = 0;
322 // Return a value that is incremented each time the renderer swaps a new frame
324 virtual uint32
RendererFrameNumber() = 0;
325 // Called each time the RenderWidgetHost receives a new frame for display from
327 virtual void DidReceiveRendererFrame() = 0;
329 #if defined(OS_MACOSX)
330 // Does any event handling necessary for plugin IME; should be called after
331 // the plugin has already had a chance to process the event. If plugin IME is
332 // not enabled, this is a no-op, so it is always safe to call.
333 // Returns true if the event was handled by IME.
334 virtual bool PostProcessEventForPluginIme(
335 const NativeWebKeyboardEvent
& event
) = 0;
338 #if defined(OS_ANDROID)
339 virtual void ShowDisambiguationPopup(const gfx::Rect
& target_rect
,
340 const SkBitmap
& zoomed_bitmap
) = 0;
344 virtual void SetParentNativeViewAccessible(
345 gfx::NativeViewAccessible accessible_parent
) = 0;
347 // Returns an HWND that's given as the parent window for windowless Flash to
348 // workaround crbug.com/301548.
349 virtual gfx::NativeViewId
GetParentForWindowlessPlugin() const = 0;
353 } // namespace content
355 #endif // CONTENT_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_