Back to index

lightning-sunbird  0.9+nobinonly
nsXBLWindowDragHandler.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   - Mike Pinkerton (pinkerton@netscape.com)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsCOMPtr.h"
00040 #include "nsXBLPrototypeHandler.h"
00041 #include "nsXBLWindowDragHandler.h"
00042 #include "nsXBLAtoms.h"
00043 #include "nsIContent.h"
00044 #include "nsIAtom.h"
00045 #include "nsIDOMNSUIEvent.h"
00046 #include "nsIDOMMouseEvent.h"
00047 #include "nsIDOMEventReceiver.h"
00048 #include "nsXBLService.h"
00049 #include "nsIServiceManager.h"
00050 #include "nsHTMLAtoms.h"
00051 #include "nsIXBLDocumentInfo.h"
00052 #include "nsIScriptGlobalObject.h"
00053 #include "nsIDOMElement.h"
00054 
00055 nsXBLWindowDragHandler::nsXBLWindowDragHandler(nsIDOMEventReceiver* aReceiver)
00056   : nsXBLWindowHandler(nsnull, aReceiver)
00057 {
00058 }
00059 
00060 nsXBLWindowDragHandler::~nsXBLWindowDragHandler()
00061 {
00062 }
00063 
00064 NS_IMPL_ISUPPORTS1(nsXBLWindowDragHandler, nsIDOMDragListener)
00065 
00066 
00067 NS_IMETHODIMP
00068 nsXBLWindowDragHandler::WalkHandlers(nsIDOMEvent* aDragEvent, nsIAtom* aEventType)
00069 {
00070   nsCOMPtr<nsIDOMNSUIEvent> evt = do_QueryInterface(aDragEvent);
00071   PRBool prevent;
00072   evt->GetPreventDefault(&prevent);
00073   if (prevent)
00074     return NS_OK;
00075 
00076   // Make sure our event is really a mouse event
00077   nsCOMPtr<nsIDOMMouseEvent> dragEvent(do_QueryInterface(aDragEvent));
00078   if (!dragEvent)
00079     return NS_OK;
00080 
00081   nsresult rv = EnsureHandlers(nsnull);
00082   NS_ENSURE_SUCCESS(rv, rv);
00083   
00084   WalkHandlersInternal(aDragEvent, aEventType, mHandler);
00085   
00086   return NS_OK;
00087 }
00088 
00089 
00090 //
00091 // DragGesture
00092 // DragEnter
00093 // DragExit
00094 // DragOver
00095 // DragDrop
00096 //
00097 // On the particular event, walk the handlers we loaded in to
00098 // do something with the event.
00099 //
00100 nsresult 
00101 nsXBLWindowDragHandler::DragGesture(nsIDOMEvent* aDragEvent)
00102 {
00103   return WalkHandlers(aDragEvent, nsXBLAtoms::draggesture);
00104 }
00105 
00106 nsresult 
00107 nsXBLWindowDragHandler::DragEnter(nsIDOMEvent* aDragEvent)
00108 {
00109   return WalkHandlers(aDragEvent, nsXBLAtoms::dragenter);
00110 }
00111 
00112 nsresult 
00113 nsXBLWindowDragHandler::DragExit(nsIDOMEvent* aDragEvent)
00114 {
00115   return WalkHandlers(aDragEvent, nsXBLAtoms::dragexit);
00116 }
00117 
00118 nsresult 
00119 nsXBLWindowDragHandler::DragOver(nsIDOMEvent* aDragEvent)
00120 {
00121   return WalkHandlers(aDragEvent, nsXBLAtoms::dragevent);
00122 }
00123 
00124 nsresult 
00125 nsXBLWindowDragHandler::DragDrop(nsIDOMEvent* aDragEvent)
00126 {
00127   return WalkHandlers(aDragEvent, nsXBLAtoms::dragdrop);
00128 }
00129 
00130 
00131 //
00132 // EventMatched
00133 //
00134 // See if the given handler cares about this particular key event
00135 //
00136 PRBool
00137 nsXBLWindowDragHandler::EventMatched (nsXBLPrototypeHandler* inHandler,
00138                                       nsIAtom* inEventType,
00139                                       nsIDOMEvent* inEvent)
00140 {
00141   nsCOMPtr<nsIDOMMouseEvent> dragEvent ( do_QueryInterface(inEvent) );
00142   if ( dragEvent )
00143     return inHandler->MouseEventMatched(inEventType, dragEvent);
00144   
00145   return PR_FALSE;
00146 }
00147 
00148  
00150 
00151 nsresult
00152 NS_NewXBLWindowDragHandler(nsIDOMEventReceiver* aReceiver, nsXBLWindowDragHandler** aResult)
00153 {
00154   *aResult = new nsXBLWindowDragHandler(aReceiver);
00155   if (!*aResult)
00156     return NS_ERROR_OUT_OF_MEMORY;
00157   NS_ADDREF(*aResult);
00158   return NS_OK;
00159 }