Implement Android accessible hit testing using an IPC to the renderer process.
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_impl.h
blob7080894ea63d423c31651db54342fc0e2fb3521a
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_
8 #include <deque>
9 #include <list>
10 #include <map>
11 #include <queue>
12 #include <string>
13 #include <utility>
14 #include <vector>
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;
51 namespace base {
52 class TimeTicks;
55 namespace cc {
56 class CompositorFrame;
57 class CompositorFrameAck;
60 namespace gfx {
61 class Range;
64 namespace ui {
65 class KeyEvent;
68 namespace blink {
69 class WebInputEvent;
70 class WebMouseEvent;
71 struct WebCompositionUnderline;
72 struct WebScreenInfo;
75 #if defined(OS_ANDROID)
76 namespace blink {
77 class WebLayer;
79 #endif
81 namespace content {
82 class InputRouter;
83 class MockRenderWidgetHost;
84 class OverscrollController;
85 class RenderWidgetHostDelegate;
86 class RenderWidgetHostViewBase;
87 class SyntheticGestureController;
88 class TimeoutMonitor;
89 class TouchEmulator;
90 class WebCursor;
91 struct EditCommand;
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 {
102 public:
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,
109 int routing_id,
110 bool hidden);
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;
145 #endif
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)
192 const OVERRIDE;
193 virtual void AccessibilityHitTest(const gfx::Point& point) OVERRIDE;
194 virtual void AccessibilityFatalError() OVERRIDE;
196 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const;
198 // Notification that the screen info has changed.
199 void NotifyScreenInfoChanged();
201 // Invalidates the cached screen info so that next resize request
202 // will carry the up to date screen info. Unlike
203 // |NotifyScreenInfoChanged|, this doesn't send a message to the renderer.
204 void InvalidateScreenInfo();
206 // Sets the View of this RenderWidgetHost.
207 void SetView(RenderWidgetHostViewBase* view);
209 int surface_id() const { return surface_id_; }
211 bool empty() const { return current_size_.IsEmpty(); }
213 // Called when a renderer object already been created for this host, and we
214 // just need to be attached to it. Used for window.open, <select> dropdown
215 // menus, and other times when the renderer initiates creating an object.
216 virtual void Init();
218 // Tells the renderer to die and then calls Destroy().
219 virtual void Shutdown();
221 // IPC::Listener
222 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
224 // Sends a message to the corresponding object in the renderer.
225 virtual bool Send(IPC::Message* msg) OVERRIDE;
227 // Called to notify the RenderWidget that it has been hidden or restored from
228 // having been hidden.
229 void WasHidden();
230 void WasShown();
232 // Returns true if the RenderWidget is hidden.
233 bool is_hidden() const { return is_hidden_; }
235 // Called to notify the RenderWidget that its associated native window
236 // got/lost focused.
237 virtual void GotFocus();
238 virtual void LostCapture();
240 // Called to notify the RenderWidget that it has lost the mouse lock.
241 virtual void LostMouseLock();
243 // Noifies the RenderWidget of the current mouse cursor visibility state.
244 void SendCursorVisibilityState(bool is_visible);
246 // Notifies the RenderWidgetHost that the View was destroyed.
247 void ViewDestroyed();
249 // Indicates if the page has finished loading.
250 void SetIsLoading(bool is_loading);
252 // Pause for a moment to wait for pending repaint or resize messages sent to
253 // the renderer to arrive. If pending resize messages are for an old window
254 // size, then also pump through a new resize message if there is time.
255 void PauseForPendingResizeOrRepaints();
257 // Whether pausing may be useful.
258 bool CanPauseForPendingResizeOrRepaints();
260 // Wait for a surface matching the size of the widget's view, possibly
261 // blocking until the renderer sends a new frame.
262 void WaitForSurface();
264 // GPU accelerated version of GetBackingStore function. This will
265 // trigger a re-composite to the view. It may fail if a resize is pending, or
266 // if a composite has already been requested and not acked yet.
267 bool ScheduleComposite();
269 // Starts a hang monitor timeout. If there's already a hang monitor timeout
270 // the new one will only fire if it has a shorter delay than the time
271 // left on the existing timeouts.
272 void StartHangMonitorTimeout(base::TimeDelta delay);
274 // Stops all existing hang monitor timeouts and assumes the renderer is
275 // responsive.
276 void StopHangMonitorTimeout();
278 // Forwards the given message to the renderer. These are called by the view
279 // when it has received a message.
280 void ForwardGestureEventWithLatencyInfo(
281 const blink::WebGestureEvent& gesture_event,
282 const ui::LatencyInfo& ui_latency);
283 void ForwardTouchEventWithLatencyInfo(
284 const blink::WebTouchEvent& touch_event,
285 const ui::LatencyInfo& ui_latency);
286 void ForwardMouseEventWithLatencyInfo(
287 const blink::WebMouseEvent& mouse_event,
288 const ui::LatencyInfo& ui_latency);
289 void ForwardWheelEventWithLatencyInfo(
290 const blink::WebMouseWheelEvent& wheel_event,
291 const ui::LatencyInfo& ui_latency);
293 // TouchEmulatorClient overrides.
294 virtual void ForwardGestureEvent(
295 const blink::WebGestureEvent& gesture_event) OVERRIDE;
296 virtual void ForwardTouchEvent(
297 const blink::WebTouchEvent& touch_event) OVERRIDE;
298 virtual void SetCursor(const WebCursor& cursor) OVERRIDE;
300 // Queues a synthetic gesture for testing purposes. Invokes the on_complete
301 // callback when the gesture is finished running.
302 void QueueSyntheticGesture(
303 scoped_ptr<SyntheticGesture> synthetic_gesture,
304 const base::Callback<void(SyntheticGesture::Result)>& on_complete);
306 void CancelUpdateTextDirection();
308 // Called when a mouse click/gesture tap activates the renderer.
309 virtual void OnPointerEventActivate();
311 // Notifies the renderer whether or not the input method attached to this
312 // process is activated.
313 // When the input method is activated, a renderer process sends IPC messages
314 // to notify the status of its composition node. (This message is mainly used
315 // for notifying the position of the input cursor so that the browser can
316 // display input method windows under the cursor.)
317 void SetInputMethodActive(bool activate);
319 // Notifies the renderer changes of IME candidate window state.
320 void CandidateWindowShown();
321 void CandidateWindowUpdated();
322 void CandidateWindowHidden();
324 // Update the composition node of the renderer (or WebKit).
325 // WebKit has a special node (a composition node) for input method to change
326 // its text without affecting any other DOM nodes. When the input method
327 // (attached to the browser) updates its text, the browser sends IPC messages
328 // to update the composition node of the renderer.
329 // (Read the comments of each function for its detail.)
331 // Sets the text of the composition node.
332 // This function can also update the cursor position and mark the specified
333 // range in the composition node.
334 // A browser should call this function:
335 // * when it receives a WM_IME_COMPOSITION message with a GCS_COMPSTR flag
336 // (on Windows);
337 // * when it receives a "preedit_changed" signal of GtkIMContext (on Linux);
338 // * when markedText of NSTextInput is called (on Mac).
339 void ImeSetComposition(
340 const base::string16& text,
341 const std::vector<blink::WebCompositionUnderline>& underlines,
342 int selection_start,
343 int selection_end);
345 // Finishes an ongoing composition with the specified text.
346 // A browser should call this function:
347 // * when it receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR flag
348 // (on Windows);
349 // * when it receives a "commit" signal of GtkIMContext (on Linux);
350 // * when insertText of NSTextInput is called (on Mac).
351 void ImeConfirmComposition(const base::string16& text,
352 const gfx::Range& replacement_range,
353 bool keep_selection);
355 // Cancels an ongoing composition.
356 void ImeCancelComposition();
358 // This is for derived classes to give us access to the resizer rect.
359 // And to also expose it to the RenderWidgetHostView.
360 virtual gfx::Rect GetRootWindowResizerRect() const;
362 bool ignore_input_events() const {
363 return ignore_input_events_;
366 bool input_method_active() const {
367 return input_method_active_;
370 // Whether forwarded WebInputEvents should be ignored. True if either
371 // |ignore_input_events_| or |process_->IgnoreInputEvents()| is true.
372 bool IgnoreInputEvents() const;
374 // Event queries delegated to the |input_router_|.
375 bool ShouldForwardTouchEvent() const;
377 bool has_touch_handler() const { return has_touch_handler_; }
379 // Notification that the user has made some kind of input that could
380 // perform an action. See OnUserGesture for more details.
381 void StartUserGesture();
383 // Set the RenderView background transparency.
384 void SetBackgroundOpaque(bool opaque);
386 // Notifies the renderer that the next key event is bound to one or more
387 // pre-defined edit commands
388 void SetEditCommandsForNextKeyEvent(
389 const std::vector<EditCommand>& commands);
391 // Gets the accessibility mode.
392 AccessibilityMode accessibility_mode() const {
393 return accessibility_mode_;
396 // Adds the given accessibility mode to the current accessibility mode bitmap.
397 void AddAccessibilityMode(AccessibilityMode mode);
399 // Removes the given accessibility mode from the current accessibility mode
400 // bitmap, managing the bits that are shared with other modes such that a
401 // bit will only be turned off when all modes that depend on it have been
402 // removed.
403 void RemoveAccessibilityMode(AccessibilityMode mode);
405 // Resets the accessibility mode to the default setting in
406 // BrowserStateAccessibilityImpl.
407 void ResetAccessibilityMode();
409 #if defined(OS_WIN)
410 void SetParentNativeViewAccessible(
411 gfx::NativeViewAccessible accessible_parent);
412 gfx::NativeViewAccessible GetParentNativeViewAccessible() const;
413 #endif
415 // Executes the edit command on the RenderView.
416 void ExecuteEditCommand(const std::string& command,
417 const std::string& value);
419 // Tells the renderer to scroll the currently focused node into rect only if
420 // the currently focused node is a Text node (textfield, text area or content
421 // editable divs).
422 void ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
424 // Requests the renderer to move the caret selection towards the point.
425 void MoveCaret(const gfx::Point& point);
427 // Called when the reponse to a pending mouse lock request has arrived.
428 // Returns true if |allowed| is true and the mouse has been successfully
429 // locked.
430 bool GotResponseToLockMouseRequest(bool allowed);
432 // Tells the RenderWidget about the latest vsync parameters.
433 // Note: Make sure the timebase was obtained using
434 // base::TimeTicks::HighResNow. Using the non-high res timer will result in
435 // incorrect synchronization across processes.
436 virtual void UpdateVSyncParameters(base::TimeTicks timebase,
437 base::TimeDelta interval);
439 // Called by the view in response to AcceleratedSurfaceBuffersSwapped or
440 // AcceleratedSurfacePostSubBuffer.
441 static void AcknowledgeBufferPresent(
442 int32 route_id,
443 int gpu_host_id,
444 const AcceleratedSurfaceMsg_BufferPresented_Params& params);
446 // Called by the view in response to OnSwapCompositorFrame.
447 static void SendSwapCompositorFrameAck(
448 int32 route_id,
449 uint32 output_surface_id,
450 int renderer_host_id,
451 const cc::CompositorFrameAck& ack);
453 // Called by the view to return resources to the compositor.
454 static void SendReclaimCompositorResources(int32 route_id,
455 uint32 output_surface_id,
456 int renderer_host_id,
457 const cc::CompositorFrameAck& ack);
459 void set_allow_privileged_mouse_lock(bool allow) {
460 allow_privileged_mouse_lock_ = allow;
463 // Resets state variables related to tracking pending size and painting.
465 // We need to reset these flags when we want to repaint the contents of
466 // browser plugin in this RWH. Resetting these flags will ensure we ignore
467 // any previous pending acks that are not relevant upon repaint.
468 void ResetSizeAndRepaintPendingFlags();
470 void DetachDelegate();
472 // Update the renderer's cache of the screen rect of the view and window.
473 void SendScreenRects();
475 OverscrollController* overscroll_controller() const {
476 return overscroll_controller_.get();
479 // Sets whether the overscroll controller should be enabled for this page.
480 void SetOverscrollControllerEnabled(bool enabled);
482 // Suppreses future char events until a keydown. See
483 // suppress_next_char_events_.
484 void SuppressNextCharEvents();
486 // Called by RenderWidgetHostView in response to OnSetNeedsFlushInput.
487 void FlushInput();
489 // InputRouterClient
490 virtual void SetNeedsFlush() OVERRIDE;
492 // Indicates whether the renderer drives the RenderWidgetHosts's size or the
493 // other way around.
494 bool should_auto_resize() { return should_auto_resize_; }
496 void ComputeTouchLatency(const ui::LatencyInfo& latency_info);
497 void FrameSwapped(const ui::LatencyInfo& latency_info);
498 void DidReceiveRendererFrame();
500 // Returns the ID that uniquely describes this component to the latency
501 // subsystem.
502 int64 GetLatencyComponentId();
504 static void CompositorFrameDrawn(
505 const std::vector<ui::LatencyInfo>& latency_info);
507 // Don't check whether we expected a resize ack during layout tests.
508 static void DisableResizeAckCheckForTesting();
510 void WindowSnapshotAsyncCallback(
511 int routing_id,
512 int snapshot_id,
513 gfx::Size snapshot_size,
514 scoped_refptr<base::RefCountedBytes> png_data);
516 // LatencyComponents generated in the renderer must have component IDs
517 // provided to them by the browser process. This function adds the correct
518 // component ID where necessary.
519 void AddLatencyInfoComponentIds(ui::LatencyInfo* latency_info);
521 InputRouter* input_router() { return input_router_.get(); }
523 protected:
524 virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() OVERRIDE;
526 // Create a LatencyInfo struct with INPUT_EVENT_LATENCY_RWH_COMPONENT
527 // component if it is not already in |original|. And if |original| is
528 // not NULL, it is also merged into the resulting LatencyInfo.
529 ui::LatencyInfo CreateRWHLatencyInfoIfNotExist(
530 const ui::LatencyInfo* original, blink::WebInputEvent::Type type);
532 // Called when we receive a notification indicating that the renderer
533 // process has gone. This will reset our state so that our state will be
534 // consistent if a new renderer is created.
535 void RendererExited(base::TerminationStatus status, int exit_code);
537 // Retrieves an id the renderer can use to refer to its view.
538 // This is used for various IPC messages, including plugins.
539 gfx::NativeViewId GetNativeViewId() const;
541 // Retrieves an id for the surface that the renderer can draw to
542 // when accelerated compositing is enabled.
543 gfx::GLSurfaceHandle GetCompositingSurface();
545 // ---------------------------------------------------------------------------
546 // The following methods are overridden by RenderViewHost to send upwards to
547 // its delegate.
549 // Called when a mousewheel event was not processed by the renderer.
550 virtual void UnhandledWheelEvent(const blink::WebMouseWheelEvent& event) {}
552 // Notification that the user has made some kind of input that could
553 // perform an action. The gestures that count are 1) any mouse down
554 // event and 2) enter or space key presses.
555 virtual void OnUserGesture() {}
557 // Callbacks for notification when the renderer becomes unresponsive to user
558 // input events, and subsequently responsive again.
559 virtual void NotifyRendererUnresponsive() {}
560 virtual void NotifyRendererResponsive() {}
562 // Called when auto-resize resulted in the renderer size changing.
563 virtual void OnRenderAutoResized(const gfx::Size& new_size) {}
565 // ---------------------------------------------------------------------------
567 // RenderViewHost overrides this method to impose further restrictions on when
568 // to allow mouse lock.
569 // Once the request is approved or rejected, GotResponseToLockMouseRequest()
570 // will be called.
571 virtual void RequestToLockMouse(bool user_gesture,
572 bool last_unlocked_by_target);
574 void RejectMouseLockOrUnlockIfNecessary();
575 bool IsMouseLocked() const;
577 // RenderViewHost overrides this method to report when in fullscreen mode.
578 virtual bool IsFullscreen() const;
580 // Indicates if the render widget host should track the render widget's size
581 // as opposed to visa versa.
582 void SetShouldAutoResize(bool enable);
584 // Expose increment/decrement of the in-flight event count, so
585 // RenderViewHostImpl can account for in-flight beforeunload/unload events.
586 int increment_in_flight_event_count() { return ++in_flight_event_count_; }
587 int decrement_in_flight_event_count() { return --in_flight_event_count_; }
589 // Returns whether an overscroll gesture is in progress.
590 bool IsInOverscrollGesture() const;
592 // The View associated with the RenderViewHost. The lifetime of this object
593 // is associated with the lifetime of the Render process. If the Renderer
594 // crashes, its View is destroyed and this pointer becomes NULL, even though
595 // render_view_host_ lives on to load another URL (creating a new View while
596 // doing so).
597 RenderWidgetHostViewBase* view_;
599 // true if a renderer has once been valid. We use this flag to display a sad
600 // tab only when we lose our renderer and not if a paint occurs during
601 // initialization.
602 bool renderer_initialized_;
604 // This value indicates how long to wait before we consider a renderer hung.
605 int hung_renderer_delay_ms_;
607 private:
608 friend class MockRenderWidgetHost;
610 // Tell this object to destroy itself.
611 void Destroy();
613 // Called by |hang_timeout_monitor_| on delayed response from the renderer.
614 void RendererIsUnresponsive();
616 // Called if we know the renderer is responsive. When we currently think the
617 // renderer is unresponsive, this will clear that state and call
618 // NotifyRendererResponsive.
619 void RendererIsResponsive();
621 // IPC message handlers
622 void OnRenderViewReady();
623 void OnRenderProcessGone(int status, int error_code);
624 void OnClose();
625 void OnUpdateScreenRectsAck();
626 void OnRequestMove(const gfx::Rect& pos);
627 void OnSetTooltipText(const base::string16& tooltip_text,
628 blink::WebTextDirection text_direction_hint);
629 #if defined(OS_MACOSX)
630 void OnCompositorSurfaceBuffersSwapped(
631 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params& params);
632 #endif
633 bool OnSwapCompositorFrame(const IPC::Message& message);
634 void OnFlingingStopped();
635 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
636 void OnQueueSyntheticGesture(const SyntheticGesturePacket& gesture_packet);
637 virtual void OnFocus();
638 virtual void OnBlur();
639 void OnSetCursor(const WebCursor& cursor);
640 void OnSetTouchEventEmulationEnabled(bool enabled, bool allow_pinch);
641 void OnTextInputTypeChanged(ui::TextInputType type,
642 ui::TextInputMode input_mode,
643 bool can_compose_inline);
644 #if defined(OS_MACOSX) || defined(USE_AURA)
645 void OnImeCompositionRangeChanged(
646 const gfx::Range& range,
647 const std::vector<gfx::Rect>& character_bounds);
648 #endif
649 void OnImeCancelComposition();
650 void OnLockMouse(bool user_gesture,
651 bool last_unlocked_by_target,
652 bool privileged);
653 void OnUnlockMouse();
654 void OnShowDisambiguationPopup(const gfx::Rect& rect,
655 const gfx::Size& size,
656 const cc::SharedBitmapId& id);
657 #if defined(OS_WIN)
658 void OnWindowlessPluginDummyWindowCreated(
659 gfx::NativeViewId dummy_activation_window);
660 void OnWindowlessPluginDummyWindowDestroyed(
661 gfx::NativeViewId dummy_activation_window);
662 #endif
663 void OnSelectionChanged(const base::string16& text,
664 size_t offset,
665 const gfx::Range& range);
666 void OnSelectionBoundsChanged(
667 const ViewHostMsg_SelectionBounds_Params& params);
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
672 // again.
673 void DidUpdateBackingStore(const ViewHostMsg_UpdateRect_Params& params,
674 const base::TimeTicks& paint_start);
676 // Give key press listeners a chance to handle this key press. This allow
677 // widgets that don't have focus to still handle key presses.
678 bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
680 // InputRouterClient
681 virtual InputEventAckState FilterInputEvent(
682 const blink::WebInputEvent& event,
683 const ui::LatencyInfo& latency_info) OVERRIDE;
684 virtual void IncrementInFlightEventCount() OVERRIDE;
685 virtual void DecrementInFlightEventCount() OVERRIDE;
686 virtual void OnHasTouchEventHandlers(bool has_handlers) OVERRIDE;
687 virtual OverscrollController* GetOverscrollController() const OVERRIDE;
688 virtual void DidFlush() OVERRIDE;
689 virtual void DidOverscroll(const DidOverscrollParams& params) OVERRIDE;
691 // InputAckHandler
692 virtual void OnKeyboardEventAck(const NativeWebKeyboardEvent& event,
693 InputEventAckState ack_result) OVERRIDE;
694 virtual void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event,
695 InputEventAckState ack_result) OVERRIDE;
696 virtual void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
697 InputEventAckState ack_result) OVERRIDE;
698 virtual void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
699 InputEventAckState ack_result) OVERRIDE;
700 virtual void OnUnexpectedEventAck(UnexpectedEventAckType type) OVERRIDE;
702 void OnSyntheticGestureCompleted(SyntheticGesture::Result result);
704 // Called when there is a new auto resize (using a post to avoid a stack
705 // which may get in recursive loops).
706 void DelayedAutoResized();
708 void WindowSnapshotReachedScreen(int snapshot_id);
710 // Send a message to the renderer process to change the accessibility mode.
711 void SetAccessibilityMode(AccessibilityMode AccessibilityMode);
713 // Our delegate, which wants to know mainly about keyboard events.
714 // It will remain non-NULL until DetachDelegate() is called.
715 RenderWidgetHostDelegate* delegate_;
717 // Created during construction but initialized during Init*(). Therefore, it
718 // is guaranteed never to be NULL, but its channel may be NULL if the
719 // renderer crashed, so you must always check that.
720 RenderProcessHost* process_;
722 // The ID of the corresponding object in the Renderer Instance.
723 int routing_id_;
725 // The ID of the surface corresponding to this render widget.
726 int surface_id_;
728 // Indicates whether a page is loading or not.
729 bool is_loading_;
731 // Indicates whether a page is hidden or not.
732 bool is_hidden_;
734 // Indicates whether a page is fullscreen or not.
735 bool is_fullscreen_;
737 // Set if we are waiting for a repaint ack for the view.
738 bool repaint_ack_pending_;
740 // True when waiting for RESIZE_ACK.
741 bool resize_ack_pending_;
743 // Cached copy of the screen info so that it doesn't need to be updated every
744 // time the window is resized.
745 scoped_ptr<blink::WebScreenInfo> screen_info_;
747 // Set if screen_info_ may have changed and should be recomputed and force a
748 // resize message.
749 bool screen_info_out_of_date_;
751 // The current size of the RenderWidget.
752 gfx::Size current_size_;
754 // The size of the view's backing surface in non-DPI-adjusted pixels.
755 gfx::Size physical_backing_size_;
757 // The height of the physical backing surface that is overdrawn opaquely in
758 // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
759 float overdraw_bottom_height_;
761 // The size of the visible viewport, which may be smaller than the view if the
762 // view is partially occluded (e.g. by a virtual keyboard). The size is in
763 // DPI-adjusted pixels.
764 gfx::Size visible_viewport_size_;
766 // The size we last sent as requested size to the renderer. |current_size_|
767 // is only updated once the resize message has been ack'd. This on the other
768 // hand is updated when the resize message is sent. This is very similar to
769 // |resize_ack_pending_|, but the latter is not set if the new size has width
770 // or height zero, which is why we need this too.
771 gfx::Size last_requested_size_;
773 // The next auto resize to send.
774 gfx::Size new_auto_size_;
776 // True if the render widget host should track the render widget's size as
777 // opposed to visa versa.
778 bool should_auto_resize_;
780 bool waiting_for_screen_rects_ack_;
781 gfx::Rect last_view_screen_rect_;
782 gfx::Rect last_window_screen_rect_;
784 AccessibilityMode accessibility_mode_;
786 // Keyboard event listeners.
787 std::vector<KeyPressEventCallback> key_press_event_callbacks_;
789 // Mouse event callbacks.
790 std::vector<MouseEventCallback> mouse_event_callbacks_;
792 // If true, then we should repaint when restoring even if we have a
793 // backingstore. This flag is set to true if we receive a paint message
794 // while is_hidden_ to true. Even though we tell the render widget to hide
795 // itself, a paint message could already be in flight at that point.
796 bool needs_repainting_on_restore_;
798 // This is true if the renderer is currently unresponsive.
799 bool is_unresponsive_;
801 // The following value indicates a time in the future when we would consider
802 // the renderer hung if it does not generate an appropriate response message.
803 base::Time time_when_considered_hung_;
805 // This value denotes the number of input events yet to be acknowledged
806 // by the renderer.
807 int in_flight_event_count_;
809 // This timer runs to check if time_when_considered_hung_ has past.
810 base::OneShotTimer<RenderWidgetHostImpl> hung_renderer_timer_;
812 // Flag to detect recursive calls to GetBackingStore().
813 bool in_get_backing_store_;
815 // Used for UMA histogram logging to measure the time for a repaint view
816 // operation to finish.
817 base::TimeTicks repaint_start_time_;
819 // Set to true if we shouldn't send input events from the render widget.
820 bool ignore_input_events_;
822 // Indicates whether IME is active.
823 bool input_method_active_;
825 // Set when we update the text direction of the selected input element.
826 bool text_direction_updated_;
827 blink::WebTextDirection text_direction_;
829 // Set when we cancel updating the text direction.
830 // This flag also ignores succeeding update requests until we call
831 // NotifyTextDirection().
832 bool text_direction_canceled_;
834 // Indicates if the next sequence of Char events should be suppressed or not.
835 // System may translate a RawKeyDown event into zero or more Char events,
836 // usually we send them to the renderer directly in sequence. However, If a
837 // RawKeyDown event was not handled by the renderer but was handled by
838 // our UnhandledKeyboardEvent() method, e.g. as an accelerator key, then we
839 // shall not send the following sequence of Char events, which was generated
840 // by this RawKeyDown event, to the renderer. Otherwise the renderer may
841 // handle the Char events and cause unexpected behavior.
842 // For example, pressing alt-2 may let the browser switch to the second tab,
843 // but the Char event generated by alt-2 may also activate a HTML element
844 // if its accesskey happens to be "2", then the user may get confused when
845 // switching back to the original tab, because the content may already be
846 // changed.
847 bool suppress_next_char_events_;
849 // The last scroll offset of the render widget.
850 gfx::Vector2d last_scroll_offset_;
852 bool pending_mouse_lock_request_;
853 bool allow_privileged_mouse_lock_;
855 // Keeps track of whether the webpage has any touch event handler. If it does,
856 // then touch events are sent to the renderer. Otherwise, the touch events are
857 // not sent to the renderer.
858 bool has_touch_handler_;
860 base::WeakPtrFactory<RenderWidgetHostImpl> weak_factory_;
862 scoped_ptr<SyntheticGestureController> synthetic_gesture_controller_;
864 scoped_ptr<TouchEmulator> touch_emulator_;
866 // Receives and handles all input events.
867 scoped_ptr<InputRouter> input_router_;
869 scoped_ptr<OverscrollController> overscroll_controller_;
871 scoped_ptr<TimeoutMonitor> hang_monitor_timeout_;
873 #if defined(OS_WIN)
874 std::list<HWND> dummy_windows_for_activation_;
875 #endif
877 int64 last_input_number_;
879 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostImpl);
882 } // namespace content
884 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_IMPL_H_