~ubuntu-branches/ubuntu/wily/epiphany-browser/wily

1.1.48 by Gustavo Noronha Silva
Import upstream version 2.28.0
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
1 by Sebastien Bacher
Import upstream version 1.9.2
2
/*
1.1.15 by Sebastien Bacher
Import upstream version 2.16.1
3
 *  Copyright © 2004 Christian Persch
4
 *  Copyright © 2005 Philip Langdale
1 by Sebastien Bacher
Import upstream version 1.9.2
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2, or (at your option)
9
 *  any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
1.1.24 by Sebastien Bacher
Import upstream version 2.18.1
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1 by Sebastien Bacher
Import upstream version 1.9.2
19
 *
20
 */
21
22
#include "config.h"
23
#include "ephy-link-action.h"
24
25
#include "ephy-debug.h"
26
#include "ephy-gui.h"
1.7.4 by Jeremy Bicha
Import upstream version 3.3.4.1
27
#include "ephy-link.h"
28
#include "ephy-window-action.h"
1 by Sebastien Bacher
Import upstream version 1.9.2
29
1.1.39 by Sebastien Bacher
Import upstream version 2.23.91
30
#include <gtk/gtk.h>
1 by Sebastien Bacher
Import upstream version 1.9.2
31
1.7.4 by Jeremy Bicha
Import upstream version 3.3.4.1
32
G_DEFINE_TYPE_WITH_CODE (EphyLinkAction, ephy_link_action, EPHY_TYPE_WINDOW_ACTION,
33
			 G_IMPLEMENT_INTERFACE (EPHY_TYPE_LINK,
34
						NULL))
35
36
#define EPHY_LINK_ACTION_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_LINK_ACTION, EphyLinkActionPrivate))
37
38
struct _EphyLinkActionPrivate
39
{
40
	guint button;
41
};
1 by Sebastien Bacher
Import upstream version 1.9.2
42
43
static gboolean
44
proxy_button_press_event_cb (GtkButton *button,
1.7.4 by Jeremy Bicha
Import upstream version 3.3.4.1
45
			     GdkEventButton *event,
46
			     EphyLinkAction *action)
