diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-03 22:51:52 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-03 22:51:52 +0000 |
commit | 32e851ac4653283d8602cdf20ac1c689416389c8 (patch) | |
tree | f2a332366a9f8b2965b0d70c0a4127aa1293c485 /views/widget | |
parent | d48fd7b8104831e3c5481ca1269f40a9b22271ae (diff) | |
download | chromium_src-32e851ac4653283d8602cdf20ac1c689416389c8.zip chromium_src-32e851ac4653283d8602cdf20ac1c689416389c8.tar.gz chromium_src-32e851ac4653283d8602cdf20ac1c689416389c8.tar.bz2 |
Checking in patch for Denis Romanov (originally reviewed here: http://codereview.chromium.org/651027).
Make mouse wheel scroll contents of views::ScrollView control in Linux (GTK).
BUG=26970
TEST=Make and run out/Debug/view_examples and scroll in ScrollView tab.
TBR=denisromanov
Review URL: http://codereview.chromium.org/667008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40555 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/widget_gtk.cc | 56 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 26 |
2 files changed, 64 insertions, 18 deletions
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 7cce516..7cb0278 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -807,8 +807,7 @@ gboolean WidgetGtk::OnMotionNotify(GtkWidget* widget, GdkEventMotion* event) { } gboolean WidgetGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event) { - ProcessMousePressed(event); - return true; + return ProcessMousePressed(event); } gboolean WidgetGtk::OnButtonRelease(GtkWidget* widget, GdkEventButton* event) { @@ -816,6 +815,10 @@ gboolean WidgetGtk::OnButtonRelease(GtkWidget* widget, GdkEventButton* event) { return true; } +gboolean WidgetGtk::OnScroll(GtkWidget* widget, GdkEventScroll* event) { + return ProcessScroll(event); +} + gboolean WidgetGtk::OnFocusIn(GtkWidget* widget, GdkEventFocus* event) { if (has_focus_) return false; // This is the second focus-in event in a row, ignore it. @@ -936,18 +939,10 @@ bool WidgetGtk::ProcessMousePressed(GdkEventButton* event) { return true; } - // An event may come from a child widget which has its own gdk window. - // Translate it to the widget's cooridnate. - int x = event->x; - int y = event->y; - GdkWindow* dest = GTK_WIDGET(window_contents_)->window; - if (event->window != dest) { - int dest_x, dest_y; - gdk_window_get_root_origin(dest, &dest_x, &dest_y); - x = event->x_root - dest_x; - y = event->y_root - dest_y; - } - + // An event may come from a contained widget which has its own gdk window. + // Translate it to the widget's coordinates. + int x, y; + GetContainedWidgetEventCoordinates(event, &x, &y); last_mouse_event_was_move_ = false; MouseEvent mouse_pressed(Event::ET_MOUSE_PRESSED, x, y, GetFlagsForEventButton(*event)); @@ -968,7 +963,6 @@ void WidgetGtk::ProcessMouseReleased(GdkEventButton* event) { GetFlagsForEventButton(*event)); // Release the capture first, that way we don't get confused if // OnMouseReleased blocks. - if (has_capture_ && ReleaseCaptureOnMouseReleased()) ReleaseGrab(); is_mouse_down_ = false; @@ -977,6 +971,38 @@ void WidgetGtk::ProcessMouseReleased(GdkEventButton* event) { root_view_->OnMouseReleased(mouse_up, false); } +bool WidgetGtk::ProcessScroll(GdkEventScroll* event) { + // An event may come from a contained widget which has its own gdk window. + // Translate it to the widget's coordinates. + int x, y; + GetContainedWidgetEventCoordinates(event, &x, &y); + int flags = Event::GetFlagsFromGdkState(event->state); + int increment = 0; + bool is_horizontal; + switch (event->direction) { + case GDK_SCROLL_UP: + increment = -1; + is_horizontal = false; + break; + case GDK_SCROLL_DOWN: + increment = 1; + is_horizontal = false; + break; + case GDK_SCROLL_LEFT: + increment = -1; + is_horizontal = true; + break; + case GDK_SCROLL_RIGHT: + increment = 1; + is_horizontal = false; + break; + } + increment *= is_horizontal ? root_view_->width() / 5 : + root_view_->height() / 5; + MouseWheelEvent wheel_event(increment, x, y, flags); + return root_view_->ProcessMouseWheelEvent(wheel_event); +} + // static void WidgetGtk::SetRootViewForWidget(GtkWidget* widget, RootView* root_view) { g_object_set_data(G_OBJECT(widget), "root-view", root_view); diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index 0c0096c..29d99be 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -186,6 +186,26 @@ class WidgetGtk virtual View* GetFocusTraversableParentView(); protected: + // If widget containes another widget, translates event coordinates to the + // contained widget's coordinates, else returns original event coordinates. + template<class Event> bool GetContainedWidgetEventCoordinates(Event* event, + int* x, + int* y) { + if (event == NULL || x == NULL || y == NULL) + return false; + *x = event->x; + *y = event->y; + GdkWindow* dest = GTK_WIDGET(window_contents_)->window; + if (event->window != dest) { + int dest_x, dest_y; + gdk_window_get_root_origin(dest, &dest_x, &dest_y); + *x = event->x_root - dest_x; + *y = event->y_root - dest_y; + return true; + } + return false; + } + // Returns the view::Event::flags for a GdkEventButton. static int GetFlagsForEventButton(const GdkEventButton& event); @@ -228,9 +248,7 @@ class WidgetGtk gint y, gboolean keyboard_mode, GtkTooltip* tooltip); - virtual gboolean OnScroll(GtkWidget* widget, GdkEventScroll* event) { - return false; - } + virtual gboolean OnScroll(GtkWidget* widget, GdkEventScroll* event); virtual gboolean OnVisibilityNotify(GtkWidget* widget, GdkEventVisibility* event) { return false; @@ -271,6 +289,8 @@ class WidgetGtk // Process a mouse click. bool ProcessMousePressed(GdkEventButton* event); void ProcessMouseReleased(GdkEventButton* event); + // Process scroll event. + bool ProcessScroll(GdkEventScroll* event); static void SetRootViewForWidget(GtkWidget* widget, RootView* root_view); |