| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/render_widget.h" | 5 #include "chrome/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include "base/gfx/point.h" | 7 #include "base/gfx/point.h" |
| 8 #include "base/gfx/size.h" | 8 #include "base/gfx/size.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 SetHidden(false); | 208 SetHidden(false); |
| 209 needs_repainting_on_restore_ = false; | 209 needs_repainting_on_restore_ = false; |
| 210 | 210 |
| 211 // We shouldn't be asked to resize to our current size. | 211 // We shouldn't be asked to resize to our current size. |
| 212 DCHECK(size_ != new_size); | 212 DCHECK(size_ != new_size); |
| 213 size_ = new_size; | 213 size_ = new_size; |
| 214 | 214 |
| 215 // We should not be sent a Resize message if we have not ACK'd the previous | 215 // We should not be sent a Resize message if we have not ACK'd the previous |
| 216 DCHECK(!next_paint_is_resize_ack()); | 216 DCHECK(!next_paint_is_resize_ack()); |
| 217 | 217 |
| 218 paint_aggregator_.ClearPendingUpdate(); |
| 219 |
| 218 // When resizing, we want to wait to paint before ACK'ing the resize. This | 220 // When resizing, we want to wait to paint before ACK'ing the resize. This |
| 219 // ensures that we only resize as fast as we can paint. We only need to send | 221 // ensures that we only resize as fast as we can paint. We only need to send |
| 220 // an ACK if we are resized to a non-empty rect. | 222 // an ACK if we are resized to a non-empty rect. |
| 221 webwidget_->resize(new_size); | 223 webwidget_->resize(new_size); |
| 222 if (!new_size.IsEmpty()) { | 224 if (!new_size.IsEmpty()) { |
| 223 DCHECK(!paint_rect_.IsEmpty()); | 225 // Resize should have caused an invalidation of the entire view. |
| 224 | 226 DCHECK(paint_aggregator_.HasPendingUpdate()); |
| 225 // This should have caused an invalidation of the entire view. The damaged | |
| 226 // rect could be larger than new_size if we are being made smaller. | |
| 227 DCHECK_GE(paint_rect_.width(), new_size.width()); | |
| 228 DCHECK_GE(paint_rect_.height(), new_size.height()); | |
| 229 | 227 |
| 230 // We will send the Resize_ACK flag once we paint again. | 228 // We will send the Resize_ACK flag once we paint again. |
| 231 set_next_paint_is_resize_ack(); | 229 set_next_paint_is_resize_ack(); |
| 232 } | 230 } |
| 233 } | 231 } |
| 234 | 232 |
| 235 void RenderWidget::OnWasHidden() { | 233 void RenderWidget::OnWasHidden() { |
| 236 // Go into a mode where we stop generating paint and scrolling events. | 234 // Go into a mode where we stop generating paint and scrolling events. |
| 237 SetHidden(true); | 235 SetHidden(true); |
| 238 } | 236 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 264 // we should have no current paint buf. | 262 // we should have no current paint buf. |
| 265 if (current_paint_buf_) { | 263 if (current_paint_buf_) { |
| 266 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); | 264 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 267 current_paint_buf_ = NULL; | 265 current_paint_buf_ = NULL; |
| 268 } | 266 } |
| 269 | 267 |
| 270 // Notify subclasses | 268 // Notify subclasses |
| 271 DidPaint(); | 269 DidPaint(); |
| 272 | 270 |
| 273 // Continue painting if necessary... | 271 // Continue painting if necessary... |
| 274 CallDoDeferredPaint(); | 272 CallDoDeferredUpdate(); |
| 275 } | 273 } |
| 276 | 274 |
| 277 void RenderWidget::OnRequestMoveAck() { | 275 void RenderWidget::OnRequestMoveAck() { |
| 278 DCHECK(pending_window_rect_count_); | 276 DCHECK(pending_window_rect_count_); |
| 279 pending_window_rect_count_--; | 277 pending_window_rect_count_--; |
| 280 } | 278 } |
| 281 | 279 |
| 282 void RenderWidget::OnScrollRectAck() { | 280 void RenderWidget::OnScrollRectAck() { |
| 283 DCHECK(scroll_reply_pending()); | 281 DCHECK(scroll_reply_pending()); |
| 284 | 282 |
| 285 if (current_scroll_buf_) { | 283 if (current_scroll_buf_) { |
| 286 RenderProcess::current()->ReleaseTransportDIB(current_scroll_buf_); | 284 RenderProcess::current()->ReleaseTransportDIB(current_scroll_buf_); |
| 287 current_scroll_buf_ = NULL; | 285 current_scroll_buf_ = NULL; |
| 288 } | 286 } |
| 289 | 287 |
| 290 // Continue scrolling if necessary... | 288 // Continue scrolling if necessary... |
| 291 CallDoDeferredScroll(); | 289 CallDoDeferredUpdate(); |
| 292 } | |
| 293 | |
| 294 void RenderWidget::CallDoDeferredScroll() { | |
| 295 DoDeferredScroll(); | |
| 296 | |
| 297 if (pending_input_event_ack_.get()) { | |
| 298 Send(pending_input_event_ack_.get()); | |
| 299 pending_input_event_ack_.release(); | |
| 300 } | |
| 301 } | 290 } |
| 302 | 291 |
| 303 void RenderWidget::OnHandleInputEvent(const IPC::Message& message) { | 292 void RenderWidget::OnHandleInputEvent(const IPC::Message& message) { |
| 304 void* iter = NULL; | 293 void* iter = NULL; |
| 305 | 294 |
| 306 const char* data; | 295 const char* data; |
| 307 int data_length; | 296 int data_length; |
| 308 handling_input_event_ = true; | 297 handling_input_event_ = true; |
| 309 if (!message.ReadData(&iter, &data, &data_length)) { | 298 if (!message.ReadData(&iter, &data, &data_length)) { |
| 310 handling_input_event_ = false; | 299 handling_input_event_ = false; |
| 311 return; | 300 return; |
| 312 } | 301 } |
| 313 | 302 |
| 314 const WebInputEvent* input_event = | 303 const WebInputEvent* input_event = |
| 315 reinterpret_cast<const WebInputEvent*>(data); | 304 reinterpret_cast<const WebInputEvent*>(data); |
| 316 bool processed = false; | 305 bool processed = false; |
| 317 if (webwidget_) | 306 if (webwidget_) |
| 318 processed = webwidget_->handleInputEvent(*input_event); | 307 processed = webwidget_->handleInputEvent(*input_event); |
| 319 | 308 |
| 320 IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_); | 309 IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_); |
| 321 response->WriteInt(input_event->type); | 310 response->WriteInt(input_event->type); |
| 322 response->WriteBool(processed); | 311 response->WriteBool(processed); |
| 323 | 312 |
| 324 if (input_event->type == WebInputEvent::MouseMove && | 313 if (input_event->type == WebInputEvent::MouseMove && |
| 325 (!paint_rect_.IsEmpty() || !scroll_rect_.IsEmpty())) { | 314 paint_aggregator_.HasPendingUpdate()) { |
| 326 // We want to rate limit the input events in this case, so we'll wait for | 315 // We want to rate limit the input events in this case, so we'll wait for |
| 327 // painting to finish before ACKing this message. | 316 // painting to finish before ACKing this message. |
| 328 pending_input_event_ack_.reset(response); | 317 pending_input_event_ack_.reset(response); |
| 329 } else { | 318 } else { |
| 330 Send(response); | 319 Send(response); |
| 331 } | 320 } |
| 332 | 321 |
| 333 handling_input_event_ = false; | 322 handling_input_event_ = false; |
| 334 | 323 |
| 335 WebInputEvent::Type type = input_event->type; | 324 WebInputEvent::Type type = input_event->type; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 369 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 381 canvas->drawPaint(paint); | 370 canvas->drawPaint(paint); |
| 382 } | 371 } |
| 383 | 372 |
| 384 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect); | 373 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect); |
| 385 | 374 |
| 386 // Flush to underlying bitmap. TODO(darin): is this needed? | 375 // Flush to underlying bitmap. TODO(darin): is this needed? |
| 387 canvas->getTopPlatformDevice().accessBitmap(false); | 376 canvas->getTopPlatformDevice().accessBitmap(false); |
| 388 } | 377 } |
| 389 | 378 |
| 390 void RenderWidget::CallDoDeferredPaint() { | 379 void RenderWidget::CallDoDeferredUpdate() { |
| 391 DoDeferredPaint(); | 380 DoDeferredUpdate(); |
| 392 | 381 |
| 393 if (pending_input_event_ack_.get()) { | 382 if (pending_input_event_ack_.get()) { |
| 394 Send(pending_input_event_ack_.get()); | 383 Send(pending_input_event_ack_.get()); |
| 395 pending_input_event_ack_.release(); | 384 pending_input_event_ack_.release(); |
| 396 } | 385 } |
| 397 } | 386 } |
| 398 | 387 |
| 399 void RenderWidget::DoDeferredPaint() { | 388 void RenderWidget::DoDeferredUpdate() { |
| 400 if (!webwidget_ || paint_reply_pending() || paint_rect_.IsEmpty()) | 389 if (!webwidget_ || !paint_aggregator_.HasPendingUpdate() || |
| 390 paint_reply_pending() || scroll_reply_pending()) |
| 401 return; | 391 return; |
| 402 | 392 |
| 403 // When we are hidden, we want to suppress painting, but we still need to | 393 // Suppress updating when we are hidden. |
| 404 // mark this DoDeferredPaint as complete. | |
| 405 if (is_hidden_ || size_.IsEmpty()) { | 394 if (is_hidden_ || size_.IsEmpty()) { |
| 406 paint_rect_ = gfx::Rect(); | 395 paint_aggregator_.ClearPendingUpdate(); |
| 407 needs_repainting_on_restore_ = true; | 396 needs_repainting_on_restore_ = true; |
| 408 return; | 397 return; |
| 409 } | 398 } |
| 410 | 399 |
| 411 // Layout may generate more invalidation... | 400 // Layout may generate more invalidation. |
| 412 webwidget_->layout(); | 401 webwidget_->layout(); |
| 413 | 402 |
| 414 // OK, save the current paint_rect to a local since painting may cause more | 403 // OK, save the pending update to a local since painting may cause more |
| 415 // invalidation. Some WebCore rendering objects only layout when painted. | 404 // invalidation. Some WebCore rendering objects only layout when painted. |
| 416 gfx::Rect damaged_rect = paint_rect_; | 405 PaintAggregator::PendingUpdate update = paint_aggregator_.GetPendingUpdate(); |
| 417 paint_rect_ = gfx::Rect(); | 406 paint_aggregator_.ClearPendingUpdate(); |
| 418 | 407 |
| 419 // Compute a buffer for painting and cache it. | 408 if (!update.scroll_rect.IsEmpty()) { |
| 420 skia::PlatformCanvas* canvas = | 409 // Optmized scrolling |
| 421 RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, | 410 |
| 422 damaged_rect); | 411 // Compute the region we will expose by scrolling, and paint that into a |
| 423 if (!canvas) { | 412 // shared memory section. |
| 424 NOTREACHED(); | 413 gfx::Rect damaged_rect = update.GetScrollDamage(); |
| 425 return; | 414 |
| 415 scoped_ptr<skia::PlatformCanvas> canvas( |
| 416 RenderProcess::current()->GetDrawingCanvas(¤t_scroll_buf_, |
| 417 damaged_rect)); |
| 418 if (!canvas.get()) { |
| 419 NOTREACHED(); |
| 420 return; |
| 421 } |
| 422 |
| 423 // We may get back a smaller canvas than we asked for. |
| 424 damaged_rect.set_width(canvas->getDevice()->width()); |
| 425 damaged_rect.set_height(canvas->getDevice()->height()); |
| 426 |
| 427 // Set these parameters before calling Paint, since that could result in |
| 428 // further invalidates (uncommon). |
| 429 ViewHostMsg_ScrollRect_Params params; |
| 430 params.bitmap_rect = damaged_rect; |
| 431 params.dx = update.scroll_delta.x(); |
| 432 params.dy = update.scroll_delta.y(); |
| 433 params.clip_rect = update.scroll_rect; |
| 434 params.view_size = size_; |
| 435 params.plugin_window_moves = plugin_window_moves_; |
| 436 params.bitmap = current_scroll_buf_->id(); |
| 437 |
| 438 plugin_window_moves_.clear(); |
| 439 |
| 440 PaintRect(damaged_rect, canvas.get()); |
| 441 Send(new ViewHostMsg_ScrollRect(routing_id_, params)); |
| 426 } | 442 } |
| 427 | 443 |
| 428 // We may get back a smaller canvas than we asked for. | 444 if (!update.paint_rect.IsEmpty()) { |
| 429 damaged_rect.set_width(canvas->getDevice()->width()); | 445 // Normal painting |
| 430 damaged_rect.set_height(canvas->getDevice()->height()); | |
| 431 | 446 |
| 432 PaintRect(damaged_rect, canvas); | 447 gfx::Rect damaged_rect = update.paint_rect; |
| 433 | 448 |
| 434 ViewHostMsg_PaintRect_Params params; | 449 // Compute a buffer for painting and cache it. |
| 435 params.bitmap_rect = damaged_rect; | 450 scoped_ptr<skia::PlatformCanvas> canvas( |
| 436 params.view_size = size_; | 451 RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, |
| 437 params.plugin_window_moves = plugin_window_moves_; | 452 damaged_rect)); |
| 438 params.flags = next_paint_flags_; | 453 if (!canvas.get()) { |
| 439 params.bitmap = current_paint_buf_->id(); | 454 NOTREACHED(); |
| 455 return; |
| 456 } |
| 440 | 457 |
| 441 delete canvas; | 458 // We may get back a smaller canvas than we asked for. |
| 459 damaged_rect.set_width(canvas->getDevice()->width()); |
| 460 damaged_rect.set_height(canvas->getDevice()->height()); |
| 442 | 461 |
| 443 plugin_window_moves_.clear(); | 462 PaintRect(damaged_rect, canvas.get()); |
| 444 | 463 |
| 445 paint_reply_pending_ = true; | 464 ViewHostMsg_PaintRect_Params params; |
| 446 Send(new ViewHostMsg_PaintRect(routing_id_, params)); | 465 params.bitmap_rect = damaged_rect; |
| 447 next_paint_flags_ = 0; | 466 params.view_size = size_; |
| 467 params.plugin_window_moves = plugin_window_moves_; |
| 468 params.flags = next_paint_flags_; |
| 469 params.bitmap = current_paint_buf_->id(); |
| 470 |
| 471 plugin_window_moves_.clear(); |
| 472 |
| 473 paint_reply_pending_ = true; |
| 474 Send(new ViewHostMsg_PaintRect(routing_id_, params)); |
| 475 next_paint_flags_ = 0; |
| 476 } |
| 448 | 477 |
| 449 UpdateIME(); | 478 UpdateIME(); |
| 450 } | 479 } |
| 451 | 480 |
| 452 void RenderWidget::DoDeferredScroll() { | |
| 453 if (!webwidget_ || scroll_reply_pending() || scroll_rect_.IsEmpty()) | |
| 454 return; | |
| 455 | |
| 456 // When we are hidden, we want to suppress scrolling, but we still need to | |
| 457 // mark this DoDeferredScroll as complete. | |
| 458 if (is_hidden_ || size_.IsEmpty()) { | |
| 459 scroll_rect_ = gfx::Rect(); | |
| 460 needs_repainting_on_restore_ = true; | |
| 461 return; | |
| 462 } | |
| 463 | |
| 464 // Layout may generate more invalidation, so we might have to bail on | |
| 465 // optimized scrolling... | |
| 466 webwidget_->layout(); | |
| 467 | |
| 468 if (scroll_rect_.IsEmpty()) | |
| 469 return; | |
| 470 | |
| 471 gfx::Rect damaged_rect; | |
| 472 | |
| 473 // Compute the region we will expose by scrolling, and paint that into a | |
| 474 // shared memory section. | |
| 475 if (scroll_delta_.x()) { | |
| 476 int dx = scroll_delta_.x(); | |
| 477 damaged_rect.set_y(scroll_rect_.y()); | |
| 478 damaged_rect.set_height(scroll_rect_.height()); | |
| 479 if (dx > 0) { | |
| 480 damaged_rect.set_x(scroll_rect_.x()); | |
| 481 damaged_rect.set_width(dx); | |
| 482 } else { | |
| 483 damaged_rect.set_x(scroll_rect_.right() + dx); | |
| 484 damaged_rect.set_width(-dx); | |
| 485 } | |
| 486 } else { | |
| 487 int dy = scroll_delta_.y(); | |
| 488 damaged_rect.set_x(scroll_rect_.x()); | |
| 489 damaged_rect.set_width(scroll_rect_.width()); | |
| 490 if (dy > 0) { | |
| 491 damaged_rect.set_y(scroll_rect_.y()); | |
| 492 damaged_rect.set_height(dy); | |
| 493 } else { | |
| 494 damaged_rect.set_y(scroll_rect_.bottom() + dy); | |
| 495 damaged_rect.set_height(-dy); | |
| 496 } | |
| 497 } | |
| 498 | |
| 499 // In case the scroll offset exceeds the width/height of the scroll rect | |
| 500 damaged_rect = scroll_rect_.Intersect(damaged_rect); | |
| 501 | |
| 502 skia::PlatformCanvas* canvas = | |
| 503 RenderProcess::current()->GetDrawingCanvas(¤t_scroll_buf_, | |
| 504 damaged_rect); | |
| 505 if (!canvas) { | |
| 506 NOTREACHED(); | |
| 507 return; | |
| 508 } | |
| 509 | |
| 510 // We may get back a smaller canvas than we asked for. | |
| 511 damaged_rect.set_width(canvas->getDevice()->width()); | |
| 512 damaged_rect.set_height(canvas->getDevice()->height()); | |
| 513 | |
| 514 // Set these parameters before calling Paint, since that could result in | |
| 515 // further invalidates (uncommon). | |
| 516 ViewHostMsg_ScrollRect_Params params; | |
| 517 params.bitmap_rect = damaged_rect; | |
| 518 params.dx = scroll_delta_.x(); | |
| 519 params.dy = scroll_delta_.y(); | |
| 520 params.clip_rect = scroll_rect_; | |
| 521 params.view_size = size_; | |
| 522 params.plugin_window_moves = plugin_window_moves_; | |
| 523 params.bitmap = current_scroll_buf_->id(); | |
| 524 | |
| 525 plugin_window_moves_.clear(); | |
| 526 | |
| 527 // Mark the scroll operation as no longer pending. | |
| 528 scroll_rect_ = gfx::Rect(); | |
| 529 | |
| 530 PaintRect(damaged_rect, canvas); | |
| 531 Send(new ViewHostMsg_ScrollRect(routing_id_, params)); | |
| 532 delete canvas; | |
| 533 UpdateIME(); | |
| 534 } | |
| 535 | |
| 536 /////////////////////////////////////////////////////////////////////////////// | 481 /////////////////////////////////////////////////////////////////////////////// |
| 537 // WebWidgetDelegate | 482 // WebWidgetDelegate |
| 538 | 483 |
| 539 void RenderWidget::didInvalidateRect(const WebRect& rect) { | 484 void RenderWidget::didInvalidateRect(const WebRect& rect) { |
| 540 // We only want one pending DoDeferredPaint call at any time... | 485 // We only want one pending DoDeferredUpdate call at any time... |
| 541 bool paint_pending = !paint_rect_.IsEmpty(); | 486 bool update_pending = paint_aggregator_.HasPendingUpdate(); |
| 542 | 487 |
| 543 // If this invalidate overlaps with a pending scroll, then we have to | 488 // The invalidated rect might be outside the bounds of the view. |
| 544 // downgrade to invalidating the scroll rect. | |
| 545 if (gfx::Rect(rect).Intersects(scroll_rect_)) { | |
| 546 paint_rect_ = paint_rect_.Union(scroll_rect_); | |
| 547 scroll_rect_ = gfx::Rect(); | |
| 548 } | |
| 549 | |
| 550 gfx::Rect view_rect(0, 0, size_.width(), size_.height()); | 489 gfx::Rect view_rect(0, 0, size_.width(), size_.height()); |
| 551 // TODO(iyengar) Investigate why we have painting issues when | 490 gfx::Rect damaged_rect = view_rect.Intersect(rect); |
| 552 // we ignore invalid regions outside the view. | 491 if (damaged_rect.IsEmpty()) |
| 553 // Ignore invalidates that occur outside the bounds of the view | |
| 554 // TODO(darin): maybe this should move into the paint code? | |
| 555 // paint_rect_ = view_rect.Intersect(paint_rect_.Union(rect)); | |
| 556 paint_rect_ = paint_rect_.Union(view_rect.Intersect(rect)); | |
| 557 | |
| 558 if (paint_rect_.IsEmpty() || paint_reply_pending() || paint_pending) | |
| 559 return; | 492 return; |
| 560 | 493 |
| 561 // Perform painting asynchronously. This serves two purposes: | 494 paint_aggregator_.InvalidateRect(damaged_rect); |
| 495 |
| 496 // We may not need to schedule another call to DoDeferredUpdate. |
| 497 if (update_pending) |
| 498 return; |
| 499 if (!paint_aggregator_.HasPendingUpdate()) |
| 500 return; |
| 501 if (paint_reply_pending() || scroll_reply_pending()) |
| 502 return; |
| 503 |
| 504 // Perform updating asynchronously. This serves two purposes: |
| 562 // 1) Ensures that we call WebView::Paint without a bunch of other junk | 505 // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 563 // on the call stack. | 506 // on the call stack. |
| 564 // 2) Allows us to collect more damage rects before painting to help coalesce | 507 // 2) Allows us to collect more damage rects before painting to help coalesce |
| 565 // the work that we will need to do. | 508 // the work that we will need to do. |
| 566 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 509 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 567 this, &RenderWidget::CallDoDeferredPaint)); | 510 this, &RenderWidget::CallDoDeferredUpdate)); |
| 568 } | 511 } |
| 569 | 512 |
| 570 void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { | 513 void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { |
| 571 if (dx != 0 && dy != 0) { | 514 // We only want one pending DoDeferredUpdate call at any time... |
| 572 // We only support scrolling along one axis at a time. | 515 bool update_pending = paint_aggregator_.HasPendingUpdate(); |
| 573 didScrollRect(0, dy, clip_rect); | |
| 574 dy = 0; | |
| 575 } | |
| 576 | 516 |
| 577 bool intersects_with_painting = paint_rect_.Intersects(clip_rect); | 517 // The scrolled rect might be outside the bounds of the view. |
| 578 | 518 gfx::Rect view_rect(0, 0, size_.width(), size_.height()); |
| 579 // If we already have a pending scroll operation or if this scroll operation | 519 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect); |
| 580 // intersects the existing paint region, then just failover to invalidating. | 520 if (damaged_rect.IsEmpty()) |
| 581 if (!scroll_rect_.IsEmpty() || intersects_with_painting) { | |
| 582 if (!intersects_with_painting && scroll_rect_ == gfx::Rect(clip_rect)) { | |
| 583 // OK, we can just update the scroll delta (requires same scrolling axis) | |
| 584 if (!dx && !scroll_delta_.x()) { | |
| 585 scroll_delta_.set_y(scroll_delta_.y() + dy); | |
| 586 return; | |
| 587 } | |
| 588 if (!dy && !scroll_delta_.y()) { | |
| 589 scroll_delta_.set_x(scroll_delta_.x() + dx); | |
| 590 return; | |
| 591 } | |
| 592 } | |
| 593 didInvalidateRect(scroll_rect_); | |
| 594 DCHECK(scroll_rect_.IsEmpty()); | |
| 595 didInvalidateRect(clip_rect); | |
| 596 return; | |
| 597 } | |
| 598 | |
| 599 // We only want one pending DoDeferredScroll call at any time... | |
| 600 bool scroll_pending = !scroll_rect_.IsEmpty(); | |
| 601 | |
| 602 scroll_rect_ = clip_rect; | |
| 603 scroll_delta_.SetPoint(dx, dy); | |
| 604 | |
| 605 if (scroll_pending) | |
| 606 return; | 521 return; |
| 607 | 522 |
| 608 // Perform scrolling asynchronously since we need to call WebView::Paint | 523 paint_aggregator_.ScrollRect(dx, dy, damaged_rect); |
| 524 |
| 525 // We may not need to schedule another call to DoDeferredUpdate. |
| 526 if (update_pending) |
| 527 return; |
| 528 if (!paint_aggregator_.HasPendingUpdate()) |
| 529 return; |
| 530 if (paint_reply_pending() || scroll_reply_pending()) |
| 531 return; |
| 532 |
| 533 // Perform updating asynchronously. This serves two purposes: |
| 534 // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 535 // on the call stack. |
| 536 // 2) Allows us to collect more damage rects before painting to help coalesce |
| 537 // the work that we will need to do. |
| 609 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 538 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 610 this, &RenderWidget::CallDoDeferredScroll)); | 539 this, &RenderWidget::CallDoDeferredUpdate)); |
| 611 } | 540 } |
| 612 | 541 |
| 613 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { | 542 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
| 614 // TODO(darin): Eliminate this temporary. | 543 // TODO(darin): Eliminate this temporary. |
| 615 WebCursor cursor(cursor_info); | 544 WebCursor cursor(cursor_info); |
| 616 | 545 |
| 617 // Only send a SetCursor message if we need to make a change. | 546 // Only send a SetCursor message if we need to make a change. |
| 618 if (!current_cursor_.IsEqual(cursor)) { | 547 if (!current_cursor_.IsEqual(cursor)) { |
| 619 current_cursor_ = cursor; | 548 current_cursor_ = cursor; |
| 620 Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); | 549 Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 | 839 |
| 911 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { | 840 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
| 912 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); | 841 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
| 913 i != plugin_window_moves_.end(); ++i) { | 842 i != plugin_window_moves_.end(); ++i) { |
| 914 if (i->window == window) { | 843 if (i->window == window) { |
| 915 plugin_window_moves_.erase(i); | 844 plugin_window_moves_.erase(i); |
| 916 break; | 845 break; |
| 917 } | 846 } |
| 918 } | 847 } |
| 919 } | 848 } |
| OLD | NEW |