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 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
8 #include <gdk/gdk.h> | 8 #include <gdk/gdk.h> |
9 #include <gdk/gdkkeysyms.h> | 9 #include <gdk/gdkkeysyms.h> |
10 #include <gdk/gdkx.h> | 10 #include <gdk/gdkx.h> |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
23 #include "base/strings/utf_offset_string_conversions.h" | 23 #include "base/strings/utf_offset_string_conversions.h" |
24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
26 #include "content/browser/accessibility/browser_accessibility_gtk.h" | 26 #include "content/browser/accessibility/browser_accessibility_gtk.h" |
27 #include "content/browser/accessibility/browser_accessibility_manager_gtk.h" | 27 #include "content/browser/accessibility/browser_accessibility_manager_gtk.h" |
28 #include "content/browser/renderer_host/backing_store_gtk.h" | 28 #include "content/browser/renderer_host/backing_store_gtk.h" |
29 #include "content/browser/renderer_host/gtk_im_context_wrapper.h" | 29 #include "content/browser/renderer_host/gtk_im_context_wrapper.h" |
30 #include "content/browser/renderer_host/gtk_key_bindings_handler.h" | 30 #include "content/browser/renderer_host/gtk_key_bindings_handler.h" |
31 #include "content/browser/renderer_host/gtk_window_utils.h" | 31 #include "content/browser/renderer_host/gtk_window_utils.h" |
| 32 #include "content/browser/renderer_host/input/web_input_event_builders_gtk.h" |
32 #include "content/browser/renderer_host/render_view_host_delegate.h" | 33 #include "content/browser/renderer_host/render_view_host_delegate.h" |
33 #include "content/browser/renderer_host/render_view_host_impl.h" | 34 #include "content/browser/renderer_host/render_view_host_impl.h" |
34 #include "content/common/gpu/gpu_messages.h" | 35 #include "content/common/gpu/gpu_messages.h" |
35 #include "content/common/input_messages.h" | 36 #include "content/common/input_messages.h" |
36 #include "content/common/view_messages.h" | 37 #include "content/common/view_messages.h" |
37 #include "content/common/webplugin_geometry.h" | 38 #include "content/common/webplugin_geometry.h" |
38 #include "content/public/browser/native_web_keyboard_event.h" | 39 #include "content/public/browser/native_web_keyboard_event.h" |
39 #include "content/public/common/content_switches.h" | 40 #include "content/public/common/content_switches.h" |
40 #include "skia/ext/platform_canvas.h" | 41 #include "skia/ext/platform_canvas.h" |
41 #include "third_party/WebKit/public/web/WebInputEvent.h" | 42 #include "third_party/WebKit/public/web/WebInputEvent.h" |
42 #include "third_party/WebKit/public/web/WebScreenInfo.h" | 43 #include "third_party/WebKit/public/web/WebScreenInfo.h" |
43 #include "third_party/WebKit/public/web/gtk/WebInputEventFactory.h" | |
44 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 44 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
45 #include "ui/base/x/active_window_watcher_x.h" | 45 #include "ui/base/x/active_window_watcher_x.h" |
46 #include "ui/base/x/x11_util.h" | 46 #include "ui/base/x/x11_util.h" |
47 #include "ui/gfx/gtk_compat.h" | 47 #include "ui/gfx/gtk_compat.h" |
48 #include "ui/gfx/gtk_native_view_id_manager.h" | 48 #include "ui/gfx/gtk_native_view_id_manager.h" |
49 #include "ui/gfx/gtk_preserve_window.h" | 49 #include "ui/gfx/gtk_preserve_window.h" |
50 #include "ui/gfx/text_elider.h" | 50 #include "ui/gfx/text_elider.h" |
51 #include "webkit/common/cursors/webcursor_gtk_data.h" | 51 #include "webkit/common/cursors/webcursor_gtk_data.h" |
52 | 52 |
53 using WebKit::WebInputEventFactory; | |
54 using WebKit::WebMouseWheelEvent; | 53 using WebKit::WebMouseWheelEvent; |
55 using WebKit::WebScreenInfo; | 54 using WebKit::WebScreenInfo; |
56 | 55 |
57 namespace content { | 56 namespace content { |
58 namespace { | 57 namespace { |
59 | 58 |
60 // Paint rects on Linux are bounded by the maximum size of a shared memory | 59 // Paint rects on Linux are bounded by the maximum size of a shared memory |
61 // region. By default that's 32MB, but many distros increase it significantly | 60 // region. By default that's 32MB, but many distros increase it significantly |
62 // (i.e. to 256MB). | 61 // (i.e. to 256MB). |
63 // | 62 // |
64 // We fetch the maximum value from /proc/sys/kernel/shmmax at runtime and, if | 63 // We fetch the maximum value from /proc/sys/kernel/shmmax at runtime and, if |
65 // we exceed that, then we limit the height of the paint rect in the renderer. | 64 // we exceed that, then we limit the height of the paint rect in the renderer. |
66 // | 65 // |
67 // These constants are here to ensure that, in the event that we exceed it, we | 66 // These constants are here to ensure that, in the event that we exceed it, we |
68 // end up with something a little more square. Previously we had 4000x4000, but | 67 // end up with something a little more square. Previously we had 4000x4000, but |
69 // people's monitor setups are actually exceeding that these days. | 68 // people's monitor setups are actually exceeding that these days. |
70 const int kMaxWindowWidth = 10000; | 69 const int kMaxWindowWidth = 10000; |
71 const int kMaxWindowHeight = 10000; | 70 const int kMaxWindowHeight = 10000; |
72 | 71 |
73 // See WebInputEventFactor.cpp for a reason for this being the default | |
74 // scroll size for linux. | |
75 const float kDefaultScrollPixelsPerTick = 160.0f / 3.0f; | |
76 | |
77 const GdkColor kBGColor = | 72 const GdkColor kBGColor = |
78 #if defined(NDEBUG) | 73 #if defined(NDEBUG) |
79 { 0, 0xff * 257, 0xff * 257, 0xff * 257 }; | 74 { 0, 0xff * 257, 0xff * 257, 0xff * 257 }; |
80 #else | 75 #else |
81 { 0, 0x00 * 257, 0xff * 257, 0x00 * 257 }; | 76 { 0, 0x00 * 257, 0xff * 257, 0x00 * 257 }; |
82 #endif | 77 #endif |
83 | 78 |
84 // Returns the spinning cursor used for loading state. | 79 // Returns the spinning cursor used for loading state. |
85 GdkCursor* GetMozSpinningCursor() { | 80 GdkCursor* GetMozSpinningCursor() { |
86 static GdkCursor* moz_spinning_cursor = NULL; | 81 static GdkCursor* moz_spinning_cursor = NULL; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 342 |
348 // TODO(evanm): why is this necessary here but not in test shell? | 343 // TODO(evanm): why is this necessary here but not in test shell? |
349 // This logic is the same as GtkButton. | 344 // This logic is the same as GtkButton. |
350 if (event->type == GDK_BUTTON_PRESS && !gtk_widget_has_focus(widget)) | 345 if (event->type == GDK_BUTTON_PRESS && !gtk_widget_has_focus(widget)) |
351 gtk_widget_grab_focus(widget); | 346 gtk_widget_grab_focus(widget); |
352 | 347 |
353 host_view->is_popup_first_mouse_release_ = false; | 348 host_view->is_popup_first_mouse_release_ = false; |
354 RenderWidgetHostImpl* widget_host = | 349 RenderWidgetHostImpl* widget_host = |
355 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost()); | 350 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost()); |
356 if (widget_host) | 351 if (widget_host) |
357 widget_host->ForwardMouseEvent(WebInputEventFactory::mouseEvent(event)); | 352 widget_host->ForwardMouseEvent(WebMouseEventBuilder::Build(event)); |
358 | 353 |
359 // Although we did handle the mouse event, we need to let other handlers | 354 // Although we did handle the mouse event, we need to let other handlers |
360 // run (in particular the one installed by WebContentsViewGtk). | 355 // run (in particular the one installed by WebContentsViewGtk). |
361 return FALSE; | 356 return FALSE; |
362 } | 357 } |
363 | 358 |
364 static gboolean OnMouseMoveEvent(GtkWidget* widget, | 359 static gboolean OnMouseMoveEvent(GtkWidget* widget, |
365 GdkEventMotion* event, | 360 GdkEventMotion* event, |
366 RenderWidgetHostViewGtk* host_view) { | 361 RenderWidgetHostViewGtk* host_view) { |
367 TRACE_EVENT0("browser", | 362 TRACE_EVENT0("browser", |
368 "RenderWidgetHostViewGtkWidget::OnMouseMoveEvent"); | 363 "RenderWidgetHostViewGtkWidget::OnMouseMoveEvent"); |
369 // We want to translate the coordinates of events that do not originate | 364 // We want to translate the coordinates of events that do not originate |
370 // from this widget to be relative to the top left of the widget. | 365 // from this widget to be relative to the top left of the widget. |
371 GtkWidget* event_widget = gtk_get_event_widget( | 366 GtkWidget* event_widget = gtk_get_event_widget( |
372 reinterpret_cast<GdkEvent*>(event)); | 367 reinterpret_cast<GdkEvent*>(event)); |
373 if (event_widget != widget) { | 368 if (event_widget != widget) { |
374 int x = 0; | 369 int x = 0; |
375 int y = 0; | 370 int y = 0; |
376 gtk_widget_get_pointer(widget, &x, &y); | 371 gtk_widget_get_pointer(widget, &x, &y); |
377 event->x = x; | 372 event->x = x; |
378 event->y = y; | 373 event->y = y; |
379 } | 374 } |
380 | 375 |
381 host_view->ModifyEventForEdgeDragging(widget, event); | 376 host_view->ModifyEventForEdgeDragging(widget, event); |
382 | 377 |
383 WebKit::WebMouseEvent mouse_event = | 378 WebKit::WebMouseEvent mouse_event = WebMouseEventBuilder::Build(event); |
384 WebInputEventFactory::mouseEvent(event); | |
385 | 379 |
386 if (host_view->mouse_locked_) { | 380 if (host_view->mouse_locked_) { |
387 gfx::Point center = host_view->GetWidgetCenter(); | 381 gfx::Point center = host_view->GetWidgetCenter(); |
388 | 382 |
389 bool moved_to_center = MovedToPoint(mouse_event, center); | 383 bool moved_to_center = MovedToPoint(mouse_event, center); |
390 if (moved_to_center) | 384 if (moved_to_center) |
391 host_view->mouse_has_been_warped_to_new_center_ = true; | 385 host_view->mouse_has_been_warped_to_new_center_ = true; |
392 | 386 |
393 host_view->ModifyEventMovementAndCoords(&mouse_event); | 387 host_view->ModifyEventMovementAndCoords(&mouse_event); |
394 | 388 |
(...skipping 29 matching lines...) Expand all Loading... |
424 GDK_BUTTON3_MASK | | 418 GDK_BUTTON3_MASK | |
425 GDK_BUTTON4_MASK | | 419 GDK_BUTTON4_MASK | |
426 GDK_BUTTON5_MASK; | 420 GDK_BUTTON5_MASK; |
427 | 421 |
428 // Only forward crossing events if the mouse button is not down. | 422 // Only forward crossing events if the mouse button is not down. |
429 // (When the mouse button is down, the proper events are already being | 423 // (When the mouse button is down, the proper events are already being |
430 // sent by ButtonPressReleaseEvent and MouseMoveEvent, above, and if we | 424 // sent by ButtonPressReleaseEvent and MouseMoveEvent, above, and if we |
431 // additionally send this crossing event with the state indicating the | 425 // additionally send this crossing event with the state indicating the |
432 // button is down, it causes problems with drag and drop in WebKit.) | 426 // button is down, it causes problems with drag and drop in WebKit.) |
433 if (!(event->state & any_button_mask)) { | 427 if (!(event->state & any_button_mask)) { |
434 WebKit::WebMouseEvent mouse_event = | 428 WebKit::WebMouseEvent mouse_event = WebMouseEventBuilder::Build(event); |
435 WebInputEventFactory::mouseEvent(event); | |
436 host_view->ModifyEventMovementAndCoords(&mouse_event); | 429 host_view->ModifyEventMovementAndCoords(&mouse_event); |
437 // When crossing out and back into a render view the movement values | 430 // When crossing out and back into a render view the movement values |
438 // must represent the instantaneous movement of the mouse, not the jump | 431 // must represent the instantaneous movement of the mouse, not the jump |
439 // from the exit to re-entry point. | 432 // from the exit to re-entry point. |
440 mouse_event.movementX = 0; | 433 mouse_event.movementX = 0; |
441 mouse_event.movementY = 0; | 434 mouse_event.movementY = 0; |
442 RenderWidgetHostImpl::From( | 435 RenderWidgetHostImpl::From( |
443 host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event); | 436 host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event); |
444 } | 437 } |
445 | 438 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 } | 486 } |
494 } | 487 } |
495 } | 488 } |
496 } | 489 } |
497 } | 490 } |
498 // If we have an event left we put it back on the queue. | 491 // If we have an event left we put it back on the queue. |
499 if (event) { | 492 if (event) { |
500 gdk_event_put(event); | 493 gdk_event_put(event); |
501 gdk_event_free(event); | 494 gdk_event_free(event); |
502 } | 495 } |
503 return num_clicks * kDefaultScrollPixelsPerTick; | 496 return num_clicks * WebMouseWheelEventBuilder::ScrollbarPixelsPerTick(); |
504 } | 497 } |
505 | 498 |
506 static gboolean OnMouseScrollEvent(GtkWidget* widget, | 499 static gboolean OnMouseScrollEvent(GtkWidget* widget, |
507 GdkEventScroll* event, | 500 GdkEventScroll* event, |
508 RenderWidgetHostViewGtk* host_view) { | 501 RenderWidgetHostViewGtk* host_view) { |
509 TRACE_EVENT0("browser", | 502 TRACE_EVENT0("browser", |
510 "RenderWidgetHostViewGtkWidget::OnMouseScrollEvent"); | 503 "RenderWidgetHostViewGtkWidget::OnMouseScrollEvent"); |
511 // If the user is holding shift, translate it into a horizontal scroll. We | 504 // If the user is holding shift, translate it into a horizontal scroll. We |
512 // don't care what other modifiers the user may be holding (zooming is | 505 // don't care what other modifiers the user may be holding (zooming is |
513 // handled at the WebContentsView level). | 506 // handled at the WebContentsView level). |
514 if (event->state & GDK_SHIFT_MASK) { | 507 if (event->state & GDK_SHIFT_MASK) { |
515 if (event->direction == GDK_SCROLL_UP) | 508 if (event->direction == GDK_SCROLL_UP) |
516 event->direction = GDK_SCROLL_LEFT; | 509 event->direction = GDK_SCROLL_LEFT; |
517 else if (event->direction == GDK_SCROLL_DOWN) | 510 else if (event->direction == GDK_SCROLL_DOWN) |
518 event->direction = GDK_SCROLL_RIGHT; | 511 event->direction = GDK_SCROLL_RIGHT; |
519 } | 512 } |
520 | 513 |
521 WebMouseWheelEvent web_event = WebInputEventFactory::mouseWheelEvent(event); | 514 WebMouseWheelEvent web_event = WebMouseWheelEventBuilder::Build(event); |
| 515 const float pixelsPerTick = |
| 516 WebMouseWheelEventBuilder::ScrollbarPixelsPerTick(); |
522 // We peek ahead at the top of the queue to look for additional pending | 517 // We peek ahead at the top of the queue to look for additional pending |
523 // scroll events. | 518 // scroll events. |
524 if (event->direction == GDK_SCROLL_UP || | 519 if (event->direction == GDK_SCROLL_UP || |
525 event->direction == GDK_SCROLL_DOWN) { | 520 event->direction == GDK_SCROLL_DOWN) { |
526 if (event->direction == GDK_SCROLL_UP) | 521 if (event->direction == GDK_SCROLL_UP) |
527 web_event.deltaY = kDefaultScrollPixelsPerTick; | 522 web_event.deltaY = pixelsPerTick; |
528 else | 523 else |
529 web_event.deltaY = -kDefaultScrollPixelsPerTick; | 524 web_event.deltaY = -pixelsPerTick; |
530 web_event.deltaY += GetPendingScrollDelta(true, event->state); | 525 web_event.deltaY += GetPendingScrollDelta(true, event->state); |
531 } else { | 526 } else { |
532 if (event->direction == GDK_SCROLL_LEFT) | 527 if (event->direction == GDK_SCROLL_LEFT) |
533 web_event.deltaX = kDefaultScrollPixelsPerTick; | 528 web_event.deltaX = pixelsPerTick; |
534 else | 529 else |
535 web_event.deltaX = -kDefaultScrollPixelsPerTick; | 530 web_event.deltaX = -pixelsPerTick; |
536 web_event.deltaX += GetPendingScrollDelta(false, event->state); | 531 web_event.deltaX += GetPendingScrollDelta(false, event->state); |
537 } | 532 } |
538 RenderWidgetHostImpl::From( | 533 RenderWidgetHostImpl::From( |
539 host_view->GetRenderWidgetHost())->ForwardWheelEvent(web_event); | 534 host_view->GetRenderWidgetHost())->ForwardWheelEvent(web_event); |
540 return FALSE; | 535 return FALSE; |
541 } | 536 } |
542 | 537 |
543 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); | 538 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); |
544 }; | 539 }; |
545 | 540 |
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 gfx::PluginWindowHandle id) { | 1572 gfx::PluginWindowHandle id) { |
1578 plugin_container_manager_.CreatePluginContainer(id); | 1573 plugin_container_manager_.CreatePluginContainer(id); |
1579 } | 1574 } |
1580 | 1575 |
1581 void RenderWidgetHostViewGtk::OnDestroyPluginContainer( | 1576 void RenderWidgetHostViewGtk::OnDestroyPluginContainer( |
1582 gfx::PluginWindowHandle id) { | 1577 gfx::PluginWindowHandle id) { |
1583 plugin_container_manager_.DestroyPluginContainer(id); | 1578 plugin_container_manager_.DestroyPluginContainer(id); |
1584 } | 1579 } |
1585 | 1580 |
1586 } // namespace content | 1581 } // namespace content |
OLD | NEW |