| 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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 449 |
| 450 static gboolean OnClientEvent(GtkWidget* widget, | 450 static gboolean OnClientEvent(GtkWidget* widget, |
| 451 GdkEventClient* event, | 451 GdkEventClient* event, |
| 452 RenderWidgetHostViewGtk* host_view) { | 452 RenderWidgetHostViewGtk* host_view) { |
| 453 VLOG(1) << "client event type: " << event->message_type | 453 VLOG(1) << "client event type: " << event->message_type |
| 454 << " data_format: " << event->data_format | 454 << " data_format: " << event->data_format |
| 455 << " data: " << event->data.l; | 455 << " data: " << event->data.l; |
| 456 return TRUE; | 456 return TRUE; |
| 457 } | 457 } |
| 458 | 458 |
| 459 // Allow the vertical scroll delta to be overridden from the command line. | |
| 460 // This will allow us to test more easily to discover the amount | |
| 461 // (either hard coded or computed) that's best. | |
| 462 static float GetScrollPixelsPerTick() { | |
| 463 static float scroll_pixels = -1; | |
| 464 if (scroll_pixels < 0) { | |
| 465 // TODO(brettw): Remove the command line switch (crbug.com/63525) | |
| 466 scroll_pixels = kDefaultScrollPixelsPerTick; | |
| 467 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 468 std::string scroll_pixels_option = | |
| 469 command_line->GetSwitchValueASCII(switches::kScrollPixels); | |
| 470 if (!scroll_pixels_option.empty()) { | |
| 471 double v; | |
| 472 if (base::StringToDouble(scroll_pixels_option, &v)) | |
| 473 scroll_pixels = static_cast<float>(v); | |
| 474 } | |
| 475 DCHECK_GT(scroll_pixels, 0); | |
| 476 } | |
| 477 return scroll_pixels; | |
| 478 } | |
| 479 | |
| 480 // Return the net up / down (or left / right) distance represented by events | 459 // Return the net up / down (or left / right) distance represented by events |
| 481 // in the events will be removed from the queue. We only look at the top of | 460 // in the events will be removed from the queue. We only look at the top of |
| 482 // queue...any other type of event will cause us not to look farther. | 461 // queue...any other type of event will cause us not to look farther. |
| 483 // If there is a change to the set of modifier keys or scroll axis | 462 // If there is a change to the set of modifier keys or scroll axis |
| 484 // in the events we will stop looking as well. | 463 // in the events we will stop looking as well. |
| 485 static int GetPendingScrollDelta(bool vert, guint current_event_state) { | 464 static int GetPendingScrollDelta(bool vert, guint current_event_state) { |
| 486 int num_clicks = 0; | 465 int num_clicks = 0; |
| 487 GdkEvent* event; | 466 GdkEvent* event; |
| 488 bool event_coalesced = true; | 467 bool event_coalesced = true; |
| 489 while ((event = gdk_event_get()) && event_coalesced) { | 468 while ((event = gdk_event_get()) && event_coalesced) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 515 } | 494 } |
| 516 } | 495 } |
| 517 } | 496 } |
| 518 } | 497 } |
| 519 } | 498 } |
| 520 // If we have an event left we put it back on the queue. | 499 // If we have an event left we put it back on the queue. |
| 521 if (event) { | 500 if (event) { |
| 522 gdk_event_put(event); | 501 gdk_event_put(event); |
| 523 gdk_event_free(event); | 502 gdk_event_free(event); |
| 524 } | 503 } |
| 525 return num_clicks * GetScrollPixelsPerTick(); | 504 return num_clicks * kDefaultScrollPixelsPerTick; |
| 526 } | 505 } |
| 527 | 506 |
| 528 static gboolean OnMouseScrollEvent(GtkWidget* widget, | 507 static gboolean OnMouseScrollEvent(GtkWidget* widget, |
| 529 GdkEventScroll* event, | 508 GdkEventScroll* event, |
| 530 RenderWidgetHostViewGtk* host_view) { | 509 RenderWidgetHostViewGtk* host_view) { |
| 531 TRACE_EVENT0("browser", | 510 TRACE_EVENT0("browser", |
| 532 "RenderWidgetHostViewGtkWidget::OnMouseScrollEvent"); | 511 "RenderWidgetHostViewGtkWidget::OnMouseScrollEvent"); |
| 533 // If the user is holding shift, translate it into a horizontal scroll. We | 512 // If the user is holding shift, translate it into a horizontal scroll. We |
| 534 // don't care what other modifiers the user may be holding (zooming is | 513 // don't care what other modifiers the user may be holding (zooming is |
| 535 // handled at the WebContentsView level). | 514 // handled at the WebContentsView level). |
| 536 if (event->state & GDK_SHIFT_MASK) { | 515 if (event->state & GDK_SHIFT_MASK) { |
| 537 if (event->direction == GDK_SCROLL_UP) | 516 if (event->direction == GDK_SCROLL_UP) |
| 538 event->direction = GDK_SCROLL_LEFT; | 517 event->direction = GDK_SCROLL_LEFT; |
| 539 else if (event->direction == GDK_SCROLL_DOWN) | 518 else if (event->direction == GDK_SCROLL_DOWN) |
| 540 event->direction = GDK_SCROLL_RIGHT; | 519 event->direction = GDK_SCROLL_RIGHT; |
| 541 } | 520 } |
| 542 | 521 |
| 543 WebMouseWheelEvent web_event = WebInputEventFactory::mouseWheelEvent(event); | 522 WebMouseWheelEvent web_event = WebInputEventFactory::mouseWheelEvent(event); |
| 544 // We peek ahead at the top of the queue to look for additional pending | 523 // We peek ahead at the top of the queue to look for additional pending |
| 545 // scroll events. | 524 // scroll events. |
| 546 if (event->direction == GDK_SCROLL_UP || | 525 if (event->direction == GDK_SCROLL_UP || |
| 547 event->direction == GDK_SCROLL_DOWN) { | 526 event->direction == GDK_SCROLL_DOWN) { |
| 548 if (event->direction == GDK_SCROLL_UP) | 527 if (event->direction == GDK_SCROLL_UP) |
| 549 web_event.deltaY = GetScrollPixelsPerTick(); | 528 web_event.deltaY = kDefaultScrollPixelsPerTick; |
| 550 else | 529 else |
| 551 web_event.deltaY = -GetScrollPixelsPerTick(); | 530 web_event.deltaY = -kDefaultScrollPixelsPerTick; |
| 552 web_event.deltaY += GetPendingScrollDelta(true, event->state); | 531 web_event.deltaY += GetPendingScrollDelta(true, event->state); |
| 553 } else { | 532 } else { |
| 554 if (event->direction == GDK_SCROLL_LEFT) | 533 if (event->direction == GDK_SCROLL_LEFT) |
| 555 web_event.deltaX = GetScrollPixelsPerTick(); | 534 web_event.deltaX = kDefaultScrollPixelsPerTick; |
| 556 else | 535 else |
| 557 web_event.deltaX = -GetScrollPixelsPerTick(); | 536 web_event.deltaX = -kDefaultScrollPixelsPerTick; |
| 558 web_event.deltaX += GetPendingScrollDelta(false, event->state); | 537 web_event.deltaX += GetPendingScrollDelta(false, event->state); |
| 559 } | 538 } |
| 560 RenderWidgetHostImpl::From( | 539 RenderWidgetHostImpl::From( |
| 561 host_view->GetRenderWidgetHost())->ForwardWheelEvent(web_event); | 540 host_view->GetRenderWidgetHost())->ForwardWheelEvent(web_event); |
| 562 return FALSE; | 541 return FALSE; |
| 563 } | 542 } |
| 564 | 543 |
| 565 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); | 544 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); |
| 566 }; | 545 }; |
| 567 | 546 |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 this)); | 1529 this)); |
| 1551 } | 1530 } |
| 1552 BrowserAccessibilityGtk* root = | 1531 BrowserAccessibilityGtk* root = |
| 1553 browser_accessibility_manager_->GetRoot()->ToBrowserAccessibilityGtk(); | 1532 browser_accessibility_manager_->GetRoot()->ToBrowserAccessibilityGtk(); |
| 1554 | 1533 |
| 1555 atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); | 1534 atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); |
| 1556 return root->GetAtkObject(); | 1535 return root->GetAtkObject(); |
| 1557 } | 1536 } |
| 1558 | 1537 |
| 1559 } // namespace content | 1538 } // namespace content |
| OLD | NEW |