Back to index

lightning-sunbird  0.9+nobinonly
nsDOMXULCommandEvent.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 Gecko.
00017  *
00018  * The Initial Developer of the Original Code is Google Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2006
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Brian Ryner <bryner@brianryner.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * 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 "nsDOMXULCommandEvent.h"
00040 #include "nsContentUtils.h"
00041 
00042 nsDOMXULCommandEvent::nsDOMXULCommandEvent(nsPresContext* aPresContext,
00043                                            nsXULCommandEvent* aEvent)
00044   : nsDOMUIEvent(aPresContext,
00045                  aEvent ? aEvent : new nsXULCommandEvent(PR_FALSE, 0, nsnull))
00046 {
00047   if (aEvent) {
00048     mEventIsInternal = PR_FALSE;
00049   }
00050   else {
00051     mEventIsInternal = PR_TRUE;
00052     mEvent->time = PR_Now();
00053   }
00054 }
00055 
00056 nsDOMXULCommandEvent::~nsDOMXULCommandEvent()
00057 {
00058   if (mEventIsInternal) {
00059     delete mEvent->userType;
00060     nsXULCommandEvent* command = NS_STATIC_CAST(nsXULCommandEvent*, mEvent);
00061     delete command;
00062     mEvent = nsnull;
00063   }
00064 }
00065 
00066 NS_IMPL_ADDREF_INHERITED(nsDOMXULCommandEvent, nsDOMUIEvent)
00067 NS_IMPL_RELEASE_INHERITED(nsDOMXULCommandEvent, nsDOMUIEvent)
00068 
00069 NS_INTERFACE_MAP_BEGIN(nsDOMXULCommandEvent)
00070   NS_INTERFACE_MAP_ENTRY(nsIDOMXULCommandEvent)
00071   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULCommandEvent)
00072 NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
00073 
00074 NS_IMETHODIMP
00075 nsDOMXULCommandEvent::GetAltKey(PRBool* aIsDown)
00076 {
00077   NS_ENSURE_ARG_POINTER(aIsDown);
00078   *aIsDown = Event()->isAlt;
00079   return NS_OK;
00080 }
00081 
00082 NS_IMETHODIMP
00083 nsDOMXULCommandEvent::GetCtrlKey(PRBool* aIsDown)
00084 {
00085   NS_ENSURE_ARG_POINTER(aIsDown);
00086   *aIsDown = Event()->isControl;
00087   return NS_OK;
00088 }
00089 
00090 NS_IMETHODIMP
00091 nsDOMXULCommandEvent::GetShiftKey(PRBool* aIsDown)
00092 {
00093   NS_ENSURE_ARG_POINTER(aIsDown);
00094   *aIsDown = Event()->isShift;
00095   return NS_OK;
00096 }
00097 
00098 NS_IMETHODIMP
00099 nsDOMXULCommandEvent::GetMetaKey(PRBool* aIsDown)
00100 {
00101   NS_ENSURE_ARG_POINTER(aIsDown);
00102   *aIsDown = Event()->isMeta;
00103   return NS_OK;
00104 }
00105 
00106 NS_IMETHODIMP
00107 nsDOMXULCommandEvent::GetSourceEvent(nsIDOMEvent** aSourceEvent)
00108 {
00109   NS_ENSURE_ARG_POINTER(aSourceEvent);
00110   NS_IF_ADDREF(*aSourceEvent = Event()->sourceEvent);
00111   return NS_OK;
00112 }
00113 
00114 NS_IMETHODIMP
00115 nsDOMXULCommandEvent::InitCommandEvent(const nsAString& aType,
00116                                        PRBool aCanBubble, PRBool aCancelable,
00117                                        nsIDOMAbstractView *aView,
00118                                        PRInt32 aDetail,
00119                                        PRBool aCtrlKey, PRBool aAltKey,
00120                                        PRBool aShiftKey, PRBool aMetaKey,
00121                                        nsIDOMEvent* aSourceEvent)
00122 {
00123   nsresult rv = nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable,
00124                                           aView, aDetail);
00125   NS_ENSURE_SUCCESS(rv, rv);
00126 
00127   nsXULCommandEvent *event = Event();
00128   event->isControl = aCtrlKey;
00129   event->isAlt = aAltKey;
00130   event->isShift = aShiftKey;
00131   event->isMeta = aMetaKey;
00132   event->sourceEvent = aSourceEvent;
00133 
00134   return NS_OK;
00135 }
00136 
00137 
00138 nsresult NS_NewDOMXULCommandEvent(nsIDOMEvent** aInstancePtrResult,
00139                                   nsPresContext* aPresContext,
00140                                   nsXULCommandEvent *aEvent) 
00141 {
00142   nsDOMXULCommandEvent* it = new nsDOMXULCommandEvent(aPresContext, aEvent);
00143   if (nsnull == it) {
00144     return NS_ERROR_OUT_OF_MEMORY;
00145   }
00146 
00147   return CallQueryInterface(it, aInstancePtrResult);
00148 }