| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser/renderer_host/render_widget_host_view_gtk.h" | 5 #include "chrome/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 URLRequestStatus::Status. | 9 // badly with URLRequestStatus::Status. |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 #if defined(OS_CHROMEOS) | 42 #if defined(OS_CHROMEOS) |
| 43 #include "views/widget/tooltip_window_gtk.h" | 43 #include "views/widget/tooltip_window_gtk.h" |
| 44 #endif // defined(OS_CHROMEOS) | 44 #endif // defined(OS_CHROMEOS) |
| 45 | 45 |
| 46 static const int kMaxWindowWidth = 4000; | 46 static const int kMaxWindowWidth = 4000; |
| 47 static const int kMaxWindowHeight = 4000; | 47 static const int kMaxWindowHeight = 4000; |
| 48 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; | 48 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; |
| 49 | 49 |
| 50 #if defined(OS_CHROMEOS) | 50 #if defined(OS_CHROMEOS) |
| 51 static const float kDefaultVertScrollDelta = 20.0; | 51 // TODO(davemoore) Under Chromeos we are increasing the rate that the trackpad |
| 52 // generates events to get better precisions. Eventually we will coordinate the |
| 53 // driver and this setting to ensure they match. |
| 54 static const float kDefaultScrollPixelsPerTick = 20; |
| 55 #else |
| 56 // See WebInputEventFactor.cpp for a reason for this being the default |
| 57 // scroll size for linux. |
| 58 static const float kDefaultScrollPixelsPerTick = 160.0f / 3.0f; |
| 52 #endif | 59 #endif |
| 53 | 60 |
| 54 using WebKit::WebInputEventFactory; | 61 using WebKit::WebInputEventFactory; |
| 55 using WebKit::WebMouseWheelEvent; | 62 using WebKit::WebMouseWheelEvent; |
| 56 | 63 |
| 57 // This class is a simple convenience wrapper for Gtk functions. It has only | 64 // This class is a simple convenience wrapper for Gtk functions. It has only |
| 58 // static methods. | 65 // static methods. |
| 59 class RenderWidgetHostViewGtkWidget { | 66 class RenderWidgetHostViewGtkWidget { |
| 60 public: | 67 public: |
| 61 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { | 68 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 310 } |
| 304 | 311 |
| 305 static gboolean ClientEvent(GtkWidget* widget, GdkEventClient* event, | 312 static gboolean ClientEvent(GtkWidget* widget, GdkEventClient* event, |
| 306 RenderWidgetHostViewGtk* host_view) { | 313 RenderWidgetHostViewGtk* host_view) { |
| 307 LOG(INFO) << "client event type: " << event->message_type | 314 LOG(INFO) << "client event type: " << event->message_type |
| 308 << " data_format: " << event->data_format | 315 << " data_format: " << event->data_format |
| 309 << " data: " << event->data.l; | 316 << " data: " << event->data.l; |
| 310 return true; | 317 return true; |
| 311 } | 318 } |
| 312 | 319 |
| 313 #if defined(OS_CHROMEOS) | |
| 314 // Allow the vertical scroll delta to be overridden from the command line. | 320 // Allow the vertical scroll delta to be overridden from the command line. |
| 315 // This will allow us to test more easily to discover the amount | 321 // This will allow us to test more easily to discover the amount |
| 316 // (either hard coded or computed) that's best. | 322 // (either hard coded or computed) that's best. |
| 317 static float GetVertScrollDelta() { | 323 static float GetScrollPixelsPerTick() { |
| 318 static float vert_scroll_delta = -1; | 324 static float scroll_pixels = -1; |
| 319 if (vert_scroll_delta < 0) { | 325 if (scroll_pixels < 0) { |
| 320 vert_scroll_delta = kDefaultVertScrollDelta; | 326 scroll_pixels = kDefaultScrollPixelsPerTick; |
| 321 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 327 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 322 std::string vert_scroll_option = | 328 std::string scroll_pixels_option = |
| 323 command_line->GetSwitchValueASCII(switches::kVertScrollDelta); | 329 command_line->GetSwitchValueASCII(switches::kScrollPixels); |
| 324 if (!vert_scroll_option.empty()) { | 330 if (!scroll_pixels_option.empty()) { |
| 325 double v; | 331 double v; |
| 326 if (StringToDouble(vert_scroll_option, &v)) | 332 if (StringToDouble(scroll_pixels_option, &v)) |
| 327 vert_scroll_delta = static_cast<float>(v); | 333 scroll_pixels = static_cast<float>(v); |
| 328 } | 334 } |
| 329 DCHECK_GT(vert_scroll_delta, 0); | 335 DCHECK_GT(scroll_pixels, 0); |
| 330 } | 336 } |
| 331 return vert_scroll_delta; | 337 return scroll_pixels; |
| 332 } | 338 } |
| 333 #endif | 339 |
| 340 // Return the net up / down (or left / right) distance represented by events |
| 341 // in the events will be removed from the queue. We only look at the top of |
| 342 // queue...any other type of event will cause us not to look farther. |
| 343 // If there is a change to the set of modifier keys or scroll axis |
| 344 // in the events we will stop looking as well. |
| 345 static int GetPendingScrollDelta(bool vert, guint current_event_state) { |
| 346 int num_clicks = 0; |
| 347 GdkEvent* event; |
| 348 bool event_coalesced = true; |
| 349 while ((event = gdk_event_get()) && event_coalesced) { |
| 350 event_coalesced = false; |
| 351 if (event->type == GDK_SCROLL) { |
| 352 GdkEventScroll scroll = event->scroll; |
| 353 if (scroll.state & GDK_SHIFT_MASK) { |
| 354 if (scroll.direction == GDK_SCROLL_UP) |
| 355 scroll.direction = GDK_SCROLL_LEFT; |
| 356 else if (scroll.direction == GDK_SCROLL_DOWN) |
| 357 scroll.direction = GDK_SCROLL_RIGHT; |
| 358 } |
| 359 if (vert) { |
| 360 if (scroll.direction == GDK_SCROLL_UP || |
| 361 scroll.direction == GDK_SCROLL_DOWN) { |
| 362 if (scroll.state == current_event_state) { |
| 363 num_clicks += (scroll.direction == GDK_SCROLL_UP ? 1 : -1); |
| 364 gdk_event_free(event); |
| 365 event_coalesced = true; |
| 366 } |
| 367 } |
| 368 } else { |
| 369 if (scroll.direction == GDK_SCROLL_RIGHT || |
| 370 scroll.direction == GDK_SCROLL_LEFT) { |
| 371 if (scroll.state == current_event_state) { |
| 372 num_clicks += (scroll.direction == GDK_SCROLL_RIGHT ? 1 : -1); |
| 373 gdk_event_free(event); |
| 374 event_coalesced = true; |
| 375 } |
| 376 } |
| 377 } |
| 378 } |
| 379 } |
| 380 // If we have an event left we put it back on the queue. |
| 381 if (event) { |
| 382 gdk_event_put(event); |
| 383 gdk_event_free(event); |
| 384 } |
| 385 return num_clicks * GetScrollPixelsPerTick(); |
| 386 } |
| 334 | 387 |
| 335 static gboolean MouseScrollEvent(GtkWidget* widget, GdkEventScroll* event, | 388 static gboolean MouseScrollEvent(GtkWidget* widget, GdkEventScroll* event, |
| 336 RenderWidgetHostViewGtk* host_view) { | 389 RenderWidgetHostViewGtk* host_view) { |
| 337 // If the user is holding shift, translate it into a horizontal scroll. We | 390 // If the user is holding shift, translate it into a horizontal scroll. We |
| 338 // don't care what other modifiers the user may be holding (zooming is | 391 // don't care what other modifiers the user may be holding (zooming is |
| 339 // handled at the TabContentsView level). | 392 // handled at the TabContentsView level). |
| 340 if (event->state & GDK_SHIFT_MASK) { | 393 if (event->state & GDK_SHIFT_MASK) { |
| 341 if (event->direction == GDK_SCROLL_UP) | 394 if (event->direction == GDK_SCROLL_UP) |
| 342 event->direction = GDK_SCROLL_LEFT; | 395 event->direction = GDK_SCROLL_LEFT; |
| 343 else if (event->direction == GDK_SCROLL_DOWN) | 396 else if (event->direction == GDK_SCROLL_DOWN) |
| 344 event->direction = GDK_SCROLL_RIGHT; | 397 event->direction = GDK_SCROLL_RIGHT; |
| 345 } | 398 } |
| 346 | 399 |
| 347 WebMouseWheelEvent web_event = WebInputEventFactory::mouseWheelEvent(event); | 400 WebMouseWheelEvent web_event = WebInputEventFactory::mouseWheelEvent(event); |
| 348 #if defined (OS_CHROMEOS) | 401 // We peek ahead at the top of the queue to look for additional pending |
| 349 // Under ChromeOS we know that the wheel is a touchpad. The driver for this | 402 // scroll events. |
| 350 // can generate events very quickly. We configure it to generate more | 403 if (event->direction == GDK_SCROLL_UP || |
| 351 // events and scroll by a smaller amount on each, to give us better | 404 event->direction == GDK_SCROLL_DOWN) { |
| 352 // precision. This is only configured for vertical scrolling, and | |
| 353 // doesn't apply if we are using the shift modifier to cause a horizontal | |
| 354 // scroll. | |
| 355 if (!(event->state & GDK_SHIFT_MASK)) { | |
| 356 if (event->direction == GDK_SCROLL_UP) | 405 if (event->direction == GDK_SCROLL_UP) |
| 357 web_event.deltaY = GetVertScrollDelta(); | 406 web_event.deltaY = GetScrollPixelsPerTick(); |
| 358 else | 407 else |
| 359 web_event.deltaY = -GetVertScrollDelta(); | 408 web_event.deltaY = -GetScrollPixelsPerTick(); |
| 409 web_event.deltaY += GetPendingScrollDelta(true, event->state); |
| 410 } else { |
| 411 if (event->direction == GDK_SCROLL_RIGHT) |
| 412 web_event.deltaX = GetScrollPixelsPerTick(); |
| 413 else |
| 414 web_event.deltaX = -GetScrollPixelsPerTick(); |
| 415 web_event.deltaX += GetPendingScrollDelta(false, event->state); |
| 360 } | 416 } |
| 361 #endif // OS_CHROMEOS | |
| 362 host_view->GetRenderWidgetHost()->ForwardWheelEvent(web_event); | 417 host_view->GetRenderWidgetHost()->ForwardWheelEvent(web_event); |
| 363 return FALSE; | 418 return FALSE; |
| 364 } | 419 } |
| 365 | 420 |
| 366 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); | 421 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); |
| 367 }; | 422 }; |
| 368 | 423 |
| 369 // static | 424 // static |
| 370 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | 425 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( |
| 371 RenderWidgetHost* widget) { | 426 RenderWidgetHost* widget) { |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 } | 965 } |
| 911 | 966 |
| 912 // static | 967 // static |
| 913 RenderWidgetHostView* | 968 RenderWidgetHostView* |
| 914 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 969 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
| 915 gfx::NativeView widget) { | 970 gfx::NativeView widget) { |
| 916 gpointer user_data = g_object_get_data(G_OBJECT(widget), | 971 gpointer user_data = g_object_get_data(G_OBJECT(widget), |
| 917 kRenderWidgetHostViewKey); | 972 kRenderWidgetHostViewKey); |
| 918 return reinterpret_cast<RenderWidgetHostView*>(user_data); | 973 return reinterpret_cast<RenderWidgetHostView*>(user_data); |
| 919 } | 974 } |
| OLD | NEW |