bug 477627 - avoiding deadlocks in ClaimTitle. r=brendan
[mozilla-central.git] / content / events / src / nsDOMXULCommandEvent.cpp
blobd5415a8d41a91bc25509b45c1fb01e460ccef5dc
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Gecko.
18 * The Initial Developer of the Original Code is Google Inc.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Brian Ryner <bryner@brianryner.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsDOMXULCommandEvent.h"
40 #include "nsContentUtils.h"
42 nsDOMXULCommandEvent::nsDOMXULCommandEvent(nsPresContext* aPresContext,
43 nsXULCommandEvent* aEvent)
44 : nsDOMUIEvent(aPresContext,
45 aEvent ? aEvent : new nsXULCommandEvent(PR_FALSE, 0, nsnull))
47 if (aEvent) {
48 mEventIsInternal = PR_FALSE;
50 else {
51 mEventIsInternal = PR_TRUE;
52 mEvent->time = PR_Now();
56 nsDOMXULCommandEvent::~nsDOMXULCommandEvent()
58 if (mEventIsInternal) {
59 nsXULCommandEvent* command = static_cast<nsXULCommandEvent*>(mEvent);
60 delete command;
61 mEvent = nsnull;
65 NS_IMPL_ADDREF_INHERITED(nsDOMXULCommandEvent, nsDOMUIEvent)
66 NS_IMPL_RELEASE_INHERITED(nsDOMXULCommandEvent, nsDOMUIEvent)
68 NS_INTERFACE_MAP_BEGIN(nsDOMXULCommandEvent)
69 NS_INTERFACE_MAP_ENTRY(nsIDOMXULCommandEvent)
70 NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULCommandEvent)
71 NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
73 NS_IMETHODIMP
74 nsDOMXULCommandEvent::GetAltKey(PRBool* aIsDown)
76 NS_ENSURE_ARG_POINTER(aIsDown);
77 *aIsDown = Event()->isAlt;
78 return NS_OK;
81 NS_IMETHODIMP
82 nsDOMXULCommandEvent::GetCtrlKey(PRBool* aIsDown)
84 NS_ENSURE_ARG_POINTER(aIsDown);
85 *aIsDown = Event()->isControl;
86 return NS_OK;
89 NS_IMETHODIMP
90 nsDOMXULCommandEvent::GetShiftKey(PRBool* aIsDown)
92 NS_ENSURE_ARG_POINTER(aIsDown);
93 *aIsDown = Event()->isShift;
94 return NS_OK;
97 NS_IMETHODIMP
98 nsDOMXULCommandEvent::GetMetaKey(PRBool* aIsDown)
100 NS_ENSURE_ARG_POINTER(aIsDown);
101 *aIsDown = Event()->isMeta;
102 return NS_OK;
105 NS_IMETHODIMP
106 nsDOMXULCommandEvent::GetSourceEvent(nsIDOMEvent** aSourceEvent)
108 NS_ENSURE_ARG_POINTER(aSourceEvent);
109 NS_IF_ADDREF(*aSourceEvent = Event()->sourceEvent);
110 return NS_OK;
113 NS_IMETHODIMP
114 nsDOMXULCommandEvent::InitCommandEvent(const nsAString& aType,
115 PRBool aCanBubble, PRBool aCancelable,
116 nsIDOMAbstractView *aView,
117 PRInt32 aDetail,
118 PRBool aCtrlKey, PRBool aAltKey,
119 PRBool aShiftKey, PRBool aMetaKey,
120 nsIDOMEvent* aSourceEvent)
122 nsresult rv = nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable,
123 aView, aDetail);
124 NS_ENSURE_SUCCESS(rv, rv);
126 nsXULCommandEvent *event = Event();
127 event->isControl = aCtrlKey;
128 event->isAlt = aAltKey;
129 event->isShift = aShiftKey;
130 event->isMeta = aMetaKey;
131 event->sourceEvent = aSourceEvent;
133 return NS_OK;
137 nsresult NS_NewDOMXULCommandEvent(nsIDOMEvent** aInstancePtrResult,
138 nsPresContext* aPresContext,
139 nsXULCommandEvent *aEvent)
141 nsDOMXULCommandEvent* it = new nsDOMXULCommandEvent(aPresContext, aEvent);
142 if (nsnull == it) {
143 return NS_ERROR_OUT_OF_MEMORY;
146 return CallQueryInterface(it, aInstancePtrResult);