Back to index

lightning-sunbird  0.9+nobinonly
EmbedEventListener.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard.  All Rights Reserved.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Christopher Blizzard <blizzard@mozilla.org>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include <nsCOMPtr.h>
00039 #include <nsIDOMMouseEvent.h>
00040 
00041 #include "nsIDOMKeyEvent.h"
00042 #include "nsIDOMUIEvent.h"
00043 
00044 #include "EmbedEventListener.h"
00045 #include "EmbedPrivate.h"
00046 
00047 EmbedEventListener::EmbedEventListener(void)
00048 {
00049   mOwner = nsnull;
00050 }
00051 
00052 EmbedEventListener::~EmbedEventListener()
00053 {
00054 }
00055 
00056 NS_IMPL_ADDREF(EmbedEventListener)
00057 NS_IMPL_RELEASE(EmbedEventListener)
00058 NS_INTERFACE_MAP_BEGIN(EmbedEventListener)
00059   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMKeyListener)
00060   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMKeyListener)
00061   NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener)
00062   NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener)
00063   NS_INTERFACE_MAP_ENTRY(nsIDOMUIListener)
00064 NS_INTERFACE_MAP_END
00065 
00066 nsresult
00067 EmbedEventListener::Init(EmbedPrivate *aOwner)
00068 {
00069   mOwner = aOwner;
00070   return NS_OK;
00071 }
00072 
00073 NS_IMETHODIMP
00074 EmbedEventListener::HandleEvent(nsIDOMEvent* aDOMEvent)
00075 {
00076   return NS_OK;
00077 }
00078 
00079 NS_IMETHODIMP
00080 EmbedEventListener::KeyDown(nsIDOMEvent* aDOMEvent)
00081 {
00082   nsCOMPtr <nsIDOMKeyEvent> keyEvent;
00083   keyEvent = do_QueryInterface(aDOMEvent);
00084   if (!keyEvent)
00085     return NS_OK;
00086   // Return FALSE to this function to mark the event as not
00087   // consumed...
00088   gint return_val = FALSE;
00089   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00090                 moz_embed_signals[DOM_KEY_DOWN],
00091                 (void *)keyEvent, &return_val);
00092   if (return_val) {
00093     aDOMEvent->StopPropagation();
00094     aDOMEvent->PreventDefault();
00095   }
00096   return NS_OK;
00097 }
00098 
00099 NS_IMETHODIMP
00100 EmbedEventListener::KeyUp(nsIDOMEvent* aDOMEvent)
00101 {
00102   nsCOMPtr <nsIDOMKeyEvent> keyEvent;
00103   keyEvent = do_QueryInterface(aDOMEvent);
00104   if (!keyEvent)
00105     return NS_OK;
00106   // return FALSE to this function to mark this event as not
00107   // consumed...
00108   gint return_val = FALSE;
00109   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00110                 moz_embed_signals[DOM_KEY_UP],
00111                 (void *)keyEvent, &return_val);
00112   if (return_val) {
00113     aDOMEvent->StopPropagation();
00114     aDOMEvent->PreventDefault();
00115   }
00116   return NS_OK;
00117 }
00118 
00119 NS_IMETHODIMP
00120 EmbedEventListener::KeyPress(nsIDOMEvent* aDOMEvent)
00121 {
00122   nsCOMPtr <nsIDOMKeyEvent> keyEvent;
00123   keyEvent = do_QueryInterface(aDOMEvent);
00124   if (!keyEvent)
00125     return NS_OK;
00126   // Return TRUE from your signal handler to mark the event as consumed.
00127   gint return_val = FALSE;
00128   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00129                 moz_embed_signals[DOM_KEY_PRESS],
00130                 (void *)keyEvent, &return_val);
00131   if (return_val) {
00132     aDOMEvent->StopPropagation();
00133     aDOMEvent->PreventDefault();
00134   }
00135   return NS_OK;
00136 }
00137 
00138 NS_IMETHODIMP
00139 EmbedEventListener::MouseDown(nsIDOMEvent* aDOMEvent)
00140 {
00141   nsCOMPtr <nsIDOMMouseEvent> mouseEvent;
00142   mouseEvent = do_QueryInterface(aDOMEvent);
00143   if (!mouseEvent)
00144     return NS_OK;
00145   // Return TRUE from your signal handler to mark the event as consumed.
00146   gint return_val = FALSE;
00147   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00148                 moz_embed_signals[DOM_MOUSE_DOWN],
00149                 (void *)mouseEvent, &return_val);
00150   if (return_val) {
00151     aDOMEvent->StopPropagation();
00152     aDOMEvent->PreventDefault();
00153   }
00154   return NS_OK;
00155 }
00156 
00157 NS_IMETHODIMP
00158 EmbedEventListener::MouseUp(nsIDOMEvent* aDOMEvent)
00159 {
00160   nsCOMPtr <nsIDOMMouseEvent> mouseEvent;
00161   mouseEvent = do_QueryInterface(aDOMEvent);
00162   if (!mouseEvent)
00163     return NS_OK;
00164   // Return TRUE from your signal handler to mark the event as consumed.
00165   gint return_val = FALSE;
00166   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00167                 moz_embed_signals[DOM_MOUSE_UP],
00168                 (void *)mouseEvent, &return_val);
00169   if (return_val) {
00170     aDOMEvent->StopPropagation();
00171     aDOMEvent->PreventDefault();
00172   }
00173   return NS_OK;
00174 }
00175 
00176 NS_IMETHODIMP
00177 EmbedEventListener::MouseClick(nsIDOMEvent* aDOMEvent)
00178 {
00179   nsCOMPtr <nsIDOMMouseEvent> mouseEvent;
00180   mouseEvent = do_QueryInterface(aDOMEvent);
00181   if (!mouseEvent)
00182     return NS_OK;
00183   // Return TRUE from your signal handler to mark the event as consumed.
00184   gint return_val = FALSE;
00185   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00186                 moz_embed_signals[DOM_MOUSE_CLICK],
00187                 (void *)mouseEvent, &return_val);
00188   if (return_val) {
00189     aDOMEvent->StopPropagation();
00190     aDOMEvent->PreventDefault();
00191   }
00192   return NS_OK;
00193 }
00194 
00195 NS_IMETHODIMP
00196 EmbedEventListener::MouseDblClick(nsIDOMEvent* aDOMEvent)
00197 {
00198   nsCOMPtr <nsIDOMMouseEvent> mouseEvent;
00199   mouseEvent = do_QueryInterface(aDOMEvent);
00200   if (!mouseEvent)
00201     return NS_OK;
00202   // Return TRUE from your signal handler to mark the event as consumed.
00203   gint return_val = FALSE;
00204   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00205                 moz_embed_signals[DOM_MOUSE_DBL_CLICK],
00206                 (void *)mouseEvent, &return_val);
00207   if (return_val) {
00208     aDOMEvent->StopPropagation();
00209     aDOMEvent->PreventDefault();
00210   }
00211   return NS_OK;
00212 }
00213 
00214 NS_IMETHODIMP
00215 EmbedEventListener::MouseOver(nsIDOMEvent* aDOMEvent)
00216 {
00217   nsCOMPtr <nsIDOMMouseEvent> mouseEvent;
00218   mouseEvent = do_QueryInterface(aDOMEvent);
00219   if (!mouseEvent)
00220     return NS_OK;
00221   // Return TRUE from your signal handler to mark the event as consumed.
00222   gint return_val = FALSE;
00223   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00224                 moz_embed_signals[DOM_MOUSE_OVER],
00225                 (void *)mouseEvent, &return_val);
00226   if (return_val) {
00227     aDOMEvent->StopPropagation();
00228     aDOMEvent->PreventDefault();
00229   }
00230   return NS_OK;
00231 }
00232 
00233 NS_IMETHODIMP
00234 EmbedEventListener::MouseOut(nsIDOMEvent* aDOMEvent)
00235 {
00236   nsCOMPtr <nsIDOMMouseEvent> mouseEvent;
00237   mouseEvent = do_QueryInterface(aDOMEvent);
00238   if (!mouseEvent)
00239     return NS_OK;
00240   // Return TRUE from your signal handler to mark the event as consumed.
00241   gint return_val = FALSE;
00242   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00243                 moz_embed_signals[DOM_MOUSE_OUT],
00244                 (void *)mouseEvent, &return_val);
00245   if (return_val) {
00246     aDOMEvent->StopPropagation();
00247     aDOMEvent->PreventDefault();
00248   }
00249   return NS_OK;
00250 }
00251 
00252 NS_IMETHODIMP
00253 EmbedEventListener::Activate(nsIDOMEvent* aDOMEvent)
00254 {
00255   nsCOMPtr <nsIDOMUIEvent> uiEvent = do_QueryInterface(aDOMEvent);
00256   if (!uiEvent)
00257     return NS_OK;
00258   // Return TRUE from your signal handler to mark the event as consumed.
00259   gint return_val = FALSE;
00260   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00261                   moz_embed_signals[DOM_ACTIVATE],
00262                   (void *)uiEvent, &return_val);
00263   if (return_val) {
00264     aDOMEvent->StopPropagation();
00265     aDOMEvent->PreventDefault();
00266   }
00267   return NS_OK;
00268 }
00269 
00270 NS_IMETHODIMP
00271 EmbedEventListener::FocusIn(nsIDOMEvent* aDOMEvent)
00272 {
00273   nsCOMPtr <nsIDOMUIEvent> uiEvent = do_QueryInterface(aDOMEvent);
00274   if (!uiEvent)
00275     return NS_OK;
00276   // Return TRUE from your signal handler to mark the event as consumed.
00277   gint return_val = FALSE;
00278   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00279                   moz_embed_signals[DOM_FOCUS_IN],
00280                   (void *)uiEvent, &return_val);
00281   if (return_val) {
00282     aDOMEvent->StopPropagation();
00283     aDOMEvent->PreventDefault();
00284   }
00285   return NS_OK;
00286 }
00287 
00288 NS_IMETHODIMP
00289 EmbedEventListener::FocusOut(nsIDOMEvent* aDOMEvent)
00290 {
00291   nsCOMPtr <nsIDOMUIEvent> uiEvent = do_QueryInterface(aDOMEvent);
00292   if (!uiEvent)
00293     return NS_OK;
00294   // Return TRUE from your signal handler to mark the event as consumed.
00295   gint return_val = FALSE;
00296   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00297                   moz_embed_signals[DOM_FOCUS_OUT],
00298                   (void *)uiEvent, &return_val);
00299   if (return_val) {
00300     aDOMEvent->StopPropagation();
00301     aDOMEvent->PreventDefault();
00302   }
00303   return NS_OK;
00304 }