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