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 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
110 // Updates the range of the marked text in an IME composition.
111 virtual void ImeCompositionRangeChanged(
112 const gfx::Range
& range
,
113 const std::vector
<gfx::Rect
>& character_bounds
) = 0;
116 // Informs the view that a portion of the widget's backing store was scrolled
117 // and/or painted. The view should ensure this gets copied to the screen.
119 // If the scroll_rect is non-empty, then a portion of the widget's backing
120 // store was scrolled by dx pixels horizontally and dy pixels vertically.
121 // The exposed rect from the scroll operation is included in copy_rects.
123 // There are subtle performance implications here. The RenderWidget gets sent
124 // a paint ack after this returns, so if the view only ever invalidates in
125 // response to this, then on Windows, where WM_PAINT has lower priority than
126 // events which can cause renderer resizes/paint rect updates, e.g.
127 // drag-resizing can starve painting; this function thus provides the view its
128 // main chance to ensure it stays painted and not just invalidated. On the
129 // other hand, if this always blindly paints, then if we're already in the
130 // midst of a paint on the callstack, we can double-paint unnecessarily.
131 // (Worse, we might recursively call RenderWidgetHost::GetBackingStore().)
132 // Thus implementers should generally paint as much of |rect| as possible
133 // synchronously with as little overpainting as possible.
134 virtual void DidUpdateBackingStore(
135 const gfx::Rect
& scroll_rect
,
136 const gfx::Vector2d
& scroll_delta
,
137 const std::vector
<gfx::Rect
>& copy_rects
,
138 const std::vector
<ui::LatencyInfo
>& latency_info
) = 0;
140 // Notifies the View that the renderer has ceased to exist.
141 virtual void RenderProcessGone(base::TerminationStatus status
,
144 // Tells the View to destroy itself.
145 virtual void Destroy() = 0;
147 // Tells the View that the tooltip text for the current mouse position over
148 // the page has changed.
149 virtual void SetTooltipText(const base::string16
& tooltip_text
) = 0;
151 // Notifies the View that the renderer text selection has changed.
152 virtual void SelectionChanged(const base::string16
& text
,
154 const gfx::Range
& range
) = 0;
156 // Notifies the View that the renderer selection bounds has changed.
157 // |start_rect| and |end_rect| are the bounds end of the selection in the
158 // coordinate system of the render view. |start_direction| and |end_direction|
159 // indicates the direction at which the selection was made on touch devices.
160 virtual void SelectionBoundsChanged(
161 const ViewHostMsg_SelectionBounds_Params
& params
) = 0;
163 // Notifies the view that the scroll offset has changed.
164 virtual void ScrollOffsetChanged() = 0;
166 // Allocate a backing store for this view.
167 virtual BackingStore
* AllocBackingStore(const gfx::Size
& size
) = 0;
169 // Copies the contents of the compositing surface into the given
170 // (uninitialized) PlatformCanvas if any.
171 // The rectangle region specified with |src_subrect| is copied from the
172 // contents, scaled to |dst_size|, and written to |output|.
173 // |callback| is invoked with true on success, false otherwise. |output| can
174 // be initialized even on failure.
175 // A smaller region than |src_subrect| may be copied if the underlying surface
176 // is smaller than |src_subrect|.
177 // NOTE: |callback| is called asynchronously.
178 virtual void CopyFromCompositingSurface(
179 const gfx::Rect
& src_subrect
,
180 const gfx::Size
& dst_size
,
181 const base::Callback
<void(bool, const SkBitmap
&)>& callback
) = 0;
183 // Copies a given subset of the compositing surface's content into a YV12
184 // VideoFrame, and invokes a callback with a success/fail parameter. |target|
185 // must contain an allocated, YV12 video frame of the intended size. If the
186 // copy rectangle does not match |target|'s size, the copied content will be
187 // scaled and letterboxed with black borders. The copy will happen
188 // asynchronously. This operation will fail if there is no available
189 // compositing surface.
190 virtual void CopyFromCompositingSurfaceToVideoFrame(
191 const gfx::Rect
& src_subrect
,
192 const scoped_refptr
<media::VideoFrame
>& target
,
193 const base::Callback
<void(bool)>& callback
) = 0;
195 // Returns true if CopyFromCompositingSurfaceToVideoFrame() is likely to
198 // TODO(nick): When VideoFrame copies are broadly implemented, this method
199 // should be renamed to HasCompositingSurface(), or unified with
200 // IsSurfaceAvailableForCopy() and HasAcceleratedSurface().
201 virtual bool CanCopyToVideoFrame() const = 0;
203 // Return true if frame subscription is supported on this platform.
204 virtual bool CanSubscribeFrame() const = 0;
206 // Begin subscribing for presentation events and captured frames.
207 // |subscriber| is now owned by this object, it will be called only on the
209 virtual void BeginFrameSubscription(
210 scoped_ptr
<RenderWidgetHostViewFrameSubscriber
> subscriber
) = 0;
212 // End subscribing for frame presentation events. FrameSubscriber will be
213 // deleted after this call.
214 virtual void EndFrameSubscription() = 0;
216 // Called when accelerated compositing state changes.
217 virtual void OnAcceleratedCompositingStateChange() = 0;
218 // Called when an accelerated compositing surface is initialized.
219 virtual void AcceleratedSurfaceInitialized(int host_id
, int route_id
) = 0;
220 // |params.window| and |params.surface_id| indicate which accelerated
221 // surface's buffers swapped. |params.renderer_id| and |params.route_id|
222 // are used to formulate a reply to the GPU process to prevent it from getting
223 // too far ahead. They may all be zero, in which case no flow control is
224 // enforced; this case is currently used for accelerated plugins.
225 virtual void AcceleratedSurfaceBuffersSwapped(
226 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params
& params_in_pixel
,
227 int gpu_host_id
) = 0;
228 // Similar to above, except |params.(x|y|width|height)| define the region
229 // of the surface that changed.
230 virtual void AcceleratedSurfacePostSubBuffer(
231 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params
& params_in_pixel
,
232 int gpu_host_id
) = 0;
234 // Release the accelerated surface temporarily. It will be recreated on the
235 // next swap buffers or post sub buffer.
236 virtual void AcceleratedSurfaceSuspend() = 0;
238 virtual void AcceleratedSurfaceRelease() = 0;
240 // Return true if the view has an accelerated surface that contains the last
241 // presented frame for the view. If |desired_size| is non-empty, true is
242 // returned only if the accelerated surface size matches.
243 virtual bool HasAcceleratedSurface(const gfx::Size
& desired_size
) = 0;
245 virtual void OnSwapCompositorFrame(
246 uint32 output_surface_id
,
247 scoped_ptr
<cc::CompositorFrame
> frame
) = 0;
249 virtual void GetScreenInfo(blink::WebScreenInfo
* results
) = 0;
251 // The size of the view's backing surface in non-DPI-adjusted pixels.
252 virtual gfx::Size
GetPhysicalBackingSize() const = 0;
254 // The height of the physical backing surface that is overdrawn opaquely in
255 // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
256 virtual float GetOverdrawBottomHeight() const = 0;
258 // Gets the bounds of the window, in screen coordinates.
259 virtual gfx::Rect
GetBoundsInRootWindow() = 0;
261 virtual gfx::GLSurfaceHandle
GetCompositingSurface() = 0;
263 // Resize compositing surface.
264 virtual void ResizeCompositingSurface(const gfx::Size
&) = 0;
266 // Because the associated remote WebKit instance can asynchronously
267 // prevent-default on a dispatched touch event, the touch events are queued in
268 // the GestureRecognizer until invocation of ProcessAckedTouchEvent releases
269 // it to be consumed (when |ack_result| is NOT_CONSUMED OR NO_CONSUMER_EXISTS)
270 // or ignored (when |ack_result| is CONSUMED).
271 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo
& touch
,
272 InputEventAckState ack_result
) = 0;
274 virtual void SetHasHorizontalScrollbar(bool has_horizontal_scrollbar
) = 0;
275 virtual void SetScrollOffsetPinning(
276 bool is_pinned_to_left
, bool is_pinned_to_right
) = 0;
278 // Called when a mousewheel event was not processed by the renderer.
279 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent
& event
) = 0;
281 // Called prior to forwarding input event messages to the renderer, giving
282 // the view a chance to perform in-process event filtering or processing.
283 // Return values of |NOT_CONSUMED| or |UNKNOWN| will result in |input_event|
285 virtual InputEventAckState
FilterInputEvent(
286 const blink::WebInputEvent
& input_event
) = 0;
288 // Called by the host when it requires an input flush; the flush call should
289 // by synchronized with BeginFrame.
290 virtual void OnSetNeedsFlushInput() = 0;
292 // Called by the host when the input flush has completed.
293 virtual void OnDidFlushInput() = 0;
295 // Create a platform specific SyntheticGestureTarget implementation that will
296 // be used to inject synthetic input events.
297 virtual scoped_ptr
<SyntheticGestureTarget
> CreateSyntheticGestureTarget() = 0;
299 virtual void GestureEventAck(int gesture_event_type
,
300 InputEventAckState ack_result
) = 0;
302 virtual void OnOverscrolled(gfx::Vector2dF accumulated_overscroll
,
303 gfx::Vector2dF current_fling_velocity
) = 0;
305 virtual void SetPopupType(blink::WebPopupType popup_type
) = 0;
306 virtual blink::WebPopupType
GetPopupType() = 0;
308 // Get the BrowserAccessibilityManager if it exists, may return NULL.
309 virtual BrowserAccessibilityManager
*
310 GetBrowserAccessibilityManager() const = 0;
311 // Create a BrowserAccessibilityManager for this view if it's possible to
312 // create one and if one doesn't exist already. Some ports may not create
313 // one depending on the current state.
314 virtual void CreateBrowserAccessibilityManagerIfNeeded() = 0;
316 // Return a value that is incremented each time the renderer swaps a new frame
318 virtual uint32
RendererFrameNumber() = 0;
319 // Called each time the RenderWidgetHost receives a new frame for display from
321 virtual void DidReceiveRendererFrame() = 0;
323 #if defined(OS_MACOSX)
324 // Does any event handling necessary for plugin IME; should be called after
325 // the plugin has already had a chance to process the event. If plugin IME is
326 // not enabled, this is a no-op, so it is always safe to call.
327 // Returns true if the event was handled by IME.
328 virtual bool PostProcessEventForPluginIme(
329 const NativeWebKeyboardEvent
& event
) = 0;
332 #if defined(OS_ANDROID)
333 virtual void ShowDisambiguationPopup(const gfx::Rect
& target_rect
,
334 const SkBitmap
& zoomed_bitmap
) = 0;
335 virtual void HasTouchEventHandlers(bool need_touch_events
) = 0;
338 #if defined(OS_WIN) && !defined(USE_AURA)
339 virtual void WillWmDestroy() = 0;
342 #if defined(OS_WIN) && defined(USE_AURA)
343 virtual void SetParentNativeViewAccessible(
344 gfx::NativeViewAccessible accessible_parent
) = 0;
346 // Returns an HWND that's given as the parent window for windowless Flash to
347 // workaround crbug.com/301548.
348 virtual gfx::NativeViewId
GetParentForWindowlessPlugin() const = 0;
352 } // namespace content
354 #endif // CONTENT_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_