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