Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / content / events / src / nsDOMMouseEvent.cpp
blob0b653d8aa63a24c3e42e104cf60e517865dbdea2
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Steve Clark (buster@netscape.com)
24 * Ilya Konstantinov (mozilla-code@future.shiny.co.il)
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsDOMMouseEvent.h"
41 #include "nsGUIEvent.h"
42 #include "nsIContent.h"
43 #include "nsIEventStateManager.h"
44 #include "nsContentUtils.h"
46 nsDOMMouseEvent::nsDOMMouseEvent(nsPresContext* aPresContext,
47 nsInputEvent* aEvent)
48 : nsDOMUIEvent(aPresContext, aEvent ? aEvent :
49 new nsMouseEvent(PR_FALSE, 0, nsnull,
50 nsMouseEvent::eReal))
52 // There's no way to make this class' ctor allocate an nsMouseScrollEvent.
53 // It's not that important, though, since a scroll event is not a real
54 // DOM event.
56 if (aEvent) {
57 mEventIsInternal = PR_FALSE;
59 else {
60 mEventIsInternal = PR_TRUE;
61 mEvent->time = PR_Now();
62 mEvent->refPoint.x = mEvent->refPoint.y = 0;
65 switch (mEvent->eventStructType)
67 case NS_MOUSE_EVENT:
68 mDetail = static_cast<nsMouseEvent*>(mEvent)->clickCount;
69 break;
70 default:
71 break;
75 nsDOMMouseEvent::~nsDOMMouseEvent()
77 if (mEventIsInternal && mEvent) {
78 switch (mEvent->eventStructType)
80 case NS_MOUSE_EVENT:
81 delete static_cast<nsMouseEvent*>(mEvent);
82 break;
83 default:
84 delete mEvent;
85 break;
87 mEvent = nsnull;
91 NS_IMPL_ADDREF_INHERITED(nsDOMMouseEvent, nsDOMUIEvent)
92 NS_IMPL_RELEASE_INHERITED(nsDOMMouseEvent, nsDOMUIEvent)
94 NS_INTERFACE_MAP_BEGIN(nsDOMMouseEvent)
95 NS_INTERFACE_MAP_ENTRY(nsIDOMMouseEvent)
96 NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MouseEvent)
97 NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
99 NS_IMETHODIMP
100 nsDOMMouseEvent::InitMouseEvent(const nsAString & aType, PRBool aCanBubble, PRBool aCancelable,
101 nsIDOMAbstractView *aView, PRInt32 aDetail, PRInt32 aScreenX,
102 PRInt32 aScreenY, PRInt32 aClientX, PRInt32 aClientY,
103 PRBool aCtrlKey, PRBool aAltKey, PRBool aShiftKey,
104 PRBool aMetaKey, PRUint16 aButton, nsIDOMEventTarget *aRelatedTarget)
106 nsresult rv = nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
107 NS_ENSURE_SUCCESS(rv, rv);
109 switch(mEvent->eventStructType)
111 case NS_MOUSE_EVENT:
112 case NS_MOUSE_SCROLL_EVENT:
114 static_cast<nsMouseEvent_base*>(mEvent)->relatedTarget = aRelatedTarget;
115 static_cast<nsMouseEvent_base*>(mEvent)->button = aButton;
116 nsInputEvent* inputEvent = static_cast<nsInputEvent*>(mEvent);
117 inputEvent->isControl = aCtrlKey;
118 inputEvent->isAlt = aAltKey;
119 inputEvent->isShift = aShiftKey;
120 inputEvent->isMeta = aMetaKey;
121 mClientPoint.x = aClientX;
122 mClientPoint.y = aClientY;
123 inputEvent->refPoint.x = aScreenX;
124 inputEvent->refPoint.y = aScreenY;
126 if (mEvent->eventStructType == NS_MOUSE_EVENT) {
127 nsMouseEvent* mouseEvent = static_cast<nsMouseEvent*>(mEvent);
128 mouseEvent->clickCount = aDetail;
130 break;
132 default:
133 break;
136 return NS_OK;
139 NS_IMETHODIMP
140 nsDOMMouseEvent::GetButton(PRUint16* aButton)
142 NS_ENSURE_ARG_POINTER(aButton);
143 switch(mEvent->eventStructType)
145 case NS_MOUSE_EVENT:
146 case NS_MOUSE_SCROLL_EVENT:
147 *aButton = static_cast<nsMouseEvent_base*>(mEvent)->button;
148 break;
149 default:
150 NS_WARNING("Tried to get mouse button for non-mouse event!");
151 *aButton = nsMouseEvent::eLeftButton;
152 break;
154 return NS_OK;
157 NS_IMETHODIMP
158 nsDOMMouseEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget)
160 NS_ENSURE_ARG_POINTER(aRelatedTarget);
161 *aRelatedTarget = nsnull;
162 nsISupports* relatedTarget = nsnull;
163 switch(mEvent->eventStructType)
165 case NS_MOUSE_EVENT:
166 case NS_MOUSE_SCROLL_EVENT:
167 relatedTarget = static_cast<nsMouseEvent_base*>(mEvent)->relatedTarget;
168 break;
169 default:
170 break;
173 if (relatedTarget) {
174 CallQueryInterface(relatedTarget, aRelatedTarget);
176 return NS_OK;
179 NS_METHOD nsDOMMouseEvent::GetScreenX(PRInt32* aScreenX)
181 NS_ENSURE_ARG_POINTER(aScreenX);
182 *aScreenX = GetScreenPoint().x;
183 return NS_OK;
186 NS_IMETHODIMP
187 nsDOMMouseEvent::GetScreenY(PRInt32* aScreenY)
189 NS_ENSURE_ARG_POINTER(aScreenY);
190 *aScreenY = GetScreenPoint().y;
191 return NS_OK;
195 NS_METHOD nsDOMMouseEvent::GetClientX(PRInt32* aClientX)
197 NS_ENSURE_ARG_POINTER(aClientX);
198 *aClientX = GetClientPoint().x;
199 return NS_OK;
202 NS_IMETHODIMP
203 nsDOMMouseEvent::GetClientY(PRInt32* aClientY)
205 NS_ENSURE_ARG_POINTER(aClientY);
206 *aClientY = GetClientPoint().y;
207 return NS_OK;
210 NS_IMETHODIMP
211 nsDOMMouseEvent::GetAltKey(PRBool* aIsDown)
213 NS_ENSURE_ARG_POINTER(aIsDown);
214 *aIsDown = ((nsInputEvent*)mEvent)->isAlt;
215 return NS_OK;
218 NS_IMETHODIMP
219 nsDOMMouseEvent::GetCtrlKey(PRBool* aIsDown)
221 NS_ENSURE_ARG_POINTER(aIsDown);
222 *aIsDown = ((nsInputEvent*)mEvent)->isControl;
223 return NS_OK;
226 NS_IMETHODIMP
227 nsDOMMouseEvent::GetShiftKey(PRBool* aIsDown)
229 NS_ENSURE_ARG_POINTER(aIsDown);
230 *aIsDown = ((nsInputEvent*)mEvent)->isShift;
231 return NS_OK;
234 NS_IMETHODIMP
235 nsDOMMouseEvent::GetMetaKey(PRBool* aIsDown)
237 NS_ENSURE_ARG_POINTER(aIsDown);
238 *aIsDown = ((nsInputEvent*)mEvent)->isMeta;
239 return NS_OK;
242 NS_IMETHODIMP
243 nsDOMMouseEvent::GetWhich(PRUint32* aWhich)
245 NS_ENSURE_ARG_POINTER(aWhich);
246 PRUint16 button;
247 (void) GetButton(&button);
248 *aWhich = button + 1;
249 return NS_OK;
252 nsresult NS_NewDOMMouseEvent(nsIDOMEvent** aInstancePtrResult,
253 nsPresContext* aPresContext,
254 nsInputEvent *aEvent)
256 nsDOMMouseEvent* it = new nsDOMMouseEvent(aPresContext, aEvent);
257 if (nsnull == it) {
258 return NS_ERROR_OUT_OF_MEMORY;
261 return CallQueryInterface(it, aInstancePtrResult);