47
{
48
	action->priv->button = event->button;
1 by Sebastien Bacher
Import upstream version 1.9.2
49
50
	return FALSE;
51
}
52
53
static GtkWidget *
54
get_event_widget (GtkWidget *proxy)
55
{
56
	GtkWidget *widget;
57
1.1.48 by Gustavo Noronha Silva
Import upstream version 2.28.0
58
	/*
1 by Sebastien Bacher
Import upstream version 1.9.2
59
	 * Finding the interesting widget requires internal knowledge of
60
	 * the widgets in question. This can't be helped, but by keeping
61
	 * the sneaky code in one place, it can easily be updated.
62
	 */
63
	if (GTK_IS_MENU_ITEM (proxy))
64
	{
65
		/* Menu items already forward middle clicks */
66
		widget = NULL;
67
	}
68
	else if (GTK_IS_TOOL_BUTTON (proxy))
69
	{
70
		/* The tool button's button is the direct child */
71
		widget = gtk_bin_get_child (GTK_BIN (proxy));
72
	}
73
	else if (GTK_IS_BUTTON (proxy))
74
	{
75
		widget = proxy;
76
	}
77
	else
78
	{
79
		/* Don't touch anything we don't know about */
80
		widget = NULL;
81
	}
82
83
	return widget;
84
}
85
86
static void
87
ephy_link_action_connect_proxy (GtkAction *action, GtkWidget *proxy)
88
{
89
	GtkWidget *widget;
90
91
	LOG ("Connect link action proxy");
92
1.7.4 by Jeremy Bicha
Import upstream version 3.3.4.1
93
	widget = get_event_widget (proxy);
1 by Sebastien Bacher
Import upstream version 1.9.2
94
	if (widget)
95
	{
96
		g_signal_connect (widget, "button-press-event",
97
				  G_CALLBACK (proxy_button_press_event_cb),
98
				  action);
99
	}
100
1.1.35 by Alexander Sack
Import upstream version 2.21.92
101
	GTK_ACTION_CLASS (ephy_link_action_parent_class)->connect_proxy (action, proxy);
1 by Sebastien Bacher
Import upstream version 1.9.2
102
}
103
104
static void
105
ephy_link_action_disconnect_proxy (GtkAction *action, GtkWidget *proxy)
106
{
107
	GtkWidget *widget;
108
109
	LOG ("Disconnect link action proxy");
110
1.7.4 by Jeremy Bicha
Import upstream version 3.3.4.1
111
	widget = get_event_widget (proxy);
1 by Sebastien Bacher
Import upstream version 1.9.2
112
	if (widget)
113
	{
114
		g_signal_handlers_disconnect_by_func (widget,
115
						      G_CALLBACK (proxy_button_press_event_cb),
116
						      action);
117
	}
118
1.1.35 by Alexander Sack
Import upstream version 2.21.92
119
	GTK_ACTION_CLASS (ephy_link_action_parent_class)->disconnect_proxy (action, proxy);
120
}
121
122
static void
123
ephy_link_action_init (EphyLinkAction *action)
124
{
1.7.4 by Jeremy Bicha
Import upstream version 3.3.4.1
125
	action->priv = EPHY_LINK_ACTION_GET_PRIVATE (action);
1 by Sebastien Bacher
Import upstream version 1.9.2
126
}
127
128
static void
129
ephy_link_action_class_init (EphyLinkActionClass *class)
130
{
131
	GtkActionClass *action_class = GTK_ACTION_CLASS (class);
132
133
	action_class->connect_proxy = ephy_link_action_connect_proxy;
134
	action_class->disconnect_proxy = ephy_link_action_disconnect_proxy;
1.7.4 by Jeremy Bicha
Import upstream version 3.3.4.1
135
136
	g_type_class_add_private (G_OBJECT_CLASS (class), sizeof (EphyLinkActionPrivate));
137
}
138
139
/**
140
 * ephy_link_action_get_button:
141
 * @action: an #EphyLinkAction
142
 * 
143
 * This method stores the mouse button number that last activated, or
144
 * is activating, the @action. This is useful because #GtkButton's
145
 * cannot be clicked with a middle click by default, so inside
146
 * Epiphany we fake this by forwarding a left click (button 1) event
147
 * instead of a middle click (button 2) to the button. That makes the
148
 * EphyGUI methods like ephy_gui_is_middle_click not work here, so we
149
 * need to ask the @action directly about the button that activated
150
 * it.
151
 * 
152
 * Returns: the button number that last activated (or is activating) the @action
153
 **/
154
guint
155
ephy_link_action_get_button (EphyLinkAction *action)
156
{
157
	g_return_val_if_fail (EPHY_IS_LINK_ACTION (action), 0);
158
159
	return action->priv->button;
1 by Sebastien Bacher
Import upstream version 1.9.2
160
}
161
1.1.35 by Alexander Sack
Import upstream version 2.21.92
162
static void
163
ephy_link_action_group_class_init (EphyLinkActionGroupClass *klass)
164
{
1.7.4 by Jeremy Bicha
Import upstream version 3.3.4.1
165
	/* Empty, needed for G_DEFINE_TYPE macro */
1.1.35 by Alexander Sack
Import upstream version 2.21.92
166
}
167
168
static void
169
ephy_link_action_group_init (EphyLinkActionGroup *action_group)
170
{
1.7.4 by Jeremy Bicha
Import upstream version 3.3.4.1
171
	/* Empty, needed for G_DEFINE_TYPE macro */
1.1.35 by Alexander Sack
Import upstream version 2.21.92
172
}
173
174
G_DEFINE_TYPE_WITH_CODE (EphyLinkActionGroup, ephy_link_action_group, GTK_TYPE_ACTION_GROUP,
1.7.4 by Jeremy Bicha
Import upstream version 3.3.4.1
175
			 G_IMPLEMENT_INTERFACE (EPHY_TYPE_LINK,
176
						NULL))
1 by Sebastien Bacher
Import upstream version 1.9.2
177
178
EphyLinkActionGroup *
1.1.5 by Sebastien Bacher
Import upstream version 1.9.7
179
ephy_link_action_group_new (const char * name)
1 by Sebastien Bacher
Import upstream version 1.9.2
180
{
1.1.5 by Sebastien Bacher
Import upstream version 1.9.7
181
	return g_object_new (EPHY_TYPE_LINK_ACTION_GROUP,
182
			     "name", name,
183
			     NULL);
1 by Sebastien Bacher
Import upstream version 1.9.2
184
}