Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / render_widget_host_view_base.h
index 1e8103c..7dd8676 100644 (file)
@@ -9,88 +9,93 @@
 #include <OpenGL/OpenGL.h>
 #endif
 
-#if defined(TOOLKIT_GTK)
-#include <gdk/gdk.h>
-#endif
-
 #include <string>
 #include <vector>
 
 #include "base/memory/scoped_ptr.h"
 #include "base/callback_forward.h"
+#include "base/process/kill.h"
 #include "base/timer/timer.h"
+#include "cc/output/compositor_frame.h"
+#include "content/browser/renderer_host/event_with_latency_info.h"
 #include "content/common/content_export.h"
-#include "content/port/browser/render_widget_host_view_port.h"
+#include "content/common/input/input_event_ack_state.h"
+#include "content/public/browser/render_widget_host_view.h"
+#include "ipc/ipc_listener.h"
+#include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
+#include "third_party/WebKit/public/web/WebPopupType.h"
+#include "third_party/WebKit/public/web/WebTextDirection.h"
+#include "ui/base/ime/text_input_mode.h"
+#include "ui/base/ime/text_input_type.h"
+#include "ui/gfx/display.h"
 #include "ui/gfx/native_widget_types.h"
 #include "ui/gfx/range/range.h"
 #include "ui/gfx/rect.h"
+#include "ui/surface/transport_dib.h"
 
