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/kill.h"
22 #include "base/strings/string16.h"
23 #include "base/time/time.h"
24 #include "base/timer/timer.h"
25 #include "build/build_config.h"
26 #include "cc/resources/shared_bitmap.h"
27 #include "content/browser/accessibility/browser_accessibility_manager.h"
28 #include "content/browser/renderer_host/event_with_latency_info.h"
29 #include "content/browser/renderer_host/input/input_ack_handler.h"
30 #include "content/browser/renderer_host/input/input_router_client.h"
31 #include "content/browser/renderer_host/input/synthetic_gesture.h"
32 #include "content/browser/renderer_host/input/touch_emulator_client.h"
33 #include "content/common/input/input_event_ack_state.h"
34 #include "content/common/input/synthetic_gesture_packet.h"
35 #include "content/common/view_message_enums.h"
36 #include "content/public/browser/render_widget_host.h"
37 #include "content/public/common/page_zoom.h"
38 #include "ipc/ipc_listener.h"
39 #include "ui/base/ime/text_input_mode.h"
40 #include "ui/base/ime/text_input_type.h"
41 #include "ui/events/latency_info.h"
42 #include "ui/gfx/native_widget_types.h"
44 struct AcceleratedSurfaceMsg_BufferPresented_Params
;
45 struct ViewHostMsg_BeginSmoothScroll_Params
;
46 struct ViewHostMsg_CompositorSurfaceBuffersSwapped_Params
;
47 struct ViewHostMsg_SelectionBounds_Params
;
48 struct ViewHostMsg_TextInputState_Params
;
49 struct ViewHostMsg_UpdateRect_Params
;
56 class CompositorFrame
;
57 class CompositorFrameAck
;
71 struct WebCompositionUnderline
;
75 #if defined(OS_ANDROID)
83 class MockRenderWidgetHost
;
84 class OverscrollController
;
85 class RenderWidgetHostDelegate
;
86 class RenderWidgetHostViewBase
;
87 class SyntheticGestureController
;
93 // This implements the RenderWidgetHost interface that is exposed to
94 // embedders of content, and adds things only visible to content.
95 class CONTENT_EXPORT RenderWidgetHostImpl
96 : virtual public RenderWidgetHost
,
97 public InputRouterClient
,
98 public InputAckHandler
,
99 public TouchEmulatorClient
,
100 public IPC::Listener
,
101 public BrowserAccessibilityDelegate
{
103 // routing_id can be MSG_ROUTING_NONE, in which case the next available
104 // routing id is taken from the RenderProcessHost.
105 // If this object outlives |delegate|, DetachDelegate() must be called when
106 // |delegate| goes away.
107 RenderWidgetHostImpl(RenderWidgetHostDelegate
* delegate
,
108 RenderProcessHost
* process
,
111 virtual ~RenderWidgetHostImpl();
113 // Similar to RenderWidgetHost::FromID, but returning the Impl object.
114 static RenderWidgetHostImpl
* FromID(int32 process_id
, int32 routing_id
);
116 // Returns all RenderWidgetHosts including swapped out ones for
117 // internal use. The public interface
118 // RendgerWidgetHost::GetRenderWidgetHosts only returns active ones.
119 static scoped_ptr
<RenderWidgetHostIterator
> GetAllRenderWidgetHosts();
121 // Use RenderWidgetHostImpl::From(rwh) to downcast a
122 // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this
123 // uses RenderWidgetHost::AsRenderWidgetHostImpl().
124 static RenderWidgetHostImpl
* From(RenderWidgetHost
* rwh
);
126 void set_hung_renderer_delay_ms(const base::TimeDelta
& timeout
) {
127 hung_renderer_delay_ms_
= timeout
.InMilliseconds();
130 // RenderWidgetHost implementation.
131 virtual void UpdateTextDirection(blink::WebTextDirection direction
) OVERRIDE
;
132 virtual void NotifyTextDirection() OVERRIDE
;
133 virtual void Focus() OVERRIDE
;
134 virtual void Blur() OVERRIDE
;
135 virtual void SetActive(bool active
) OVERRIDE
;
136 virtual void CopyFromBackingStore(
137 const gfx::Rect
& src_rect
,
138 const gfx::Size
& accelerated_dst_size
,
139 const base::Callback
<void(bool, const SkBitmap
&)>& callback
,
140 const SkBitmap::Config
& bitmap_config
) OVERRIDE
;
141 virtual bool CanCopyFromBackingStore() OVERRIDE
;
142 #if defined(OS_ANDROID)
143 virtual void LockBackingStore() OVERRIDE
;
144 virtual void UnlockBackingStore() OVERRIDE
;
146 virtual void EnableFullAccessibilityMode() OVERRIDE
;
147 virtual bool IsFullAccessibilityModeForTesting() OVERRIDE
;
148 virtual void EnableTreeOnlyAccessibilityMode() OVERRIDE
;
149 virtual bool IsTreeOnlyAccessibilityModeForTesting() OVERRIDE
;
150 virtual void ForwardMouseEvent(
151 const blink::WebMouseEvent
& mouse_event
) OVERRIDE
;
152 virtual void ForwardWheelEvent(
153 const blink::WebMouseWheelEvent
& wheel_event
) OVERRIDE
;
154 virtual void ForwardKeyboardEvent(
155 const NativeWebKeyboardEvent
& key_event
) OVERRIDE
;
156 virtual const gfx::Vector2d
& GetLastScrollOffset() const OVERRIDE
;
157 virtual RenderProcessHost
* GetProcess() const OVERRIDE
;
158 virtual int GetRoutingID() const OVERRIDE
;
159 virtual RenderWidgetHostView
* GetView() const OVERRIDE
;
160 virtual bool IsLoading() const OVERRIDE
;
161 virtual bool IsRenderView() const OVERRIDE
;
162 virtual void ResizeRectChanged(const gfx::Rect
& new_rect
) OVERRIDE
;
163 virtual void RestartHangMonitorTimeout() OVERRIDE
;
164 virtual void SetIgnoreInputEvents(bool ignore_input_events
) OVERRIDE
;
165 virtual void Stop() OVERRIDE
;
166 virtual void WasResized() OVERRIDE
;
167 virtual void AddKeyPressEventCallback(
168 const KeyPressEventCallback
& callback
) OVERRIDE
;
169 virtual void RemoveKeyPressEventCallback(
170 const KeyPressEventCallback
& callback
) OVERRIDE
;
171 virtual void AddMouseEventCallback(
172 const MouseEventCallback
& callback
) OVERRIDE
;
173 virtual void RemoveMouseEventCallback(
174 const MouseEventCallback
& callback
) OVERRIDE
;
175 virtual void GetWebScreenInfo(blink::WebScreenInfo
* result
) OVERRIDE
;
177 virtual SkBitmap::Config
PreferredReadbackFormat() OVERRIDE
;
179 // BrowserAccessibilityDelegate
180 virtual void AccessibilitySetFocus(int acc_obj_id
) OVERRIDE
;
181 virtual void AccessibilityDoDefaultAction(int acc_obj_id
) OVERRIDE
;
182 virtual void AccessibilityShowMenu(int acc_obj_id
) OVERRIDE
;
183 virtual void AccessibilityScrollToMakeVisible(
184 int acc_obj_id
, gfx::Rect subfocus
) OVERRIDE
;
185 virtual void AccessibilityScrollToPoint(
186 int acc_obj_id
, gfx::Point point
) OVERRIDE
;
187 virtual void AccessibilitySetTextSelection(
188 int acc_obj_id
, int start_offset
, int end_offset
) OVERRIDE
;
189 virtual bool AccessibilityViewHasFocus() const OVERRIDE
;
190 virtual gfx::Rect
AccessibilityGetViewBounds() const OVERRIDE
;
191 virtual gfx::Point
AccessibilityOriginInScreen(const gfx::Rect
& bounds
)
193 virtual void AccessibilityFatalError() OVERRIDE
;
195 const NativeWebKeyboardEvent
* GetLastKeyboardEvent() const;
197 // Notification that the screen info has changed.
198 void NotifyScreenInfoChanged();
200 // Invalidates the cached screen info so that next resize request
201 // will carry the up to date screen info. Unlike
202 // |NotifyScreenInfoChanged|, this doesn't send a message to the renderer.
203 void InvalidateScreenInfo();
205 // Sets the View of this RenderWidgetHost.
206 void SetView(RenderWidgetHostViewBase
* view
);
208 int surface_id() const { return surface_id_
; }
210 bool empty() const { return current_size_
.IsEmpty(); }
212 // Called when a renderer object already been created for this host, and we
213 // just need to be attached to it. Used for window.open, <select> dropdown
214 // menus, and other times when the renderer initiates creating an object.
217 // Tells the renderer to die and then calls Destroy().
218 virtual void Shutdown();
221 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
223 // Sends a message to the corresponding object in the renderer.
224 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
226 // Called to notify the RenderWidget that it has been hidden or restored from
227 // having been hidden.
231 // Returns true if the RenderWidget is hidden.
232 bool is_hidden() const { return is_hidden_
; }
234 // Called to notify the RenderWidget that its associated native window
236 virtual void GotFocus();
237 virtual void LostCapture();
239 // Called to notify the RenderWidget that it has lost the mouse lock.
240 virtual void LostMouseLock();
242 // Noifies the RenderWidget of the current mouse cursor visibility state.
243 void SendCursorVisibilityState(bool is_visible
);
245 // Tells us whether the page is rendered directly via the GPU process.
246 bool is_accelerated_compositing_active() {
247 return is_accelerated_compositing_active_
;
250 // Notifies the RenderWidgetHost that the View was destroyed.
251 void ViewDestroyed();
253 // Indicates if the page has finished loading.
254 void SetIsLoading(bool is_loading
);
256 // Pause for a moment to wait for pending repaint or resize messages sent to
257 // the renderer to arrive. If pending resize messages are for an old window
258 // size, then also pump through a new resize message if there is time.
259 void PauseForPendingResizeOrRepaints();
261 // Whether pausing may be useful.
262 bool CanPauseForPendingResizeOrRepaints();
264 // Wait for a surface matching the size of the widget's view, possibly
265 // blocking until the renderer sends a new frame.
266 void WaitForSurface();
268 // GPU accelerated version of GetBackingStore function. This will
269 // trigger a re-composite to the view. It may fail if a resize is pending, or
270 // if a composite has already been requested and not acked yet.
271 bool ScheduleComposite();
273 // Starts a hang monitor timeout. If there's already a hang monitor timeout
274 // the new one will only fire if it has a shorter delay than the time
275 // left on the existing timeouts.
276 void StartHangMonitorTimeout(base::TimeDelta delay
);
278 // Stops all existing hang monitor timeouts and assumes the renderer is
280 void StopHangMonitorTimeout();
282 // Forwards the given message to the renderer. These are called by the view
283 // when it has received a message.
284 void ForwardGestureEventWithLatencyInfo(
285 const blink::WebGestureEvent
& gesture_event
,
286 const ui::LatencyInfo
& ui_latency
);
287 void ForwardTouchEventWithLatencyInfo(
288 const blink::WebTouchEvent
& touch_event
,
289 const ui::LatencyInfo
& ui_latency
);
290 void ForwardMouseEventWithLatencyInfo(
291 const blink::WebMouseEvent
& mouse_event
,
292 const ui::LatencyInfo
& ui_latency
);
293 void ForwardWheelEventWithLatencyInfo(
294 const blink::WebMouseWheelEvent
& wheel_event
,
295 const ui::LatencyInfo
& ui_latency
);
297 // TouchEmulatorClient overrides.
298 virtual void ForwardGestureEvent(
299 const blink::WebGestureEvent
& gesture_event
) OVERRIDE
;
300 virtual void ForwardTouchEvent(
301 const blink::WebTouchEvent
& touch_event
) OVERRIDE
;
302 virtual void SetCursor(const WebCursor
& cursor
) OVERRIDE
;
304 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
305 // callback when the gesture is finished running.
306 void QueueSyntheticGesture(
307 scoped_ptr
<SyntheticGesture
> synthetic_gesture
,
308 const base::Callback
<void(SyntheticGesture::Result
)>& on_complete
);
310 void CancelUpdateTextDirection();
312 // Called when a mouse click/gesture tap activates the renderer.
313 virtual void OnPointerEventActivate();
315 // Notifies the renderer whether or not the input method attached to this
316 // process is activated.
317 // When the input method is activated, a renderer process sends IPC messages
318 // to notify the status of its composition node. (This message is mainly used
319 // for notifying the position of the input cursor so that the browser can
320 // display input method windows under the cursor.)
321 void SetInputMethodActive(bool activate
);
323 // Notifies the renderer changes of IME candidate window state.
324 void CandidateWindowShown();
325 void CandidateWindowUpdated();
326 void CandidateWindowHidden();
328 // Update the composition node of the renderer (or WebKit).
329 // WebKit has a special node (a composition node) for input method to change
330 // its text without affecting any other DOM nodes. When the input method
331 // (attached to the browser) updates its text, the browser sends IPC messages
332 // to update the composition node of the renderer.
333 // (Read the comments of each function for its detail.)
335 // Sets the text of the composition node.
336 // This function can also update the cursor position and mark the specified
337 // range in the composition node.
338 // A browser should call this function:
339 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
341 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
342 // * when markedText of NSTextInput is called (on Mac).
343 void ImeSetComposition(
344 const base::string16
& text
,
345 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
349 // Finishes an ongoing composition with the specified text.
350 // A browser should call this function:
351 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
353 // * when it receives a "commit" signal of GtkIMContext (on Linux);
354 // * when insertText of NSTextInput is called (on Mac).
355 void ImeConfirmComposition(const base::string16
& text
,
356 const gfx::Range
& replacement_range
,
357 bool keep_selection
);
359 // Cancels an ongoing composition.
360 void ImeCancelComposition();
362 // This is for derived classes to give us access to the resizer rect.
363 // And to also expose it to the RenderWidgetHostView.
364 virtual gfx::Rect
GetRootWindowResizerRect() const;
366 bool ignore_input_events() const {
367 return ignore_input_events_
;
370 bool input_method_active() const {
371 return input_method_active_
;
374 // Whether forwarded WebInputEvents should be ignored. True if either
375 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
376 bool IgnoreInputEvents() const;
378 // Event queries delegated to the |input_router_|.
379 bool ShouldForwardTouchEvent() const;
381 bool has_touch_handler() const { return has_touch_handler_
; }
383 // Notification that the user has made some kind of input that could
384 // perform an action. See OnUserGesture for more details.
385 void StartUserGesture();
387 // Set the RenderView background.
388 void SetBackground(const SkBitmap
& background
);
390 // Notifies the renderer that the next key event is bound to one or more
391 // pre-defined edit commands
392 void SetEditCommandsForNextKeyEvent(
393 const std::vector
<EditCommand
>& commands
);
395 // Gets the accessibility mode.
396 AccessibilityMode
accessibility_mode() const {
397 return accessibility_mode_
;
400 // Adds the given accessibility mode to the current accessibility mode bitmap.
401 void AddAccessibilityMode(AccessibilityMode mode
);
403 // Removes the given accessibility mode from the current accessibility mode
404 // bitmap, managing the bits that are shared with other modes such that a
405 // bit will only be turned off when all modes that depend on it have been
407 void RemoveAccessibilityMode(AccessibilityMode mode
);
409 // Resets the accessibility mode to the default setting in
410 // BrowserStateAccessibilityImpl.
411 void ResetAccessibilityMode();
414 void SetParentNativeViewAccessible(
415 gfx::NativeViewAccessible accessible_parent
);
416 gfx::NativeViewAccessible
GetParentNativeViewAccessible() const;
419 // Executes the edit command on the RenderView.
420 void ExecuteEditCommand(const std::string
& command
,
421 const std::string
& value
);
423 // Tells the renderer to scroll the currently focused node into rect only if
424 // the currently focused node is a Text node (textfield, text area or content
426 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect
& rect
);
428 // Requests the renderer to move the caret selection towards the point.
429 void MoveCaret(const gfx::Point
& point
);
431 // Called when the reponse to a pending mouse lock request has arrived.
432 // Returns true if |allowed| is true and the mouse has been successfully
434 bool GotResponseToLockMouseRequest(bool allowed
);
436 // Tells the RenderWidget about the latest vsync parameters.
437 // Note: Make sure the timebase was obtained using
438 // base::TimeTicks::HighResNow. Using the non-high res timer will result in
439 // incorrect synchronization across processes.
440 virtual void UpdateVSyncParameters(base::TimeTicks timebase
,
441 base::TimeDelta interval
);
443 // Called by the view in response to AcceleratedSurfaceBuffersSwapped or
444 // AcceleratedSurfacePostSubBuffer.
445 static void AcknowledgeBufferPresent(
448 const AcceleratedSurfaceMsg_BufferPresented_Params
& params
);
450 // Called by the view in response to OnSwapCompositorFrame.
451 static void SendSwapCompositorFrameAck(
453 uint32 output_surface_id
,
454 int renderer_host_id
,
455 const cc::CompositorFrameAck
& ack
);
457 // Called by the view to return resources to the compositor.
458 static void SendReclaimCompositorResources(int32 route_id
,
459 uint32 output_surface_id
,
460 int renderer_host_id
,
461 const cc::CompositorFrameAck
& ack
);
463 void set_allow_privileged_mouse_lock(bool allow
) {
464 allow_privileged_mouse_lock_
= allow
;
467 // Resets state variables related to tracking pending size and painting.
469 // We need to reset these flags when we want to repaint the contents of
470 // browser plugin in this RWH. Resetting these flags will ensure we ignore
471 // any previous pending acks that are not relevant upon repaint.
472 void ResetSizeAndRepaintPendingFlags();
474 void DetachDelegate();
476 // Update the renderer's cache of the screen rect of the view and window.
477 void SendScreenRects();
479 OverscrollController
* overscroll_controller() const {
480 return overscroll_controller_
.get();
483 // Sets whether the overscroll controller should be enabled for this page.
484 void SetOverscrollControllerEnabled(bool enabled
);
486 // Suppreses future char events until a keydown. See
487 // suppress_next_char_events_.
488 void SuppressNextCharEvents();
490 // Called by RenderWidgetHostView in response to OnSetNeedsFlushInput.
494 virtual void SetNeedsFlush() OVERRIDE
;
496 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
498 bool should_auto_resize() { return should_auto_resize_
; }
500 void ComputeTouchLatency(const ui::LatencyInfo
& latency_info
);
501 void FrameSwapped(const ui::LatencyInfo
& latency_info
);
502 void DidReceiveRendererFrame();
504 // Returns the ID that uniquely describes this component to the latency
506 int64
GetLatencyComponentId();
508 static void CompositorFrameDrawn(
509 const std::vector
<ui::LatencyInfo
>& latency_info
);
511 // Don't check whether we expected a resize ack during layout tests.
512 static void DisableResizeAckCheckForTesting();
514 void WindowSnapshotAsyncCallback(
517 gfx::Size snapshot_size
,
518 scoped_refptr
<base::RefCountedBytes
> png_data
);
520 // LatencyComponents generated in the renderer must have component IDs
521 // provided to them by the browser process. This function adds the correct
522 // component ID where necessary.
523 void AddLatencyInfoComponentIds(ui::LatencyInfo
* latency_info
);
525 InputRouter
* input_router() { return input_router_
.get(); }
528 virtual RenderWidgetHostImpl
* AsRenderWidgetHostImpl() OVERRIDE
;
530 // Create a LatencyInfo struct with INPUT_EVENT_LATENCY_RWH_COMPONENT
531 // component if it is not already in |original|. And if |original| is
532 // not NULL, it is also merged into the resulting LatencyInfo.
533 ui::LatencyInfo
CreateRWHLatencyInfoIfNotExist(
534 const ui::LatencyInfo
* original
, blink::WebInputEvent::Type type
);
536 // Called when we receive a notification indicating that the renderer
537 // process has gone. This will reset our state so that our state will be
538 // consistent if a new renderer is created.
539 void RendererExited(base::TerminationStatus status
, int exit_code
);
541 // Retrieves an id the renderer can use to refer to its view.
542 // This is used for various IPC messages, including plugins.
543 gfx::NativeViewId
GetNativeViewId() const;
545 // Retrieves an id for the surface that the renderer can draw to
546 // when accelerated compositing is enabled.
547 gfx::GLSurfaceHandle
GetCompositingSurface();
549 // ---------------------------------------------------------------------------
550 // The following methods are overridden by RenderViewHost to send upwards to
553 // Called when a mousewheel event was not processed by the renderer.
554 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent
& event
) {}
556 // Notification that the user has made some kind of input that could
557 // perform an action. The gestures that count are 1) any mouse down
558 // event and 2) enter or space key presses.
559 virtual void OnUserGesture() {}
561 // Callbacks for notification when the renderer becomes unresponsive to user
562 // input events, and subsequently responsive again.
563 virtual void NotifyRendererUnresponsive() {}
564 virtual void NotifyRendererResponsive() {}
566 // Called when auto-resize resulted in the renderer size changing.
567 virtual void OnRenderAutoResized(const gfx::Size
& new_size
) {}
569 // ---------------------------------------------------------------------------
571 // RenderViewHost overrides this method to impose further restrictions on when
572 // to allow mouse lock.
573 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
575 virtual void RequestToLockMouse(bool user_gesture
,
576 bool last_unlocked_by_target
);
578 void RejectMouseLockOrUnlockIfNecessary();
579 bool IsMouseLocked() const;
581 // RenderViewHost overrides this method to report when in fullscreen mode.
582 virtual bool IsFullscreen() const;
584 // Indicates if the render widget host should track the render widget's size
585 // as opposed to visa versa.
586 void SetShouldAutoResize(bool enable
);
588 // Expose increment/decrement of the in-flight event count, so
589 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
590 int increment_in_flight_event_count() { return ++in_flight_event_count_
; }
591 int decrement_in_flight_event_count() { return --in_flight_event_count_
; }
593 // Returns whether an overscroll gesture is in progress.
594 bool IsInOverscrollGesture() const;
596 // The View associated with the RenderViewHost. The lifetime of this object
597 // is associated with the lifetime of the Render process. If the Renderer
598 // crashes, its View is destroyed and this pointer becomes NULL, even though
599 // render_view_host_ lives on to load another URL (creating a new View while
601 RenderWidgetHostViewBase
* view_
;
603 // true if a renderer has once been valid. We use this flag to display a sad
604 // tab only when we lose our renderer and not if a paint occurs during
606 bool renderer_initialized_
;
608 // This value indicates how long to wait before we consider a renderer hung.
609 int hung_renderer_delay_ms_
;
612 friend class MockRenderWidgetHost
;
614 // Tell this object to destroy itself.
617 // Called by |hang_timeout_monitor_| on delayed response from the renderer.
618 void RendererIsUnresponsive();
620 // Called if we know the renderer is responsive. When we currently think the
621 // renderer is unresponsive, this will clear that state and call
622 // NotifyRendererResponsive.
623 void RendererIsResponsive();
625 // IPC message handlers
626 void OnRenderViewReady();
627 void OnRenderProcessGone(int status
, int error_code
);
629 void OnUpdateScreenRectsAck();
630 void OnRequestMove(const gfx::Rect
& pos
);
631 void OnSetTooltipText(const base::string16
& tooltip_text
,
632 blink::WebTextDirection text_direction_hint
);
633 #if defined(OS_MACOSX)
634 void OnCompositorSurfaceBuffersSwapped(
635 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params
& params
);
637 bool OnSwapCompositorFrame(const IPC::Message
& message
);
638 void OnFlingingStopped();
639 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params
& params
);
640 void OnUpdateIsDelayed();
641 void OnQueueSyntheticGesture(const SyntheticGesturePacket
& gesture_packet
);
642 virtual void OnFocus();
643 virtual void OnBlur();
644 void OnSetCursor(const WebCursor
& cursor
);
645 void OnSetTouchEventEmulationEnabled(bool enabled
, bool allow_pinch
);
646 void OnTextInputTypeChanged(ui::TextInputType type
,
647 ui::TextInputMode input_mode
,
648 bool can_compose_inline
);
649 #if defined(OS_MACOSX) || defined(USE_AURA)
650 void OnImeCompositionRangeChanged(
651 const gfx::Range
& range
,
652 const std::vector
<gfx::Rect
>& character_bounds
);
654 void OnImeCancelComposition();
655 void OnDidActivateAcceleratedCompositing(bool activated
);
656 void OnLockMouse(bool user_gesture
,
657 bool last_unlocked_by_target
,
659 void OnUnlockMouse();
660 void OnShowDisambiguationPopup(const gfx::Rect
& rect
,
661 const gfx::Size
& size
,
662 const cc::SharedBitmapId
& id
);
664 void OnWindowlessPluginDummyWindowCreated(
665 gfx::NativeViewId dummy_activation_window
);
666 void OnWindowlessPluginDummyWindowDestroyed(
667 gfx::NativeViewId dummy_activation_window
);
669 void OnSelectionChanged(const base::string16
& text
,
671 const gfx::Range
& range
);
672 void OnSelectionBoundsChanged(
673 const ViewHostMsg_SelectionBounds_Params
& params
);
674 void OnSnapshot(bool success
, const SkBitmap
& bitmap
);
676 // Called (either immediately or asynchronously) after we're done with our
677 // BackingStore and can send an ACK to the renderer so it can paint onto it
679 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params
& params
,
680 const base::TimeTicks
& paint_start
);
682 // Give key press listeners a chance to handle this key press. This allow
683 // widgets that don't have focus to still handle key presses.
684 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent
& event
);
687 virtual InputEventAckState
FilterInputEvent(
688 const blink::WebInputEvent
& event
,
689 const ui::LatencyInfo
& latency_info
) OVERRIDE
;
690 virtual void IncrementInFlightEventCount() OVERRIDE
;
691 virtual void DecrementInFlightEventCount() OVERRIDE
;
692 virtual void OnHasTouchEventHandlers(bool has_handlers
) OVERRIDE
;
693 virtual OverscrollController
* GetOverscrollController() const OVERRIDE
;
694 virtual void DidFlush() OVERRIDE
;
697 virtual void OnKeyboardEventAck(const NativeWebKeyboardEvent
& event
,
698 InputEventAckState ack_result
) OVERRIDE
;
699 virtual void OnWheelEventAck(const MouseWheelEventWithLatencyInfo
& event
,
700 InputEventAckState ack_result
) OVERRIDE
;
701 virtual void OnTouchEventAck(const TouchEventWithLatencyInfo
& event
,
702 InputEventAckState ack_result
) OVERRIDE
;
703 virtual void OnGestureEventAck(const GestureEventWithLatencyInfo
& event
,
704 InputEventAckState ack_result
) OVERRIDE
;
705 virtual void OnUnexpectedEventAck(UnexpectedEventAckType type
) OVERRIDE
;
707 void OnSyntheticGestureCompleted(SyntheticGesture::Result result
);
709 // Called when there is a new auto resize (using a post to avoid a stack
710 // which may get in recursive loops).
711 void DelayedAutoResized();
713 void WindowSnapshotReachedScreen(int snapshot_id
);
715 // Send a message to the renderer process to change the accessibility mode.
716 void SetAccessibilityMode(AccessibilityMode AccessibilityMode
);
718 // Our delegate, which wants to know mainly about keyboard events.
719 // It will remain non-NULL until DetachDelegate() is called.
720 RenderWidgetHostDelegate
* delegate_
;
722 // Created during construction but initialized during Init*(). Therefore, it
723 // is guaranteed never to be NULL, but its channel may be NULL if the
724 // renderer crashed, so you must always check that.
725 RenderProcessHost
* process_
;
727 // The ID of the corresponding object in the Renderer Instance.
730 // The ID of the surface corresponding to this render widget.
733 // Indicates whether a page is loading or not.
736 // Indicates whether a page is hidden or not.
739 // Indicates whether a page is fullscreen or not.
742 // True when a page is rendered directly via the GPU process.
743 bool is_accelerated_compositing_active_
;
745 // Set if we are waiting for a repaint ack for the view.
746 bool repaint_ack_pending_
;
748 // True when waiting for RESIZE_ACK.
749 bool resize_ack_pending_
;
751 // Cached copy of the screen info so that it doesn't need to be updated every
752 // time the window is resized.
753 scoped_ptr
<blink::WebScreenInfo
> screen_info_
;
755 // Set if screen_info_ may have changed and should be recomputed and force a
757 bool screen_info_out_of_date_
;
759 // The current size of the RenderWidget.
760 gfx::Size current_size_
;
762 // The size of the view's backing surface in non-DPI-adjusted pixels.
763 gfx::Size physical_backing_size_
;
765 // The height of the physical backing surface that is overdrawn opaquely in
766 // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
767 float overdraw_bottom_height_
;
769 // The size of the visible viewport, which may be smaller than the view if the
770 // view is partially occluded (e.g. by a virtual keyboard). The size is in
771 // DPI-adjusted pixels.
772 gfx::Size visible_viewport_size_
;
774 // The size we last sent as requested size to the renderer. |current_size_|
775 // is only updated once the resize message has been ack'd. This on the other
776 // hand is updated when the resize message is sent. This is very similar to
777 // |resize_ack_pending_|, but the latter is not set if the new size has width
778 // or height zero, which is why we need this too.
779 gfx::Size last_requested_size_
;
781 // The next auto resize to send.
782 gfx::Size new_auto_size_
;
784 // True if the render widget host should track the render widget's size as
785 // opposed to visa versa.
786 bool should_auto_resize_
;
788 bool waiting_for_screen_rects_ack_
;
789 gfx::Rect last_view_screen_rect_
;
790 gfx::Rect last_window_screen_rect_
;
792 AccessibilityMode accessibility_mode_
;
794 // Keyboard event listeners.
795 std::vector
<KeyPressEventCallback
> key_press_event_callbacks_
;
797 // Mouse event callbacks.
798 std::vector
<MouseEventCallback
> mouse_event_callbacks_
;
800 // If true, then we should repaint when restoring even if we have a
801 // backingstore. This flag is set to true if we receive a paint message
802 // while is_hidden_ to true. Even though we tell the render widget to hide
803 // itself, a paint message could already be in flight at that point.
804 bool needs_repainting_on_restore_
;
806 // This is true if the renderer is currently unresponsive.
807 bool is_unresponsive_
;
809 // The following value indicates a time in the future when we would consider
810 // the renderer hung if it does not generate an appropriate response message.
811 base::Time time_when_considered_hung_
;
813 // This value denotes the number of input events yet to be acknowledged
815 int in_flight_event_count_
;
817 // This timer runs to check if time_when_considered_hung_ has past.
818 base::OneShotTimer
<RenderWidgetHostImpl
> hung_renderer_timer_
;
820 // Flag to detect recursive calls to GetBackingStore().
821 bool in_get_backing_store_
;
823 // Flag to trigger the GetBackingStore method to abort early.
824 bool abort_get_backing_store_
;
826 // Set when we call DidPaintRect/DidScrollRect on the view.
827 bool view_being_painted_
;
829 // Used for UMA histogram logging to measure the time for a repaint view
830 // operation to finish.
831 base::TimeTicks repaint_start_time_
;
833 // Set to true if we shouldn't send input events from the render widget.
834 bool ignore_input_events_
;
836 // Indicates whether IME is active.
837 bool input_method_active_
;
839 // Set when we update the text direction of the selected input element.
840 bool text_direction_updated_
;
841 blink::WebTextDirection text_direction_
;
843 // Set when we cancel updating the text direction.
844 // This flag also ignores succeeding update requests until we call
845 // NotifyTextDirection().
846 bool text_direction_canceled_
;
848 // Indicates if the next sequence of Char events should be suppressed or not.
849 // System may translate a RawKeyDown event into zero or more Char events,
850 // usually we send them to the renderer directly in sequence. However, If a
851 // RawKeyDown event was not handled by the renderer but was handled by
852 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
853 // shall not send the following sequence of Char events, which was generated
854 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
855 // handle the Char events and cause unexpected behavior.
856 // For example, pressing alt-2 may let the browser switch to the second tab,
857 // but the Char event generated by alt-2 may also activate a HTML element
858 // if its accesskey happens to be "2", then the user may get confused when
859 // switching back to the original tab, because the content may already be
861 bool suppress_next_char_events_
;
863 // The last scroll offset of the render widget.
864 gfx::Vector2d last_scroll_offset_
;
866 bool pending_mouse_lock_request_
;
867 bool allow_privileged_mouse_lock_
;
869 // Keeps track of whether the webpage has any touch event handler. If it does,
870 // then touch events are sent to the renderer. Otherwise, the touch events are
871 // not sent to the renderer.
872 bool has_touch_handler_
;
874 base::WeakPtrFactory
<RenderWidgetHostImpl
> weak_factory_
;
876 scoped_ptr
<SyntheticGestureController
> synthetic_gesture_controller_
;
878 scoped_ptr
<TouchEmulator
> touch_emulator_
;
880 // Receives and handles all input events.
881 scoped_ptr
<InputRouter
> input_router_
;
883 scoped_ptr
<OverscrollController
> overscroll_controller_
;
885 scoped_ptr
<TimeoutMonitor
> hang_monitor_timeout_
;
888 std::list
<HWND
> dummy_windows_for_activation_
;
891 int64 last_input_number_
;
893 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl
);
896 } // namespace content
898 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_