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