// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_ #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_ #if defined(OS_MACOSX) #include #endif #include #include #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/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/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" class SkBitmap; struct AccessibilityHostMsg_EventParams; struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params; struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params; struct ViewHostMsg_TextInputState_Params; struct ViewHostMsg_SelectionBounds_Params; namespace media { class VideoFrame; } namespace blink { struct WebScreenInfo; } namespace content { 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(); // 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 gfx::Size GetVisibleViewportSize() const OVERRIDE; virtual void SetInsets(const gfx::Insets& insets) OVERRIDE; virtual void BeginFrameSubscription( scoped_ptr subscriber) OVERRIDE; virtual void EndFrameSubscription() OVERRIDE; // 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(); // Get the BrowserAccessibilityManager if it exists, may return NULL. BrowserAccessibilityManager* GetBrowserAccessibilityManager() const; void SetBrowserAccessibilityManager(BrowserAccessibilityManager* manager); // 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); // Tells if the display property (work area/scale factor) has // 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 CreateSyntheticGestureTarget(); // Return true if frame subscription is supported on this platform. virtual bool CanSubscribeFrame() const; // Create a BrowserAccessibilityManager for this view if it's possible to // create one and if one doesn't exist already. Some ports may not create // one depending on the current state. virtual void CreateBrowserAccessibilityManagerIfNeeded(); virtual void OnAccessibilitySetFocus(int acc_obj_id); virtual void AccessibilityShowMenu(int acc_obj_id); virtual gfx::Point AccessibilityOriginInScreen(const gfx::Rect& bounds); virtual SkBitmap::Config 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 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