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 26class SkBitmap; 27class WebCursor; 28 29struct AccessibilityHostMsg_EventParams; 30struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params; 31struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params; 32struct ViewHostMsg_TextInputState_Params; 33struct ViewHostMsg_SelectionBounds_Params; 34 35namespace media { 36class VideoFrame; 37} 38 39namespace blink { 40struct WebScreenInfo; 41} 42 43namespace content { 44class BackingStore; 45class RenderWidgetHostViewFrameSubscriber; 46class SyntheticGesture; 47class SyntheticGestureTarget; 48struct WebPluginGeometry; 49struct 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. 54class 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#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; 114#endif 115 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. 118 // 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. 122 // 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 ui::LatencyInfo& latency_info) = 0; 139 140 // Notifies the View that the renderer has ceased to exist. 141 virtual void RenderProcessGone(base::TerminationStatus status, 142 int error_code) = 0; 143 144 // Tells the View to destroy itself. 145 virtual void Destroy() = 0; 146 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; 150 151 // Notifies the View that the renderer text selection has changed. 152 virtual void SelectionChanged(const base::string16& text, 153 size_t offset, 154 const gfx::Range& range) = 0; 155 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; 162 163 // Notifies the view that the scroll offset has changed. 164 virtual void ScrollOffsetChanged() = 0; 165 166 // Allocate a backing store for this view. 167 virtual BackingStore* AllocBackingStore(const gfx::Size& size) = 0; 168 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; 182 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; 194 195 // Returns true if CopyFromCompositingSurfaceToVideoFrame() is likely to 196 // succeed. 197 // 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; 202 203 // Return true if frame subscription is supported on this platform. 204 virtual bool CanSubscribeFrame() const = 0; 205 206 // Begin subscribing for presentation events and captured frames. 207 // |subscriber| is now owned by this object, it will be called only on the 208 // UI thread. 209 virtual void BeginFrameSubscription( 210 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) = 0; 211 212 // End subscribing for frame presentation events. FrameSubscriber will be 213 // deleted after this call. 214 virtual void EndFrameSubscription() = 0; 215 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; 233 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; 237 238 virtual void AcceleratedSurfaceRelease() = 0; 239 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; 244 245 virtual void OnSwapCompositorFrame( 246 uint32 output_surface_id, 247 scoped_ptr<cc::CompositorFrame> frame) = 0; 248 249 virtual void GetScreenInfo(blink::WebScreenInfo* results) = 0; 250 251 // The size of the view's backing surface in non-DPI-adjusted pixels. 252 virtual gfx::Size GetPhysicalBackingSize() const = 0; 253 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; 257 258 // Gets the bounds of the window, in screen coordinates. 259 virtual gfx::Rect GetBoundsInRootWindow() = 0; 260 261 virtual gfx::GLSurfaceHandle GetCompositingSurface() = 0; 262 263 // Resize compositing surface. 264 virtual void ResizeCompositingSurface(const gfx::Size&) = 0; 265 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; 273 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; 277 278 // Called when a mousewheel event was not processed by the renderer. 279 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) = 0; 280 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| 284 // being forwarded. 285 virtual InputEventAckState FilterInputEvent( 286 const blink::WebInputEvent& input_event) = 0; 287 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; 291 292 // Called by the host when the input flush has completed. 293 virtual void OnDidFlushInput() = 0; 294 295 // Create a platform specific SyntheticGestureTarget implementation that will 296 // be used to inject synthetic input events. 297 virtual scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget() = 0; 298 299 virtual void GestureEventAck(int gesture_event_type, 300 InputEventAckState ack_result) = 0; 301 302 virtual void OnOverscrolled(gfx::Vector2dF accumulated_overscroll, 303 gfx::Vector2dF current_fling_velocity) = 0; 304 305 virtual void SetPopupType(blink::WebPopupType popup_type) = 0; 306 virtual blink::WebPopupType GetPopupType() = 0; 307 308 virtual BrowserAccessibilityManager* 309 GetBrowserAccessibilityManager() const = 0; 310 virtual void OnAccessibilityEvents( 311 const std::vector<AccessibilityHostMsg_EventParams>& params) = 0; 312 313 // Return a value that is incremented each time the renderer swaps a new frame 314 // to the view. 315 virtual uint32 RendererFrameNumber() = 0; 316 // Called each time the RenderWidgetHost receives a new frame for display from 317 // the renderer. 318 virtual void DidReceiveRendererFrame() = 0; 319 320#if defined(OS_MACOSX) 321 // Called just before GetBackingStore blocks for an updated frame. 322 virtual void AboutToWaitForBackingStoreMsg() = 0; 323 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; 330#endif 331 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; 336#endif 337 338#if defined(OS_WIN) && !defined(USE_AURA) 339 virtual void WillWmDestroy() = 0; 340#endif 341 342#if defined(OS_WIN) && defined(USE_AURA) 343 virtual void SetParentNativeViewAccessible( 344 gfx::NativeViewAccessible accessible_parent) = 0; 345 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; 349#endif 350}; 351 352} // namespace content 353 354#endif // CONTENT_PORT_BROWSER_RENDER_WIDGET_HOST_VIEW_PORT_H_ 355