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_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_
16 #include "base/callback.h"
17 #include "base/gtest_prod_util.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/weak_ptr.h"
20 #include "base/observer_list.h"
21 #include "base/process_util.h"
22 #include "base/strings/string16.h"
23 #include "base/time.h"
24 #include "base/timer.h"
25 #include "build/build_config.h"
26 #include "content/browser/renderer_host/smooth_scroll_gesture_controller.h"
27 #include "content/common/browser_rendering_stats.h"
28 #include "content/common/view_message_enums.h"
29 #include "content/port/browser/event_with_latency_info.h"
30 #include "content/port/common/input_event_ack_state.h"
31 #include "content/public/browser/render_widget_host.h"
32 #include "content/public/common/page_zoom.h"
33 #include "ipc/ipc_listener.h"
34 #include "ui/base/ime/text_input_type.h"
35 #include "ui/base/latency_info.h"
36 #include "ui/gfx/native_widget_types.h"
39 struct AcceleratedSurfaceMsg_BufferPresented_Params
;
40 struct ViewHostMsg_CompositorSurfaceBuffersSwapped_Params
;
41 struct ViewHostMsg_UpdateRect_Params
;
42 struct ViewHostMsg_TextInputState_Params
;
43 struct ViewHostMsg_BeginSmoothScroll_Params
;
50 class CompositorFrame
;
51 class CompositorFrameAck
;
62 struct WebCompositionUnderline
;
66 #if defined(OS_ANDROID)
74 class GestureEventFilter
;
75 class MockRenderWidgetHost
;
76 class OverscrollController
;
77 class RenderWidgetHostDelegate
;
78 class RenderWidgetHostViewPort
;
79 class SmoothScrollGestureController
;
80 class TouchEventQueue
;
83 // This implements the RenderWidgetHost interface that is exposed to
84 // embedders of content, and adds things only visible to content.
85 class CONTENT_EXPORT RenderWidgetHostImpl
: virtual public RenderWidgetHost
,
86 public IPC::Listener
{
88 // routing_id can be MSG_ROUTING_NONE, in which case the next available
89 // routing id is taken from the RenderProcessHost.
90 // If this object outlives |delegate|, DetachDelegate() must be called when
91 // |delegate| goes away.
92 RenderWidgetHostImpl(RenderWidgetHostDelegate
* delegate
,
93 RenderProcessHost
* process
,
95 virtual ~RenderWidgetHostImpl();
97 // Similar to RenderWidgetHost::FromID, but returning the Impl object.
98 static RenderWidgetHostImpl
* FromID(int32 process_id
, int32 routing_id
);
100 // Use RenderWidgetHostImpl::From(rwh) to downcast a
101 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this
102 // uses RenderWidgetHost::AsRenderWidgetHostImpl().
103 static RenderWidgetHostImpl
* From(RenderWidgetHost
* rwh
);
105 void set_hung_renderer_delay_ms(const base::TimeDelta
& timeout
) {
106 hung_renderer_delay_ms_
= timeout
.InMilliseconds();
109 // RenderWidgetHost implementation.
110 virtual void Undo() OVERRIDE
;
111 virtual void Redo() OVERRIDE
;
112 virtual void Cut() OVERRIDE
;
113 virtual void Copy() OVERRIDE
;
114 virtual void CopyToFindPboard() OVERRIDE
;
115 virtual void Paste() OVERRIDE
;
116 virtual void PasteAndMatchStyle() OVERRIDE
;
117 virtual void Delete() OVERRIDE
;
118 virtual void SelectAll() OVERRIDE
;
119 virtual void Unselect() OVERRIDE
;
120 virtual void UpdateTextDirection(WebKit::WebTextDirection direction
) OVERRIDE
;
121 virtual void NotifyTextDirection() OVERRIDE
;
122 virtual void Focus() OVERRIDE
;
123 virtual void Blur() OVERRIDE
;
124 virtual void SetActive(bool active
) OVERRIDE
;
125 virtual void CopyFromBackingStore(
126 const gfx::Rect
& src_rect
,
127 const gfx::Size
& accelerated_dst_size
,
128 const base::Callback
<void(bool, const SkBitmap
&)>& callback
) OVERRIDE
;
129 #if defined(TOOLKIT_GTK)
130 virtual bool CopyFromBackingStoreToGtkWindow(const gfx::Rect
& dest_rect
,
131 GdkWindow
* target
) OVERRIDE
;
132 #elif defined(OS_MACOSX)
133 virtual gfx::Size
GetBackingStoreSize() OVERRIDE
;
134 virtual bool CopyFromBackingStoreToCGContext(const CGRect
& dest_rect
,
135 CGContextRef target
) OVERRIDE
;
137 virtual void EnableFullAccessibilityMode() OVERRIDE
;
138 virtual void ForwardMouseEvent(
139 const WebKit::WebMouseEvent
& mouse_event
) OVERRIDE
;
140 virtual void ForwardWheelEvent(
141 const WebKit::WebMouseWheelEvent
& wheel_event
) OVERRIDE
;
142 virtual void ForwardKeyboardEvent(
143 const NativeWebKeyboardEvent
& key_event
) OVERRIDE
;
144 virtual const gfx::Vector2d
& GetLastScrollOffset() const OVERRIDE
;
145 virtual RenderProcessHost
* GetProcess() const OVERRIDE
;
146 virtual int GetRoutingID() const OVERRIDE
;
147 virtual RenderWidgetHostView
* GetView() const OVERRIDE
;
148 virtual bool IsLoading() const OVERRIDE
;
149 virtual bool IsRenderView() const OVERRIDE
;
150 virtual void PaintAtSize(TransportDIB::Handle dib_handle
,
152 const gfx::Size
& page_size
,
153 const gfx::Size
& desired_size
) OVERRIDE
;
154 virtual void Replace(const string16
& word
) OVERRIDE
;
155 virtual void ReplaceMisspelling(const string16
& word
) OVERRIDE
;
156 virtual void ResizeRectChanged(const gfx::Rect
& new_rect
) OVERRIDE
;
157 virtual void RestartHangMonitorTimeout() OVERRIDE
;
158 virtual void SetIgnoreInputEvents(bool ignore_input_events
) OVERRIDE
;
159 virtual void Stop() OVERRIDE
;
160 virtual void WasResized() OVERRIDE
;
161 virtual void AddKeyboardListener(KeyboardListener
* listener
) OVERRIDE
;
162 virtual void RemoveKeyboardListener(KeyboardListener
* listener
) OVERRIDE
;
163 virtual void GetWebScreenInfo(WebKit::WebScreenInfo
* result
) OVERRIDE
;
164 virtual void GetSnapshotFromRenderer(
165 const gfx::Rect
& src_subrect
,
166 const base::Callback
<void(bool, const SkBitmap
&)>& callback
) OVERRIDE
;
168 const NativeWebKeyboardEvent
* GetLastKeyboardEvent() const;
170 // Notification that the screen info has changed.
171 void NotifyScreenInfoChanged();
173 // Sets the View of this RenderWidgetHost.
174 void SetView(RenderWidgetHostView
* view
);
176 int surface_id() const { return surface_id_
; }
178 bool empty() const { return current_size_
.IsEmpty(); }
180 // Called when a renderer object already been created for this host, and we
181 // just need to be attached to it. Used for window.open, <select> dropdown
182 // menus, and other times when the renderer initiates creating an object.
185 // Tells the renderer to die and then calls Destroy().
186 virtual void Shutdown();
189 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
191 // Sends a message to the corresponding object in the renderer.
192 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
194 // Called to notify the RenderWidget that it has been hidden or restored from
195 // having been hidden.
199 // Returns true if the RenderWidget is hidden.
200 bool is_hidden() const { return is_hidden_
; }
202 // Called to notify the RenderWidget that its associated native window
204 virtual void GotFocus();
205 virtual void LostCapture();
207 // Called to notify the RenderWidget that it has lost the mouse lock.
208 virtual void LostMouseLock();
210 // Noifies the RenderWidget of the current mouse cursor visibility state.
211 void SendCursorVisibilityState(bool is_visible
);
213 // Tells us whether the page is rendered directly via the GPU process.
214 bool is_accelerated_compositing_active() {
215 return is_accelerated_compositing_active_
;
218 // Notifies the RenderWidgetHost that the View was destroyed.
219 void ViewDestroyed();
221 // Indicates if the page has finished loading.
222 void SetIsLoading(bool is_loading
);
224 // Check for the existance of a BackingStore of the given |desired_size| and
225 // return it if it exists. If the BackingStore is GPU, true is returned and
226 // |*backing_store| is set to NULL.
227 bool TryGetBackingStore(const gfx::Size
& desired_size
,
228 BackingStore
** backing_store
);
230 // Get access to the widget's backing store matching the size of the widget's
231 // view. If you pass |force_create| as true, then GetBackingStore may block
232 // for the renderer to send a new frame. Otherwise, NULL will be returned if
233 // the backing store doesn't already exist. It will also return NULL if the
234 // backing store could not be created.
236 // Mac only: NULL may also be returned if the last frame was GPU accelerated.
237 // Call GetView()->HasAcceleratedSurface to determine if the last frame was
239 BackingStore
* GetBackingStore(bool force_create
);
241 // Allocate a new backing store of the given size. Returns NULL on failure
242 // (for example, if we don't currently have a RenderWidgetHostView.)
243 BackingStore
* AllocBackingStore(const gfx::Size
& size
);
245 // When a backing store does asynchronous painting, it will call this function
246 // when it is done with the DIB. We will then forward a message to the
247 // renderer to send another paint.
248 void DonePaintingToBackingStore();
250 // GPU accelerated version of GetBackingStore function. This will
251 // trigger a re-composite to the view. If a resize is pending, it will
252 // block briefly waiting for an ack from the renderer.
253 void ScheduleComposite();
255 // Starts a hang monitor timeout. If there's already a hang monitor timeout
256 // the new one will only fire if it has a shorter delay than the time
257 // left on the existing timeouts.
258 void StartHangMonitorTimeout(base::TimeDelta delay
);
260 // Stops all existing hang monitor timeouts and assumes the renderer is
262 void StopHangMonitorTimeout();
264 // Forwards the given message to the renderer. These are called by the view
265 // when it has received a message.
266 void ForwardGestureEvent(const WebKit::WebGestureEvent
& gesture_event
);
267 virtual void ForwardTouchEventWithLatencyInfo(
268 const WebKit::WebTouchEvent
& touch_event
,
269 const ui::LatencyInfo
& ui_latency
);
271 // Forwards the given event immediately to the renderer.
272 void ForwardMouseEventImmediately(
273 const MouseEventWithLatencyInfo
& mouse_event
);
274 void ForwardTouchEventImmediately(
275 const TouchEventWithLatencyInfo
& touch_event
);
276 void ForwardGestureEventImmediately(
277 const GestureEventWithLatencyInfo
& gesture_event
);
279 void CancelUpdateTextDirection();
281 // Called when a mouse click/gesture tap activates the renderer.
282 virtual void OnPointerEventActivate();
284 // Notifies the renderer whether or not the input method attached to this
285 // process is activated.
286 // When the input method is activated, a renderer process sends IPC messages
287 // to notify the status of its composition node. (This message is mainly used
288 // for notifying the position of the input cursor so that the browser can
289 // display input method windows under the cursor.)
290 void SetInputMethodActive(bool activate
);
292 // Update the composition node of the renderer (or WebKit).
293 // WebKit has a special node (a composition node) for input method to change
294 // its text without affecting any other DOM nodes. When the input method
295 // (attached to the browser) updates its text, the browser sends IPC messages
296 // to update the composition node of the renderer.
297 // (Read the comments of each function for its detail.)
299 // Sets the text of the composition node.
300 // This function can also update the cursor position and mark the specified
301 // range in the composition node.
302 // A browser should call this function:
303 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
305 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
306 // * when markedText of NSTextInput is called (on Mac).
307 void ImeSetComposition(
308 const string16
& text
,
309 const std::vector
<WebKit::WebCompositionUnderline
>& underlines
,
313 // Finishes an ongoing composition with the specified text.
314 // A browser should call this function:
315 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
317 // * when it receives a "commit" signal of GtkIMContext (on Linux);
318 // * when insertText of NSTextInput is called (on Mac).
319 void ImeConfirmComposition(const string16
& text
);
320 void ImeConfirmComposition(const string16
& text
,
321 const ui::Range
& replacement_range
);
323 // Finishes an ongoing composition with the composition text set by last
324 // SetComposition() call.
325 void ImeConfirmComposition();
327 // Cancels an ongoing composition.
328 void ImeCancelComposition();
330 // Deletes the current selection plus the specified number of characters
331 // before and after the selection or caret.
332 void ExtendSelectionAndDelete(size_t before
, size_t after
);
334 // This is for derived classes to give us access to the resizer rect.
335 // And to also expose it to the RenderWidgetHostView.
336 virtual gfx::Rect
GetRootWindowResizerRect() const;
338 bool ignore_input_events() const {
339 return ignore_input_events_
;
342 bool input_method_active() const {
343 return input_method_active_
;
346 bool ShouldForwardTouchEvent() const;
348 bool has_touch_handler() const { return has_touch_handler_
; }
350 // Notification that the user has made some kind of input that could
351 // perform an action. See OnUserGesture for more details.
352 void StartUserGesture();
354 // Set the RenderView background.
355 void SetBackground(const SkBitmap
& background
);
357 // Notifies the renderer that the next key event is bound to one or more
358 // pre-defined edit commands
359 void SetEditCommandsForNextKeyEvent(
360 const std::vector
<EditCommand
>& commands
);
362 // Gets the accessibility mode.
363 AccessibilityMode
accessibility_mode() const {
364 return accessibility_mode_
;
367 // Send a message to the renderer process to change the accessibility mode.
368 void SetAccessibilityMode(AccessibilityMode mode
);
370 // Relay a request from assistive technology to perform the default action
372 void AccessibilityDoDefaultAction(int object_id
);
374 // Relay a request from assistive technology to set focus to a given node.
375 void AccessibilitySetFocus(int object_id
);
377 // Relay a request from assistive technology to make a given object
378 // visible by scrolling as many scrollable containers as necessary.
379 // In addition, if it's not possible to make the entire object visible,
380 // scroll so that the |subfocus| rect is visible at least. The subfocus
381 // rect is in local coordinates of the object itself.
382 void AccessibilityScrollToMakeVisible(
383 int acc_obj_id
, gfx::Rect subfocus
);
385 // Relay a request from assistive technology to move a given object
386 // to a specific location, in the WebContents area coordinate space, i.e.
387 // (0, 0) is the top-left corner of the WebContents.
388 void AccessibilityScrollToPoint(int acc_obj_id
, gfx::Point point
);
390 // Relay a request from assistive technology to set text selection.
391 void AccessibilitySetTextSelection(
392 int acc_obj_id
, int start_offset
, int end_offset
);
394 // Kill the renderer because we got a fatal accessibility error.
395 void FatalAccessibilityTreeError();
397 #if defined(OS_WIN) && defined(USE_AURA)
398 void SetParentNativeViewAccessible(
399 gfx::NativeViewAccessible accessible_parent
);
400 gfx::NativeViewAccessible
GetParentNativeViewAccessible() const;
403 // Executes the edit command on the RenderView.
404 void ExecuteEditCommand(const std::string
& command
,
405 const std::string
& value
);
407 // Tells the renderer to scroll the currently focused node into rect only if
408 // the currently focused node is a Text node (textfield, text area or content
410 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect
& rect
);
412 // Requests the renderer to select the region between two points.
413 void SelectRange(const gfx::Point
& start
, const gfx::Point
& end
);
415 // Requests the renderer to move the caret selection towards the point.
416 void MoveCaret(const gfx::Point
& point
);
418 // Called when the reponse to a pending mouse lock request has arrived.
419 // Returns true if |allowed| is true and the mouse has been successfully
421 bool GotResponseToLockMouseRequest(bool allowed
);
423 // Tells the RenderWidget about the latest vsync parameters.
424 // Note: Make sure the timebase was obtained using
425 // base::TimeTicks::HighResNow. Using the non-high res timer will result in
426 // incorrect synchronization across processes.
427 virtual void UpdateVSyncParameters(base::TimeTicks timebase
,
428 base::TimeDelta interval
);
430 // Called by the view in response to AcceleratedSurfaceBuffersSwapped or
431 // AcceleratedSurfacePostSubBuffer.
432 static void AcknowledgeBufferPresent(
435 const AcceleratedSurfaceMsg_BufferPresented_Params
& params
);
437 // Called by the view in response to OnSwapCompositorFrame.
438 static void SendSwapCompositorFrameAck(
439 int32 route_id
, int renderer_host_id
, const cc::CompositorFrameAck
& ack
);
441 // Called by the view in response to AcceleratedSurfaceBuffersSwapped for
442 // platforms that support deferred GPU process descheduling. This does
443 // nothing if the compositor thread is enabled.
444 // TODO(jbates) Once the compositor thread is always on, this can be removed.
445 void AcknowledgeSwapBuffersToRenderer();
447 bool is_threaded_compositing_enabled() const {
448 return is_threaded_compositing_enabled_
;
451 #if defined(USE_AURA)
452 // Called by the view when the parent changes. If a parent isn't available,
454 void ParentChanged(gfx::NativeViewId new_parent
);
457 // Signals that the compositing surface was updated, e.g. after a lost context
459 void CompositingSurfaceUpdated();
461 void set_allow_privileged_mouse_lock(bool allow
) {
462 allow_privileged_mouse_lock_
= allow
;
465 // Resets state variables related to tracking pending size and painting.
467 // We need to reset these flags when we want to repaint the contents of
468 // browser plugin in this RWH. Resetting these flags will ensure we ignore
469 // any previous pending acks that are not relevant upon repaint.
470 void ResetSizeAndRepaintPendingFlags();
472 void DetachDelegate();
474 // Update the renderer's cache of the screen rect of the view and window.
475 void SendScreenRects();
477 GestureEventFilter
* gesture_event_filter() {
478 return gesture_event_filter_
.get();
481 OverscrollController
* overscroll_controller() {
482 return overscroll_controller_
.get();
485 base::TimeDelta
GetSyntheticScrollMessageInterval() const;
487 // Sets whether the overscroll controller should be enabled for this page.
488 void SetOverscrollControllerEnabled(bool enabled
);
490 // Suppreses future char events until a keydown. See
491 // suppress_next_char_events_.
492 void SuppressNextCharEvents();
494 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
496 bool should_auto_resize() { return should_auto_resize_
; }
498 void FrameSwapped(const ui::LatencyInfo
& latency_info
);
500 // Returns the ID that uniquely describes this component to the latency
502 int64
GetLatencyComponentId();
504 static void CompositorFrameDrawn(const ui::LatencyInfo
& latency_info
);
506 // Don't check whether we expected a resize ack during layout tests.
507 static void DisableResizeAckCheckForTesting();
510 virtual RenderWidgetHostImpl
* AsRenderWidgetHostImpl() OVERRIDE
;
512 // Transmits the given input event. This is an internal helper for
513 // |ForwardInputEvent()| and should not be used directly from elsewhere.
514 void SendInputEvent(const WebKit::WebInputEvent
& input_event
,
515 int event_size
, const ui::LatencyInfo
& latency_info
,
516 bool is_keyboard_shortcut
);
518 // Internal implementation of the public Forward*Event() methods.
519 void ForwardInputEvent(const WebKit::WebInputEvent
& input_event
,
520 int event_size
, const ui::LatencyInfo
& latency_info
,
521 bool is_keyboard_shortcut
);
523 // Internal forwarding implementations that take a LatencyInfo.
524 virtual void ForwardMouseEventWithLatencyInfo(
525 const MouseEventWithLatencyInfo
& mouse_event
);
526 virtual void ForwardWheelEventWithLatencyInfo(
527 const WebKit::WebMouseWheelEvent
& wheel_event
,
528 const ui::LatencyInfo
& latency_info
);
530 // Create a LatencyInfo struct for a new input event that was just received.
531 ui::LatencyInfo
NewInputLatencyInfo();
533 // Called when we receive a notification indicating that the renderer
534 // process has gone. This will reset our state so that our state will be
535 // consistent if a new renderer is created.
536 void RendererExited(base::TerminationStatus status
, int exit_code
);
538 // Retrieves an id the renderer can use to refer to its view.
539 // This is used for various IPC messages, including plugins.
540 gfx::NativeViewId
GetNativeViewId() const;
542 // Retrieves an id for the surface that the renderer can draw to
543 // when accelerated compositing is enabled.
544 gfx::GLSurfaceHandle
GetCompositingSurface();
546 // ---------------------------------------------------------------------------
547 // The following methods are overridden by RenderViewHost to send upwards to
550 // Called when a mousewheel event was not processed by the renderer.
551 virtual void UnhandledWheelEvent(const WebKit::WebMouseWheelEvent
& event
) {}
553 // Notification that the user has made some kind of input that could
554 // perform an action. The gestures that count are 1) any mouse down
555 // event and 2) enter or space key presses.
556 virtual void OnUserGesture() {}
558 // Callbacks for notification when the renderer becomes unresponsive to user
559 // input events, and subsequently responsive again.
560 virtual void NotifyRendererUnresponsive() {}
561 virtual void NotifyRendererResponsive() {}
563 // Called when auto-resize resulted in the renderer size changing.
564 virtual void OnRenderAutoResized(const gfx::Size
& new_size
) {}
566 // ---------------------------------------------------------------------------
568 // RenderViewHost overrides this method to impose further restrictions on when
569 // to allow mouse lock.
570 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
572 virtual void RequestToLockMouse(bool user_gesture
,
573 bool last_unlocked_by_target
);
575 void RejectMouseLockOrUnlockIfNecessary();
576 bool IsMouseLocked() const;
578 // RenderViewHost overrides this method to report when in fullscreen mode.
579 virtual bool IsFullscreen() const;
581 // Indicates if the render widget host should track the render widget's size
582 // as opposed to visa versa.
583 void SetShouldAutoResize(bool enable
);
585 // Expose increment/decrement of the in-flight event count, so
586 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
587 int increment_in_flight_event_count() { return ++in_flight_event_count_
; }
588 int decrement_in_flight_event_count() { return --in_flight_event_count_
; }
590 // Returns whether an overscroll gesture is in progress.
591 bool IsInOverscrollGesture() const;
593 // The View associated with the RenderViewHost. The lifetime of this object
594 // is associated with the lifetime of the Render process. If the Renderer
595 // crashes, its View is destroyed and this pointer becomes NULL, even though
596 // render_view_host_ lives on to load another URL (creating a new View while
598 RenderWidgetHostViewPort
* view_
;
600 // true if a renderer has once been valid. We use this flag to display a sad
601 // tab only when we lose our renderer and not if a paint occurs during
603 bool renderer_initialized_
;
605 // This value indicates how long to wait before we consider a renderer hung.
606 int hung_renderer_delay_ms_
;
609 friend class MockRenderWidgetHost
;
611 // Tell this object to destroy itself.
614 // Checks whether the renderer is hung and calls NotifyRendererUnresponsive
616 void CheckRendererIsUnresponsive();
618 // Called if we know the renderer is responsive. When we currently think the
619 // renderer is unresponsive, this will clear that state and call
620 // NotifyRendererResponsive.
621 void RendererIsResponsive();
623 // IPC message handlers
624 void OnRenderViewReady();
625 void OnRenderViewGone(int status
, int error_code
);
627 void OnUpdateScreenRectsAck();
628 void OnRequestMove(const gfx::Rect
& pos
);
629 void OnSetTooltipText(const string16
& tooltip_text
,
630 WebKit::WebTextDirection text_direction_hint
);
631 void OnPaintAtSizeAck(int tag
, const gfx::Size
& size
);
632 void OnCompositorSurfaceBuffersSwapped(
633 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params
& params
);
634 bool OnSwapCompositorFrame(const IPC::Message
& message
);
635 void OnOverscrolled(gfx::Vector2dF accumulated_overscroll
,
636 gfx::Vector2dF current_fling_velocity
);
637 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params
& params
);
638 void OnUpdateIsDelayed();
639 void OnInputEventAck(WebKit::WebInputEvent::Type event_type
,
640 InputEventAckState ack_result
);
641 void OnBeginSmoothScroll(
642 const ViewHostMsg_BeginSmoothScroll_Params
& params
);
643 void OnSelectRangeAck();
644 void OnMsgMoveCaretAck();
645 virtual void OnFocus();
646 virtual void OnBlur();
647 void OnHasTouchEventHandlers(bool has_handlers
);
648 void OnSetCursor(const WebCursor
& cursor
);
649 void OnTextInputTypeChanged(ui::TextInputType type
, bool can_compose_inline
);
650 void OnImeCompositionRangeChanged(
651 const ui::Range
& range
,
652 const std::vector
<gfx::Rect
>& character_bounds
);
653 void OnImeCancelComposition();
654 void OnDidActivateAcceleratedCompositing(bool activated
);
655 void OnLockMouse(bool user_gesture
,
656 bool last_unlocked_by_target
,
658 void OnUnlockMouse();
659 void OnShowDisambiguationPopup(const gfx::Rect
& rect
,
660 const gfx::Size
& size
,
661 const TransportDIB::Id
& id
);
663 void OnWindowlessPluginDummyWindowCreated(
664 gfx::NativeViewId dummy_activation_window
);
665 void OnWindowlessPluginDummyWindowDestroyed(
666 gfx::NativeViewId dummy_activation_window
);
668 void OnSnapshot(bool success
, const SkBitmap
& bitmap
);
670 // Called (either immediately or asynchronously) after we're done with our
671 // BackingStore and can send an ACK to the renderer so it can paint onto it
673 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params
& params
,
674 const base::TimeTicks
& paint_start
);
676 // Paints the given bitmap to the current backing store at the given
677 // location. Returns true if the passed callback was asynchronously
678 // scheduled in the future (and thus the caller must manually synchronously
679 // call the callback function).
680 bool PaintBackingStoreRect(TransportDIB::Id bitmap
,
681 const gfx::Rect
& bitmap_rect
,
682 const std::vector
<gfx::Rect
>& copy_rects
,
683 const gfx::Size
& view_size
,
685 const base::Closure
& completion_callback
);
687 // Scrolls the given |clip_rect| in the backing by the given dx/dy amount. The
688 // |dib| and its corresponding location |bitmap_rect| in the backing store
689 // is the newly painted pixels by the renderer.
690 void ScrollBackingStoreRect(const gfx::Vector2d
& delta
,
691 const gfx::Rect
& clip_rect
,
692 const gfx::Size
& view_size
);
694 // Give key press listeners a chance to handle this key press. This allow
695 // widgets that don't have focus to still handle key presses.
696 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent
& event
);
698 // Called by OnInputEventAck() to process a keyboard event ack message.
699 void ProcessKeyboardEventAck(int type
, bool processed
);
701 // Called by OnInputEventAck() to process a wheel event ack message.
702 // This could result in a task being posted to allow additional wheel
703 // input messages to be coalesced.
704 void ProcessWheelAck(bool processed
);
706 // Called by OnInputEventAck() to process a gesture event ack message.
707 // This validates the gesture for suppression of touchpad taps and sends one
708 // previously queued coalesced gesture if it exists.
709 void ProcessGestureAck(bool processed
, int type
);
711 void SimulateTouchGestureWithMouse(const WebKit::WebMouseEvent
& mouse_event
);
713 // Called on OnInputEventAck() to process a touch event ack message.
714 // This can result in a gesture event being generated and sent back to the
716 void ProcessTouchAck(InputEventAckState ack_result
);
718 // Called when there is a new auto resize (using a post to avoid a stack
719 // which may get in recursive loops).
720 void DelayedAutoResized();
723 // Our delegate, which wants to know mainly about keyboard events.
724 // It will remain non-NULL until DetachDelegate() is called.
725 RenderWidgetHostDelegate
* delegate_
;
727 // Created during construction but initialized during Init*(). Therefore, it
728 // is guaranteed never to be NULL, but its channel may be NULL if the
729 // renderer crashed, so you must always check that.
730 RenderProcessHost
* process_
;
732 // The ID of the corresponding object in the Renderer Instance.
735 // The ID of the surface corresponding to this render widget.
738 // Indicates whether a page is loading or not.
741 // Indicates whether a page is hidden or not.
744 // Indicates whether a page is fullscreen or not.
747 // True when a page is rendered directly via the GPU process.
748 bool is_accelerated_compositing_active_
;
750 // True if threaded compositing is enabled on this view.
751 bool is_threaded_compositing_enabled_
;
753 // Set if we are waiting for a repaint ack for the view.
754 bool repaint_ack_pending_
;
756 // True when waiting for RESIZE_ACK.
757 bool resize_ack_pending_
;
759 // Cached copy of the screen info so that it doesn't need to be updated every
760 // time the window is resized.
761 scoped_ptr
<WebKit::WebScreenInfo
> screen_info_
;
763 // Set if screen_info_ may have changed and should be recomputed and force a
765 bool screen_info_out_of_date_
;
767 // The current size of the RenderWidget.
768 gfx::Size current_size_
;
770 // The size of the view's backing surface in non-DPI-adjusted pixels.
771 gfx::Size physical_backing_size_
;
773 // The height of the physical backing surface that is overdrawn opaquely in
774 // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
775 float overdraw_bottom_height_
;
777 // The size we last sent as requested size to the renderer. |current_size_|
778 // is only updated once the resize message has been ack'd. This on the other
779 // hand is updated when the resize message is sent. This is very similar to
780 // |resize_ack_pending_|, but the latter is not set if the new size has width
781 // or height zero, which is why we need this too.
782 gfx::Size in_flight_size_
;
784 // The next auto resize to send.
785 gfx::Size new_auto_size_
;
787 // True if the render widget host should track the render widget's size as
788 // opposed to visa versa.
789 bool should_auto_resize_
;
791 bool waiting_for_screen_rects_ack_
;
792 gfx::Rect last_view_screen_rect_
;
793 gfx::Rect last_window_screen_rect_
;
795 // True if a mouse move event was sent to the render view and we are waiting
796 // for a corresponding InputHostMsg_HandleInputEvent_ACK message.
797 bool mouse_move_pending_
;
799 // The next mouse move event to send (only non-null while mouse_move_pending_
801 scoped_ptr
<MouseEventWithLatencyInfo
> next_mouse_move_
;
803 // (Similar to |mouse_move_pending_|.) True if a mouse wheel event was sent
804 // and we are waiting for a corresponding ack.
805 bool mouse_wheel_pending_
;
806 WebKit::WebMouseWheelEvent current_wheel_event_
;
808 typedef std::deque
<MouseWheelEventWithLatencyInfo
> WheelEventQueue
;
810 // (Similar to |next_mouse_move_|.) The next mouse wheel events to send.
811 // Unlike mouse moves, mouse wheel events received while one is pending are
812 // coalesced (by accumulating deltas) if they match the previous event in
813 // modifiers. On the Mac, in particular, mouse wheel events are received at a
814 // high rate; not waiting for the ack results in jankiness, and using the same
815 // mechanism as for mouse moves (just dropping old events when multiple ones
816 // would be queued) results in very slow scrolling.
817 WheelEventQueue coalesced_mouse_wheel_events_
;
819 AccessibilityMode accessibility_mode_
;
821 // (Similar to |mouse_move_pending_|.) True while waiting for SelectRange_ACK.
822 bool select_range_pending_
;
824 // (Similar to |next_mouse_move_|.) The next SelectRange to send, if any.
825 struct SelectionRange
{
826 gfx::Point start
, end
;
828 scoped_ptr
<SelectionRange
> next_selection_range_
;
830 // (Similar to |mouse_move_pending_|.) True while waiting for MoveCaret_ACK.
831 bool move_caret_pending_
;
833 // (Similar to |next_mouse_move_|.) The next MoveCaret to send, if any.
834 scoped_ptr
<gfx::Point
> next_move_caret_
;
836 // The time when an input event was sent to the RenderWidget.
837 base::TimeTicks input_event_start_time_
;
839 // Keyboard event listeners.
840 ObserverList
<KeyboardListener
> keyboard_listeners_
;
842 // If true, then we should repaint when restoring even if we have a
843 // backingstore. This flag is set to true if we receive a paint message
844 // while is_hidden_ to true. Even though we tell the render widget to hide
845 // itself, a paint message could already be in flight at that point.
846 bool needs_repainting_on_restore_
;
848 // This is true if the renderer is currently unresponsive.
849 bool is_unresponsive_
;
851 // The following value indicates a time in the future when we would consider
852 // the renderer hung if it does not generate an appropriate response message.
853 base::Time time_when_considered_hung_
;
855 // This value denotes the number of input events yet to be acknowledged
857 int in_flight_event_count_
;
859 // This timer runs to check if time_when_considered_hung_ has past.
860 base::OneShotTimer
<RenderWidgetHostImpl
> hung_renderer_timer_
;
862 // Flag to detect recursive calls to GetBackingStore().
863 bool in_get_backing_store_
;
865 // Flag to trigger the GetBackingStore method to abort early.
866 bool abort_get_backing_store_
;
868 // Set when we call DidPaintRect/DidScrollRect on the view.
869 bool view_being_painted_
;
871 // Used for UMA histogram logging to measure the time for a repaint view
872 // operation to finish.
873 base::TimeTicks repaint_start_time_
;
875 // Queue of keyboard events that we need to track.
876 typedef std::deque
<NativeWebKeyboardEvent
> KeyQueue
;
878 // A queue of keyboard events. We can't trust data from the renderer so we
879 // stuff key events into a queue and pop them out on ACK, feeding our copy
880 // back to whatever unhandled handler instead of the returned version.
883 // Set to true if we shouldn't send input events from the render widget.
884 bool ignore_input_events_
;
886 // Indicates whether IME is active.
887 bool input_method_active_
;
889 // Set when we update the text direction of the selected input element.
890 bool text_direction_updated_
;
891 WebKit::WebTextDirection text_direction_
;
893 // Set when we cancel updating the text direction.
894 // This flag also ignores succeeding update requests until we call
895 // NotifyTextDirection().
896 bool text_direction_canceled_
;
898 // Indicates if the next sequence of Char events should be suppressed or not.
899 // System may translate a RawKeyDown event into zero or more Char events,
900 // usually we send them to the renderer directly in sequence. However, If a
901 // RawKeyDown event was not handled by the renderer but was handled by
902 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
903 // shall not send the following sequence of Char events, which was generated
904 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
905 // handle the Char events and cause unexpected behavior.
906 // For example, pressing alt-2 may let the browser switch to the second tab,
907 // but the Char event generated by alt-2 may also activate a HTML element
908 // if its accesskey happens to be "2", then the user may get confused when
909 // switching back to the original tab, because the content may already be
911 bool suppress_next_char_events_
;
913 // The last scroll offset of the render widget.
914 gfx::Vector2d last_scroll_offset_
;
916 bool pending_mouse_lock_request_
;
917 bool allow_privileged_mouse_lock_
;
919 // Keeps track of whether the webpage has any touch event handler. If it does,
920 // then touch events are sent to the renderer. Otherwise, the touch events are
921 // not sent to the renderer.
922 bool has_touch_handler_
;
924 base::WeakPtrFactory
<RenderWidgetHostImpl
> weak_factory_
;
926 SmoothScrollGestureController smooth_scroll_gesture_controller_
;
927 scoped_ptr
<TouchEventQueue
> touch_event_queue_
;
928 scoped_ptr
<GestureEventFilter
> gesture_event_filter_
;
929 scoped_ptr
<OverscrollController
> overscroll_controller_
;
932 std::list
<HWND
> dummy_windows_for_activation_
;
935 // List of callbacks for pending snapshot requests to the renderer.
936 std::queue
<base::Callback
<void(bool, const SkBitmap
&)> > pending_snapshots_
;
938 int64 last_input_number_
;
940 BrowserRenderingStats rendering_stats_
;
942 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl
);
945 } // namespace content
947 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_