Back to index

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