bug 518266 - Implement mechanism to provide haptic feed back, android r=dougt a=blocking-fennec

This commit is contained in:
Brad Lassey 2010-11-22 11:38:02 -05:00
parent e5c1ab6e92
commit f12a85806e
7 changed files with 140 additions and 2 deletions

View File

@ -55,10 +55,11 @@ include $(topsrcdir)/ipc/chromium/chromium-config.mk
CPPSRCS = \ CPPSRCS = \
nsAccelerometerSystem.cpp \ nsAccelerometerSystem.cpp \
AndroidLocationProvider.cpp \ AndroidLocationProvider.cpp \
nsHapticFeedback.cpp \
$(NULL) $(NULL)
LOCAL_INCLUDES += -I$(topsrcdir)/dom/src/geolocation \ LOCAL_INCLUDES += -I$(topsrcdir)/dom/src/geolocation \
$(NULL) $(NULL)
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,55 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* ***** 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 Android code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brad Lassey <blassey@mozilla.com>
*
* 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 "mozilla/dom/ContentChild.h"
#include "nsHapticFeedback.h"
#include "AndroidBridge.h"
using namespace mozilla;
NS_IMPL_ISUPPORTS1(nsHapticFeedback, nsIHapticFeedback)
NS_IMETHODIMP
nsHapticFeedback::PerformSimpleAction(PRInt32 aType)
{
AndroidBridge* bridge = AndroidBridge::Bridge();
if (bridge) {
bridge->PerformHapticFeedback(aType == LongPress);
return NS_OK;
}
return NS_ERROR_FAILURE;
}

View File

@ -0,0 +1,45 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* ***** 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 Android code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brad Lassey <blassey@mozilla.com>
*
* 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 "nsIHapticFeedback.h"
class nsHapticFeedback : public nsIHapticFeedback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIHAPTICFEEDBACK
};

View File

