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 #include "content/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return false; | 240 return false; |
241 } | 241 } |
242 | 242 |
243 // If given a messsage without a routing ID, then assign our routing ID. | 243 // If given a messsage without a routing ID, then assign our routing ID. |
244 if (message->routing_id() == MSG_ROUTING_NONE) | 244 if (message->routing_id() == MSG_ROUTING_NONE) |
245 message->set_routing_id(routing_id_); | 245 message->set_routing_id(routing_id_); |
246 | 246 |
247 return RenderThread::Get()->Send(message); | 247 return RenderThread::Get()->Send(message); |
248 } | 248 } |
249 | 249 |
250 // Got a response from the browser after the renderer decided to create a new | 250 void RenderWidget::Resize(const gfx::Size& new_size, |
251 // view. | 251 const gfx::Rect& resizer_rect, |
252 void RenderWidget::OnCreatingNewAck( | 252 bool is_fullscreen, |
253 gfx::NativeViewId parent) { | 253 ResizeAck resize_ack) { |
254 DCHECK(routing_id_ != MSG_ROUTING_NONE); | 254 // A resize ack shouldn't be requested if we have not ACK'd the previous one. |
| 255 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack()); |
| 256 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK); |
255 | 257 |
256 CompleteInit(parent); | 258 // Ignore this during shutdown. |
257 } | |
258 | |
259 void RenderWidget::OnClose() { | |
260 if (closing_) | |
261 return; | |
262 closing_ = true; | |
263 | |
264 // Browser correspondence is no longer needed at this point. | |
265 if (routing_id_ != MSG_ROUTING_NONE) { | |
266 RenderThread::Get()->RemoveRoute(routing_id_); | |
267 SetHidden(false); | |
268 } | |
269 | |
270 // If there is a Send call on the stack, then it could be dangerous to close | |
271 // now. Post a task that only gets invoked when there are no nested message | |
272 // loops. | |
273 MessageLoop::current()->PostNonNestableTask( | |
274 FROM_HERE, base::Bind(&RenderWidget::Close, this)); | |
275 | |
276 // Balances the AddRef taken when we called AddRoute. | |
277 Release(); | |
278 } | |
279 | |
280 void RenderWidget::OnResize(const gfx::Size& new_size, | |
281 const gfx::Rect& resizer_rect, | |
282 bool is_fullscreen) { | |
283 // During shutdown we can just ignore this message. | |
284 if (!webwidget_) | 259 if (!webwidget_) |
285 return; | 260 return; |
286 | 261 |
287 // Remember the rect where the resize corner will be drawn. | 262 // Remember the rect where the resize corner will be drawn. |
288 resizer_rect_ = resizer_rect; | 263 resizer_rect_ = resizer_rect; |
289 | 264 |
290 // NOTE: We may have entered fullscreen mode without changing our size. | 265 // NOTE: We may have entered fullscreen mode without changing our size. |
291 bool fullscreen_change = is_fullscreen_ != is_fullscreen; | 266 bool fullscreen_change = is_fullscreen_ != is_fullscreen; |
292 if (fullscreen_change) | 267 if (fullscreen_change) |
293 WillToggleFullscreen(); | 268 WillToggleFullscreen(); |
294 is_fullscreen_ = is_fullscreen; | 269 is_fullscreen_ = is_fullscreen; |
295 | 270 |
296 if (size_ != new_size) { | 271 if (size_ != new_size) { |
297 // TODO(darin): We should not need to reset this here. | 272 // TODO(darin): We should not need to reset this here. |
298 SetHidden(false); | 273 SetHidden(false); |
299 needs_repainting_on_restore_ = false; | 274 needs_repainting_on_restore_ = false; |
300 | 275 |
301 size_ = new_size; | 276 size_ = new_size; |
302 | 277 |
303 // We should not be sent a Resize message if we have not ACK'd the previous | |
304 DCHECK(!next_paint_is_resize_ack()); | |
305 | |
306 paint_aggregator_.ClearPendingUpdate(); | 278 paint_aggregator_.ClearPendingUpdate(); |
307 | 279 |
308 // When resizing, we want to wait to paint before ACK'ing the resize. This | 280 // When resizing, we want to wait to paint before ACK'ing the resize. This |
309 // ensures that we only resize as fast as we can paint. We only need to | 281 // ensures that we only resize as fast as we can paint. We only need to |
310 // send an ACK if we are resized to a non-empty rect. | 282 // send an ACK if we are resized to a non-empty rect. |
311 webwidget_->resize(new_size); | 283 webwidget_->resize(new_size); |
312 if (!new_size.IsEmpty()) { | 284 if (!new_size.IsEmpty()) { |
313 if (!is_accelerated_compositing_active_) { | 285 if (!is_accelerated_compositing_active_) { |
314 // Resize should have caused an invalidation of the entire view. | 286 // Resize should have caused an invalidation of the entire view. |
315 DCHECK(paint_aggregator_.HasPendingUpdate()); | 287 DCHECK(paint_aggregator_.HasPendingUpdate()); |
316 } | 288 } |
317 | 289 |
318 // We will send the Resize_ACK flag once we paint again. | 290 // Send the Resize_ACK flag once we paint again if requested. |
319 set_next_paint_is_resize_ack(); | 291 if (resize_ack == SEND_RESIZE_ACK) |
| 292 set_next_paint_is_resize_ack(); |
320 } | 293 } |
321 } | 294 } |
322 | 295 |
323 if (fullscreen_change) | 296 if (fullscreen_change) |
324 DidToggleFullscreen(); | 297 DidToggleFullscreen(); |
| 298 |
| 299 // If a resize ack is requested and it isn't set-up, then no more resizes will |
| 300 // come in and in general things will go wrong. |
| 301 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() || |
| 302 next_paint_is_resize_ack()); |
| 303 } |
| 304 |
| 305 void RenderWidget::OnClose() { |
| 306 if (closing_) |
| 307 return; |
| 308 closing_ = true; |
| 309 |
| 310 // Browser correspondence is no longer needed at this point. |
| 311 if (routing_id_ != MSG_ROUTING_NONE) { |
| 312 RenderThread::Get()->RemoveRoute(routing_id_); |
| 313 SetHidden(false); |
| 314 } |
| 315 |
| 316 // If there is a Send call on the stack, then it could be dangerous to close |
| 317 // now. Post a task that only gets invoked when there are no nested message |
| 318 // loops. |
| 319 MessageLoop::current()->PostNonNestableTask( |
| 320 FROM_HERE, base::Bind(&RenderWidget::Close, this)); |
| 321 |
| 322 // Balances the AddRef taken when we called AddRoute. |
| 323 Release(); |
| 324 } |
| 325 |
| 326 // Got a response from the browser after the renderer decided to create a new |
| 327 // view. |
| 328 void RenderWidget::OnCreatingNewAck( |
| 329 gfx::NativeViewId parent) { |
| 330 DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 331 |
| 332 CompleteInit(parent); |
| 333 } |
| 334 |
| 335 void RenderWidget::OnResize(const gfx::Size& new_size, |
| 336 const gfx::Rect& resizer_rect, |
| 337 bool is_fullscreen) { |
| 338 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK); |
325 } | 339 } |
326 | 340 |
327 void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { | 341 void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { |
328 if (resizer_rect_ != resizer_rect) { | 342 if (resizer_rect_ != resizer_rect) { |
329 gfx::Rect view_rect(size_); | 343 gfx::Rect view_rect(size_); |
330 | 344 |
331 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_); | 345 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_); |
332 if (!old_damage_rect.IsEmpty()) | 346 if (!old_damage_rect.IsEmpty()) |
333 paint_aggregator_.InvalidateRect(old_damage_rect); | 347 paint_aggregator_.InvalidateRect(old_damage_rect); |
334 | 348 |
(...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1644 } | 1658 } |
1645 } | 1659 } |
1646 | 1660 |
1647 bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 1661 bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
1648 return false; | 1662 return false; |
1649 } | 1663 } |
1650 | 1664 |
1651 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { | 1665 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { |
1652 return false; | 1666 return false; |
1653 } | 1667 } |
OLD | NEW |