| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_RENDER_WIDGET_H_ | 5 #ifndef CONTENT_RENDERER_RENDER_WIDGET_H_ |
| 6 #define CONTENT_RENDERER_RENDER_WIDGET_H_ | 6 #define CONTENT_RENDERER_RENDER_WIDGET_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <deque> | 11 #include <deque> |
| 12 #include <map> | 12 #include <map> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
| 23 #include "content/common/cursors/webcursor.h" | 23 #include "content/common/cursors/webcursor.h" |
| 24 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 24 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 25 #include "content/common/input/synthetic_gesture_params.h" | 25 #include "content/common/input/synthetic_gesture_params.h" |
| 26 #include "content/renderer/gpu/render_widget_compositor_delegate.h" | |
| 27 #include "content/renderer/input/render_widget_input_handler.h" | 26 #include "content/renderer/input/render_widget_input_handler.h" |
| 28 #include "content/renderer/input/render_widget_input_handler_delegate.h" | 27 #include "content/renderer/input/render_widget_input_handler_delegate.h" |
| 29 #include "content/renderer/message_delivery_policy.h" | 28 #include "content/renderer/message_delivery_policy.h" |
| 30 #include "ipc/ipc_listener.h" | 29 #include "ipc/ipc_listener.h" |
| 31 #include "ipc/ipc_sender.h" | 30 #include "ipc/ipc_sender.h" |
| 32 #include "third_party/WebKit/public/platform/WebDisplayMode.h" | 31 #include "third_party/WebKit/public/platform/WebDisplayMode.h" |
| 33 #include "third_party/WebKit/public/platform/WebRect.h" | 32 #include "third_party/WebKit/public/platform/WebRect.h" |
| 34 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 33 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
| 35 #include "third_party/WebKit/public/web/WebInputEvent.h" | 34 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 36 #include "third_party/WebKit/public/web/WebPopupType.h" | 35 #include "third_party/WebKit/public/web/WebPopupType.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // | 96 // |
| 98 // RenderWidget is used to implement: | 97 // RenderWidget is used to implement: |
| 99 // - RenderViewImpl (deprecated) | 98 // - RenderViewImpl (deprecated) |
| 100 // - Fullscreen mode (RenderWidgetFullScreen) | 99 // - Fullscreen mode (RenderWidgetFullScreen) |
| 101 // - Popup "menus" (like the color chooser and date picker) | 100 // - Popup "menus" (like the color chooser and date picker) |
| 102 // - Widgets for frames (for out-of-process iframe support) | 101 // - Widgets for frames (for out-of-process iframe support) |
| 103 class CONTENT_EXPORT RenderWidget | 102 class CONTENT_EXPORT RenderWidget |
| 104 : public IPC::Listener, | 103 : public IPC::Listener, |
| 105 public IPC::Sender, | 104 public IPC::Sender, |
| 106 NON_EXPORTED_BASE(virtual public blink::WebWidgetClient), | 105 NON_EXPORTED_BASE(virtual public blink::WebWidgetClient), |
| 107 public RenderWidgetCompositorDelegate, | |
| 108 public RenderWidgetInputHandlerDelegate, | 106 public RenderWidgetInputHandlerDelegate, |
| 109 public base::RefCounted<RenderWidget> { | 107 public base::RefCounted<RenderWidget> { |
| 110 public: | 108 public: |
| 111 // Creates a new RenderWidget. The opener_id is the routing ID of the | 109 // Creates a new RenderWidget. The opener_id is the routing ID of the |
| 112 // RenderView that this widget lives inside. | 110 // RenderView that this widget lives inside. |
| 113 static RenderWidget* Create(int32_t opener_id, | 111 static RenderWidget* Create(int32_t opener_id, |
| 114 CompositorDependencies* compositor_deps, | 112 CompositorDependencies* compositor_deps, |
| 115 blink::WebPopupType popup_type, | 113 blink::WebPopupType popup_type, |
| 116 const blink::WebScreenInfo& screen_info); | 114 const blink::WebScreenInfo& screen_info); |
| 117 | 115 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 132 | 130 |
| 133 CompositorDependencies* compositor_deps() const { return compositor_deps_; } | 131 CompositorDependencies* compositor_deps() const { return compositor_deps_; } |
| 134 blink::WebWidget* webwidget() const { return webwidget_; } | 132 blink::WebWidget* webwidget() const { return webwidget_; } |
| 135 gfx::Size size() const { return size_; } | 133 gfx::Size size() const { return size_; } |
| 136 bool is_fullscreen_granted() const { return is_fullscreen_granted_; } | 134 bool is_fullscreen_granted() const { return is_fullscreen_granted_; } |
| 137 blink::WebDisplayMode display_mode() const { return display_mode_; } | 135 blink::WebDisplayMode display_mode() const { return display_mode_; } |
| 138 bool is_hidden() const { return is_hidden_; } | 136 bool is_hidden() const { return is_hidden_; } |
| 139 // Temporary for debugging purposes... | 137 // Temporary for debugging purposes... |
| 140 bool closing() const { return closing_; } | 138 bool closing() const { return closing_; } |
| 141 bool is_swapped_out() { return is_swapped_out_; } | 139 bool is_swapped_out() { return is_swapped_out_; } |
| 140 bool for_oopif() { return for_oopif_; } |
| 142 bool has_host_context_menu_location() { | 141 bool has_host_context_menu_location() { |
| 143 return has_host_context_menu_location_; | 142 return has_host_context_menu_location_; |
| 144 } | 143 } |
| 145 gfx::Point host_context_menu_location() { | 144 gfx::Point host_context_menu_location() { |
| 146 return host_context_menu_location_; | 145 return host_context_menu_location_; |
| 147 } | 146 } |
| 148 | 147 |
| 149 // ScreenInfo exposed so it can be passed to subframe RenderWidgets. | 148 // ScreenInfo exposed so it can be passed to subframe RenderWidgets. |
| 150 blink::WebScreenInfo screen_info() const { return screen_info_; } | 149 blink::WebScreenInfo screen_info() const { return screen_info_; } |
| 151 | 150 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 162 void RegisterVideoHoleFrame(RenderFrameImpl* frame); | 161 void RegisterVideoHoleFrame(RenderFrameImpl* frame); |
| 163 void UnregisterVideoHoleFrame(RenderFrameImpl* frame); | 162 void UnregisterVideoHoleFrame(RenderFrameImpl* frame); |
| 164 #endif // defined(VIDEO_HOLE) | 163 #endif // defined(VIDEO_HOLE) |
| 165 | 164 |
| 166 // IPC::Listener | 165 // IPC::Listener |
| 167 bool OnMessageReceived(const IPC::Message& msg) override; | 166 bool OnMessageReceived(const IPC::Message& msg) override; |
| 168 | 167 |
| 169 // IPC::Sender | 168 // IPC::Sender |
| 170 bool Send(IPC::Message* msg) override; | 169 bool Send(IPC::Message* msg) override; |
| 171 | 170 |
| 172 // RenderWidgetCompositorDelegate | |
| 173 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | |
| 174 const gfx::Vector2dF& outer_delta, | |
| 175 const gfx::Vector2dF& elastic_overscroll_delta, | |
| 176 float page_scale, | |
| 177 float top_controls_delta) override; | |
| 178 void BeginMainFrame(double frame_time_sec) override; | |
| 179 scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) override; | |
| 180 scoped_ptr<cc::BeginFrameSource> CreateExternalBeginFrameSource() override; | |
| 181 void DidCommitAndDrawCompositorFrame() override; | |
| 182 void DidCommitCompositorFrame() override; | |
| 183 void DidCompletePageScaleAnimation() override; | |
| 184 void DidCompleteSwapBuffers() override; | |
| 185 bool ForOOPIF() const override; | |
| 186 void ForwardCompositorProto(const std::vector<uint8_t>& proto) override; | |
| 187 void OnSwapBuffersAborted() override; | |
| 188 void OnSwapBuffersComplete() override; | |
| 189 void OnSwapBuffersPosted() override; | |
| 190 void RecordFrameTimingEvents( | |
| 191 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, | |
| 192 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) | |
| 193 override; | |
| 194 void ScheduleAnimation() override; | |
| 195 void UpdateVisualState() override; | |
| 196 void WillBeginCompositorFrame() override; | |
| 197 | |
| 198 // RenderWidgetInputHandlerDelegate | 171 // RenderWidgetInputHandlerDelegate |
| 199 void FocusChangeComplete() override; | 172 void FocusChangeComplete() override; |
| 200 bool HasTouchEventHandlersAt(const gfx::Point& point) const override; | 173 bool HasTouchEventHandlersAt(const gfx::Point& point) const override; |
| 201 void ObserveWheelEventAndResult(const blink::WebMouseWheelEvent& wheel_event, | 174 void ObserveWheelEventAndResult(const blink::WebMouseWheelEvent& wheel_event, |
| 202 const gfx::Vector2dF& wheel_unused_delta, | 175 const gfx::Vector2dF& wheel_unused_delta, |
| 203 bool event_processed) override; | 176 bool event_processed) override; |
| 204 void OnDidHandleKeyEvent() override; | 177 void OnDidHandleKeyEvent() override; |
| 205 void OnDidOverscroll(const DidOverscrollParams& params) override; | 178 void OnDidOverscroll(const DidOverscrollParams& params) override; |
| 206 void OnInputEventAck(scoped_ptr<InputEventAck> input_event_ack) override; | 179 void OnInputEventAck(scoped_ptr<InputEventAck> input_event_ack) override; |
| 207 void SetInputHandler(RenderWidgetInputHandler* input_handler) override; | 180 void SetInputHandler(RenderWidgetInputHandler* input_handler) override; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 249 |
| 277 // When paused in debugger, we send ack for mouse event early. This ensures | 250 // When paused in debugger, we send ack for mouse event early. This ensures |
| 278 // that we continue receiving mouse moves and pass them to debugger. Returns | 251 // that we continue receiving mouse moves and pass them to debugger. Returns |
| 279 // whether we are paused in mouse move event and have sent the ack. | 252 // whether we are paused in mouse move event and have sent the ack. |
| 280 bool SendAckForMouseMoveFromDebugger(); | 253 bool SendAckForMouseMoveFromDebugger(); |
| 281 | 254 |
| 282 // When resumed from pause in debugger while handling mouse move, | 255 // When resumed from pause in debugger while handling mouse move, |
| 283 // we should not send an extra ack (see SendAckForMouseMoveFromDebugger). | 256 // we should not send an extra ack (see SendAckForMouseMoveFromDebugger). |
| 284 void IgnoreAckForMouseMoveFromDebugger(); | 257 void IgnoreAckForMouseMoveFromDebugger(); |
| 285 | 258 |
| 259 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback); |
| 260 |
| 286 // Callback for use with synthetic gestures (e.g. BeginSmoothScroll). | 261 // Callback for use with synthetic gestures (e.g. BeginSmoothScroll). |
| 287 typedef base::Callback<void()> SyntheticGestureCompletionCallback; | 262 typedef base::Callback<void()> SyntheticGestureCompletionCallback; |
| 288 | 263 |
| 289 // Send a synthetic gesture to the browser to be queued to the synthetic | 264 // Send a synthetic gesture to the browser to be queued to the synthetic |
| 290 // gesture controller. | 265 // gesture controller. |
| 291 void QueueSyntheticGesture( | 266 void QueueSyntheticGesture( |
| 292 scoped_ptr<SyntheticGestureParams> gesture_params, | 267 scoped_ptr<SyntheticGestureParams> gesture_params, |
| 293 const SyntheticGestureCompletionCallback& callback); | 268 const SyntheticGestureCompletionCallback& callback); |
| 294 | 269 |
| 295 // Deliveres |message| together with compositor state change updates. The | 270 // Deliveres |message| together with compositor state change updates. The |
| 296 // exact behavior depends on |policy|. | 271 // exact behavior depends on |policy|. |
| 297 // This mechanism is not a drop-in replacement for IPC: messages sent this way | 272 // This mechanism is not a drop-in replacement for IPC: messages sent this way |
| 298 // will not be automatically available to BrowserMessageFilter, for example. | 273 // will not be automatically available to BrowserMessageFilter, for example. |
| 299 // FIFO ordering is preserved between messages enqueued with the same | 274 // FIFO ordering is preserved between messages enqueued with the same |
| 300 // |policy|, the ordering between messages enqueued for different policies is | 275 // |policy|, the ordering between messages enqueued for different policies is |
| 301 // undefined. | 276 // undefined. |
| 302 // | 277 // |
| 303 // |msg| message to send, ownership of |msg| is transferred. | 278 // |msg| message to send, ownership of |msg| is transferred. |
| 304 // |policy| see the comment on MessageDeliveryPolicy. | 279 // |policy| see the comment on MessageDeliveryPolicy. |
| 305 void QueueMessage(IPC::Message* msg, MessageDeliveryPolicy policy); | 280 void QueueMessage(IPC::Message* msg, MessageDeliveryPolicy policy); |
| 306 | 281 |
| 307 // Handle start and finish of IME event guard. | 282 // Handle start and finish of IME event guard. |
| 308 void OnImeEventGuardStart(ImeEventGuard* guard); | 283 void OnImeEventGuardStart(ImeEventGuard* guard); |
| 309 void OnImeEventGuardFinish(ImeEventGuard* guard); | 284 void OnImeEventGuardFinish(ImeEventGuard* guard); |
| 310 | 285 |
| 311 // Returns whether we currently should handle an IME event. | 286 // Returns whether we currently should handle an IME event. |
| 312 bool ShouldHandleImeEvent(); | 287 bool ShouldHandleImeEvent(); |
| 313 | 288 |
| 289 // Called by the compositor when page scale animation completed. |
| 290 virtual void DidCompletePageScaleAnimation() {} |
| 291 |
| 314 // ScreenMetricsEmulator class manages screen emulation inside a render | 292 // ScreenMetricsEmulator class manages screen emulation inside a render |
| 315 // widget. This includes resizing, placing view on the screen at desired | 293 // widget. This includes resizing, placing view on the screen at desired |
| 316 // position, changing device scale factor, and scaling down the whole | 294 // position, changing device scale factor, and scaling down the whole |
| 317 // widget if required to fit into the browser window. | 295 // widget if required to fit into the browser window. |
| 318 class ScreenMetricsEmulator; | 296 class ScreenMetricsEmulator; |
| 319 | 297 |
| 320 void SetPopupOriginAdjustmentsForEmulation(ScreenMetricsEmulator* emulator); | 298 void SetPopupOriginAdjustmentsForEmulation(ScreenMetricsEmulator* emulator); |
| 321 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor); | 299 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor); |
| 322 | 300 |
| 301 // Indicates that the compositor is about to begin a frame. This is primarily |
| 302 // to signal to flow control mechanisms that a frame is beginning, not to |
| 303 // perform actual painting work. |
| 304 void WillBeginCompositorFrame(); |
| 305 |
| 306 // Notifies about a compositor frame commit operation having finished. |
| 307 virtual void DidCommitCompositorFrame(); |
| 308 |
| 309 // Notifies that the draw commands for a committed frame have been issued. |
| 310 void DidCommitAndDrawCompositorFrame(); |
| 311 |
| 312 // Notifies that the compositor has posted a swapbuffers operation to the GPU |
| 313 // process. |
| 314 void DidCompleteSwapBuffers(); |
| 323 | 315 |
| 324 void ScheduleComposite(); | 316 void ScheduleComposite(); |
| 325 void ScheduleCompositeWithForcedRedraw(); | 317 void ScheduleCompositeWithForcedRedraw(); |
| 326 | 318 |
| 319 // Called by the compositor in single-threaded mode when a swap is posted, |
| 320 // completes or is aborted. |
| 321 void OnSwapBuffersPosted(); |
| 322 void OnSwapBuffersComplete(); |
| 323 void OnSwapBuffersAborted(); |
| 324 |
| 327 // Checks if the selection bounds have been changed. If they are changed, | 325 // Checks if the selection bounds have been changed. If they are changed, |
| 328 // the new value will be sent to the browser process. | 326 // the new value will be sent to the browser process. |
| 329 void UpdateSelectionBounds(); | 327 void UpdateSelectionBounds(); |
| 330 | 328 |
| 331 // Called by the compositor to forward a proto that represents serialized | 329 // Called by the compositor to forward a proto that represents serialized |
| 332 // compositor state. | 330 // compositor state. |
| 331 void ForwardCompositorProto(const std::vector<uint8_t>& proto); |
| 333 | 332 |
| 334 virtual void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end); | 333 virtual void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end); |
| 335 | 334 |
| 336 void OnShowHostContextMenu(ContextMenuParams* params); | 335 void OnShowHostContextMenu(ContextMenuParams* params); |
| 337 | 336 |
| 338 // Checks if the composition range or composition character bounds have been | 337 // Checks if the composition range or composition character bounds have been |
| 339 // changed. If they are changed, the new value will be sent to the browser | 338 // changed. If they are changed, the new value will be sent to the browser |
| 340 // process. This method does nothing when the browser process is not able to | 339 // process. This method does nothing when the browser process is not able to |
| 341 // handle composition range and composition character bounds. | 340 // handle composition range and composition character bounds. |
| 342 void UpdateCompositionInfo(bool should_update_range); | 341 void UpdateCompositionInfo(bool should_update_range); |
| 343 | 342 |
| 343 bool host_closing() const { return host_closing_; } |
| 344 |
| 344 protected: | 345 protected: |
| 345 // Friend RefCounted so that the dtor can be non-public. Using this class | 346 // Friend RefCounted so that the dtor can be non-public. Using this class |
| 346 // without ref-counting is an error. | 347 // without ref-counting is an error. |
| 347 friend class base::RefCounted<RenderWidget>; | 348 friend class base::RefCounted<RenderWidget>; |
| 348 | 349 |
| 349 // For unit tests. | 350 // For unit tests. |
| 350 friend class RenderWidgetTest; | 351 friend class RenderWidgetTest; |
| 351 | 352 |
| 352 enum ResizeAck { | 353 enum ResizeAck { |
| 353 SEND_RESIZE_ACK, | 354 SEND_RESIZE_ACK, |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 | 754 |
| 754 scoped_ptr<scheduler::RenderWidgetSchedulingState> | 755 scoped_ptr<scheduler::RenderWidgetSchedulingState> |
| 755 render_widget_scheduling_state_; | 756 render_widget_scheduling_state_; |
| 756 | 757 |
| 757 DISALLOW_COPY_AND_ASSIGN(RenderWidget); | 758 DISALLOW_COPY_AND_ASSIGN(RenderWidget); |
| 758 }; | 759 }; |
| 759 | 760 |
| 760 } // namespace content | 761 } // namespace content |
| 761 | 762 |
| 762 #endif // CONTENT_RENDERER_RENDER_WIDGET_H_ | 763 #endif // CONTENT_RENDERER_RENDER_WIDGET_H_ |
| OLD | NEW |