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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_gtk.cc

Issue 9473001: Extract minimal RenderViewHost interface for embedders, leaving (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to LKGR. Created 8 years, 9 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
OLDNEW
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/browser/renderer_host/render_widget_host_view_gtk.h" 5 #include "content/browser/renderer_host/render_widget_host_view_gtk.h"
6 6
7 // If this gets included after the gtk headers, then a bunch of compiler 7 // If this gets included after the gtk headers, then a bunch of compiler
8 // errors happen because of a "#define Status int" in Xlib.h, which interacts 8 // errors happen because of a "#define Status int" in Xlib.h, which interacts
9 // badly with net::URLRequestStatus::Status. 9 // badly with net::URLRequestStatus::Status.
10 #include "content/common/view_messages.h" 10 #include "content/common/view_messages.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // We return TRUE because we did handle the event. If it turns out webkit 221 // We return TRUE because we did handle the event. If it turns out webkit
222 // can't handle the event, we'll deal with it in 222 // can't handle the event, we'll deal with it in
223 // RenderView::UnhandledKeyboardEvent(). 223 // RenderView::UnhandledKeyboardEvent().
224 return TRUE; 224 return TRUE;
225 } 225 }
226 226
227 static gboolean OnFocusIn(GtkWidget* widget, 227 static gboolean OnFocusIn(GtkWidget* widget,
228 GdkEventFocus* focus, 228 GdkEventFocus* focus,
229 RenderWidgetHostViewGtk* host_view) { 229 RenderWidgetHostViewGtk* host_view) {
230 host_view->ShowCurrentCursor(); 230 host_view->ShowCurrentCursor();
231 RenderWidgetHostImpl::FromRWHV(host_view)->GotFocus(); 231 RenderWidgetHostImpl* host =
232 RenderWidgetHostImpl::FromRWHV(host_view)->SetActive(true); 232 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost());
233 host->GotFocus();
234 host->SetActive(true);
233 235
234 // The only way to enable a GtkIMContext object is to call its focus in 236 // The only way to enable a GtkIMContext object is to call its focus in
235 // handler. 237 // handler.
236 host_view->im_context_->OnFocusIn(); 238 host_view->im_context_->OnFocusIn();
237 239
238 return TRUE; 240 return TRUE;
239 } 241 }
240 242
241 static gboolean OnFocusOut(GtkWidget* widget, 243 static gboolean OnFocusOut(GtkWidget* widget,
242 GdkEventFocus* focus, 244 GdkEventFocus* focus,
243 RenderWidgetHostViewGtk* host_view) { 245 RenderWidgetHostViewGtk* host_view) {
244 // Whenever we lose focus, set the cursor back to that of our parent window, 246 // Whenever we lose focus, set the cursor back to that of our parent window,
245 // which should be the default arrow. 247 // which should be the default arrow.
246 gdk_window_set_cursor(gtk_widget_get_window(widget), NULL); 248 gdk_window_set_cursor(gtk_widget_get_window(widget), NULL);
247 // If we are showing a context menu, maintain the illusion that webkit has 249 // If we are showing a context menu, maintain the illusion that webkit has
248 // focus. 250 // focus.
249 if (!host_view->IsShowingContextMenu()) { 251 if (!host_view->IsShowingContextMenu()) {
250 RenderWidgetHostImpl::FromRWHV(host_view)->SetActive(false); 252 RenderWidgetHostImpl* host =
251 RenderWidgetHostImpl::FromRWHV(host_view)->Blur(); 253 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost());
254 host->SetActive(false);
255 host->Blur();
252 } 256 }
253 257
254 // Prevents us from stealing input context focus in OnGrabNotify() handler. 258 // Prevents us from stealing input context focus in OnGrabNotify() handler.
255 host_view->was_imcontext_focused_before_grab_ = false; 259 host_view->was_imcontext_focused_before_grab_ = false;
256 260
257 // Disable the GtkIMContext object. 261 // Disable the GtkIMContext object.
258 host_view->im_context_->OnFocusOut(); 262 host_view->im_context_->OnFocusOut();
259 263
260 return TRUE; 264 return TRUE;
261 } 265 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 event->button == 8 ? GDK_SCROLL_LEFT : GDK_SCROLL_RIGHT; 308 event->button == 8 ? GDK_SCROLL_LEFT : GDK_SCROLL_RIGHT;
305 } else { 309 } else {
306 scroll_event.direction = 310 scroll_event.direction =
307 event->button == 8 ? GDK_SCROLL_UP : GDK_SCROLL_DOWN; 311 event->button == 8 ? GDK_SCROLL_UP : GDK_SCROLL_DOWN;
308 } 312 }
309 scroll_event.device = event->device; 313 scroll_event.device = event->device;
310 scroll_event.x_root = event->x_root; 314 scroll_event.x_root = event->x_root;
311 scroll_event.y_root = event->y_root; 315 scroll_event.y_root = event->y_root;
312 WebMouseWheelEvent web_event = 316 WebMouseWheelEvent web_event =
313 WebInputEventFactory::mouseWheelEvent(&scroll_event); 317 WebInputEventFactory::mouseWheelEvent(&scroll_event);
314 RenderWidgetHostImpl::FromRWHV( 318 RenderWidgetHostImpl::From(
315 host_view)->ForwardWheelEvent(web_event); 319 host_view->GetRenderWidgetHost())->ForwardWheelEvent(web_event);
316 } 320 }
317 #endif 321 #endif
318 322
319 if (event->type != GDK_BUTTON_RELEASE) 323 if (event->type != GDK_BUTTON_RELEASE)
320 host_view->set_last_mouse_down(event); 324 host_view->set_last_mouse_down(event);
321 325
322 if (!(event->button == 1 || event->button == 2 || event->button == 3)) 326 if (!(event->button == 1 || event->button == 2 || event->button == 3))
323 return FALSE; // We do not forward any other buttons to the renderer. 327 return FALSE; // We do not forward any other buttons to the renderer.
324 if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) 328 if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
325 return FALSE; 329 return FALSE;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 event->y = y; 364 event->y = y;
361 } 365 }
362 366
363 // TODO(evanm): why is this necessary here but not in test shell? 367 // TODO(evanm): why is this necessary here but not in test shell?
364 // This logic is the same as GtkButton. 368 // This logic is the same as GtkButton.
365 if (event->type == GDK_BUTTON_PRESS && !gtk_widget_has_focus(widget)) 369 if (event->type == GDK_BUTTON_PRESS && !gtk_widget_has_focus(widget))
366 gtk_widget_grab_focus(widget); 370 gtk_widget_grab_focus(widget);
367 371
368 host_view->is_popup_first_mouse_release_ = false; 372 host_view->is_popup_first_mouse_release_ = false;
369 RenderWidgetHostImpl* widget_host = 373 RenderWidgetHostImpl* widget_host =
370 RenderWidgetHostImpl::FromRWHV(host_view); 374 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost());
371 if (widget_host) 375 if (widget_host)
372 widget_host->ForwardMouseEvent(WebInputEventFactory::mouseEvent(event)); 376 widget_host->ForwardMouseEvent(WebInputEventFactory::mouseEvent(event));
373 377
374 // Although we did handle the mouse event, we need to let other handlers 378 // Although we did handle the mouse event, we need to let other handlers
375 // run (in particular the one installed by TabContentsViewGtk). 379 // run (in particular the one installed by TabContentsViewGtk).
376 return FALSE; 380 return FALSE;
377 } 381 }
378 382
379 static gboolean OnMouseMoveEvent(GtkWidget* widget, 383 static gboolean OnMouseMoveEvent(GtkWidget* widget,
380 GdkEventMotion* event, 384 GdkEventMotion* event,
(...skipping 23 matching lines...) Expand all
404 host_view->mouse_has_been_warped_to_new_center_ = true; 408 host_view->mouse_has_been_warped_to_new_center_ = true;
405 409
406 host_view->ModifyEventMovementAndCoords(&mouse_event); 410 host_view->ModifyEventMovementAndCoords(&mouse_event);
407 411
408 if (!moved_to_center && 412 if (!moved_to_center &&
409 (mouse_event.movementX || mouse_event.movementY)) { 413 (mouse_event.movementX || mouse_event.movementY)) {
410 GdkDisplay* display = gtk_widget_get_display(widget); 414 GdkDisplay* display = gtk_widget_get_display(widget);
411 GdkScreen* screen = gtk_widget_get_screen(widget); 415 GdkScreen* screen = gtk_widget_get_screen(widget);
412 gdk_display_warp_pointer(display, screen, center.x(), center.y()); 416 gdk_display_warp_pointer(display, screen, center.x(), center.y());
413 if (host_view->mouse_has_been_warped_to_new_center_) 417 if (host_view->mouse_has_been_warped_to_new_center_)
414 RenderWidgetHostImpl::FromRWHV( 418 RenderWidgetHostImpl::From(
415 host_view)->ForwardMouseEvent(mouse_event); 419 host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event);
416 } 420 }
417 } else { // Mouse is not locked. 421 } else { // Mouse is not locked.
418 host_view->ModifyEventMovementAndCoords(&mouse_event); 422 host_view->ModifyEventMovementAndCoords(&mouse_event);
419 RenderWidgetHostImpl::FromRWHV( 423 RenderWidgetHostImpl::From(
420 host_view)->ForwardMouseEvent(mouse_event); 424 host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event);
421 } 425 }
422 return FALSE; 426 return FALSE;
423 } 427 }
424 428
425 static gboolean OnCrossingEvent(GtkWidget* widget, 429 static gboolean OnCrossingEvent(GtkWidget* widget,
426 GdkEventCrossing* event, 430 GdkEventCrossing* event,
427 RenderWidgetHostViewGtk* host_view) { 431 RenderWidgetHostViewGtk* host_view) {
428 const int any_button_mask = 432 const int any_button_mask =
429 GDK_BUTTON1_MASK | 433 GDK_BUTTON1_MASK |
430 GDK_BUTTON2_MASK | 434 GDK_BUTTON2_MASK |
431 GDK_BUTTON3_MASK | 435 GDK_BUTTON3_MASK |
432 GDK_BUTTON4_MASK | 436 GDK_BUTTON4_MASK |
433 GDK_BUTTON5_MASK; 437 GDK_BUTTON5_MASK;
434 438
435 // Only forward crossing events if the mouse button is not down. 439 // Only forward crossing events if the mouse button is not down.
436 // (When the mouse button is down, the proper events are already being 440 // (When the mouse button is down, the proper events are already being
437 // sent by ButtonPressReleaseEvent and MouseMoveEvent, above, and if we 441 // sent by ButtonPressReleaseEvent and MouseMoveEvent, above, and if we
438 // additionally send this crossing event with the state indicating the 442 // additionally send this crossing event with the state indicating the
439 // button is down, it causes problems with drag and drop in WebKit.) 443 // button is down, it causes problems with drag and drop in WebKit.)
440 if (!(event->state & any_button_mask)) { 444 if (!(event->state & any_button_mask)) {
441 WebKit::WebMouseEvent mouse_event = 445 WebKit::WebMouseEvent mouse_event =
442 WebInputEventFactory::mouseEvent(event); 446 WebInputEventFactory::mouseEvent(event);
443 host_view->ModifyEventMovementAndCoords(&mouse_event); 447 host_view->ModifyEventMovementAndCoords(&mouse_event);
444 // When crossing out and back into a render view the movement values 448 // When crossing out and back into a render view the movement values
445 // must represent the instantaneous movement of the mouse, not the jump 449 // must represent the instantaneous movement of the mouse, not the jump
446 // from the exit to re-entry point. 450 // from the exit to re-entry point.
447 mouse_event.movementX = 0; 451 mouse_event.movementX = 0;
448 mouse_event.movementY = 0; 452 mouse_event.movementY = 0;
449 RenderWidgetHostImpl::FromRWHV( 453 RenderWidgetHostImpl::From(
450 host_view)->ForwardMouseEvent(mouse_event); 454 host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event);
451 } 455 }
452 456
453 return FALSE; 457 return FALSE;
454 } 458 }
455 459
456 static gboolean OnClientEvent(GtkWidget* widget, 460 static gboolean OnClientEvent(GtkWidget* widget,
457 GdkEventClient* event, 461 GdkEventClient* event,
458 RenderWidgetHostViewGtk* host_view) { 462 RenderWidgetHostViewGtk* host_view) {
459 VLOG(1) << "client event type: " << event->message_type 463 VLOG(1) << "client event type: " << event->message_type
460 << " data_format: " << event->data_format 464 << " data_format: " << event->data_format
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 else 558 else
555 web_event.deltaY = -GetScrollPixelsPerTick(); 559 web_event.deltaY = -GetScrollPixelsPerTick();
556 web_event.deltaY += GetPendingScrollDelta(true, event->state); 560 web_event.deltaY += GetPendingScrollDelta(true, event->state);
557 } else { 561 } else {
558 if (event->direction == GDK_SCROLL_LEFT) 562 if (event->direction == GDK_SCROLL_LEFT)
559 web_event.deltaX = GetScrollPixelsPerTick(); 563 web_event.deltaX = GetScrollPixelsPerTick();
560 else 564 else
561 web_event.deltaX = -GetScrollPixelsPerTick(); 565 web_event.deltaX = -GetScrollPixelsPerTick();
562 web_event.deltaX += GetPendingScrollDelta(false, event->state); 566 web_event.deltaX += GetPendingScrollDelta(false, event->state);
563 } 567 }
564 RenderWidgetHostImpl::FromRWHV(host_view)->ForwardWheelEvent(web_event); 568 RenderWidgetHostImpl::From(
569 host_view->GetRenderWidgetHost())->ForwardWheelEvent(web_event);
565 return FALSE; 570 return FALSE;
566 } 571 }
567 572
568 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); 573 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget);
569 }; 574 };
570 575
571 RenderWidgetHostViewGtk::RenderWidgetHostViewGtk(RenderWidgetHost* widget_host) 576 RenderWidgetHostViewGtk::RenderWidgetHostViewGtk(RenderWidgetHost* widget_host)
572 : about_to_validate_and_paint_(false), 577 : host_(RenderWidgetHostImpl::From(widget_host)),
578 about_to_validate_and_paint_(false),
573 is_hidden_(false), 579 is_hidden_(false),
574 is_loading_(false), 580 is_loading_(false),
575 parent_(NULL), 581 parent_(NULL),
576 is_popup_first_mouse_release_(true), 582 is_popup_first_mouse_release_(true),
577 was_imcontext_focused_before_grab_(false), 583 was_imcontext_focused_before_grab_(false),
578 do_x_grab_(false), 584 do_x_grab_(false),
579 is_fullscreen_(false), 585 is_fullscreen_(false),
580 destroy_handler_id_(0), 586 destroy_handler_id_(0),
581 dragged_at_horizontal_edge_(0), 587 dragged_at_horizontal_edge_(0),
582 dragged_at_vertical_edge_(0), 588 dragged_at_vertical_edge_(0),
583 compositing_surface_(gfx::kNullPluginWindow), 589 compositing_surface_(gfx::kNullPluginWindow),
584 last_mouse_down_(NULL) { 590 last_mouse_down_(NULL) {
585 host_ = static_cast<RenderWidgetHostImpl*>(widget_host);
586 host_->SetView(this); 591 host_->SetView(this);
587 } 592 }
588 593
589 RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() { 594 RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() {
590 UnlockMouse(); 595 UnlockMouse();
591 set_last_mouse_down(NULL); 596 set_last_mouse_down(NULL);
592 view_.Destroy(); 597 view_.Destroy();
593 } 598 }
594 599
595 void RenderWidgetHostViewGtk::InitAsChild( 600 void RenderWidgetHostViewGtk::InitAsChild(
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 int gpu_host_id) { 1033 int gpu_host_id) {
1029 RenderWidgetHostImpl::AcknowledgePostSubBuffer(params.route_id, gpu_host_id); 1034 RenderWidgetHostImpl::AcknowledgePostSubBuffer(params.route_id, gpu_host_id);
1030 } 1035 }
1031 1036
1032 void RenderWidgetHostViewGtk::AcceleratedSurfaceSuspend() { 1037 void RenderWidgetHostViewGtk::AcceleratedSurfaceSuspend() {
1033 } 1038 }
1034 1039
1035 1040
1036 void RenderWidgetHostViewGtk::SetBackground(const SkBitmap& background) { 1041 void RenderWidgetHostViewGtk::SetBackground(const SkBitmap& background) {
1037 content::RenderWidgetHostViewBase::SetBackground(background); 1042 content::RenderWidgetHostViewBase::SetBackground(background);
1038 host_->Send(new ViewMsg_SetBackground(host_->routing_id(), background)); 1043 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background));
1039 } 1044 }
1040 1045
1041 void RenderWidgetHostViewGtk::ModifyEventForEdgeDragging( 1046 void RenderWidgetHostViewGtk::ModifyEventForEdgeDragging(
1042 GtkWidget* widget, GdkEventMotion* event) { 1047 GtkWidget* widget, GdkEventMotion* event) {
1043 // If the widget is aligned with an edge of the monitor its on and the user 1048 // If the widget is aligned with an edge of the monitor its on and the user
1044 // attempts to drag past that edge we track the number of times it has 1049 // attempts to drag past that edge we track the number of times it has
1045 // occurred, so that we can force the widget to scroll when it otherwise 1050 // occurred, so that we can force the widget to scroll when it otherwise
1046 // would be unable to, by modifying the (x,y) position in the drag 1051 // would be unable to, by modifying the (x,y) position in the drag
1047 // event that we forward on to webkit. If we get a move that's no longer a 1052 // event that we forward on to webkit. If we get a move that's no longer a
1048 // drag or a drag indicating the user is no longer at that edge we stop 1053 // drag or a drag indicating the user is no longer at that edge we stop
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 dragged_at_horizontal_edge_ = new_dragged_at_horizontal_edge; 1095 dragged_at_horizontal_edge_ = new_dragged_at_horizontal_edge;
1091 dragged_at_vertical_edge_ = new_dragged_at_vertical_edge; 1096 dragged_at_vertical_edge_ = new_dragged_at_vertical_edge;
1092 } 1097 }
1093 1098
1094 void RenderWidgetHostViewGtk::Paint(const gfx::Rect& damage_rect) { 1099 void RenderWidgetHostViewGtk::Paint(const gfx::Rect& damage_rect) {
1095 TRACE_EVENT0("ui::gtk", "RenderWidgetHostViewGtk::Paint"); 1100 TRACE_EVENT0("ui::gtk", "RenderWidgetHostViewGtk::Paint");
1096 1101
1097 // If the GPU process is rendering directly into the View, 1102 // If the GPU process is rendering directly into the View,
1098 // call the compositor directly. 1103 // call the compositor directly.
1099 RenderWidgetHostImpl* render_widget_host = 1104 RenderWidgetHostImpl* render_widget_host =
1100 static_cast<RenderWidgetHostImpl*>(GetRenderWidgetHost()); 1105 RenderWidgetHostImpl::From(GetRenderWidgetHost());
1101 if (render_widget_host->is_accelerated_compositing_active()) { 1106 if (render_widget_host->is_accelerated_compositing_active()) {
1102 host_->ScheduleComposite(); 1107 host_->ScheduleComposite();
1103 return; 1108 return;
1104 } 1109 }
1105 1110
1106 GdkWindow* window = gtk_widget_get_window(view_.get()); 1111 GdkWindow* window = gtk_widget_get_window(view_.get());
1107 DCHECK(!about_to_validate_and_paint_); 1112 DCHECK(!about_to_validate_and_paint_);
1108 1113
1109 invalid_rect_ = damage_rect; 1114 invalid_rect_ = damage_rect;
1110 about_to_validate_and_paint_ = true; 1115 about_to_validate_and_paint_ = true;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 void RenderWidgetHostViewGtk::ForwardKeyboardEvent( 1314 void RenderWidgetHostViewGtk::ForwardKeyboardEvent(
1310 const NativeWebKeyboardEvent& event) { 1315 const NativeWebKeyboardEvent& event) {
1311 if (!host_) 1316 if (!host_)
1312 return; 1317 return;
1313 1318
1314 #if !defined(OS_CHROMEOS) 1319 #if !defined(OS_CHROMEOS)
1315 EditCommands edit_commands; 1320 EditCommands edit_commands;
1316 if (!event.skip_in_browser && 1321 if (!event.skip_in_browser &&
1317 key_bindings_handler_->Match(event, &edit_commands)) { 1322 key_bindings_handler_->Match(event, &edit_commands)) {
1318 host_->Send(new ViewMsg_SetEditCommandsForNextKeyEvent( 1323 host_->Send(new ViewMsg_SetEditCommandsForNextKeyEvent(
1319 host_->routing_id(), edit_commands)); 1324 host_->GetRoutingID(), edit_commands));
1320 NativeWebKeyboardEvent copy_event(event); 1325 NativeWebKeyboardEvent copy_event(event);
1321 copy_event.match_edit_command = true; 1326 copy_event.match_edit_command = true;
1322 host_->ForwardKeyboardEvent(copy_event); 1327 host_->ForwardKeyboardEvent(copy_event);
1323 return; 1328 return;
1324 } 1329 }
1325 #endif 1330 #endif
1326 1331
1327 host_->ForwardKeyboardEvent(event); 1332 host_->ForwardKeyboardEvent(event);
1328 } 1333 }
1329 1334
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 return new RenderWidgetHostViewGtk(widget); 1422 return new RenderWidgetHostViewGtk(widget);
1418 } 1423 }
1419 1424
1420 // static 1425 // static
1421 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( 1426 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo(
1422 WebKit::WebScreenInfo* results) { 1427 WebKit::WebScreenInfo* results) {
1423 GdkWindow* gdk_window = 1428 GdkWindow* gdk_window =
1424 gdk_display_get_default_group(gdk_display_get_default()); 1429 gdk_display_get_default_group(gdk_display_get_default());
1425 content::GetScreenInfoFromNativeWindow(gdk_window, results); 1430 content::GetScreenInfoFromNativeWindow(gdk_window, results);
1426 } 1431 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698