Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1360)

Side by Side Diff: chrome/common/gtk_util.cc

Issue 131071: Implement window open disposition for (some) navigation buttons.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: bool->int Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/gtk_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/common/gtk_util.h" 5 #include "chrome/common/gtk_util.h"
6 6
7 #include <cstdarg> 7 #include <cstdarg>
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #include <gdk/gdkx.h> 9 #include <gdk/gdkx.h>
10 10
11 #include "base/linux_util.h" 11 #include "base/linux_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
14 14
15 namespace { 15 namespace {
16 16
17 // Callback used in RemoveAllChildren. 17 // Callback used in RemoveAllChildren.
18 void RemoveWidget(GtkWidget* widget, gpointer container) { 18 void RemoveWidget(GtkWidget* widget, gpointer container) {
19 gtk_container_remove(GTK_CONTAINER(container), widget); 19 gtk_container_remove(GTK_CONTAINER(container), widget);
20 } 20 }
21 21
22 // These two functions are copped almost directly from gtk core. The only
23 // difference is that they accept middle clicks.
24 gboolean OnMouseButtonPressed(GtkWidget* widget, GdkEventButton* event,
25 gpointer unused) {
26 if (event->type == GDK_BUTTON_PRESS) {
27 if (gtk_button_get_focus_on_click(GTK_BUTTON(widget)) &&
28 !GTK_WIDGET_HAS_FOCUS(widget)) {
29 gtk_widget_grab_focus(widget);
30 }
31
32 if (event->button == 1 || event->button == 2)
33 gtk_button_pressed(GTK_BUTTON(widget));
34 }
35
36 return TRUE;
37 }
38
39 gboolean OnMouseButtonReleased(GtkWidget* widget, GdkEventButton* event,
40 gpointer unused) {
41 if (event->button == 1 || event->button == 2)
42 gtk_button_released(GTK_BUTTON(widget));
43
44 return TRUE;
45 }
46
22 } // namespace 47 } // namespace
23 48
24 namespace event_utils { 49 namespace event_utils {
25 50
26 WindowOpenDisposition DispositionFromEventFlags(guint event_flags) { 51 WindowOpenDisposition DispositionFromEventFlags(guint event_flags) {
27 if ((event_flags & GDK_BUTTON2_MASK) || (event_flags & GDK_CONTROL_MASK)) { 52 if ((event_flags & GDK_BUTTON2_MASK) || (event_flags & GDK_CONTROL_MASK)) {
28 return (event_flags & GDK_SHIFT_MASK) ? 53 return (event_flags & GDK_SHIFT_MASK) ?
29 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; 54 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
30 } 55 }
31 56
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 GdkWindow* window = static_cast<GdkWindow*>(iter->data); 225 GdkWindow* window = static_cast<GdkWindow*>(iter->data);
201 XID xid = GDK_WINDOW_XID(window); 226 XID xid = GDK_WINDOW_XID(window);
202 if (delegate->ShouldStopIterating(xid)) 227 if (delegate->ShouldStopIterating(xid))
203 break; 228 break;
204 } 229 }
205 230
206 g_list_foreach(stack, (GFunc)g_object_unref, NULL); 231 g_list_foreach(stack, (GFunc)g_object_unref, NULL);
207 g_list_free(stack); 232 g_list_free(stack);
208 } 233 }
209 234
235 void SetButtonTriggersNavigation(GtkWidget* button) {
236 // We handle button activation manually because we want to accept middle mouse
237 // clicks.
238 g_signal_connect(G_OBJECT(button), "button-press-event",
239 G_CALLBACK(OnMouseButtonPressed), NULL);
240 g_signal_connect(G_OBJECT(button), "button-release-event",
241 G_CALLBACK(OnMouseButtonReleased), NULL);
242 }
243
210 } // namespace gtk_util 244 } // namespace gtk_util
OLDNEW
« no previous file with comments | « chrome/common/gtk_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698