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