| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/gfx/point.h" | 8 #include "base/gfx/point.h" |
| 9 #include "base/gfx/size.h" | 9 #include "base/gfx/size.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 using WebKit::WebSize; | 43 using WebKit::WebSize; |
| 44 using WebKit::WebTextDirection; | 44 using WebKit::WebTextDirection; |
| 45 | 45 |
| 46 RenderWidget::RenderWidget(RenderThreadBase* render_thread, bool activatable) | 46 RenderWidget::RenderWidget(RenderThreadBase* render_thread, bool activatable) |
| 47 : routing_id_(MSG_ROUTING_NONE), | 47 : routing_id_(MSG_ROUTING_NONE), |
| 48 webwidget_(NULL), | 48 webwidget_(NULL), |
| 49 opener_id_(MSG_ROUTING_NONE), | 49 opener_id_(MSG_ROUTING_NONE), |
| 50 render_thread_(render_thread), | 50 render_thread_(render_thread), |
| 51 host_window_(0), | 51 host_window_(0), |
| 52 current_paint_buf_(NULL), | 52 current_paint_buf_(NULL), |
| 53 current_scroll_buf_(NULL), |
| 53 next_paint_flags_(0), | 54 next_paint_flags_(0), |
| 54 update_reply_pending_(false), | 55 paint_reply_pending_(false), |
| 55 did_show_(false), | 56 did_show_(false), |
| 56 is_hidden_(false), | 57 is_hidden_(false), |
| 57 needs_repainting_on_restore_(false), | 58 needs_repainting_on_restore_(false), |
| 58 has_focus_(false), | 59 has_focus_(false), |
| 59 handling_input_event_(false), | 60 handling_input_event_(false), |
| 60 closing_(false), | 61 closing_(false), |
| 61 ime_is_active_(false), | 62 ime_is_active_(false), |
| 62 ime_control_enable_ime_(true), | 63 ime_control_enable_ime_(true), |
| 63 ime_control_x_(-1), | 64 ime_control_x_(-1), |
| 64 ime_control_y_(-1), | 65 ime_control_y_(-1), |
| 65 ime_control_new_state_(false), | 66 ime_control_new_state_(false), |
| 66 ime_control_updated_(false), | 67 ime_control_updated_(false), |
| 67 ime_control_busy_(false), | 68 ime_control_busy_(false), |
| 68 activatable_(activatable), | 69 activatable_(activatable), |
| 69 pending_window_rect_count_(0), | 70 pending_window_rect_count_(0), |
| 70 suppress_next_char_events_(false) { | 71 suppress_next_char_events_(false) { |
| 71 RenderProcess::current()->AddRefProcess(); | 72 RenderProcess::current()->AddRefProcess(); |
| 72 DCHECK(render_thread_); | 73 DCHECK(render_thread_); |
| 73 } | 74 } |
| 74 | 75 |
| 75 RenderWidget::~RenderWidget() { | 76 RenderWidget::~RenderWidget() { |
| 76 DCHECK(!webwidget_) << "Leaking our WebWidget!"; | 77 DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
| 77 if (current_paint_buf_) { | 78 if (current_paint_buf_) { |
| 78 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); | 79 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 79 current_paint_buf_ = NULL; | 80 current_paint_buf_ = NULL; |
| 80 } | 81 } |
| 82 if (current_scroll_buf_) { |
| 83 RenderProcess::current()->ReleaseTransportDIB(current_scroll_buf_); |
| 84 current_scroll_buf_ = NULL; |
| 85 } |
| 81 RenderProcess::current()->ReleaseProcess(); | 86 RenderProcess::current()->ReleaseProcess(); |
| 82 } | 87 } |
| 83 | 88 |
| 84 /*static*/ | 89 /*static*/ |
| 85 RenderWidget* RenderWidget::Create(int32 opener_id, | 90 RenderWidget* RenderWidget::Create(int32 opener_id, |
| 86 RenderThreadBase* render_thread, | 91 RenderThreadBase* render_thread, |
| 87 bool activatable) { | 92 bool activatable) { |
| 88 DCHECK(opener_id != MSG_ROUTING_NONE); | 93 DCHECK(opener_id != MSG_ROUTING_NONE); |
| 89 scoped_refptr<RenderWidget> widget = new RenderWidget(render_thread, | 94 scoped_refptr<RenderWidget> widget = new RenderWidget(render_thread, |
| 90 activatable); | 95 activatable); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 135 |
| 131 Send(new ViewHostMsg_RenderViewReady(routing_id_)); | 136 Send(new ViewHostMsg_RenderViewReady(routing_id_)); |
| 132 } | 137 } |
| 133 | 138 |
| 134 IPC_DEFINE_MESSAGE_MAP(RenderWidget) | 139 IPC_DEFINE_MESSAGE_MAP(RenderWidget) |
| 135 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) | 140 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
| 136 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) | 141 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) |
| 137 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) | 142 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) |
| 138 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) | 143 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
| 139 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored) | 144 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored) |
| 140 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck) | 145 IPC_MESSAGE_HANDLER(ViewMsg_PaintRect_ACK, OnPaintRectAck) |
| 146 IPC_MESSAGE_HANDLER(ViewMsg_ScrollRect_ACK, OnScrollRectAck) |
| 141 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) | 147 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) |
| 142 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) | 148 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) |
| 143 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) | 149 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) |
| 144 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetInputMode, OnImeSetInputMode) | 150 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetInputMode, OnImeSetInputMode) |
| 145 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) | 151 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) |
| 146 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) | 152 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) |
| 147 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) | 153 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
| 148 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) | 154 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
| 149 IPC_MESSAGE_UNHANDLED_ERROR() | 155 IPC_MESSAGE_UNHANDLED_ERROR() |
| 150 IPC_END_MESSAGE_MAP() | 156 IPC_END_MESSAGE_MAP() |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 needs_repainting_on_restore_ = false; | 251 needs_repainting_on_restore_ = false; |
| 246 | 252 |
| 247 // Tag the next paint as a restore ack, which is picked up by DoDeferredUpdate | 253 // Tag the next paint as a restore ack, which is picked up by DoDeferredUpdate |
| 248 // when it sends out the next PaintRect message. | 254 // when it sends out the next PaintRect message. |
| 249 set_next_paint_is_restore_ack(); | 255 set_next_paint_is_restore_ack(); |
| 250 | 256 |
| 251 // Generate a full repaint. | 257 // Generate a full repaint. |
| 252 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); | 258 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
| 253 } | 259 } |
| 254 | 260 |
| 255 void RenderWidget::OnRequestMoveAck() { | 261 void RenderWidget::OnPaintRectAck() { |
| 256 DCHECK(pending_window_rect_count_); | 262 DCHECK(paint_reply_pending()); |
| 257 pending_window_rect_count_--; | 263 paint_reply_pending_ = false; |
| 258 } | 264 // If we sent a PaintRect message with a zero-sized bitmap, then |
| 259 | 265 // we should have no current paint buf. |
| 260 void RenderWidget::OnUpdateRectAck() { | |
| 261 DCHECK(update_reply_pending()); | |
| 262 update_reply_pending_ = false; | |
| 263 | |
| 264 // If we sent an UpdateRect message with a zero-sized bitmap, then we should | |
| 265 // have no current update buf. | |
| 266 if (current_paint_buf_) { | 266 if (current_paint_buf_) { |
| 267 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); | 267 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 268 current_paint_buf_ = NULL; | 268 current_paint_buf_ = NULL; |
| 269 } | 269 } |
| 270 | 270 |
| 271 // Notify subclasses | 271 // Notify subclasses |
| 272 DidPaint(); | 272 DidPaint(); |
| 273 | 273 |
| 274 // Continue painting if necessary... | 274 // Continue painting if necessary... |
| 275 CallDoDeferredUpdate(); | 275 CallDoDeferredUpdate(); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void RenderWidget::OnRequestMoveAck() { |
| 279 DCHECK(pending_window_rect_count_); |
| 280 pending_window_rect_count_--; |
| 281 } |
| 282 |
| 283 void RenderWidget::OnScrollRectAck() { |
| 284 DCHECK(scroll_reply_pending()); |
| 285 |
| 286 if (current_scroll_buf_) { |
| 287 RenderProcess::current()->ReleaseTransportDIB(current_scroll_buf_); |
| 288 current_scroll_buf_ = NULL; |
| 289 } |
| 290 |
| 291 // Continue scrolling if necessary... |
| 292 CallDoDeferredUpdate(); |
| 293 } |
| 294 |
| 278 void RenderWidget::OnHandleInputEvent(const IPC::Message& message) { | 295 void RenderWidget::OnHandleInputEvent(const IPC::Message& message) { |
| 279 void* iter = NULL; | 296 void* iter = NULL; |
| 280 | 297 |
| 281 const char* data; | 298 const char* data; |
| 282 int data_length; | 299 int data_length; |
| 283 handling_input_event_ = true; | 300 handling_input_event_ = true; |
| 284 if (!message.ReadData(&iter, &data, &data_length)) { | 301 if (!message.ReadData(&iter, &data, &data_length)) { |
| 285 handling_input_event_ = false; | 302 handling_input_event_ = false; |
| 286 return; | 303 return; |
| 287 } | 304 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 canvas->restore(); | 398 canvas->restore(); |
| 382 } | 399 } |
| 383 | 400 |
| 384 void RenderWidget::PaintDebugBorder(const gfx::Rect& rect, | 401 void RenderWidget::PaintDebugBorder(const gfx::Rect& rect, |
| 385 skia::PlatformCanvas* canvas) { | 402 skia::PlatformCanvas* canvas) { |
| 386 static bool kPaintBorder = | 403 static bool kPaintBorder = |
| 387 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects); | 404 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects); |
| 388 if (!kPaintBorder) | 405 if (!kPaintBorder) |
| 389 return; | 406 return; |
| 390 | 407 |
| 391 // Cycle through these colors to help distinguish new paint rects. | |
| 392 const SkColor colors[] = { | |
| 393 SkColorSetARGB(0x3F, 0xFF, 0, 0), | |
| 394 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF), | |
| 395 SkColorSetARGB(0x3F, 0, 0, 0xFF), | |
| 396 }; | |
| 397 static int color_selector = 0; | |
| 398 | |
| 399 SkPaint paint; | 408 SkPaint paint; |
| 400 paint.setStyle(SkPaint::kStroke_Style); | 409 paint.setStyle(SkPaint::kStroke_Style); |
| 401 paint.setColor(colors[color_selector++ % arraysize(colors)]); | 410 paint.setColor(SkColorSetARGB(0x3F, 0xFF, 0, 0)); |
| 402 paint.setStrokeWidth(1); | 411 paint.setStrokeWidth(1); |
| 403 | 412 |
| 404 SkIRect irect; | 413 SkIRect irect; |
| 405 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1); | 414 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1); |
| 406 canvas->drawIRect(irect, paint); | 415 canvas->drawIRect(irect, paint); |
| 407 } | 416 } |
| 408 | 417 |
| 409 void RenderWidget::CallDoDeferredUpdate() { | 418 void RenderWidget::CallDoDeferredUpdate() { |
| 410 DoDeferredUpdate(); | 419 DoDeferredUpdate(); |
| 411 | 420 |
| 412 if (pending_input_event_ack_.get()) { | 421 if (pending_input_event_ack_.get()) { |
| 413 Send(pending_input_event_ack_.get()); | 422 Send(pending_input_event_ack_.get()); |
| 414 pending_input_event_ack_.release(); | 423 pending_input_event_ack_.release(); |
| 415 } | 424 } |
| 416 } | 425 } |
| 417 | 426 |
| 418 void RenderWidget::DoDeferredUpdate() { | 427 void RenderWidget::DoDeferredUpdate() { |
| 419 if (!webwidget_ || !paint_aggregator_.HasPendingUpdate() || | 428 if (!webwidget_ || !paint_aggregator_.HasPendingUpdate() || |
| 420 update_reply_pending()) | 429 paint_reply_pending() || scroll_reply_pending()) |
| 421 return; | 430 return; |
| 422 | 431 |
| 423 // Suppress updating when we are hidden. | 432 // Suppress updating when we are hidden. |
| 424 if (is_hidden_ || size_.IsEmpty()) { | 433 if (is_hidden_ || size_.IsEmpty()) { |
| 425 paint_aggregator_.ClearPendingUpdate(); | 434 paint_aggregator_.ClearPendingUpdate(); |
| 426 needs_repainting_on_restore_ = true; | 435 needs_repainting_on_restore_ = true; |
| 427 return; | 436 return; |
| 428 } | 437 } |
| 429 | 438 |
| 430 // Layout may generate more invalidation. | 439 // Layout may generate more invalidation. |
| 431 webwidget_->layout(); | 440 webwidget_->layout(); |
| 432 | 441 |
| 433 // OK, save the pending update to a local since painting may cause more | 442 // OK, save the pending update to a local since painting may cause more |
| 434 // invalidation. Some WebCore rendering objects only layout when painted. | 443 // invalidation. Some WebCore rendering objects only layout when painted. |
| 435 PaintAggregator::PendingUpdate update = paint_aggregator_.GetPendingUpdate(); | 444 PaintAggregator::PendingUpdate update = paint_aggregator_.GetPendingUpdate(); |
| 436 paint_aggregator_.ClearPendingUpdate(); | 445 paint_aggregator_.ClearPendingUpdate(); |
| 437 | 446 |
| 438 gfx::Rect scroll_damage = update.GetScrollDamage(); | 447 if (!update.scroll_rect.IsEmpty()) { |
| 439 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage); | 448 // Optmized scrolling |
| 440 | 449 |
| 441 // Compute a buffer for painting and cache it. | 450 // Compute the region we will expose by scrolling, and paint that into a |
| 442 scoped_ptr<skia::PlatformCanvas> canvas( | 451 // shared memory section. |
| 443 RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, bounds)); | 452 gfx::Rect damaged_rect = update.GetScrollDamage(); |
| 444 if (!canvas.get()) { | 453 |
| 445 NOTREACHED(); | 454 scoped_ptr<skia::PlatformCanvas> canvas( |
| 446 return; | 455 RenderProcess::current()->GetDrawingCanvas(¤t_scroll_buf_, |
| 456 damaged_rect)); |
| 457 if (!canvas.get()) { |
| 458 NOTREACHED(); |
| 459 return; |
| 460 } |
| 461 |
| 462 // We may get back a smaller canvas than we asked for. |
| 463 damaged_rect.set_width(canvas->getDevice()->width()); |
| 464 damaged_rect.set_height(canvas->getDevice()->height()); |
| 465 |
| 466 // Set these parameters before calling Paint, since that could result in |
| 467 // further invalidates (uncommon). |
| 468 ViewHostMsg_ScrollRect_Params params; |
| 469 params.bitmap_rect = damaged_rect; |
| 470 params.dx = update.scroll_delta.x(); |
| 471 params.dy = update.scroll_delta.y(); |
| 472 params.clip_rect = update.scroll_rect; |
| 473 params.view_size = size_; |
| 474 params.plugin_window_moves = plugin_window_moves_; |
| 475 params.bitmap = current_scroll_buf_->id(); |
| 476 |
| 477 plugin_window_moves_.clear(); |
| 478 |
| 479 PaintRect(damaged_rect, damaged_rect.origin(), canvas.get()); |
| 480 Send(new ViewHostMsg_ScrollRect(routing_id_, params)); |
| 447 } | 481 } |
| 448 | 482 |
| 449 // We may get back a smaller canvas than we asked for. | 483 if (!update.paint_rects.empty()) { |
| 450 // TODO(darin): This seems like it could cause painting problems! | 484 // Normal painting |
| 451 DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); | |
| 452 DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); | |
| 453 bounds.set_width(canvas->getDevice()->width()); | |
| 454 bounds.set_height(canvas->getDevice()->height()); | |
| 455 | 485 |
| 456 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size()); | 486 gfx::Rect bounds = update.GetPaintBounds(); |
| 457 | 487 |
| 458 // The scroll damage is just another rectangle to paint and copy. | 488 // Compute a buffer for painting and cache it. |
| 459 std::vector<gfx::Rect> copy_rects; | 489 scoped_ptr<skia::PlatformCanvas> canvas( |
| 460 copy_rects.swap(update.paint_rects); | 490 RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, |
| 461 if (!scroll_damage.IsEmpty()) | 491 bounds)); |
| 462 copy_rects.push_back(scroll_damage); | 492 if (!canvas.get()) { |
| 493 NOTREACHED(); |
| 494 return; |
| 495 } |
| 463 | 496 |
| 464 // TODO(darin): Re-enable painting multiple damage rects once the | 497 // We may get back a smaller canvas than we asked for. |
| 465 // page-cycler regressions are resolved. See bug 29589. | 498 bounds.set_width(canvas->getDevice()->width()); |
| 466 if (update.scroll_rect.IsEmpty()) { | 499 bounds.set_height(canvas->getDevice()->height()); |
| 467 update.paint_rects.clear(); | 500 |
| 468 update.paint_rects.push_back(bounds); | 501 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size()); |
| 502 |
| 503 // TODO(darin): Re-enable painting multiple damage rects once the |
| 504 // page-cycler regressions are resolved. See bug 29589. |
| 505 if (update.scroll_rect.IsEmpty()) { |
| 506 update.paint_rects.clear(); |
| 507 update.paint_rects.push_back(bounds); |
| 508 } |
| 509 |
| 510 for (size_t i = 0; i < update.paint_rects.size(); ++i) |
| 511 PaintRect(update.paint_rects[i], bounds.origin(), canvas.get()); |
| 512 |
| 513 ViewHostMsg_PaintRect_Params params; |
| 514 params.bitmap_rect = bounds; |
| 515 params.update_rects = update.paint_rects; // TODO(darin): clip to bounds? |
| 516 params.view_size = size_; |
| 517 params.plugin_window_moves = plugin_window_moves_; |
| 518 params.flags = next_paint_flags_; |
| 519 params.bitmap = current_paint_buf_->id(); |
| 520 |
| 521 plugin_window_moves_.clear(); |
| 522 |
| 523 paint_reply_pending_ = true; |
| 524 Send(new ViewHostMsg_PaintRect(routing_id_, params)); |
| 525 next_paint_flags_ = 0; |
| 469 } | 526 } |
| 470 | 527 |
| 471 for (size_t i = 0; i < copy_rects.size(); ++i) | |
| 472 PaintRect(copy_rects[i], bounds.origin(), canvas.get()); | |
| 473 | |
| 474 ViewHostMsg_UpdateRect_Params params; | |
| 475 params.bitmap = current_paint_buf_->id(); | |
| 476 params.bitmap_rect = bounds; | |
| 477 params.dx = update.scroll_delta.x(); | |
| 478 params.dy = update.scroll_delta.y(); | |
| 479 params.scroll_rect = update.scroll_rect; | |
| 480 params.copy_rects.swap(copy_rects); // TODO(darin): clip to bounds? | |
| 481 params.view_size = size_; | |
| 482 params.plugin_window_moves.swap(plugin_window_moves_); | |
| 483 params.flags = next_paint_flags_; | |
| 484 | |
| 485 update_reply_pending_ = true; | |
| 486 Send(new ViewHostMsg_UpdateRect(routing_id_, params)); | |
| 487 next_paint_flags_ = 0; | |
| 488 | |
| 489 UpdateIME(); | 528 UpdateIME(); |
| 490 } | 529 } |
| 491 | 530 |
| 492 /////////////////////////////////////////////////////////////////////////////// | 531 /////////////////////////////////////////////////////////////////////////////// |
| 493 // WebWidgetDelegate | 532 // WebWidgetDelegate |
| 494 | 533 |
| 495 void RenderWidget::didInvalidateRect(const WebRect& rect) { | 534 void RenderWidget::didInvalidateRect(const WebRect& rect) { |
| 496 // We only want one pending DoDeferredUpdate call at any time... | 535 // We only want one pending DoDeferredUpdate call at any time... |
| 497 bool update_pending = paint_aggregator_.HasPendingUpdate(); | 536 bool update_pending = paint_aggregator_.HasPendingUpdate(); |
| 498 | 537 |
| 499 // The invalidated rect might be outside the bounds of the view. | 538 // The invalidated rect might be outside the bounds of the view. |
| 500 gfx::Rect view_rect(0, 0, size_.width(), size_.height()); | 539 gfx::Rect view_rect(0, 0, size_.width(), size_.height()); |
| 501 gfx::Rect damaged_rect = view_rect.Intersect(rect); | 540 gfx::Rect damaged_rect = view_rect.Intersect(rect); |
| 502 if (damaged_rect.IsEmpty()) | 541 if (damaged_rect.IsEmpty()) |
| 503 return; | 542 return; |
| 504 | 543 |
| 505 paint_aggregator_.InvalidateRect(damaged_rect); | 544 paint_aggregator_.InvalidateRect(damaged_rect); |
| 506 | 545 |
| 507 // We may not need to schedule another call to DoDeferredUpdate. | 546 // We may not need to schedule another call to DoDeferredUpdate. |
| 508 if (update_pending) | 547 if (update_pending) |
| 509 return; | 548 return; |
| 510 if (!paint_aggregator_.HasPendingUpdate()) | 549 if (!paint_aggregator_.HasPendingUpdate()) |
| 511 return; | 550 return; |
| 512 if (update_reply_pending()) | 551 if (paint_reply_pending() || scroll_reply_pending()) |
| 513 return; | 552 return; |
| 514 | 553 |
| 515 // Perform updating asynchronously. This serves two purposes: | 554 // Perform updating asynchronously. This serves two purposes: |
| 516 // 1) Ensures that we call WebView::Paint without a bunch of other junk | 555 // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 517 // on the call stack. | 556 // on the call stack. |
| 518 // 2) Allows us to collect more damage rects before painting to help coalesce | 557 // 2) Allows us to collect more damage rects before painting to help coalesce |
| 519 // the work that we will need to do. | 558 // the work that we will need to do. |
| 520 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 559 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 521 this, &RenderWidget::CallDoDeferredUpdate)); | 560 this, &RenderWidget::CallDoDeferredUpdate)); |
| 522 } | 561 } |
| 523 | 562 |
| 524 void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { | 563 void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { |
| 525 // We only want one pending DoDeferredUpdate call at any time... | 564 // We only want one pending DoDeferredUpdate call at any time... |
| 526 bool update_pending = paint_aggregator_.HasPendingUpdate(); | 565 bool update_pending = paint_aggregator_.HasPendingUpdate(); |
| 527 | 566 |
| 528 // The scrolled rect might be outside the bounds of the view. | 567 // The scrolled rect might be outside the bounds of the view. |
| 529 gfx::Rect view_rect(0, 0, size_.width(), size_.height()); | 568 gfx::Rect view_rect(0, 0, size_.width(), size_.height()); |
| 530 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect); | 569 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect); |
| 531 if (damaged_rect.IsEmpty()) | 570 if (damaged_rect.IsEmpty()) |
| 532 return; | 571 return; |
| 533 | 572 |
| 534 paint_aggregator_.ScrollRect(dx, dy, damaged_rect); | 573 paint_aggregator_.ScrollRect(dx, dy, damaged_rect); |
| 535 | 574 |
| 536 // We may not need to schedule another call to DoDeferredUpdate. | 575 // We may not need to schedule another call to DoDeferredUpdate. |
| 537 if (update_pending) | 576 if (update_pending) |
| 538 return; | 577 return; |
| 539 if (!paint_aggregator_.HasPendingUpdate()) | 578 if (!paint_aggregator_.HasPendingUpdate()) |
| 540 return; | 579 return; |
| 541 if (update_reply_pending()) | 580 if (paint_reply_pending() || scroll_reply_pending()) |
| 542 return; | 581 return; |
| 543 | 582 |
| 544 // Perform updating asynchronously. This serves two purposes: | 583 // Perform updating asynchronously. This serves two purposes: |
| 545 // 1) Ensures that we call WebView::Paint without a bunch of other junk | 584 // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 546 // on the call stack. | 585 // on the call stack. |
| 547 // 2) Allows us to collect more damage rects before painting to help coalesce | 586 // 2) Allows us to collect more damage rects before painting to help coalesce |
| 548 // the work that we will need to do. | 587 // the work that we will need to do. |
| 549 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 588 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 550 this, &RenderWidget::CallDoDeferredUpdate)); | 589 this, &RenderWidget::CallDoDeferredUpdate)); |
| 551 } | 590 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 render_thread_->WidgetRestored(); | 766 render_thread_->WidgetRestored(); |
| 728 } | 767 } |
| 729 | 768 |
| 730 void RenderWidget::SetBackground(const SkBitmap& background) { | 769 void RenderWidget::SetBackground(const SkBitmap& background) { |
| 731 background_ = background; | 770 background_ = background; |
| 732 // Generate a full repaint. | 771 // Generate a full repaint. |
| 733 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); | 772 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
| 734 } | 773 } |
| 735 | 774 |
| 736 bool RenderWidget::next_paint_is_resize_ack() const { | 775 bool RenderWidget::next_paint_is_resize_ack() const { |
| 737 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_); | 776 return ViewHostMsg_PaintRect_Flags::is_resize_ack(next_paint_flags_); |
| 738 } | 777 } |
| 739 | 778 |
| 740 bool RenderWidget::next_paint_is_restore_ack() const { | 779 bool RenderWidget::next_paint_is_restore_ack() const { |
| 741 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_); | 780 return ViewHostMsg_PaintRect_Flags::is_restore_ack(next_paint_flags_); |
| 742 } | 781 } |
| 743 | 782 |
| 744 void RenderWidget::set_next_paint_is_resize_ack() { | 783 void RenderWidget::set_next_paint_is_resize_ack() { |
| 745 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; | 784 next_paint_flags_ |= ViewHostMsg_PaintRect_Flags::IS_RESIZE_ACK; |
| 746 } | 785 } |
| 747 | 786 |
| 748 void RenderWidget::set_next_paint_is_restore_ack() { | 787 void RenderWidget::set_next_paint_is_restore_ack() { |
| 749 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK; | 788 next_paint_flags_ |= ViewHostMsg_PaintRect_Flags::IS_RESTORE_ACK; |
| 750 } | 789 } |
| 751 | 790 |
| 752 void RenderWidget::set_next_paint_is_repaint_ack() { | 791 void RenderWidget::set_next_paint_is_repaint_ack() { |
| 753 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; | 792 next_paint_flags_ |= ViewHostMsg_PaintRect_Flags::IS_REPAINT_ACK; |
| 754 } | 793 } |
| 755 | 794 |
| 756 void RenderWidget::UpdateIME() { | 795 void RenderWidget::UpdateIME() { |
| 757 // If a browser process does not have IMEs, its IMEs are not active, or there | 796 // If a browser process does not have IMEs, its IMEs are not active, or there |
| 758 // are not any attached widgets. | 797 // are not any attached widgets. |
| 759 // a renderer process does not have to retrieve information of the focused | 798 // a renderer process does not have to retrieve information of the focused |
| 760 // control or send notification messages to a browser process. | 799 // control or send notification messages to a browser process. |
| 761 if (!ime_is_active_) { | 800 if (!ime_is_active_) { |
| 762 return; | 801 return; |
| 763 } | 802 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 | 889 |
| 851 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { | 890 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
| 852 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); | 891 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
| 853 i != plugin_window_moves_.end(); ++i) { | 892 i != plugin_window_moves_.end(); ++i) { |
| 854 if (i->window == window) { | 893 if (i->window == window) { |
| 855 plugin_window_moves_.erase(i); | 894 plugin_window_moves_.erase(i); |
| 856 break; | 895 break; |
| 857 } | 896 } |
| 858 } | 897 } |
| 859 } | 898 } |
| OLD | NEW |