2011-11-10 16:17:46 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=4 sw=4 sts=4 tw=80 et: */
|
2012-07-20 02:10:44 -07:00
|
|
|
/* Copyright 2012 Mozilla Foundation and Mozilla contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2014-03-04 00:45:50 -08:00
|
|
|
#ifndef _GNU_SOURCE
|
2011-11-10 16:17:46 -08:00
|
|
|
#define _GNU_SOURCE
|
2014-03-04 00:45:50 -08:00
|
|
|
#endif
|
2011-11-10 16:17:46 -08:00
|
|
|
|
|
|
|
#include <dirent.h>
|
2011-12-29 14:39:25 -08:00
|
|
|
#include <errno.h>
|
2011-11-10 16:17:46 -08:00
|
|
|
#include <fcntl.h>
|
2014-10-16 18:44:00 -07:00
|
|
|
#include <hardware_legacy/power.h>
|
2011-11-10 16:17:46 -08:00
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/epoll.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
2011-12-29 14:39:25 -08:00
|
|
|
#include <sys/types.h>
|
2011-11-10 16:17:46 -08:00
|
|
|
#include <unistd.h>
|
2014-04-09 11:24:00 -07:00
|
|
|
#include <utils/BitSet.h>
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2012-04-20 04:43:25 -07:00
|
|
|
#include "base/basictypes.h"
|
2013-12-05 06:29:07 -08:00
|
|
|
#include "GonkPermission.h"
|
2011-12-29 14:39:25 -08:00
|
|
|
#include "nscore.h"
|
2013-06-11 13:47:44 -07:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2013-06-10 05:22:05 -07:00
|
|
|
#include "MediaResourceManagerService.h"
|
2013-06-11 13:47:44 -07:00
|
|
|
#endif
|
2013-09-25 04:21:16 -07:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2011-12-29 14:39:25 -08:00
|
|
|
#include "mozilla/FileUtils.h"
|
2012-04-20 04:43:25 -07:00
|
|
|
#include "mozilla/Hal.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2012-01-25 11:00:34 -08:00
|
|
|
#include "mozilla/Mutex.h"
|
2011-12-29 14:39:25 -08:00
|
|
|
#include "mozilla/Services.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-11-21 13:03:27 -08:00
|
|
|
#if ANDROID_VERSION >= 18
|
|
|
|
#include "nativewindow/FakeSurfaceComposer.h"
|
|
|
|
#endif
|
2011-11-10 16:17:46 -08:00
|
|
|
#include "nsAppShell.h"
|
2013-04-05 01:49:00 -07:00
|
|
|
#include "mozilla/dom/Touch.h"
|
2011-11-10 16:17:46 -08:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIObserverService.h"
|
2012-02-06 17:47:11 -08:00
|
|
|
#include "nsIScreen.h"
|
|
|
|
#include "nsScreenManagerGonk.h"
|
2013-08-27 21:14:57 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2011-12-29 14:39:25 -08:00
|
|
|
#include "nsWindow.h"
|
2012-04-20 04:43:25 -07:00
|
|
|
#include "OrientationObserver.h"
|
2012-10-31 10:29:14 -07:00
|
|
|
#include "GonkMemoryPressureMonitoring.h"
|
2011-11-10 16:17:46 -08:00
|
|
|
|
|
|
|
#include "android/log.h"
|
2012-03-25 03:06:02 -07:00
|
|
|
#include "libui/EventHub.h"
|
|
|
|
#include "libui/InputReader.h"
|
|
|
|
#include "libui/InputDispatcher.h"
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2013-06-03 03:14:46 -07:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
#include "ipc/Nuwa.h"
|
|
|
|
#endif
|
|
|
|
|
2014-06-19 00:33:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2012-06-27 08:55:42 -07:00
|
|
|
|
2013-04-23 20:49:48 -07:00
|
|
|
// Defines kKeyMapping and GetKeyNameIndex()
|
|
|
|
#include "GonkKeyMapping.h"
|
2014-08-31 15:38:00 -07:00
|
|
|
#include "GeckoTouchDispatcher.h"
|
2013-04-23 20:49:48 -07:00
|
|
|
|
2011-12-29 14:39:25 -08:00
|
|
|
#define LOG(args...) \
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
|
|
|
|
#ifdef VERBOSE_LOG_ENABLED
|
|
|
|
# define VERBOSE_LOG(args...) \
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
|
|
|
|
#else
|
|
|
|
# define VERBOSE_LOG(args...) \
|
|
|
|
(void)0
|
|
|
|
#endif
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
using namespace android;
|
2012-05-08 14:36:07 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2012-11-28 10:43:19 -08:00
|
|
|
using namespace mozilla::services;
|
2012-12-15 17:26:04 -08:00
|
|
|
using namespace mozilla::widget;
|
2011-11-10 16:17:46 -08:00
|
|
|
|
|
|
|
bool gDrawRequest = false;
|
2013-10-28 07:05:51 -07:00
|
|
|
static nsAppShell *gAppShell = nullptr;
|
2011-11-10 16:17:46 -08:00
|
|
|
static int epollfd = 0;
|
|
|
|
static int signalfds[2] = {0};
|
2013-07-29 21:27:48 -07:00
|
|
|
static bool sDevInputAudioJack;
|
|
|
|
static int32_t sHeadphoneState;
|
|
|
|
static int32_t sMicrophoneState;
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2014-03-12 17:31:09 -07:00
|
|
|
// Amount of time in MS before an input is considered expired.
|
|
|
|
static const uint64_t kInputExpirationThresholdMs = 1000;
|
2014-10-16 18:44:00 -07:00
|
|
|
static const char kKey_WAKE_LOCK_ID[] = "GeckoKeyEvent";
|
2014-03-12 17:31:09 -07:00
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsAppShell, nsBaseAppShell, nsIObserver)
|
2012-11-28 10:43:19 -08:00
|
|
|
|
2014-03-12 17:31:09 -07:00
|
|
|
static uint64_t
|
|
|
|
nanosecsToMillisecs(nsecs_t nsecs)
|
|
|
|
{
|
|
|
|
return nsecs / 1000000;
|
|
|
|
}
|
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
bool ProcessNextEvent()
|
|
|
|
{
|
|
|
|
return gAppShell->ProcessNextNativeEvent(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyEvent()
|
|
|
|
{
|
|
|
|
gAppShell->NotifyNativeEvent();
|
|
|
|
}
|
|
|
|
|
2013-04-05 01:49:00 -07:00
|
|
|
} // namespace mozilla
|
2011-11-10 16:17:46 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
pipeHandler(int fd, FdHandler *data)
|
|
|
|
{
|
|
|
|
ssize_t len;
|
|
|
|
do {
|
|
|
|
char tmp[32];
|
|
|
|
len = read(fd, tmp, sizeof(tmp));
|
|
|
|
} while (len > 0);
|
|
|
|
}
|
|
|
|
|
2012-01-25 12:37:31 -08:00
|
|
|
struct Touch {
|
|
|
|
int32_t id;
|
|
|
|
PointerCoords coords;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UserInputData {
|
|
|
|
uint64_t timeMs;
|
|
|
|
enum {
|
|
|
|
MOTION_DATA,
|
|
|
|
KEY_DATA
|
|
|
|
} type;
|
|
|
|
int32_t action;
|
|
|
|
int32_t flags;
|
|
|
|
int32_t metaState;
|
2013-11-11 15:19:04 -08:00
|
|
|
int32_t deviceId;
|
2012-01-25 12:37:31 -08:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int32_t keyCode;
|
|
|
|
int32_t scanCode;
|
|
|
|
} key;
|
|
|
|
struct {
|
|
|
|
int32_t touchCount;
|
2013-04-05 01:49:00 -07:00
|
|
|
::Touch touches[MAX_POINTERS];
|
2012-01-25 12:37:31 -08:00
|
|
|
} motion;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-08-31 15:38:00 -07:00
|
|
|
static mozilla::Modifiers
|
|
|
|
getDOMModifiers(int32_t metaState)
|
2014-01-07 07:03:51 -08:00
|
|
|
{
|
2014-08-31 15:38:00 -07:00
|
|
|
mozilla::Modifiers result = 0;
|
2014-01-07 07:03:51 -08:00
|
|
|
if (metaState & (AMETA_ALT_ON | AMETA_ALT_LEFT_ON | AMETA_ALT_RIGHT_ON)) {
|
|
|
|
result |= MODIFIER_ALT;
|
|
|
|
}
|
|
|
|
if (metaState & (AMETA_SHIFT_ON |
|
|
|
|
AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_RIGHT_ON)) {
|
|
|
|
result |= MODIFIER_SHIFT;
|
|
|
|
}
|
|
|
|
if (metaState & AMETA_FUNCTION_ON) {
|
|
|
|
result |= MODIFIER_FN;
|
|
|
|
}
|
|
|
|
if (metaState & (AMETA_CTRL_ON |
|
|
|
|
AMETA_CTRL_LEFT_ON | AMETA_CTRL_RIGHT_ON)) {
|
|
|
|
result |= MODIFIER_CONTROL;
|
|
|
|
}
|
|
|
|
if (metaState & (AMETA_META_ON |
|
|
|
|
AMETA_META_LEFT_ON | AMETA_META_RIGHT_ON)) {
|
|
|
|
result |= MODIFIER_META;
|
|
|
|
}
|
|
|
|
if (metaState & AMETA_CAPS_LOCK_ON) {
|
|
|
|
result |= MODIFIER_CAPSLOCK;
|
|
|
|
}
|
|
|
|
if (metaState & AMETA_NUM_LOCK_ON) {
|
|
|
|
result |= MODIFIER_NUMLOCK;
|
|
|
|
}
|
|
|
|
if (metaState & AMETA_SCROLL_LOCK_ON) {
|
|
|
|
result |= MODIFIER_SCROLLLOCK;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-10 08:14:55 -08:00
|
|
|
class MOZ_STACK_CLASS KeyEventDispatcher
|
2011-12-23 23:13:33 -08:00
|
|
|
{
|
2013-12-10 08:14:55 -08:00
|
|
|
public:
|
|
|
|
KeyEventDispatcher(const UserInputData& aData,
|
|
|
|
KeyCharacterMap* aKeyCharMap);
|
|
|
|
void Dispatch();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const UserInputData& mData;
|
|
|
|
sp<KeyCharacterMap> mKeyCharMap;
|
|
|
|
|
2014-01-07 07:03:51 -08:00
|
|
|
char16_t mChar;
|
|
|
|
char16_t mUnmodifiedChar;
|
|
|
|
|
2013-12-10 08:14:55 -08:00
|
|
|
uint32_t mDOMKeyCode;
|
|
|
|
KeyNameIndex mDOMKeyNameIndex;
|
2014-05-24 19:09:00 -07:00
|
|
|
CodeNameIndex mDOMCodeNameIndex;
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t mDOMPrintableKeyValue;
|
2013-12-10 08:14:55 -08:00
|
|
|
|
|
|
|
bool IsKeyPress() const
|
|
|
|
{
|
|
|
|
return mData.action == AKEY_EVENT_ACTION_DOWN;
|
|
|
|
}
|
|
|
|
bool IsRepeat() const
|
|
|
|
{
|
|
|
|
return IsKeyPress() && (mData.flags & AKEY_EVENT_FLAG_LONG_PRESS);
|
|
|
|
}
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t PrintableKeyValue() const;
|
2013-12-10 08:14:55 -08:00
|
|
|
|
2014-01-07 07:03:51 -08:00
|
|
|
int32_t UnmodifiedMetaState() const
|
|
|
|
{
|
|
|
|
return mData.metaState &
|
|
|
|
~(AMETA_ALT_ON | AMETA_ALT_LEFT_ON | AMETA_ALT_RIGHT_ON |
|
|
|
|
AMETA_CTRL_ON | AMETA_CTRL_LEFT_ON | AMETA_CTRL_RIGHT_ON |
|
|
|
|
AMETA_META_ON | AMETA_META_LEFT_ON | AMETA_META_RIGHT_ON);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsControlChar(char16_t aChar)
|
|
|
|
{
|
|
|
|
return (aChar < ' ' || aChar == 0x7F);
|
|
|
|
}
|
|
|
|
|
2013-12-10 08:14:55 -08:00
|
|
|
void DispatchKeyDownEvent();
|
|
|
|
void DispatchKeyUpEvent();
|
|
|
|
nsEventStatus DispatchKeyEventInternal(uint32_t aEventMessage);
|
|
|
|
};
|
|
|
|
|
|
|
|
KeyEventDispatcher::KeyEventDispatcher(const UserInputData& aData,
|
|
|
|
KeyCharacterMap* aKeyCharMap) :
|
2014-01-07 07:03:51 -08:00
|
|
|
mData(aData), mKeyCharMap(aKeyCharMap), mChar(0), mUnmodifiedChar(0),
|
|
|
|
mDOMPrintableKeyValue(0)
|
2013-12-10 08:14:55 -08:00
|
|
|
{
|
2013-12-10 08:14:55 -08:00
|
|
|
// XXX Printable key's keyCode value should be computed with actual
|
|
|
|
// input character.
|
2014-03-04 00:45:51 -08:00
|
|
|
mDOMKeyCode = (mData.key.keyCode < (ssize_t)ArrayLength(kKeyMapping)) ?
|
2013-12-10 08:14:55 -08:00
|
|
|
kKeyMapping[mData.key.keyCode] : 0;
|
|
|
|
mDOMKeyNameIndex = GetKeyNameIndex(mData.key.keyCode);
|
2014-05-24 19:09:00 -07:00
|
|
|
mDOMCodeNameIndex = GetCodeNameIndex(mData.key.scanCode);
|
2013-12-10 08:14:55 -08:00
|
|
|
|
|
|
|
if (!mKeyCharMap.get()) {
|
2014-01-07 07:03:51 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mChar = mKeyCharMap->getCharacter(mData.key.keyCode, mData.metaState);
|
|
|
|
if (IsControlChar(mChar)) {
|
|
|
|
mChar = 0;
|
2013-12-10 08:14:55 -08:00
|
|
|
}
|
2014-01-07 07:03:51 -08:00
|
|
|
int32_t unmodifiedMetaState = UnmodifiedMetaState();
|
|
|
|
if (mData.metaState == unmodifiedMetaState) {
|
|
|
|
mUnmodifiedChar = mChar;
|
|
|
|
} else {
|
|
|
|
mUnmodifiedChar = mKeyCharMap->getCharacter(mData.key.keyCode,
|
|
|
|
unmodifiedMetaState);
|
|
|
|
if (IsControlChar(mUnmodifiedChar)) {
|
|
|
|
mUnmodifiedChar = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mDOMPrintableKeyValue = PrintableKeyValue();
|
2013-12-10 08:14:55 -08:00
|
|
|
}
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t
|
2013-12-10 08:14:55 -08:00
|
|
|
KeyEventDispatcher::PrintableKeyValue() const
|
|
|
|
{
|
2014-01-07 07:03:51 -08:00
|
|
|
if (mDOMKeyNameIndex != KEY_NAME_INDEX_USE_STRING) {
|
2013-12-10 08:14:55 -08:00
|
|
|
return 0;
|
|
|
|
}
|
2014-01-07 07:03:51 -08:00
|
|
|
return mChar ? mChar : mUnmodifiedChar;
|
2013-12-10 08:14:55 -08:00
|
|
|
}
|
|
|
|
|
2013-12-10 08:14:55 -08:00
|
|
|
nsEventStatus
|
|
|
|
KeyEventDispatcher::DispatchKeyEventInternal(uint32_t aEventMessage)
|
|
|
|
{
|
|
|
|
WidgetKeyboardEvent event(true, aEventMessage, nullptr);
|
|
|
|
if (aEventMessage == NS_KEY_PRESS) {
|
2014-01-07 07:03:51 -08:00
|
|
|
// XXX If the charCode is not a printable character, the charCode
|
|
|
|
// should be computed without Ctrl/Alt/Meta modifiers.
|
|
|
|
event.charCode = static_cast<uint32_t>(mChar);
|
2013-12-10 08:14:55 -08:00
|
|
|
}
|
|
|
|
if (!event.charCode) {
|
|
|
|
event.keyCode = mDOMKeyCode;
|
2013-11-19 10:14:41 -08:00
|
|
|
}
|
|
|
|
event.isChar = !!event.charCode;
|
2013-12-10 08:14:55 -08:00
|
|
|
event.mIsRepeat = IsRepeat();
|
|
|
|
event.mKeyNameIndex = mDOMKeyNameIndex;
|
2013-12-10 08:14:55 -08:00
|
|
|
if (mDOMPrintableKeyValue) {
|
|
|
|
event.mKeyValue = mDOMPrintableKeyValue;
|
|
|
|
}
|
2014-05-24 19:09:00 -07:00
|
|
|
event.mCodeNameIndex = mDOMCodeNameIndex;
|
2014-08-31 15:38:00 -07:00
|
|
|
event.modifiers = getDOMModifiers(mData.metaState);
|
2012-05-03 01:35:02 -07:00
|
|
|
event.location = nsIDOMKeyEvent::DOM_KEY_LOCATION_MOBILE;
|
2013-12-10 08:14:55 -08:00
|
|
|
event.time = mData.timeMs;
|
2011-12-23 23:13:33 -08:00
|
|
|
return nsWindow::DispatchInputEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-12-10 08:14:55 -08:00
|
|
|
void
|
|
|
|
KeyEventDispatcher::Dispatch()
|
|
|
|
{
|
2013-12-10 08:14:55 -08:00
|
|
|
// XXX Even if unknown key is pressed, DOM key event should be
|
|
|
|
// dispatched since Gecko for the other platforms are implemented
|
|
|
|
// as so.
|
2013-12-10 08:14:55 -08:00
|
|
|
if (!mDOMKeyCode && mDOMKeyNameIndex == KEY_NAME_INDEX_Unidentified) {
|
|
|
|
VERBOSE_LOG("Got unknown key event code. "
|
|
|
|
"type 0x%04x code 0x%04x value %d",
|
|
|
|
mData.action, mData.key.keyCode, IsKeyPress());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsKeyPress()) {
|
|
|
|
DispatchKeyDownEvent();
|
|
|
|
} else {
|
|
|
|
DispatchKeyUpEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyEventDispatcher::DispatchKeyDownEvent()
|
2011-12-23 23:13:33 -08:00
|
|
|
{
|
2013-12-10 08:14:55 -08:00
|
|
|
nsEventStatus status = DispatchKeyEventInternal(NS_KEY_DOWN);
|
|
|
|
if (status != nsEventStatus_eConsumeNoDefault) {
|
|
|
|
DispatchKeyEventInternal(NS_KEY_PRESS);
|
2013-04-23 20:49:48 -07:00
|
|
|
}
|
2011-12-29 14:39:25 -08:00
|
|
|
}
|
|
|
|
|
2013-12-10 08:14:55 -08:00
|
|
|
void
|
|
|
|
KeyEventDispatcher::DispatchKeyUpEvent()
|
|
|
|
{
|
|
|
|
DispatchKeyEventInternal(NS_KEY_UP);
|
|
|
|
}
|
|
|
|
|
2013-07-29 21:27:48 -07:00
|
|
|
class SwitchEventRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
SwitchEventRunnable(hal::SwitchEvent& aEvent) : mEvent(aEvent)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2014-01-20 01:35:24 -08:00
|
|
|
hal::NotifySwitchStateFromInputDevice(mEvent.device(),
|
|
|
|
mEvent.status());
|
2013-07-29 21:27:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
hal::SwitchEvent mEvent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
updateHeadphoneSwitch()
|
|
|
|
{
|
|
|
|
hal::SwitchEvent event;
|
|
|
|
|
|
|
|
switch (sHeadphoneState) {
|
|
|
|
case AKEY_STATE_UP:
|
|
|
|
event.status() = hal::SWITCH_STATE_OFF;
|
|
|
|
break;
|
|
|
|
case AKEY_STATE_DOWN:
|
|
|
|
event.status() = sMicrophoneState == AKEY_STATE_DOWN ?
|
2014-04-10 19:04:49 -07:00
|
|
|
hal::SWITCH_STATE_HEADSET : hal::SWITCH_STATE_HEADPHONE;
|
2013-07-29 21:27:48 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.device() = hal::SWITCH_HEADPHONES;
|
|
|
|
NS_DispatchToMainThread(new SwitchEventRunnable(event));
|
|
|
|
}
|
|
|
|
|
2012-08-24 11:06:19 -07:00
|
|
|
class GeckoPointerController : public PointerControllerInterface {
|
|
|
|
float mX;
|
|
|
|
float mY;
|
|
|
|
int32_t mButtonState;
|
|
|
|
InputReaderConfiguration* mConfig;
|
|
|
|
public:
|
|
|
|
GeckoPointerController(InputReaderConfiguration* config)
|
|
|
|
: mX(0)
|
|
|
|
, mY(0)
|
|
|
|
, mButtonState(0)
|
|
|
|
, mConfig(config)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual bool getBounds(float* outMinX, float* outMinY,
|
|
|
|
float* outMaxX, float* outMaxY) const;
|
|
|
|
virtual void move(float deltaX, float deltaY);
|
|
|
|
virtual void setButtonState(int32_t buttonState);
|
|
|
|
virtual int32_t getButtonState() const;
|
|
|
|
virtual void setPosition(float x, float y);
|
|
|
|
virtual void getPosition(float* outX, float* outY) const;
|
|
|
|
virtual void fade(Transition transition) {}
|
|
|
|
virtual void unfade(Transition transition) {}
|
|
|
|
virtual void setPresentation(Presentation presentation) {}
|
|
|
|
virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
|
|
|
|
BitSet32 spotIdBits) {}
|
|
|
|
virtual void clearSpots() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
|
|
|
GeckoPointerController::getBounds(float* outMinX,
|
|
|
|
float* outMinY,
|
|
|
|
float* outMaxX,
|
|
|
|
float* outMaxY) const
|
|
|
|
{
|
2013-08-26 14:59:18 -07:00
|
|
|
DisplayViewport viewport;
|
|
|
|
|
|
|
|
mConfig->getDisplayInfo(false, &viewport);
|
2012-08-24 11:06:19 -07:00
|
|
|
|
|
|
|
*outMinX = *outMinY = 0;
|
2013-12-03 13:44:01 -08:00
|
|
|
*outMaxX = viewport.logicalRight;
|
|
|
|
*outMaxY = viewport.logicalBottom;
|
2012-08-24 11:06:19 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GeckoPointerController::move(float deltaX, float deltaY)
|
|
|
|
{
|
|
|
|
float minX, minY, maxX, maxY;
|
|
|
|
getBounds(&minX, &minY, &maxX, &maxY);
|
|
|
|
|
|
|
|
mX = clamped(mX + deltaX, minX, maxX);
|
|
|
|
mY = clamped(mY + deltaY, minY, maxY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GeckoPointerController::setButtonState(int32_t buttonState)
|
|
|
|
{
|
|
|
|
mButtonState = buttonState;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
GeckoPointerController::getButtonState() const
|
|
|
|
{
|
|
|
|
return mButtonState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GeckoPointerController::setPosition(float x, float y)
|
|
|
|
{
|
|
|
|
mX = x;
|
|
|
|
mY = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GeckoPointerController::getPosition(float* outX, float* outY) const
|
|
|
|
{
|
|
|
|
*outX = mX;
|
|
|
|
*outY = mY;
|
|
|
|
}
|
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
class GeckoInputReaderPolicy : public InputReaderPolicyInterface {
|
2012-03-25 03:06:02 -07:00
|
|
|
InputReaderConfiguration mConfig;
|
2012-01-25 11:00:34 -08:00
|
|
|
public:
|
|
|
|
GeckoInputReaderPolicy() {}
|
|
|
|
|
2012-03-25 03:06:02 -07:00
|
|
|
virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
|
2012-04-10 18:49:49 -07:00
|
|
|
virtual sp<PointerControllerInterface> obtainPointerController(int32_t
|
2012-04-24 02:56:15 -07:00
|
|
|
deviceId)
|
|
|
|
{
|
2012-08-24 11:06:19 -07:00
|
|
|
return new GeckoPointerController(&mConfig);
|
2012-04-24 02:56:15 -07:00
|
|
|
};
|
2013-08-26 14:59:18 -07:00
|
|
|
virtual void notifyInputDevicesChanged(const android::Vector<InputDeviceInfo>& inputDevices) {};
|
|
|
|
virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor)
|
|
|
|
{
|
2013-10-28 07:05:51 -07:00
|
|
|
return nullptr;
|
2013-08-26 14:59:18 -07:00
|
|
|
};
|
|
|
|
virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier)
|
|
|
|
{
|
|
|
|
return String8::empty();
|
|
|
|
};
|
|
|
|
|
2012-03-25 03:06:02 -07:00
|
|
|
void setDisplayInfo();
|
2012-01-25 11:00:34 -08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~GeckoInputReaderPolicy() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GeckoInputDispatcher : public InputDispatcherInterface {
|
|
|
|
public:
|
2013-11-11 15:19:04 -08:00
|
|
|
GeckoInputDispatcher(sp<EventHub> &aEventHub)
|
2012-01-25 11:00:34 -08:00
|
|
|
: mQueueLock("GeckoInputDispatcher::mQueueMutex")
|
2013-11-11 15:19:04 -08:00
|
|
|
, mEventHub(aEventHub)
|
2014-03-12 17:31:09 -07:00
|
|
|
, mKeyDownCount(0)
|
|
|
|
, mKeyEventsFiltered(false)
|
2014-10-16 18:44:00 -07:00
|
|
|
, mPowerWakelock(false)
|
2014-06-19 00:33:00 -07:00
|
|
|
{
|
2014-08-31 15:38:00 -07:00
|
|
|
mTouchDispatcher = new GeckoTouchDispatcher();
|
2014-06-19 00:33:00 -07:00
|
|
|
}
|
2012-01-25 11:00:34 -08:00
|
|
|
|
|
|
|
virtual void dump(String8& dump);
|
|
|
|
|
2012-03-25 03:06:02 -07:00
|
|
|
virtual void monitor() {}
|
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
// Called on the main thread
|
|
|
|
virtual void dispatchOnce();
|
|
|
|
|
|
|
|
// notify* methods are called on the InputReaderThread
|
2012-03-25 03:06:02 -07:00
|
|
|
virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args);
|
|
|
|
virtual void notifyKey(const NotifyKeyArgs* args);
|
|
|
|
virtual void notifyMotion(const NotifyMotionArgs* args);
|
|
|
|
virtual void notifySwitch(const NotifySwitchArgs* args);
|
|
|
|
virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
|
2012-01-25 11:00:34 -08:00
|
|
|
|
|
|
|
virtual int32_t injectInputEvent(const InputEvent* event,
|
2012-03-25 03:06:02 -07:00
|
|
|
int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
|
|
|
|
uint32_t policyFlags);
|
|
|
|
|
2013-07-09 16:33:29 -07:00
|
|
|
virtual void setInputWindows(const android::Vector<sp<InputWindowHandle> >& inputWindowHandles);
|
2012-03-25 03:06:02 -07:00
|
|
|
virtual void setFocusedApplication(const sp<InputApplicationHandle>& inputApplicationHandle);
|
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
virtual void setInputDispatchMode(bool enabled, bool frozen);
|
2012-03-25 03:06:02 -07:00
|
|
|
virtual void setInputFilterEnabled(bool enabled) {}
|
|
|
|
virtual bool transferTouchFocus(const sp<InputChannel>& fromChannel,
|
|
|
|
const sp<InputChannel>& toChannel) { return true; }
|
|
|
|
|
|
|
|
virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel,
|
|
|
|
const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
|
2012-01-25 11:00:34 -08:00
|
|
|
virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel);
|
|
|
|
|
2012-03-25 03:06:02 -07:00
|
|
|
|
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
protected:
|
2014-08-31 15:38:00 -07:00
|
|
|
virtual ~GeckoInputDispatcher() { }
|
2012-01-25 11:00:34 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
// mQueueLock should generally be locked while using mEventQueue.
|
|
|
|
// UserInputData is pushed on on the InputReaderThread and
|
|
|
|
// popped and dispatched on the main thread.
|
|
|
|
mozilla::Mutex mQueueLock;
|
|
|
|
std::queue<UserInputData> mEventQueue;
|
2013-11-11 15:19:04 -08:00
|
|
|
sp<EventHub> mEventHub;
|
2014-08-31 15:38:00 -07:00
|
|
|
nsRefPtr<GeckoTouchDispatcher> mTouchDispatcher;
|
2014-03-12 17:31:09 -07:00
|
|
|
|
|
|
|
int mKeyDownCount;
|
|
|
|
bool mKeyEventsFiltered;
|
2014-10-16 18:44:00 -07:00
|
|
|
bool mPowerWakelock;
|
2012-01-25 11:00:34 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// GeckoInputReaderPolicy
|
2012-03-25 03:06:02 -07:00
|
|
|
void
|
|
|
|
GeckoInputReaderPolicy::setDisplayInfo()
|
2011-12-29 14:39:25 -08:00
|
|
|
{
|
2013-07-18 10:59:53 -07:00
|
|
|
static_assert(nsIScreen::ROTATION_0_DEG ==
|
|
|
|
DISPLAY_ORIENTATION_0,
|
|
|
|
"Orientation enums not matched!");
|
|
|
|
static_assert(nsIScreen::ROTATION_90_DEG ==
|
|
|
|
DISPLAY_ORIENTATION_90,
|
|
|
|
"Orientation enums not matched!");
|
|
|
|
static_assert(nsIScreen::ROTATION_180_DEG ==
|
|
|
|
DISPLAY_ORIENTATION_180,
|
|
|
|
"Orientation enums not matched!");
|
|
|
|
static_assert(nsIScreen::ROTATION_270_DEG ==
|
|
|
|
DISPLAY_ORIENTATION_270,
|
|
|
|
"Orientation enums not matched!");
|
2012-02-06 17:47:11 -08:00
|
|
|
|
2013-08-26 14:59:18 -07:00
|
|
|
DisplayViewport viewport;
|
|
|
|
viewport.displayId = 0;
|
|
|
|
viewport.orientation = nsScreenGonk::GetRotation();
|
2013-09-24 14:58:58 -07:00
|
|
|
viewport.physicalRight = viewport.deviceWidth = gScreenBounds.width;
|
|
|
|
viewport.physicalBottom = viewport.deviceHeight = gScreenBounds.height;
|
|
|
|
if (viewport.orientation == DISPLAY_ORIENTATION_90 ||
|
|
|
|
viewport.orientation == DISPLAY_ORIENTATION_270) {
|
|
|
|
viewport.logicalRight = gScreenBounds.height;
|
|
|
|
viewport.logicalBottom = gScreenBounds.width;
|
|
|
|
} else {
|
|
|
|
viewport.logicalRight = gScreenBounds.width;
|
|
|
|
viewport.logicalBottom = gScreenBounds.height;
|
|
|
|
}
|
2013-08-26 14:59:18 -07:00
|
|
|
mConfig.setDisplayInfo(false, viewport);
|
2011-12-29 14:39:25 -08:00
|
|
|
}
|
|
|
|
|
2012-03-25 03:06:02 -07:00
|
|
|
void GeckoInputReaderPolicy::getReaderConfiguration(InputReaderConfiguration* outConfig)
|
2011-12-29 14:39:25 -08:00
|
|
|
{
|
2012-03-25 03:06:02 -07:00
|
|
|
*outConfig = mConfig;
|
2012-01-25 11:00:34 -08:00
|
|
|
}
|
2011-12-29 14:39:25 -08:00
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
|
|
|
|
// GeckoInputDispatcher
|
|
|
|
void
|
|
|
|
GeckoInputDispatcher::dump(String8& dump)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-12 17:31:09 -07:00
|
|
|
static bool
|
|
|
|
isExpired(const UserInputData& data)
|
|
|
|
{
|
|
|
|
uint64_t timeNowMs =
|
|
|
|
nanosecsToMillisecs(systemTime(SYSTEM_TIME_MONOTONIC));
|
|
|
|
return (timeNowMs - data.timeMs) > kInputExpirationThresholdMs;
|
|
|
|
}
|
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
void
|
|
|
|
GeckoInputDispatcher::dispatchOnce()
|
|
|
|
{
|
|
|
|
UserInputData data;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mQueueLock);
|
|
|
|
if (mEventQueue.empty())
|
|
|
|
return;
|
|
|
|
data = mEventQueue.front();
|
|
|
|
mEventQueue.pop();
|
|
|
|
if (!mEventQueue.empty())
|
|
|
|
gAppShell->NotifyNativeEvent();
|
2011-12-29 14:39:25 -08:00
|
|
|
}
|
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
switch (data.type) {
|
|
|
|
case UserInputData::MOTION_DATA: {
|
2014-08-31 15:38:00 -07:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Should not dispatch touch events here anymore");
|
2012-01-25 11:00:34 -08:00
|
|
|
break;
|
|
|
|
}
|
2013-11-07 03:17:33 -08:00
|
|
|
case UserInputData::KEY_DATA: {
|
2014-03-12 17:31:09 -07:00
|
|
|
if (!mKeyDownCount) {
|
|
|
|
// No pending events, the filter state can be updated.
|
|
|
|
mKeyEventsFiltered = isExpired(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
mKeyDownCount += (data.action == AKEY_EVENT_ACTION_DOWN) ? 1 : -1;
|
|
|
|
if (mKeyEventsFiltered) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-11 15:19:04 -08:00
|
|
|
sp<KeyCharacterMap> kcm = mEventHub->getKeyCharacterMap(data.deviceId);
|
2013-12-10 08:14:55 -08:00
|
|
|
KeyEventDispatcher dispatcher(data, kcm.get());
|
|
|
|
dispatcher.Dispatch();
|
2012-01-25 11:00:34 -08:00
|
|
|
break;
|
|
|
|
}
|
2013-11-07 03:17:33 -08:00
|
|
|
}
|
2014-10-16 18:44:00 -07:00
|
|
|
MutexAutoLock lock(mQueueLock);
|
|
|
|
if (mPowerWakelock && mEventQueue.empty()) {
|
|
|
|
release_wake_lock(kKey_WAKE_LOCK_ID);
|
|
|
|
mPowerWakelock = false;
|
|
|
|
}
|
2012-01-25 11:00:34 -08:00
|
|
|
}
|
2011-12-29 14:39:25 -08:00
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
void
|
2012-03-25 03:06:02 -07:00
|
|
|
GeckoInputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChangedArgs*)
|
2012-01-25 11:00:34 -08:00
|
|
|
{
|
2011-12-23 23:13:33 -08:00
|
|
|
}
|
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
void
|
2012-03-25 03:06:02 -07:00
|
|
|
GeckoInputDispatcher::notifyKey(const NotifyKeyArgs* args)
|
2012-01-25 11:00:34 -08:00
|
|
|
{
|
|
|
|
UserInputData data;
|
2012-03-25 03:06:02 -07:00
|
|
|
data.timeMs = nanosecsToMillisecs(args->eventTime);
|
2012-01-25 11:00:34 -08:00
|
|
|
data.type = UserInputData::KEY_DATA;
|
2012-03-25 03:06:02 -07:00
|
|
|
data.action = args->action;
|
|
|
|
data.flags = args->flags;
|
|
|
|
data.metaState = args->metaState;
|
2013-11-11 15:19:04 -08:00
|
|
|
data.deviceId = args->deviceId;
|
2012-03-25 03:06:02 -07:00
|
|
|
data.key.keyCode = args->keyCode;
|
|
|
|
data.key.scanCode = args->scanCode;
|
2012-01-25 11:00:34 -08:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mQueueLock);
|
|
|
|
mEventQueue.push(data);
|
2014-10-16 18:44:00 -07:00
|
|
|
if (!mPowerWakelock) {
|
|
|
|
mPowerWakelock =
|
|
|
|
acquire_wake_lock(PARTIAL_WAKE_LOCK, kKey_WAKE_LOCK_ID);
|
|
|
|
}
|
2011-11-10 16:17:46 -08:00
|
|
|
}
|
2012-01-25 11:00:34 -08:00
|
|
|
gAppShell->NotifyNativeEvent();
|
2011-11-10 16:17:46 -08:00
|
|
|
}
|
|
|
|
|
2014-08-31 15:38:00 -07:00
|
|
|
static void
|
|
|
|
addMultiTouch(MultiTouchInput& aMultiTouch,
|
|
|
|
const NotifyMotionArgs* args, int aIndex)
|
|
|
|
{
|
|
|
|
int32_t id = args->pointerProperties[aIndex].id;
|
|
|
|
PointerCoords coords = args->pointerCoords[aIndex];
|
|
|
|
float force = coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE);
|
2014-09-24 16:00:00 -07:00
|
|
|
|
|
|
|
float orientation = coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION);
|
|
|
|
float rotationAngle = orientation * 180 / M_PI;
|
|
|
|
if (rotationAngle == 90) {
|
|
|
|
rotationAngle = -90;
|
|
|
|
}
|
|
|
|
|
|
|
|
float radiusX, radiusY;
|
|
|
|
if (rotationAngle < 0) {
|
|
|
|
radiusX = coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR) / 2;
|
|
|
|
radiusY = coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR) / 2;
|
|
|
|
rotationAngle += 90;
|
|
|
|
} else {
|
|
|
|
radiusX = coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR) / 2;
|
|
|
|
radiusY = coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR) / 2;
|
|
|
|
}
|
|
|
|
|
2014-08-31 15:38:00 -07:00
|
|
|
ScreenIntPoint point(floor(coords.getX() + 0.5),
|
|
|
|
floor(coords.getY() + 0.5));
|
|
|
|
|
2014-09-24 16:00:00 -07:00
|
|
|
SingleTouchData touchData(id, point, ScreenSize(radiusX, radiusY),
|
|
|
|
rotationAngle, force);
|
2014-08-31 15:38:00 -07:00
|
|
|
|
|
|
|
aMultiTouch.mTouches.AppendElement(touchData);
|
|
|
|
}
|
2012-03-25 03:06:02 -07:00
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
void
|
2012-03-25 03:06:02 -07:00
|
|
|
GeckoInputDispatcher::notifyMotion(const NotifyMotionArgs* args)
|
2012-01-25 11:00:34 -08:00
|
|
|
{
|
2014-08-31 15:38:00 -07:00
|
|
|
uint32_t time = nanosecsToMillisecs(args->eventTime);
|
|
|
|
int32_t action = args->action & AMOTION_EVENT_ACTION_MASK;
|
|
|
|
int touchCount = args->pointerCount;
|
|
|
|
MOZ_ASSERT(touchCount <= MAX_POINTERS);
|
2014-10-29 13:37:06 -07:00
|
|
|
TimeStamp timestamp = TimeStamp(args->eventTime);
|
2014-08-31 15:38:00 -07:00
|
|
|
Modifiers modifiers = getDOMModifiers(args->metaState);
|
|
|
|
|
|
|
|
MultiTouchInput::MultiTouchType touchType = MultiTouchInput::MULTITOUCH_CANCEL;
|
|
|
|
switch (action) {
|
|
|
|
case AMOTION_EVENT_ACTION_DOWN:
|
|
|
|
case AMOTION_EVENT_ACTION_POINTER_DOWN:
|
|
|
|
touchType = MultiTouchInput::MULTITOUCH_START;
|
|
|
|
break;
|
|
|
|
case AMOTION_EVENT_ACTION_MOVE:
|
|
|
|
touchType = MultiTouchInput::MULTITOUCH_MOVE;
|
|
|
|
break;
|
|
|
|
case AMOTION_EVENT_ACTION_UP:
|
|
|
|
case AMOTION_EVENT_ACTION_POINTER_UP:
|
|
|
|
touchType = MultiTouchInput::MULTITOUCH_END;
|
|
|
|
break;
|
|
|
|
case AMOTION_EVENT_ACTION_OUTSIDE:
|
|
|
|
case AMOTION_EVENT_ACTION_CANCEL:
|
|
|
|
touchType = MultiTouchInput::MULTITOUCH_CANCEL;
|
|
|
|
break;
|
2014-09-03 11:00:56 -07:00
|
|
|
case AMOTION_EVENT_ACTION_HOVER_EXIT:
|
|
|
|
case AMOTION_EVENT_ACTION_HOVER_ENTER:
|
|
|
|
case AMOTION_EVENT_ACTION_HOVER_MOVE:
|
|
|
|
NS_WARNING("Ignoring hover touch events");
|
|
|
|
return;
|
2014-08-31 15:38:00 -07:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Could not assign a touch type");
|
|
|
|
break;
|
2014-08-30 14:04:15 -07:00
|
|
|
}
|
2014-08-29 17:43:17 -07:00
|
|
|
|
2014-08-31 15:38:00 -07:00
|
|
|
MultiTouchInput touchData(touchType, time, timestamp, modifiers);
|
2014-08-30 17:18:29 -07:00
|
|
|
|
2014-08-31 15:38:00 -07:00
|
|
|
// For touch ends, we have to filter out which finger is actually
|
|
|
|
// the touch end since the touch array has all fingers, not just the touch
|
|
|
|
// that we want to end
|
|
|
|
if (touchType == MultiTouchInput::MULTITOUCH_END) {
|
|
|
|
int touchIndex = args->action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK;
|
|
|
|
touchIndex >>= AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
|
|
|
|
addMultiTouch(touchData, args, touchIndex);
|
|
|
|
} else {
|
|
|
|
for (int32_t i = 0; i < touchCount; ++i) {
|
|
|
|
addMultiTouch(touchData, args, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 13:37:06 -07:00
|
|
|
mTouchDispatcher->NotifyTouch(touchData, timestamp);
|
2014-08-31 15:38:00 -07:00
|
|
|
}
|
2014-08-30 17:18:29 -07:00
|
|
|
|
2012-03-25 03:06:02 -07:00
|
|
|
void GeckoInputDispatcher::notifySwitch(const NotifySwitchArgs* args)
|
2011-11-10 16:17:46 -08:00
|
|
|
{
|
2013-07-29 21:27:48 -07:00
|
|
|
if (!sDevInputAudioJack)
|
|
|
|
return;
|
|
|
|
|
2013-08-26 14:59:18 -07:00
|
|
|
bool needSwitchUpdate = false;
|
|
|
|
|
|
|
|
if (args->switchMask & (1 << SW_HEADPHONE_INSERT)) {
|
|
|
|
sHeadphoneState = (args->switchValues & (1 << SW_HEADPHONE_INSERT)) ?
|
|
|
|
AKEY_STATE_DOWN : AKEY_STATE_UP;
|
|
|
|
needSwitchUpdate = true;
|
2013-07-29 21:27:48 -07:00
|
|
|
}
|
2013-08-26 14:59:18 -07:00
|
|
|
|
|
|
|
if (args->switchMask & (1 << SW_MICROPHONE_INSERT)) {
|
|
|
|
sMicrophoneState = (args->switchValues & (1 << SW_MICROPHONE_INSERT)) ?
|
|
|
|
AKEY_STATE_DOWN : AKEY_STATE_UP;
|
|
|
|
needSwitchUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needSwitchUpdate)
|
|
|
|
updateHeadphoneSwitch();
|
2012-01-25 11:00:34 -08:00
|
|
|
}
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2012-03-25 03:06:02 -07:00
|
|
|
void GeckoInputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args)
|
|
|
|
{
|
|
|
|
}
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2012-03-25 03:06:02 -07:00
|
|
|
int32_t GeckoInputDispatcher::injectInputEvent(
|
|
|
|
const InputEvent* event,
|
|
|
|
int32_t injectorPid, int32_t injectorUid, int32_t syncMode,
|
|
|
|
int32_t timeoutMillis, uint32_t policyFlags)
|
2012-01-25 11:00:34 -08:00
|
|
|
{
|
|
|
|
return INPUT_EVENT_INJECTION_SUCCEEDED;
|
|
|
|
}
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
void
|
2013-07-09 16:33:29 -07:00
|
|
|
GeckoInputDispatcher::setInputWindows(const android::Vector<sp<InputWindowHandle> >& inputWindowHandles)
|
2012-01-25 11:00:34 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-25 03:06:02 -07:00
|
|
|
GeckoInputDispatcher::setFocusedApplication(const sp<InputApplicationHandle>& inputApplicationHandle)
|
2012-01-25 11:00:34 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GeckoInputDispatcher::setInputDispatchMode(bool enabled, bool frozen)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t
|
|
|
|
GeckoInputDispatcher::registerInputChannel(const sp<InputChannel>& inputChannel,
|
2012-03-25 03:06:02 -07:00
|
|
|
const sp<InputWindowHandle>& inputWindowHandle, bool monitor)
|
2012-01-25 11:00:34 -08:00
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t
|
|
|
|
GeckoInputDispatcher::unregisterInputChannel(const sp<InputChannel>& inputChannel)
|
|
|
|
{
|
|
|
|
return OK;
|
2011-11-10 16:17:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShell::nsAppShell()
|
|
|
|
: mNativeCallbackRequest(false)
|
2012-11-28 10:43:19 -08:00
|
|
|
, mEnableDraw(false)
|
2013-07-11 10:04:17 -07:00
|
|
|
, mHandlers()
|
2011-11-10 16:17:46 -08:00
|
|
|
{
|
|
|
|
gAppShell = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShell::~nsAppShell()
|
|
|
|
{
|
2012-11-27 19:07:19 -08:00
|
|
|
// mReaderThread and mEventHub will both be null if InitInputDevices
|
|
|
|
// is not called.
|
|
|
|
if (mReaderThread.get()) {
|
|
|
|
// We separate requestExit() and join() here so we can wake the EventHub's
|
|
|
|
// input loop, and stop it from polling for input events
|
|
|
|
mReaderThread->requestExit();
|
|
|
|
mEventHub->wake();
|
|
|
|
|
|
|
|
status_t result = mReaderThread->requestExitAndWait();
|
|
|
|
if (result)
|
|
|
|
LOG("Could not stop reader thread - %d", result);
|
|
|
|
}
|
2013-10-28 07:05:51 -07:00
|
|
|
gAppShell = nullptr;
|
2011-11-10 16:17:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAppShell::Init()
|
|
|
|
{
|
|
|
|
nsresult rv = nsBaseAppShell::Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
epollfd = epoll_create(16);
|
|
|
|
NS_ENSURE_TRUE(epollfd >= 0, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
int ret = pipe2(signalfds, O_NONBLOCK);
|
|
|
|
NS_ENSURE_FALSE(ret, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2011-12-29 14:39:25 -08:00
|
|
|
rv = AddFdHandler(signalfds[0], pipeHandler, "");
|
2011-12-29 14:39:25 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2012-10-31 10:29:14 -07:00
|
|
|
InitGonkMemoryPressureMonitoring();
|
|
|
|
|
2013-06-10 05:22:05 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
2014-07-09 20:15:00 -07:00
|
|
|
printf("*****************************************************************\n");
|
|
|
|
printf("***\n");
|
|
|
|
printf("*** This is stdout. Most of the useful output will be in logcat.\n");
|
|
|
|
printf("***\n");
|
|
|
|
printf("*****************************************************************\n");
|
2013-11-21 13:03:27 -08:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
|
|
|
android::MediaResourceManagerService::instantiate();
|
2013-06-11 13:47:44 -07:00
|
|
|
#endif
|
2014-01-08 03:04:32 -08:00
|
|
|
#if ANDROID_VERSION >= 18 && (defined(MOZ_OMX_DECODER) || defined(MOZ_B2G_CAMERA))
|
2013-11-21 13:03:27 -08:00
|
|
|
android::FakeSurfaceComposer::instantiate();
|
|
|
|
#endif
|
2013-12-05 06:29:07 -08:00
|
|
|
GonkPermissionService::instantiate();
|
2014-01-28 13:33:15 -08:00
|
|
|
|
|
|
|
// Causes the kernel timezone to be set, which in turn causes the
|
|
|
|
// timestamps on SD cards to have the local time rather than UTC time.
|
|
|
|
hal::SetTimezone(hal::GetTimezone());
|
2013-11-21 13:03:27 -08:00
|
|
|
}
|
|
|
|
|
2012-11-28 10:43:19 -08:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ = GetObserverService();
|
|
|
|
if (obsServ) {
|
|
|
|
obsServ->AddObserver(this, "browser-ui-startup-complete", false);
|
2014-03-16 23:33:48 -07:00
|
|
|
obsServ->AddObserver(this, "network-connection-state-changed", false);
|
2012-11-28 10:43:19 -08:00
|
|
|
}
|
|
|
|
|
2013-06-03 03:14:46 -07:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
// Make sure main thread was woken up after Nuwa fork.
|
|
|
|
NuwaAddConstructor((void (*)(void *))&NotifyEvent, nullptr);
|
|
|
|
#endif
|
|
|
|
|
2012-03-25 03:06:02 -07:00
|
|
|
// Delay initializing input devices until the screen has been
|
|
|
|
// initialized (and we know the resolution).
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-11-28 10:43:19 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShell::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aData)
|
2012-11-28 10:43:19 -08:00
|
|
|
{
|
2014-03-16 23:33:48 -07:00
|
|
|
if (!strcmp(aTopic, "network-connection-state-changed")) {
|
|
|
|
NS_ConvertUTF16toUTF8 type(aData);
|
|
|
|
if (!type.IsEmpty()) {
|
|
|
|
hal::NotifyNetworkChange(hal::NetworkInformation(atoi(type.get()), 0, 0));
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
} else if (!strcmp(aTopic, "browser-ui-startup-complete")) {
|
|
|
|
if (sDevInputAudioJack) {
|
|
|
|
sHeadphoneState = mReader->getSwitchState(-1, AINPUT_SOURCE_SWITCH, SW_HEADPHONE_INSERT);
|
|
|
|
sMicrophoneState = mReader->getSwitchState(-1, AINPUT_SOURCE_SWITCH, SW_MICROPHONE_INSERT);
|
|
|
|
updateHeadphoneSwitch();
|
|
|
|
}
|
|
|
|
mEnableDraw = true;
|
|
|
|
NotifyEvent();
|
|
|
|
return NS_OK;
|
2013-07-29 21:27:48 -07:00
|
|
|
}
|
|
|
|
|
2014-03-16 23:33:48 -07:00
|
|
|
return nsBaseAppShell::Observe(aSubject, aTopic, aData);
|
2012-11-28 10:43:19 -08:00
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShell::Exit()
|
|
|
|
{
|
2012-11-28 10:43:19 -08:00
|
|
|
OrientationObserver::ShutDown();
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ = GetObserverService();
|
|
|
|
if (obsServ) {
|
|
|
|
obsServ->RemoveObserver(this, "browser-ui-startup-complete");
|
2014-03-16 23:33:48 -07:00
|
|
|
obsServ->RemoveObserver(this, "network-connection-state-changed");
|
2012-11-28 10:43:19 -08:00
|
|
|
}
|
|
|
|
return nsBaseAppShell::Exit();
|
2012-06-10 16:44:50 -07:00
|
|
|
}
|
|
|
|
|
2012-03-25 03:06:02 -07:00
|
|
|
void
|
|
|
|
nsAppShell::InitInputDevices()
|
|
|
|
{
|
2014-07-01 10:52:00 -07:00
|
|
|
sDevInputAudioJack = hal::IsHeadphoneEventFromInputDev();
|
2013-07-29 21:27:48 -07:00
|
|
|
sHeadphoneState = AKEY_STATE_UNKNOWN;
|
|
|
|
sMicrophoneState = AKEY_STATE_UNKNOWN;
|
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
mEventHub = new EventHub();
|
|
|
|
mReaderPolicy = new GeckoInputReaderPolicy();
|
2012-03-25 03:06:02 -07:00
|
|
|
mReaderPolicy->setDisplayInfo();
|
2013-11-11 15:19:04 -08:00
|
|
|
mDispatcher = new GeckoInputDispatcher(mEventHub);
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
mReader = new InputReader(mEventHub, mReaderPolicy, mDispatcher);
|
|
|
|
mReaderThread = new InputReaderThread(mReader);
|
2011-11-10 16:17:46 -08:00
|
|
|
|
2012-01-25 11:00:34 -08:00
|
|
|
status_t result = mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY);
|
2012-03-25 03:06:02 -07:00
|
|
|
if (result) {
|
|
|
|
LOG("Failed to initialize InputReader thread, bad things are going to happen...");
|
|
|
|
}
|
2011-11-10 16:17:46 -08:00
|
|
|
}
|
|
|
|
|
2011-12-29 14:39:25 -08:00
|
|
|
nsresult
|
2011-12-29 14:39:25 -08:00
|
|
|
nsAppShell::AddFdHandler(int fd, FdHandlerCallback handlerFunc,
|
|
|
|
const char* deviceName)
|
2011-12-29 14:39:25 -08:00
|
|
|
{
|
|
|
|
epoll_event event = {
|
|
|
|
EPOLLIN,
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
FdHandler *handler = mHandlers.AppendElement();
|
|
|
|
handler->fd = fd;
|
2011-12-29 14:39:25 -08:00
|
|
|
strncpy(handler->name, deviceName, sizeof(handler->name) - 1);
|
2011-12-29 14:39:25 -08:00
|
|
|
handler->func = handlerFunc;
|
|
|
|
event.data.u32 = mHandlers.Length() - 1;
|
|
|
|
return epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &event) ?
|
|
|
|
NS_ERROR_UNEXPECTED : NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
void
|
|
|
|
nsAppShell::ScheduleNativeEventCallback()
|
|
|
|
{
|
|
|
|
mNativeCallbackRequest = true;
|
|
|
|
NotifyEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
|
|
|
{
|
2014-05-23 14:12:29 -07:00
|
|
|
PROFILER_LABEL("nsAppShell", "ProcessNextNativeEvent",
|
|
|
|
js::ProfileEntry::Category::EVENTS);
|
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
epoll_event events[16] = {{ 0 }};
|
|
|
|
|
|
|
|
int event_count;
|
2012-06-27 08:55:42 -07:00
|
|
|
{
|
2014-05-23 14:12:29 -07:00
|
|
|
PROFILER_LABEL("nsAppShell", "ProcessNextNativeEvent::Wait",
|
|
|
|
js::ProfileEntry::Category::EVENTS);
|
|
|
|
|
2012-06-27 08:55:42 -07:00
|
|
|
if ((event_count = epoll_wait(epollfd, events, 16, mayWait ? -1 : 0)) <= 0)
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-10 16:17:46 -08:00
|
|
|
|
|
|
|
for (int i = 0; i < event_count; i++)
|
|
|
|
mHandlers[events[i].data.u32].run();
|
|
|
|
|
2012-03-25 17:12:29 -07:00
|
|
|
if (mDispatcher.get())
|
|
|
|
mDispatcher->dispatchOnce();
|
2012-01-25 11:00:34 -08:00
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
// NativeEventCallback always schedules more if it needs it
|
|
|
|
// so we can coalesce these.
|
|
|
|
// See the implementation in nsBaseAppShell.cpp for more info
|
|
|
|
if (mNativeCallbackRequest) {
|
|
|
|
mNativeCallbackRequest = false;
|
|
|
|
NativeEventCallback();
|
|
|
|
}
|
|
|
|
|
2012-11-28 10:43:19 -08:00
|
|
|
if (gDrawRequest && mEnableDraw) {
|
2011-11-10 16:17:46 -08:00
|
|
|
gDrawRequest = false;
|
|
|
|
nsWindow::DoDraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::NotifyNativeEvent()
|
|
|
|
{
|
|
|
|
write(signalfds[1], "w", 1);
|
|
|
|
}
|
|
|
|
|
2012-04-24 20:59:01 -07:00
|
|
|
/* static */ void
|
2012-03-25 03:06:02 -07:00
|
|
|
nsAppShell::NotifyScreenInitialized()
|
|
|
|
{
|
|
|
|
gAppShell->InitInputDevices();
|
2012-04-20 04:43:25 -07:00
|
|
|
|
|
|
|
// Getting the instance of OrientationObserver to initialize it.
|
|
|
|
OrientationObserver::GetInstance();
|
2012-03-25 03:06:02 -07:00
|
|
|
}
|
2012-04-24 20:59:01 -07:00
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsAppShell::NotifyScreenRotation()
|
|
|
|
{
|
|
|
|
gAppShell->mReaderPolicy->setDisplayInfo();
|
|
|
|
gAppShell->mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
|
2012-05-08 14:36:07 -07:00
|
|
|
|
|
|
|
hal::NotifyScreenConfigurationChange(nsScreenGonk::GetConfiguration());
|
2012-04-24 20:59:01 -07:00
|
|
|
}
|