@ -614,6 +614,13 @@ class GeckoAppShell
showFilePicker(getMimeTypeFromExtensions(aFilters)); showFilePicker(getMimeTypeFromExtensions(aFilters));
} }
public static void performHapticFeedback(boolean aIsLongPress) {
GeckoApp.surfaceView.
performHapticFeedback(aIsLongPress ?
HapticFeedbackConstants.LONG_PRESS :
HapticFeedbackConstants.VIRTUAL_KEY);
}
public static void showInputMethodPicker() { public static void showInputMethodPicker() {
InputMethodManager imm = (InputMethodManager) GeckoApp.surfaceView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) GeckoApp.surfaceView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showInputMethodPicker(); imm.showInputMethodPicker();

View File

@ -159,10 +159,17 @@ using mozilla::dom::indexedDB::IndexedDatabaseManager;
#include "nsNullPrincipal.h" #include "nsNullPrincipal.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsINodeInfo.h" #include "nsINodeInfo.h"
#ifdef ANDROID
#include "nsHapticFeedback.h"
#endif
#define NS_EDITORCOMMANDTABLE_CID \ #define NS_EDITORCOMMANDTABLE_CID \
{ 0x4f5e62b8, 0xd659, 0x4156, { 0x84, 0xfc, 0x2f, 0x60, 0x99, 0x40, 0x03, 0x69 }} { 0x4f5e62b8, 0xd659, 0x4156, { 0x84, 0xfc, 0x2f, 0x60, 0x99, 0x40, 0x03, 0x69 }}
#define NS_HAPTICFEEDBACK_CID \
{ 0x1f15dbc8, 0xbfaa, 0x45de, \
{ 0x8a, 0x46, 0x08, 0xe2, 0xe2, 0x63, 0x26, 0xb0 } }
static NS_DEFINE_CID(kEditorCommandTableCID, NS_EDITORCOMMANDTABLE_CID); static NS_DEFINE_CID(kEditorCommandTableCID, NS_EDITORCOMMANDTABLE_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPlaintextEditor) NS_GENERIC_FACTORY_CONSTRUCTOR(nsPlaintextEditor)
@ -335,6 +342,9 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAccelerometerSystem)
#endif #endif
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ThirdPartyUtil, Init) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ThirdPartyUtil, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWorkerFactory) NS_GENERIC_FACTORY_CONSTRUCTOR(nsWorkerFactory)
#ifdef ANDROID
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHapticFeedback)
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -898,6 +908,9 @@ NS_DEFINE_NAMED_CID(NS_WORKERFACTORY_CID);
defined(android) defined(android)
NS_DEFINE_NAMED_CID(NS_ACCELEROMETER_CID); NS_DEFINE_NAMED_CID(NS_ACCELEROMETER_CID);
#endif #endif
#ifdef ANDROID
NS_DEFINE_NAMED_CID(NS_HAPTICFEEDBACK_CID);
#endif
static const mozilla::Module::CIDEntry kLayoutCIDs[] = { static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
XPCONNECT_CIDENTRIES XPCONNECT_CIDENTRIES
@ -1047,6 +1060,9 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
defined(machintosh) || \ defined(machintosh) || \
defined(android) defined(android)
{ &kNS_ACCELEROMETER_CID, false, NULL, nsAccelerometerSystemConstructor }, { &kNS_ACCELEROMETER_CID, false, NULL, nsAccelerometerSystemConstructor },
#endif
#ifdef ANDROID
{ &kNS_HAPTICFEEDBACK_CID, false, NULL, nsHapticFeedbackConstructor },
#endif #endif
{ &kTHIRDPARTYUTIL_CID, false, NULL, ThirdPartyUtilConstructor }, { &kTHIRDPARTYUTIL_CID, false, NULL, ThirdPartyUtilConstructor },
{ &kNS_WORKERFACTORY_CID, false, NULL, nsWorkerFactoryConstructor }, { &kNS_WORKERFACTORY_CID, false, NULL, nsWorkerFactoryConstructor },
@ -1195,6 +1211,9 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
defined(machintosh) || \ defined(machintosh) || \
defined(android) defined(android)
{ NS_ACCELEROMETER_CONTRACTID, &kNS_ACCELEROMETER_CID }, { NS_ACCELEROMETER_CONTRACTID, &kNS_ACCELEROMETER_CID },
#endif
#ifdef ANDROID
{ "@mozilla.org/widget/hapticfeedback;1", &kNS_HAPTICFEEDBACK_CID },
#endif #endif
{ THIRDPARTYUTIL_CONTRACTID, &kTHIRDPARTYUTIL_CID }, { THIRDPARTYUTIL_CONTRACTID, &kTHIRDPARTYUTIL_CID },
{ NS_WORKERFACTORY_CONTRACTID, &kNS_WORKERFACTORY_CID }, { NS_WORKERFACTORY_CONTRACTID, &kNS_WORKERFACTORY_CID },

View File

@ -120,6 +120,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
jSetFullScreen = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setFullScreen", "(Z)V"); jSetFullScreen = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setFullScreen", "(Z)V");
jShowInputMethodPicker = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "showInputMethodPicker", "()V"); jShowInputMethodPicker = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "showInputMethodPicker", "()V");
jHideProgressDialog = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "hideProgressDialog", "()V"); jHideProgressDialog = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "hideProgressDialog", "()V");
jPerformHapticFeedback = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "performHapticFeedback", "(Z)V");
jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext")); jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext"));
jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10")); jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10"));
@ -535,6 +536,13 @@ AndroidBridge::HideProgressDialogOnce()
} }
} }
void
AndroidBridge::PerformHapticFeedback(PRBool aIsLongPress)
{
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass,
jPerformHapticFeedback, aIsLongPress);
}
void void
AndroidBridge::SetSurfaceView(jobject obj) AndroidBridge::SetSurfaceView(jobject obj)
{ {

View File

@ -170,6 +170,8 @@ public:
void ShowFilePicker(nsAString& aFilePath, nsAString& aFilters); void ShowFilePicker(nsAString& aFilePath, nsAString& aFilters);
void PerformHapticFeedback(PRBool aIsLongPress);
void SetFullScreen(PRBool aFullScreen); void SetFullScreen(PRBool aFullScreen);
void ShowInputMethodPicker(); void ShowInputMethodPicker();
@ -253,6 +255,7 @@ protected:
jmethodID jSetFullScreen; jmethodID jSetFullScreen;
jmethodID jShowInputMethodPicker; jmethodID jShowInputMethodPicker;
jmethodID jHideProgressDialog; jmethodID jHideProgressDialog;
jmethodID jPerformHapticFeedback;
// stuff we need for CallEglCreateWindowSurface // stuff we need for CallEglCreateWindowSurface
jclass jEGLSurfaceImplClass; jclass jEGLSurfaceImplClass;