2011-11-11 04:17:46 +04: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 13:10:44 +04: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-11 04:17:46 +04:00
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
|
|
|
#include <dirent.h>
|
2011-12-30 02:39:25 +04:00
|
|
|
#include <errno.h>
|
2011-11-11 04:17:46 +04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/epoll.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
2011-12-30 02:39:25 +04:00
|
|
|
#include <sys/types.h>
|
2011-11-11 04:17:46 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2012-04-20 15:43:25 +04:00
|
|
|
#include "base/basictypes.h"
|
2011-12-30 02:39:25 +04:00
|
|
|
#include "nscore.h"
|
2013-06-12 00:47:44 +04:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2013-06-10 16:22:05 +04:00
|
|
|
#include "MediaResourceManagerService.h"
|
2013-06-12 00:47:44 +04:00
|
|
|
#endif
|
2013-09-25 15:21:16 +04:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2011-12-30 02:39:25 +04:00
|
|
|
#include "mozilla/FileUtils.h"
|
2012-04-20 15:43:25 +04:00
|
|
|
#include "mozilla/Hal.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2012-01-25 23:00:34 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2011-12-30 02:39:25 +04:00
|
|
|
#include "mozilla/Services.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-11-22 01:03:27 +04:00
|
|
|
#if ANDROID_VERSION >= 18
|
|
|
|
#include "nativewindow/FakeSurfaceComposer.h"
|
|
|
|
#endif
|
2011-11-11 04:17:46 +04:00
|
|
|
#include "nsAppShell.h"
|
2013-04-05 12:49:00 +04:00
|
|
|
#include "mozilla/dom/Touch.h"
|
2011-11-11 04:17:46 +04:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIObserverService.h"
|
2012-02-07 05:47:11 +04:00
|
|
|
#include "nsIScreen.h"
|
|
|
|
#include "nsScreenManagerGonk.h"
|
2013-08-28 08:14:57 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2011-12-30 02:39:25 +04:00
|
|
|
#include "nsWindow.h"
|
2012-04-20 15:43:25 +04:00
|
|
|
#include "OrientationObserver.h"
|
2012-10-31 21:29:14 +04:00
|
|
|
#include "GonkMemoryPressureMonitoring.h"
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
#include "android/log.h"
|
2012-03-25 14:06:02 +04:00
|
|
|
#include "libui/EventHub.h"
|
|
|
|
#include "libui/InputReader.h"
|
|
|
|
#include "libui/InputDispatcher.h"
|
2013-07-30 08:27:48 +04:00
|
|
|
#include "cutils/properties.h"
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2013-06-03 14:14:46 +04:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
#include "ipc/Nuwa.h"
|
|
|
|
#endif
|
|
|
|
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2012-06-27 19:55:42 +04:00
|
|
|
|
2013-04-24 07:49:48 +04:00
|
|
|
// Defines kKeyMapping and GetKeyNameIndex()
|
|
|
|
#include "GonkKeyMapping.h"
|
|
|
|
|
2011-12-30 02:39:25 +04: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-11 04:17:46 +04:00
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
using namespace android;
|
2012-05-09 01:36:07 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2012-11-28 22:43:19 +04:00
|
|
|
using namespace mozilla::services;
|
2012-12-16 05:26:04 +04:00
|
|
|
using namespace mozilla::widget;
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
bool gDrawRequest = false;
|
2013-10-28 18:05:51 +04:00
|
|
|
static nsAppShell *gAppShell = nullptr;
|
2011-11-11 04:17:46 +04:00
|
|
|
static int epollfd = 0;
|
|
|
|
static int signalfds[2] = {0};
|
2013-07-30 08:27:48 +04:00
|
|
|
static bool sDevInputAudioJack;
|
|
|
|
static int32_t sHeadphoneState;
|
|
|
|
static int32_t sMicrophoneState;
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-11-28 22:43:19 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsAppShell, nsBaseAppShell, nsIObserver)
|
|
|
|
|
2011-11-11 04:17:46 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
bool ProcessNextEvent()
|
|
|
|
{
|
|
|
|
return gAppShell->ProcessNextNativeEvent(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyEvent()
|
|
|
|
{
|
|
|
|
gAppShell->NotifyNativeEvent();
|
|
|
|
}
|
|
|
|
|
2013-04-05 12:49:00 +04:00
|
|
|
} // namespace mozilla
|
2011-11-11 04:17:46 +04: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-26 00:37:31 +04: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-12 03:19:04 +04:00
|
|
|
int32_t deviceId;
|
2012-01-26 00:37:31 +04:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int32_t keyCode;
|
|
|
|
int32_t scanCode;
|
|
|
|
} key;
|
|
|
|
struct {
|
|
|
|
int32_t touchCount;
|
2013-04-05 12:49:00 +04:00
|
|
|
::Touch touches[MAX_POINTERS];
|
2012-01-26 00:37:31 +04:00
|
|
|
} motion;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2011-11-11 04:17:46 +04:00
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
sendMouseEvent(uint32_t msg, uint64_t timeMs, int x, int y, bool forwardToChildren)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
2013-10-28 18:05:51 +04:00
|
|
|
WidgetMouseEvent event(true, msg, nullptr,
|
2013-10-02 10:38:27 +04:00
|
|
|
WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
event.refPoint.x = x;
|
|
|
|
event.refPoint.y = y;
|
2012-01-25 23:00:34 +04:00
|
|
|
event.time = timeMs;
|
2013-10-02 10:38:27 +04:00
|
|
|
event.button = WidgetMouseEvent::eLeftButton;
|
2013-01-24 18:53:39 +04:00
|
|
|
event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
|
2011-11-11 04:17:46 +04:00
|
|
|
if (msg != NS_MOUSE_MOVE)
|
|
|
|
event.clickCount = 1;
|
|
|
|
|
2012-12-16 05:26:05 +04:00
|
|
|
event.mFlags.mNoCrossProcessBoundaryForwarding = !forwardToChildren;
|
2012-07-19 23:40:24 +04:00
|
|
|
|
2011-11-11 04:17:46 +04:00
|
|
|
nsWindow::DispatchInputEvent(event);
|
|
|
|
}
|
|
|
|
|
2012-01-26 00:37:31 +04:00
|
|
|
static void
|
2013-09-27 10:20:57 +04:00
|
|
|
addDOMTouch(UserInputData& data, WidgetTouchEvent& event, int i)
|
2012-01-26 00:37:31 +04:00
|
|
|
{
|
2013-04-05 12:49:00 +04:00
|
|
|
const ::Touch& touch = data.motion.touches[i];
|
2012-01-26 00:37:31 +04:00
|
|
|
event.touches.AppendElement(
|
2013-04-05 12:49:00 +04:00
|
|
|
new dom::Touch(touch.id,
|
2012-03-25 14:06:02 +04:00
|
|
|
nsIntPoint(touch.coords.getX(), touch.coords.getY()),
|
|
|
|
nsIntPoint(touch.coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE),
|
|
|
|
touch.coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE)),
|
2012-01-26 00:37:31 +04:00
|
|
|
0,
|
2012-03-25 14:06:02 +04:00
|
|
|
touch.coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE))
|
|
|
|
);
|
2012-01-26 00:37:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsEventStatus
|
2012-09-12 00:05:52 +04:00
|
|
|
sendTouchEvent(UserInputData& data, bool* captured)
|
2012-01-26 00:37:31 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t msg;
|
2012-01-26 00:37:31 +04:00
|
|
|
int32_t action = data.action & AMOTION_EVENT_ACTION_MASK;
|
|
|
|
switch (action) {
|
|
|
|
case AMOTION_EVENT_ACTION_DOWN:
|
|
|
|
case AMOTION_EVENT_ACTION_POINTER_DOWN:
|
|
|
|
msg = NS_TOUCH_START;
|
|
|
|
break;
|
|
|
|
case AMOTION_EVENT_ACTION_MOVE:
|
|
|
|
msg = NS_TOUCH_MOVE;
|
|
|
|
break;
|
|
|
|
case AMOTION_EVENT_ACTION_UP:
|
|
|
|
case AMOTION_EVENT_ACTION_POINTER_UP:
|
|
|
|
msg = NS_TOUCH_END;
|
|
|
|
break;
|
|
|
|
case AMOTION_EVENT_ACTION_OUTSIDE:
|
|
|
|
case AMOTION_EVENT_ACTION_CANCEL:
|
|
|
|
msg = NS_TOUCH_CANCEL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-28 18:05:51 +04:00
|
|
|
WidgetTouchEvent event(true, msg, nullptr);
|
2012-01-26 00:37:31 +04:00
|
|
|
|
|
|
|
event.time = data.timeMs;
|
|
|
|
|
|
|
|
int32_t i;
|
|
|
|
if (msg == NS_TOUCH_END) {
|
|
|
|
i = data.action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK;
|
|
|
|
i >>= AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
|
|
|
|
addDOMTouch(data, event, i);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < data.motion.touchCount; ++i)
|
|
|
|
addDOMTouch(data, event, i);
|
|
|
|
}
|
|
|
|
|
2012-09-12 00:05:52 +04:00
|
|
|
return nsWindow::DispatchInputEvent(event, captured);
|
2012-01-26 00:37:31 +04:00
|
|
|
}
|
|
|
|
|
2011-12-24 11:13:33 +04:00
|
|
|
static nsEventStatus
|
2012-08-22 19:56:38 +04:00
|
|
|
sendKeyEventWithMsg(uint32_t keyCode,
|
2013-11-12 03:19:04 +04:00
|
|
|
int16_t charCode,
|
2013-04-24 07:49:48 +04:00
|
|
|
KeyNameIndex keyNameIndex,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t msg,
|
2013-11-07 15:17:33 +04:00
|
|
|
uint64_t timeMs,
|
|
|
|
bool isRepeat)
|
2011-12-24 11:13:33 +04:00
|
|
|
{
|
2013-10-28 18:05:51 +04:00
|
|
|
WidgetKeyboardEvent event(true, msg, nullptr);
|
2013-11-19 22:14:41 +04:00
|
|
|
if (msg == NS_KEY_PRESS && charCode >= ' ') {
|
|
|
|
event.charCode = charCode;
|
|
|
|
} else {
|
|
|
|
event.keyCode = keyCode;
|
|
|
|
}
|
|
|
|
event.isChar = !!event.charCode;
|
2013-11-07 15:17:33 +04:00
|
|
|
event.mIsRepeat = isRepeat;
|
2013-04-24 07:49:48 +04:00
|
|
|
event.mKeyNameIndex = keyNameIndex;
|
2012-05-03 12:35:02 +04:00
|
|
|
event.location = nsIDOMKeyEvent::DOM_KEY_LOCATION_MOBILE;
|
2012-01-25 23:00:34 +04:00
|
|
|
event.time = timeMs;
|
2011-12-24 11:13:33 +04:00
|
|
|
return nsWindow::DispatchInputEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-12 03:19:04 +04:00
|
|
|
sendKeyEvent(uint32_t keyCode, int16_t charCode, KeyNameIndex keyNameIndex,
|
|
|
|
bool down, uint64_t timeMs, bool isRepeat)
|
2011-12-24 11:13:33 +04:00
|
|
|
{
|
2012-12-16 05:26:04 +04:00
|
|
|
EventFlags extraFlags;
|
2011-12-24 11:13:33 +04:00
|
|
|
nsEventStatus status =
|
2013-11-12 03:19:04 +04:00
|
|
|
sendKeyEventWithMsg(keyCode, charCode, keyNameIndex,
|
2013-11-07 15:17:33 +04:00
|
|
|
down ? NS_KEY_DOWN : NS_KEY_UP, timeMs, isRepeat);
|
2013-07-25 10:09:28 +04:00
|
|
|
if (down && status != nsEventStatus_eConsumeNoDefault) {
|
2013-11-12 03:19:04 +04:00
|
|
|
sendKeyEventWithMsg(keyCode, charCode, keyNameIndex, NS_KEY_PRESS,
|
|
|
|
timeMs, isRepeat);
|
2013-04-24 07:49:48 +04:00
|
|
|
}
|
2011-12-30 02:39:25 +04:00
|
|
|
}
|
|
|
|
|
2013-07-30 08:27:48 +04:00
|
|
|
class SwitchEventRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
SwitchEventRunnable(hal::SwitchEvent& aEvent) : mEvent(aEvent)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
hal::NotifySwitchChange(mEvent);
|
|
|
|
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 ?
|
|
|
|
hal::SWITCH_STATE_HEADPHONE : hal::SWITCH_STATE_HEADSET;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.device() = hal::SWITCH_HEADPHONES;
|
|
|
|
NS_DispatchToMainThread(new SwitchEventRunnable(event));
|
|
|
|
}
|
|
|
|
|
2012-08-24 22:06:19 +04: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-27 01:59:18 +04:00
|
|
|
DisplayViewport viewport;
|
|
|
|
|
|
|
|
mConfig->getDisplayInfo(false, &viewport);
|
2012-08-24 22:06:19 +04:00
|
|
|
|
|
|
|
*outMinX = *outMinY = 0;
|
2013-12-04 01:44:01 +04:00
|
|
|
*outMaxX = viewport.logicalRight;
|
|
|
|
*outMaxY = viewport.logicalBottom;
|
2012-08-24 22:06:19 +04: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 23:00:34 +04:00
|
|
|
class GeckoInputReaderPolicy : public InputReaderPolicyInterface {
|
2012-03-25 14:06:02 +04:00
|
|
|
InputReaderConfiguration mConfig;
|
2012-01-25 23:00:34 +04:00
|
|
|
public:
|
|
|
|
GeckoInputReaderPolicy() {}
|
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
|
2012-04-11 05:49:49 +04:00
|
|
|
virtual sp<PointerControllerInterface> obtainPointerController(int32_t
|
2012-04-24 13:56:15 +04:00
|
|
|
deviceId)
|
|
|
|
{
|
2012-08-24 22:06:19 +04:00
|
|
|
return new GeckoPointerController(&mConfig);
|
2012-04-24 13:56:15 +04:00
|
|
|
};
|
2013-08-27 01:59:18 +04:00
|
|
|
virtual void notifyInputDevicesChanged(const android::Vector<InputDeviceInfo>& inputDevices) {};
|
|
|
|
virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor)
|
|
|
|
{
|
2013-10-28 18:05:51 +04:00
|
|
|
return nullptr;
|
2013-08-27 01:59:18 +04:00
|
|
|
};
|
|
|
|
virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier)
|
|
|
|
{
|
|
|
|
return String8::empty();
|
|
|
|
};
|
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
void setDisplayInfo();
|
2012-01-25 23:00:34 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~GeckoInputReaderPolicy() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GeckoInputDispatcher : public InputDispatcherInterface {
|
|
|
|
public:
|
2013-11-12 03:19:04 +04:00
|
|
|
GeckoInputDispatcher(sp<EventHub> &aEventHub)
|
2012-01-25 23:00:34 +04:00
|
|
|
: mQueueLock("GeckoInputDispatcher::mQueueMutex")
|
2013-11-12 03:19:04 +04:00
|
|
|
, mEventHub(aEventHub)
|
2012-01-25 23:00:34 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
virtual void dump(String8& dump);
|
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
virtual void monitor() {}
|
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
// Called on the main thread
|
|
|
|
virtual void dispatchOnce();
|
|
|
|
|
|
|
|
// notify* methods are called on the InputReaderThread
|
2012-03-25 14:06:02 +04: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 23:00:34 +04:00
|
|
|
|
|
|
|
virtual int32_t injectInputEvent(const InputEvent* event,
|
2012-03-25 14:06:02 +04:00
|
|
|
int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
|
|
|
|
uint32_t policyFlags);
|
|
|
|
|
2013-07-10 03:33:29 +04:00
|
|
|
virtual void setInputWindows(const android::Vector<sp<InputWindowHandle> >& inputWindowHandles);
|
2012-03-25 14:06:02 +04:00
|
|
|
virtual void setFocusedApplication(const sp<InputApplicationHandle>& inputApplicationHandle);
|
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
virtual void setInputDispatchMode(bool enabled, bool frozen);
|
2012-03-25 14:06:02 +04: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 23:00:34 +04:00
|
|
|
virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel);
|
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
|
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
protected:
|
|
|
|
virtual ~GeckoInputDispatcher() {}
|
|
|
|
|
|
|
|
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-12 03:19:04 +04:00
|
|
|
sp<EventHub> mEventHub;
|
2012-01-25 23:00:34 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// GeckoInputReaderPolicy
|
2012-03-25 14:06:02 +04:00
|
|
|
void
|
|
|
|
GeckoInputReaderPolicy::setDisplayInfo()
|
2011-12-30 02:39:25 +04:00
|
|
|
{
|
2013-07-18 21:59:53 +04: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-07 05:47:11 +04:00
|
|
|
|
2013-08-27 01:59:18 +04:00
|
|
|
DisplayViewport viewport;
|
|
|
|
viewport.displayId = 0;
|
|
|
|
viewport.orientation = nsScreenGonk::GetRotation();
|
2013-09-25 01:58:58 +04: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-27 01:59:18 +04:00
|
|
|
mConfig.setDisplayInfo(false, viewport);
|
2011-12-30 02:39:25 +04:00
|
|
|
}
|
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
void GeckoInputReaderPolicy::getReaderConfiguration(InputReaderConfiguration* outConfig)
|
2011-12-30 02:39:25 +04:00
|
|
|
{
|
2012-03-25 14:06:02 +04:00
|
|
|
*outConfig = mConfig;
|
2012-01-25 23:00:34 +04:00
|
|
|
}
|
2011-12-30 02:39:25 +04:00
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
|
|
|
|
// GeckoInputDispatcher
|
|
|
|
void
|
|
|
|
GeckoInputDispatcher::dump(String8& dump)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GeckoInputDispatcher::dispatchOnce()
|
|
|
|
{
|
|
|
|
UserInputData data;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mQueueLock);
|
|
|
|
if (mEventQueue.empty())
|
|
|
|
return;
|
|
|
|
data = mEventQueue.front();
|
|
|
|
mEventQueue.pop();
|
|
|
|
if (!mEventQueue.empty())
|
|
|
|
gAppShell->NotifyNativeEvent();
|
2011-12-30 02:39:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
switch (data.type) {
|
|
|
|
case UserInputData::MOTION_DATA: {
|
2012-08-24 22:06:19 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
if ((data.action & AMOTION_EVENT_ACTION_MASK) !=
|
|
|
|
AMOTION_EVENT_ACTION_HOVER_MOVE) {
|
2012-09-12 00:05:52 +04:00
|
|
|
bool captured;
|
|
|
|
status = sendTouchEvent(data, &captured);
|
|
|
|
if (captured) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-24 22:06:19 +04:00
|
|
|
}
|
2012-01-26 00:37:31 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t msg;
|
2012-01-26 00:37:31 +04:00
|
|
|
switch (data.action & AMOTION_EVENT_ACTION_MASK) {
|
2012-01-25 23:00:34 +04:00
|
|
|
case AMOTION_EVENT_ACTION_DOWN:
|
|
|
|
msg = NS_MOUSE_BUTTON_DOWN;
|
|
|
|
break;
|
2012-01-26 00:37:31 +04:00
|
|
|
case AMOTION_EVENT_ACTION_POINTER_DOWN:
|
|
|
|
case AMOTION_EVENT_ACTION_POINTER_UP:
|
2012-01-25 23:00:34 +04:00
|
|
|
case AMOTION_EVENT_ACTION_MOVE:
|
2012-08-24 22:06:19 +04:00
|
|
|
case AMOTION_EVENT_ACTION_HOVER_MOVE:
|
2012-01-25 23:00:34 +04:00
|
|
|
msg = NS_MOUSE_MOVE;
|
|
|
|
break;
|
2012-01-26 00:37:31 +04:00
|
|
|
case AMOTION_EVENT_ACTION_OUTSIDE:
|
|
|
|
case AMOTION_EVENT_ACTION_CANCEL:
|
2012-01-25 23:00:34 +04:00
|
|
|
case AMOTION_EVENT_ACTION_UP:
|
|
|
|
msg = NS_MOUSE_BUTTON_UP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sendMouseEvent(msg,
|
|
|
|
data.timeMs,
|
2012-03-25 14:06:02 +04:00
|
|
|
data.motion.touches[0].coords.getX(),
|
2012-07-19 23:40:24 +04:00
|
|
|
data.motion.touches[0].coords.getY(),
|
|
|
|
status != nsEventStatus_eConsumeNoDefault);
|
2012-01-25 23:00:34 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-11-07 15:17:33 +04:00
|
|
|
case UserInputData::KEY_DATA: {
|
2013-11-12 03:19:04 +04:00
|
|
|
uint32_t DOMKeyCode =
|
|
|
|
(data.key.keyCode < ArrayLength(kKeyMapping)) ?
|
|
|
|
kKeyMapping[data.key.keyCode] : 0;
|
|
|
|
KeyNameIndex DOMKeyNameIndex = GetKeyNameIndex(data.key.keyCode);
|
|
|
|
if (!DOMKeyCode && DOMKeyNameIndex == KEY_NAME_INDEX_Unidentified) {
|
|
|
|
VERBOSE_LOG("Got unknown key event code. "
|
|
|
|
"type 0x%04x code 0x%04x value %d",
|
|
|
|
keyCode, pressed);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-07 15:17:33 +04:00
|
|
|
bool isPress = data.action == AKEY_EVENT_ACTION_DOWN;
|
2013-11-12 03:19:04 +04:00
|
|
|
bool isRepeat = isPress && (data.flags & AKEY_EVENT_FLAG_LONG_PRESS);
|
|
|
|
int16_t charCode = 0;
|
|
|
|
sp<KeyCharacterMap> kcm = mEventHub->getKeyCharacterMap(data.deviceId);
|
|
|
|
if (kcm.get())
|
|
|
|
charCode = kcm->getCharacter(data.key.keyCode, data.metaState);
|
|
|
|
sendKeyEvent(DOMKeyCode,
|
|
|
|
charCode,
|
|
|
|
DOMKeyNameIndex,
|
|
|
|
isPress,
|
|
|
|
data.timeMs,
|
|
|
|
isRepeat);
|
2012-01-25 23:00:34 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-11-07 15:17:33 +04:00
|
|
|
}
|
2012-01-25 23:00:34 +04:00
|
|
|
}
|
2011-12-30 02:39:25 +04:00
|
|
|
|
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
void
|
2012-03-25 14:06:02 +04:00
|
|
|
GeckoInputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChangedArgs*)
|
2012-01-25 23:00:34 +04:00
|
|
|
{
|
2011-12-24 11:13:33 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
static uint64_t
|
|
|
|
nanosecsToMillisecs(nsecs_t nsecs)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
2012-01-25 23:00:34 +04:00
|
|
|
return nsecs / 1000000;
|
|
|
|
}
|
2011-12-30 02:39:25 +04:00
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
void
|
2012-03-25 14:06:02 +04:00
|
|
|
GeckoInputDispatcher::notifyKey(const NotifyKeyArgs* args)
|
2012-01-25 23:00:34 +04:00
|
|
|
{
|
|
|
|
UserInputData data;
|
2012-03-25 14:06:02 +04:00
|
|
|
data.timeMs = nanosecsToMillisecs(args->eventTime);
|
2012-01-25 23:00:34 +04:00
|
|
|
data.type = UserInputData::KEY_DATA;
|
2012-03-25 14:06:02 +04:00
|
|
|
data.action = args->action;
|
|
|
|
data.flags = args->flags;
|
|
|
|
data.metaState = args->metaState;
|
2013-11-12 03:19:04 +04:00
|
|
|
data.deviceId = args->deviceId;
|
2012-03-25 14:06:02 +04:00
|
|
|
data.key.keyCode = args->keyCode;
|
|
|
|
data.key.scanCode = args->scanCode;
|
2012-01-25 23:00:34 +04:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mQueueLock);
|
|
|
|
mEventQueue.push(data);
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
2012-01-25 23:00:34 +04:00
|
|
|
gAppShell->NotifyNativeEvent();
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
void
|
2012-03-25 14:06:02 +04:00
|
|
|
GeckoInputDispatcher::notifyMotion(const NotifyMotionArgs* args)
|
2012-01-25 23:00:34 +04:00
|
|
|
{
|
|
|
|
UserInputData data;
|
2012-03-25 14:06:02 +04:00
|
|
|
data.timeMs = nanosecsToMillisecs(args->eventTime);
|
2012-01-25 23:00:34 +04:00
|
|
|
data.type = UserInputData::MOTION_DATA;
|
2012-03-25 14:06:02 +04:00
|
|
|
data.action = args->action;
|
|
|
|
data.flags = args->flags;
|
|
|
|
data.metaState = args->metaState;
|
2013-11-12 03:19:04 +04:00
|
|
|
data.deviceId = args->deviceId;
|
2012-03-25 14:06:02 +04:00
|
|
|
MOZ_ASSERT(args->pointerCount <= MAX_POINTERS);
|
|
|
|
data.motion.touchCount = args->pointerCount;
|
|
|
|
for (uint32_t i = 0; i < args->pointerCount; ++i) {
|
2013-04-05 12:49:00 +04:00
|
|
|
::Touch& touch = data.motion.touches[i];
|
2012-03-25 14:06:02 +04:00
|
|
|
touch.id = args->pointerProperties[i].id;
|
|
|
|
memcpy(&touch.coords, &args->pointerCoords[i], sizeof(*args->pointerCoords));
|
2012-01-26 00:37:31 +04:00
|
|
|
}
|
2012-01-25 23:00:34 +04:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mQueueLock);
|
2012-02-10 02:37:22 +04:00
|
|
|
if (!mEventQueue.empty() &&
|
|
|
|
mEventQueue.back().type == UserInputData::MOTION_DATA &&
|
2012-08-24 22:06:19 +04:00
|
|
|
((mEventQueue.back().action & AMOTION_EVENT_ACTION_MASK) ==
|
|
|
|
AMOTION_EVENT_ACTION_MOVE ||
|
2012-02-10 02:37:22 +04:00
|
|
|
(mEventQueue.back().action & AMOTION_EVENT_ACTION_MASK) ==
|
2012-08-24 22:06:19 +04:00
|
|
|
AMOTION_EVENT_ACTION_HOVER_MOVE))
|
2012-02-08 10:42:44 +04:00
|
|
|
mEventQueue.back() = data;
|
|
|
|
else
|
|
|
|
mEventQueue.push(data);
|
2011-12-24 11:13:33 +04:00
|
|
|
}
|
2012-01-25 23:00:34 +04:00
|
|
|
gAppShell->NotifyNativeEvent();
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
|
|
|
|
|
|
|
|
void GeckoInputDispatcher::notifySwitch(const NotifySwitchArgs* args)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
2013-07-30 08:27:48 +04:00
|
|
|
if (!sDevInputAudioJack)
|
|
|
|
return;
|
|
|
|
|
2013-08-27 01:59:18 +04: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-30 08:27:48 +04:00
|
|
|
}
|
2013-08-27 01:59:18 +04: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 23:00:34 +04:00
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
void GeckoInputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args)
|
|
|
|
{
|
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-03-25 14:06:02 +04: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 23:00:34 +04:00
|
|
|
{
|
|
|
|
return INPUT_EVENT_INJECTION_SUCCEEDED;
|
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
void
|
2013-07-10 03:33:29 +04:00
|
|
|
GeckoInputDispatcher::setInputWindows(const android::Vector<sp<InputWindowHandle> >& inputWindowHandles)
|
2012-01-25 23:00:34 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-25 14:06:02 +04:00
|
|
|
GeckoInputDispatcher::setFocusedApplication(const sp<InputApplicationHandle>& inputApplicationHandle)
|
2012-01-25 23:00:34 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GeckoInputDispatcher::setInputDispatchMode(bool enabled, bool frozen)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t
|
|
|
|
GeckoInputDispatcher::registerInputChannel(const sp<InputChannel>& inputChannel,
|
2012-03-25 14:06:02 +04:00
|
|
|
const sp<InputWindowHandle>& inputWindowHandle, bool monitor)
|
2012-01-25 23:00:34 +04:00
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t
|
|
|
|
GeckoInputDispatcher::unregisterInputChannel(const sp<InputChannel>& inputChannel)
|
|
|
|
{
|
|
|
|
return OK;
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShell::nsAppShell()
|
|
|
|
: mNativeCallbackRequest(false)
|
2012-11-28 22:43:19 +04:00
|
|
|
, mEnableDraw(false)
|
2013-07-11 21:04:17 +04:00
|
|
|
, mHandlers()
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
|
|
|
gAppShell = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShell::~nsAppShell()
|
|
|
|
{
|
2012-11-28 07:07:19 +04: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 18:05:51 +04:00
|
|
|
gAppShell = nullptr;
|
2011-11-11 04:17:46 +04: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-30 02:39:25 +04:00
|
|
|
rv = AddFdHandler(signalfds[0], pipeHandler, "");
|
2011-12-30 02:39:25 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-10-31 21:29:14 +04:00
|
|
|
InitGonkMemoryPressureMonitoring();
|
|
|
|
|
2013-06-10 16:22:05 +04:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
2013-11-22 01:03:27 +04:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
|
|
|
android::MediaResourceManagerService::instantiate();
|
2013-06-12 00:47:44 +04:00
|
|
|
#endif
|
2013-11-22 01:03:27 +04:00
|
|
|
#if ANDROID_VERSION >= 18
|
|
|
|
android::FakeSurfaceComposer::instantiate();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:43:19 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obsServ = GetObserverService();
|
|
|
|
if (obsServ) {
|
|
|
|
obsServ->AddObserver(this, "browser-ui-startup-complete", false);
|
|
|
|
}
|
|
|
|
|
2013-06-03 14:14:46 +04:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
// Make sure main thread was woken up after Nuwa fork.
|
|
|
|
NuwaAddConstructor((void (*)(void *))&NotifyEvent, nullptr);
|
|
|
|
#endif
|
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
// Delay initializing input devices until the screen has been
|
|
|
|
// initialized (and we know the resolution).
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:43:19 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShell::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
if (strcmp(aTopic, "browser-ui-startup-complete")) {
|
|
|
|
return nsBaseAppShell::Observe(aSubject, aTopic, aData);
|
|
|
|
}
|
|
|
|
|
2013-07-30 08:27:48 +04:00
|
|
|
if (sDevInputAudioJack) {
|
|
|
|
sHeadphoneState = mReader->getSwitchState(-1, AINPUT_SOURCE_SWITCH, SW_HEADPHONE_INSERT);
|
|
|
|
sMicrophoneState = mReader->getSwitchState(-1, AINPUT_SOURCE_SWITCH, SW_MICROPHONE_INSERT);
|
|
|
|
updateHeadphoneSwitch();
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:43:19 +04:00
|
|
|
mEnableDraw = true;
|
|
|
|
NotifyEvent();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShell::Exit()
|
|
|
|
{
|
2012-11-28 22:43:19 +04:00
|
|
|
OrientationObserver::ShutDown();
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ = GetObserverService();
|
|
|
|
if (obsServ) {
|
|
|
|
obsServ->RemoveObserver(this, "browser-ui-startup-complete");
|
|
|
|
}
|
|
|
|
return nsBaseAppShell::Exit();
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
void
|
|
|
|
nsAppShell::InitInputDevices()
|
|
|
|
{
|
2013-07-30 08:27:48 +04:00
|
|
|
char value[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("ro.moz.devinputjack", value, "0");
|
|
|
|
sDevInputAudioJack = !strcmp(value, "1");
|
|
|
|
sHeadphoneState = AKEY_STATE_UNKNOWN;
|
|
|
|
sMicrophoneState = AKEY_STATE_UNKNOWN;
|
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
mEventHub = new EventHub();
|
|
|
|
mReaderPolicy = new GeckoInputReaderPolicy();
|
2012-03-25 14:06:02 +04:00
|
|
|
mReaderPolicy->setDisplayInfo();
|
2013-11-12 03:19:04 +04:00
|
|
|
mDispatcher = new GeckoInputDispatcher(mEventHub);
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
mReader = new InputReader(mEventHub, mReaderPolicy, mDispatcher);
|
|
|
|
mReaderThread = new InputReaderThread(mReader);
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-01-25 23:00:34 +04:00
|
|
|
status_t result = mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY);
|
2012-03-25 14:06:02 +04:00
|
|
|
if (result) {
|
|
|
|
LOG("Failed to initialize InputReader thread, bad things are going to happen...");
|
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
2011-12-30 02:39:25 +04:00
|
|
|
nsresult
|
2011-12-30 02:39:25 +04:00
|
|
|
nsAppShell::AddFdHandler(int fd, FdHandlerCallback handlerFunc,
|
|
|
|
const char* deviceName)
|
2011-12-30 02:39:25 +04:00
|
|
|
{
|
|
|
|
epoll_event event = {
|
|
|
|
EPOLLIN,
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
FdHandler *handler = mHandlers.AppendElement();
|
|
|
|
handler->fd = fd;
|
2011-12-30 02:39:25 +04:00
|
|
|
strncpy(handler->name, deviceName, sizeof(handler->name) - 1);
|
2011-12-30 02:39:25 +04: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-11 04:17:46 +04:00
|
|
|
void
|
|
|
|
nsAppShell::ScheduleNativeEventCallback()
|
|
|
|
{
|
|
|
|
mNativeCallbackRequest = true;
|
|
|
|
NotifyEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
|
|
|
{
|
2013-03-16 08:47:02 +04:00
|
|
|
PROFILER_LABEL("nsAppShell", "ProcessNextNativeEvent");
|
2011-11-11 04:17:46 +04:00
|
|
|
epoll_event events[16] = {{ 0 }};
|
|
|
|
|
|
|
|
int event_count;
|
2012-06-27 19:55:42 +04:00
|
|
|
{
|
2013-03-16 08:47:02 +04:00
|
|
|
PROFILER_LABEL("nsAppShell", "ProcessNextNativeEvent::Wait");
|
2012-06-27 19:55:42 +04:00
|
|
|
if ((event_count = epoll_wait(epollfd, events, 16, mayWait ? -1 : 0)) <= 0)
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
for (int i = 0; i < event_count; i++)
|
|
|
|
mHandlers[events[i].data.u32].run();
|
|
|
|
|
2012-03-26 04:12:29 +04:00
|
|
|
if (mDispatcher.get())
|
|
|
|
mDispatcher->dispatchOnce();
|
2012-01-25 23:00:34 +04:00
|
|
|
|
2011-11-11 04:17:46 +04: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 22:43:19 +04:00
|
|
|
if (gDrawRequest && mEnableDraw) {
|
2011-11-11 04:17:46 +04:00
|
|
|
gDrawRequest = false;
|
|
|
|
nsWindow::DoDraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::NotifyNativeEvent()
|
|
|
|
{
|
|
|
|
write(signalfds[1], "w", 1);
|
|
|
|
}
|
|
|
|
|
2012-04-25 07:59:01 +04:00
|
|
|
/* static */ void
|
2012-03-25 14:06:02 +04:00
|
|
|
nsAppShell::NotifyScreenInitialized()
|
|
|
|
{
|
|
|
|
gAppShell->InitInputDevices();
|
2012-04-20 15:43:25 +04:00
|
|
|
|
|
|
|
// Getting the instance of OrientationObserver to initialize it.
|
|
|
|
OrientationObserver::GetInstance();
|
2012-03-25 14:06:02 +04:00
|
|
|
}
|
2012-04-25 07:59:01 +04:00
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsAppShell::NotifyScreenRotation()
|
|
|
|
{
|
|
|
|
gAppShell->mReaderPolicy->setDisplayInfo();
|
|
|
|
gAppShell->mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
|
2012-05-09 01:36:07 +04:00
|
|
|
|
|
|
|
hal::NotifyScreenConfigurationChange(nsScreenGonk::GetConfiguration());
|
2012-04-25 07:59:01 +04:00
|
|
|
}
|