Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / renderer / render_widget.h
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.
4
5 #ifndef CONTENT_RENDERER_RENDER_WIDGET_H_
6 #define CONTENT_RENDERER_RENDER_WIDGET_H_
7
8 #include <deque>
9 #include <map>
10
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/time/time.h"
17 #include "base/timer/timer.h"
18 #include "cc/debug/rendering_stats_instrumentation.h"
19 #include "content/common/content_export.h"
20 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
21 #include "content/common/input/synthetic_gesture_params.h"
22 #include "content/renderer/paint_aggregator.h"
23 #include "ipc/ipc_listener.h"
24 #include "ipc/ipc_sender.h"
25 #include "third_party/WebKit/public/platform/WebRect.h"
26 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
27 #include "third_party/WebKit/public/web/WebPopupType.h"
28 #include "third_party/WebKit/public/web/WebTextDirection.h"
29 #include "third_party/WebKit/public/web/WebTextInputInfo.h"
30 #include "third_party/WebKit/public/web/WebTouchAction.h"
31 #include "third_party/WebKit/public/web/WebWidget.h"
32 #include "third_party/WebKit/public/web/WebWidgetClient.h"
33 #include "third_party/skia/include/core/SkBitmap.h"
34 #include "ui/base/ime/text_input_mode.h"
35 #include "ui/base/ime/text_input_type.h"
36 #include "ui/base/ui_base_types.h"
37 #include "ui/gfx/native_widget_types.h"
38 #include "ui/gfx/range/range.h"
39 #include "ui/gfx/rect.h"
40 #include "ui/gfx/vector2d.h"
41 #include "ui/gfx/vector2d_f.h"
42 #include "ui/surface/transport_dib.h"
43 #include "webkit/common/cursors/webcursor.h"
44
45 struct ViewHostMsg_UpdateRect_Params;
46 struct ViewMsg_Resize_Params;
47 class ViewHostMsg_UpdateRect;
48
49 namespace IPC {
50 class SyncMessage;
51 }
52
53 namespace blink {
54 class WebGestureEvent;
55 class WebInputEvent;
56 class WebKeyboardEvent;
57 class WebMouseEvent;
58 class WebTouchEvent;
59 }
60
61 namespace cc { class OutputSurface; }
62
63 namespace gfx {
64 class Range;
65 }
66
67 namespace content {
68 class ExternalPopupMenu;
69 class PepperPluginInstanceImpl;
70 class RenderFrameImpl;
71 class RenderWidgetCompositor;
72 class RenderWidgetTest;
73 class ResizingModeSelector;
74 struct ContextMenuParams;
75 struct WebPluginGeometry;
76
77 // RenderWidget provides a communication bridge between a WebWidget and
78 // a RenderWidgetHost, the latter of which lives in a different process.
79 class CONTENT_EXPORT RenderWidget
80     : public IPC::Listener,
81       public IPC::Sender,
82       NON_EXPORTED_BASE(virtual public blink::WebWidgetClient),
83       public base::RefCounted<RenderWidget> {
84  public:
85   // Creates a new RenderWidget.  The opener_id is the routing ID of the
86   // RenderView that this widget lives inside.
87   static RenderWidget* Create(int32 opener_id,
88                               blink::WebPopupType popup_type,
89                               const blink::WebScreenInfo& screen_info);
90
91   // Creates a WebWidget based on the popup type.
92   static blink::WebWidget* CreateWebWidget(RenderWidget* render_widget);
93
94   // The compositing surface assigned by the RenderWidgetHost
95   // (or RenderViewHost). Will be gfx::kNullPluginWindow if not assigned yet,
96   // in which case we should not create any GPU command buffers with it.
97   // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
98   // not yet assigned a view ID, in which case, the process MUST NOT send
99   // messages with this ID to the parent.
100   int32 routing_id() const {
101     return routing_id_;
102   }
103
104   int32 surface_id() const {
105     return surface_id_;
106   }
107
108   // May return NULL when the window is closing.
109   blink::WebWidget* webwidget() const { return webwidget_; }
110
111   gfx::Size size() const { return size_; }
112   bool has_focus() const { return has_focus_; }
113   bool is_fullscreen() const { return is_fullscreen_; }
114   bool is_hidden() const { return is_hidden_; }
115
116   // Functions to track out-of-process frames for special notifications.
117   void RegisterSwappedOutChildFrame(RenderFrameImpl* frame);
118   void UnregisterSwappedOutChildFrame(RenderFrameImpl* frame);
119
120   // IPC::Listener
121   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
122
123   // IPC::Sender
124   virtual bool Send(IPC::Message* msg) OVERRIDE;
125
126   // blink::WebWidgetClient
127   virtual void suppressCompositorScheduling(bool enable);
128   virtual void willBeginCompositorFrame();
129   virtual void didInvalidateRect(const blink::WebRect&);
130   virtual void didScrollRect(int dx, int dy,
131                              const blink::WebRect& clipRect);
132   virtual void didAutoResize(const blink::WebSize& new_size);
133   virtual void didActivateCompositor(int input_handler_identifier);
134   virtual void didDeactivateCompositor();
135   virtual void initializeLayerTreeView();
136   virtual blink::WebLayerTreeView* layerTreeView();
137   virtual void didBecomeReadyForAdditionalInput();
138   virtual void didCommitAndDrawCompositorFrame();
139   virtual void didCompleteSwapBuffers();
140   virtual void scheduleComposite();
141   virtual void scheduleAnimation();
142   virtual void didFocus();
143   virtual void didBlur();
144   virtual void didChangeCursor(const blink::WebCursorInfo&);
145   virtual void closeWidgetSoon();
146   virtual void show(blink::WebNavigationPolicy);
147   virtual void runModal() {}
148   virtual blink::WebRect windowRect();
149   virtual void setToolTipText(const blink::WebString& text,
150                               blink::WebTextDirection hint);
151   virtual void setWindowRect(const blink::WebRect&);
152   virtual blink::WebRect windowResizerRect();
153   virtual blink::WebRect rootWindowRect();
154   virtual blink::WebScreenInfo screenInfo();
155   virtual float deviceScaleFactor();
156   virtual void resetInputMethod();
157   virtual void didHandleGestureEvent(const blink::WebGestureEvent& event,
158                                      bool event_cancelled);
159
160   // Called when a plugin is moved.  These events are queued up and sent with
161   // the next paint or scroll message to the host.
162   void SchedulePluginMove(const WebPluginGeometry& move);
163
164   // Called when a plugin window has been destroyed, to make sure the currently
165   // pending moves don't try to reference it.
166   void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window);
167
168   RenderWidgetCompositor* compositor() const;
169
170   virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback);
171
172   // Callback for use with synthetic gestures (e.g. BeginSmoothScroll).
173   typedef base::Callback<void()> SyntheticGestureCompletionCallback;
174
175   // Send a synthetic gesture to the browser to be queued to the synthetic
176   // gesture controller.
177   void QueueSyntheticGesture(
178       scoped_ptr<SyntheticGestureParams> gesture_params,
179       const SyntheticGestureCompletionCallback& callback);
180
181   // Close the underlying WebWidget.
182   virtual void Close();
183
184   // Notifies about a compositor frame commit operation having finished.
185   virtual void DidCommitCompositorFrame();
186
187   float filtered_time_per_frame() const {
188     return filtered_time_per_frame_;
189   }
190
191   // Handle common setup/teardown for handling IME events.
192   void StartHandlingImeEvent();
193   void FinishHandlingImeEvent();
194
195   virtual void InstrumentWillBeginFrame(int frame_id) {}
196   virtual void InstrumentDidBeginFrame() {}
197   virtual void InstrumentDidCancelFrame() {}
198   virtual void InstrumentWillComposite() {}
199
200   virtual bool AllowPartialSwap() const;
201   bool UsingSynchronousRendererCompositor() const;
202
203   bool is_swapped_out() { return is_swapped_out_; }
204
205   // ScreenMetricsEmulator class manages screen emulation inside a render
206   // widget. This includes resizing, placing view on the screen at desired
207   // position, changing device scale factor, and scaling down the whole
208   // widget if required to fit into the browser window.
209   class ScreenMetricsEmulator;
210
211   // Emulates screen and widget metrics. Supplied values override everything
212   // coming from host.
213   void EnableScreenMetricsEmulation(
214       const gfx::Rect& device_rect,
215       const gfx::Rect& widget_rect,
216       float device_scale_factor,
217       bool fit_to_view);
218   void DisableScreenMetricsEmulation();
219   void SetPopupOriginAdjustmentsForEmulation(ScreenMetricsEmulator* emulator);
220
221   void ScheduleCompositeWithForcedRedraw();
222
223   // Called by the compositor in single-threaded mode when a swap is posted,
224   // completes or is aborted.
225   void OnSwapBuffersPosted();
226   void OnSwapBuffersComplete();
227   void OnSwapBuffersAborted();
228
229   // Checks if the text input state and compose inline mode have been changed.
230   // If they are changed, the new value will be sent to the browser process.
231   void UpdateTextInputType();
232
233   // Checks if the selection bounds have been changed. If they are changed,
234   // the new value will be sent to the browser process.
235   void UpdateSelectionBounds();
236
237   void OnShowHostContextMenu(ContextMenuParams* params);
238
239 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
240   // Checks if the composition range or composition character bounds have been
241   // changed. If they are changed, the new value will be sent to the browser
242   // process.
243   void UpdateCompositionInfo(bool should_update_range);
244 #endif
245
246   // Temporary for debugging purposes...
247   bool closing() const { return closing_; }
248
249   ui::MenuSourceType context_menu_source_type() {
250     return context_menu_source_type_; }
251   gfx::Point touch_editing_context_menu_location() {
252     return touch_editing_context_menu_location_;
253   }
254
255  protected:
256   // Friend RefCounted so that the dtor can be non-public. Using this class
257   // without ref-counting is an error.
258   friend class base::RefCounted<RenderWidget>;
259   // For unit tests.
260   friend class RenderWidgetTest;
261
262   enum ResizeAck {
263     SEND_RESIZE_ACK,
264     NO_RESIZE_ACK,
265   };
266
267   RenderWidget(blink::WebPopupType popup_type,
268                const blink::WebScreenInfo& screen_info,
269                bool swapped_out,
270                bool hidden);
271
272   virtual ~RenderWidget();
273
274   // Initializes this view with the given opener.  CompleteInit must be called
275   // later.
276   bool Init(int32 opener_id);
277
278   // Called by Init and subclasses to perform initialization.
279   bool DoInit(int32 opener_id,
280               blink::WebWidget* web_widget,
281               IPC::SyncMessage* create_widget_message);
282
283   // Finishes creation of a pending view started with Init.
284   void CompleteInit();
285
286   // Sets whether this RenderWidget has been swapped out to be displayed by
287   // a RenderWidget in a different process.  If so, no new IPC messages will be
288   // sent (only ACKs) and the process is free to exit when there are no other
289   // active RenderWidgets.
290   void SetSwappedOut(bool is_swapped_out);
291
292   // Paints the given rectangular region of the WebWidget into canvas (a
293   // shared memory segment returned by AllocPaintBuf on Windows). The caller
294   // must ensure that the given rect fits within the bounds of the WebWidget.
295   void PaintRect(const gfx::Rect& rect, const gfx::Point& canvas_origin,
296                  SkCanvas* canvas);
297
298   // Paints a border at the given rect for debugging purposes.
299   void PaintDebugBorder(const gfx::Rect& rect, SkCanvas* canvas);
300
301   bool IsRenderingVSynced();
302   void AnimationCallback();
303   void AnimateIfNeeded();
304   void InvalidationCallback();
305   void FlushPendingInputEventAck();
306   void DoDeferredUpdateAndSendInputAck();
307   void DoDeferredUpdate();
308   void DoDeferredClose();
309   void DoDeferredSetWindowRect(const blink::WebRect& pos);
310   virtual void Composite(base::TimeTicks frame_begin_time);
311
312   // Set the background of the render widget to a bitmap. The bitmap will be
313   // tiled in both directions if it isn't big enough to fill the area. This is
314   // mainly intended to be used in conjuction with WebView::SetIsTransparent().
315   virtual void SetBackground(const SkBitmap& bitmap);
316
317   // Resizes the render widget.
318   void Resize(const gfx::Size& new_size,
319               const gfx::Size& physical_backing_size,
320               float overdraw_bottom_height,
321               const gfx::Rect& resizer_rect,
322               bool is_fullscreen,
323               ResizeAck resize_ack);
324   // Used to force the size of a window when running layout tests.
325   void ResizeSynchronously(const gfx::Rect& new_position);
326   virtual void SetScreenMetricsEmulationParameters(
327       float device_scale_factor,
328       const gfx::Point& root_layer_offset,
329       float root_layer_scale);
330   void SetExternalPopupOriginAdjustmentsForEmulation(
331       ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator);
332
333   // RenderWidget IPC message handlers
334   void OnHandleInputEvent(const blink::WebInputEvent* event,
335                           ui::LatencyInfo latency_info,
336                           bool keyboard_shortcut);
337   void OnCursorVisibilityChange(bool is_visible);
338   void OnMouseCaptureLost();
339   virtual void OnSetFocus(bool enable);
340   void OnClose();
341   void OnCreatingNewAck();
342   virtual void OnResize(const ViewMsg_Resize_Params& params);
343   void OnChangeResizeRect(const gfx::Rect& resizer_rect);
344   virtual void OnWasHidden();
345   virtual void OnWasShown(bool needs_repainting);
346   virtual void OnWasSwappedOut();
347   void OnUpdateRectAck();
348   void OnCreateVideoAck(int32 video_id);
349   void OnUpdateVideoAck(int32 video_id);
350   void OnRequestMoveAck();
351   void OnSetInputMethodActive(bool is_active);
352   void OnCandidateWindowShown();
353   void OnCandidateWindowUpdated();
354   void OnCandidateWindowHidden();
355   virtual void OnImeSetComposition(
356       const base::string16& text,
357       const std::vector<blink::WebCompositionUnderline>& underlines,
358       int selection_start,
359       int selection_end);
360   virtual void OnImeConfirmComposition(const base::string16& text,
361                                        const gfx::Range& replacement_range,
362                                        bool keep_selection);
363   void OnRepaint(gfx::Size size_to_paint);
364   void OnSyntheticGestureCompleted();
365   void OnSetTextDirection(blink::WebTextDirection direction);
366   void OnGetFPS();
367   void OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
368                            const gfx::Rect& window_screen_rect);
369 #if defined(OS_ANDROID)
370   void OnShowImeIfNeeded();
371
372   // Whenever an IME event that needs an acknowledgement is sent to the browser,
373   // the number of outstanding IME events that needs acknowledgement should be
374   // incremented. All IME events will be dropped until we receive an ack from
375   // the browser.
376   void IncrementOutstandingImeEventAcks();
377
378   // Called by the browser process for every required IME acknowledgement.
379   void OnImeEventAck();
380 #endif
381   // Returns whether we currently should handle an IME event.
382   bool ShouldHandleImeEvent();
383
384   void OnSnapshot(const gfx::Rect& src_subrect);
385
386   // Notify the compositor about a change in viewport size. This should be
387   // used only with auto resize mode WebWidgets, as normal WebWidgets should
388   // go through OnResize.
389   void AutoResizeCompositor();
390
391   virtual void SetDeviceScaleFactor(float device_scale_factor);
392
393   // Override points to notify derived classes that a paint has happened.
394   // DidInitiatePaint happens when that has completed, and subsequent rendering
395   // won't affect the painted content. DidFlushPaint happens once we've received
396   // the ACK that the screen has been updated. For a given paint operation,
397   // these overrides will always be called in the order DidInitiatePaint,
398   // DidFlushPaint.
399   virtual void DidInitiatePaint() {}
400   virtual void DidFlushPaint() {}
401
402   // Override and return true when the widget is rendered with a graphics
403   // context that supports asynchronous swapbuffers. When returning true, the
404   // subclass must call OnSwapBuffersPosted() when swap is posted,
405   // OnSwapBuffersComplete() when swaps complete, and OnSwapBuffersAborted if
406   // the context is lost.
407   virtual bool SupportsAsynchronousSwapBuffers();
408   virtual GURL GetURLForGraphicsContext3D();
409
410   virtual bool ForceCompositingModeEnabled();
411
412   // Detects if a suitable opaque plugin covers the given paint bounds with no
413   // compositing necessary.
414   //
415   // Returns the plugin instance that's the source of the paint if the paint
416   // can be handled by just blitting the plugin bitmap. In this case, the
417   // location, clipping, and ID of the backing store will be filled into the
418   // given output parameters.
419   //
420   // A return value of null means optimized painting can not be used and we
421   // should continue with the normal painting code path.
422   virtual PepperPluginInstanceImpl* GetBitmapForOptimizedPluginPaint(
423       const gfx::Rect& paint_bounds,
424       TransportDIB** dib,
425       gfx::Rect* location,
426       gfx::Rect* clip,
427       float* scale_factor);
428
429   // Gets the scroll offset of this widget, if this widget has a notion of
430   // scroll offset.
431   virtual gfx::Vector2d GetScrollOffset();
432
433   // Sets the "hidden" state of this widget.  All accesses to is_hidden_ should
434   // use this method so that we can properly inform the RenderThread of our
435   // state.
436   void SetHidden(bool hidden);
437
438   void WillToggleFullscreen();
439   void DidToggleFullscreen();
440
441   bool next_paint_is_resize_ack() const;
442   bool next_paint_is_restore_ack() const;
443   void set_next_paint_is_resize_ack();
444   void set_next_paint_is_restore_ack();
445   void set_next_paint_is_repaint_ack();
446
447 #if defined(OS_ANDROID) || defined(USE_AURA)
448   // |show_ime_if_needed| should be true iff the update may cause the ime to be
449   // displayed, e.g. after a tap on an input field on mobile.
450   // |send_ime_ack| should be true iff the browser side is required to
451   // acknowledge the change before the renderer handles any more IME events.
452   // This is when the event did not originate from the browser side IME, such as
453   // changes from JavaScript or autofill.
454   void UpdateTextInputState(bool show_ime_if_needed, bool send_ime_ack);
455 #endif
456
457   // Override point to obtain that the current input method state and caret
458   // position.
459   virtual ui::TextInputType GetTextInputType();
460   virtual void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end);
461   virtual ui::TextInputType WebKitToUiTextInputType(
462       blink::WebTextInputType type);
463
464 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
465   // Override point to obtain that the current composition character bounds.
466   // In the case of surrogate pairs, the character is treated as two characters:
467   // the bounds for first character is actual one, and the bounds for second
468   // character is zero width rectangle.
469   virtual void GetCompositionCharacterBounds(
470       std::vector<gfx::Rect>* character_bounds);
471
472   // Returns the range of the text that is being composed or the selection if
473   // the composition does not exist.
474   virtual void GetCompositionRange(gfx::Range* range);
475
476   // Returns true if the composition range or composition character bounds
477   // should be sent to the browser process.
478   bool ShouldUpdateCompositionInfo(
479       const gfx::Range& range,
480       const std::vector<gfx::Rect>& bounds);
481 #endif
482
483   // Override point to obtain that the current input method state about
484   // composition text.
485   virtual bool CanComposeInline();
486
487   // Tells the renderer it does not have focus. Used to prevent us from getting
488   // the focus on our own when the browser did not focus us.
489   void ClearFocus();
490
491   // Set the pending window rect.
492   // Because the real render_widget is hosted in another process, there is
493   // a time period where we may have set a new window rect which has not yet
494   // been processed by the browser.  So we maintain a pending window rect
495   // size.  If JS code sets the WindowRect, and then immediately calls
496   // GetWindowRect() we'll use this pending window rect as the size.
497   void SetPendingWindowRect(const blink::WebRect& r);
498
499   // Called by OnHandleInputEvent() to notify subclasses that a key event was
500   // just handled.
501   virtual void DidHandleKeyEvent() {}
502
503   // Called by OnHandleInputEvent() to notify subclasses that a mouse event is
504   // about to be handled.
505   // Returns true if no further handling is needed. In that case, the event
506   // won't be sent to WebKit or trigger DidHandleMouseEvent().
507   virtual bool WillHandleMouseEvent(const blink::WebMouseEvent& event);
508
509   // Called by OnHandleInputEvent() to notify subclasses that a gesture event is
510   // about to be handled.
511   // Returns true if no further handling is needed. In that case, the event
512   // won't be sent to WebKit.
513   virtual bool WillHandleGestureEvent(const blink::WebGestureEvent& event);
514
515   // Called by OnHandleInputEvent() to notify subclasses that a mouse event was
516   // just handled.
517   virtual void DidHandleMouseEvent(const blink::WebMouseEvent& event) {}
518
519   // Called by OnHandleInputEvent() to notify subclasses that a touch event was
520   // just handled.
521   virtual void DidHandleTouchEvent(const blink::WebTouchEvent& event) {}
522
523   // Check whether the WebWidget has any touch event handlers registered
524   // at the given point.
525   virtual bool HasTouchEventHandlersAt(const gfx::Point& point) const;
526
527   // Check whether the WebWidget has any touch event handlers registered.
528   virtual void hasTouchEventHandlers(bool has_handlers);
529
530   // Tell the browser about the actions permitted for a new touch point.
531   virtual void setTouchAction(blink::WebTouchAction touch_action);
532
533   // Creates a 3D context associated with this view.
534   scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateGraphicsContext3D(
535       const blink::WebGraphicsContext3D::Attributes& attributes);
536
537   bool OnSnapshotHelper(const gfx::Rect& src_subrect, SkBitmap* bitmap);
538
539   // Routing ID that allows us to communicate to the parent browser process
540   // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
541   int32 routing_id_;
542
543   int32 surface_id_;
544
545   // We are responsible for destroying this object via its Close method.
546   blink::WebWidget* webwidget_;
547
548   // This is lazily constructed and must not outlive webwidget_.
549   scoped_ptr<RenderWidgetCompositor> compositor_;
550
551   // Set to the ID of the view that initiated creating this view, if any. When
552   // the view was initiated by the browser (the common case), this will be
553   // MSG_ROUTING_NONE. This is used in determining ownership when opening
554   // child tabs. See RenderWidget::createWebViewWithRequest.
555   //
556   // This ID may refer to an invalid view if that view is closed before this
557   // view is.
558   int32 opener_id_;
559
560   // The position where this view should be initially shown.
561   gfx::Rect initial_pos_;
562
563   bool init_complete_;
564
565   // We store the current cursor object so we can avoid spamming SetCursor
566   // messages.
567   WebCursor current_cursor_;
568
569   // The size of the RenderWidget.
570   gfx::Size size_;
571
572   // The TransportDIB that is being used to transfer an image to the browser.
573   TransportDIB* current_paint_buf_;
574
575   PaintAggregator paint_aggregator_;
576
577   // The size of the view's backing surface in non-DPI-adjusted pixels.
578   gfx::Size physical_backing_size_;
579
580   // The height of the physical backing surface that is overdrawn opaquely in
581   // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
582   float overdraw_bottom_height_;
583
584   // The area that must be reserved for drawing the resize corner.
585   gfx::Rect resizer_rect_;
586
587   // Flags for the next ViewHostMsg_UpdateRect message.
588   int next_paint_flags_;
589
590   // Filtered time per frame based on UpdateRect messages.
591   float filtered_time_per_frame_;
592
593   // True if we are expecting an UpdateRect_ACK message (i.e., that a
594   // UpdateRect message has been sent).
595   bool update_reply_pending_;
596
597   // Whether the WebWidget is in auto resize mode, which is used for example
598   // by extension popups.
599   bool auto_resize_mode_;
600
601   // True if we need to send an UpdateRect message to notify the browser about
602   // an already-completed auto-resize.
603   bool need_update_rect_for_auto_resize_;
604
605   // True if the underlying graphics context supports asynchronous swap.
606   // Cached on the RenderWidget because determining support is costly.
607   bool using_asynchronous_swapbuffers_;
608
609   // Number of OnSwapBuffersComplete we are expecting. Incremented each time
610   // WebWidget::composite has been been performed when the RenderWidget subclass
611   // SupportsAsynchronousSwapBuffers. Decremented in OnSwapBuffers. Will block
612   // rendering.
613   int num_swapbuffers_complete_pending_;
614
615   // When accelerated rendering is on, is the maximum number of swapbuffers that
616   // can be outstanding before we start throttling based on
617   // OnSwapBuffersComplete callback.
618   static const int kMaxSwapBuffersPending = 2;
619
620   // Set to true if we should ignore RenderWidget::Show calls.
621   bool did_show_;
622
623   // Indicates that we shouldn't bother generated paint events.
624   bool is_hidden_;
625
626   // Indicates that we are in fullscreen mode.
627   bool is_fullscreen_;
628
629   // Indicates that we should be repainted when restored.  This flag is set to
630   // true if we receive an invalidation / scroll event from webkit while our
631   // is_hidden_ flag is set to true.  This is used to force a repaint once we
632   // restore to account for the fact that our host would not know about the
633   // invalidation / scroll event(s) from webkit while we are hidden.
634   bool needs_repainting_on_restore_;
635
636   // Indicates whether we have been focused/unfocused by the browser.
637   bool has_focus_;
638
639   // Are we currently handling an input event?
640   bool handling_input_event_;
641
642   // Are we currently handling an ime event?
643   bool handling_ime_event_;
644
645   // Are we currently handling a touchstart event?
646   bool handling_touchstart_event_;
647
648   // True if we have requested this widget be closed.  No more messages will
649   // be sent, except for a Close.
650   bool closing_;
651
652   // Whether this RenderWidget is currently swapped out, such that the view is
653   // being rendered by another process.  If all RenderWidgets in a process are
654   // swapped out, the process can exit.
655   bool is_swapped_out_;
656
657   // Indicates if an input method is active in the browser process.
658   bool input_method_is_active_;
659
660   // Stores information about the current text input.
661   blink::WebTextInputInfo text_input_info_;
662
663   // Stores the current text input type of |webwidget_|.
664   ui::TextInputType text_input_type_;
665
666   // Stores the current text input mode of |webwidget_|.
667   ui::TextInputMode text_input_mode_;
668
669   // Stores the current type of composition text rendering of |webwidget_|.
670   bool can_compose_inline_;
671
672   // Stores the current selection bounds.
673   gfx::Rect selection_focus_rect_;
674   gfx::Rect selection_anchor_rect_;
675
676   // Stores the current composition character bounds.
677   std::vector<gfx::Rect> composition_character_bounds_;
678
679   // Stores the current composition range.
680   gfx::Range composition_range_;
681
682   // The kind of popup this widget represents, NONE if not a popup.
683   blink::WebPopupType popup_type_;
684
685   // Holds all the needed plugin window moves for a scroll.
686   typedef std::vector<WebPluginGeometry> WebPluginGeometryVector;
687   WebPluginGeometryVector plugin_window_moves_;
688
689   // A custom background for the widget.
690   SkBitmap background_;
691
692   // While we are waiting for the browser to update window sizes, we track the
693   // pending size temporarily.
694   int pending_window_rect_count_;
695   blink::WebRect pending_window_rect_;
696
697   // The screen rects of the view and the window that contains it.
698   gfx::Rect view_screen_rect_;
699   gfx::Rect window_screen_rect_;
700
701   scoped_ptr<IPC::Message> pending_input_event_ack_;
702
703   // The time spent in input handlers this frame. Used to throttle input acks.
704   base::TimeDelta total_input_handling_time_this_frame_;
705
706   // Indicates if the next sequence of Char events should be suppressed or not.
707   bool suppress_next_char_events_;
708
709   // Set to true if painting to the window is handled by the accelerated
710   // compositor.
711   bool is_accelerated_compositing_active_;
712
713   // Set to true if compositing has ever been active for this widget. Once a
714   // widget has used compositing, it will act as though force compositing mode
715   // is on for the remainder of the widget's lifetime.
716   bool was_accelerated_compositing_ever_active_;
717
718   base::OneShotTimer<RenderWidget> animation_timer_;
719   base::Time animation_floor_time_;
720   bool animation_update_pending_;
721   bool invalidation_task_posted_;
722
723   bool has_disable_gpu_vsync_switch_;
724   base::TimeTicks last_do_deferred_update_time_;
725
726   // Stats for legacy software mode
727   scoped_ptr<cc::RenderingStatsInstrumentation> legacy_software_mode_stats_;
728
729   // UpdateRect parameters for the current compositing pass. This is used to
730   // pass state between DoDeferredUpdate and OnSwapBuffersPosted.
731   scoped_ptr<ViewHostMsg_UpdateRect_Params> pending_update_params_;
732
733   // Queue of UpdateRect messages corresponding to a SwapBuffers. We want to
734   // delay sending of UpdateRect until the corresponding SwapBuffers has been
735   // executed. Since we can have several in flight, we need to keep them in a
736   // queue. Note: some SwapBuffers may not correspond to an update, in which
737   // case NULL is added to the queue.
738   std::deque<ViewHostMsg_UpdateRect*> updates_pending_swap_;
739
740   // Properties of the screen hosting this RenderWidget instance.
741   blink::WebScreenInfo screen_info_;
742
743   // The device scale factor. This value is computed from the DPI entries in
744   // |screen_info_| on some platforms, and defaults to 1 on other platforms.
745   float device_scale_factor_;
746
747   // State associated with synthetic gestures. Synthetic gestures are processed
748   // in-order, so a queue is sufficient to identify the correct state for a
749   // completed gesture.
750   std::queue<SyntheticGestureCompletionCallback>
751       pending_synthetic_gesture_callbacks_;
752
753   // Specified whether the compositor will run in its own thread.
754   bool is_threaded_compositing_enabled_;
755
756   // The latency information for any current non-accelerated-compositing
757   // frame.
758   std::vector<ui::LatencyInfo> latency_info_;
759
760   uint32 next_output_surface_id_;
761
762 #if defined(OS_ANDROID)
763   // A counter for number of outstanding messages from the renderer to the
764   // browser regarding IME-type events that have not been acknowledged by the
765   // browser. If this value is not 0 IME events will be dropped.
766   int outstanding_ime_acks_;
767 #endif
768
769   scoped_ptr<ScreenMetricsEmulator> screen_metrics_emulator_;
770
771   // Popups may be displaced when screen metrics emulation is enabled.
772   // These values are used to properly adjust popup position.
773   gfx::Point popup_view_origin_for_emulation_;
774   gfx::Point popup_screen_origin_for_emulation_;
775   float popup_origin_scale_for_emulation_;
776
777   scoped_ptr<ResizingModeSelector> resizing_mode_selector_;
778
779   // A list of swapped out RenderFrames that need to be notified
780   // of compositing-related events (e.g. DidCommitCompositorFrame).
781   ObserverList<RenderFrameImpl> swapped_out_frames_;
782
783   ui::MenuSourceType context_menu_source_type_;
784   gfx::Point touch_editing_context_menu_location_;
785
786   DISALLOW_COPY_AND_ASSIGN(RenderWidget);
787 };
788
789 }  // namespace content
790
791 #endif  // CONTENT_RENDERER_RENDER_WIDGET_H_