[MacViews] Show comboboxes with a native NSMenu
[chromium-blink-merge.git] / content / renderer / render_widget.h
blobbdce8a0cc9ab294341ac444fb50b901b04f868f6
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_RENDER_WIDGET_H_
6 #define CONTENT_RENDERER_RENDER_WIDGET_H_
8 #include <deque>
9 #include <map>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/observer_list.h"
17 #include "base/time/time.h"
18 #include "content/common/content_export.h"
19 #include "content/common/cursors/webcursor.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/message_delivery_policy.h"
23 #include "ipc/ipc_listener.h"
24 #include "ipc/ipc_sender.h"
25 #include "third_party/WebKit/public/platform/WebDisplayMode.h"
26 #include "third_party/WebKit/public/platform/WebRect.h"
27 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
28 #include "third_party/WebKit/public/web/WebInputEvent.h"
29 #include "third_party/WebKit/public/web/WebPopupType.h"
30 #include "third_party/WebKit/public/web/WebTextDirection.h"
31 #include "third_party/WebKit/public/web/WebTextInputInfo.h"
32 #include "third_party/WebKit/public/web/WebTouchAction.h"
33 #include "third_party/WebKit/public/web/WebWidget.h"
34 #include "third_party/WebKit/public/web/WebWidgetClient.h"
35 #include "third_party/skia/include/core/SkBitmap.h"
36 #include "ui/base/ime/text_input_mode.h"
37 #include "ui/base/ime/text_input_type.h"
38 #include "ui/base/ui_base_types.h"
39 #include "ui/gfx/geometry/rect.h"
40 #include "ui/gfx/geometry/vector2d.h"
41 #include "ui/gfx/geometry/vector2d_f.h"
42 #include "ui/gfx/native_widget_types.h"
43 #include "ui/gfx/range/range.h"
44 #include "ui/surface/transport_dib.h"
46 struct ViewHostMsg_UpdateRect_Params;
47 struct ViewMsg_Resize_Params;
48 class ViewHostMsg_UpdateRect;
50 namespace IPC {
51 class SyncMessage;
52 class SyncMessageFilter;
55 namespace blink {
56 struct WebDeviceEmulationParams;
57 class WebFrameWidget;
58 class WebGestureEvent;
59 class WebKeyboardEvent;
60 class WebLocalFrame;
61 class WebMouseEvent;
62 class WebNode;
63 struct WebPoint;
64 class WebTouchEvent;
65 class WebView;
68 namespace cc {
69 struct InputHandlerScrollResult;
70 class OutputSurface;
71 class SwapPromise;
74 namespace gfx {
75 class Range;
78 namespace content {
79 class CompositorDependencies;
80 class ExternalPopupMenu;
81 class FrameSwapMessageQueue;
82 class PepperPluginInstanceImpl;
83 class RenderFrameImpl;
84 class RenderFrameProxy;
85 class RenderWidgetCompositor;
86 class RenderWidgetTest;
87 class ResizingModeSelector;
88 struct ContextMenuParams;
89 struct DidOverscrollParams;
90 struct WebPluginGeometry;
92 // RenderWidget provides a communication bridge between a WebWidget and
93 // a RenderWidgetHost, the latter of which lives in a different process.
95 // RenderWidget is used to implement:
96 // - RenderViewImpl (deprecated)
97 // - Fullscreen mode (RenderWidgetFullScreen)
98 // - Popup "menus" (like the color chooser and date picker)
99 // - Widgets for frames (for out-of-process iframe support)
100 class CONTENT_EXPORT RenderWidget
101 : public IPC::Listener,
102 public IPC::Sender,
103 NON_EXPORTED_BASE(virtual public blink::WebWidgetClient),
104 public base::RefCounted<RenderWidget> {
105 public:
106 // Creates a new RenderWidget. The opener_id is the routing ID of the
107 // RenderView that this widget lives inside.
108 static RenderWidget* Create(int32 opener_id,
109 CompositorDependencies* compositor_deps,
110 blink::WebPopupType popup_type,
111 const blink::WebScreenInfo& screen_info);
113 // Creates a new RenderWidget that will be attached to a RenderFrame.
114 static RenderWidget* CreateForFrame(int routing_id,
115 int surface_id,
116 bool hidden,
117 const blink::WebScreenInfo& screen_info,
118 CompositorDependencies* compositor_deps,
119 blink::WebLocalFrame* frame);
121 // Closes a RenderWidget that was created by |CreateForFrame|.
122 void CloseForFrame();
124 int32 routing_id() const { return routing_id_; }
125 int32 surface_id() const { return surface_id_; }
126 CompositorDependencies* compositor_deps() const { return compositor_deps_; }
127 blink::WebWidget* webwidget() const { return webwidget_; }
128 gfx::Size size() const { return size_; }
129 bool has_focus() const { return has_focus_; }
130 bool is_fullscreen_granted() const { return is_fullscreen_granted_; }
131 blink::WebDisplayMode display_mode() const { return display_mode_; }
132 bool is_hidden() const { return is_hidden_; }
133 bool handling_input_event() const { return handling_input_event_; }
134 // Temporary for debugging purposes...
135 bool closing() const { return closing_; }
136 bool is_swapped_out() { return is_swapped_out_; }
137 bool for_oopif() { return for_oopif_; }
138 ui::MenuSourceType context_menu_source_type() {
139 return context_menu_source_type_;
141 bool has_host_context_menu_location() {
142 return has_host_context_menu_location_;
144 gfx::Point host_context_menu_location() {
145 return host_context_menu_location_;
148 // ScreenInfo exposed so it can be passed to subframe RenderWidgets.
149 blink::WebScreenInfo screen_info() const { return screen_info_; }
151 // Functions to track out-of-process frames for special notifications.
152 void RegisterRenderFrameProxy(RenderFrameProxy* proxy);
153 void UnregisterRenderFrameProxy(RenderFrameProxy* proxy);
155 // Functions to track all RenderFrame objects associated with this
156 // RenderWidget.
157 void RegisterRenderFrame(RenderFrameImpl* frame);
158 void UnregisterRenderFrame(RenderFrameImpl* frame);
160 #if defined(VIDEO_HOLE)
161 void RegisterVideoHoleFrame(RenderFrameImpl* frame);
162 void UnregisterVideoHoleFrame(RenderFrameImpl* frame);
163 #endif // defined(VIDEO_HOLE)
165 // IPC::Listener
166 bool OnMessageReceived(const IPC::Message& msg) override;
168 // IPC::Sender
169 bool Send(IPC::Message* msg) override;
171 // blink::WebWidgetClient
172 virtual void didAutoResize(const blink::WebSize& new_size);
173 virtual void initializeLayerTreeView();
174 virtual blink::WebLayerTreeView* layerTreeView();
175 virtual void didFirstVisuallyNonEmptyLayout();
176 virtual void didFirstLayoutAfterFinishedParsing();
177 virtual void didFocus();
178 virtual void didBlur();
179 virtual void didChangeCursor(const blink::WebCursorInfo&);
180 virtual void closeWidgetSoon();
181 virtual void show(blink::WebNavigationPolicy);
182 virtual blink::WebRect windowRect();
183 virtual void setToolTipText(const blink::WebString& text,
184 blink::WebTextDirection hint);
185 virtual void setWindowRect(const blink::WebRect&);
186 virtual blink::WebRect windowResizerRect();
187 virtual blink::WebRect rootWindowRect();
188 virtual blink::WebScreenInfo screenInfo();
189 virtual float deviceScaleFactor();
190 virtual void resetInputMethod();
191 virtual void didHandleGestureEvent(const blink::WebGestureEvent& event,
192 bool event_cancelled);
193 virtual void didOverscroll(
194 const blink::WebFloatSize& unusedDelta,
195 const blink::WebFloatSize& accumulatedRootOverScroll,
196 const blink::WebFloatPoint& position,
197 const blink::WebFloatSize& velocity);
198 virtual void showImeIfNeeded();
200 #if defined(OS_ANDROID)
201 // Notifies that a tap was not consumed, so showing a UI for the unhandled
202 // tap may be needed.
203 // Performs various checks on the given WebNode to apply heuristics to
204 // determine if triggering is appropriate.
205 virtual void showUnhandledTapUIIfNeeded(
206 const blink::WebPoint& tapped_position,
207 const blink::WebNode& tapped_node,
208 bool page_changed) override;
209 #endif
211 // Begins the compositor's scheduler to start producing frames.
212 void StartCompositor();
214 // Stop compositing.
215 void WillCloseLayerTreeView();
217 // Called when a plugin is moved. These events are queued up and sent with
218 // the next paint or scroll message to the host.
219 void SchedulePluginMove(const WebPluginGeometry& move);
221 // Called when a plugin window has been destroyed, to make sure the currently
222 // pending moves don't try to reference it.
223 void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window);
225 RenderWidgetCompositor* compositor() const;
227 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback);
229 // Callback for use with synthetic gestures (e.g. BeginSmoothScroll).
230 typedef base::Callback<void()> SyntheticGestureCompletionCallback;
232 // Send a synthetic gesture to the browser to be queued to the synthetic
233 // gesture controller.
234 void QueueSyntheticGesture(
235 scoped_ptr<SyntheticGestureParams> gesture_params,
236 const SyntheticGestureCompletionCallback& callback);
238 // Deliveres |message| together with compositor state change updates. The
239 // exact behavior depends on |policy|.
240 // This mechanism is not a drop-in replacement for IPC: messages sent this way
241 // will not be automatically available to BrowserMessageFilter, for example.
242 // FIFO ordering is preserved between messages enqueued with the same
243 // |policy|, the ordering between messages enqueued for different policies is
244 // undefined.
246 // |msg| message to send, ownership of |msg| is transferred.
247 // |policy| see the comment on MessageDeliveryPolicy.
248 void QueueMessage(IPC::Message* msg, MessageDeliveryPolicy policy);
250 // Handle common setup/teardown for handling IME events.
251 void StartHandlingImeEvent();
252 void FinishHandlingImeEvent();
254 // Returns whether we currently should handle an IME event.
255 bool ShouldHandleImeEvent();
257 // Called by the compositor when page scale animation completed.
258 virtual void DidCompletePageScaleAnimation() {}
260 // When paused in debugger, we send ack for mouse event early. This ensures
261 // that we continue receiving mouse moves and pass them to debugger. Returns
262 // whether we are paused in mouse move event and have sent the ack.
263 bool SendAckForMouseMoveFromDebugger();
265 // When resumed from pause in debugger while handling mouse move,
266 // we should not send an extra ack (see SendAckForMouseMoveFromDebugger).
267 void IgnoreAckForMouseMoveFromDebugger();
269 // ScreenMetricsEmulator class manages screen emulation inside a render
270 // widget. This includes resizing, placing view on the screen at desired
271 // position, changing device scale factor, and scaling down the whole
272 // widget if required to fit into the browser window.
273 class ScreenMetricsEmulator;
275 void SetPopupOriginAdjustmentsForEmulation(ScreenMetricsEmulator* emulator);
276 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
278 // Indicates that the compositor is about to begin a frame. This is primarily
279 // to signal to flow control mechanisms that a frame is beginning, not to
280 // perform actual painting work.
281 void WillBeginCompositorFrame();
283 // Notifies about a compositor frame commit operation having finished.
284 virtual void DidCommitCompositorFrame();
286 // Notifies that the draw commands for a committed frame have been issued.
287 void DidCommitAndDrawCompositorFrame();
289 // Notifies that the compositor has posted a swapbuffers operation to the GPU
290 // process.
291 void DidCompleteSwapBuffers();
293 void ScheduleComposite();
294 void ScheduleCompositeWithForcedRedraw();
296 // Called by the compositor in single-threaded mode when a swap is posted,
297 // completes or is aborted.
298 void OnSwapBuffersPosted();
299 void OnSwapBuffersComplete();
300 void OnSwapBuffersAborted();
302 // Checks if the selection bounds have been changed. If they are changed,
303 // the new value will be sent to the browser process.
304 void UpdateSelectionBounds();
306 virtual void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end);
308 void OnShowHostContextMenu(ContextMenuParams* params);
310 enum ShowIme {
311 SHOW_IME_IF_NEEDED,
312 NO_SHOW_IME,
315 enum ChangeSource {
316 FROM_NON_IME,
317 FROM_IME,
320 // |show_ime| should be SHOW_IME_IF_NEEDED iff the update may cause the ime to
321 // be displayed, e.g. after a tap on an input field on mobile.
322 // |change_source| should be FROM_NON_IME when the renderer has to wait for
323 // the browser to acknowledge the change before the renderer handles any more
324 // IME events. This is when the text change did not originate from the IME in
325 // the browser side, such as changes by JavaScript or autofill.
326 void UpdateTextInputState(ShowIme show_ime, ChangeSource change_source);
328 // Called when animations due to focus change have completed (if any). Can be
329 // called from the renderer, browser, or compositor.
330 virtual void FocusChangeComplete() {}
332 // Checks if the composition range or composition character bounds have been
333 // changed. If they are changed, the new value will be sent to the browser
334 // process. This method does nothing when the browser process is not able to
335 // handle composition range and composition character bounds.
336 void UpdateCompositionInfo(bool should_update_range);
338 #if defined(OS_ANDROID)
339 void DidChangeBodyBackgroundColor(SkColor bg_color);
340 virtual bool DoesRecordFullLayer() const;
341 #endif
343 bool host_closing() const { return host_closing_; }
345 protected:
346 // Friend RefCounted so that the dtor can be non-public. Using this class
347 // without ref-counting is an error.
348 friend class base::RefCounted<RenderWidget>;
349 // For unit tests.
350 friend class RenderWidgetTest;
352 enum ResizeAck {
353 SEND_RESIZE_ACK,
354 NO_RESIZE_ACK,
357 RenderWidget(CompositorDependencies* compositor_deps,
358 blink::WebPopupType popup_type,
359 const blink::WebScreenInfo& screen_info,
360 bool swapped_out,
361 bool hidden,
362 bool never_visible);
364 ~RenderWidget() override;
366 static blink::WebWidget* CreateWebFrameWidget(RenderWidget* render_widget,
367 blink::WebLocalFrame* frame);
369 // Creates a WebWidget based on the popup type.
370 static blink::WebWidget* CreateWebWidget(RenderWidget* render_widget);
372 // Initializes this view with the given opener. CompleteInit must be called
373 // later.
374 bool Init(int32 opener_id);
376 // Called by Init and subclasses to perform initialization.
377 bool DoInit(int32 opener_id,
378 blink::WebWidget* web_widget,
379 IPC::SyncMessage* create_widget_message);
381 // Finishes creation of a pending view started with Init.
382 void CompleteInit();
384 // Sets whether this RenderWidget has been swapped out to be displayed by
385 // a RenderWidget in a different process. If so, no new IPC messages will be
386 // sent (only ACKs) and the process is free to exit when there are no other
387 // active RenderWidgets.
388 void SetSwappedOut(bool is_swapped_out);
390 // Allows the process to exit once the unload handler has finished, if there
391 // are no other active RenderWidgets.
392 void WasSwappedOut();
394 void FlushPendingInputEventAck();
395 void DoDeferredClose();
396 void NotifyOnClose();
398 // Close the underlying WebWidget.
399 virtual void Close();
401 // Resizes the render widget.
402 void Resize(const gfx::Size& new_size,
403 const gfx::Size& physical_backing_size,
404 bool top_controls_shrink_blink_size,
405 float top_controls_height,
406 const gfx::Size& visible_viewport_size,
407 const gfx::Rect& resizer_rect,
408 bool is_fullscreen_granted,
409 blink::WebDisplayMode display_mode,
410 ResizeAck resize_ack);
411 // Used to force the size of a window when running layout tests.
412 void SetWindowRectSynchronously(const gfx::Rect& new_window_rect);
413 virtual void SetScreenMetricsEmulationParameters(
414 bool enabled,
415 const blink::WebDeviceEmulationParams& params);
416 #if defined(OS_MACOSX) || defined(OS_ANDROID)
417 void SetExternalPopupOriginAdjustmentsForEmulation(
418 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator);
419 #endif
421 // RenderWidget IPC message handlers
422 void OnHandleInputEvent(const blink::WebInputEvent* event,
423 const ui::LatencyInfo& latency_info,
424 bool keyboard_shortcut);
425 void OnCursorVisibilityChange(bool is_visible);
426 void OnMouseCaptureLost();
427 virtual void OnSetFocus(bool enable);
428 void OnClose();
429 void OnCreatingNewAck();
430 virtual void OnResize(const ViewMsg_Resize_Params& params);
431 void OnEnableDeviceEmulation(const blink::WebDeviceEmulationParams& params);
432 void OnDisableDeviceEmulation();
433 void OnColorProfile(const std::vector<char>& color_profile);
434 void OnChangeResizeRect(const gfx::Rect& resizer_rect);
435 virtual void OnWasHidden();
436 virtual void OnWasShown(bool needs_repainting,
437 const ui::LatencyInfo& latency_info);
438 void OnCreateVideoAck(int32 video_id);
439 void OnUpdateVideoAck(int32 video_id);
440 void OnRequestMoveAck();
441 virtual void OnImeSetComposition(
442 const base::string16& text,
443 const std::vector<blink::WebCompositionUnderline>& underlines,
444 int selection_start,
445 int selection_end);
446 virtual void OnImeConfirmComposition(const base::string16& text,
447 const gfx::Range& replacement_range,
448 bool keep_selection);
449 void OnRepaint(gfx::Size size_to_paint);
450 void OnSyntheticGestureCompleted();
451 void OnSetTextDirection(blink::WebTextDirection direction);
452 void OnGetFPS();
453 void OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
454 const gfx::Rect& window_screen_rect);
455 void OnShowImeIfNeeded();
456 void OnSetSurfaceIdNamespace(uint32_t surface_id_namespace);
458 #if defined(OS_ANDROID)
459 // Called when we send IME event that expects an ACK.
460 void OnImeEventSentForAck(const blink::WebTextInputInfo& info);
462 // Called by the browser process for every required IME acknowledgement.
463 void OnImeEventAck();
464 #endif
466 // Notify the compositor about a change in viewport size. This should be
467 // used only with auto resize mode WebWidgets, as normal WebWidgets should
468 // go through OnResize.
469 void AutoResizeCompositor();
471 virtual void SetDeviceScaleFactor(float device_scale_factor);
472 virtual bool SetDeviceColorProfile(const std::vector<char>& color_profile);
473 virtual void ResetDeviceColorProfileForTesting();
475 virtual void OnOrientationChange();
477 // Override points to notify derived classes that a paint has happened.
478 // DidInitiatePaint happens when that has completed, and subsequent rendering
479 // won't affect the painted content. DidFlushPaint happens once we've received
480 // the ACK that the screen has been updated. For a given paint operation,
481 // these overrides will always be called in the order DidInitiatePaint,
482 // DidFlushPaint.
483 virtual void DidInitiatePaint() {}
484 virtual void DidFlushPaint() {}
486 virtual GURL GetURLForGraphicsContext3D();
488 // Gets the scroll offset of this widget, if this widget has a notion of
489 // scroll offset.
490 virtual gfx::Vector2d GetScrollOffset();
492 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
493 // use this method so that we can properly inform the RenderThread of our
494 // state.
495 void SetHidden(bool hidden);
497 void DidToggleFullscreen();
499 bool next_paint_is_resize_ack() const;
500 void set_next_paint_is_resize_ack();
501 void set_next_paint_is_repaint_ack();
503 // QueueMessage implementation extracted into a static method for easy
504 // testing.
505 static scoped_ptr<cc::SwapPromise> QueueMessageImpl(
506 IPC::Message* msg,
507 MessageDeliveryPolicy policy,
508 FrameSwapMessageQueue* frame_swap_message_queue,
509 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
510 int source_frame_number);
512 // Override point to obtain that the current input method state and caret
513 // position.
514 virtual ui::TextInputType GetTextInputType();
515 virtual ui::TextInputType WebKitToUiTextInputType(
516 blink::WebTextInputType type);
518 // Override point to obtain that the current composition character bounds.
519 // In the case of surrogate pairs, the character is treated as two characters:
520 // the bounds for first character is actual one, and the bounds for second
521 // character is zero width rectangle.
522 virtual void GetCompositionCharacterBounds(
523 std::vector<gfx::Rect>* character_bounds);
525 // Returns the range of the text that is being composed or the selection if
526 // the composition does not exist.
527 virtual void GetCompositionRange(gfx::Range* range);
529 // Returns true if the composition range or composition character bounds
530 // should be sent to the browser process.
531 bool ShouldUpdateCompositionInfo(
532 const gfx::Range& range,
533 const std::vector<gfx::Rect>& bounds);
535 // Override point to obtain that the current input method state about
536 // composition text.
537 virtual bool CanComposeInline();
539 // Tells the renderer it does not have focus. Used to prevent us from getting
540 // the focus on our own when the browser did not focus us.
541 void ClearFocus();
543 // Set the pending window rect.
544 // Because the real render_widget is hosted in another process, there is
545 // a time period where we may have set a new window rect which has not yet
546 // been processed by the browser. So we maintain a pending window rect
547 // size. If JS code sets the WindowRect, and then immediately calls
548 // GetWindowRect() we'll use this pending window rect as the size.
549 void SetPendingWindowRect(const blink::WebRect& r);
551 // Called by OnHandleInputEvent() to notify subclasses that a key event was
552 // just handled.
553 virtual void DidHandleKeyEvent() {}
555 // Called by OnHandleInputEvent() to notify subclasses that a mouse event is
556 // about to be handled.
557 // Returns true if no further handling is needed. In that case, the event
558 // won't be sent to WebKit or trigger DidHandleMouseEvent().
559 virtual bool WillHandleMouseEvent(const blink::WebMouseEvent& event);
561 // Called by OnHandleInputEvent() to notify subclasses that a gesture event is
562 // about to be handled.
563 // Returns true if no further handling is needed. In that case, the event
564 // won't be sent to WebKit.
565 virtual bool WillHandleGestureEvent(const blink::WebGestureEvent& event);
567 // Called by OnHandleInputEvent() to forward a mouse wheel event to the
568 // compositor thread, to effect the elastic overscroll effect.
569 void ObserveWheelEventAndResult(const blink::WebMouseWheelEvent& wheel_event,
570 const gfx::Vector2dF& wheel_unused_delta,
571 bool event_processed);
573 // Check whether the WebWidget has any touch event handlers registered
574 // at the given point.
575 virtual bool HasTouchEventHandlersAt(const gfx::Point& point) const;
577 // Check whether the WebWidget has any touch event handlers registered.
578 virtual void hasTouchEventHandlers(bool has_handlers);
580 // Tell the browser about the actions permitted for a new touch point.
581 virtual void setTouchAction(blink::WebTouchAction touch_action);
583 // Called when value of focused text field gets dirty, e.g. value is modified
584 // by script, not by user input.
585 virtual void didUpdateTextOfFocusedElementByNonUserInput();
587 // Creates a 3D context associated with this view.
588 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateGraphicsContext3D(
589 bool compositor);
591 // Routing ID that allows us to communicate to the parent browser process
592 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
593 int32 routing_id_;
595 int32 surface_id_;
597 // Dependencies for initializing a compositor, including flags for optional
598 // features.
599 CompositorDependencies* const compositor_deps_;
601 // We are responsible for destroying this object via its Close method.
602 // May be NULL when the window is closing.
603 blink::WebWidget* webwidget_;
605 // This is lazily constructed and must not outlive webwidget_.
606 scoped_ptr<RenderWidgetCompositor> compositor_;
608 // Set to the ID of the view that initiated creating this view, if any. When
609 // the view was initiated by the browser (the common case), this will be
610 // MSG_ROUTING_NONE. This is used in determining ownership when opening
611 // child tabs. See RenderWidget::createWebViewWithRequest.
613 // This ID may refer to an invalid view if that view is closed before this
614 // view is.
615 int32 opener_id_;
617 // The rect where this view should be initially shown.
618 gfx::Rect initial_rect_;
620 bool init_complete_;
622 // We store the current cursor object so we can avoid spamming SetCursor
623 // messages.
624 WebCursor current_cursor_;
626 // The size of the RenderWidget.
627 gfx::Size size_;
629 // The size of the view's backing surface in non-DPI-adjusted pixels.
630 gfx::Size physical_backing_size_;
632 // Whether or not Blink's viewport size should be shrunk by the height of the
633 // URL-bar (always false on platforms where URL-bar hiding isn't supported).
634 bool top_controls_shrink_blink_size_;
636 // The height of the top controls (always 0 on platforms where URL-bar hiding
637 // isn't supported).
638 float top_controls_height_;
640 // The size of the visible viewport in DPI-adjusted pixels.
641 gfx::Size visible_viewport_size_;
643 // The area that must be reserved for drawing the resize corner.
644 gfx::Rect resizer_rect_;
646 // Flags for the next ViewHostMsg_UpdateRect message.
647 int next_paint_flags_;
649 // Whether the WebWidget is in auto resize mode, which is used for example
650 // by extension popups.
651 bool auto_resize_mode_;
653 // True if we need to send an UpdateRect message to notify the browser about
654 // an already-completed auto-resize.
655 bool need_update_rect_for_auto_resize_;
657 // Set to true if we should ignore RenderWidget::Show calls.
658 bool did_show_;
660 // Indicates that we shouldn't bother generated paint events.
661 bool is_hidden_;
663 // Indicates that we are never visible, so never produce graphical output.
664 bool never_visible_;
666 // Indicates whether tab-initiated fullscreen was granted.
667 bool is_fullscreen_granted_;
669 // Indicates the display mode.
670 blink::WebDisplayMode display_mode_;
672 // Indicates whether we have been focused/unfocused by the browser.
673 bool has_focus_;
675 // Are we currently handling an input event?
676 bool handling_input_event_;
678 // Used to intercept overscroll notifications while an event is being
679 // handled. If the event causes overscroll, the overscroll metadata can be
680 // bundled in the event ack, saving an IPC. Note that we must continue
681 // supporting overscroll IPC notifications due to fling animation updates.
682 scoped_ptr<DidOverscrollParams>* handling_event_overscroll_;
684 // Are we currently handling an ime event?
685 bool handling_ime_event_;
687 // Type of the input event we are currently handling.
688 blink::WebInputEvent::Type handling_event_type_;
690 // Whether we should not send ack for the current mouse move.
691 bool ignore_ack_for_mouse_move_from_debugger_;
693 // True if we have requested this widget be closed. No more messages will
694 // be sent, except for a Close.
695 bool closing_;
697 // True if it is known that the host is in the process of being shut down.
698 bool host_closing_;
700 // Whether this RenderWidget is currently swapped out, such that the view is
701 // being rendered by another process. If all RenderWidgets in a process are
702 // swapped out, the process can exit.
703 bool is_swapped_out_;
705 // TODO(simonhong): Remove this when we enable BeginFrame scheduling for
706 // OOPIF(crbug.com/471411).
707 // Whether this RenderWidget is for an out-of-process iframe or not.
708 bool for_oopif_;
710 // Stores information about the current text input.
711 blink::WebTextInputInfo text_input_info_;
713 // Stores the current text input type of |webwidget_|.
714 ui::TextInputType text_input_type_;
716 // Stores the current text input mode of |webwidget_|.
717 ui::TextInputMode text_input_mode_;
719 // Stores the current text input flags of |webwidget_|.
720 int text_input_flags_;
722 // Stores the current type of composition text rendering of |webwidget_|.
723 bool can_compose_inline_;
725 // Stores the current selection bounds.
726 gfx::Rect selection_focus_rect_;
727 gfx::Rect selection_anchor_rect_;
729 // Stores the current composition character bounds.
730 std::vector<gfx::Rect> composition_character_bounds_;
732 // Stores the current composition range.
733 gfx::Range composition_range_;
735 // The kind of popup this widget represents, NONE if not a popup.
736 blink::WebPopupType popup_type_;
738 // Holds all the needed plugin window moves for a scroll.
739 typedef std::vector<WebPluginGeometry> WebPluginGeometryVector;
740 WebPluginGeometryVector plugin_window_moves_;
742 // While we are waiting for the browser to update window sizes, we track the
743 // pending size temporarily.
744 int pending_window_rect_count_;
745 blink::WebRect pending_window_rect_;
747 // The screen rects of the view and the window that contains it.
748 gfx::Rect view_screen_rect_;
749 gfx::Rect window_screen_rect_;
751 scoped_ptr<IPC::Message> pending_input_event_ack_;
753 // The time spent in input handlers this frame. Used to throttle input acks.
754 base::TimeDelta total_input_handling_time_this_frame_;
756 // Indicates if the next sequence of Char events should be suppressed or not.
757 bool suppress_next_char_events_;
759 // Properties of the screen hosting this RenderWidget instance.
760 blink::WebScreenInfo screen_info_;
762 // The device scale factor. This value is computed from the DPI entries in
763 // |screen_info_| on some platforms, and defaults to 1 on other platforms.
764 float device_scale_factor_;
766 // The device color profile on supported platforms.
767 std::vector<char> device_color_profile_;
769 // State associated with synthetic gestures. Synthetic gestures are processed
770 // in-order, so a queue is sufficient to identify the correct state for a
771 // completed gesture.
772 std::queue<SyntheticGestureCompletionCallback>
773 pending_synthetic_gesture_callbacks_;
775 uint32 next_output_surface_id_;
777 #if defined(OS_ANDROID)
778 // Indicates value in the focused text field is in dirty state, i.e. modified
779 // by script etc., not by user input.
780 bool text_field_is_dirty_;
782 // Stores the history of text input infos from the last ACK'ed one from the
783 // current one. The size is the number of pending ACKs plus one, since we
784 // intentionally keep the last ack'd value to know what the browser is
785 // currently aware of.
786 std::deque<blink::WebTextInputInfo> text_input_info_history_;
788 // The background color of the document body element. This is used as the
789 // default background color for filling the screen areas for which we don't
790 // have the actual content.
791 SkColor body_background_color_;
792 #endif
794 scoped_ptr<ScreenMetricsEmulator> screen_metrics_emulator_;
796 // Popups may be displaced when screen metrics emulation is enabled.
797 // These values are used to properly adjust popup position.
798 gfx::PointF popup_view_origin_for_emulation_;
799 gfx::PointF popup_screen_origin_for_emulation_;
800 float popup_origin_scale_for_emulation_;
802 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue_;
803 scoped_ptr<ResizingModeSelector> resizing_mode_selector_;
805 // Lists of RenderFrameProxy objects that need to be notified of
806 // compositing-related events (e.g. DidCommitCompositorFrame).
807 base::ObserverList<RenderFrameProxy> render_frame_proxies_;
808 #if defined(VIDEO_HOLE)
809 base::ObserverList<RenderFrameImpl> video_hole_frames_;
810 #endif // defined(VIDEO_HOLE)
812 // A list of RenderFrames associated with this RenderWidget. Notifications
813 // are sent to each frame in the list for events such as changing
814 // visibility state for example.
815 base::ObserverList<RenderFrameImpl> render_frames_;
817 ui::MenuSourceType context_menu_source_type_;
818 bool has_host_context_menu_location_;
819 gfx::Point host_context_menu_location_;
821 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
824 } // namespace content
826 #endif // CONTENT_RENDERER_RENDER_WIDGET_H_