2010-11-24 21:22:40 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
#include <android/log.h>
|
2010-08-26 09:52:08 +04:00
|
|
|
#include <math.h>
|
2011-12-21 23:05:23 +04:00
|
|
|
#include <unistd.h>
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2010-11-24 21:22:40 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
#include "mozilla/unused.h"
|
2011-06-07 11:38:00 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-02-27 23:31:29 +04:00
|
|
|
#include "mozilla/layers/RenderTrace.h"
|
2010-11-24 21:22:40 +03:00
|
|
|
|
|
|
|
using mozilla::dom::ContentParent;
|
|
|
|
using mozilla::dom::ContentChild;
|
|
|
|
using mozilla::unused;
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
#include "nsAppShell.h"
|
|
|
|
#include "nsIdleService.h"
|
|
|
|
#include "nsWindow.h"
|
2010-11-24 21:22:40 +03:00
|
|
|
#include "nsIObserverService.h"
|
2011-11-08 23:58:37 +04:00
|
|
|
#include "nsFocusManager.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2010-08-26 09:52:08 +04:00
|
|
|
#include "nsIDOMSimpleGestureEvent.h"
|
2012-01-25 04:31:33 +04:00
|
|
|
#include "nsDOMTouchEvent.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-10-14 22:11:22 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
#include "Layers.h"
|
|
|
|
#include "BasicLayers.h"
|
|
|
|
#include "LayerManagerOGL.h"
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
#include "AndroidBridge.h"
|
2012-04-19 21:49:31 +04:00
|
|
|
#include "android_npapi.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-10-11 04:40:17 +04:00
|
|
|
#include "imgIEncoder.h"
|
|
|
|
|
2011-11-10 05:39:29 +04:00
|
|
|
#include "nsStringGlue.h"
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
using namespace mozilla;
|
2011-11-27 15:51:52 +04:00
|
|
|
using namespace mozilla::widget;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
|
|
|
|
|
|
|
|
// The dimensions of the current android view
|
2011-12-16 03:45:52 +04:00
|
|
|
static gfxIntSize gAndroidBounds = gfxIntSize(0, 0);
|
2011-01-14 23:36:19 +03:00
|
|
|
static gfxIntSize gAndroidScreenBounds;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-12-21 23:05:23 +04:00
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
2012-03-14 08:15:11 +04:00
|
|
|
#include "mozilla/layers/CompositorChild.h"
|
|
|
|
#include "mozilla/layers/CompositorParent.h"
|
2011-12-21 23:05:23 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-11-24 21:22:40 +03:00
|
|
|
class ContentCreationNotifier;
|
|
|
|
static nsCOMPtr<ContentCreationNotifier> gContentCreationNotifier;
|
|
|
|
// A helper class to send updates when content processes
|
|
|
|
// are created. Currently an update for the screen size is sent.
|
|
|
|
class ContentCreationNotifier : public nsIObserver
|
|
|
|
{
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "ipc:content-created")) {
|
2011-08-02 23:35:42 +04:00
|
|
|
nsCOMPtr<nsIObserver> cpo = do_QueryInterface(aSubject);
|
|
|
|
ContentParent* cp = static_cast<ContentParent*>(cpo.get());
|
2011-01-14 23:36:19 +03:00
|
|
|
unused << cp->SendScreenSizeChanged(gAndroidScreenBounds);
|
2010-11-24 21:22:40 +03:00
|
|
|
} else if (!strcmp(aTopic, "xpcom-shutdown")) {
|
|
|
|
nsCOMPtr<nsIObserverService>
|
|
|
|
obs(do_GetService("@mozilla.org/observer-service;1"));
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this),
|
|
|
|
"xpcom-shutdown");
|
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this),
|
|
|
|
"ipc:content-created");
|
|
|
|
}
|
|
|
|
gContentCreationNotifier = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(ContentCreationNotifier,
|
|
|
|
nsIObserver)
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gMenu;
|
|
|
|
static bool gMenuConsumed;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
// All the toplevel windows that have been created; these are in
|
|
|
|
// stacking order, so the window at gAndroidBounds[0] is the topmost
|
|
|
|
// one.
|
|
|
|
static nsTArray<nsWindow*> gTopLevelWindows;
|
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
static nsRefPtr<gl::GLContext> sGLContext;
|
2010-09-09 02:19:11 +04:00
|
|
|
static bool sFailedToCreateGLContext = false;
|
2010-12-14 01:37:25 +03:00
|
|
|
static bool sValidSurface;
|
2011-08-24 00:52:03 +04:00
|
|
|
static bool sSurfaceExists = false;
|
2011-09-21 20:46:00 +04:00
|
|
|
static void *sNativeWindow = nsnull;
|
2010-08-26 09:52:08 +04:00
|
|
|
|
2010-11-18 20:18:31 +03:00
|
|
|
// Multitouch swipe thresholds in inches
|
|
|
|
static const double SWIPE_MAX_PINCH_DELTA_INCHES = 0.4;
|
|
|
|
static const double SWIPE_MIN_DISTANCE_INCHES = 0.6;
|
2010-06-26 04:52:37 +04:00
|
|
|
|
2012-04-20 20:49:50 +04:00
|
|
|
nsWindow*
|
|
|
|
nsWindow::TopWindow()
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
if (!gTopLevelWindows.IsEmpty())
|
|
|
|
return gTopLevelWindows[0];
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::LogWindow(nsWindow *win, int index, int indent)
|
|
|
|
{
|
|
|
|
char spaces[] = " ";
|
|
|
|
spaces[indent < 20 ? indent : 20] = 0;
|
|
|
|
ALOG("%s [% 2d] 0x%08x [parent 0x%08x] [% 3d,% 3d % 3dx% 3d] vis %d type %d",
|
|
|
|
spaces, index, (intptr_t)win, (intptr_t)win->mParent,
|
|
|
|
win->mBounds.x, win->mBounds.y,
|
|
|
|
win->mBounds.width, win->mBounds.height,
|
|
|
|
win->mIsVisible, win->mWindowType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DumpWindows()
|
|
|
|
{
|
|
|
|
DumpWindows(gTopLevelWindows);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DumpWindows(const nsTArray<nsWindow*>& wins, int indent)
|
|
|
|
{
|
2010-06-26 04:52:37 +04:00
|
|
|
for (PRUint32 i = 0; i < wins.Length(); ++i) {
|
2010-06-04 00:56:36 +04:00
|
|
|
nsWindow *w = wins[i];
|
|
|
|
LogWindow(w, i, indent);
|
|
|
|
DumpWindows(w->mChildren, indent+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::nsWindow() :
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsVisible(false),
|
2011-02-15 04:01:01 +03:00
|
|
|
mParent(nsnull),
|
2011-09-23 20:07:40 +04:00
|
|
|
mFocus(nsnull),
|
2011-10-17 18:59:28 +04:00
|
|
|
mIMEComposing(false)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::~nsWindow()
|
|
|
|
{
|
|
|
|
gTopLevelWindows.RemoveElement(this);
|
2011-02-15 04:01:01 +03:00
|
|
|
nsWindow *top = FindTopLevel();
|
|
|
|
if (top->mFocus == this)
|
|
|
|
top->mFocus = nsnull;
|
2010-06-04 00:56:36 +04:00
|
|
|
ALOG("nsWindow %p destructor", (void*)this);
|
2012-03-29 02:00:32 +04:00
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
|
|
|
SetCompositor(NULL, NULL, NULL);
|
|
|
|
#endif
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-06-04 00:56:36 +04:00
|
|
|
nsWindow::IsTopLevel()
|
|
|
|
{
|
|
|
|
return mWindowType == eWindowType_toplevel ||
|
|
|
|
mWindowType == eWindowType_dialog ||
|
|
|
|
mWindowType == eWindowType_invisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
2011-04-17 05:22:44 +04:00
|
|
|
nsDeviceContext *aContext,
|
2010-06-04 00:56:36 +04:00
|
|
|
nsWidgetInitData *aInitData)
|
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::Create %p [%d %d %d %d]", (void*)this, (void*)aParent, aRect.x, aRect.y, aRect.width, aRect.height);
|
|
|
|
nsWindow *parent = (nsWindow*) aParent;
|
|
|
|
|
2010-06-26 00:29:43 +04:00
|
|
|
if (!AndroidBridge::Bridge()) {
|
|
|
|
aNativeParent = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
if (aNativeParent) {
|
|
|
|
if (parent) {
|
|
|
|
ALOG("Ignoring native parent on Android window [%p], since parent was specified (%p %p)", (void*)this, (void*)aNativeParent, (void*)aParent);
|
|
|
|
} else {
|
|
|
|
parent = (nsWindow*) aNativeParent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mBounds = aRect;
|
|
|
|
|
|
|
|
// for toplevel windows, bounds are fixed to full screen size
|
|
|
|
if (!parent) {
|
|
|
|
mBounds.x = 0;
|
|
|
|
mBounds.y = 0;
|
|
|
|
mBounds.width = gAndroidBounds.width;
|
|
|
|
mBounds.height = gAndroidBounds.height;
|
|
|
|
}
|
|
|
|
|
2011-10-25 19:05:32 +04:00
|
|
|
BaseCreate(nsnull, mBounds, aHandleEventFunction, aContext, aInitData);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(IsTopLevel() || parent, "non top level windowdoesn't have a parent!");
|
|
|
|
|
|
|
|
if (IsTopLevel()) {
|
|
|
|
gTopLevelWindows.AppendElement(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
parent->mChildren.AppendElement(this);
|
|
|
|
mParent = parent;
|
|
|
|
}
|
|
|
|
|
2010-11-18 20:18:31 +03:00
|
|
|
float dpi = GetDPI();
|
|
|
|
mSwipeMaxPinchDelta = SWIPE_MAX_PINCH_DELTA_INCHES * dpi;
|
|
|
|
mSwipeMinDistance = SWIPE_MIN_DISTANCE_INCHES * dpi;
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Destroy(void)
|
|
|
|
{
|
2011-11-23 00:31:49 +04:00
|
|
|
nsBaseWidget::mOnDestroyCalled = true;
|
|
|
|
|
2012-05-26 19:06:25 +04:00
|
|
|
while (mChildren.Length()) {
|
2010-06-04 00:56:36 +04:00
|
|
|
// why do we still have children?
|
2012-05-26 19:06:25 +04:00
|
|
|
ALOG("### Warning: Destroying window %p and reparenting child %p to null!", (void*)this, (void*)mChildren[0]);
|
|
|
|
mChildren[0]->SetParent(nsnull);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsTopLevel())
|
|
|
|
gTopLevelWindows.RemoveElement(this);
|
|
|
|
|
|
|
|
if (mParent)
|
|
|
|
mParent->mChildren.RemoveElement(this);
|
|
|
|
|
2011-11-23 00:29:54 +04:00
|
|
|
nsBaseWidget::OnDestroy();
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ConfigureChildren(const nsTArray<nsIWidget::Configuration>& config)
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < config.Length(); ++i) {
|
|
|
|
nsWindow *childWin = (nsWindow*) config[i].mChild;
|
|
|
|
childWin->Resize(config[i].mBounds.x,
|
|
|
|
config[i].mBounds.y,
|
|
|
|
config[i].mBounds.width,
|
|
|
|
config[i].mBounds.height,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-10 05:39:29 +04:00
|
|
|
void
|
|
|
|
nsWindow::RedrawAll()
|
|
|
|
{
|
2011-12-16 03:45:52 +04:00
|
|
|
nsIntRect entireRect(0, 0, gAndroidBounds.width, gAndroidBounds.height);
|
2011-11-18 07:20:29 +04:00
|
|
|
AndroidGeckoEvent *event = new AndroidGeckoEvent(AndroidGeckoEvent::DRAW, entireRect);
|
2011-11-10 05:39:29 +04:00
|
|
|
nsAppShell::gAppShell->PostEvent(event);
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetParent(nsIWidget *aNewParent)
|
|
|
|
{
|
|
|
|
if ((nsIWidget*)mParent == aNewParent)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// If we had a parent before, remove ourselves from its list of
|
|
|
|
// children. If we didn't have a parent, then remove ourselves
|
|
|
|
// from the list of toplevel windows if we're about to get a
|
|
|
|
// parent.
|
|
|
|
if (mParent)
|
|
|
|
mParent->mChildren.RemoveElement(this);
|
|
|
|
|
|
|
|
mParent = (nsWindow*)aNewParent;
|
|
|
|
|
|
|
|
if (mParent)
|
|
|
|
mParent->mChildren.AppendElement(this);
|
|
|
|
|
|
|
|
// if we are now in the toplevel window's hierarchy, schedule a redraw
|
2012-04-20 20:49:50 +04:00
|
|
|
if (FindTopLevel() == nsWindow::TopWindow())
|
2011-11-10 05:39:29 +04:00
|
|
|
RedrawAll();
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-18 15:28:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ReparentNativeWidget(nsIWidget *aNewParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewParent, "");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
nsIWidget*
|
|
|
|
nsWindow::GetParent()
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
2010-10-07 21:28:27 +04:00
|
|
|
float
|
|
|
|
nsWindow::GetDPI()
|
|
|
|
{
|
|
|
|
if (AndroidBridge::Bridge())
|
|
|
|
return AndroidBridge::Bridge()->GetDPI();
|
|
|
|
return 160.0f;
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::Show(bool aState)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::Show %d", (void*)this, aState);
|
|
|
|
|
|
|
|
if (mWindowType == eWindowType_invisible) {
|
|
|
|
ALOG("trying to show invisible window! ignoring..");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-02-15 04:01:01 +03:00
|
|
|
if (aState == mIsVisible)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mIsVisible = aState;
|
|
|
|
|
|
|
|
if (IsTopLevel()) {
|
|
|
|
// XXX should we bring this to the front when it's shown,
|
|
|
|
// if it's a toplevel widget?
|
|
|
|
|
|
|
|
// XXX we should synthesize a NS_MOUSE_EXIT (for old top
|
|
|
|
// window)/NS_MOUSE_ENTER (for new top window) since we need
|
|
|
|
// to pretend that the top window always has focus. Not sure
|
|
|
|
// if Show() is the right place to do this, though.
|
|
|
|
|
|
|
|
if (aState) {
|
|
|
|
// It just became visible, so send a resize update if necessary
|
|
|
|
// and bring it to the front.
|
2011-10-17 18:59:28 +04:00
|
|
|
Resize(0, 0, gAndroidBounds.width, gAndroidBounds.height, false);
|
2011-02-15 04:01:01 +03:00
|
|
|
BringToFront();
|
2012-04-20 20:49:50 +04:00
|
|
|
} else if (nsWindow::TopWindow() == this) {
|
2011-02-15 04:01:01 +03:00
|
|
|
// find the next visible window to show
|
2011-03-02 20:23:02 +03:00
|
|
|
unsigned int i;
|
2011-02-15 04:01:01 +03:00
|
|
|
for (i = 1; i < gTopLevelWindows.Length(); i++) {
|
|
|
|
nsWindow *win = gTopLevelWindows[i];
|
|
|
|
if (!win->mIsVisible)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
win->BringToFront();
|
|
|
|
break;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
}
|
2012-04-20 20:49:50 +04:00
|
|
|
} else if (FindTopLevel() == nsWindow::TopWindow()) {
|
2011-11-10 05:39:29 +04:00
|
|
|
RedrawAll();
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2011-08-29 22:29:39 +04:00
|
|
|
#ifdef DEBUG_ANDROID_WIDGET
|
2010-06-04 00:56:36 +04:00
|
|
|
DumpWindows();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::SetModal(bool aState)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::SetModal %d ignored", (void*)this, aState);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::IsVisible(bool& aState)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
aState = mIsVisible;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::ConstrainPosition(bool aAllowSlop,
|
2010-06-04 00:56:36 +04:00
|
|
|
PRInt32 *aX,
|
|
|
|
PRInt32 *aY)
|
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::ConstrainPosition %d [%d %d]", (void*)this, aAllowSlop, *aX, *aY);
|
|
|
|
|
|
|
|
// constrain toplevel windows; children we don't care about
|
|
|
|
if (IsTopLevel()) {
|
|
|
|
*aX = 0;
|
|
|
|
*aY = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Move(PRInt32 aX,
|
|
|
|
PRInt32 aY)
|
|
|
|
{
|
|
|
|
if (IsTopLevel())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return Resize(aX,
|
|
|
|
aY,
|
|
|
|
mBounds.width,
|
|
|
|
mBounds.height,
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(PRInt32 aWidth,
|
|
|
|
PRInt32 aHeight,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRepaint)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
return Resize(mBounds.x,
|
|
|
|
mBounds.y,
|
|
|
|
aWidth,
|
|
|
|
aHeight,
|
|
|
|
aRepaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(PRInt32 aX,
|
|
|
|
PRInt32 aY,
|
|
|
|
PRInt32 aWidth,
|
|
|
|
PRInt32 aHeight,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRepaint)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::Resize [%d %d %d %d] (repaint %d)", (void*)this, aX, aY, aWidth, aHeight, aRepaint);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needSizeDispatch = aWidth != mBounds.width || aHeight != mBounds.height;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
mBounds.x = aX;
|
|
|
|
mBounds.y = aY;
|
|
|
|
mBounds.width = aWidth;
|
|
|
|
mBounds.height = aHeight;
|
|
|
|
|
|
|
|
if (needSizeDispatch)
|
|
|
|
OnSizeChanged(gfxIntSize(aWidth, aHeight));
|
|
|
|
|
|
|
|
// Should we skip honoring aRepaint here?
|
2012-04-20 20:49:50 +04:00
|
|
|
if (aRepaint && FindTopLevel() == nsWindow::TopWindow())
|
2011-11-10 05:39:29 +04:00
|
|
|
RedrawAll();
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetZIndex(PRInt32 aZIndex)
|
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::SetZIndex %d ignored", (void*)this, aZIndex);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aActivate)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetSizeMode(PRInt32 aMode)
|
|
|
|
{
|
2010-06-16 21:20:54 +04:00
|
|
|
switch (aMode) {
|
|
|
|
case nsSizeMode_Minimized:
|
|
|
|
AndroidBridge::Bridge()->MoveTaskToBack();
|
|
|
|
break;
|
2010-11-09 05:11:13 +03:00
|
|
|
case nsSizeMode_Fullscreen:
|
2011-10-17 18:59:28 +04:00
|
|
|
MakeFullScreen(true);
|
2010-11-09 05:11:13 +03:00
|
|
|
break;
|
2010-06-16 21:20:54 +04:00
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::Enable(bool aState)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::Enable %d ignored", (void*)this, aState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::IsEnabled(bool *aState)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aState = true;
|
2010-06-04 00:56:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-12-24 07:52:21 +04:00
|
|
|
nsWindow::Invalidate(const nsIntRect &aRect)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2011-11-10 05:39:29 +04:00
|
|
|
AndroidGeckoEvent *event = new AndroidGeckoEvent(AndroidGeckoEvent::DRAW, aRect);
|
|
|
|
nsAppShell::gAppShell->PostEvent(event);
|
2010-06-04 00:56:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow*
|
|
|
|
nsWindow::FindTopLevel()
|
|
|
|
{
|
|
|
|
nsWindow *toplevel = this;
|
|
|
|
while (toplevel) {
|
|
|
|
if (toplevel->IsTopLevel())
|
|
|
|
return toplevel;
|
|
|
|
|
|
|
|
toplevel = toplevel->mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALOG("nsWindow::FindTopLevel(): couldn't find a toplevel or dialog window in this [%p] widget's hierarchy!", (void*)this);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::SetFocus(bool aRaise)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
if (!aRaise)
|
|
|
|
ALOG("nsWindow::SetFocus: can't set focus without raising, ignoring aRaise = false!");
|
|
|
|
|
2010-07-16 22:24:42 +04:00
|
|
|
if (!AndroidBridge::Bridge())
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-02-15 04:01:01 +03:00
|
|
|
nsWindow *top = FindTopLevel();
|
|
|
|
top->mFocus = this;
|
|
|
|
top->BringToFront();
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::BringToFront()
|
|
|
|
{
|
2011-11-08 23:58:37 +04:00
|
|
|
// If the window to be raised is the same as the currently raised one,
|
|
|
|
// do nothing. We need to check the focus manager as well, as the first
|
|
|
|
// window that is created will be first in the window list but won't yet
|
|
|
|
// be focused.
|
|
|
|
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIDOMWindow> existingTopWindow;
|
|
|
|
fm->GetActiveWindow(getter_AddRefs(existingTopWindow));
|
2012-04-20 20:49:50 +04:00
|
|
|
if (existingTopWindow && FindTopLevel() == nsWindow::TopWindow())
|
2010-06-04 00:56:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!IsTopLevel()) {
|
|
|
|
FindTopLevel()->BringToFront();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
nsWindow *oldTop = nsnull;
|
2011-11-23 00:31:49 +04:00
|
|
|
nsWindow *newTop = this;
|
2010-06-04 00:56:36 +04:00
|
|
|
if (!gTopLevelWindows.IsEmpty())
|
|
|
|
oldTop = gTopLevelWindows[0];
|
|
|
|
|
|
|
|
gTopLevelWindows.RemoveElement(this);
|
|
|
|
gTopLevelWindows.InsertElementAt(0, this);
|
|
|
|
|
|
|
|
if (oldTop) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsGUIEvent event(true, NS_DEACTIVATE, oldTop);
|
2010-06-04 00:56:36 +04:00
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2011-11-23 00:31:49 +04:00
|
|
|
if (Destroyed()) {
|
|
|
|
// somehow the deactivate event handler destroyed this window.
|
|
|
|
// try to recover by grabbing the next window in line and activating
|
|
|
|
// that instead
|
|
|
|
if (gTopLevelWindows.IsEmpty())
|
|
|
|
return;
|
|
|
|
newTop = gTopLevelWindows[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGUIEvent event(true, NS_ACTIVATE, newTop);
|
2010-06-04 00:56:36 +04:00
|
|
|
DispatchEvent(&event);
|
|
|
|
|
2011-08-09 20:08:19 +04:00
|
|
|
// force a window resize
|
2011-11-23 00:31:49 +04:00
|
|
|
nsAppShell::gAppShell->ResendLastResizeEvent(newTop);
|
2011-11-10 05:39:29 +04:00
|
|
|
RedrawAll();
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::GetScreenBounds(nsIntRect &aRect)
|
|
|
|
{
|
|
|
|
nsIntPoint p = WidgetToScreenOffset();
|
|
|
|
|
|
|
|
aRect.x = p.x;
|
|
|
|
aRect.y = p.y;
|
|
|
|
aRect.width = mBounds.width;
|
|
|
|
aRect.height = mBounds.height;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint
|
|
|
|
nsWindow::WidgetToScreenOffset()
|
|
|
|
{
|
|
|
|
nsIntPoint p(0, 0);
|
|
|
|
nsWindow *w = this;
|
|
|
|
|
|
|
|
while (w && !w->IsTopLevel()) {
|
|
|
|
p.x += w->mBounds.x;
|
|
|
|
p.y += w->mBounds.y;
|
|
|
|
|
|
|
|
w = w->mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::DispatchEvent(nsGUIEvent *aEvent,
|
|
|
|
nsEventStatus &aStatus)
|
|
|
|
{
|
|
|
|
aStatus = DispatchEvent(aEvent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
nsWindow::DispatchEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
2010-08-21 04:07:26 +04:00
|
|
|
if (mEventCallback) {
|
|
|
|
nsEventStatus status = (*mEventCallback)(aEvent);
|
|
|
|
|
2010-09-24 07:59:26 +04:00
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_COMPOSITION_START:
|
2011-10-17 18:59:28 +04:00
|
|
|
mIMEComposing = true;
|
2010-09-24 07:59:26 +04:00
|
|
|
break;
|
|
|
|
case NS_COMPOSITION_END:
|
2011-10-17 18:59:28 +04:00
|
|
|
mIMEComposing = false;
|
2010-09-24 07:59:26 +04:00
|
|
|
break;
|
|
|
|
case NS_TEXT_TEXT:
|
|
|
|
mIMEComposingText = static_cast<nsTextEvent*>(aEvent)->theText;
|
|
|
|
break;
|
2012-02-15 05:08:47 +04:00
|
|
|
case NS_KEY_PRESS:
|
|
|
|
// Sometimes the text changes after a key press do not generate notifications (see Bug 723810)
|
|
|
|
// Call the corresponding methods explicitly to send those changes back to Java
|
|
|
|
OnIMETextChange(0, 0, 0);
|
|
|
|
OnIMESelectionChange();
|
|
|
|
break;
|
2010-09-24 07:59:26 +04:00
|
|
|
}
|
2010-08-21 04:07:26 +04:00
|
|
|
return status;
|
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2010-11-09 05:11:13 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::MakeFullScreen(bool aFullScreen)
|
2010-11-09 05:11:13 +03:00
|
|
|
{
|
|
|
|
AndroidBridge::Bridge()->SetFullScreen(aFullScreen);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetWindowClass(const nsAString& xulWinType)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-09 02:19:11 +04:00
|
|
|
mozilla::layers::LayerManager*
|
2011-08-12 18:12:03 +04:00
|
|
|
nsWindow::GetLayerManager(PLayersChild*, LayersBackend, LayerManagerPersistence,
|
|
|
|
bool* aAllowRetaining)
|
2010-09-09 02:19:11 +04:00
|
|
|
{
|
2010-10-15 14:34:29 +04:00
|
|
|
if (aAllowRetaining) {
|
|
|
|
*aAllowRetaining = true;
|
|
|
|
}
|
2010-09-09 02:19:11 +04:00
|
|
|
if (mLayerManager) {
|
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow *topWindow = TopWindow();
|
|
|
|
|
|
|
|
if (!topWindow) {
|
|
|
|
printf_stderr(" -- no topwindow\n");
|
2010-09-15 03:40:23 +04:00
|
|
|
mLayerManager = CreateBasicLayerManager();
|
2010-09-09 02:19:11 +04:00
|
|
|
return mLayerManager;
|
|
|
|
}
|
2012-03-29 02:00:32 +04:00
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
2012-05-22 19:34:34 +04:00
|
|
|
bool useCompositor = UseOffMainThreadCompositing();
|
2012-02-01 23:15:52 +04:00
|
|
|
|
|
|
|
if (useCompositor) {
|
|
|
|
CreateCompositor();
|
2012-02-04 06:35:58 +04:00
|
|
|
if (mLayerManager) {
|
2012-03-29 02:00:32 +04:00
|
|
|
SetCompositor(mCompositorParent, mCompositorChild, mCompositorThread);
|
2012-02-02 23:16:59 +04:00
|
|
|
return mLayerManager;
|
2012-02-04 06:35:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here, then off main thread compositing failed to initialize.
|
2012-02-02 23:16:59 +04:00
|
|
|
sFailedToCreateGLContext = true;
|
2012-02-01 23:15:52 +04:00
|
|
|
}
|
2012-03-29 02:00:32 +04:00
|
|
|
#endif
|
2010-09-09 02:19:11 +04:00
|
|
|
mUseAcceleratedRendering = GetShouldAccelerate();
|
|
|
|
|
|
|
|
if (!mUseAcceleratedRendering ||
|
|
|
|
sFailedToCreateGLContext)
|
|
|
|
{
|
|
|
|
printf_stderr(" -- creating basic, not accelerated\n");
|
2010-09-15 03:40:23 +04:00
|
|
|
mLayerManager = CreateBasicLayerManager();
|
2010-09-09 02:19:11 +04:00
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
2012-01-26 23:23:13 +04:00
|
|
|
if (!mLayerManager) {
|
|
|
|
if (!sGLContext) {
|
|
|
|
// the window we give doesn't matter here
|
|
|
|
sGLContext = mozilla::gl::GLContextProvider::CreateForWindow(this);
|
|
|
|
}
|
2010-09-09 02:19:11 +04:00
|
|
|
|
2012-01-26 23:23:13 +04:00
|
|
|
if (sGLContext) {
|
|
|
|
nsRefPtr<mozilla::layers::LayerManagerOGL> layerManager =
|
|
|
|
new mozilla::layers::LayerManagerOGL(this);
|
2010-09-09 02:19:11 +04:00
|
|
|
|
2012-01-26 23:23:13 +04:00
|
|
|
if (layerManager && layerManager->Initialize(sGLContext))
|
|
|
|
mLayerManager = layerManager;
|
|
|
|
sValidSurface = true;
|
|
|
|
}
|
2010-09-09 02:19:11 +04:00
|
|
|
|
2012-01-26 23:23:13 +04:00
|
|
|
if (!sGLContext || !mLayerManager) {
|
|
|
|
sGLContext = nsnull;
|
|
|
|
sFailedToCreateGLContext = true;
|
|
|
|
|
|
|
|
mLayerManager = CreateBasicLayerManager();
|
|
|
|
}
|
2010-09-09 02:19:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
void
|
|
|
|
nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2010-07-16 22:24:42 +04:00
|
|
|
if (!AndroidBridge::Bridge())
|
|
|
|
return;
|
|
|
|
|
2010-10-28 00:10:15 +04:00
|
|
|
nsWindow *win = TopWindow();
|
|
|
|
if (!win)
|
|
|
|
return;
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
switch (ae->Type()) {
|
2011-08-09 20:08:19 +04:00
|
|
|
case AndroidGeckoEvent::FORCED_RESIZE:
|
|
|
|
win->mBounds.width = 0;
|
|
|
|
win->mBounds.height = 0;
|
|
|
|
// also resize the children
|
|
|
|
for (PRUint32 i = 0; i < win->mChildren.Length(); i++) {
|
|
|
|
win->mChildren[i]->mBounds.width = 0;
|
|
|
|
win->mChildren[i]->mBounds.height = 0;
|
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
case AndroidGeckoEvent::SIZE_CHANGED: {
|
2012-01-25 04:31:33 +04:00
|
|
|
nsTArray<nsIntPoint> points = ae->Points();
|
2012-02-24 19:51:41 +04:00
|
|
|
NS_ASSERTION(points.Length() == 2, "Size changed does not have enough coordinates");
|
2012-01-25 04:31:33 +04:00
|
|
|
|
2012-02-14 02:17:12 +04:00
|
|
|
int nw = points[0].x;
|
|
|
|
int nh = points[0].y;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-08-09 20:08:19 +04:00
|
|
|
if (ae->Type() == AndroidGeckoEvent::FORCED_RESIZE || nw != gAndroidBounds.width ||
|
2011-01-14 23:36:19 +03:00
|
|
|
nh != gAndroidBounds.height) {
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-01-14 23:36:19 +03:00
|
|
|
gAndroidBounds.width = nw;
|
|
|
|
gAndroidBounds.height = nh;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-01-14 23:36:19 +03:00
|
|
|
// tell all the windows about the new size
|
|
|
|
for (size_t i = 0; i < gTopLevelWindows.Length(); ++i) {
|
|
|
|
if (gTopLevelWindows[i]->mIsVisible)
|
|
|
|
gTopLevelWindows[i]->Resize(gAndroidBounds.width,
|
|
|
|
gAndroidBounds.height,
|
2012-03-19 18:06:24 +04:00
|
|
|
false);
|
2011-01-14 23:36:19 +03:00
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 04:31:33 +04:00
|
|
|
int newScreenWidth = points[1].x;
|
|
|
|
int newScreenHeight = points[1].y;
|
2011-01-14 23:36:19 +03:00
|
|
|
|
|
|
|
if (newScreenWidth == gAndroidScreenBounds.width &&
|
|
|
|
newScreenHeight == gAndroidScreenBounds.height)
|
|
|
|
break;
|
|
|
|
|
|
|
|
gAndroidScreenBounds.width = newScreenWidth;
|
|
|
|
gAndroidScreenBounds.height = newScreenHeight;
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Tell the content process the new screen size.
|
2011-08-02 23:35:42 +04:00
|
|
|
nsTArray<ContentParent*> cplist;
|
|
|
|
ContentParent::GetAll(cplist);
|
|
|
|
for (PRUint32 i = 0; i < cplist.Length(); ++i)
|
|
|
|
unused << cplist[i]->SendScreenSizeChanged(gAndroidScreenBounds);
|
2011-01-14 23:36:19 +03:00
|
|
|
|
|
|
|
if (gContentCreationNotifier)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// If the content process is not created yet, wait until it's
|
|
|
|
// created and then tell it the screen size.
|
|
|
|
nsCOMPtr<nsIObserverService> obs = do_GetService("@mozilla.org/observer-service;1");
|
|
|
|
if (!obs)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<ContentCreationNotifier> notifier = new ContentCreationNotifier;
|
2011-10-17 18:59:28 +04:00
|
|
|
if (NS_SUCCEEDED(obs->AddObserver(notifier, "ipc:content-created", false))) {
|
|
|
|
if (NS_SUCCEEDED(obs->AddObserver(notifier, "xpcom-shutdown", false)))
|
2011-01-14 23:36:19 +03:00
|
|
|
gContentCreationNotifier = notifier;
|
|
|
|
else
|
|
|
|
obs->RemoveObserver(notifier, "ipc:content-created");
|
2010-11-24 21:22:40 +03:00
|
|
|
}
|
2012-01-25 04:31:33 +04:00
|
|
|
break;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::MOTION_EVENT: {
|
2010-10-28 00:10:15 +04:00
|
|
|
win->UserActivity();
|
2010-06-04 00:56:36 +04:00
|
|
|
if (!gTopLevelWindows.IsEmpty()) {
|
2012-01-25 04:31:33 +04:00
|
|
|
nsIntPoint pt(0,0);
|
|
|
|
nsTArray<nsIntPoint> points = ae->Points();
|
|
|
|
if (points.Length() > 0) {
|
|
|
|
pt = points[0];
|
|
|
|
}
|
2012-02-28 03:57:28 +04:00
|
|
|
pt.x = clamped(pt.x, 0, NS_MAX(gAndroidBounds.width - 1, 0));
|
|
|
|
pt.y = clamped(pt.y, 0, NS_MAX(gAndroidBounds.height - 1, 0));
|
2010-10-28 00:10:15 +04:00
|
|
|
nsWindow *target = win->FindWindowForPoint(pt);
|
2010-06-04 00:56:36 +04:00
|
|
|
#if 0
|
2012-01-25 04:31:33 +04:00
|
|
|
ALOG("MOTION_EVENT %f,%f -> %p (visible: %d children: %d)", pt.x, pt.y, (void*)target,
|
2010-06-04 00:56:36 +04:00
|
|
|
target ? target->mIsVisible : 0,
|
|
|
|
target ? target->mChildren.Length() : 0);
|
|
|
|
|
|
|
|
DumpWindows();
|
|
|
|
#endif
|
2010-07-08 01:34:12 +04:00
|
|
|
if (target) {
|
2012-01-25 04:31:33 +04:00
|
|
|
bool preventDefaultActions = target->OnMultitouchEvent(ae);
|
|
|
|
if (!preventDefaultActions && ae->Count() == 2) {
|
|
|
|
target->OnGestureEvent(ae);
|
|
|
|
}
|
|
|
|
#ifndef MOZ_ONLY_TOUCH_EVENTS
|
|
|
|
if (!preventDefaultActions && ae->Count() < 2)
|
2010-07-08 01:34:12 +04:00
|
|
|
target->OnMotionEvent(ae);
|
2012-01-25 04:31:33 +04:00
|
|
|
#endif
|
2010-07-08 01:34:12 +04:00
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::KEY_EVENT:
|
2010-10-28 00:10:15 +04:00
|
|
|
win->UserActivity();
|
2011-02-15 04:01:01 +03:00
|
|
|
if (win->mFocus)
|
|
|
|
win->mFocus->OnKeyEvent(ae);
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::DRAW:
|
2012-02-27 23:31:29 +04:00
|
|
|
layers::renderTraceEventStart("Global draw start", "414141");
|
2010-10-28 00:10:15 +04:00
|
|
|
win->OnDraw(ae);
|
2012-02-27 23:31:29 +04:00
|
|
|
layers::renderTraceEventEnd("414141");
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::IME_EVENT:
|
2010-10-28 00:10:15 +04:00
|
|
|
win->UserActivity();
|
2011-02-15 04:01:01 +03:00
|
|
|
if (win->mFocus) {
|
|
|
|
win->mFocus->OnIMEEvent(ae);
|
2010-06-23 04:15:29 +04:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Sending unexpected IME event to top window");
|
2010-10-28 00:10:15 +04:00
|
|
|
win->OnIMEEvent(ae);
|
2010-06-23 04:15:29 +04:00
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
|
2011-03-02 20:23:02 +03:00
|
|
|
case AndroidGeckoEvent::SURFACE_CREATED:
|
2011-08-24 00:52:03 +04:00
|
|
|
sSurfaceExists = true;
|
2011-09-21 20:46:00 +04:00
|
|
|
|
|
|
|
if (AndroidBridge::Bridge()->HasNativeWindowAccess()) {
|
|
|
|
AndroidGeckoSurfaceView& sview(AndroidBridge::Bridge()->SurfaceView());
|
2012-05-04 19:08:47 +04:00
|
|
|
JNIEnv *env = AndroidBridge::GetJNIEnv();
|
|
|
|
if (env) {
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2012-05-08 17:35:59 +04:00
|
|
|
jobject surface = sview.GetSurface(&jniFrame);
|
2012-05-04 19:08:47 +04:00
|
|
|
if (surface) {
|
|
|
|
sNativeWindow = AndroidBridge::Bridge()->AcquireNativeWindow(env, surface);
|
|
|
|
if (sNativeWindow) {
|
|
|
|
AndroidBridge::Bridge()->SetNativeWindowFormat(sNativeWindow, 0, 0, AndroidBridge::WINDOW_FORMAT_RGB_565);
|
|
|
|
}
|
2011-09-21 20:46:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 20:23:02 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::SURFACE_DESTROYED:
|
2011-08-24 00:52:03 +04:00
|
|
|
if (sGLContext && sValidSurface) {
|
|
|
|
sGLContext->ReleaseSurface();
|
|
|
|
}
|
2011-09-21 20:46:00 +04:00
|
|
|
if (sNativeWindow) {
|
|
|
|
AndroidBridge::Bridge()->ReleaseNativeWindow(sNativeWindow);
|
|
|
|
sNativeWindow = nsnull;
|
|
|
|
}
|
2011-08-24 00:52:03 +04:00
|
|
|
sSurfaceExists = false;
|
2011-03-02 20:23:02 +03:00
|
|
|
sValidSurface = false;
|
|
|
|
break;
|
2010-12-14 01:37:25 +03:00
|
|
|
|
2012-03-29 02:00:32 +04:00
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
|
|
|
case AndroidGeckoEvent::COMPOSITOR_PAUSE:
|
|
|
|
// The compositor gets paused when the app is about to go into the
|
|
|
|
// background. While the compositor is paused, we need to ensure that
|
|
|
|
// no layer tree updates (from draw events) occur, since the compositor
|
|
|
|
// cannot make a GL context current in order to process updates.
|
|
|
|
if (sCompositorChild) {
|
|
|
|
sCompositorChild->SendPause();
|
|
|
|
}
|
|
|
|
sCompositorPaused = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::COMPOSITOR_RESUME:
|
|
|
|
// When we receive this, the compositor has already been told to
|
|
|
|
// resume. (It turns out that waiting till we reach here to tell
|
|
|
|
// the compositor to resume takes too long, resulting in a black
|
|
|
|
// flash.) This means it's now safe for layer updates to occur.
|
|
|
|
// Since we might have prevented one or more draw events from
|
|
|
|
// occurring while the compositor was paused, we need to schedule
|
|
|
|
// a draw event now.
|
|
|
|
sCompositorPaused = false;
|
|
|
|
win->RedrawAll();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2011-03-02 20:23:02 +03:00
|
|
|
case AndroidGeckoEvent::GECKO_EVENT_SYNC:
|
|
|
|
AndroidBridge::Bridge()->AcknowledgeEventSync();
|
|
|
|
break;
|
2010-12-14 01:37:25 +03:00
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnAndroidEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2010-07-16 22:24:42 +04:00
|
|
|
if (!AndroidBridge::Bridge())
|
|
|
|
return;
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
switch (ae->Type()) {
|
|
|
|
case AndroidGeckoEvent::DRAW:
|
|
|
|
OnDraw(ae);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ALOG("Window got targetted android event type %d, but didn't handle!", ae->Type());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-06-04 00:56:36 +04:00
|
|
|
nsWindow::DrawTo(gfxASurface *targetSurface)
|
2011-11-15 07:12:14 +04:00
|
|
|
{
|
|
|
|
nsIntRect boundsRect(0, 0, mBounds.width, mBounds.height);
|
|
|
|
return DrawTo(targetSurface, boundsRect);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-11-10 05:39:29 +04:00
|
|
|
nsWindow::DrawTo(gfxASurface *targetSurface, const nsIntRect &invalidRect)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2012-02-27 23:31:29 +04:00
|
|
|
mozilla::layers::RenderTraceScope trace("DrawTo", "717171");
|
2010-06-04 00:56:36 +04:00
|
|
|
if (!mIsVisible)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2010-06-26 04:52:37 +04:00
|
|
|
nsEventStatus status;
|
2010-06-04 00:56:36 +04:00
|
|
|
nsIntRect boundsRect(0, 0, mBounds.width, mBounds.height);
|
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
// Figure out if any of our children cover this widget completely
|
|
|
|
PRInt32 coveringChildIndex = -1;
|
|
|
|
for (PRUint32 i = 0; i < mChildren.Length(); ++i) {
|
|
|
|
if (mChildren[i]->mBounds.IsEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mChildren[i]->mBounds.Contains(boundsRect)) {
|
|
|
|
coveringChildIndex = PRInt32(i);
|
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
// If we have no covering child, then we need to render this.
|
|
|
|
if (coveringChildIndex == -1) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsPaintEvent event(true, NS_PAINT, this);
|
2012-05-03 20:34:02 +04:00
|
|
|
event.region = invalidRect;
|
2011-11-18 07:20:29 +04:00
|
|
|
|
2010-12-07 05:05:52 +03:00
|
|
|
switch (GetLayerManager(nsnull)->GetBackendType()) {
|
2010-06-26 04:52:37 +04:00
|
|
|
case LayerManager::LAYERS_BASIC: {
|
2012-02-03 07:28:22 +04:00
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
|
|
|
|
|
|
|
|
{
|
2012-02-27 23:31:29 +04:00
|
|
|
mozilla::layers::RenderTraceScope trace2("Basic DrawTo", "727272");
|
2010-07-16 01:08:04 +04:00
|
|
|
AutoLayerManagerSetup
|
2011-01-21 21:14:03 +03:00
|
|
|
setupLayerManager(this, ctx, BasicLayerManager::BUFFER_NONE);
|
2011-11-18 07:20:29 +04:00
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
status = DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX uhh.. we can't just ignore this because we no longer have
|
|
|
|
// what we needed before, but let's keep drawing the children anyway?
|
2010-06-04 00:56:36 +04:00
|
|
|
#if 0
|
2010-06-26 04:52:37 +04:00
|
|
|
if (status == nsEventStatus_eIgnore)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-06-04 00:56:36 +04:00
|
|
|
#endif
|
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
// XXX if we got an ignore for the parent, do we still want to draw the children?
|
|
|
|
// We don't really have a good way not to...
|
|
|
|
break;
|
2010-06-29 10:42:28 +04:00
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
case LayerManager::LAYERS_OPENGL: {
|
2012-02-03 07:28:22 +04:00
|
|
|
|
2010-12-07 05:05:52 +03:00
|
|
|
static_cast<mozilla::layers::LayerManagerOGL*>(GetLayerManager(nsnull))->
|
2010-06-26 04:52:37 +04:00
|
|
|
SetClippingRegion(nsIntRegion(boundsRect));
|
|
|
|
|
|
|
|
status = DispatchEvent(&event);
|
|
|
|
break;
|
2010-06-29 10:42:28 +04:00
|
|
|
}
|
2010-06-26 04:52:37 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid layer manager");
|
|
|
|
}
|
|
|
|
|
|
|
|
// We had no covering child, so make sure we draw all the children,
|
|
|
|
// starting from index 0.
|
|
|
|
coveringChildIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxPoint offset;
|
|
|
|
|
|
|
|
if (targetSurface)
|
|
|
|
offset = targetSurface->GetDeviceOffset();
|
|
|
|
|
|
|
|
for (PRUint32 i = coveringChildIndex; i < mChildren.Length(); ++i) {
|
|
|
|
if (mChildren[i]->mBounds.IsEmpty() ||
|
2010-06-29 10:42:28 +04:00
|
|
|
!mChildren[i]->mBounds.Intersects(boundsRect)) {
|
2010-06-26 04:52:37 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetSurface)
|
|
|
|
targetSurface->SetDeviceOffset(offset + gfxPoint(mChildren[i]->mBounds.x,
|
|
|
|
mChildren[i]->mBounds.y));
|
|
|
|
|
2011-11-10 05:39:29 +04:00
|
|
|
bool ok = mChildren[i]->DrawTo(targetSurface, invalidRect);
|
2010-06-26 04:52:37 +04:00
|
|
|
|
|
|
|
if (!ok) {
|
2010-06-04 00:56:36 +04:00
|
|
|
ALOG("nsWindow[%p]::DrawTo child %d[%p] returned FALSE!", (void*) this, i, (void*)mChildren[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
if (targetSurface)
|
|
|
|
targetSurface->SetDeviceOffset(offset);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnDraw(AndroidGeckoEvent *ae)
|
|
|
|
{
|
|
|
|
if (!IsTopLevel()) {
|
|
|
|
ALOG("##### redraw for window %p, which is not a toplevel window -- sending to toplevel!", (void*) this);
|
|
|
|
DumpWindows();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mIsVisible) {
|
|
|
|
ALOG("##### redraw for window %p, which is not visible -- ignoring!", (void*) this);
|
|
|
|
DumpWindows();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-03 07:28:22 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
|
2012-05-04 19:08:47 +04:00
|
|
|
JNIEnv *env = AndroidBridge::GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
AutoLocalJNIFrame jniFrame;
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
2012-03-29 02:00:32 +04:00
|
|
|
// We're paused, or we haven't been given a window-size yet, so do nothing
|
|
|
|
if (sCompositorPaused || gAndroidBounds.width <= 0 || gAndroidBounds.height <= 0) {
|
2011-12-16 03:45:52 +04:00
|
|
|
return;
|
2012-02-04 03:48:26 +04:00
|
|
|
}
|
2011-12-16 03:45:52 +04:00
|
|
|
|
2012-02-27 23:31:29 +04:00
|
|
|
layers::renderTraceEventStart("Get surface", "424545");
|
2012-02-25 06:51:14 +04:00
|
|
|
static unsigned char bits2[32 * 32 * 2];
|
2012-02-03 07:28:22 +04:00
|
|
|
nsRefPtr<gfxImageSurface> targetSurface =
|
2012-02-07 03:25:18 +04:00
|
|
|
new gfxImageSurface(bits2, gfxIntSize(32, 32), 32 * 2,
|
2012-02-03 07:28:22 +04:00
|
|
|
gfxASurface::ImageFormatRGB16_565);
|
2012-02-27 23:31:29 +04:00
|
|
|
layers::renderTraceEventEnd("Get surface", "424545");
|
2012-02-03 07:28:22 +04:00
|
|
|
|
2012-02-27 23:31:29 +04:00
|
|
|
layers::renderTraceEventStart("Widget draw to", "434646");
|
2012-02-04 03:48:26 +04:00
|
|
|
if (targetSurface->CairoStatus()) {
|
2012-02-03 08:24:49 +04:00
|
|
|
ALOG("### Failed to create a valid surface from the bitmap");
|
2012-02-17 18:16:14 +04:00
|
|
|
} else {
|
2012-05-03 20:34:02 +04:00
|
|
|
DrawTo(targetSurface, ae->Rect());
|
2011-11-15 07:12:14 +04:00
|
|
|
}
|
2012-02-27 23:31:29 +04:00
|
|
|
layers::renderTraceEventEnd("Widget draw to", "434646");
|
2011-11-18 07:20:29 +04:00
|
|
|
return;
|
2011-11-15 07:12:14 +04:00
|
|
|
#endif
|
2010-11-09 05:11:13 +03:00
|
|
|
|
2011-11-15 13:09:26 +04:00
|
|
|
if (!sSurfaceExists) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-09 05:11:13 +03:00
|
|
|
AndroidGeckoSurfaceView& sview(AndroidBridge::Bridge()->SurfaceView());
|
|
|
|
|
|
|
|
NS_ASSERTION(!sview.isNull(), "SurfaceView is null!");
|
|
|
|
|
2010-11-12 23:02:14 +03:00
|
|
|
AndroidBridge::Bridge()->HideProgressDialogOnce();
|
2010-11-09 05:11:13 +03:00
|
|
|
|
2010-12-07 05:05:52 +03:00
|
|
|
if (GetLayerManager(nsnull)->GetBackendType() == LayerManager::LAYERS_BASIC) {
|
2011-09-21 20:46:00 +04:00
|
|
|
if (sNativeWindow) {
|
|
|
|
unsigned char *bits;
|
|
|
|
int width, height, format, stride;
|
|
|
|
if (!AndroidBridge::Bridge()->LockWindow(sNativeWindow, &bits, &width, &height, &format, &stride)) {
|
|
|
|
ALOG("failed to lock buffer - skipping draw");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bits || format != AndroidBridge::WINDOW_FORMAT_RGB_565 ||
|
|
|
|
width != mBounds.width || height != mBounds.height) {
|
|
|
|
|
|
|
|
ALOG("surface is not expected dimensions or format - skipping draw");
|
|
|
|
AndroidBridge::Bridge()->UnlockWindow(sNativeWindow);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> targetSurface =
|
|
|
|
new gfxImageSurface(bits,
|
|
|
|
gfxIntSize(mBounds.width, mBounds.height),
|
|
|
|
stride * 2,
|
|
|
|
gfxASurface::ImageFormatRGB16_565);
|
|
|
|
if (targetSurface->CairoStatus()) {
|
|
|
|
ALOG("### Failed to create a valid surface from the bitmap");
|
|
|
|
} else {
|
|
|
|
DrawTo(targetSurface);
|
|
|
|
}
|
|
|
|
|
|
|
|
AndroidBridge::Bridge()->UnlockWindow(sNativeWindow);
|
|
|
|
} else if (AndroidBridge::Bridge()->HasNativeBitmapAccess()) {
|
2012-05-08 17:35:59 +04:00
|
|
|
jobject bitmap = sview.GetSoftwareDrawBitmap(&jniFrame);
|
2011-06-16 13:03:00 +04:00
|
|
|
if (!bitmap) {
|
|
|
|
ALOG("no bitmap to draw into - skipping draw");
|
|
|
|
return;
|
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-06-16 13:03:00 +04:00
|
|
|
if (!AndroidBridge::Bridge()->ValidateBitmap(bitmap, mBounds.width, mBounds.height))
|
|
|
|
return;
|
|
|
|
|
|
|
|
void *buf = AndroidBridge::Bridge()->LockBitmap(bitmap);
|
|
|
|
if (buf == nsnull) {
|
|
|
|
ALOG("### Software drawing, but failed to lock bitmap.");
|
|
|
|
return;
|
|
|
|
}
|
2010-06-26 04:52:37 +04:00
|
|
|
|
2011-06-16 13:03:00 +04:00
|
|
|
nsRefPtr<gfxImageSurface> targetSurface =
|
|
|
|
new gfxImageSurface((unsigned char *)buf,
|
|
|
|
gfxIntSize(mBounds.width, mBounds.height),
|
|
|
|
mBounds.width * 2,
|
|
|
|
gfxASurface::ImageFormatRGB16_565);
|
2011-07-22 07:41:39 +04:00
|
|
|
if (targetSurface->CairoStatus()) {
|
|
|
|
ALOG("### Failed to create a valid surface from the bitmap");
|
|
|
|
} else {
|
|
|
|
DrawTo(targetSurface);
|
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-06-16 13:03:00 +04:00
|
|
|
AndroidBridge::Bridge()->UnlockBitmap(bitmap);
|
|
|
|
sview.Draw2D(bitmap, mBounds.width, mBounds.height);
|
|
|
|
} else {
|
2012-05-08 17:35:59 +04:00
|
|
|
jobject bytebuf = sview.GetSoftwareDrawBuffer(&jniFrame);
|
2011-06-16 13:03:00 +04:00
|
|
|
if (!bytebuf) {
|
|
|
|
ALOG("no buffer to draw into - skipping draw");
|
|
|
|
return;
|
|
|
|
}
|
2011-11-10 05:39:29 +04:00
|
|
|
|
2012-01-30 00:39:30 +04:00
|
|
|
void *buf = env->GetDirectBufferAddress(bytebuf);
|
|
|
|
int cap = env->GetDirectBufferCapacity(bytebuf);
|
2011-06-16 13:03:00 +04:00
|
|
|
if (!buf || cap != (mBounds.width * mBounds.height * 2)) {
|
|
|
|
ALOG("### Software drawing, but unexpected buffer size %d expected %d (or no buffer %p)!", cap, mBounds.width * mBounds.height * 2, buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> targetSurface =
|
|
|
|
new gfxImageSurface((unsigned char *)buf,
|
|
|
|
gfxIntSize(mBounds.width, mBounds.height),
|
|
|
|
mBounds.width * 2,
|
|
|
|
gfxASurface::ImageFormatRGB16_565);
|
2011-07-22 07:41:39 +04:00
|
|
|
if (targetSurface->CairoStatus()) {
|
|
|
|
ALOG("### Failed to create a valid surface");
|
|
|
|
} else {
|
|
|
|
DrawTo(targetSurface);
|
|
|
|
}
|
2011-06-16 13:03:00 +04:00
|
|
|
|
|
|
|
sview.Draw2D(bytebuf, mBounds.width * 2);
|
|
|
|
}
|
2010-06-29 10:42:28 +04:00
|
|
|
} else {
|
|
|
|
int drawType = sview.BeginDrawing();
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-08-22 20:57:12 +04:00
|
|
|
if (drawType == AndroidGeckoSurfaceView::DRAW_DISABLED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-29 10:42:28 +04:00
|
|
|
if (drawType == AndroidGeckoSurfaceView::DRAW_ERROR) {
|
|
|
|
ALOG("##### BeginDrawing failed!");
|
|
|
|
return;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
2010-06-29 10:42:28 +04:00
|
|
|
|
2010-12-14 01:37:25 +03:00
|
|
|
if (!sValidSurface) {
|
|
|
|
sGLContext->RenewSurface();
|
|
|
|
sValidSurface = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
NS_ASSERTION(sGLContext, "Drawing with GLES without a GL context?");
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
DrawTo(nsnull);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2010-06-29 10:42:28 +04:00
|
|
|
sview.EndDrawing();
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnSizeChanged(const gfxIntSize& aSize)
|
|
|
|
{
|
|
|
|
int w = aSize.width;
|
|
|
|
int h = aSize.height;
|
|
|
|
|
|
|
|
ALOG("nsWindow: %p OnSizeChanged [%d %d]", (void*)this, w, h);
|
|
|
|
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
nsSizeEvent event(true, NS_SIZE, this);
|
2010-06-04 00:56:36 +04:00
|
|
|
InitEvent(event);
|
|
|
|
|
|
|
|
nsIntRect wsz(0, 0, w, h);
|
|
|
|
event.windowSize = &wsz;
|
|
|
|
event.mWinWidth = w;
|
|
|
|
event.mWinHeight = h;
|
|
|
|
|
|
|
|
mBounds.width = w;
|
|
|
|
mBounds.height = h;
|
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::InitEvent(nsGUIEvent& event, nsIntPoint* aPoint)
|
|
|
|
{
|
|
|
|
if (aPoint) {
|
|
|
|
event.refPoint.x = aPoint->x;
|
|
|
|
event.refPoint.y = aPoint->y;
|
|
|
|
} else {
|
|
|
|
event.refPoint.x = 0;
|
|
|
|
event.refPoint.y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.time = PR_Now() / 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxIntSize
|
2011-01-14 23:36:19 +03:00
|
|
|
nsWindow::GetAndroidScreenBounds()
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2010-11-24 21:22:40 +03:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
return ContentChild::GetSingleton()->GetScreenSize();
|
|
|
|
}
|
2011-01-14 23:36:19 +03:00
|
|
|
return gAndroidScreenBounds;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
nsWindow::GetNativeData(PRUint32 aDataType)
|
|
|
|
{
|
|
|
|
switch (aDataType) {
|
2010-06-26 04:52:37 +04:00
|
|
|
// used by GLContextProviderEGL, NULL is EGL_DEFAULT_DISPLAY
|
|
|
|
case NS_NATIVE_DISPLAY:
|
|
|
|
return NULL;
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
case NS_NATIVE_WIDGET:
|
|
|
|
return (void *) this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnMotionEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
|
|
|
PRUint32 msg;
|
|
|
|
switch (ae->Action() & AndroidMotionEvent::ACTION_MASK) {
|
|
|
|
case AndroidMotionEvent::ACTION_DOWN:
|
|
|
|
msg = NS_MOUSE_BUTTON_DOWN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidMotionEvent::ACTION_MOVE:
|
|
|
|
msg = NS_MOUSE_MOVE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidMotionEvent::ACTION_UP:
|
|
|
|
case AndroidMotionEvent::ACTION_CANCEL:
|
|
|
|
msg = NS_MOUSE_BUTTON_UP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_again:
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMouseEvent event(true,
|
2010-06-04 00:56:36 +04:00
|
|
|
msg, this,
|
|
|
|
nsMouseEvent::eReal, nsMouseEvent::eNormal);
|
|
|
|
// XXX can we synthesize different buttons?
|
|
|
|
event.button = nsMouseEvent::eLeftButton;
|
|
|
|
|
|
|
|
if (msg != NS_MOUSE_MOVE)
|
|
|
|
event.clickCount = 1;
|
|
|
|
|
|
|
|
// XXX add the double-click handling logic here
|
2012-01-25 04:31:33 +04:00
|
|
|
if (ae->Points().Length() > 0)
|
|
|
|
DispatchMotionEvent(event, ae, ae->Points()[0]);
|
2011-11-23 00:31:49 +04:00
|
|
|
if (Destroyed())
|
|
|
|
return;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
if (msg == NS_MOUSE_BUTTON_DOWN) {
|
|
|
|
msg = NS_MOUSE_MOVE;
|
|
|
|
goto send_again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-08 01:34:12 +04:00
|
|
|
static double
|
2010-08-26 09:52:08 +04:00
|
|
|
getDistance(const nsIntPoint &p1, const nsIntPoint &p2)
|
2010-07-08 01:34:12 +04:00
|
|
|
{
|
2010-08-26 09:52:08 +04:00
|
|
|
double deltaX = p2.x - p1.x;
|
|
|
|
double deltaY = p2.y - p1.y;
|
2010-07-08 01:34:12 +04:00
|
|
|
return sqrt(deltaX*deltaX + deltaY*deltaY);
|
|
|
|
}
|
|
|
|
|
2012-01-25 04:31:33 +04:00
|
|
|
bool nsWindow::OnMultitouchEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2012-04-07 11:09:26 +04:00
|
|
|
// This is set to true once we have called SetPreventPanning() exactly
|
|
|
|
// once for a given sequence of touch events. It is reset on the start
|
|
|
|
// of the next sequence.
|
|
|
|
static bool sDefaultPreventedNotified = false;
|
|
|
|
static bool sLastWasDownEvent = false;
|
|
|
|
|
|
|
|
bool preventDefaultActions = false;
|
|
|
|
bool isDownEvent = false;
|
2012-01-25 04:31:33 +04:00
|
|
|
switch (ae->Action() & AndroidMotionEvent::ACTION_MASK) {
|
|
|
|
case AndroidMotionEvent::ACTION_DOWN:
|
|
|
|
case AndroidMotionEvent::ACTION_POINTER_DOWN: {
|
2012-04-04 13:15:10 +04:00
|
|
|
nsTouchEvent event(true, NS_TOUCH_START, this);
|
2012-04-07 11:09:26 +04:00
|
|
|
preventDefaultActions = DispatchMultitouchEvent(event, ae);
|
|
|
|
isDownEvent = true;
|
|
|
|
break;
|
2012-01-25 04:31:33 +04:00
|
|
|
}
|
|
|
|
case AndroidMotionEvent::ACTION_MOVE: {
|
2012-04-04 13:15:10 +04:00
|
|
|
nsTouchEvent event(true, NS_TOUCH_MOVE, this);
|
2012-04-07 11:09:26 +04:00
|
|
|
preventDefaultActions = DispatchMultitouchEvent(event, ae);
|
|
|
|
break;
|
2012-01-25 04:31:33 +04:00
|
|
|
}
|
|
|
|
case AndroidMotionEvent::ACTION_UP:
|
|
|
|
case AndroidMotionEvent::ACTION_POINTER_UP: {
|
2012-04-04 13:15:10 +04:00
|
|
|
nsTouchEvent event(true, NS_TOUCH_END, this);
|
2012-04-07 11:09:26 +04:00
|
|
|
preventDefaultActions = DispatchMultitouchEvent(event, ae);
|
|
|
|
break;
|
2012-01-25 04:31:33 +04:00
|
|
|
}
|
|
|
|
case AndroidMotionEvent::ACTION_OUTSIDE:
|
|
|
|
case AndroidMotionEvent::ACTION_CANCEL: {
|
2012-04-04 13:15:10 +04:00
|
|
|
nsTouchEvent event(true, NS_TOUCH_CANCEL, this);
|
2012-04-07 11:09:26 +04:00
|
|
|
preventDefaultActions = DispatchMultitouchEvent(event, ae);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the last event we got was a down event, then by now we know for sure whether
|
|
|
|
// this block has been default-prevented or not. if we haven't already sent the
|
|
|
|
// notification for this block, do so now.
|
|
|
|
if (sLastWasDownEvent && !sDefaultPreventedNotified) {
|
|
|
|
// if this event is a down event, that means it's the start of a new block, and the
|
|
|
|
// previous block should not be default-prevented
|
|
|
|
bool defaultPrevented = isDownEvent ? false : preventDefaultActions;
|
|
|
|
AndroidBridge::Bridge()->NotifyDefaultPrevented(defaultPrevented);
|
|
|
|
sDefaultPreventedNotified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now, if this event is a down event, then we might already know that it has been
|
|
|
|
// default-prevented. if so, we send the notification right away; otherwise we wait
|
|
|
|
// for the next event.
|
|
|
|
if (isDownEvent) {
|
|
|
|
if (preventDefaultActions) {
|
|
|
|
AndroidBridge::Bridge()->NotifyDefaultPrevented(true);
|
|
|
|
sDefaultPreventedNotified = true;
|
|
|
|
} else {
|
|
|
|
sDefaultPreventedNotified = false;
|
2012-01-25 04:31:33 +04:00
|
|
|
}
|
|
|
|
}
|
2012-04-07 11:09:26 +04:00
|
|
|
sLastWasDownEvent = isDownEvent;
|
|
|
|
|
|
|
|
return preventDefaultActions;
|
2012-01-25 04:31:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsWindow::DispatchMultitouchEvent(nsTouchEvent &event, AndroidGeckoEvent *ae)
|
|
|
|
{
|
|
|
|
nsIntPoint offset = WidgetToScreenOffset();
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
event.modifiers = 0;
|
2012-01-25 04:31:33 +04:00
|
|
|
event.time = ae->Time();
|
|
|
|
|
|
|
|
int action = ae->Action() & AndroidMotionEvent::ACTION_MASK;
|
|
|
|
if (action == AndroidMotionEvent::ACTION_UP ||
|
|
|
|
action == AndroidMotionEvent::ACTION_POINTER_UP) {
|
|
|
|
event.touches.SetCapacity(1);
|
|
|
|
int pointerIndex = ae->PointerIndex();
|
|
|
|
nsCOMPtr<nsIDOMTouch> t(new nsDOMTouch(ae->PointIndicies()[pointerIndex],
|
|
|
|
ae->Points()[pointerIndex] - offset,
|
|
|
|
ae->PointRadii()[pointerIndex],
|
|
|
|
ae->Orientations()[pointerIndex],
|
|
|
|
ae->Pressures()[pointerIndex]));
|
|
|
|
event.touches.AppendElement(t);
|
|
|
|
} else {
|
|
|
|
int count = ae->Count();
|
|
|
|
event.touches.SetCapacity(count);
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
nsCOMPtr<nsIDOMTouch> t(new nsDOMTouch(ae->PointIndicies()[i],
|
|
|
|
ae->Points()[i] - offset,
|
|
|
|
ae->PointRadii()[i],
|
|
|
|
ae->Orientations()[i],
|
|
|
|
ae->Pressures()[i]));
|
|
|
|
event.touches.AppendElement(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
2012-04-07 11:09:26 +04:00
|
|
|
return (status == nsEventStatus_eConsumeNoDefault);
|
2012-01-25 04:31:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnGestureEvent(AndroidGeckoEvent *ae)
|
2010-07-08 01:34:12 +04:00
|
|
|
{
|
2010-08-26 09:52:08 +04:00
|
|
|
PRUint32 msg = 0;
|
|
|
|
|
|
|
|
nsIntPoint midPoint;
|
2012-01-25 04:31:33 +04:00
|
|
|
midPoint.x = ((ae->Points()[0].x + ae->Points()[1].x) / 2);
|
|
|
|
midPoint.y = ((ae->Points()[0].y + ae->Points()[1].y) / 2);
|
2010-08-26 09:52:08 +04:00
|
|
|
nsIntPoint refPoint = midPoint - WidgetToScreenOffset();
|
|
|
|
|
2012-01-25 04:31:33 +04:00
|
|
|
double pinchDist = getDistance(ae->Points()[0], ae->Points()[1]);
|
2010-08-26 09:52:08 +04:00
|
|
|
double pinchDelta = 0;
|
2010-07-08 01:34:12 +04:00
|
|
|
|
|
|
|
switch (ae->Action() & AndroidMotionEvent::ACTION_MASK) {
|
|
|
|
case AndroidMotionEvent::ACTION_POINTER_DOWN:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY_START;
|
2010-08-26 09:52:08 +04:00
|
|
|
mStartPoint = new nsIntPoint(midPoint);
|
|
|
|
mStartDist = mLastDist = pinchDist;
|
|
|
|
mGestureFinished = false;
|
|
|
|
break;
|
|
|
|
case AndroidMotionEvent::ACTION_MOVE:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY_UPDATE;
|
|
|
|
pinchDelta = pinchDist - mLastDist;
|
|
|
|
mLastDist = pinchDist;
|
2010-07-08 01:34:12 +04:00
|
|
|
break;
|
|
|
|
case AndroidMotionEvent::ACTION_POINTER_UP:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY;
|
2010-08-26 09:52:08 +04:00
|
|
|
pinchDelta = pinchDist - mStartDist;
|
|
|
|
mStartPoint = nsnull;
|
2010-07-08 01:34:12 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-26 09:52:08 +04:00
|
|
|
if (!mGestureFinished) {
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2010-08-26 09:52:08 +04:00
|
|
|
DispatchGestureEvent(msg, 0, pinchDelta, refPoint, ae->Time());
|
2011-11-23 00:31:49 +04:00
|
|
|
if (Destroyed())
|
|
|
|
return;
|
2010-08-26 09:52:08 +04:00
|
|
|
|
|
|
|
// If the cumulative pinch delta goes past the threshold, treat this
|
|
|
|
// as a pinch only, and not a swipe.
|
2010-11-18 20:18:31 +03:00
|
|
|
if (fabs(pinchDist - mStartDist) > mSwipeMaxPinchDelta)
|
2010-08-26 09:52:08 +04:00
|
|
|
mStartPoint = nsnull;
|
|
|
|
|
|
|
|
// If we have traveled more than SWIPE_MIN_DISTANCE from the start
|
|
|
|
// point, stop the pinch gesture and fire a swipe event.
|
|
|
|
if (mStartPoint) {
|
|
|
|
double swipeDistance = getDistance(midPoint, *mStartPoint);
|
2010-11-18 20:18:31 +03:00
|
|
|
if (swipeDistance > mSwipeMinDistance) {
|
2010-08-26 09:52:08 +04:00
|
|
|
PRUint32 direction = 0;
|
|
|
|
nsIntPoint motion = midPoint - *mStartPoint;
|
|
|
|
|
|
|
|
if (motion.x < -swipeDistance/2)
|
|
|
|
direction |= nsIDOMSimpleGestureEvent::DIRECTION_LEFT;
|
|
|
|
if (motion.x > swipeDistance/2)
|
|
|
|
direction |= nsIDOMSimpleGestureEvent::DIRECTION_RIGHT;
|
|
|
|
if (motion.y < -swipeDistance/2)
|
|
|
|
direction |= nsIDOMSimpleGestureEvent::DIRECTION_UP;
|
|
|
|
if (motion.y > swipeDistance/2)
|
|
|
|
direction |= nsIDOMSimpleGestureEvent::DIRECTION_DOWN;
|
|
|
|
|
|
|
|
// Finish the pinch gesture, then fire the swipe event:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY;
|
|
|
|
DispatchGestureEvent(msg, 0, pinchDist - mStartDist, refPoint, ae->Time());
|
2011-11-23 00:31:49 +04:00
|
|
|
if (Destroyed())
|
|
|
|
return;
|
2010-08-26 09:52:08 +04:00
|
|
|
msg = NS_SIMPLE_GESTURE_SWIPE;
|
|
|
|
DispatchGestureEvent(msg, direction, 0, refPoint, ae->Time());
|
|
|
|
|
|
|
|
// Don't generate any more gesture events for this touch.
|
|
|
|
mGestureFinished = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchGestureEvent(PRUint32 msg, PRUint32 direction, double delta,
|
|
|
|
const nsIntPoint &refPoint, PRUint64 time)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsSimpleGestureEvent event(true, msg, this, direction, delta);
|
2010-07-08 01:34:12 +04:00
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
event.modifiers = 0;
|
2010-08-26 09:52:08 +04:00
|
|
|
event.time = time;
|
|
|
|
event.refPoint = refPoint;
|
2010-07-08 01:34:12 +04:00
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2012-01-25 04:31:33 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchMotionEvent(nsInputEvent &event, AndroidGeckoEvent *ae,
|
|
|
|
const nsIntPoint &refPoint)
|
|
|
|
{
|
|
|
|
nsIntPoint offset = WidgetToScreenOffset();
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
event.modifiers = 0;
|
2012-01-25 04:31:33 +04:00
|
|
|
event.time = ae->Time();
|
|
|
|
|
|
|
|
// XXX possibly bound the range of event.refPoint here.
|
|
|
|
// some code may get confused.
|
|
|
|
event.refPoint = refPoint - offset;
|
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2012-04-20 00:34:03 +04:00
|
|
|
static unsigned int ConvertAndroidKeyCodeToDOMKeyCode(int androidKeyCode)
|
|
|
|
{
|
|
|
|
// Special-case alphanumeric keycodes because they are most common.
|
|
|
|
if (androidKeyCode >= AndroidKeyEvent::KEYCODE_A &&
|
|
|
|
androidKeyCode <= AndroidKeyEvent::KEYCODE_Z) {
|
|
|
|
return androidKeyCode - AndroidKeyEvent::KEYCODE_A + NS_VK_A;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (androidKeyCode >= AndroidKeyEvent::KEYCODE_0 &&
|
|
|
|
androidKeyCode <= AndroidKeyEvent::KEYCODE_9) {
|
|
|
|
return androidKeyCode - AndroidKeyEvent::KEYCODE_0 + NS_VK_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (androidKeyCode) {
|
2012-04-25 07:47:46 +04:00
|
|
|
// KEYCODE_UNKNOWN (0) ... KEYCODE_HOME (3)
|
|
|
|
case AndroidKeyEvent::KEYCODE_BACK: return NS_VK_ESCAPE;
|
|
|
|
// KEYCODE_CALL (5) ... KEYCODE_POUND (18)
|
2012-04-20 00:34:03 +04:00
|
|
|
case AndroidKeyEvent::KEYCODE_DPAD_UP: return NS_VK_UP;
|
|
|
|
case AndroidKeyEvent::KEYCODE_DPAD_DOWN: return NS_VK_DOWN;
|
|
|
|
case AndroidKeyEvent::KEYCODE_DPAD_LEFT: return NS_VK_LEFT;
|
|
|
|
case AndroidKeyEvent::KEYCODE_DPAD_RIGHT: return NS_VK_RIGHT;
|
2012-05-19 02:51:53 +04:00
|
|
|
case AndroidKeyEvent::KEYCODE_DPAD_CENTER: return NS_VK_RETURN;
|
2012-04-20 00:34:03 +04:00
|
|
|
// KEYCODE_VOLUME_UP (24) ... KEYCODE_Z (54)
|
|
|
|
case AndroidKeyEvent::KEYCODE_COMMA: return NS_VK_COMMA;
|
|
|
|
case AndroidKeyEvent::KEYCODE_PERIOD: return NS_VK_PERIOD;
|
|
|
|
case AndroidKeyEvent::KEYCODE_ALT_LEFT: return NS_VK_ALT;
|
|
|
|
case AndroidKeyEvent::KEYCODE_ALT_RIGHT: return NS_VK_ALT;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SHIFT_LEFT: return NS_VK_SHIFT;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SHIFT_RIGHT: return NS_VK_SHIFT;
|
|
|
|
case AndroidKeyEvent::KEYCODE_TAB: return NS_VK_TAB;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SPACE: return NS_VK_SPACE;
|
|
|
|
// KEYCODE_SYM (63) ... KEYCODE_ENVELOPE (65)
|
|
|
|
case AndroidKeyEvent::KEYCODE_ENTER: return NS_VK_RETURN;
|
|
|
|
case AndroidKeyEvent::KEYCODE_DEL: return NS_VK_BACK; // Backspace
|
|
|
|
case AndroidKeyEvent::KEYCODE_GRAVE: return NS_VK_BACK_QUOTE;
|
|
|
|
// KEYCODE_MINUS (69)
|
|
|
|
case AndroidKeyEvent::KEYCODE_EQUALS: return NS_VK_EQUALS;
|
|
|
|
case AndroidKeyEvent::KEYCODE_LEFT_BRACKET: return NS_VK_OPEN_BRACKET;
|
|
|
|
case AndroidKeyEvent::KEYCODE_RIGHT_BRACKET: return NS_VK_CLOSE_BRACKET;
|
|
|
|
case AndroidKeyEvent::KEYCODE_BACKSLASH: return NS_VK_BACK_SLASH;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SEMICOLON: return NS_VK_SEMICOLON;
|
|
|
|
// KEYCODE_APOSTROPHE (75)
|
|
|
|
case AndroidKeyEvent::KEYCODE_SLASH: return NS_VK_SLASH;
|
|
|
|
// KEYCODE_AT (77) ... KEYCODE_MUTE (91)
|
|
|
|
case AndroidKeyEvent::KEYCODE_PAGE_UP: return NS_VK_PAGE_UP;
|
|
|
|
case AndroidKeyEvent::KEYCODE_PAGE_DOWN: return NS_VK_PAGE_DOWN;
|
|
|
|
// KEYCODE_PICTSYMBOLS (94) ... KEYCODE_BUTTON_MODE (110)
|
|
|
|
case AndroidKeyEvent::KEYCODE_ESCAPE: return NS_VK_ESCAPE;
|
|
|
|
case AndroidKeyEvent::KEYCODE_FORWARD_DEL: return NS_VK_DELETE;
|
|
|
|
case AndroidKeyEvent::KEYCODE_CTRL_LEFT: return NS_VK_CONTROL;
|
|
|
|
case AndroidKeyEvent::KEYCODE_CTRL_RIGHT: return NS_VK_CONTROL;
|
|
|
|
case AndroidKeyEvent::KEYCODE_CAPS_LOCK: return NS_VK_CAPS_LOCK;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SCROLL_LOCK: return NS_VK_SCROLL_LOCK;
|
|
|
|
// KEYCODE_META_LEFT (117) ... KEYCODE_FUNCTION (119)
|
|
|
|
case AndroidKeyEvent::KEYCODE_SYSRQ: return NS_VK_PRINTSCREEN;
|
|
|
|
case AndroidKeyEvent::KEYCODE_BREAK: return NS_VK_PAUSE;
|
|
|
|
case AndroidKeyEvent::KEYCODE_MOVE_HOME: return NS_VK_HOME;
|
|
|
|
case AndroidKeyEvent::KEYCODE_MOVE_END: return NS_VK_END;
|
|
|
|
case AndroidKeyEvent::KEYCODE_INSERT: return NS_VK_INSERT;
|
|
|
|
// KEYCODE_FORWARD (125) ... KEYCODE_MEDIA_RECORD (130)
|
|
|
|
case AndroidKeyEvent::KEYCODE_F1: return NS_VK_F1;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F2: return NS_VK_F2;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F3: return NS_VK_F3;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F4: return NS_VK_F4;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F5: return NS_VK_F5;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F6: return NS_VK_F6;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F7: return NS_VK_F7;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F8: return NS_VK_F8;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F9: return NS_VK_F9;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F10: return NS_VK_F10;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F11: return NS_VK_F11;
|
|
|
|
case AndroidKeyEvent::KEYCODE_F12: return NS_VK_F12;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUM_LOCK: return NS_VK_NUM_LOCK;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_0: return NS_VK_NUMPAD0;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_1: return NS_VK_NUMPAD1;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_2: return NS_VK_NUMPAD2;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_3: return NS_VK_NUMPAD3;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_4: return NS_VK_NUMPAD4;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_5: return NS_VK_NUMPAD5;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_6: return NS_VK_NUMPAD6;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_7: return NS_VK_NUMPAD7;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_8: return NS_VK_NUMPAD8;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_9: return NS_VK_NUMPAD9;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_DIVIDE: return NS_VK_DIVIDE;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_MULTIPLY: return NS_VK_MULTIPLY;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_SUBTRACT: return NS_VK_SUBTRACT;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_ADD: return NS_VK_ADD;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_DOT: return NS_VK_DECIMAL;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_COMMA: return NS_VK_SEPARATOR;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_ENTER: return NS_VK_RETURN;
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUMPAD_EQUALS: return NS_VK_EQUALS;
|
|
|
|
// KEYCODE_NUMPAD_LEFT_PAREN (162) ... KEYCODE_CALCULATOR (210)
|
|
|
|
|
|
|
|
default:
|
|
|
|
ALOG("ConvertAndroidKeyCodeToDOMKeyCode: "
|
|
|
|
"No DOM keycode for Android keycode %d", androidKeyCode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:49:31 +04:00
|
|
|
static void InitPluginEvent(ANPEvent* pluginEvent, ANPKeyActions keyAction,
|
|
|
|
AndroidGeckoEvent& key)
|
|
|
|
{
|
|
|
|
int androidKeyCode = key.KeyCode();
|
|
|
|
PRUint32 domKeyCode = ConvertAndroidKeyCodeToDOMKeyCode(androidKeyCode);
|
|
|
|
|
|
|
|
int modifiers = 0;
|
|
|
|
if (key.IsAltPressed())
|
|
|
|
modifiers |= kAlt_ANPKeyModifier;
|
|
|
|
if (key.IsShiftPressed())
|
|
|
|
modifiers |= kShift_ANPKeyModifier;
|
|
|
|
|
|
|
|
pluginEvent->inSize = sizeof(ANPEvent);
|
|
|
|
pluginEvent->eventType = kKey_ANPEventType;
|
|
|
|
pluginEvent->data.key.action = keyAction;
|
|
|
|
pluginEvent->data.key.nativeCode = androidKeyCode;
|
|
|
|
pluginEvent->data.key.virtualCode = domKeyCode;
|
|
|
|
pluginEvent->data.key.unichar = key.UnicodeChar();
|
|
|
|
pluginEvent->data.key.modifiers = modifiers;
|
|
|
|
pluginEvent->data.key.repeatCount = key.RepeatCount();
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
void
|
2012-04-19 21:49:31 +04:00
|
|
|
nsWindow::InitKeyEvent(nsKeyEvent& event, AndroidGeckoEvent& key,
|
|
|
|
ANPEvent* pluginEvent)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2012-04-19 21:49:31 +04:00
|
|
|
int androidKeyCode = key.KeyCode();
|
|
|
|
PRUint32 domKeyCode = ConvertAndroidKeyCodeToDOMKeyCode(androidKeyCode);
|
|
|
|
|
|
|
|
if (event.message == NS_KEY_PRESS) {
|
|
|
|
// Android gives us \n, so filter out some control characters.
|
|
|
|
event.isChar = (key.UnicodeChar() >= ' ');
|
|
|
|
event.charCode = event.isChar ? key.UnicodeChar() : 0;
|
|
|
|
event.keyCode = (event.charCode > 0) ? 0 : domKeyCode;
|
|
|
|
event.pluginEvent = NULL;
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (event.message != NS_KEY_DOWN && event.message != NS_KEY_UP) {
|
|
|
|
ALOG("InitKeyEvent: unexpected event.message %d", event.message);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
// Flash will want a pluginEvent for keydown and keyup events.
|
|
|
|
ANPKeyActions action = event.message == NS_KEY_DOWN
|
|
|
|
? kDown_ANPKeyAction
|
|
|
|
: kUp_ANPKeyAction;
|
|
|
|
InitPluginEvent(pluginEvent, action, key);
|
|
|
|
|
|
|
|
event.isChar = false;
|
|
|
|
event.charCode = 0;
|
|
|
|
event.keyCode = domKeyCode;
|
|
|
|
event.pluginEvent = pluginEvent;
|
2012-04-19 23:50:46 +04:00
|
|
|
}
|
2012-04-19 21:49:31 +04:00
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
event.InitBasicModifiers(gMenu,
|
|
|
|
key.IsAltPressed(),
|
|
|
|
key.IsShiftPressed(),
|
|
|
|
false);
|
2012-05-03 12:35:02 +04:00
|
|
|
event.location = nsIDOMKeyEvent::DOM_KEY_LOCATION_MOBILE;
|
2010-06-04 00:56:36 +04:00
|
|
|
event.time = key.Time();
|
2010-10-16 16:15:54 +04:00
|
|
|
|
|
|
|
if (gMenu)
|
2011-10-17 18:59:28 +04:00
|
|
|
gMenuConsumed = true;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::HandleSpecialKey(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2010-06-04 00:56:36 +04:00
|
|
|
nsCOMPtr<nsIAtom> command;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isDown = ae->Action() == AndroidKeyEvent::ACTION_DOWN;
|
|
|
|
bool isLongPress = !!(ae->Flags() & AndroidKeyEvent::FLAG_LONG_PRESS);
|
|
|
|
bool doCommand = false;
|
2010-06-04 00:56:36 +04:00
|
|
|
PRUint32 keyCode = ae->KeyCode();
|
|
|
|
|
|
|
|
if (isDown) {
|
|
|
|
switch (keyCode) {
|
2010-11-13 02:58:29 +03:00
|
|
|
case AndroidKeyEvent::KEYCODE_BACK:
|
|
|
|
if (isLongPress) {
|
2011-10-14 22:11:22 +04:00
|
|
|
command = nsGkAtoms::Clear;
|
2011-10-17 18:59:28 +04:00
|
|
|
doCommand = true;
|
2010-11-13 02:58:29 +03:00
|
|
|
}
|
|
|
|
break;
|
2010-06-04 00:56:36 +04:00
|
|
|
case AndroidKeyEvent::KEYCODE_VOLUME_UP:
|
2011-10-14 22:11:22 +04:00
|
|
|
command = nsGkAtoms::VolumeUp;
|
2011-10-17 18:59:28 +04:00
|
|
|
doCommand = true;
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_VOLUME_DOWN:
|
2011-10-14 22:11:22 +04:00
|
|
|
command = nsGkAtoms::VolumeDown;
|
2011-10-17 18:59:28 +04:00
|
|
|
doCommand = true;
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
2010-10-16 16:15:54 +04:00
|
|
|
case AndroidKeyEvent::KEYCODE_MENU:
|
2011-10-17 18:59:28 +04:00
|
|
|
gMenu = true;
|
2010-11-13 02:58:29 +03:00
|
|
|
gMenuConsumed = isLongPress;
|
2010-10-16 16:15:54 +04:00
|
|
|
break;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (keyCode) {
|
|
|
|
case AndroidKeyEvent::KEYCODE_BACK: {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsKeyEvent pressEvent(true, NS_KEY_PRESS, this);
|
2012-04-19 21:49:31 +04:00
|
|
|
ANPEvent pluginEvent;
|
|
|
|
InitKeyEvent(pressEvent, *ae, &pluginEvent);
|
2010-06-04 00:56:36 +04:00
|
|
|
DispatchEvent(&pressEvent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case AndroidKeyEvent::KEYCODE_MENU:
|
2011-10-17 18:59:28 +04:00
|
|
|
gMenu = false;
|
2010-10-16 16:15:54 +04:00
|
|
|
if (!gMenuConsumed) {
|
2011-10-14 22:11:22 +04:00
|
|
|
command = nsGkAtoms::Menu;
|
2011-10-17 18:59:28 +04:00
|
|
|
doCommand = true;
|
2010-10-16 16:15:54 +04:00
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SEARCH:
|
2011-10-14 22:11:22 +04:00
|
|
|
command = nsGkAtoms::Search;
|
2011-10-17 18:59:28 +04:00
|
|
|
doCommand = true;
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ALOG("Unknown special key code!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (doCommand) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsCommandEvent event(true, nsGkAtoms::onAppCommand, command, this);
|
2010-06-04 00:56:36 +04:00
|
|
|
InitEvent(event);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnKeyEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2010-06-04 00:56:36 +04:00
|
|
|
PRUint32 msg;
|
|
|
|
switch (ae->Action()) {
|
|
|
|
case AndroidKeyEvent::ACTION_DOWN:
|
|
|
|
msg = NS_KEY_DOWN;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::ACTION_UP:
|
|
|
|
msg = NS_KEY_UP;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::ACTION_MULTIPLE:
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsTextEvent event(true, NS_TEXT_TEXT, this);
|
2010-06-04 00:56:36 +04:00
|
|
|
event.theText.Assign(ae->Characters());
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
ALOG("Unknown key action event!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-22 01:36:28 +03:00
|
|
|
bool firePress = ae->Action() == AndroidKeyEvent::ACTION_DOWN;
|
2010-06-04 00:56:36 +04:00
|
|
|
switch (ae->KeyCode()) {
|
|
|
|
case AndroidKeyEvent::KEYCODE_SHIFT_LEFT:
|
|
|
|
case AndroidKeyEvent::KEYCODE_SHIFT_RIGHT:
|
|
|
|
case AndroidKeyEvent::KEYCODE_ALT_LEFT:
|
|
|
|
case AndroidKeyEvent::KEYCODE_ALT_RIGHT:
|
2010-12-22 01:36:28 +03:00
|
|
|
firePress = false;
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_BACK:
|
|
|
|
case AndroidKeyEvent::KEYCODE_MENU:
|
|
|
|
case AndroidKeyEvent::KEYCODE_SEARCH:
|
|
|
|
case AndroidKeyEvent::KEYCODE_VOLUME_UP:
|
|
|
|
case AndroidKeyEvent::KEYCODE_VOLUME_DOWN:
|
|
|
|
HandleSpecialKey(ae);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-22 01:36:28 +03:00
|
|
|
nsEventStatus status;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsKeyEvent event(true, msg, this);
|
2012-04-19 21:49:31 +04:00
|
|
|
ANPEvent pluginEvent;
|
|
|
|
InitKeyEvent(event, *ae, &pluginEvent);
|
2010-12-22 01:36:28 +03:00
|
|
|
DispatchEvent(&event, status);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-11-23 00:31:49 +04:00
|
|
|
if (Destroyed())
|
|
|
|
return;
|
2010-12-22 01:36:28 +03:00
|
|
|
if (!firePress)
|
|
|
|
return;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsKeyEvent pressEvent(true, NS_KEY_PRESS, this);
|
2012-04-19 21:49:31 +04:00
|
|
|
InitKeyEvent(pressEvent, *ae, &pluginEvent);
|
2010-12-22 01:36:28 +03:00
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
pressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
|
|
|
}
|
2011-08-29 22:29:39 +04:00
|
|
|
#ifdef DEBUG_ANDROID_WIDGET
|
2012-04-25 07:00:02 +04:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, "Gecko", "Dispatching key pressEvent with keyCode %d charCode %d shift %d alt %d sym/ctrl %d metamask %d", pressEvent.keyCode, pressEvent.charCode, pressEvent.IsShift(), pressEvent.IsAlt(), pressEvent.IsControl(), ae->MetaState());
|
2010-06-04 00:56:36 +04:00
|
|
|
#endif
|
2010-12-22 01:36:28 +03:00
|
|
|
DispatchEvent(&pressEvent);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2011-08-29 22:29:39 +04:00
|
|
|
#ifdef DEBUG_ANDROID_IME
|
2010-08-04 23:47:26 +04:00
|
|
|
#define ALOGIME(args...) ALOG(args)
|
|
|
|
#else
|
|
|
|
#define ALOGIME(args...)
|
|
|
|
#endif
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2010-08-04 23:47:26 +04:00
|
|
|
void
|
|
|
|
nsWindow::OnIMEAddRange(AndroidGeckoEvent *ae)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2010-08-04 23:47:26 +04:00
|
|
|
//ALOGIME("IME: IME_ADD_RANGE");
|
|
|
|
nsTextRange range;
|
|
|
|
range.mStartOffset = ae->Offset();
|
|
|
|
range.mEndOffset = range.mStartOffset + ae->Count();
|
|
|
|
range.mRangeType = ae->RangeType();
|
|
|
|
range.mRangeStyle.mDefinedStyles = ae->RangeStyles();
|
|
|
|
range.mRangeStyle.mLineStyle = nsTextRangeStyle::LINESTYLE_SOLID;
|
|
|
|
range.mRangeStyle.mForegroundColor = NS_RGBA(
|
|
|
|
((ae->RangeForeColor() >> 16) & 0xff),
|
|
|
|
((ae->RangeForeColor() >> 8) & 0xff),
|
|
|
|
(ae->RangeForeColor() & 0xff),
|
|
|
|
((ae->RangeForeColor() >> 24) & 0xff));
|
|
|
|
range.mRangeStyle.mBackgroundColor = NS_RGBA(
|
|
|
|
((ae->RangeBackColor() >> 16) & 0xff),
|
|
|
|
((ae->RangeBackColor() >> 8) & 0xff),
|
|
|
|
(ae->RangeBackColor() & 0xff),
|
|
|
|
((ae->RangeBackColor() >> 24) & 0xff));
|
|
|
|
mIMERanges.AppendElement(range);
|
|
|
|
return;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnIMEEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2010-06-04 00:56:36 +04:00
|
|
|
switch (ae->Action()) {
|
2010-08-04 23:47:26 +04:00
|
|
|
case AndroidGeckoEvent::IME_COMPOSITION_END:
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2010-08-04 23:47:26 +04:00
|
|
|
ALOGIME("IME: IME_COMPOSITION_END");
|
2011-10-17 18:59:28 +04:00
|
|
|
nsCompositionEvent event(true, NS_COMPOSITION_END, this);
|
2010-08-04 23:47:26 +04:00
|
|
|
InitEvent(event, nsnull);
|
2011-09-22 13:17:40 +04:00
|
|
|
event.data = mIMELastDispatchedComposingText;
|
|
|
|
mIMELastDispatchedComposingText.Truncate();
|
2010-06-04 00:56:36 +04:00
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
return;
|
2010-08-04 23:47:26 +04:00
|
|
|
case AndroidGeckoEvent::IME_COMPOSITION_BEGIN:
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2010-08-04 23:47:26 +04:00
|
|
|
ALOGIME("IME: IME_COMPOSITION_BEGIN");
|
2011-09-22 13:17:40 +04:00
|
|
|
mIMELastDispatchedComposingText.Truncate();
|
2011-10-17 18:59:28 +04:00
|
|
|
nsCompositionEvent event(true, NS_COMPOSITION_START, this);
|
2010-08-04 23:47:26 +04:00
|
|
|
InitEvent(event, nsnull);
|
2010-06-04 00:56:36 +04:00
|
|
|
DispatchEvent(&event);
|
2010-08-04 23:47:26 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_ADD_RANGE:
|
|
|
|
{
|
|
|
|
OnIMEAddRange(ae);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_SET_TEXT:
|
|
|
|
{
|
2010-08-04 23:47:26 +04:00
|
|
|
OnIMEAddRange(ae);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsTextEvent event(true, NS_TEXT_TEXT, this);
|
2010-08-04 23:47:26 +04:00
|
|
|
InitEvent(event, nsnull);
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
event.theText.Assign(ae->Characters());
|
2010-08-04 23:47:26 +04:00
|
|
|
event.rangeArray = mIMERanges.Elements();
|
|
|
|
event.rangeCount = mIMERanges.Length();
|
|
|
|
|
2011-09-22 13:17:40 +04:00
|
|
|
if (mIMEComposing &&
|
|
|
|
event.theText != mIMELastDispatchedComposingText) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsCompositionEvent compositionUpdate(true,
|
2011-09-22 13:17:40 +04:00
|
|
|
NS_COMPOSITION_UPDATE,
|
|
|
|
this);
|
|
|
|
InitEvent(compositionUpdate, nsnull);
|
|
|
|
compositionUpdate.data = event.theText;
|
|
|
|
mIMELastDispatchedComposingText = event.theText;
|
|
|
|
DispatchEvent(&compositionUpdate);
|
2011-11-23 00:31:49 +04:00
|
|
|
if (Destroyed())
|
|
|
|
return;
|
2011-09-22 13:17:40 +04:00
|
|
|
}
|
|
|
|
|
2010-08-04 23:47:26 +04:00
|
|
|
ALOGIME("IME: IME_SET_TEXT: l=%u, r=%u",
|
|
|
|
event.theText.Length(), mIMERanges.Length());
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
DispatchEvent(&event);
|
2010-08-04 23:47:26 +04:00
|
|
|
mIMERanges.Clear();
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_GET_TEXT:
|
|
|
|
{
|
2010-08-04 23:47:26 +04:00
|
|
|
ALOGIME("IME: IME_GET_TEXT: o=%u, l=%u", ae->Offset(), ae->Count());
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsQueryContentEvent event(true, NS_QUERY_TEXT_CONTENT, this);
|
2010-08-04 23:47:26 +04:00
|
|
|
InitEvent(event, nsnull);
|
|
|
|
|
|
|
|
event.InitForQueryTextContent(ae->Offset(), ae->Count());
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
DispatchEvent(&event);
|
|
|
|
|
|
|
|
if (!event.mSucceeded) {
|
2010-08-04 23:47:26 +04:00
|
|
|
ALOGIME("IME: -> failed");
|
|
|
|
AndroidBridge::Bridge()->ReturnIMEQueryResult(
|
|
|
|
nsnull, 0, 0, 0);
|
2010-06-04 00:56:36 +04:00
|
|
|
return;
|
2010-08-17 12:07:45 +04:00
|
|
|
} else if (!event.mWasAsync) {
|
|
|
|
AndroidBridge::Bridge()->ReturnIMEQueryResult(
|
|
|
|
event.mReply.mString.get(),
|
|
|
|
event.mReply.mString.Length(), 0, 0);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
2010-08-04 23:47:26 +04:00
|
|
|
//ALOGIME("IME: -> l=%u", event.mReply.mString.Length());
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_DELETE_TEXT:
|
2012-04-19 21:49:31 +04:00
|
|
|
{
|
2010-08-04 23:47:26 +04:00
|
|
|
ALOGIME("IME: IME_DELETE_TEXT");
|
2011-10-17 18:59:28 +04:00
|
|
|
nsKeyEvent event(true, NS_KEY_PRESS, this);
|
2012-04-19 21:49:31 +04:00
|
|
|
ANPEvent pluginEvent;
|
|
|
|
InitKeyEvent(event, *ae, &pluginEvent);
|
2010-08-18 03:52:00 +04:00
|
|
|
event.keyCode = NS_VK_BACK;
|
2010-08-04 23:47:26 +04:00
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_SET_SELECTION:
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2010-08-04 23:47:26 +04:00
|
|
|
ALOGIME("IME: IME_SET_SELECTION: o=%u, l=%d", ae->Offset(), ae->Count());
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsSelectionEvent selEvent(true, NS_SELECTION_SET, this);
|
2010-08-04 23:47:26 +04:00
|
|
|
InitEvent(selEvent, nsnull);
|
|
|
|
|
|
|
|
selEvent.mOffset = PRUint32(ae->Count() >= 0 ?
|
|
|
|
ae->Offset() :
|
|
|
|
ae->Offset() + ae->Count());
|
2011-06-02 16:56:50 +04:00
|
|
|
selEvent.mLength = PRUint32(NS_ABS(ae->Count()));
|
2011-10-17 18:59:28 +04:00
|
|
|
selEvent.mReversed = ae->Count() >= 0 ? false : true;
|
2010-08-04 23:47:26 +04:00
|
|
|
|
|
|
|
DispatchEvent(&selEvent);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_GET_SELECTION:
|
|
|
|
{
|
|
|
|
ALOGIME("IME: IME_GET_SELECTION");
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsQueryContentEvent event(true, NS_QUERY_SELECTED_TEXT, this);
|
2010-08-04 23:47:26 +04:00
|
|
|
InitEvent(event, nsnull);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
|
|
|
|
if (!event.mSucceeded) {
|
|
|
|
ALOGIME("IME: -> failed");
|
|
|
|
AndroidBridge::Bridge()->ReturnIMEQueryResult(
|
|
|
|
nsnull, 0, 0, 0);
|
|
|
|
return;
|
2010-08-17 12:07:45 +04:00
|
|
|
} else if (!event.mWasAsync) {
|
|
|
|
AndroidBridge::Bridge()->ReturnIMEQueryResult(
|
|
|
|
event.mReply.mString.get(),
|
|
|
|
event.mReply.mString.Length(),
|
|
|
|
event.GetSelectionStart(),
|
|
|
|
event.GetSelectionEnd() - event.GetSelectionStart());
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
2010-08-04 23:47:26 +04:00
|
|
|
//ALOGIME("IME: -> o=%u, l=%u", event.mReply.mOffset, event.mReply.mString.Length());
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow *
|
|
|
|
nsWindow::FindWindowForPoint(const nsIntPoint& pt)
|
|
|
|
{
|
|
|
|
if (!mBounds.Contains(pt))
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// children mBounds are relative to their parent
|
|
|
|
nsIntPoint childPoint(pt.x - mBounds.x, pt.y - mBounds.y);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < mChildren.Length(); ++i) {
|
|
|
|
if (mChildren[i]->mBounds.Contains(childPoint))
|
|
|
|
return mChildren[i]->FindWindowForPoint(childPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::UserActivity()
|
|
|
|
{
|
|
|
|
if (!mIdleService) {
|
|
|
|
mIdleService = do_GetService("@mozilla.org/widget/idleservice;1");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIdleService) {
|
|
|
|
mIdleService->ResetIdleTimeOut();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 23:47:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ResetInputState()
|
|
|
|
{
|
|
|
|
//ALOGIME("IME: ResetInputState: s=%d", aState);
|
|
|
|
|
|
|
|
// Cancel composition on Gecko side
|
|
|
|
if (mIMEComposing) {
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsTextEvent textEvent(true, NS_TEXT_TEXT, this);
|
2010-08-21 04:07:26 +04:00
|
|
|
InitEvent(textEvent, nsnull);
|
|
|
|
textEvent.theText = mIMEComposingText;
|
|
|
|
DispatchEvent(&textEvent);
|
2010-09-24 07:59:26 +04:00
|
|
|
mIMEComposingText.Truncate(0);
|
2010-08-21 04:07:26 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsCompositionEvent event(true, NS_COMPOSITION_END, this);
|
2010-08-04 23:47:26 +04:00
|
|
|
InitEvent(event, nsnull);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2010-08-05 22:11:32 +04:00
|
|
|
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_RESETINPUTSTATE, 0);
|
2011-12-16 01:35:45 +04:00
|
|
|
|
|
|
|
// Send IME text/selection change notifications
|
|
|
|
OnIMETextChange(0, 0, 0);
|
|
|
|
OnIMESelectionChange();
|
|
|
|
|
2010-08-04 23:47:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-27 15:51:52 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsWindow::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2011-11-27 15:51:53 +04:00
|
|
|
ALOGIME("IME: SetInputContext: s=0x%X, 0x%X, action=0x%X, 0x%X",
|
|
|
|
aContext.mIMEState.mEnabled, aContext.mIMEState.mOpen,
|
|
|
|
aAction.mCause, aAction.mFocusChange);
|
2010-08-04 23:47:26 +04:00
|
|
|
|
2011-11-27 15:51:52 +04:00
|
|
|
mInputContext = aContext;
|
2011-04-20 16:47:40 +04:00
|
|
|
|
|
|
|
// Ensure that opening the virtual keyboard is allowed for this specific
|
2011-11-27 15:51:52 +04:00
|
|
|
// InputContext depending on the content.ime.strict.policy pref
|
2011-11-27 15:51:53 +04:00
|
|
|
if (aContext.mIMEState.mEnabled != IMEState::DISABLED &&
|
|
|
|
aContext.mIMEState.mEnabled != IMEState::PLUGIN &&
|
2011-11-27 15:51:52 +04:00
|
|
|
Preferences::GetBool("content.ime.strict_policy", false) &&
|
2011-11-27 15:51:53 +04:00
|
|
|
!aAction.ContentGotFocusByTrustedCause() &&
|
|
|
|
!aAction.UserMightRequestOpenVKB()) {
|
2011-11-27 15:51:52 +04:00
|
|
|
return;
|
2011-04-20 16:47:40 +04:00
|
|
|
}
|
|
|
|
|
2012-05-24 19:03:07 +04:00
|
|
|
int enabled = int(aContext.mIMEState.mEnabled);
|
|
|
|
|
|
|
|
// Only show the virtual keyboard for plugins if mOpen is set appropriately.
|
|
|
|
// This avoids showing it whenever a plugin is focused. Bug 747492
|
|
|
|
if (aContext.mIMEState.mEnabled == IMEState::PLUGIN &&
|
|
|
|
aContext.mIMEState.mOpen != IMEState::OPEN) {
|
|
|
|
enabled = int(IMEState::DISABLED);
|
|
|
|
}
|
|
|
|
|
|
|
|
AndroidBridge::NotifyIMEEnabled(enabled,
|
2011-11-27 15:51:52 +04:00
|
|
|
aContext.mHTMLInputType,
|
|
|
|
aContext.mActionHint);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2011-11-27 15:51:52 +04:00
|
|
|
NS_IMETHODIMP_(InputContext)
|
|
|
|
nsWindow::GetInputContext()
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2011-11-27 15:51:53 +04:00
|
|
|
mInputContext.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
|
2011-11-27 15:51:52 +04:00
|
|
|
return mInputContext;
|
2010-08-04 23:47:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::CancelIMEComposition()
|
|
|
|
{
|
|
|
|
ALOGIME("IME: CancelIMEComposition");
|
|
|
|
|
|
|
|
// Cancel composition on Gecko side
|
|
|
|
if (mIMEComposing) {
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsTextEvent textEvent(true, NS_TEXT_TEXT, this);
|
2010-08-04 23:47:26 +04:00
|
|
|
InitEvent(textEvent, nsnull);
|
|
|
|
DispatchEvent(&textEvent);
|
2010-09-24 07:59:26 +04:00
|
|
|
mIMEComposingText.Truncate(0);
|
2010-08-04 23:47:26 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsCompositionEvent compEvent(true, NS_COMPOSITION_END, this);
|
2010-08-04 23:47:26 +04:00
|
|
|
InitEvent(compEvent, nsnull);
|
|
|
|
DispatchEvent(&compEvent);
|
|
|
|
}
|
|
|
|
|
2010-08-05 22:11:32 +04:00
|
|
|
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_CANCELCOMPOSITION, 0);
|
2010-08-04 23:47:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::OnIMEFocusChange(bool aFocus)
|
2010-08-04 23:47:26 +04:00
|
|
|
{
|
|
|
|
ALOGIME("IME: OnIMEFocusChange: f=%d", aFocus);
|
2010-08-17 12:07:45 +04:00
|
|
|
|
|
|
|
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_FOCUSCHANGE,
|
|
|
|
int(aFocus));
|
2010-11-25 01:09:24 +03:00
|
|
|
|
|
|
|
if (aFocus) {
|
|
|
|
OnIMETextChange(0, 0, 0);
|
|
|
|
OnIMESelectionChange();
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-08-04 23:47:26 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::OnIMETextChange(PRUint32 aStart, PRUint32 aOldEnd, PRUint32 aNewEnd)
|
|
|
|
{
|
|
|
|
ALOGIME("IME: OnIMETextChange: s=%d, oe=%d, ne=%d",
|
|
|
|
aStart, aOldEnd, aNewEnd);
|
|
|
|
|
2010-11-25 01:09:24 +03:00
|
|
|
// A quirk in Android makes it necessary to pass the whole text.
|
|
|
|
// The more efficient way would have been passing the substring from index
|
|
|
|
// aStart to index aNewEnd
|
2010-08-04 23:47:26 +04:00
|
|
|
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
nsQueryContentEvent event(true, NS_QUERY_TEXT_CONTENT, this);
|
2010-11-25 01:09:24 +03:00
|
|
|
InitEvent(event, nsnull);
|
|
|
|
event.InitForQueryTextContent(0, PR_UINT32_MAX);
|
2010-08-04 23:47:26 +04:00
|
|
|
|
2010-11-25 01:09:24 +03:00
|
|
|
DispatchEvent(&event);
|
|
|
|
if (!event.mSucceeded)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
AndroidBridge::NotifyIMEChange(event.mReply.mString.get(),
|
|
|
|
event.mReply.mString.Length(),
|
|
|
|
aStart, aOldEnd, aNewEnd);
|
2010-08-04 23:47:26 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::OnIMESelectionChange(void)
|
|
|
|
{
|
|
|
|
ALOGIME("IME: OnIMESelectionChange");
|
|
|
|
|
2011-11-23 00:31:49 +04:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
nsQueryContentEvent event(true, NS_QUERY_SELECTED_TEXT, this);
|
2010-08-04 23:47:26 +04:00
|
|
|
InitEvent(event, nsnull);
|
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
if (!event.mSucceeded)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-08-05 22:11:32 +04:00
|
|
|
AndroidBridge::NotifyIMEChange(nsnull, 0, int(event.mReply.mOffset),
|
|
|
|
int(event.mReply.mOffset +
|
|
|
|
event.mReply.mString.Length()), -1);
|
2010-08-04 23:47:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-24 07:28:15 +04:00
|
|
|
nsIMEUpdatePreference
|
|
|
|
nsWindow::GetIMEUpdatePreference()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return nsIMEUpdatePreference(true, true);
|
2010-09-24 07:28:15 +04:00
|
|
|
}
|
|
|
|
|
2012-02-10 07:47:50 +04:00
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
|
|
|
void
|
2012-05-04 19:08:47 +04:00
|
|
|
nsWindow::DrawWindowUnderlay(LayerManager* aManager, nsIntRect aRect)
|
|
|
|
{
|
2012-05-04 19:08:46 +04:00
|
|
|
JNIEnv *env = GetJNIForThread();
|
|
|
|
NS_ABORT_IF_FALSE(env, "No JNI environment at DrawWindowUnderlay()!");
|
|
|
|
if (!env)
|
|
|
|
return;
|
2012-02-11 11:03:02 +04:00
|
|
|
|
2012-05-04 19:08:47 +04:00
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2012-02-11 11:03:02 +04:00
|
|
|
|
2012-05-04 19:08:46 +04:00
|
|
|
AndroidGeckoLayerClient& client = AndroidBridge::Bridge()->GetLayerClient();
|
2012-05-08 17:35:59 +04:00
|
|
|
if (!client.CreateFrame(&jniFrame, mLayerRendererFrame)) return;
|
|
|
|
if (!client.ActivateProgram(&jniFrame)) return;
|
|
|
|
if (!mLayerRendererFrame.BeginDrawing(&jniFrame)) return;
|
|
|
|
if (!mLayerRendererFrame.DrawBackground(&jniFrame)) return;
|
|
|
|
if (!client.DeactivateProgram(&jniFrame)) return; // redundant, but in case somebody adds code after this...
|
2012-02-10 07:47:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-04 19:08:47 +04:00
|
|
|
nsWindow::DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect)
|
|
|
|
{
|
2012-05-04 19:08:46 +04:00
|
|
|
JNIEnv *env = GetJNIForThread();
|
|
|
|
NS_ABORT_IF_FALSE(env, "No JNI environment at DrawWindowOverlay()!");
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2012-05-04 19:08:47 +04:00
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
|
2012-02-10 11:55:13 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mLayerRendererFrame.isNull(),
|
|
|
|
"Frame should have been created in DrawWindowUnderlay()!");
|
2012-02-11 11:03:02 +04:00
|
|
|
|
2012-02-14 02:52:30 +04:00
|
|
|
AndroidGeckoLayerClient& client = AndroidBridge::Bridge()->GetLayerClient();
|
|
|
|
|
2012-05-08 17:35:59 +04:00
|
|
|
if (!client.ActivateProgram(&jniFrame)) return;
|
|
|
|
if (!mLayerRendererFrame.DrawForeground(&jniFrame)) return;
|
|
|
|
if (!mLayerRendererFrame.EndDrawing(&jniFrame)) return;
|
|
|
|
if (!client.DeactivateProgram(&jniFrame)) return;
|
2012-05-04 19:08:46 +04:00
|
|
|
mLayerRendererFrame.Dispose(env);
|
2012-02-10 07:47:50 +04:00
|
|
|
}
|
2012-03-14 08:15:11 +04:00
|
|
|
|
|
|
|
// off-main-thread compositor fields and functions
|
|
|
|
|
|
|
|
nsRefPtr<mozilla::layers::CompositorParent> nsWindow::sCompositorParent = 0;
|
2012-03-29 02:00:32 +04:00
|
|
|
nsRefPtr<mozilla::layers::CompositorChild> nsWindow::sCompositorChild = 0;
|
2012-03-14 08:15:11 +04:00
|
|
|
base::Thread * nsWindow::sCompositorThread = 0;
|
2012-03-29 02:00:32 +04:00
|
|
|
bool nsWindow::sCompositorPaused = false;
|
2012-03-14 08:15:11 +04:00
|
|
|
|
|
|
|
void
|
2012-03-29 02:00:32 +04:00
|
|
|
nsWindow::SetCompositor(mozilla::layers::CompositorParent* aCompositorParent,
|
|
|
|
mozilla::layers::CompositorChild* aCompositorChild,
|
|
|
|
::base::Thread* aCompositorThread)
|
2012-03-14 08:15:11 +04:00
|
|
|
{
|
|
|
|
sCompositorParent = aCompositorParent;
|
2012-03-29 02:00:32 +04:00
|
|
|
sCompositorChild = aCompositorChild;
|
2012-03-14 08:15:11 +04:00
|
|
|
sCompositorThread = aCompositorThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::ScheduleComposite()
|
|
|
|
{
|
|
|
|
if (sCompositorParent) {
|
|
|
|
sCompositorParent->ScheduleRenderOnCompositorThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::SchedulePauseComposition()
|
|
|
|
{
|
|
|
|
if (sCompositorParent) {
|
|
|
|
sCompositorParent->SchedulePauseOnCompositorThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-04-20 19:46:30 +04:00
|
|
|
nsWindow::ScheduleResumeComposition(int width, int height)
|
2012-03-14 08:15:11 +04:00
|
|
|
{
|
|
|
|
if (sCompositorParent) {
|
2012-04-20 19:46:30 +04:00
|
|
|
sCompositorParent->ScheduleResumeOnCompositorThread(width, height);
|
2012-03-14 08:15:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-10 07:47:50 +04:00
|
|
|
#endif
|
|
|
|
|