-namespace content {
+class SkBitmap;
+
+struct AccessibilityHostMsg_EventParams;
+struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
+struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params;
+struct ViewHostMsg_SelectionBounds_Params;
+struct ViewHostMsg_TextInputState_Params;
 
-class RenderWidgetHostImpl;
-
-// Basic implementation shared by concrete RenderWidgetHostView
-// subclasses.
-//
-// Note that nothing should use this class, except concrete subclasses
-// that are deriving from it, and code that is written specifically to
-// use one of these concrete subclasses (i.e. platform-specific code).
-//
-// To enable embedders that add ports, everything else in content/
-// should use the RenderWidgetHostViewPort interface.
-//
-// RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
-class CONTENT_EXPORT RenderWidgetHostViewBase
-    : public RenderWidgetHostViewPort {
+namespace media {
+class VideoFrame;
+}
+
+namespace blink {
+struct WebScreenInfo;
+}
+
+namespace content {
+class BrowserAccessibilityDelegate;
+class BrowserAccessibilityManager;
+class SyntheticGesture;
+class SyntheticGestureTarget;
+class WebCursor;
+struct DidOverscrollParams;
+struct NativeWebKeyboardEvent;
+struct WebPluginGeometry;
+
+// Basic implementation shared by concrete RenderWidgetHostView subclasses.
+class CONTENT_EXPORT RenderWidgetHostViewBase : public RenderWidgetHostView,
+                                                public IPC::Listener {
  public:
   virtual ~RenderWidgetHostViewBase();
 
-  // RenderWidgetHostViewPort implementation.
-  virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
-  virtual void SelectionChanged(const base::string16& text,
-                                size_t offset,
-                                const gfx::Range& range) OVERRIDE;
-  virtual void SetBackground(const SkBitmap& background) OVERRIDE;
-  virtual const SkBitmap& GetBackground() OVERRIDE;
-  virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE;
-  virtual float GetOverdrawBottomHeight() const OVERRIDE;
+  // RenderWidgetHostView implementation.
+  virtual void SetBackgroundOpaque(bool opaque) OVERRIDE;
+  virtual bool GetBackgroundOpaque() OVERRIDE;
+  virtual ui::TextInputClient* GetTextInputClient() OVERRIDE;
   virtual bool IsShowingContextMenu() const OVERRIDE;
   virtual void SetShowingContextMenu(bool showing_menu) OVERRIDE;
   virtual base::string16 GetSelectedText() const OVERRIDE;
   virtual bool IsMouseLocked() OVERRIDE;
-  virtual void UnhandledWheelEvent(
-      const blink::WebMouseWheelEvent& event) OVERRIDE;
-  virtual InputEventAckState FilterInputEvent(
-      const blink::WebInputEvent& input_event) OVERRIDE;
-  virtual void OnSetNeedsFlushInput() OVERRIDE;
-  virtual void OnDidFlushInput() OVERRIDE;
-  virtual void GestureEventAck(int gesture_event_type,
-                               InputEventAckState ack_result) OVERRIDE;
-  virtual void SetPopupType(blink::WebPopupType popup_type) OVERRIDE;
-  virtual blink::WebPopupType GetPopupType() OVERRIDE;
-  virtual BrowserAccessibilityManager*
-      GetBrowserAccessibilityManager() const OVERRIDE;
-  virtual void CreateBrowserAccessibilityManagerIfNeeded() OVERRIDE;
-  virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
-                                      InputEventAckState ack_result) OVERRIDE;
-  virtual scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget()
-      OVERRIDE;
-  virtual void FocusedNodeChanged(bool is_editable_node) OVERRIDE;
-  virtual bool CanSubscribeFrame() const OVERRIDE;
+  virtual gfx::Size GetVisibleViewportSize() const OVERRIDE;
+  virtual void SetInsets(const gfx::Insets& insets) OVERRIDE;
   virtual void BeginFrameSubscription(
       scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) OVERRIDE;
   virtual void EndFrameSubscription() OVERRIDE;
-  virtual void OnSwapCompositorFrame(
-      uint32 output_surface_id,
-      scoped_ptr<cc::CompositorFrame> frame) OVERRIDE {}
-  virtual void ResizeCompositingSurface(const gfx::Size&) OVERRIDE {}
-  virtual void OnOverscrolled(gfx::Vector2dF accumulated_overscroll,
-                              gfx::Vector2dF current_fling_velocity) OVERRIDE;
-  virtual void DidStopFlinging() OVERRIDE {}
-  virtual uint32 RendererFrameNumber() OVERRIDE;
-  virtual void DidReceiveRendererFrame() OVERRIDE;
-
-  void SetBrowserAccessibilityManager(BrowserAccessibilityManager* manager);
+
+  // IPC::Listener implementation:
+  virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
+
+  // Called by the host when the input flush has completed.
+  void OnDidFlushInput();
+
+  void SetPopupType(blink::WebPopupType popup_type);
+
+  blink::WebPopupType GetPopupType();
+
+  // Return a value that is incremented each time the renderer swaps a new frame
+  // to the view.
+  uint32 RendererFrameNumber();
+
+  // Called each time the RenderWidgetHost receives a new frame for display from
+  // the renderer.
+  void DidReceiveRendererFrame();
 
   // Notification that a resize or move session ended on the native widget.
   void UpdateScreenInfo(gfx::NativeView view);
@@ -99,7 +104,259 @@ class CONTENT_EXPORT RenderWidgetHostViewBase
   // changed since the last time.
   bool HasDisplayPropertyChanged(gfx::NativeView view);
 
+  //----------------------------------------------------------------------------
+  // The following methods can be overridden by derived classes.
+
+  // Notifies the View that the renderer text selection has changed.
+  virtual void SelectionChanged(const base::string16& text,
+                                size_t offset,
+                                const gfx::Range& range);
+
+  // The requested size of the renderer. May differ from GetViewBounds().size()
+  // when the view requires additional throttling.
+  virtual gfx::Size GetRequestedRendererSize() const;
+
+  // The size of the view's backing surface in non-DPI-adjusted pixels.
+  virtual gfx::Size GetPhysicalBackingSize() const;
+
+  // The height of the physical backing surface that is overdrawn opaquely in
+  // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
+  virtual float GetOverdrawBottomHeight() const;
+
+  // Called prior to forwarding input event messages to the renderer, giving
+  // the view a chance to perform in-process event filtering or processing.
+  // Return values of |NOT_CONSUMED| or |UNKNOWN| will result in |input_event|
+  // being forwarded.
+  virtual InputEventAckState FilterInputEvent(
+      const blink::WebInputEvent& input_event);
+
+  // Called by the host when it requires an input flush; the flush call should
+  // by synchronized with BeginFrame.
+  virtual void OnSetNeedsFlushInput();
+
+  virtual void WheelEventAck(const blink::WebMouseWheelEvent& event,
+                             InputEventAckState ack_result);
+
+  virtual void GestureEventAck(const blink::WebGestureEvent& event,
+                               InputEventAckState ack_result);
+
+  // Create a platform specific SyntheticGestureTarget implementation that will
+  // be used to inject synthetic input events.
+  virtual scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget();
+
+  // Return true if frame subscription is supported on this platform.
+  virtual bool CanSubscribeFrame() const;
+
+  // Create a BrowserAccessibilityManager for this view.
+  virtual BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
+      BrowserAccessibilityDelegate* delegate);
+
+  virtual void AccessibilityShowMenu(const gfx::Point& point);
+  virtual gfx::Point AccessibilityOriginInScreen(const gfx::Rect& bounds);
+  virtual gfx::AcceleratedWidget AccessibilityGetAcceleratedWidget();
+  virtual gfx::NativeViewAccessible AccessibilityGetNativeViewAccessible();
+
+  virtual SkColorType PreferredReadbackFormat();
+
+  // Informs that the focused DOM node has changed.
+  virtual void FocusedNodeChanged(bool is_editable_node) {}
+
+  virtual void OnSwapCompositorFrame(uint32 output_surface_id,
+                                     scoped_ptr<cc::CompositorFrame> frame) {}
+
+  // Because the associated remote WebKit instance can asynchronously
+  // prevent-default on a dispatched touch event, the touch events are queued in
+  // the GestureRecognizer until invocation of ProcessAckedTouchEvent releases
+  // it to be consumed (when |ack_result| is NOT_CONSUMED OR NO_CONSUMER_EXISTS)
+  // or ignored (when |ack_result| is CONSUMED).
+  virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
+                                      InputEventAckState ack_result) {}
+
+  virtual void DidOverscroll(const DidOverscrollParams& params) {}
+
+  virtual void DidStopFlinging() {}
+
+  //----------------------------------------------------------------------------
+  // The following static methods are implemented by each platform.
+
+  static void GetDefaultScreenInfo(blink::WebScreenInfo* results);
+
+  //----------------------------------------------------------------------------
+  // The following pure virtual methods are implemented by derived classes.
+
+  // Perform all the initialization steps necessary for this object to represent
+  // a popup (such as a <select> dropdown), then shows the popup at |pos|.
+  virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
+                           const gfx::Rect& pos) = 0;
+
+  // Perform all the initialization steps necessary for this object to represent
+  // a full screen window.
+  // |reference_host_view| is the view associated with the creating page that
+  // helps to position the full screen widget on the correct monitor.
+  virtual void InitAsFullscreen(RenderWidgetHostView* reference_host_view) = 0;
+
+  // Notifies the View that it has become visible.
+  virtual void WasShown() = 0;
+
+  // Notifies the View that it has been hidden.
+  virtual void WasHidden() = 0;
+
+  // Moves all plugin windows as described in the given list.
+  // |scroll_offset| is the scroll offset of the render view.
+  virtual void MovePluginWindows(
+      const std::vector<WebPluginGeometry>& moves) = 0;
+
+  // Take focus from the associated View component.
+  virtual void Blur() = 0;
+
+  // Sets the cursor to the one associated with the specified cursor_type
+  virtual void UpdateCursor(const WebCursor& cursor) = 0;
+
+  // Indicates whether the page has finished loading.
+  virtual void SetIsLoading(bool is_loading) = 0;
+
+  // Updates the type of the input method attached to the view.
+  virtual void TextInputStateChanged(
+      const ViewHostMsg_TextInputState_Params& params) = 0;
+
+  // Cancel the ongoing composition of the input method attached to the view.
+  virtual void ImeCancelComposition() = 0;
+
+  // Notifies the View that the renderer has ceased to exist.
+  virtual void RenderProcessGone(base::TerminationStatus status,
+                                 int error_code) = 0;
+
+  // Tells the View to destroy itself.
+  virtual void Destroy() = 0;
+
+  // Tells the View that the tooltip text for the current mouse position over
+  // the page has changed.
+  virtual void SetTooltipText(const base::string16& tooltip_text) = 0;
+
+  // Notifies the View that the renderer selection bounds has changed.
+  // |start_rect| and |end_rect| are the bounds end of the selection in the
+  // coordinate system of the render view. |start_direction| and |end_direction|
+  // indicates the direction at which the selection was made on touch devices.
+  virtual void SelectionBoundsChanged(
+      const ViewHostMsg_SelectionBounds_Params& params) = 0;
+
+  // Notifies the view that the scroll offset has changed.
+  virtual void ScrollOffsetChanged() = 0;
+
+  // Copies the contents of the compositing surface, providing a new SkBitmap
+  // result via an asynchronously-run |callback|. |src_subrect| is specified in
+  // layer space coordinates for the current platform (e.g., DIP for Aura/Mac,
+  // physical for Android), and is the region to be copied from this view. The
+  // copy is then scaled to a SkBitmap of size |dst_size|. |callback| is run
+  // with true on success, false otherwise. A smaller region than |src_subrect|
+  // may be copied if the underlying surface is smaller than |src_subrect|.
+  virtual void CopyFromCompositingSurface(
+      const gfx::Rect& src_subrect,
+      const gfx::Size& dst_size,
+      const base::Callback<void(bool, const SkBitmap&)>& callback,
+      const SkColorType color_type) = 0;
+
+  // Copies the contents of the compositing surface, populating the given
+  // |target| with YV12 image data. |src_subrect| is specified in layer space
+  // coordinates for the current platform (e.g., DIP for Aura/Mac, physical for
+  // Android), and is the region to be copied from this view. The copy is then
+  // scaled and letterboxed with black borders to fit |target|. Finally,
+  // |callback| is asynchronously run with true/false for
+  // success/failure. |target| must point to an allocated, YV12 video frame of
+  // the intended size. This operation will fail if there is no available
+  // compositing surface.
+  virtual void CopyFromCompositingSurfaceToVideoFrame(
+      const gfx::Rect& src_subrect,
+      const scoped_refptr<media::VideoFrame>& target,
+      const base::Callback<void(bool)>& callback) = 0;
+
+  // Returns true if CopyFromCompositingSurfaceToVideoFrame() is likely to
+  // succeed.
+  //
+  // TODO(nick): When VideoFrame copies are broadly implemented, this method
+  // should be renamed to HasCompositingSurface(), or unified with
+  // IsSurfaceAvailableForCopy() and HasAcceleratedSurface().
+  virtual bool CanCopyToVideoFrame() const = 0;
+
+  // Called when an accelerated compositing surface is initialized.
+  virtual void AcceleratedSurfaceInitialized(int host_id, int route_id) = 0;
+  // |params.window| and |params.surface_id| indicate which accelerated
+  // surface's buffers swapped. |params.renderer_id| and |params.route_id|
+  // are used to formulate a reply to the GPU process to prevent it from getting
+  // too far ahead. They may all be zero, in which case no flow control is
+  // enforced; this case is currently used for accelerated plugins.
+  virtual void AcceleratedSurfaceBuffersSwapped(
+      const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
+      int gpu_host_id) = 0;
+  // Similar to above, except |params.(x|y|width|height)| define the region
+  // of the surface that changed.
+  virtual void AcceleratedSurfacePostSubBuffer(
+      const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
+      int gpu_host_id) = 0;
+
+  // Release the accelerated surface temporarily. It will be recreated on the
+  // next swap buffers or post sub buffer.
+  virtual void AcceleratedSurfaceSuspend() = 0;
+
+  virtual void AcceleratedSurfaceRelease() = 0;
+
+  // Return true if the view has an accelerated surface that contains the last
+  // presented frame for the view. If |desired_size| is non-empty, true is
+  // returned only if the accelerated surface size matches.
+  virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) = 0;
+
+  // Compute the orientation type of the display assuming it is a mobile device.
+  static blink::WebScreenOrientationType GetOrientationTypeForMobile(
+      const gfx::Display& display);
+
+  // Compute the orientation type of the display assuming it is a desktop.
+  static blink::WebScreenOrientationType GetOrientationTypeForDesktop(
+      const gfx::Display& display);
+
+  virtual void GetScreenInfo(blink::WebScreenInfo* results) = 0;
+
+  // Gets the bounds of the window, in screen coordinates.
+  virtual gfx::Rect GetBoundsInRootWindow() = 0;
+
+  virtual gfx::GLSurfaceHandle GetCompositingSurface() = 0;
+
+  virtual void OnTextSurroundingSelectionResponse(const base::string16& content,
+                                                  size_t start_offset,
+                                                  size_t end_offset) {};
+
+#if defined(OS_ANDROID)
+  virtual void ShowDisambiguationPopup(const gfx::Rect& target_rect,
+                                       const SkBitmap& zoomed_bitmap) = 0;
+
+  // Instructs the view to not drop the surface even when the view is hidden.
+  virtual void LockCompositingSurface() = 0;
+  virtual void UnlockCompositingSurface() = 0;
+#endif
+
+#if defined(OS_MACOSX)
+  // Does any event handling necessary for plugin IME; should be called after
+  // the plugin has already had a chance to process the event. If plugin IME is
+  // not enabled, this is a no-op, so it is always safe to call.
+  // Returns true if the event was handled by IME.
+  virtual bool PostProcessEventForPluginIme(
+      const NativeWebKeyboardEvent& event) = 0;
+#endif
+
+#if defined(OS_MACOSX) || defined(USE_AURA)
+  // Updates the range of the marked text in an IME composition.
+  virtual void ImeCompositionRangeChanged(
+      const gfx::Range& range,
+      const std::vector<gfx::Rect>& character_bounds) = 0;
+#endif
+
 #if defined(OS_WIN)
