#include "base/time/time.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
+#include "cc/resources/shared_bitmap.h"
+#include "content/browser/renderer_host/event_with_latency_info.h"
#include "content/browser/renderer_host/input/input_ack_handler.h"
#include "content/browser/renderer_host/input/input_router_client.h"
#include "content/browser/renderer_host/input/synthetic_gesture.h"
+#include "content/browser/renderer_host/input/touch_emulator_client.h"
+#include "content/common/input/input_event_ack_state.h"
#include "content/common/input/synthetic_gesture_packet.h"
#include "content/common/view_message_enums.h"
-#include "content/port/browser/event_with_latency_info.h"
-#include "content/port/common/input_event_ack_state.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/common/page_zoom.h"
#include "ipc/ipc_listener.h"
struct AcceleratedSurfaceMsg_BufferPresented_Params;
struct ViewHostMsg_BeginSmoothScroll_Params;
-struct ViewHostMsg_CompositorSurfaceBuffersSwapped_Params;
struct ViewHostMsg_SelectionBounds_Params;
struct ViewHostMsg_TextInputState_Params;
struct ViewHostMsg_UpdateRect_Params;
#endif
namespace content {
-class BackingStore;
+class BrowserAccessibilityManager;
class InputRouter;
class MockRenderWidgetHost;
-class OverscrollController;
class RenderWidgetHostDelegate;
-class RenderWidgetHostViewPort;
+class RenderWidgetHostViewBase;
class SyntheticGestureController;
class TimeoutMonitor;
+class TouchEmulator;
class WebCursor;
struct EditCommand;
// This implements the RenderWidgetHost interface that is exposed to
// embedders of content, and adds things only visible to content.
-class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost,
- public InputRouterClient,
- public InputAckHandler,
- public IPC::Listener {
+class CONTENT_EXPORT RenderWidgetHostImpl
+ : virtual public RenderWidgetHost,
+ public InputRouterClient,
+ public InputAckHandler,
+ public TouchEmulatorClient,
+ public IPC::Listener {
public:
// routing_id can be MSG_ROUTING_NONE, in which case the next available
// routing id is taken from the RenderProcessHost.
const gfx::Rect& src_rect,
const gfx::Size& accelerated_dst_size,
const base::Callback<void(bool, const SkBitmap&)>& callback,
- const SkBitmap::Config& bitmap_config) OVERRIDE;
+ const SkColorType color_type) OVERRIDE;
virtual bool CanCopyFromBackingStore() OVERRIDE;
#if defined(OS_ANDROID)
virtual void LockBackingStore() OVERRIDE;
virtual void UnlockBackingStore() OVERRIDE;
#endif
-#if defined(TOOLKIT_GTK)
- virtual bool CopyFromBackingStoreToGtkWindow(const gfx::Rect& dest_rect,
- GdkWindow* target) OVERRIDE;
-#elif defined(OS_MACOSX)
- virtual gfx::Size GetBackingStoreSize() OVERRIDE;
- virtual bool CopyFromBackingStoreToCGContext(const CGRect& dest_rect,
- CGContextRef target) OVERRIDE;
-#endif
- virtual void EnableFullAccessibilityMode() OVERRIDE;
- virtual bool IsFullAccessibilityModeForTesting() OVERRIDE;
- virtual void EnableTreeOnlyAccessibilityMode() OVERRIDE;
- virtual bool IsTreeOnlyAccessibilityModeForTesting() OVERRIDE;
virtual void ForwardMouseEvent(
const blink::WebMouseEvent& mouse_event) OVERRIDE;
virtual void ForwardWheelEvent(
const blink::WebMouseWheelEvent& wheel_event) OVERRIDE;
virtual void ForwardKeyboardEvent(
const NativeWebKeyboardEvent& key_event) OVERRIDE;
- virtual const gfx::Vector2d& GetLastScrollOffset() const OVERRIDE;
virtual RenderProcessHost* GetProcess() const OVERRIDE;
virtual int GetRoutingID() const OVERRIDE;
virtual RenderWidgetHostView* GetView() const OVERRIDE;
virtual bool IsLoading() const OVERRIDE;
virtual bool IsRenderView() const OVERRIDE;
- virtual void Replace(const base::string16& word) OVERRIDE;
- virtual void ReplaceMisspelling(const base::string16& word) OVERRIDE;
virtual void ResizeRectChanged(const gfx::Rect& new_rect) OVERRIDE;
virtual void RestartHangMonitorTimeout() OVERRIDE;
virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE;
- virtual void Stop() OVERRIDE;
virtual void WasResized() OVERRIDE;
virtual void AddKeyPressEventCallback(
const KeyPressEventCallback& callback) OVERRIDE;
virtual void RemoveMouseEventCallback(
const MouseEventCallback& callback) OVERRIDE;
virtual void GetWebScreenInfo(blink::WebScreenInfo* result) OVERRIDE;
- virtual void GetSnapshotFromRenderer(
- const gfx::Rect& src_subrect,
- const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE;
- virtual SkBitmap::Config PreferredReadbackFormat() OVERRIDE;
+ virtual SkColorType PreferredReadbackFormat() OVERRIDE;
+
+ // Forces redraw in the renderer and when the update reaches the browser
+ // grabs snapshot from the compositor. Returns PNG-encoded snapshot.
+ void GetSnapshotFromBrowser(
+ const base::Callback<void(const unsigned char*,size_t)> callback);
const NativeWebKeyboardEvent* GetLastKeyboardEvent() const;
void InvalidateScreenInfo();
// Sets the View of this RenderWidgetHost.
- void SetView(RenderWidgetHostView* view);
+ void SetView(RenderWidgetHostViewBase* view);
int surface_id() const { return surface_id_; }
// Sends a message to the corresponding object in the renderer.
virtual bool Send(IPC::Message* msg) OVERRIDE;
+ // Indicates if the page has finished loading.
+ virtual void SetIsLoading(bool is_loading);
+
// Called to notify the RenderWidget that it has been hidden or restored from
// having been hidden.
- void WasHidden();
- void WasShown();
+ virtual void WasHidden();
+ virtual void WasShown(const ui::LatencyInfo& latency_info);
// Returns true if the RenderWidget is hidden.
bool is_hidden() const { return is_hidden_; }
// Noifies the RenderWidget of the current mouse cursor visibility state.
void SendCursorVisibilityState(bool is_visible);
- // Tells us whether the page is rendered directly via the GPU process.
- bool is_accelerated_compositing_active() {
- return is_accelerated_compositing_active_;
- }
-
// Notifies the RenderWidgetHost that the View was destroyed.
void ViewDestroyed();
- // Indicates if the page has finished loading.
- void SetIsLoading(bool is_loading);
-
+#if defined(OS_MACOSX)
// Pause for a moment to wait for pending repaint or resize messages sent to
// the renderer to arrive. If pending resize messages are for an old window
// size, then also pump through a new resize message if there is time.
// Whether pausing may be useful.
bool CanPauseForPendingResizeOrRepaints();
- // Check for the existance of a BackingStore of the given |desired_size| and
- // return it if it exists. If the BackingStore is GPU, true is returned and
- // |*backing_store| is set to NULL.
- bool TryGetBackingStore(const gfx::Size& desired_size,
- BackingStore** backing_store);
-
- // Get access to the widget's backing store matching the size of the widget's
- // view. If you pass |force_create| as true, then GetBackingStore may block
- // for the renderer to send a new frame. Otherwise, NULL will be returned if
- // the backing store doesn't already exist. It will also return NULL if the
- // backing store could not be created.
- //
- // Mac only: NULL may also be returned if the last frame was GPU accelerated.
- // Call GetView()->HasAcceleratedSurface to determine if the last frame was
- // accelerated.
- BackingStore* GetBackingStore(bool force_create);
-
- // Allocate a new backing store of the given size. Returns NULL on failure
- // (for example, if we don't currently have a RenderWidgetHostView.)
- BackingStore* AllocBackingStore(const gfx::Size& size);
+ // Wait for a surface matching the size of the widget's view, possibly
+ // blocking until the renderer sends a new frame.
+ void WaitForSurface();
+#endif
- // When a backing store does asynchronous painting, it will call this function
- // when it is done with the DIB. We will then forward a message to the
- // renderer to send another paint.
- void DonePaintingToBackingStore();
+ bool resize_ack_pending_for_testing() { return resize_ack_pending_; }
// GPU accelerated version of GetBackingStore function. This will
// trigger a re-composite to the view. It may fail if a resize is pending, or
// Forwards the given message to the renderer. These are called by the view
// when it has received a message.
- void ForwardGestureEvent(const blink::WebGestureEvent& gesture_event);
void ForwardGestureEventWithLatencyInfo(
const blink::WebGestureEvent& gesture_event,
const ui::LatencyInfo& ui_latency);
const blink::WebMouseWheelEvent& wheel_event,
const ui::LatencyInfo& ui_latency);
+ // Enables/disables touch emulation using mouse event. See TouchEmulator.
+ void SetTouchEventEmulationEnabled(bool enabled);
+
+ // TouchEmulatorClient implementation.
+ virtual void ForwardGestureEvent(
+ const blink::WebGestureEvent& gesture_event) OVERRIDE;
+ virtual void ForwardEmulatedTouchEvent(
+ const blink::WebTouchEvent& touch_event) OVERRIDE;
+ virtual void SetCursor(const WebCursor& cursor) OVERRIDE;
+ virtual void ShowContextMenuAtPoint(const gfx::Point& point) OVERRIDE;
+
// Queues a synthetic gesture for testing purposes. Invokes the on_complete
// callback when the gesture is finished running.
void QueueSyntheticGesture(
// perform an action. See OnUserGesture for more details.
void StartUserGesture();
- // Set the RenderView background.
- void SetBackground(const SkBitmap& background);
+ // Set the RenderView background transparency.
+ void SetBackgroundOpaque(bool opaque);
// Notifies the renderer that the next key event is bound to one or more
// pre-defined edit commands
void SetEditCommandsForNextKeyEvent(
const std::vector<EditCommand>& commands);
- // Gets the accessibility mode.
- AccessibilityMode accessibility_mode() const {
- return accessibility_mode_;
- }
-
- // Adds the given accessibility mode to the current accessibility mode bitmap.
- void AddAccessibilityMode(AccessibilityMode mode);
-
- // Removes the given accessibility mode from the current accessibility mode
- // bitmap, managing the bits that are shared with other modes such that a
- // bit will only be turned off when all modes that depend on it have been
- // removed.
- void RemoveAccessibilityMode(AccessibilityMode mode);
-
- // Resets the accessibility mode to the default setting in
- // BrowserStateAccessibilityImpl.
- void ResetAccessibilityMode();
-
- // Relay a request from assistive technology to perform the default action
- // on a given node.
- void AccessibilityDoDefaultAction(int object_id);
-
- // Relay a request from assistive technology to set focus to a given node.
- void AccessibilitySetFocus(int object_id);
-
- // Relay a request from assistive technology to make a given object
- // visible by scrolling as many scrollable containers as necessary.
- // In addition, if it's not possible to make the entire object visible,
- // scroll so that the |subfocus| rect is visible at least. The subfocus
- // rect is in local coordinates of the object itself.
- void AccessibilityScrollToMakeVisible(
- int acc_obj_id, gfx::Rect subfocus);
-
- // Relay a request from assistive technology to move a given object
- // to a specific location, in the WebContents area coordinate space, i.e.
- // (0, 0) is the top-left corner of the WebContents.
- void AccessibilityScrollToPoint(int acc_obj_id, gfx::Point point);
-
- // Relay a request from assistive technology to set text selection.
- void AccessibilitySetTextSelection(
- int acc_obj_id, int start_offset, int end_offset);
-
- // Kill the renderer because we got a fatal accessibility error.
- void FatalAccessibilityTreeError();
-
-#if defined(OS_WIN)
- void SetParentNativeViewAccessible(
- gfx::NativeViewAccessible accessible_parent);
- gfx::NativeViewAccessible GetParentNativeViewAccessible() const;
-#endif
-
// Executes the edit command on the RenderView.
void ExecuteEditCommand(const std::string& command,
const std::string& value);
int renderer_host_id,
const cc::CompositorFrameAck& ack);
- // Called by the view in response to AcceleratedSurfaceBuffersSwapped for
- // platforms that support deferred GPU process descheduling. This does
- // nothing if the compositor thread is enabled.
- // TODO(jbates) Once the compositor thread is always on, this can be removed.
- void AcknowledgeSwapBuffersToRenderer();
-
- bool is_threaded_compositing_enabled() const {
- return is_threaded_compositing_enabled_;
- }
-
void set_allow_privileged_mouse_lock(bool allow) {
allow_privileged_mouse_lock_ = allow;
}
// Update the renderer's cache of the screen rect of the view and window.
void SendScreenRects();
- OverscrollController* overscroll_controller() const {
- return overscroll_controller_.get();
- }
-
- // Sets whether the overscroll controller should be enabled for this page.
- void SetOverscrollControllerEnabled(bool enabled);
-
// Suppreses future char events until a keydown. See
// suppress_next_char_events_.
void SuppressNextCharEvents();
InputRouter* input_router() { return input_router_.get(); }
+ // Get the BrowserAccessibilityManager for the root of the frame tree,
+ BrowserAccessibilityManager* GetRootBrowserAccessibilityManager();
+
+ // Get the BrowserAccessibilityManager for the root of the frame tree,
+ // or create it if it doesn't already exist.
+ BrowserAccessibilityManager* GetOrCreateRootBrowserAccessibilityManager();
+
+#if defined(OS_WIN)
+ gfx::NativeViewAccessible GetParentNativeViewAccessible();
+#endif
+
protected:
virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() OVERRIDE;
// component if it is not already in |original|. And if |original| is
// not NULL, it is also merged into the resulting LatencyInfo.
ui::LatencyInfo CreateRWHLatencyInfoIfNotExist(
- const ui::LatencyInfo* original, blink::WebInputEvent::Type type);
+ const ui::LatencyInfo* original,
+ blink::WebInputEvent::Type type,
+ const ui::LatencyInfo::InputCoordinate* logical_coordinates,
+ size_t logical_coordinates_size);
// Called when we receive a notification indicating that the renderer
// process has gone. This will reset our state so that our state will be
int increment_in_flight_event_count() { return ++in_flight_event_count_; }
int decrement_in_flight_event_count() { return --in_flight_event_count_; }
- // Returns whether an overscroll gesture is in progress.
- bool IsInOverscrollGesture() const;
-
// The View associated with the RenderViewHost. The lifetime of this object
// is associated with the lifetime of the Render process. If the Renderer
// crashes, its View is destroyed and this pointer becomes NULL, even though
// render_view_host_ lives on to load another URL (creating a new View while
// doing so).
- RenderWidgetHostViewPort* view_;
+ RenderWidgetHostViewBase* view_;
+
+ // A weak pointer to the view. The above pointer should be weak, but changing
+ // that to be weak causes crashes on Android.
+ // TODO(ccameron): Fix this.
+ // http://crbug.com/404828
+ base::WeakPtr<RenderWidgetHostViewBase> view_weak_;
// true if a renderer has once been valid. We use this flag to display a sad
// tab only when we lose our renderer and not if a paint occurs during
void OnRequestMove(const gfx::Rect& pos);
void OnSetTooltipText(const base::string16& tooltip_text,
blink::WebTextDirection text_direction_hint);
-#if defined(OS_MACOSX)
- void OnCompositorSurfaceBuffersSwapped(
- const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params& params);
-#endif
bool OnSwapCompositorFrame(const IPC::Message& message);
- void OnOverscrolled(gfx::Vector2dF accumulated_overscroll,
- gfx::Vector2dF current_fling_velocity);
void OnFlingingStopped();
void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
- void OnUpdateIsDelayed();
void OnQueueSyntheticGesture(const SyntheticGesturePacket& gesture_packet);
virtual void OnFocus();
virtual void OnBlur();
void OnSetCursor(const WebCursor& cursor);
- void OnTextInputTypeChanged(ui::TextInputType type,
- ui::TextInputMode input_mode,
- bool can_compose_inline);
-#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
+ void OnTextInputStateChanged(
+ const ViewHostMsg_TextInputState_Params& params);
+
+#if defined(OS_MACOSX) || defined(USE_AURA)
void OnImeCompositionRangeChanged(
const gfx::Range& range,
const std::vector<gfx::Rect>& character_bounds);
#endif
void OnImeCancelComposition();
- void OnDidActivateAcceleratedCompositing(bool activated);
void OnLockMouse(bool user_gesture,
bool last_unlocked_by_target,
bool privileged);
void OnUnlockMouse();
- void OnShowDisambiguationPopup(const gfx::Rect& rect,
+ void OnShowDisambiguationPopup(const gfx::Rect& rect_pixels,
const gfx::Size& size,
- const TransportDIB::Id& id);
+ const cc::SharedBitmapId& id);
#if defined(OS_WIN)
void OnWindowlessPluginDummyWindowCreated(
gfx::NativeViewId dummy_activation_window);
void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params,
const base::TimeTicks& paint_start);
- // Paints the given bitmap to the current backing store at the given
- // location. Returns true if the passed callback was asynchronously
- // scheduled in the future (and thus the caller must manually synchronously
- // call the callback function).
- bool PaintBackingStoreRect(TransportDIB::Id bitmap,
- const gfx::Rect& bitmap_rect,
- const std::vector<gfx::Rect>& copy_rects,
- const gfx::Size& view_size,
- float scale_factor,
- const base::Closure& completion_callback);
-
- // Scrolls the given |clip_rect| in the backing by the given dx/dy amount. The
- // |dib| and its corresponding location |bitmap_rect| in the backing store
- // is the newly painted pixels by the renderer.
- void ScrollBackingStoreRect(const gfx::Vector2d& delta,
- const gfx::Rect& clip_rect,
- const gfx::Size& view_size);
-
// Give key press listeners a chance to handle this key press. This allow
// widgets that don't have focus to still handle key presses.
bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
virtual void IncrementInFlightEventCount() OVERRIDE;
virtual void DecrementInFlightEventCount() OVERRIDE;
virtual void OnHasTouchEventHandlers(bool has_handlers) OVERRIDE;
- virtual OverscrollController* GetOverscrollController() const OVERRIDE;
virtual void DidFlush() OVERRIDE;
+ virtual void DidOverscroll(const DidOverscrollParams& params) OVERRIDE;
// InputAckHandler
virtual void OnKeyboardEventAck(const NativeWebKeyboardEvent& event,
// which may get in recursive loops).
void DelayedAutoResized();
+ void WindowOldSnapshotReachedScreen(int snapshot_id);
+
void WindowSnapshotReachedScreen(int snapshot_id);
- // Send a message to the renderer process to change the accessibility mode.
- void SetAccessibilityMode(AccessibilityMode AccessibilityMode);
+ void OnSnapshotDataReceived(int snapshot_id,
+ const unsigned char* png,
+ size_t size);
+
+ void OnSnapshotDataReceivedAsync(
+ int snapshot_id,
+ scoped_refptr<base::RefCountedBytes> png_data);
// Our delegate, which wants to know mainly about keyboard events.
// It will remain non-NULL until DetachDelegate() is called.
// Indicates whether a page is loading or not.
bool is_loading_;
- // Indicates whether a page is hidden or not.
+ // Indicates whether a page is hidden or not. It has to stay in sync with the
+ // most recent call to process_->WidgetRestored() / WidgetHidden().
bool is_hidden_;
// Indicates whether a page is fullscreen or not.
bool is_fullscreen_;
- // True when a page is rendered directly via the GPU process.
- bool is_accelerated_compositing_active_;
-
- // True if threaded compositing is enabled on this view.
- bool is_threaded_compositing_enabled_;
-
// Set if we are waiting for a repaint ack for the view.
bool repaint_ack_pending_;
// The size of the view's backing surface in non-DPI-adjusted pixels.
gfx::Size physical_backing_size_;
- // 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).
- float overdraw_bottom_height_;
+ // The amount that the viewport size given to Blink was shrunk by the URL-bar
+ // (always 0 on platforms where URL-bar hiding isn't supported).
+ float top_controls_layout_height_;
+
+ // The size of the visible viewport, which may be smaller than the view if the
+ // view is partially occluded (e.g. by a virtual keyboard). The size is in
+ // DPI-adjusted pixels.
+ gfx::Size visible_viewport_size_;
// The size we last sent as requested size to the renderer. |current_size_|
// is only updated once the resize message has been ack'd. This on the other
gfx::Rect last_view_screen_rect_;
gfx::Rect last_window_screen_rect_;
- AccessibilityMode accessibility_mode_;
-
// Keyboard event listeners.
std::vector<KeyPressEventCallback> key_press_event_callbacks_;
// Flag to detect recursive calls to GetBackingStore().
bool in_get_backing_store_;
- // Flag to trigger the GetBackingStore method to abort early.
- bool abort_get_backing_store_;
-
- // Set when we call DidPaintRect/DidScrollRect on the view.
- bool view_being_painted_;
-
// Used for UMA histogram logging to measure the time for a repaint view
// operation to finish.
base::TimeTicks repaint_start_time_;
// changed.
bool suppress_next_char_events_;
- // The last scroll offset of the render widget.
- gfx::Vector2d last_scroll_offset_;
-
bool pending_mouse_lock_request_;
bool allow_privileged_mouse_lock_;
// not sent to the renderer.
bool has_touch_handler_;
- base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
-
scoped_ptr<SyntheticGestureController> synthetic_gesture_controller_;
+ scoped_ptr<TouchEmulator> touch_emulator_;
+
// Receives and handles all input events.
scoped_ptr<InputRouter> input_router_;
- scoped_ptr<OverscrollController> overscroll_controller_;
-
scoped_ptr<TimeoutMonitor> hang_monitor_timeout_;
#if defined(OS_WIN)
std::list<HWND> dummy_windows_for_activation_;
#endif
- // List of callbacks for pending snapshot requests to the renderer.
- std::queue<base::Callback<void(bool, const SkBitmap&)> > pending_snapshots_;
-
int64 last_input_number_;
+ int next_browser_snapshot_id_;
+ typedef std::map<int,
+ base::Callback<void(const unsigned char*, size_t)> > PendingSnapshotMap;
+ PendingSnapshotMap pending_browser_snapshots_;
+
+ base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl);
};