aboutsummaryrefslogtreecommitdiffstats
path: root/embed/xulrunner/src/EmbedEventListener.cpp
blob: e4803b8bd7644840be71b6b6d541a7a1b0eded21 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 *  Copyright © Christopher Blizzard
 *  Copyright © 2006 Christian Persch
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  ---------------------------------------------------------------------------
 *  Derived from Mozilla.org code, which had the following attributions:
 * 
 *  The Original Code is mozilla.org code.
 *
 *  The Initial Developer of the Original Code is
 *  Christopher Blizzard. Portions created by Christopher Blizzard are Copyright © Christopher Blizzard.  All Rights Reserved.
 *  Portions created by the Initial Developer are Copyright © 2001
 *  the Initial Developer. All Rights Reserved.
 *
 *  Contributor(s):
 *    Christopher Blizzard <blizzard@mozilla.org>
 *  ---------------------------------------------------------------------------
 *
 *  $Id$
 */

#include <mozilla-config.h>
#include "config.h"

#include <nsCOMPtr.h>
#include <nsIDOMMouseEvent.h>

#include "nsIDOMKeyEvent.h"
#include "nsIDOMUIEvent.h"

#include "EmbedEventListener.h"
#include "GeckoBrowser.h"

#include "gecko-embed-signals.h"
#include "gecko-dom-event.h"
#include "gecko-dom-event-internal.h"
#include "gecko-dom-event-private.h"

EmbedEventListener::EmbedEventListener(GeckoBrowser *aOwner)
  : mOwner(aOwner)
{
}

EmbedEventListener::~EmbedEventListener()
{
}

NS_IMPL_ADDREF(EmbedEventListener)
NS_IMPL_RELEASE(EmbedEventListener)
NS_INTERFACE_MAP_BEGIN(EmbedEventListener)
  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMKeyListener)
  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMKeyListener)
  NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener)
  NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener)
  NS_INTERFACE_MAP_ENTRY(nsIDOMUIListener)
  NS_INTERFACE_MAP_ENTRY(nsIDOMContextMenuListener)
NS_INTERFACE_MAP_END

inline NS_METHOD
EmbedEventListener::Emit(nsIDOMEvent *aDOMEvent,
             GeckoEmbedSignals signal,
             GeckoDOMEventType type)
{
  if (!aDOMEvent)
    return NS_OK;

  // g_print ("Emitting signal '%s'\n", g_signal_name (gecko_embed_signals[signal]));

  /* Check if there are any handlers connected */
  if (!g_signal_has_handler_pending (mOwner->mOwningWidget,
                                     gecko_embed_signals[signal],
                     0, FALSE /* FIXME: correct? */)) {
    return NS_OK;
  }

  GeckoDOMEvent event;
  GECKO_DOM_EVENT_STATIC_INIT (event, aDOMEvent);

  gboolean retval = FALSE;
  g_signal_emit (mOwner->mOwningWidget,
                 gecko_embed_signals[signal], 0,
                 (GeckoDOMEvent*) &event, &retval);
  if (retval) {
    aDOMEvent->StopPropagation();
    aDOMEvent->PreventDefault();
  }

  GECKO_DOM_EVENT_STATIC_DEINIT (event);

  return NS_OK;
}

NS_IMETHODIMP
EmbedEventListener::KeyDown(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_KEY_DOWN, TYPE_KEY_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::KeyPress(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_KEY_PRESS, TYPE_KEY_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::KeyUp(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_KEY_UP, TYPE_KEY_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::MouseDown(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_MOUSE_DOWN, TYPE_MOUSE_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::MouseUp(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_MOUSE_UP, TYPE_MOUSE_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::MouseClick(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_MOUSE_CLICK, TYPE_MOUSE_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::MouseDblClick(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_MOUSE_DOUBLE_CLICK, TYPE_MOUSE_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::MouseOver(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_MOUSE_OVER, TYPE_MOUSE_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::MouseOut(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_MOUSE_OUT, TYPE_MOUSE_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::FocusIn(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_FOCUS_IN, TYPE_UI_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::FocusOut(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_FOCUS_OUT, TYPE_UI_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::Activate(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_ACTIVATE, TYPE_UI_EVENT);
}

NS_IMETHODIMP
EmbedEventListener::ContextMenu(nsIDOMEvent* aDOMEvent)
{
  return Emit(aDOMEvent, DOM_CONTEXT_MENU, TYPE_MOUSE_EVENT);
}