+  virtual void SetParentNativeViewAccessible(
+      gfx::NativeViewAccessible accessible_parent) = 0;
+
+  // Returns an HWND that's given as the parent window for windowless Flash to
+  // workaround crbug.com/301548.
+  virtual gfx::NativeViewId GetParentForWindowlessPlugin() const = 0;
+
   // The callback that DetachPluginsHelper calls for each child window. Call
   // this directly if you want to do custom filtering on plugin windows first.
   static void DetachPluginWindowsCallback(HWND window);
@@ -128,9 +385,8 @@ class CONTENT_EXPORT RenderWidgetHostViewBase
   // autofill...).
   blink::WebPopupType popup_type_;
 
-  // A custom background to paint behind the web content. This will be tiled
-  // horizontally. Can be null, in which case we fall back to painting white.
-  SkBitmap background_;
+  // When false, the background of the web content is not fully opaque.
+  bool background_opaque_;
 
   // While the mouse is locked, the cursor is hidden from the user. Mouse events
   // are still generated. However, the position they report is the last known
@@ -156,12 +412,16 @@ protected:
   // The scale factor of the display the renderer is currently on.
   float current_device_scale_factor_;
 
+  // The orientation of the display the renderer is currently on.
+  gfx::Display::Rotation current_display_rotation_;
+
+  // Whether pinch-to-zoom should be enabled and pinch events forwarded to the
+  // renderer.
+  bool pinch_zoom_enabled_;
+
  private:
   void FlushInput();
 
-  // Manager of the tree representation of the WebKit render tree.
-  scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_;
-
   gfx::Rect current_display_area_;
 
   uint32 renderer_frame_number_;