2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Steve Clark (buster@netscape.com)
|
|
|
|
* Ilya Konstantinov (mozilla-code@future.shiny.co.il)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsDOMKeyboardEvent.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
|
|
|
nsDOMKeyboardEvent::nsDOMKeyboardEvent(nsPresContext* aPresContext,
|
|
|
|
nsKeyEvent* aEvent)
|
|
|
|
: nsDOMUIEvent(aPresContext, aEvent ? aEvent :
|
2011-10-17 07:59:28 -07:00
|
|
|
new nsKeyEvent(false, 0, nsnull))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mEvent->eventStructType == NS_KEY_EVENT, "event type mismatch");
|
|
|
|
|
|
|
|
if (aEvent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
mEvent->time = PR_Now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 15:38:35 -07:00
|
|
|
nsDOMKeyboardEvent::~nsDOMKeyboardEvent()
|
|
|
|
{
|
|
|
|
if (mEventIsInternal) {
|
|
|
|
delete static_cast<nsKeyEvent*>(mEvent);
|
|
|
|
mEvent = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMKeyboardEvent, nsDOMUIEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMKeyboardEvent, nsDOMUIEvent)
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(KeyboardEvent, nsDOMKeyboardEvent)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMKeyboardEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMKeyEvent)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(KeyboardEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMKeyboardEvent::GetAltKey(bool* aIsDown)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsDown);
|
2012-04-24 20:00:02 -07:00
|
|
|
*aIsDown = static_cast<nsInputEvent*>(mEvent)->IsAlt();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMKeyboardEvent::GetCtrlKey(bool* aIsDown)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsDown);
|
2012-04-24 20:00:02 -07:00
|
|
|
*aIsDown = static_cast<nsInputEvent*>(mEvent)->IsControl();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMKeyboardEvent::GetShiftKey(bool* aIsDown)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsDown);
|
2012-04-24 20:00:02 -07:00
|
|
|
*aIsDown = static_cast<nsInputEvent*>(mEvent)->IsShift();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMKeyboardEvent::GetMetaKey(bool* aIsDown)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsDown);
|
2012-04-24 20:00:02 -07:00
|
|
|
*aIsDown = static_cast<nsInputEvent*>(mEvent)->IsMeta();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMKeyboardEvent::GetCharCode(PRUint32* aCharCode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCharCode);
|
|
|
|
|
|
|
|
switch (mEvent->message) {
|
|
|
|
case NS_KEY_UP:
|
|
|
|
case NS_KEY_DOWN:
|
|
|
|
*aCharCode = 0;
|
|
|
|
break;
|
|
|
|
case NS_KEY_PRESS:
|
|
|
|
*aCharCode = ((nsKeyEvent*)mEvent)->charCode;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMKeyboardEvent::GetKeyCode(PRUint32* aKeyCode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aKeyCode);
|
|
|
|
|
|
|
|
switch (mEvent->message) {
|
|
|
|
case NS_KEY_UP:
|
|
|
|
case NS_KEY_PRESS:
|
|
|
|
case NS_KEY_DOWN:
|
|
|
|
*aKeyCode = ((nsKeyEvent*)mEvent)->keyCode;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*aKeyCode = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-26 00:43:49 -07:00
|
|
|
/* virtual */
|
|
|
|
nsresult
|
|
|
|
nsDOMKeyboardEvent::Which(PRUint32* aWhich)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aWhich);
|
|
|
|
|
|
|
|
switch (mEvent->message) {
|
|
|
|
case NS_KEY_UP:
|
|
|
|
case NS_KEY_DOWN:
|
|
|
|
return GetKeyCode(aWhich);
|
|
|
|
case NS_KEY_PRESS:
|
|
|
|
//Special case for 4xp bug 62878. Try to make value of which
|
|
|
|
//more closely mirror the values that 4.x gave for RETURN and BACKSPACE
|
|
|
|
{
|
|
|
|
PRUint32 keyCode = ((nsKeyEvent*)mEvent)->keyCode;
|
|
|
|
if (keyCode == NS_VK_RETURN || keyCode == NS_VK_BACK) {
|
|
|
|
*aWhich = keyCode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-12-06 01:30:01 -08:00
|
|
|
return GetCharCode(aWhich);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*aWhich = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMKeyboardEvent::InitKeyEvent(const nsAString& aType, bool aCanBubble, bool aCancelable,
|
|
|
|
nsIDOMWindow* aView, bool aCtrlKey, bool aAltKey,
|
|
|
|
bool aShiftKey, bool aMetaKey,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 aKeyCode, PRUint32 aCharCode)
|
|
|
|
{
|
|
|
|
nsresult rv = nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsKeyEvent* keyEvent = static_cast<nsKeyEvent*>(mEvent);
|
2012-04-24 20:00:02 -07:00
|
|
|
keyEvent->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
keyEvent->keyCode = aKeyCode;
|
|
|
|
keyEvent->charCode = aCharCode;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_NewDOMKeyboardEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsKeyEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsDOMKeyboardEvent* it = new nsDOMKeyboardEvent(aPresContext, aEvent);
|
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|