[blink-in-js] Migrate resources required for blink-in-js to grd - part 2
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_view_base.h
blob4da2b56416d704d6dba154a4c15ad07922ce3ea0
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_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_
8 #if defined(OS_MACOSX)
9 #include <OpenGL/OpenGL.h>
10 #endif
12 #include <string>
13 #include <vector>
15 #include "base/memory/scoped_ptr.h"
16 #include "base/callback_forward.h"
17 #include "base/process/kill.h"
18 #include "base/timer/timer.h"
19 #include "cc/output/compositor_frame.h"
20 #include "content/browser/renderer_host/event_with_latency_info.h"
21 #include "content/common/content_export.h"
22 #include "content/common/input/input_event_ack_state.h"
23 #include "content/public/browser/render_widget_host_view.h"
24 #include "ipc/ipc_listener.h"
25 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
26 #include "third_party/WebKit/public/web/WebPopupType.h"
27 #include "third_party/WebKit/public/web/WebTextDirection.h"
28 #include "ui/base/ime/text_input_mode.h"
29 #include "ui/base/ime/text_input_type.h"
30 #include "ui/gfx/display.h"
31 #include "ui/gfx/native_widget_types.h"
32 #include "ui/gfx/range/range.h"
33 #include "ui/gfx/rect.h"
34 #include "ui/surface/transport_dib.h"
36 class SkBitmap;
38 struct AccessibilityHostMsg_EventParams;
39 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
40 struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params;
41 struct ViewHostMsg_SelectionBounds_Params;
42 struct ViewHostMsg_TextInputState_Params;
44 namespace media {
45 class VideoFrame;
48 namespace blink {
49 struct WebScreenInfo;
52 namespace content {
53 class BrowserAccessibilityDelegate;
54 class BrowserAccessibilityManager;
55 class SyntheticGesture;
56 class SyntheticGestureTarget;
57 class WebCursor;
58 struct DidOverscrollParams;
59 struct NativeWebKeyboardEvent;
60 struct WebPluginGeometry;
62 // Basic implementation shared by concrete RenderWidgetHostView subclasses.
63 class CONTENT_EXPORT RenderWidgetHostViewBase : public RenderWidgetHostView,
64 public IPC::Listener {
65 public:
66 virtual ~RenderWidgetHostViewBase();
68 // RenderWidgetHostView implementation.
69 virtual void SetBackgroundOpaque(bool opaque) OVERRIDE;
70 virtual bool GetBackgroundOpaque() OVERRIDE;
71 virtual ui::TextInputClient* GetTextInputClient() OVERRIDE;
72 virtual bool IsShowingContextMenu() const OVERRIDE;
73 virtual void SetShowingContextMenu(bool showing_menu) OVERRIDE;
74 virtual base::string16 GetSelectedText() const OVERRIDE;
75 virtual bool IsMouseLocked() OVERRIDE;
76 virtual gfx::Size GetVisibleViewportSize() const OVERRIDE;
77 virtual void SetInsets(const gfx::Insets& insets) OVERRIDE;
78 virtual void BeginFrameSubscription(
79 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) OVERRIDE;
80 virtual void EndFrameSubscription() OVERRIDE;
82 // IPC::Listener implementation:
83 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
85 // Called by the host when the input flush has completed.
86 void OnDidFlushInput();
88 void SetPopupType(blink::WebPopupType popup_type);
90 blink::WebPopupType GetPopupType();
92 // Return a value that is incremented each time the renderer swaps a new frame
93 // to the view.
94 uint32 RendererFrameNumber();
96 // Called each time the RenderWidgetHost receives a new frame for display from
97 // the renderer.
98 void DidReceiveRendererFrame();
100 // Notification that a resize or move session ended on the native widget.
101 void UpdateScreenInfo(gfx::NativeView view);
103 // Tells if the display property (work area/scale factor) has
104 // changed since the last time.
105 bool HasDisplayPropertyChanged(gfx::NativeView view);
107 base::WeakPtr<RenderWidgetHostViewBase> GetWeakPtr();
109 //----------------------------------------------------------------------------
110 // The following methods can be overridden by derived classes.
112 // Notifies the View that the renderer text selection has changed.
113 virtual void SelectionChanged(const base::string16& text,
114 size_t offset,
115 const gfx::Range& range);
117 // The requested size of the renderer. May differ from GetViewBounds().size()
118 // when the view requires additional throttling.
119 virtual gfx::Size GetRequestedRendererSize() const;
121 // The size of the view's backing surface in non-DPI-adjusted pixels.
122 virtual gfx::Size GetPhysicalBackingSize() const;
124 // The amount that the viewport size given to Blink is shrunk by the URL-bar.
125 virtual float GetTopControlsLayoutHeight() const;
127 // Called prior to forwarding input event messages to the renderer, giving
128 // the view a chance to perform in-process event filtering or processing.
129 // Return values of |NOT_CONSUMED| or |UNKNOWN| will result in |input_event|
130 // being forwarded.
131 virtual InputEventAckState FilterInputEvent(
132 const blink::WebInputEvent& input_event);
134 // Called by the host when it requires an input flush; the flush call should
135 // by synchronized with BeginFrame.
136 virtual void OnSetNeedsFlushInput();
138 virtual void WheelEventAck(const blink::WebMouseWheelEvent& event,
139 InputEventAckState ack_result);
141 virtual void GestureEventAck(const blink::WebGestureEvent& event,
142 InputEventAckState ack_result);
144 // Create a platform specific SyntheticGestureTarget implementation that will
145 // be used to inject synthetic input events.
146 virtual scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget();
148 // Return true if frame subscription is supported on this platform.
149 virtual bool CanSubscribeFrame() const;
151 // Create a BrowserAccessibilityManager for this view.
152 virtual BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
153 BrowserAccessibilityDelegate* delegate);
155 virtual void AccessibilityShowMenu(const gfx::Point& point);
156 virtual gfx::Point AccessibilityOriginInScreen(const gfx::Rect& bounds);
157 virtual gfx::AcceleratedWidget AccessibilityGetAcceleratedWidget();
158 virtual gfx::NativeViewAccessible AccessibilityGetNativeViewAccessible();
160 virtual SkColorType PreferredReadbackFormat();
162 // Informs that the focused DOM node has changed.
163 virtual void FocusedNodeChanged(bool is_editable_node) {}
165 virtual void OnSwapCompositorFrame(uint32 output_surface_id,
166 scoped_ptr<cc::CompositorFrame> frame) {}
168 // Because the associated remote WebKit instance can asynchronously
169 // prevent-default on a dispatched touch event, the touch events are queued in
170 // the GestureRecognizer until invocation of ProcessAckedTouchEvent releases
171 // it to be consumed (when |ack_result| is NOT_CONSUMED OR NO_CONSUMER_EXISTS)
172 // or ignored (when |ack_result| is CONSUMED).
173 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
174 InputEventAckState ack_result) {}
176 virtual void DidOverscroll(const DidOverscrollParams& params) {}
178 virtual void DidStopFlinging() {}
180 //----------------------------------------------------------------------------
181 // The following static methods are implemented by each platform.
183 static void GetDefaultScreenInfo(blink::WebScreenInfo* results);
185 //----------------------------------------------------------------------------
186 // The following pure virtual methods are implemented by derived classes.
188 // Perform all the initialization steps necessary for this object to represent
189 // a popup (such as a <select> dropdown), then shows the popup at |pos|.
190 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
191 const gfx::Rect& pos) = 0;
193 // Perform all the initialization steps necessary for this object to represent
194 // a full screen window.
195 // |reference_host_view| is the view associated with the creating page that
196 // helps to position the full screen widget on the correct monitor.
197 virtual void InitAsFullscreen(RenderWidgetHostView* reference_host_view) = 0;
199 // Notifies the View that it has become visible.
200 virtual void WasShown() = 0;
202 // Notifies the View that it has been hidden.
203 virtual void WasHidden() = 0;
205 // Moves all plugin windows as described in the given list.
206 // |scroll_offset| is the scroll offset of the render view.
207 virtual void MovePluginWindows(
208 const std::vector<WebPluginGeometry>& moves) = 0;
210 // Take focus from the associated View component.
211 virtual void Blur() = 0;
213 // Sets the cursor to the one associated with the specified cursor_type
214 virtual void UpdateCursor(const WebCursor& cursor) = 0;
216 // Indicates whether the page has finished loading.
217 virtual void SetIsLoading(bool is_loading) = 0;
219 // Updates the type of the input method attached to the view.
220 virtual void TextInputStateChanged(
221 const ViewHostMsg_TextInputState_Params& params) = 0;
223 // Cancel the ongoing composition of the input method attached to the view.
224 virtual void ImeCancelComposition() = 0;
226 // Notifies the View that the renderer has ceased to exist.
227 virtual void RenderProcessGone(base::TerminationStatus status,
228 int error_code) = 0;
230 // Notifies the View that the renderer's host has ceased to exist.
231 // The default implementation of this is a no-op. This hack exists to fix
232 // a crash on the branch.
233 // TODO(ccameron): Clean this up.
234 // http://crbug.com/404828
235 virtual void RenderWidgetHostGone() {}
237 // Tells the View to destroy itself.
238 virtual void Destroy() = 0;
240 // Tells the View that the tooltip text for the current mouse position over
241 // the page has changed.
242 virtual void SetTooltipText(const base::string16& tooltip_text) = 0;
244 // Notifies the View that the renderer selection bounds has changed.
245 // |start_rect| and |end_rect| are the bounds end of the selection in the
246 // coordinate system of the render view. |start_direction| and |end_direction|
247 // indicates the direction at which the selection was made on touch devices.
248 virtual void SelectionBoundsChanged(
249 const ViewHostMsg_SelectionBounds_Params& params) = 0;
251 // Copies the contents of the compositing surface, providing a new SkBitmap
252 // result via an asynchronously-run |callback|. |src_subrect| is specified in
253 // layer space coordinates for the current platform (e.g., DIP for Aura/Mac,
254 // physical for Android), and is the region to be copied from this view. The
255 // copy is then scaled to a SkBitmap of size |dst_size|. |callback| is run
256 // with true on success, false otherwise. A smaller region than |src_subrect|
257 // may be copied if the underlying surface is smaller than |src_subrect|.
258 virtual void CopyFromCompositingSurface(
259 const gfx::Rect& src_subrect,
260 const gfx::Size& dst_size,
261 const base::Callback<void(bool, const SkBitmap&)>& callback,
262 const SkColorType color_type) = 0;
264 // Copies the contents of the compositing surface, populating the given
265 // |target| with YV12 image data. |src_subrect| is specified in layer space
266 // coordinates for the current platform (e.g., DIP for Aura/Mac, physical for
267 // Android), and is the region to be copied from this view. The copy is then
268 // scaled and letterboxed with black borders to fit |target|. Finally,
269 // |callback| is asynchronously run with true/false for
270 // success/failure. |target| must point to an allocated, YV12 video frame of
271 // the intended size. This operation will fail if there is no available
272 // compositing surface.
273 virtual void CopyFromCompositingSurfaceToVideoFrame(
274 const gfx::Rect& src_subrect,
275 const scoped_refptr<media::VideoFrame>& target,
276 const base::Callback<void(bool)>& callback) = 0;
278 // Returns true if CopyFromCompositingSurfaceToVideoFrame() is likely to
279 // succeed.
281 // TODO(nick): When VideoFrame copies are broadly implemented, this method
282 // should be renamed to HasCompositingSurface(), or unified with
283 // IsSurfaceAvailableForCopy() and HasAcceleratedSurface().
284 virtual bool CanCopyToVideoFrame() const = 0;
286 // Called when an accelerated compositing surface is initialized.
287 virtual void AcceleratedSurfaceInitialized(int host_id, int route_id) = 0;
288 // |params.window| and |params.surface_id| indicate which accelerated
289 // surface's buffers swapped. |params.renderer_id| and |params.route_id|
290 // are used to formulate a reply to the GPU process to prevent it from getting
291 // too far ahead. They may all be zero, in which case no flow control is
292 // enforced; this case is currently used for accelerated plugins.
293 virtual void AcceleratedSurfaceBuffersSwapped(
294 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
295 int gpu_host_id) = 0;
296 // Similar to above, except |params.(x|y|width|height)| define the region
297 // of the surface that changed.
298 virtual void AcceleratedSurfacePostSubBuffer(
299 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
300 int gpu_host_id) = 0;
302 // Release the accelerated surface temporarily. It will be recreated on the
303 // next swap buffers or post sub buffer.
304 virtual void AcceleratedSurfaceSuspend() = 0;
306 virtual void AcceleratedSurfaceRelease() = 0;
308 // Return true if the view has an accelerated surface that contains the last
309 // presented frame for the view. If |desired_size| is non-empty, true is
310 // returned only if the accelerated surface size matches.
311 virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) = 0;
313 // Compute the orientation type of the display assuming it is a mobile device.
314 static blink::WebScreenOrientationType GetOrientationTypeForMobile(
315 const gfx::Display& display);
317 // Compute the orientation type of the display assuming it is a desktop.
318 static blink::WebScreenOrientationType GetOrientationTypeForDesktop(
319 const gfx::Display& display);
321 virtual void GetScreenInfo(blink::WebScreenInfo* results) = 0;
323 // Gets the bounds of the window, in screen coordinates.
324 virtual gfx::Rect GetBoundsInRootWindow() = 0;
326 virtual gfx::GLSurfaceHandle GetCompositingSurface() = 0;
328 virtual void OnTextSurroundingSelectionResponse(const base::string16& content,
329 size_t start_offset,
330 size_t end_offset) {};
332 #if defined(OS_ANDROID)
333 virtual void ShowDisambiguationPopup(const gfx::Rect& target_rect,
334 const SkBitmap& zoomed_bitmap) = 0;
336 // Instructs the view to not drop the surface even when the view is hidden.
337 virtual void LockCompositingSurface() = 0;
338 virtual void UnlockCompositingSurface() = 0;
339 #endif
341 #if defined(OS_MACOSX)
342 // Does any event handling necessary for plugin IME; should be called after
343 // the plugin has already had a chance to process the event. If plugin IME is
344 // not enabled, this is a no-op, so it is always safe to call.
345 // Returns true if the event was handled by IME.
346 virtual bool PostProcessEventForPluginIme(
347 const NativeWebKeyboardEvent& event) = 0;
348 #endif
350 #if defined(OS_MACOSX) || defined(USE_AURA)
351 // Updates the range of the marked text in an IME composition.
352 virtual void ImeCompositionRangeChanged(
353 const gfx::Range& range,
354 const std::vector<gfx::Rect>& character_bounds) = 0;
355 #endif
357 #if defined(OS_WIN)
358 virtual void SetParentNativeViewAccessible(
359 gfx::NativeViewAccessible accessible_parent) = 0;
361 // Returns an HWND that's given as the parent window for windowless Flash to
362 // workaround crbug.com/301548.
363 virtual gfx::NativeViewId GetParentForWindowlessPlugin() const = 0;
365 // The callback that DetachPluginsHelper calls for each child window. Call
366 // this directly if you want to do custom filtering on plugin windows first.
367 static void DetachPluginWindowsCallback(HWND window);
368 #endif
370 protected:
371 // Interface class only, do not construct.
372 RenderWidgetHostViewBase();
374 #if defined(OS_WIN)
375 // Shared implementation of MovePluginWindows for use by win and aura/wina.
376 static void MovePluginWindowsHelper(
377 HWND parent,
378 const std::vector<WebPluginGeometry>& moves);
380 static void PaintPluginWindowsHelper(
381 HWND parent,
382 const gfx::Rect& damaged_screen_rect);
384 // Needs to be called before the HWND backing the view goes away to avoid
385 // crashes in Windowed plugins.
386 static void DetachPluginsHelper(HWND parent);
387 #endif
389 // Whether this view is a popup and what kind of popup it is (select,
390 // autofill...).
391 blink::WebPopupType popup_type_;
393 // When false, the background of the web content is not fully opaque.
394 bool background_opaque_;
396 // While the mouse is locked, the cursor is hidden from the user. Mouse events
397 // are still generated. However, the position they report is the last known
398 // mouse position just as mouse lock was entered; the movement they report
399 // indicates what the change in position of the mouse would be had it not been
400 // locked.
401 bool mouse_locked_;
403 // Whether we are showing a context menu.
404 bool showing_context_menu_;
406 // A buffer containing the text inside and around the current selection range.
407 base::string16 selection_text_;
409 // The offset of the text stored in |selection_text_| relative to the start of
410 // the web page.
411 size_t selection_text_offset_;
413 // The current selection range relative to the start of the web page.
414 gfx::Range selection_range_;
416 protected:
417 // The scale factor of the display the renderer is currently on.
418 float current_device_scale_factor_;
420 // The orientation of the display the renderer is currently on.
421 gfx::Display::Rotation current_display_rotation_;
423 // Whether pinch-to-zoom should be enabled and pinch events forwarded to the
424 // renderer.
425 bool pinch_zoom_enabled_;
427 private:
428 void FlushInput();
430 gfx::Rect current_display_area_;
432 uint32 renderer_frame_number_;
434 base::OneShotTimer<RenderWidgetHostViewBase> flush_input_timer_;
436 base::WeakPtrFactory<RenderWidgetHostViewBase> weak_factory_;
438 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewBase);
441 } // namespace content
443 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_