Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: chrome/renderer/render_widget.cc

Issue 149620: Use WebWidget from the WebKit API. This change also makes... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/render_widget.h ('k') | webkit/api/public/WebCompositionCommand.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "chrome/common/transport_dib.h" 14 #include "chrome/common/transport_dib.h"
15 #include "chrome/renderer/render_process.h" 15 #include "chrome/renderer/render_process.h"
16 #include "skia/ext/platform_canvas.h" 16 #include "skia/ext/platform_canvas.h"
17 #include "third_party/skia/include/core/SkShader.h" 17 #include "third_party/skia/include/core/SkShader.h"
18 #include "webkit/api/public/WebCursorInfo.h" 18 #include "webkit/api/public/WebCursorInfo.h"
19 #include "webkit/api/public/WebPopupMenu.h"
19 #include "webkit/api/public/WebPopupMenuInfo.h" 20 #include "webkit/api/public/WebPopupMenuInfo.h"
20 #include "webkit/api/public/WebRect.h" 21 #include "webkit/api/public/WebRect.h"
21 #include "webkit/api/public/WebScreenInfo.h" 22 #include "webkit/api/public/WebScreenInfo.h"
22 #include "webkit/api/public/WebSize.h" 23 #include "webkit/api/public/WebSize.h"
23 24
24 #if defined(OS_POSIX) 25 #if defined(OS_POSIX)
25 #include "third_party/skia/include/core/SkPixelRef.h" 26 #include "third_party/skia/include/core/SkPixelRef.h"
26 #include "third_party/skia/include/core/SkMallocPixelRef.h" 27 #include "third_party/skia/include/core/SkMallocPixelRef.h"
27 #endif // defined(OS_POSIX) 28 #endif // defined(OS_POSIX)
28 29
29 #include "webkit/glue/webtextdirection.h" 30 #include "webkit/api/public/WebWidget.h"
30 #include "webkit/glue/webwidget.h"
31 31
32 using WebKit::WebCompositionCommand;
32 using WebKit::WebCursorInfo; 33 using WebKit::WebCursorInfo;
33 using WebKit::WebInputEvent; 34 using WebKit::WebInputEvent;
35 using WebKit::WebNavigationPolicy;
36 using WebKit::WebPopupMenu;
34 using WebKit::WebPopupMenuInfo; 37 using WebKit::WebPopupMenuInfo;
35 using WebKit::WebRect; 38 using WebKit::WebRect;
36 using WebKit::WebScreenInfo; 39 using WebKit::WebScreenInfo;
37 using WebKit::WebSize; 40 using WebKit::WebSize;
41 using WebKit::WebTextDirection;
38 42
39 RenderWidget::RenderWidget(RenderThreadBase* render_thread, bool activatable) 43 RenderWidget::RenderWidget(RenderThreadBase* render_thread, bool activatable)
40 : routing_id_(MSG_ROUTING_NONE), 44 : routing_id_(MSG_ROUTING_NONE),
41 webwidget_(NULL), 45 webwidget_(NULL),
42 opener_id_(MSG_ROUTING_NONE), 46 opener_id_(MSG_ROUTING_NONE),
43 render_thread_(render_thread), 47 render_thread_(render_thread),
44 host_window_(NULL), 48 host_window_(NULL),
45 current_paint_buf_(NULL), 49 current_paint_buf_(NULL),
46 current_scroll_buf_(NULL), 50 current_scroll_buf_(NULL),
47 next_paint_flags_(0), 51 next_paint_flags_(0),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 for (size_t i = 0; i < info.items.size(); ++i) 99 for (size_t i = 0; i < info.items.size(); ++i)
96 popup_params_->popup_items.push_back(WebMenuItem(info.items[i])); 100 popup_params_->popup_items.push_back(WebMenuItem(info.items[i]));
97 } 101 }
98 102
99 void RenderWidget::Init(int32 opener_id) { 103 void RenderWidget::Init(int32 opener_id) {
100 DCHECK(!webwidget_); 104 DCHECK(!webwidget_);
101 105
102 if (opener_id != MSG_ROUTING_NONE) 106 if (opener_id != MSG_ROUTING_NONE)
103 opener_id_ = opener_id; 107 opener_id_ = opener_id;
104 108
105 webwidget_ = WebWidget::Create(this); 109 webwidget_ = WebPopupMenu::create(this);
106 110
107 bool result = render_thread_->Send( 111 bool result = render_thread_->Send(
108 new ViewHostMsg_CreateWidget(opener_id, activatable_, &routing_id_)); 112 new ViewHostMsg_CreateWidget(opener_id, activatable_, &routing_id_));
109 if (result) { 113 if (result) {
110 render_thread_->AddRoute(routing_id_, this); 114 render_thread_->AddRoute(routing_id_, this);
111 // Take a reference on behalf of the RenderThread. This will be balanced 115 // Take a reference on behalf of the RenderThread. This will be balanced
112 // when we receive ViewMsg_Close. 116 // when we receive ViewMsg_Close.
113 AddRef(); 117 AddRef();
114 } else { 118 } else {
115 DCHECK(false); 119 DCHECK(false);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // We shouldn't be asked to resize to our current size. 207 // We shouldn't be asked to resize to our current size.
204 DCHECK(size_ != new_size); 208 DCHECK(size_ != new_size);
205 size_ = new_size; 209 size_ = new_size;
206 210
207 // We should not be sent a Resize message if we have not ACK'd the previous 211 // We should not be sent a Resize message if we have not ACK'd the previous
208 DCHECK(!next_paint_is_resize_ack()); 212 DCHECK(!next_paint_is_resize_ack());
209 213
210 // When resizing, we want to wait to paint before ACK'ing the resize. This 214 // When resizing, we want to wait to paint before ACK'ing the resize. This
211 // ensures that we only resize as fast as we can paint. We only need to send 215 // ensures that we only resize as fast as we can paint. We only need to send
212 // an ACK if we are resized to a non-empty rect. 216 // an ACK if we are resized to a non-empty rect.
213 webwidget_->Resize(new_size); 217 webwidget_->resize(new_size);
214 if (!new_size.IsEmpty()) { 218 if (!new_size.IsEmpty()) {
215 DCHECK(!paint_rect_.IsEmpty()); 219 DCHECK(!paint_rect_.IsEmpty());
216 220
217 // This should have caused an invalidation of the entire view. The damaged 221 // This should have caused an invalidation of the entire view. The damaged
218 // rect could be larger than new_size if we are being made smaller. 222 // rect could be larger than new_size if we are being made smaller.
219 DCHECK_GE(paint_rect_.width(), new_size.width()); 223 DCHECK_GE(paint_rect_.width(), new_size.width());
220 DCHECK_GE(paint_rect_.height(), new_size.height()); 224 DCHECK_GE(paint_rect_.height(), new_size.height());
221 225
222 // We will send the Resize_ACK flag once we paint again. 226 // We will send the Resize_ACK flag once we paint again.
223 set_next_paint_is_resize_ack(); 227 set_next_paint_is_resize_ack();
(...skipping 15 matching lines...) Expand all
239 243
240 if (!needs_repainting && !needs_repainting_on_restore_) 244 if (!needs_repainting && !needs_repainting_on_restore_)
241 return; 245 return;
242 needs_repainting_on_restore_ = false; 246 needs_repainting_on_restore_ = false;
243 247
244 // Tag the next paint as a restore ack, which is picked up by DoDeferredPaint 248 // Tag the next paint as a restore ack, which is picked up by DoDeferredPaint
245 // when it sends out the next PaintRect message. 249 // when it sends out the next PaintRect message.
246 set_next_paint_is_restore_ack(); 250 set_next_paint_is_restore_ack();
247 251
248 // Generate a full repaint. 252 // Generate a full repaint.
249 DidInvalidateRect(webwidget_, gfx::Rect(size_.width(), size_.height())); 253 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
250 } 254 }
251 255
252 void RenderWidget::OnPaintRectAck() { 256 void RenderWidget::OnPaintRectAck() {
253 DCHECK(paint_reply_pending()); 257 DCHECK(paint_reply_pending());
254 paint_reply_pending_ = false; 258 paint_reply_pending_ = false;
255 // If we sent a PaintRect message with a zero-sized bitmap, then 259 // If we sent a PaintRect message with a zero-sized bitmap, then
256 // we should have no current paint buf. 260 // we should have no current paint buf.
257 if (current_paint_buf_) { 261 if (current_paint_buf_) {
258 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); 262 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
259 current_paint_buf_ = NULL; 263 current_paint_buf_ = NULL;
(...skipping 28 matching lines...) Expand all
288 292
289 const char* data; 293 const char* data;
290 int data_length; 294 int data_length;
291 if (!message.ReadData(&iter, &data, &data_length)) 295 if (!message.ReadData(&iter, &data, &data_length))
292 return; 296 return;
293 297
294 const WebInputEvent* input_event = 298 const WebInputEvent* input_event =
295 reinterpret_cast<const WebInputEvent*>(data); 299 reinterpret_cast<const WebInputEvent*>(data);
296 bool processed = false; 300 bool processed = false;
297 if (webwidget_) 301 if (webwidget_)
298 processed = webwidget_->HandleInputEvent(input_event); 302 processed = webwidget_->handleInputEvent(*input_event);
299 303
300 IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_); 304 IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_);
301 response->WriteInt(input_event->type); 305 response->WriteInt(input_event->type);
302 response->WriteBool(processed); 306 response->WriteBool(processed);
303 307
304 Send(response); 308 Send(response);
305 } 309 }
306 310
307 void RenderWidget::OnMouseCaptureLost() { 311 void RenderWidget::OnMouseCaptureLost() {
308 if (webwidget_) 312 if (webwidget_)
309 webwidget_->MouseCaptureLost(); 313 webwidget_->mouseCaptureLost();
310 } 314 }
311 315
312 void RenderWidget::OnSetFocus(bool enable) { 316 void RenderWidget::OnSetFocus(bool enable) {
313 has_focus_ = enable; 317 has_focus_ = enable;
314 if (webwidget_) 318 if (webwidget_)
315 webwidget_->SetFocus(enable); 319 webwidget_->setFocus(enable);
316 if (enable) { 320 if (enable) {
317 // Force to retrieve the state of the focused widget to determine if we 321 // Force to retrieve the state of the focused widget to determine if we
318 // should activate IMEs next time when this process calls the UpdateIME() 322 // should activate IMEs next time when this process calls the UpdateIME()
319 // function. 323 // function.
320 ime_control_updated_ = true; 324 ime_control_updated_ = true;
321 ime_control_new_state_ = true; 325 ime_control_new_state_ = true;
322 } 326 }
323 } 327 }
324 328
325 void RenderWidget::ClearFocus() { 329 void RenderWidget::ClearFocus() {
326 // We may have got the focus from the browser before this gets processed, in 330 // We may have got the focus from the browser before this gets processed, in
327 // which case we do not want to unfocus ourself. 331 // which case we do not want to unfocus ourself.
328 if (!has_focus_ && webwidget_) 332 if (!has_focus_ && webwidget_)
329 webwidget_->SetFocus(false); 333 webwidget_->setFocus(false);
330 } 334 }
331 335
332 void RenderWidget::PaintRect(const gfx::Rect& rect, 336 void RenderWidget::PaintRect(const gfx::Rect& rect,
333 skia::PlatformCanvas* canvas) { 337 skia::PlatformCanvas* canvas) {
334 338
335 // Bring the canvas into the coordinate system of the paint rect. 339 // Bring the canvas into the coordinate system of the paint rect.
336 canvas->translate(static_cast<SkScalar>(-rect.x()), 340 canvas->translate(static_cast<SkScalar>(-rect.x()),
337 static_cast<SkScalar>(-rect.y())); 341 static_cast<SkScalar>(-rect.y()));
338 342
339 // If there is a custom background, tile it. 343 // If there is a custom background, tile it.
340 if (!background_.empty()) { 344 if (!background_.empty()) {
341 SkPaint paint; 345 SkPaint paint;
342 SkShader* shader = SkShader::CreateBitmapShader(background_, 346 SkShader* shader = SkShader::CreateBitmapShader(background_,
343 SkShader::kRepeat_TileMode, 347 SkShader::kRepeat_TileMode,
344 SkShader::kRepeat_TileMode); 348 SkShader::kRepeat_TileMode);
345 paint.setShader(shader)->unref(); 349 paint.setShader(shader)->unref();
346 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); 350 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
347 canvas->drawPaint(paint); 351 canvas->drawPaint(paint);
348 } 352 }
349 353
350 webwidget_->Paint(canvas, rect); 354 webwidget_->paint(canvas, rect);
351 355
352 // Flush to underlying bitmap. TODO(darin): is this needed? 356 // Flush to underlying bitmap. TODO(darin): is this needed?
353 canvas->getTopPlatformDevice().accessBitmap(false); 357 canvas->getTopPlatformDevice().accessBitmap(false);
354 } 358 }
355 359
356 void RenderWidget::DoDeferredPaint() { 360 void RenderWidget::DoDeferredPaint() {
357 if (!webwidget_ || paint_reply_pending() || paint_rect_.IsEmpty()) 361 if (!webwidget_ || paint_reply_pending() || paint_rect_.IsEmpty())
358 return; 362 return;
359 363
360 // When we are hidden, we want to suppress painting, but we still need to 364 // When we are hidden, we want to suppress painting, but we still need to
361 // mark this DoDeferredPaint as complete. 365 // mark this DoDeferredPaint as complete.
362 if (is_hidden_ || size_.IsEmpty()) { 366 if (is_hidden_ || size_.IsEmpty()) {
363 paint_rect_ = gfx::Rect(); 367 paint_rect_ = gfx::Rect();
364 needs_repainting_on_restore_ = true; 368 needs_repainting_on_restore_ = true;
365 return; 369 return;
366 } 370 }
367 371
368 // Layout may generate more invalidation... 372 // Layout may generate more invalidation...
369 webwidget_->Layout(); 373 webwidget_->layout();
370 374
371 // OK, save the current paint_rect to a local since painting may cause more 375 // OK, save the current paint_rect to a local since painting may cause more
372 // invalidation. Some WebCore rendering objects only layout when painted. 376 // invalidation. Some WebCore rendering objects only layout when painted.
373 gfx::Rect damaged_rect = paint_rect_; 377 gfx::Rect damaged_rect = paint_rect_;
374 paint_rect_ = gfx::Rect(); 378 paint_rect_ = gfx::Rect();
375 379
376 // Compute a buffer for painting and cache it. 380 // Compute a buffer for painting and cache it.
377 skia::PlatformCanvas* canvas = 381 skia::PlatformCanvas* canvas =
378 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_, 382 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
379 damaged_rect); 383 damaged_rect);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // When we are hidden, we want to suppress scrolling, but we still need to 417 // When we are hidden, we want to suppress scrolling, but we still need to
414 // mark this DoDeferredScroll as complete. 418 // mark this DoDeferredScroll as complete.
415 if (is_hidden_ || size_.IsEmpty()) { 419 if (is_hidden_ || size_.IsEmpty()) {
416 scroll_rect_ = gfx::Rect(); 420 scroll_rect_ = gfx::Rect();
417 needs_repainting_on_restore_ = true; 421 needs_repainting_on_restore_ = true;
418 return; 422 return;
419 } 423 }
420 424
421 // Layout may generate more invalidation, so we might have to bail on 425 // Layout may generate more invalidation, so we might have to bail on
422 // optimized scrolling... 426 // optimized scrolling...
423 webwidget_->Layout(); 427 webwidget_->layout();
424 428
425 if (scroll_rect_.IsEmpty()) 429 if (scroll_rect_.IsEmpty())
426 return; 430 return;
427 431
428 gfx::Rect damaged_rect; 432 gfx::Rect damaged_rect;
429 433
430 // Compute the region we will expose by scrolling, and paint that into a 434 // Compute the region we will expose by scrolling, and paint that into a
431 // shared memory section. 435 // shared memory section.
432 if (scroll_delta_.x()) { 436 if (scroll_delta_.x()) {
433 int dx = scroll_delta_.x(); 437 int dx = scroll_delta_.x();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 490
487 PaintRect(damaged_rect, canvas); 491 PaintRect(damaged_rect, canvas);
488 Send(new ViewHostMsg_ScrollRect(routing_id_, params)); 492 Send(new ViewHostMsg_ScrollRect(routing_id_, params));
489 delete canvas; 493 delete canvas;
490 UpdateIME(); 494 UpdateIME();
491 } 495 }
492 496
493 /////////////////////////////////////////////////////////////////////////////// 497 ///////////////////////////////////////////////////////////////////////////////
494 // WebWidgetDelegate 498 // WebWidgetDelegate
495 499
496 void RenderWidget::DidInvalidateRect(WebWidget* webwidget, 500 void RenderWidget::didInvalidateRect(const WebRect& rect) {
497 const WebRect& rect) {
498 // We only want one pending DoDeferredPaint call at any time... 501 // We only want one pending DoDeferredPaint call at any time...
499 bool paint_pending = !paint_rect_.IsEmpty(); 502 bool paint_pending = !paint_rect_.IsEmpty();
500 503
501 // If this invalidate overlaps with a pending scroll, then we have to 504 // If this invalidate overlaps with a pending scroll, then we have to
502 // downgrade to invalidating the scroll rect. 505 // downgrade to invalidating the scroll rect.
503 if (gfx::Rect(rect).Intersects(scroll_rect_)) { 506 if (gfx::Rect(rect).Intersects(scroll_rect_)) {
504 paint_rect_ = paint_rect_.Union(scroll_rect_); 507 paint_rect_ = paint_rect_.Union(scroll_rect_);
505 scroll_rect_ = gfx::Rect(); 508 scroll_rect_ = gfx::Rect();
506 } 509 }
507 510
(...skipping 10 matching lines...) Expand all
518 521
519 // Perform painting asynchronously. This serves two purposes: 522 // Perform painting asynchronously. This serves two purposes:
520 // 1) Ensures that we call WebView::Paint without a bunch of other junk 523 // 1) Ensures that we call WebView::Paint without a bunch of other junk
521 // on the call stack. 524 // on the call stack.
522 // 2) Allows us to collect more damage rects before painting to help coalesce 525 // 2) Allows us to collect more damage rects before painting to help coalesce
523 // the work that we will need to do. 526 // the work that we will need to do.
524 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 527 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
525 this, &RenderWidget::DoDeferredPaint)); 528 this, &RenderWidget::DoDeferredPaint));
526 } 529 }
527 530
528 void RenderWidget::DidScrollRect(WebWidget* webwidget, int dx, int dy, 531 void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
529 const WebRect& clip_rect) {
530 if (dx != 0 && dy != 0) { 532 if (dx != 0 && dy != 0) {
531 // We only support scrolling along one axis at a time. 533 // We only support scrolling along one axis at a time.
532 DidScrollRect(webwidget, 0, dy, clip_rect); 534 didScrollRect(0, dy, clip_rect);
533 dy = 0; 535 dy = 0;
534 } 536 }
535 537
536 bool intersects_with_painting = paint_rect_.Intersects(clip_rect); 538 bool intersects_with_painting = paint_rect_.Intersects(clip_rect);
537 539
538 // If we already have a pending scroll operation or if this scroll operation 540 // If we already have a pending scroll operation or if this scroll operation
539 // intersects the existing paint region, then just failover to invalidating. 541 // intersects the existing paint region, then just failover to invalidating.
540 if (!scroll_rect_.IsEmpty() || intersects_with_painting) { 542 if (!scroll_rect_.IsEmpty() || intersects_with_painting) {
541 if (!intersects_with_painting && scroll_rect_ == gfx::Rect(clip_rect)) { 543 if (!intersects_with_painting && scroll_rect_ == gfx::Rect(clip_rect)) {
542 // OK, we can just update the scroll delta (requires same scrolling axis) 544 // OK, we can just update the scroll delta (requires same scrolling axis)
543 if (!dx && !scroll_delta_.x()) { 545 if (!dx && !scroll_delta_.x()) {
544 scroll_delta_.set_y(scroll_delta_.y() + dy); 546 scroll_delta_.set_y(scroll_delta_.y() + dy);
545 return; 547 return;
546 } 548 }
547 if (!dy && !scroll_delta_.y()) { 549 if (!dy && !scroll_delta_.y()) {
548 scroll_delta_.set_x(scroll_delta_.x() + dx); 550 scroll_delta_.set_x(scroll_delta_.x() + dx);
549 return; 551 return;
550 } 552 }
551 } 553 }
552 DidInvalidateRect(webwidget_, scroll_rect_); 554 didInvalidateRect(scroll_rect_);
553 DCHECK(scroll_rect_.IsEmpty()); 555 DCHECK(scroll_rect_.IsEmpty());
554 DidInvalidateRect(webwidget_, clip_rect); 556 didInvalidateRect(clip_rect);
555 return; 557 return;
556 } 558 }
557 559
558 // We only want one pending DoDeferredScroll call at any time... 560 // We only want one pending DoDeferredScroll call at any time...
559 bool scroll_pending = !scroll_rect_.IsEmpty(); 561 bool scroll_pending = !scroll_rect_.IsEmpty();
560 562
561 scroll_rect_ = clip_rect; 563 scroll_rect_ = clip_rect;
562 scroll_delta_.SetPoint(dx, dy); 564 scroll_delta_.SetPoint(dx, dy);
563 565
564 if (scroll_pending) 566 if (scroll_pending)
565 return; 567 return;
566 568
567 // Perform scrolling asynchronously since we need to call WebView::Paint 569 // Perform scrolling asynchronously since we need to call WebView::Paint
568 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 570 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
569 this, &RenderWidget::DoDeferredScroll)); 571 this, &RenderWidget::DoDeferredScroll));
570 } 572 }
571 573
572 void RenderWidget::SetCursor(WebWidget* webwidget, 574 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
573 const WebCursorInfo& cursor_info) {
574 // TODO(darin): Eliminate this temporary. 575 // TODO(darin): Eliminate this temporary.
575 WebCursor cursor(cursor_info); 576 WebCursor cursor(cursor_info);
576 577
577 // Only send a SetCursor message if we need to make a change. 578 // Only send a SetCursor message if we need to make a change.
578 if (!current_cursor_.IsEqual(cursor)) { 579 if (!current_cursor_.IsEqual(cursor)) {
579 current_cursor_ = cursor; 580 current_cursor_ = cursor;
580 Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); 581 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
581 } 582 }
582 } 583 }
583 584
584 // We are supposed to get a single call to Show for a newly created RenderWidget 585 // We are supposed to get a single call to Show for a newly created RenderWidget
585 // that was created via RenderWidget::CreateWebView. So, we wait until this 586 // that was created via RenderWidget::CreateWebView. So, we wait until this
586 // point to dispatch the ShowWidget message. 587 // point to dispatch the ShowWidget message.
587 // 588 //
588 // This method provides us with the information about how to display the newly 589 // This method provides us with the information about how to display the newly
589 // created RenderWidget (i.e., as a constrained popup or as a new tab). 590 // created RenderWidget (i.e., as a constrained popup or as a new tab).
590 // 591 //
591 void RenderWidget::Show(WebWidget* webwidget, 592 void RenderWidget::show(WebNavigationPolicy) {
592 WindowOpenDisposition disposition) {
593 DCHECK(!did_show_) << "received extraneous Show call"; 593 DCHECK(!did_show_) << "received extraneous Show call";
594 DCHECK(routing_id_ != MSG_ROUTING_NONE); 594 DCHECK(routing_id_ != MSG_ROUTING_NONE);
595 DCHECK(opener_id_ != MSG_ROUTING_NONE); 595 DCHECK(opener_id_ != MSG_ROUTING_NONE);
596 596
597 if (!did_show_) { 597 if (!did_show_) {
598 did_show_ = true; 598 did_show_ = true;
599 // NOTE: initial_pos_ may still have its default values at this point, but 599 // NOTE: initial_pos_ may still have its default values at this point, but
600 // that's okay. It'll be ignored if as_popup is false, or the browser 600 // that's okay. It'll be ignored if as_popup is false, or the browser
601 // process will impose a default position otherwise. 601 // process will impose a default position otherwise.
602 if (popup_params_.get()) { 602 if (popup_params_.get()) {
603 popup_params_->bounds = initial_pos_; 603 popup_params_->bounds = initial_pos_;
604 Send(new ViewHostMsg_ShowPopup(routing_id_, *popup_params_)); 604 Send(new ViewHostMsg_ShowPopup(routing_id_, *popup_params_));
605 popup_params_.reset(); 605 popup_params_.reset();
606 } else { 606 } else {
607 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_)); 607 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
608 } 608 }
609 SetPendingWindowRect(initial_pos_); 609 SetPendingWindowRect(initial_pos_);
610 } 610 }
611 } 611 }
612 612
613 void RenderWidget::Focus(WebWidget* webwidget) { 613 void RenderWidget::didFocus() {
614 // Prevent the widget from stealing the focus if it does not have focus 614 // Prevent the widget from stealing the focus if it does not have focus
615 // already. We do this by explicitely setting the focus to false again. 615 // already. We do this by explicitely setting the focus to false again.
616 // We only let the browser focus the renderer. 616 // We only let the browser focus the renderer.
617 if (!has_focus_ && webwidget_) { 617 if (!has_focus_ && webwidget_) {
618 MessageLoop::current()->PostTask(FROM_HERE, 618 MessageLoop::current()->PostTask(FROM_HERE,
619 NewRunnableMethod(this, &RenderWidget::ClearFocus)); 619 NewRunnableMethod(this, &RenderWidget::ClearFocus));
620 } 620 }
621 } 621 }
622 622
623 void RenderWidget::Blur(WebWidget* webwidget) { 623 void RenderWidget::didBlur() {
624 Send(new ViewHostMsg_Blur(routing_id_)); 624 Send(new ViewHostMsg_Blur(routing_id_));
625 } 625 }
626 626
627 void RenderWidget::DoDeferredClose() { 627 void RenderWidget::DoDeferredClose() {
628 Send(new ViewHostMsg_Close(routing_id_)); 628 Send(new ViewHostMsg_Close(routing_id_));
629 } 629 }
630 630
631 void RenderWidget::CloseWidgetSoon(WebWidget* webwidget) { 631 void RenderWidget::closeWidgetSoon() {
632 // If a page calls window.close() twice, we'll end up here twice, but that's 632 // If a page calls window.close() twice, we'll end up here twice, but that's
633 // OK. It is safe to send multiple Close messages. 633 // OK. It is safe to send multiple Close messages.
634 634
635 // Ask the RenderWidgetHost to initiate close. We could be called from deep 635 // Ask the RenderWidgetHost to initiate close. We could be called from deep
636 // in Javascript. If we ask the RendwerWidgetHost to close now, the window 636 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
637 // could be closed before the JS finishes executing. So instead, post a 637 // could be closed before the JS finishes executing. So instead, post a
638 // message back to the message loop, which won't run until the JS is 638 // message back to the message loop, which won't run until the JS is
639 // complete, and then the Close message can be sent. 639 // complete, and then the Close message can be sent.
640 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 640 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
641 this, &RenderWidget::DoDeferredClose)); 641 this, &RenderWidget::DoDeferredClose));
642 } 642 }
643 643
644 void RenderWidget::GenerateFullRepaint() { 644 void RenderWidget::GenerateFullRepaint() {
645 DidInvalidateRect(webwidget_, gfx::Rect(size_.width(), size_.height())); 645 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
646 } 646 }
647 647
648 void RenderWidget::Close() { 648 void RenderWidget::Close() {
649 if (webwidget_) { 649 if (webwidget_) {
650 webwidget_->Close(); 650 webwidget_->close();
651 webwidget_ = NULL; 651 webwidget_ = NULL;
652 } 652 }
653 } 653 }
654 654
655 void RenderWidget::GetWindowRect(WebWidget* webwidget, WebRect* result) { 655 WebRect RenderWidget::windowRect() {
656 if (pending_window_rect_count_) { 656 if (pending_window_rect_count_)
657 *result = pending_window_rect_; 657 return pending_window_rect_;
658 return;
659 }
660 658
661 gfx::Rect rect; 659 gfx::Rect rect;
662 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect)); 660 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
663 *result = rect; 661 return rect;
664 } 662 }
665 663
666 void RenderWidget::SetWindowRect(WebWidget* webwidget, const WebRect& pos) { 664 void RenderWidget::setWindowRect(const WebRect& pos) {
667 if (did_show_) { 665 if (did_show_) {
668 Send(new ViewHostMsg_RequestMove(routing_id_, pos)); 666 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
669 SetPendingWindowRect(pos); 667 SetPendingWindowRect(pos);
670 } else { 668 } else {
671 initial_pos_ = pos; 669 initial_pos_ = pos;
672 } 670 }
673 } 671 }
674 672
675 void RenderWidget::SetPendingWindowRect(const WebRect& rect) { 673 void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
676 pending_window_rect_ = rect; 674 pending_window_rect_ = rect;
677 pending_window_rect_count_++; 675 pending_window_rect_count_++;
678 } 676 }
679 677
680 void RenderWidget::GetRootWindowRect(WebWidget* webwidget, WebRect* result) { 678 WebRect RenderWidget::rootWindowRect() {
681 if (pending_window_rect_count_) { 679 if (pending_window_rect_count_) {
682 // NOTE(mbelshe): If there is a pending_window_rect_, then getting 680 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
683 // the RootWindowRect is probably going to return wrong results since the 681 // the RootWindowRect is probably going to return wrong results since the
684 // browser may not have processed the Move yet. There isn't really anything 682 // browser may not have processed the Move yet. There isn't really anything
685 // good to do in this case, and it shouldn't happen - since this size is 683 // good to do in this case, and it shouldn't happen - since this size is
686 // only really needed for windowToScreen, which is only used for Popups. 684 // only really needed for windowToScreen, which is only used for Popups.
687 *result = pending_window_rect_; 685 return pending_window_rect_;
688 return;
689 } 686 }
690 687
691 gfx::Rect rect; 688 gfx::Rect rect;
692 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect)); 689 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
693 *result = rect; 690 return rect;
694 } 691 }
695 692
696 void RenderWidget::GetRootWindowResizerRect(WebWidget* webwidget, 693 WebRect RenderWidget::windowResizerRect() {
697 WebRect* rect) { 694 return resizer_rect_;
698 *rect = resizer_rect_;
699 } 695 }
700 696
701 void RenderWidget::OnImeSetInputMode(bool is_active) { 697 void RenderWidget::OnImeSetInputMode(bool is_active) {
702 // To prevent this renderer process from sending unnecessary IPC messages to 698 // To prevent this renderer process from sending unnecessary IPC messages to
703 // a browser process, we permit the renderer process to send IPC messages 699 // a browser process, we permit the renderer process to send IPC messages
704 // only during the IME attached to the browser process is active. 700 // only during the IME attached to the browser process is active.
705 ime_is_active_ = is_active; 701 ime_is_active_ = is_active;
706 } 702 }
707 703
708 void RenderWidget::OnImeSetComposition(int string_type, 704 void RenderWidget::OnImeSetComposition(WebCompositionCommand command,
709 int cursor_position, 705 int cursor_position,
710 int target_start, int target_end, 706 int target_start, int target_end,
711 const std::wstring& ime_string) { 707 const string16& ime_string) {
712 if (webwidget_) { 708 if (!webwidget_)
713 ime_control_busy_ = true; 709 return;
714 webwidget_->ImeSetComposition(string_type, cursor_position, 710 ime_control_busy_ = true;
715 target_start, target_end, 711 webwidget_->handleCompositionEvent(command, cursor_position,
716 ime_string); 712 target_start, target_end,
717 ime_control_busy_ = false; 713 ime_string);
718 } 714 ime_control_busy_ = false;
719 } 715 }
720 716
721 void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { 717 void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
722 // During shutdown we can just ignore this message. 718 // During shutdown we can just ignore this message.
723 if (!webwidget_) 719 if (!webwidget_)
724 return; 720 return;
725 721
726 set_next_paint_is_repaint_ack(); 722 set_next_paint_is_repaint_ack();
727 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); 723 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
728 DidInvalidateRect(webwidget_, repaint_rect); 724 didInvalidateRect(repaint_rect);
729 } 725 }
730 726
731 void RenderWidget::OnSetTextDirection(int direction) { 727 void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
732 if (!webwidget_) 728 if (!webwidget_)
733 return; 729 return;
734 730 webwidget_->setTextDirection(direction);
735 WebTextDirection new_direction = static_cast<WebTextDirection>(direction);
736 if (new_direction == WEB_TEXT_DIRECTION_DEFAULT ||
737 new_direction == WEB_TEXT_DIRECTION_LTR ||
738 new_direction == WEB_TEXT_DIRECTION_RTL) {
739 webwidget_->SetTextDirection(new_direction);
740 } else {
741 NOTREACHED();
742 }
743 } 731 }
744 732
745 void RenderWidget::SetBackground(const SkBitmap& background) { 733 void RenderWidget::SetBackground(const SkBitmap& background) {
746 background_ = background; 734 background_ = background;
747 // Generate a full repaint. 735 // Generate a full repaint.
748 DidInvalidateRect(webwidget_, gfx::Rect(size_.width(), size_.height())); 736 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
749 } 737 }
750 738
751 bool RenderWidget::next_paint_is_resize_ack() const { 739 bool RenderWidget::next_paint_is_resize_ack() const {
752 return ViewHostMsg_PaintRect_Flags::is_resize_ack(next_paint_flags_); 740 return ViewHostMsg_PaintRect_Flags::is_resize_ack(next_paint_flags_);
753 } 741 }
754 742
755 bool RenderWidget::next_paint_is_restore_ack() const { 743 bool RenderWidget::next_paint_is_restore_ack() const {
756 return ViewHostMsg_PaintRect_Flags::is_restore_ack(next_paint_flags_); 744 return ViewHostMsg_PaintRect_Flags::is_restore_ack(next_paint_flags_);
757 } 745 }
758 746
(...skipping 15 matching lines...) Expand all
774 // a renderer process does not have to retrieve information of the focused 762 // a renderer process does not have to retrieve information of the focused
775 // control or send notification messages to a browser process. 763 // control or send notification messages to a browser process.
776 if (!ime_is_active_) { 764 if (!ime_is_active_) {
777 return; 765 return;
778 } 766 }
779 // Retrieve the caret position from the focused widget and verify we should 767 // Retrieve the caret position from the focused widget and verify we should
780 // enabled IMEs attached to the browser process. 768 // enabled IMEs attached to the browser process.
781 bool enable_ime = false; 769 bool enable_ime = false;
782 WebRect caret_rect; 770 WebRect caret_rect;
783 if (!webwidget_ || 771 if (!webwidget_ ||
784 !webwidget_->ImeUpdateStatus(&enable_ime, &caret_rect)) { 772 !webwidget_->queryCompositionStatus(&enable_ime, &caret_rect)) {
785 // There are not any editable widgets attached to this process. 773 // There are not any editable widgets attached to this process.
786 // We should disable the IME to prevent it from sending CJK strings to 774 // We should disable the IME to prevent it from sending CJK strings to
787 // non-editable widgets. 775 // non-editable widgets.
788 ime_control_updated_ = true; 776 ime_control_updated_ = true;
789 ime_control_new_state_ = false; 777 ime_control_new_state_ = false;
790 } 778 }
791 if (ime_control_new_state_ != enable_ime) { 779 if (ime_control_new_state_ != enable_ime) {
792 ime_control_updated_ = true; 780 ime_control_updated_ = true;
793 ime_control_new_state_ = enable_ime; 781 ime_control_new_state_ = enable_ime;
794 } 782 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 } 820 }
833 } 821 }
834 } 822 }
835 // Save the updated IME status to prevent from sending the same IPC messages. 823 // Save the updated IME status to prevent from sending the same IPC messages.
836 ime_control_updated_ = false; 824 ime_control_updated_ = false;
837 ime_control_enable_ime_ = ime_control_new_state_; 825 ime_control_enable_ime_ = ime_control_new_state_;
838 ime_control_x_ = caret_rect.x; 826 ime_control_x_ = caret_rect.x;
839 ime_control_y_ = caret_rect.y; 827 ime_control_y_ = caret_rect.y;
840 } 828 }
841 829
842 void RenderWidget::DidMove(WebWidget* webwidget, 830 WebScreenInfo RenderWidget::screenInfo() {
843 const WebPluginGeometry& move) { 831 WebScreenInfo results;
832 Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results));
833 return results;
834 }
835
836 void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
844 size_t i = 0; 837 size_t i = 0;
845 for (; i < plugin_window_moves_.size(); ++i) { 838 for (; i < plugin_window_moves_.size(); ++i) {
846 if (plugin_window_moves_[i].window == move.window) { 839 if (plugin_window_moves_[i].window == move.window) {
847 plugin_window_moves_[i] = move; 840 plugin_window_moves_[i] = move;
848 break; 841 break;
849 } 842 }
850 } 843 }
851 844
852 if (i == plugin_window_moves_.size()) 845 if (i == plugin_window_moves_.size())
853 plugin_window_moves_.push_back(move); 846 plugin_window_moves_.push_back(move);
854 } 847 }
855
856 WebScreenInfo RenderWidget::GetScreenInfo(WebWidget* webwidget) {
857 WebScreenInfo results;
858 Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results));
859 return results;
860 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_widget.h ('k') | webkit/api/public/WebCompositionCommand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698