OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 GdkPixmap* mask = gdk_bitmap_create_from_data( | 94 GdkPixmap* mask = gdk_bitmap_create_from_data( |
95 NULL, reinterpret_cast<const gchar*>(moz_spinning_mask_bits), 32, 32); | 95 NULL, reinterpret_cast<const gchar*>(moz_spinning_mask_bits), 32, 32); |
96 moz_spinning_cursor = | 96 moz_spinning_cursor = |
97 gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, 2, 2); | 97 gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, 2, 2); |
98 g_object_unref(source); | 98 g_object_unref(source); |
99 g_object_unref(mask); | 99 g_object_unref(mask); |
100 } | 100 } |
101 return moz_spinning_cursor; | 101 return moz_spinning_cursor; |
102 } | 102 } |
103 | 103 |
104 bool MovedToCenter(const WebKit::WebMouseEvent& mouse_event, | 104 bool MovedToPoint(const WebKit::WebMouseEvent& mouse_event, |
105 const gfx::Point& center) { | 105 const gfx::Point& center) { |
106 return mouse_event.globalX == center.x() && | 106 return mouse_event.globalX == center.x() && |
107 mouse_event.globalY == center.y(); | 107 mouse_event.globalY == center.y(); |
108 } | 108 } |
109 | 109 |
110 } // namespace | 110 } // namespace |
111 | 111 |
112 // This class is a simple convenience wrapper for Gtk functions. It has only | 112 // This class is a simple convenience wrapper for Gtk functions. It has only |
113 // static methods. | 113 // static methods. |
114 class RenderWidgetHostViewGtkWidget { | 114 class RenderWidgetHostViewGtkWidget { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 } | 384 } |
385 | 385 |
386 host_view->ModifyEventForEdgeDragging(widget, event); | 386 host_view->ModifyEventForEdgeDragging(widget, event); |
387 | 387 |
388 WebKit::WebMouseEvent mouse_event = | 388 WebKit::WebMouseEvent mouse_event = |
389 WebInputEventFactory::mouseEvent(event); | 389 WebInputEventFactory::mouseEvent(event); |
390 | 390 |
391 if (host_view->mouse_locked_) { | 391 if (host_view->mouse_locked_) { |
392 gfx::Point center = host_view->GetWidgetCenter(); | 392 gfx::Point center = host_view->GetWidgetCenter(); |
393 | 393 |
394 bool moved_to_center = MovedToCenter(mouse_event, center); | 394 bool moved_to_center = MovedToPoint(mouse_event, center); |
395 if (moved_to_center) | 395 if (moved_to_center) |
396 host_view->mouse_has_been_warped_to_new_center_ = true; | 396 host_view->mouse_has_been_warped_to_new_center_ = true; |
397 | 397 |
398 host_view->ModifyEventMovementAndCoords(&mouse_event); | 398 host_view->ModifyEventMovementAndCoords(&mouse_event); |
399 | 399 |
400 if (!moved_to_center && | 400 if (!moved_to_center && |
401 (mouse_event.movementX || mouse_event.movementY)) { | 401 (mouse_event.movementX || mouse_event.movementY)) { |
402 GdkDisplay* display = gtk_widget_get_display(widget); | 402 GdkDisplay* display = gtk_widget_get_display(widget); |
403 GdkScreen* screen = gtk_widget_get_screen(widget); | 403 GdkScreen* screen = gtk_widget_get_screen(widget); |
404 gdk_display_warp_pointer(display, screen, center.x(), center.y()); | 404 gdk_display_warp_pointer(display, screen, center.x(), center.y()); |
405 if (host_view->mouse_has_been_warped_to_new_center_) | 405 if (host_view->mouse_has_been_warped_to_new_center_) |
406 RenderWidgetHostImpl::From( | 406 RenderWidgetHostImpl::From( |
407 host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event); | 407 host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event); |
408 } | 408 } |
409 } else { // Mouse is not locked. | 409 } else { // Mouse is not locked. |
410 host_view->ModifyEventMovementAndCoords(&mouse_event); | 410 host_view->ModifyEventMovementAndCoords(&mouse_event); |
411 RenderWidgetHostImpl::From( | 411 // Do not send mouse events while the mouse cursor is being warped back |
412 host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event); | 412 // to the unlocked location. |
| 413 if (!host_view->mouse_is_being_warped_to_unlocked_position_) { |
| 414 RenderWidgetHostImpl::From( |
| 415 host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event); |
| 416 } |
413 } | 417 } |
414 return FALSE; | 418 return FALSE; |
415 } | 419 } |
416 | 420 |
417 static gboolean OnCrossingEvent(GtkWidget* widget, | 421 static gboolean OnCrossingEvent(GtkWidget* widget, |
418 GdkEventCrossing* event, | 422 GdkEventCrossing* event, |
419 RenderWidgetHostViewGtk* host_view) { | 423 RenderWidgetHostViewGtk* host_view) { |
420 TRACE_EVENT0("browser", | 424 TRACE_EVENT0("browser", |
421 "RenderWidgetHostViewGtkWidget::OnCrossingEvent"); | 425 "RenderWidgetHostViewGtkWidget::OnCrossingEvent"); |
422 const int any_button_mask = | 426 const int any_button_mask = |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 : host_(RenderWidgetHostImpl::From(widget_host)), | 552 : host_(RenderWidgetHostImpl::From(widget_host)), |
549 about_to_validate_and_paint_(false), | 553 about_to_validate_and_paint_(false), |
550 is_hidden_(false), | 554 is_hidden_(false), |
551 is_loading_(false), | 555 is_loading_(false), |
552 parent_(NULL), | 556 parent_(NULL), |
553 is_popup_first_mouse_release_(true), | 557 is_popup_first_mouse_release_(true), |
554 was_imcontext_focused_before_grab_(false), | 558 was_imcontext_focused_before_grab_(false), |
555 do_x_grab_(false), | 559 do_x_grab_(false), |
556 is_fullscreen_(false), | 560 is_fullscreen_(false), |
557 made_active_(false), | 561 made_active_(false), |
| 562 mouse_is_being_warped_to_unlocked_position_(false), |
558 destroy_handler_id_(0), | 563 destroy_handler_id_(0), |
559 dragged_at_horizontal_edge_(0), | 564 dragged_at_horizontal_edge_(0), |
560 dragged_at_vertical_edge_(0), | 565 dragged_at_vertical_edge_(0), |
561 compositing_surface_(gfx::kNullPluginWindow), | 566 compositing_surface_(gfx::kNullPluginWindow), |
562 last_mouse_down_(NULL) { | 567 last_mouse_down_(NULL) { |
563 host_->SetView(this); | 568 host_->SetView(this); |
564 } | 569 } |
565 | 570 |
566 RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() { | 571 RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() { |
567 UnlockMouse(); | 572 UnlockMouse(); |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 | 1336 |
1332 mouse_locked_ = false; | 1337 mouse_locked_ = false; |
1333 | 1338 |
1334 GtkWidget* widget = view_.get(); | 1339 GtkWidget* widget = view_.get(); |
1335 GdkDisplay* display = gtk_widget_get_display(widget); | 1340 GdkDisplay* display = gtk_widget_get_display(widget); |
1336 GdkScreen* screen = gtk_widget_get_screen(widget); | 1341 GdkScreen* screen = gtk_widget_get_screen(widget); |
1337 gdk_display_pointer_ungrab(display, GDK_CURRENT_TIME); | 1342 gdk_display_pointer_ungrab(display, GDK_CURRENT_TIME); |
1338 gdk_display_warp_pointer(display, screen, | 1343 gdk_display_warp_pointer(display, screen, |
1339 unlocked_global_mouse_position_.x(), | 1344 unlocked_global_mouse_position_.x(), |
1340 unlocked_global_mouse_position_.y()); | 1345 unlocked_global_mouse_position_.y()); |
| 1346 mouse_is_being_warped_to_unlocked_position_ = true; |
1341 | 1347 |
1342 if (host_) | 1348 if (host_) |
1343 host_->LostMouseLock(); | 1349 host_->LostMouseLock(); |
1344 } | 1350 } |
1345 | 1351 |
1346 void RenderWidgetHostViewGtk::ForwardKeyboardEvent( | 1352 void RenderWidgetHostViewGtk::ForwardKeyboardEvent( |
1347 const NativeWebKeyboardEvent& event) { | 1353 const NativeWebKeyboardEvent& event) { |
1348 if (!host_) | 1354 if (!host_) |
1349 return; | 1355 return; |
1350 | 1356 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1424 WebKit::WebMouseEvent* event) { | 1430 WebKit::WebMouseEvent* event) { |
1425 // Movement is computed by taking the difference of the new cursor position | 1431 // Movement is computed by taking the difference of the new cursor position |
1426 // and the previous. Under mouse lock the cursor will be warped back to the | 1432 // and the previous. Under mouse lock the cursor will be warped back to the |
1427 // center so that we are not limited by clipping boundaries. | 1433 // center so that we are not limited by clipping boundaries. |
1428 // We do not measure movement as the delta from cursor to center because | 1434 // We do not measure movement as the delta from cursor to center because |
1429 // we may receive more mouse movement events before our warp has taken | 1435 // we may receive more mouse movement events before our warp has taken |
1430 // effect. | 1436 // effect. |
1431 event->movementX = event->globalX - global_mouse_position_.x(); | 1437 event->movementX = event->globalX - global_mouse_position_.x(); |
1432 event->movementY = event->globalY - global_mouse_position_.y(); | 1438 event->movementY = event->globalY - global_mouse_position_.y(); |
1433 | 1439 |
| 1440 // While the cursor is being warped back to the unlocked position, suppress |
| 1441 // the movement member data. |
| 1442 if (mouse_is_being_warped_to_unlocked_position_) { |
| 1443 event->movementX = 0; |
| 1444 event->movementY = 0; |
| 1445 if (MovedToPoint(*event, unlocked_global_mouse_position_)) |
| 1446 mouse_is_being_warped_to_unlocked_position_ = false; |
| 1447 } |
| 1448 |
1434 global_mouse_position_.SetPoint(event->globalX, event->globalY); | 1449 global_mouse_position_.SetPoint(event->globalX, event->globalY); |
1435 | 1450 |
1436 // Under mouse lock, coordinates of mouse are locked to what they were when | 1451 // Under mouse lock, coordinates of mouse are locked to what they were when |
1437 // mouse lock was entered. | 1452 // mouse lock was entered. |
1438 if (mouse_locked_) { | 1453 if (mouse_locked_) { |
1439 event->x = unlocked_mouse_position_.x(); | 1454 event->x = unlocked_mouse_position_.x(); |
1440 event->y = unlocked_mouse_position_.y(); | 1455 event->y = unlocked_mouse_position_.y(); |
1441 event->windowX = unlocked_mouse_position_.x(); | 1456 event->windowX = unlocked_mouse_position_.x(); |
1442 event->windowY = unlocked_mouse_position_.y(); | 1457 event->windowY = unlocked_mouse_position_.y(); |
1443 event->globalX = unlocked_global_mouse_position_.x(); | 1458 event->globalX = unlocked_global_mouse_position_.x(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 this)); | 1545 this)); |
1531 } | 1546 } |
1532 BrowserAccessibilityGtk* root = | 1547 BrowserAccessibilityGtk* root = |
1533 browser_accessibility_manager_->GetRoot()->ToBrowserAccessibilityGtk(); | 1548 browser_accessibility_manager_->GetRoot()->ToBrowserAccessibilityGtk(); |
1534 | 1549 |
1535 atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); | 1550 atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); |
1536 return root->GetAtkObject(); | 1551 return root->GetAtkObject(); |
1537 } | 1552 } |
1538 | 1553 |
1539 } // namespace content | 1554 } // namespace content |
OLD | NEW |