2010-11-24 10:22:40 -08:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
2010-06-03 13:56:36 -07:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Android code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
2010-11-12 15:58:29 -08:00
|
|
|
* Matt Brubeck <mbrubeck@mozilla.com>
|
|
|
|
* Vivien Nicolas <vnicolas@mozilla.com>
|
2010-06-03 13:56:36 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include <android/log.h>
|
2010-08-25 22:52:08 -07:00
|
|
|
#include <math.h>
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-11-24 10:22:40 -08:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
#include "mozilla/unused.h"
|
|
|
|
|
|
|
|
using mozilla::dom::ContentParent;
|
|
|
|
using mozilla::dom::ContentChild;
|
|
|
|
using mozilla::unused;
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
#include "nsAppShell.h"
|
|
|
|
#include "nsIdleService.h"
|
|
|
|
#include "nsWindow.h"
|
2010-11-24 10:22:40 -08:00
|
|
|
#include "nsIObserverService.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2010-08-25 22:52:08 -07:00
|
|
|
#include "nsIDOMSimpleGestureEvent.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
#include "nsWidgetAtoms.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
#include "Layers.h"
|
|
|
|
#include "BasicLayers.h"
|
|
|
|
#include "LayerManagerOGL.h"
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
|
|
|
|
|
|
|
|
// The dimensions of the current android view
|
|
|
|
static gfxIntSize gAndroidBounds;
|
2011-01-14 12:36:19 -08:00
|
|
|
static gfxIntSize gAndroidScreenBounds;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-11-24 10:22:40 -08: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")) {
|
|
|
|
ContentParent *cp = ContentParent::GetSingleton(PR_FALSE);
|
|
|
|
NS_ABORT_IF_FALSE(cp, "Must have content process if notified of its creation");
|
2011-01-14 12:36:19 -08:00
|
|
|
unused << cp->SendScreenSizeChanged(gAndroidScreenBounds);
|
2010-11-24 10:22:40 -08: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)
|
|
|
|
|
2010-10-16 05:15:54 -07:00
|
|
|
static PRBool gMenu;
|
|
|
|
static PRBool gMenuConsumed;
|
2010-06-03 13:56:36 -07: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-25 17:52:37 -07:00
|
|
|
static nsRefPtr<gl::GLContext> sGLContext;
|
2010-09-08 15:19:11 -07:00
|
|
|
static bool sFailedToCreateGLContext = false;
|
2010-12-13 14:37:25 -08:00
|
|
|
static bool sValidSurface;
|
2010-08-25 22:52:08 -07:00
|
|
|
|
2010-11-18 09:18:31 -08: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-25 17:52:37 -07:00
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
static nsWindow*
|
|
|
|
TopWindow()
|
|
|
|
{
|
|
|
|
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-25 17:52:37 -07:00
|
|
|
for (PRUint32 i = 0; i < wins.Length(); ++i) {
|
2010-06-03 13:56:36 -07:00
|
|
|
nsWindow *w = wins[i];
|
|
|
|
LogWindow(w, i, indent);
|
|
|
|
DumpWindows(w->mChildren, indent+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::nsWindow() :
|
|
|
|
mIsVisible(PR_FALSE),
|
2011-02-14 17:01:01 -08:00
|
|
|
mParent(nsnull),
|
|
|
|
mFocus(nsnull)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::~nsWindow()
|
|
|
|
{
|
|
|
|
gTopLevelWindows.RemoveElement(this);
|
2011-02-14 17:01:01 -08:00
|
|
|
nsWindow *top = FindTopLevel();
|
|
|
|
if (top->mFocus == this)
|
|
|
|
top->mFocus = nsnull;
|
2010-06-03 13:56:36 -07:00
|
|
|
ALOG("nsWindow %p destructor", (void*)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
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,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
nsIAppShell *aAppShell,
|
|
|
|
nsIToolkit *aToolkit,
|
|
|
|
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-25 13:29:43 -07:00
|
|
|
if (!AndroidBridge::Bridge()) {
|
|
|
|
aNativeParent = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseCreate(nsnull, mBounds, aHandleEventFunction, aContext,
|
|
|
|
aAppShell, aToolkit, aInitData);
|
|
|
|
|
|
|
|
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 09:18:31 -08:00
|
|
|
float dpi = GetDPI();
|
|
|
|
mSwipeMaxPinchDelta = SWIPE_MAX_PINCH_DELTA_INCHES * dpi;
|
|
|
|
mSwipeMinDistance = SWIPE_MIN_DISTANCE_INCHES * dpi;
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Destroy(void)
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < mChildren.Length(); ++i) {
|
|
|
|
// why do we still have children?
|
|
|
|
ALOG("### Warning: Destroying window %p and reparenting child %p to null!", (void*)this, (void*)mChildren[i]);
|
|
|
|
mChildren[i]->SetParent(nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsTopLevel())
|
|
|
|
gTopLevelWindows.RemoveElement(this);
|
|
|
|
|
|
|
|
if (mParent)
|
|
|
|
mParent->mChildren.RemoveElement(this);
|
|
|
|
|
|
|
|
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,
|
|
|
|
PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
if (FindTopLevel() == TopWindow())
|
2011-01-18 16:25:20 -08:00
|
|
|
nsAppShell::gAppShell->PostEvent(new AndroidGeckoEvent(-1, -1, -1, -1));
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-18 04:28:50 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ReparentNativeWidget(nsIWidget *aNewParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewParent, "");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
nsIWidget*
|
|
|
|
nsWindow::GetParent()
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
2010-10-07 10:28:27 -07:00
|
|
|
float
|
|
|
|
nsWindow::GetDPI()
|
|
|
|
{
|
|
|
|
if (AndroidBridge::Bridge())
|
|
|
|
return AndroidBridge::Bridge()->GetDPI();
|
|
|
|
return 160.0f;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Show(PRBool aState)
|
|
|
|
{
|
|
|
|
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-14 17:01:01 -08: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.
|
|
|
|
Resize(0, 0, gAndroidBounds.width, gAndroidBounds.height, PR_FALSE);
|
|
|
|
BringToFront();
|
|
|
|
} else if (TopWindow() == this) {
|
|
|
|
// find the next visible window to show
|
2011-03-02 09:23:02 -08:00
|
|
|
unsigned int i;
|
2011-02-14 17:01:01 -08:00
|
|
|
for (i = 1; i < gTopLevelWindows.Length(); i++) {
|
|
|
|
nsWindow *win = gTopLevelWindows[i];
|
|
|
|
if (!win->mIsVisible)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
win->BringToFront();
|
|
|
|
break;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
}
|
2011-02-14 17:01:01 -08:00
|
|
|
} else if (FindTopLevel() == TopWindow()) {
|
|
|
|
nsAppShell::gAppShell->PostEvent(new AndroidGeckoEvent(-1, -1, -1, -1));
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ANDROID_DEBUG_WIDGET
|
|
|
|
DumpWindows();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetModal(PRBool aState)
|
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::SetModal %d ignored", (void*)this, aState);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::IsVisible(PRBool& aState)
|
|
|
|
{
|
|
|
|
aState = mIsVisible;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ConstrainPosition(PRBool aAllowSlop,
|
|
|
|
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,
|
|
|
|
PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(PRInt32 aWidth,
|
|
|
|
PRInt32 aHeight,
|
|
|
|
PRBool aRepaint)
|
|
|
|
{
|
|
|
|
return Resize(mBounds.x,
|
|
|
|
mBounds.y,
|
|
|
|
aWidth,
|
|
|
|
aHeight,
|
|
|
|
aRepaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(PRInt32 aX,
|
|
|
|
PRInt32 aY,
|
|
|
|
PRInt32 aWidth,
|
|
|
|
PRInt32 aHeight,
|
|
|
|
PRBool aRepaint)
|
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::Resize [%d %d %d %d] (repaint %d)", (void*)this, aX, aY, aWidth, aHeight, aRepaint);
|
|
|
|
|
|
|
|
PRBool needSizeDispatch = aWidth != mBounds.width || aHeight != mBounds.height;
|
|
|
|
|
|
|
|
if (IsTopLevel()) {
|
|
|
|
ALOG("... ignoring Resize sizes on toplevel window");
|
|
|
|
aX = 0;
|
|
|
|
aY = 0;
|
|
|
|
aWidth = gAndroidBounds.width;
|
|
|
|
aHeight = gAndroidBounds.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBounds.x = aX;
|
|
|
|
mBounds.y = aY;
|
|
|
|
mBounds.width = aWidth;
|
|
|
|
mBounds.height = aHeight;
|
|
|
|
|
|
|
|
if (needSizeDispatch)
|
|
|
|
OnSizeChanged(gfxIntSize(aWidth, aHeight));
|
|
|
|
|
|
|
|
// Should we skip honoring aRepaint here?
|
|
|
|
if (aRepaint && FindTopLevel() == TopWindow())
|
2011-01-18 16:25:20 -08:00
|
|
|
nsAppShell::gAppShell->PostEvent(new AndroidGeckoEvent(-1, -1, -1, -1));
|
2010-06-03 13:56:36 -07: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,
|
|
|
|
PRBool aActivate)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetSizeMode(PRInt32 aMode)
|
|
|
|
{
|
2010-06-16 10:20:54 -07:00
|
|
|
switch (aMode) {
|
|
|
|
case nsSizeMode_Minimized:
|
|
|
|
AndroidBridge::Bridge()->MoveTaskToBack();
|
|
|
|
break;
|
2010-11-08 18:11:13 -08:00
|
|
|
case nsSizeMode_Fullscreen:
|
|
|
|
MakeFullScreen(PR_TRUE);
|
|
|
|
break;
|
2010-06-16 10:20:54 -07:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Enable(PRBool aState)
|
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::Enable %d ignored", (void*)this, aState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::IsEnabled(PRBool *aState)
|
|
|
|
{
|
|
|
|
*aState = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Invalidate(const nsIntRect &aRect,
|
|
|
|
PRBool aIsSynchronous)
|
|
|
|
{
|
2011-01-18 16:25:20 -08:00
|
|
|
nsAppShell::gAppShell->PostEvent(new AndroidGeckoEvent(-1, -1, -1, -1));
|
2010-06-03 13:56:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Update()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
nsWindow::SetFocus(PRBool aRaise)
|
|
|
|
{
|
|
|
|
if (!aRaise)
|
|
|
|
ALOG("nsWindow::SetFocus: can't set focus without raising, ignoring aRaise = false!");
|
|
|
|
|
2010-07-16 11:24:42 -07:00
|
|
|
if (!AndroidBridge::Bridge())
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-02-14 17:01:01 -08:00
|
|
|
nsWindow *top = FindTopLevel();
|
|
|
|
top->mFocus = this;
|
|
|
|
top->BringToFront();
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::BringToFront()
|
|
|
|
{
|
|
|
|
if (FindTopLevel() == TopWindow())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!IsTopLevel()) {
|
|
|
|
FindTopLevel()->BringToFront();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow *oldTop = nsnull;
|
|
|
|
if (!gTopLevelWindows.IsEmpty())
|
|
|
|
oldTop = gTopLevelWindows[0];
|
|
|
|
|
|
|
|
gTopLevelWindows.RemoveElement(this);
|
|
|
|
gTopLevelWindows.InsertElementAt(0, this);
|
|
|
|
|
|
|
|
if (oldTop) {
|
2010-11-16 14:27:53 -08:00
|
|
|
nsGUIEvent event(PR_TRUE, NS_DEACTIVATE, oldTop);
|
2010-06-03 13:56:36 -07:00
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGUIEvent event(PR_TRUE, NS_ACTIVATE, this);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
|
2011-01-18 16:25:20 -08:00
|
|
|
nsAppShell::gAppShell->PostEvent(new AndroidGeckoEvent(-1, -1, -1, -1));
|
2010-06-03 13:56:36 -07: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-20 17:07:26 -07:00
|
|
|
if (mEventCallback) {
|
|
|
|
nsEventStatus status = (*mEventCallback)(aEvent);
|
|
|
|
|
2010-09-23 20:59:26 -07:00
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_COMPOSITION_START:
|
|
|
|
mIMEComposing = PR_TRUE;
|
|
|
|
break;
|
|
|
|
case NS_COMPOSITION_END:
|
|
|
|
mIMEComposing = PR_FALSE;
|
|
|
|
break;
|
|
|
|
case NS_TEXT_TEXT:
|
|
|
|
mIMEComposingText = static_cast<nsTextEvent*>(aEvent)->theText;
|
|
|
|
break;
|
|
|
|
}
|
2010-08-20 17:07:26 -07:00
|
|
|
return status;
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2010-11-08 18:11:13 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::MakeFullScreen(PRBool aFullScreen)
|
|
|
|
{
|
|
|
|
AndroidBridge::Bridge()->SetFullScreen(aFullScreen);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetWindowClass(const nsAString& xulWinType)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-08 15:19:11 -07:00
|
|
|
mozilla::layers::LayerManager*
|
2010-12-06 18:05:52 -08:00
|
|
|
nsWindow::GetLayerManager(LayerManagerPersistence, bool* aAllowRetaining)
|
2010-09-08 15:19:11 -07:00
|
|
|
{
|
2010-10-15 03:34:29 -07:00
|
|
|
if (aAllowRetaining) {
|
|
|
|
*aAllowRetaining = true;
|
|
|
|
}
|
2010-09-08 15:19:11 -07:00
|
|
|
if (mLayerManager) {
|
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf_stderr("nsWindow::GetLayerManager\n");
|
|
|
|
|
|
|
|
nsWindow *topWindow = TopWindow();
|
|
|
|
|
|
|
|
if (!topWindow) {
|
|
|
|
printf_stderr(" -- no topwindow\n");
|
2010-09-14 16:40:23 -07:00
|
|
|
mLayerManager = CreateBasicLayerManager();
|
2010-09-08 15:19:11 -07:00
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
mUseAcceleratedRendering = GetShouldAccelerate();
|
|
|
|
|
|
|
|
if (!mUseAcceleratedRendering ||
|
|
|
|
sFailedToCreateGLContext)
|
|
|
|
{
|
|
|
|
printf_stderr(" -- creating basic, not accelerated\n");
|
2010-09-14 16:40:23 -07:00
|
|
|
mLayerManager = CreateBasicLayerManager();
|
2010-09-08 15:19:11 -07:00
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sGLContext) {
|
|
|
|
// the window we give doesn't matter here
|
|
|
|
sGLContext = mozilla::gl::GLContextProvider::CreateForWindow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sGLContext) {
|
|
|
|
nsRefPtr<mozilla::layers::LayerManagerOGL> layerManager =
|
|
|
|
new mozilla::layers::LayerManagerOGL(this);
|
|
|
|
|
|
|
|
if (layerManager && layerManager->Initialize(sGLContext))
|
|
|
|
mLayerManager = layerManager;
|
2010-12-13 14:37:25 -08:00
|
|
|
sValidSurface = true;
|
2010-09-08 15:19:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!sGLContext || !mLayerManager) {
|
|
|
|
sGLContext = nsnull;
|
|
|
|
sFailedToCreateGLContext = PR_TRUE;
|
|
|
|
|
2010-09-14 16:40:23 -07:00
|
|
|
mLayerManager = CreateBasicLayerManager();
|
2010-09-08 15:19:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
gfxASurface*
|
|
|
|
nsWindow::GetThebesSurface()
|
|
|
|
{
|
|
|
|
/* This is really a dummy surface; this is only used when doing reflow, because
|
|
|
|
* we need a RenderingContext to measure text against.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// XXX this really wants to return already_AddRefed, but this only really gets used
|
|
|
|
// on direct assignment to a gfxASurface
|
|
|
|
return new gfxImageSurface(gfxIntSize(5,5), gfxImageSurface::ImageFormatRGB24);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2010-07-16 11:24:42 -07:00
|
|
|
if (!AndroidBridge::Bridge())
|
|
|
|
return;
|
|
|
|
|
2010-10-27 13:10:15 -07:00
|
|
|
nsWindow *win = TopWindow();
|
|
|
|
if (!win)
|
|
|
|
return;
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
switch (ae->Type()) {
|
|
|
|
case AndroidGeckoEvent::SIZE_CHANGED: {
|
|
|
|
int nw = ae->P0().x;
|
|
|
|
int nh = ae->P0().y;
|
|
|
|
|
2011-01-14 12:36:19 -08:00
|
|
|
if (nw != gAndroidBounds.width ||
|
|
|
|
nh != gAndroidBounds.height) {
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-01-14 12:36:19 -08:00
|
|
|
gAndroidBounds.width = nw;
|
|
|
|
gAndroidBounds.height = nh;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-01-14 12:36:19 -08: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,
|
|
|
|
PR_TRUE);
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-01-14 12:36:19 -08:00
|
|
|
int newScreenWidth = ae->P1().x;
|
|
|
|
int newScreenHeight = ae->P1().y;
|
|
|
|
|
|
|
|
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.
|
|
|
|
ContentParent *cp = ContentParent::GetSingleton(PR_FALSE);
|
|
|
|
if (cp)
|
|
|
|
unused << cp->SendScreenSizeChanged(gAndroidScreenBounds);
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (NS_SUCCEEDED(obs->AddObserver(notifier, "ipc:content-created", PR_FALSE))) {
|
|
|
|
if (NS_SUCCEEDED(obs->AddObserver(notifier, "xpcom-shutdown", PR_FALSE)))
|
|
|
|
gContentCreationNotifier = notifier;
|
|
|
|
else
|
|
|
|
obs->RemoveObserver(notifier, "ipc:content-created");
|
2010-11-24 10:22:40 -08:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::MOTION_EVENT: {
|
2010-10-27 13:10:15 -07:00
|
|
|
win->UserActivity();
|
2010-06-03 13:56:36 -07:00
|
|
|
if (!gTopLevelWindows.IsEmpty()) {
|
|
|
|
nsIntPoint pt(ae->P0());
|
|
|
|
pt.x = NS_MIN(NS_MAX(pt.x, 0), gAndroidBounds.width - 1);
|
|
|
|
pt.y = NS_MIN(NS_MAX(pt.y, 0), gAndroidBounds.height - 1);
|
2010-10-27 13:10:15 -07:00
|
|
|
nsWindow *target = win->FindWindowForPoint(pt);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
ALOG("MOTION_EVENT %f,%f -> %p (visible: %d children: %d)", ae->P0().x, ae->P0().y, (void*)target,
|
|
|
|
target ? target->mIsVisible : 0,
|
|
|
|
target ? target->mChildren.Length() : 0);
|
|
|
|
|
|
|
|
DumpWindows();
|
|
|
|
#endif
|
|
|
|
|
2010-07-07 14:34:12 -07:00
|
|
|
if (target) {
|
|
|
|
if (ae->Count() > 1)
|
|
|
|
target->OnMultitouchEvent(ae);
|
|
|
|
else
|
|
|
|
target->OnMotionEvent(ae);
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::KEY_EVENT:
|
2010-10-27 13:10:15 -07:00
|
|
|
win->UserActivity();
|
2011-02-14 17:01:01 -08:00
|
|
|
if (win->mFocus)
|
|
|
|
win->mFocus->OnKeyEvent(ae);
|
2010-06-03 13:56:36 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::DRAW:
|
2010-10-27 13:10:15 -07:00
|
|
|
win->OnDraw(ae);
|
2010-06-03 13:56:36 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::IME_EVENT:
|
2010-10-27 13:10:15 -07:00
|
|
|
win->UserActivity();
|
2011-02-14 17:01:01 -08:00
|
|
|
if (win->mFocus) {
|
|
|
|
win->mFocus->OnIMEEvent(ae);
|
2010-06-22 17:15:29 -07:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Sending unexpected IME event to top window");
|
2010-10-27 13:10:15 -07:00
|
|
|
win->OnIMEEvent(ae);
|
2010-06-22 17:15:29 -07:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
break;
|
|
|
|
|
2011-03-02 09:23:02 -08:00
|
|
|
case AndroidGeckoEvent::SURFACE_CREATED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AndroidGeckoEvent::SURFACE_DESTROYED:
|
|
|
|
sValidSurface = false;
|
|
|
|
break;
|
2010-12-13 14:37:25 -08:00
|
|
|
|
2011-03-02 09:23:02 -08:00
|
|
|
case AndroidGeckoEvent::GECKO_EVENT_SYNC:
|
|
|
|
AndroidBridge::Bridge()->AcknowledgeEventSync();
|
|
|
|
break;
|
2010-12-13 14:37:25 -08:00
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnAndroidEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2010-07-16 11:24:42 -07:00
|
|
|
if (!AndroidBridge::Bridge())
|
|
|
|
return;
|
|
|
|
|
2010-06-03 13:56:36 -07: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsWindow::DrawTo(gfxASurface *targetSurface)
|
|
|
|
{
|
|
|
|
if (!mIsVisible)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
nsEventStatus status;
|
2010-06-03 13:56:36 -07:00
|
|
|
nsIntRect boundsRect(0, 0, mBounds.width, mBounds.height);
|
|
|
|
|
2010-06-25 17:52:37 -07: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-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
// If we have no covering child, then we need to render this.
|
|
|
|
if (coveringChildIndex == -1) {
|
2010-06-28 23:42:28 -07:00
|
|
|
nsPaintEvent event(PR_TRUE, NS_PAINT, this);
|
|
|
|
event.region = boundsRect;
|
2010-12-06 18:05:52 -08:00
|
|
|
switch (GetLayerManager(nsnull)->GetBackendType()) {
|
2010-06-25 17:52:37 -07:00
|
|
|
case LayerManager::LAYERS_BASIC: {
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
|
|
|
|
|
|
|
|
{
|
2010-07-15 14:08:04 -07:00
|
|
|
AutoLayerManagerSetup
|
2011-01-21 10:14:03 -08:00
|
|
|
setupLayerManager(this, ctx, BasicLayerManager::BUFFER_NONE);
|
2010-06-25 17:52:37 -07: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-03 13:56:36 -07:00
|
|
|
#if 0
|
2010-06-25 17:52:37 -07:00
|
|
|
if (status == nsEventStatus_eIgnore)
|
|
|
|
return PR_FALSE;
|
2010-06-03 13:56:36 -07:00
|
|
|
#endif
|
|
|
|
|
2010-06-25 17:52:37 -07: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-28 23:42:28 -07:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
case LayerManager::LAYERS_OPENGL: {
|
2010-12-06 18:05:52 -08:00
|
|
|
static_cast<mozilla::layers::LayerManagerOGL*>(GetLayerManager(nsnull))->
|
2010-06-25 17:52:37 -07:00
|
|
|
SetClippingRegion(nsIntRegion(boundsRect));
|
|
|
|
|
|
|
|
status = DispatchEvent(&event);
|
|
|
|
break;
|
2010-06-28 23:42:28 -07:00
|
|
|
}
|
2010-06-25 17:52:37 -07: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-28 23:42:28 -07:00
|
|
|
!mChildren[i]->mBounds.Intersects(boundsRect)) {
|
2010-06-25 17:52:37 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetSurface)
|
|
|
|
targetSurface->SetDeviceOffset(offset + gfxPoint(mChildren[i]->mBounds.x,
|
|
|
|
mChildren[i]->mBounds.y));
|
|
|
|
|
|
|
|
PRBool ok = mChildren[i]->DrawTo(targetSurface);
|
|
|
|
|
|
|
|
if (!ok) {
|
2010-06-03 13:56:36 -07:00
|
|
|
ALOG("nsWindow[%p]::DrawTo child %d[%p] returned FALSE!", (void*) this, i, (void*)mChildren[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
if (targetSurface)
|
|
|
|
targetSurface->SetDeviceOffset(offset);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-11-08 18:11:13 -08:00
|
|
|
AndroidBridge::AutoLocalJNIFrame jniFrame;
|
|
|
|
|
|
|
|
AndroidGeckoSurfaceView& sview(AndroidBridge::Bridge()->SurfaceView());
|
|
|
|
|
|
|
|
NS_ASSERTION(!sview.isNull(), "SurfaceView is null!");
|
|
|
|
|
2010-11-12 12:02:14 -08:00
|
|
|
AndroidBridge::Bridge()->HideProgressDialogOnce();
|
|
|
|
|
2010-12-06 18:05:52 -08:00
|
|
|
if (GetLayerManager(nsnull)->GetBackendType() == LayerManager::LAYERS_BASIC) {
|
2010-06-28 23:42:28 -07:00
|
|
|
jobject bytebuf = sview.GetSoftwareDrawBuffer();
|
|
|
|
if (!bytebuf) {
|
|
|
|
ALOG("no buffer to draw into - skipping draw");
|
|
|
|
return;
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-06-28 23:42:28 -07:00
|
|
|
void *buf = AndroidBridge::JNI()->GetDirectBufferAddress(bytebuf);
|
|
|
|
int cap = AndroidBridge::JNI()->GetDirectBufferCapacity(bytebuf);
|
2010-11-08 18:11:13 -08: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);
|
2010-06-03 13:56:36 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-06-25 17:52:37 -07:00
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> targetSurface =
|
2010-06-28 23:42:28 -07:00
|
|
|
new gfxImageSurface((unsigned char *)buf,
|
2010-06-03 13:56:36 -07:00
|
|
|
gfxIntSize(mBounds.width, mBounds.height),
|
2010-06-28 23:42:28 -07:00
|
|
|
mBounds.width * 2,
|
|
|
|
gfxASurface::ImageFormatRGB16_565);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
DrawTo(targetSurface);
|
2010-11-08 18:11:13 -08:00
|
|
|
sview.Draw2D(bytebuf, mBounds.width * 2);
|
2010-06-28 23:42:28 -07:00
|
|
|
} else {
|
|
|
|
int drawType = sview.BeginDrawing();
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-06-28 23:42:28 -07:00
|
|
|
if (drawType == AndroidGeckoSurfaceView::DRAW_ERROR) {
|
|
|
|
ALOG("##### BeginDrawing failed!");
|
|
|
|
return;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
2010-06-28 23:42:28 -07:00
|
|
|
|
2010-12-13 14:37:25 -08:00
|
|
|
if (!sValidSurface) {
|
|
|
|
sGLContext->RenewSurface();
|
|
|
|
sValidSurface = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
NS_ASSERTION(sGLContext, "Drawing with GLES without a GL context?");
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
DrawTo(nsnull);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-06-28 23:42:28 -07:00
|
|
|
sview.EndDrawing();
|
2010-06-03 13:56:36 -07: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);
|
|
|
|
|
|
|
|
nsSizeEvent event(PR_TRUE, NS_SIZE, this);
|
|
|
|
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 12:36:19 -08:00
|
|
|
nsWindow::GetAndroidScreenBounds()
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2010-11-24 10:22:40 -08:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
return ContentChild::GetSingleton()->GetScreenSize();
|
|
|
|
}
|
2011-01-14 12:36:19 -08:00
|
|
|
return gAndroidScreenBounds;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
nsWindow::GetNativeData(PRUint32 aDataType)
|
|
|
|
{
|
|
|
|
switch (aDataType) {
|
2010-06-25 17:52:37 -07:00
|
|
|
// used by GLContextProviderEGL, NULL is EGL_DEFAULT_DISPLAY
|
|
|
|
case NS_NATIVE_DISPLAY:
|
|
|
|
return NULL;
|
|
|
|
|
2010-06-03 13:56:36 -07: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint pt(ae->P0());
|
|
|
|
nsIntPoint offset = WidgetToScreenOffset();
|
|
|
|
|
|
|
|
//ALOG("#### motion pt: %d %d offset: %d %d", pt.x, pt.y, offset.x, offset.y);
|
|
|
|
|
|
|
|
pt.x -= offset.x;
|
|
|
|
pt.y -= offset.y;
|
|
|
|
|
|
|
|
// XXX possibly bound the range of pt here. some code may get confused.
|
|
|
|
|
|
|
|
send_again:
|
|
|
|
|
|
|
|
nsMouseEvent event(PR_TRUE,
|
|
|
|
msg, this,
|
|
|
|
nsMouseEvent::eReal, nsMouseEvent::eNormal);
|
|
|
|
InitEvent(event, &pt);
|
|
|
|
|
|
|
|
event.time = ae->Time();
|
2010-12-21 14:36:28 -08:00
|
|
|
event.isShift = !!(ae->MetaState() & AndroidKeyEvent::META_SHIFT_ON);
|
2010-10-16 05:15:54 -07:00
|
|
|
event.isControl = PR_FALSE;
|
2010-06-03 13:56:36 -07:00
|
|
|
event.isMeta = PR_FALSE;
|
2010-12-21 14:36:28 -08:00
|
|
|
event.isAlt = !!(ae->MetaState() & AndroidKeyEvent::META_ALT_ON);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
|
|
|
|
if (msg == NS_MOUSE_BUTTON_DOWN) {
|
|
|
|
msg = NS_MOUSE_MOVE;
|
|
|
|
goto send_again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-07 14:34:12 -07:00
|
|
|
static double
|
2010-08-25 22:52:08 -07:00
|
|
|
getDistance(const nsIntPoint &p1, const nsIntPoint &p2)
|
2010-07-07 14:34:12 -07:00
|
|
|
{
|
2010-08-25 22:52:08 -07:00
|
|
|
double deltaX = p2.x - p1.x;
|
|
|
|
double deltaY = p2.y - p1.y;
|
2010-07-07 14:34:12 -07:00
|
|
|
return sqrt(deltaX*deltaX + deltaY*deltaY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWindow::OnMultitouchEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2010-08-25 22:52:08 -07:00
|
|
|
PRUint32 msg = 0;
|
|
|
|
|
|
|
|
nsIntPoint midPoint;
|
|
|
|
midPoint.x = ((ae->P0().x + ae->P1().x) / 2);
|
|
|
|
midPoint.y = ((ae->P0().y + ae->P1().y) / 2);
|
|
|
|
nsIntPoint refPoint = midPoint - WidgetToScreenOffset();
|
|
|
|
|
|
|
|
double pinchDist = getDistance(ae->P0(), ae->P1());
|
|
|
|
double pinchDelta = 0;
|
2010-07-07 14:34:12 -07:00
|
|
|
|
|
|
|
switch (ae->Action() & AndroidMotionEvent::ACTION_MASK) {
|
|
|
|
case AndroidMotionEvent::ACTION_POINTER_DOWN:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY_START;
|
2010-08-25 22:52:08 -07: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-07 14:34:12 -07:00
|
|
|
break;
|
|
|
|
case AndroidMotionEvent::ACTION_POINTER_UP:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY;
|
2010-08-25 22:52:08 -07:00
|
|
|
pinchDelta = pinchDist - mStartDist;
|
|
|
|
mStartPoint = nsnull;
|
2010-07-07 14:34:12 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-25 22:52:08 -07:00
|
|
|
if (!mGestureFinished) {
|
|
|
|
DispatchGestureEvent(msg, 0, pinchDelta, refPoint, ae->Time());
|
|
|
|
|
|
|
|
// If the cumulative pinch delta goes past the threshold, treat this
|
|
|
|
// as a pinch only, and not a swipe.
|
2010-11-18 09:18:31 -08:00
|
|
|
if (fabs(pinchDist - mStartDist) > mSwipeMaxPinchDelta)
|
2010-08-25 22:52:08 -07: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 09:18:31 -08:00
|
|
|
if (swipeDistance > mSwipeMinDistance) {
|
2010-08-25 22:52:08 -07: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());
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
nsSimpleGestureEvent event(PR_TRUE, msg, this, direction, delta);
|
2010-07-07 14:34:12 -07:00
|
|
|
|
2010-12-21 14:36:28 -08:00
|
|
|
event.isShift = PR_FALSE;
|
2010-10-16 05:15:54 -07:00
|
|
|
event.isControl = PR_FALSE;
|
2010-07-07 14:34:12 -07:00
|
|
|
event.isMeta = PR_FALSE;
|
2010-12-21 14:36:28 -08:00
|
|
|
event.isAlt = PR_FALSE;
|
2010-08-25 22:52:08 -07:00
|
|
|
event.time = time;
|
|
|
|
event.refPoint = refPoint;
|
2010-07-07 14:34:12 -07:00
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
void
|
|
|
|
nsWindow::InitKeyEvent(nsKeyEvent& event, AndroidGeckoEvent& key)
|
|
|
|
{
|
|
|
|
switch (key.KeyCode()) {
|
|
|
|
case AndroidKeyEvent::KEYCODE_UNKNOWN:
|
|
|
|
case AndroidKeyEvent::KEYCODE_HOME:
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_BACK:
|
|
|
|
event.keyCode = NS_VK_ESCAPE;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_CALL:
|
|
|
|
case AndroidKeyEvent::KEYCODE_ENDCALL:
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_0:
|
|
|
|
case AndroidKeyEvent::KEYCODE_1:
|
|
|
|
case AndroidKeyEvent::KEYCODE_2:
|
|
|
|
case AndroidKeyEvent::KEYCODE_3:
|
|
|
|
case AndroidKeyEvent::KEYCODE_4:
|
|
|
|
case AndroidKeyEvent::KEYCODE_5:
|
|
|
|
case AndroidKeyEvent::KEYCODE_6:
|
|
|
|
case AndroidKeyEvent::KEYCODE_7:
|
|
|
|
case AndroidKeyEvent::KEYCODE_8:
|
|
|
|
case AndroidKeyEvent::KEYCODE_9:
|
|
|
|
event.keyCode = key.KeyCode() - AndroidKeyEvent::KEYCODE_0 + NS_VK_0;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_STAR:
|
|
|
|
event.keyCode = NS_VK_MULTIPLY;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_POUND:
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_DPAD_UP:
|
|
|
|
event.keyCode = NS_VK_UP;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_DPAD_DOWN:
|
|
|
|
event.keyCode = NS_VK_DOWN;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SOFT_LEFT:
|
|
|
|
case AndroidKeyEvent::KEYCODE_DPAD_LEFT:
|
|
|
|
event.keyCode = NS_VK_LEFT;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SOFT_RIGHT:
|
|
|
|
case AndroidKeyEvent::KEYCODE_DPAD_RIGHT:
|
|
|
|
event.keyCode = NS_VK_RIGHT;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_VOLUME_UP:
|
|
|
|
case AndroidKeyEvent::KEYCODE_VOLUME_DOWN:
|
|
|
|
case AndroidKeyEvent::KEYCODE_POWER:
|
|
|
|
case AndroidKeyEvent::KEYCODE_CAMERA:
|
|
|
|
case AndroidKeyEvent::KEYCODE_CLEAR:
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_A:
|
|
|
|
case AndroidKeyEvent::KEYCODE_B:
|
|
|
|
case AndroidKeyEvent::KEYCODE_C:
|
|
|
|
case AndroidKeyEvent::KEYCODE_D:
|
|
|
|
case AndroidKeyEvent::KEYCODE_E:
|
|
|
|
case AndroidKeyEvent::KEYCODE_F:
|
|
|
|
case AndroidKeyEvent::KEYCODE_G:
|
|
|
|
case AndroidKeyEvent::KEYCODE_H:
|
|
|
|
case AndroidKeyEvent::KEYCODE_I:
|
|
|
|
case AndroidKeyEvent::KEYCODE_J:
|
|
|
|
case AndroidKeyEvent::KEYCODE_K:
|
|
|
|
case AndroidKeyEvent::KEYCODE_L:
|
|
|
|
case AndroidKeyEvent::KEYCODE_M:
|
|
|
|
case AndroidKeyEvent::KEYCODE_N:
|
|
|
|
case AndroidKeyEvent::KEYCODE_O:
|
|
|
|
case AndroidKeyEvent::KEYCODE_P:
|
|
|
|
case AndroidKeyEvent::KEYCODE_Q:
|
|
|
|
case AndroidKeyEvent::KEYCODE_R:
|
|
|
|
case AndroidKeyEvent::KEYCODE_S:
|
|
|
|
case AndroidKeyEvent::KEYCODE_T:
|
|
|
|
case AndroidKeyEvent::KEYCODE_U:
|
|
|
|
case AndroidKeyEvent::KEYCODE_V:
|
|
|
|
case AndroidKeyEvent::KEYCODE_W:
|
|
|
|
case AndroidKeyEvent::KEYCODE_X:
|
|
|
|
case AndroidKeyEvent::KEYCODE_Y:
|
|
|
|
case AndroidKeyEvent::KEYCODE_Z:
|
|
|
|
event.keyCode = key.KeyCode() - AndroidKeyEvent::KEYCODE_A + NS_VK_A;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_COMMA:
|
|
|
|
event.keyCode = NS_VK_COMMA;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_PERIOD:
|
|
|
|
event.keyCode = NS_VK_PERIOD;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_ALT_LEFT:
|
|
|
|
case AndroidKeyEvent::KEYCODE_ALT_RIGHT:
|
|
|
|
case AndroidKeyEvent::KEYCODE_SHIFT_LEFT:
|
|
|
|
case AndroidKeyEvent::KEYCODE_SHIFT_RIGHT:
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_TAB:
|
|
|
|
event.keyCode = NS_VK_TAB;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SPACE:
|
|
|
|
event.keyCode = NS_VK_SPACE;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SYM:
|
|
|
|
case AndroidKeyEvent::KEYCODE_EXPLORER:
|
|
|
|
case AndroidKeyEvent::KEYCODE_ENVELOPE:
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_DPAD_CENTER:
|
|
|
|
case AndroidKeyEvent::KEYCODE_ENTER:
|
|
|
|
event.keyCode = NS_VK_RETURN;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_DEL:
|
|
|
|
event.keyCode = NS_VK_BACK;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_GRAVE:
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_MINUS:
|
|
|
|
event.keyCode = NS_VK_SUBTRACT;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_EQUALS:
|
|
|
|
event.keyCode = NS_VK_EQUALS;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_LEFT_BRACKET:
|
|
|
|
event.keyCode = NS_VK_OPEN_BRACKET;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_RIGHT_BRACKET:
|
|
|
|
event.keyCode = NS_VK_CLOSE_BRACKET;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_BACKSLASH:
|
|
|
|
event.keyCode = NS_VK_BACK_SLASH;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SEMICOLON:
|
|
|
|
event.keyCode = NS_VK_SEMICOLON;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_APOSTROPHE:
|
|
|
|
event.keyCode = NS_VK_QUOTE;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SLASH:
|
|
|
|
event.keyCode = NS_VK_SLASH;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_AT:
|
|
|
|
case AndroidKeyEvent::KEYCODE_NUM:
|
|
|
|
case AndroidKeyEvent::KEYCODE_HEADSETHOOK:
|
|
|
|
case AndroidKeyEvent::KEYCODE_FOCUS:
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_PLUS:
|
|
|
|
event.keyCode = NS_VK_ADD;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_MENU:
|
|
|
|
case AndroidKeyEvent::KEYCODE_NOTIFICATION:
|
|
|
|
case AndroidKeyEvent::KEYCODE_SEARCH:
|
|
|
|
case AndroidKeyEvent::KEYCODE_MEDIA_PLAY_PAUSE:
|
|
|
|
case AndroidKeyEvent::KEYCODE_MEDIA_STOP:
|
|
|
|
case AndroidKeyEvent::KEYCODE_MEDIA_NEXT:
|
|
|
|
case AndroidKeyEvent::KEYCODE_MEDIA_PREVIOUS:
|
|
|
|
case AndroidKeyEvent::KEYCODE_MEDIA_REWIND:
|
|
|
|
case AndroidKeyEvent::KEYCODE_MEDIA_FAST_FORWARD:
|
|
|
|
case AndroidKeyEvent::KEYCODE_MUTE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ALOG("Unknown key code!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-12-21 14:36:28 -08:00
|
|
|
// Android gives us \n, so filter out some control characters.
|
|
|
|
if (event.message == NS_KEY_PRESS &&
|
|
|
|
key.UnicodeChar() >= ' ') {
|
|
|
|
event.charCode = key.UnicodeChar();
|
|
|
|
if (key.UnicodeChar())
|
|
|
|
event.keyCode = 0;
|
|
|
|
}
|
|
|
|
event.isShift = !!(key.MetaState() & AndroidKeyEvent::META_SHIFT_ON);
|
2010-10-16 05:15:54 -07:00
|
|
|
event.isControl = gMenu;
|
2010-12-21 14:36:28 -08:00
|
|
|
event.isAlt = !!(key.MetaState() & AndroidKeyEvent::META_ALT_ON);
|
2010-06-03 13:56:36 -07:00
|
|
|
event.isMeta = PR_FALSE;
|
|
|
|
event.time = key.Time();
|
2010-10-16 05:15:54 -07:00
|
|
|
|
|
|
|
if (gMenu)
|
|
|
|
gMenuConsumed = PR_TRUE;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::HandleSpecialKey(AndroidGeckoEvent *ae)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> command;
|
|
|
|
PRBool isDown = ae->Action() == AndroidKeyEvent::ACTION_DOWN;
|
2010-11-12 15:58:29 -08:00
|
|
|
PRBool isLongPress = !!(ae->Flags() & AndroidKeyEvent::FLAG_LONG_PRESS);
|
2010-06-03 13:56:36 -07:00
|
|
|
PRBool doCommand = PR_FALSE;
|
|
|
|
PRUint32 keyCode = ae->KeyCode();
|
|
|
|
|
|
|
|
if (isDown) {
|
|
|
|
switch (keyCode) {
|
2010-11-12 15:58:29 -08:00
|
|
|
case AndroidKeyEvent::KEYCODE_BACK:
|
|
|
|
if (isLongPress) {
|
|
|
|
command = nsWidgetAtoms::Clear;
|
|
|
|
doCommand = PR_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2010-06-03 13:56:36 -07:00
|
|
|
case AndroidKeyEvent::KEYCODE_VOLUME_UP:
|
|
|
|
command = nsWidgetAtoms::VolumeUp;
|
|
|
|
doCommand = PR_TRUE;
|
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_VOLUME_DOWN:
|
|
|
|
command = nsWidgetAtoms::VolumeDown;
|
|
|
|
doCommand = PR_TRUE;
|
|
|
|
break;
|
2010-10-16 05:15:54 -07:00
|
|
|
case AndroidKeyEvent::KEYCODE_MENU:
|
|
|
|
gMenu = PR_TRUE;
|
2010-11-12 15:58:29 -08:00
|
|
|
gMenuConsumed = isLongPress;
|
2010-10-16 05:15:54 -07:00
|
|
|
break;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (keyCode) {
|
|
|
|
case AndroidKeyEvent::KEYCODE_BACK: {
|
|
|
|
nsKeyEvent pressEvent(PR_TRUE, NS_KEY_PRESS, this);
|
|
|
|
InitKeyEvent(pressEvent, *ae);
|
|
|
|
DispatchEvent(&pressEvent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case AndroidKeyEvent::KEYCODE_MENU:
|
2010-10-16 05:15:54 -07:00
|
|
|
gMenu = PR_FALSE;
|
|
|
|
if (!gMenuConsumed) {
|
|
|
|
command = nsWidgetAtoms::Menu;
|
|
|
|
doCommand = PR_TRUE;
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
break;
|
|
|
|
case AndroidKeyEvent::KEYCODE_SEARCH:
|
|
|
|
command = nsWidgetAtoms::Search;
|
|
|
|
doCommand = PR_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ALOG("Unknown special key code!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (doCommand) {
|
|
|
|
nsCommandEvent event(PR_TRUE, nsWidgetAtoms::onAppCommand, command, this);
|
|
|
|
InitEvent(event);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnKeyEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
nsTextEvent event(PR_TRUE, NS_TEXT_TEXT, this);
|
|
|
|
event.theText.Assign(ae->Characters());
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
ALOG("Unknown key action event!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-21 14:36:28 -08:00
|
|
|
bool firePress = ae->Action() == AndroidKeyEvent::ACTION_DOWN;
|
2010-06-03 13:56:36 -07: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-21 14:36:28 -08:00
|
|
|
firePress = false;
|
2010-06-03 13:56:36 -07: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-21 14:36:28 -08:00
|
|
|
nsEventStatus status;
|
2010-06-03 13:56:36 -07:00
|
|
|
nsKeyEvent event(PR_TRUE, msg, this);
|
|
|
|
InitKeyEvent(event, *ae);
|
2010-12-21 14:36:28 -08:00
|
|
|
DispatchEvent(&event, status);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-12-21 14:36:28 -08:00
|
|
|
if (!firePress)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsKeyEvent pressEvent(PR_TRUE, NS_KEY_PRESS, this);
|
|
|
|
InitKeyEvent(pressEvent, *ae);
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
pressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
#ifdef ANDROID_DEBUG_WIDGET
|
2010-12-21 14:36:28 -08: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-03 13:56:36 -07:00
|
|
|
#endif
|
2010-12-21 14:36:28 -08:00
|
|
|
DispatchEvent(&pressEvent);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2010-08-04 12:47:26 -07:00
|
|
|
#ifdef ANDROID_DEBUG_IME
|
|
|
|
#define ALOGIME(args...) ALOG(args)
|
|
|
|
#else
|
|
|
|
#define ALOGIME(args...)
|
|
|
|
#endif
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-08-04 12:47:26 -07:00
|
|
|
void
|
|
|
|
nsWindow::OnIMEAddRange(AndroidGeckoEvent *ae)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2010-08-04 12:47:26 -07: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-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnIMEEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
|
|
|
switch (ae->Action()) {
|
2010-08-04 12:47:26 -07:00
|
|
|
case AndroidGeckoEvent::IME_COMPOSITION_END:
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2010-08-04 12:47:26 -07:00
|
|
|
ALOGIME("IME: IME_COMPOSITION_END");
|
2010-06-03 13:56:36 -07:00
|
|
|
nsCompositionEvent event(PR_TRUE, NS_COMPOSITION_END, this);
|
2010-08-04 12:47:26 -07:00
|
|
|
InitEvent(event, nsnull);
|
2010-06-03 13:56:36 -07:00
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
return;
|
2010-08-04 12:47:26 -07:00
|
|
|
case AndroidGeckoEvent::IME_COMPOSITION_BEGIN:
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2010-08-04 12:47:26 -07:00
|
|
|
ALOGIME("IME: IME_COMPOSITION_BEGIN");
|
2010-06-03 13:56:36 -07:00
|
|
|
nsCompositionEvent event(PR_TRUE, NS_COMPOSITION_START, this);
|
2010-08-04 12:47:26 -07:00
|
|
|
InitEvent(event, nsnull);
|
2010-06-03 13:56:36 -07:00
|
|
|
DispatchEvent(&event);
|
2010-08-04 12:47:26 -07:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_ADD_RANGE:
|
|
|
|
{
|
|
|
|
OnIMEAddRange(ae);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_SET_TEXT:
|
|
|
|
{
|
2010-08-04 12:47:26 -07:00
|
|
|
OnIMEAddRange(ae);
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
nsTextEvent event(PR_TRUE, NS_TEXT_TEXT, this);
|
2010-08-04 12:47:26 -07:00
|
|
|
InitEvent(event, nsnull);
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
event.theText.Assign(ae->Characters());
|
2010-08-04 12:47:26 -07:00
|
|
|
event.rangeArray = mIMERanges.Elements();
|
|
|
|
event.rangeCount = mIMERanges.Length();
|
|
|
|
|
|
|
|
ALOGIME("IME: IME_SET_TEXT: l=%u, r=%u",
|
|
|
|
event.theText.Length(), mIMERanges.Length());
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
DispatchEvent(&event);
|
2010-08-04 12:47:26 -07:00
|
|
|
mIMERanges.Clear();
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_GET_TEXT:
|
|
|
|
{
|
2010-08-04 12:47:26 -07:00
|
|
|
ALOGIME("IME: IME_GET_TEXT: o=%u, l=%u", ae->Offset(), ae->Count());
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
nsQueryContentEvent event(PR_TRUE, NS_QUERY_TEXT_CONTENT, this);
|
2010-08-04 12:47:26 -07:00
|
|
|
InitEvent(event, nsnull);
|
|
|
|
|
|
|
|
event.InitForQueryTextContent(ae->Offset(), ae->Count());
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
DispatchEvent(&event);
|
|
|
|
|
|
|
|
if (!event.mSucceeded) {
|
2010-08-04 12:47:26 -07:00
|
|
|
ALOGIME("IME: -> failed");
|
|
|
|
AndroidBridge::Bridge()->ReturnIMEQueryResult(
|
|
|
|
nsnull, 0, 0, 0);
|
2010-06-03 13:56:36 -07:00
|
|
|
return;
|
2010-08-17 01:07:45 -07:00
|
|
|
} else if (!event.mWasAsync) {
|
|
|
|
AndroidBridge::Bridge()->ReturnIMEQueryResult(
|
|
|
|
event.mReply.mString.get(),
|
|
|
|
event.mReply.mString.Length(), 0, 0);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
2010-08-04 12:47:26 -07:00
|
|
|
//ALOGIME("IME: -> l=%u", event.mReply.mString.Length());
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_DELETE_TEXT:
|
2010-08-04 12:47:26 -07:00
|
|
|
{
|
|
|
|
ALOGIME("IME: IME_DELETE_TEXT");
|
2010-08-17 16:52:00 -07:00
|
|
|
nsKeyEvent event(PR_TRUE, NS_KEY_PRESS, this);
|
2010-08-04 12:47:26 -07:00
|
|
|
InitEvent(event, nsnull);
|
2010-08-17 16:52:00 -07:00
|
|
|
event.keyCode = NS_VK_BACK;
|
2010-08-04 12:47:26 -07:00
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_SET_SELECTION:
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2010-08-04 12:47:26 -07:00
|
|
|
ALOGIME("IME: IME_SET_SELECTION: o=%u, l=%d", ae->Offset(), ae->Count());
|
|
|
|
|
|
|
|
nsSelectionEvent selEvent(PR_TRUE, NS_SELECTION_SET, this);
|
|
|
|
InitEvent(selEvent, nsnull);
|
|
|
|
|
|
|
|
selEvent.mOffset = PRUint32(ae->Count() >= 0 ?
|
|
|
|
ae->Offset() :
|
|
|
|
ae->Offset() + ae->Count());
|
|
|
|
selEvent.mLength = PRUint32(PR_ABS(ae->Count()));
|
|
|
|
selEvent.mReversed = ae->Count() >= 0 ? PR_FALSE : PR_TRUE;
|
|
|
|
|
|
|
|
DispatchEvent(&selEvent);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case AndroidGeckoEvent::IME_GET_SELECTION:
|
|
|
|
{
|
|
|
|
ALOGIME("IME: IME_GET_SELECTION");
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-08-04 12:47:26 -07:00
|
|
|
nsQueryContentEvent event(PR_TRUE, NS_QUERY_SELECTED_TEXT, this);
|
|
|
|
InitEvent(event, nsnull);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
|
|
|
|
if (!event.mSucceeded) {
|
|
|
|
ALOGIME("IME: -> failed");
|
|
|
|
AndroidBridge::Bridge()->ReturnIMEQueryResult(
|
|
|
|
nsnull, 0, 0, 0);
|
|
|
|
return;
|
2010-08-17 01:07:45 -07:00
|
|
|
} else if (!event.mWasAsync) {
|
|
|
|
AndroidBridge::Bridge()->ReturnIMEQueryResult(
|
|
|
|
event.mReply.mString.get(),
|
|
|
|
event.mReply.mString.Length(),
|
|
|
|
event.GetSelectionStart(),
|
|
|
|
event.GetSelectionEnd() - event.GetSelectionStart());
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
2010-08-04 12:47:26 -07:00
|
|
|
//ALOGIME("IME: -> o=%u, l=%u", event.mReply.mOffset, event.mReply.mString.Length());
|
2010-06-03 13:56:36 -07: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 12:47:26 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ResetInputState()
|
|
|
|
{
|
|
|
|
//ALOGIME("IME: ResetInputState: s=%d", aState);
|
|
|
|
|
|
|
|
// Cancel composition on Gecko side
|
|
|
|
if (mIMEComposing) {
|
2010-08-20 17:07:26 -07:00
|
|
|
nsTextEvent textEvent(PR_TRUE, NS_TEXT_TEXT, this);
|
|
|
|
InitEvent(textEvent, nsnull);
|
|
|
|
textEvent.theText = mIMEComposingText;
|
|
|
|
DispatchEvent(&textEvent);
|
2010-09-23 20:59:26 -07:00
|
|
|
mIMEComposingText.Truncate(0);
|
2010-08-20 17:07:26 -07:00
|
|
|
|
2010-08-04 12:47:26 -07:00
|
|
|
nsCompositionEvent event(PR_TRUE, NS_COMPOSITION_END, this);
|
|
|
|
InitEvent(event, nsnull);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2010-08-05 11:11:32 -07:00
|
|
|
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_RESETINPUTSTATE, 0);
|
2010-08-04 12:47:26 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
NS_IMETHODIMP
|
2010-11-22 22:48:03 -08:00
|
|
|
nsWindow::SetInputMode(const IMEContext& aContext)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2010-11-22 22:48:03 -08:00
|
|
|
ALOGIME("IME: SetInputMode: s=%d", aContext.mStatus);
|
2010-08-04 12:47:26 -07:00
|
|
|
|
2010-11-22 22:48:45 -08:00
|
|
|
mIMEContext = aContext;
|
2010-11-23 18:12:53 -08:00
|
|
|
AndroidBridge::NotifyIMEEnabled(int(aContext.mStatus), aContext.mHTMLInputType, aContext.mActionHint);
|
2010-06-03 13:56:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-11-22 22:48:45 -08:00
|
|
|
nsWindow::GetInputMode(IMEContext& aContext)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2010-11-22 22:48:45 -08:00
|
|
|
aContext = mIMEContext;
|
2010-08-04 12:47:26 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::CancelIMEComposition()
|
|
|
|
{
|
|
|
|
ALOGIME("IME: CancelIMEComposition");
|
|
|
|
|
|
|
|
// Cancel composition on Gecko side
|
|
|
|
if (mIMEComposing) {
|
|
|
|
nsTextEvent textEvent(PR_TRUE, NS_TEXT_TEXT, this);
|
|
|
|
InitEvent(textEvent, nsnull);
|
|
|
|
DispatchEvent(&textEvent);
|
2010-09-23 20:59:26 -07:00
|
|
|
mIMEComposingText.Truncate(0);
|
2010-08-04 12:47:26 -07:00
|
|
|
|
|
|
|
nsCompositionEvent compEvent(PR_TRUE, NS_COMPOSITION_END, this);
|
|
|
|
InitEvent(compEvent, nsnull);
|
|
|
|
DispatchEvent(&compEvent);
|
|
|
|
}
|
|
|
|
|
2010-08-05 11:11:32 -07:00
|
|
|
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_CANCELCOMPOSITION, 0);
|
2010-08-04 12:47:26 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::OnIMEFocusChange(PRBool aFocus)
|
|
|
|
{
|
|
|
|
ALOGIME("IME: OnIMEFocusChange: f=%d", aFocus);
|
2010-08-17 01:07:45 -07:00
|
|
|
|
|
|
|
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_FOCUSCHANGE,
|
|
|
|
int(aFocus));
|
2010-11-24 14:09:24 -08:00
|
|
|
|
|
|
|
if (aFocus) {
|
|
|
|
OnIMETextChange(0, 0, 0);
|
|
|
|
OnIMESelectionChange();
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-08-04 12:47:26 -07: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-24 14:09:24 -08: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 12:47:26 -07:00
|
|
|
|
2010-11-24 14:09:24 -08:00
|
|
|
nsQueryContentEvent event(PR_TRUE, NS_QUERY_TEXT_CONTENT, this);
|
|
|
|
InitEvent(event, nsnull);
|
|
|
|
event.InitForQueryTextContent(0, PR_UINT32_MAX);
|
2010-08-04 12:47:26 -07:00
|
|
|
|
2010-11-24 14:09:24 -08: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 12:47:26 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::OnIMESelectionChange(void)
|
|
|
|
{
|
|
|
|
ALOGIME("IME: OnIMESelectionChange");
|
|
|
|
|
|
|
|
nsQueryContentEvent event(PR_TRUE, NS_QUERY_SELECTED_TEXT, this);
|
|
|
|
InitEvent(event, nsnull);
|
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
if (!event.mSucceeded)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-08-05 11:11:32 -07:00
|
|
|
AndroidBridge::NotifyIMEChange(nsnull, 0, int(event.mReply.mOffset),
|
|
|
|
int(event.mReply.mOffset +
|
|
|
|
event.mReply.mString.Length()), -1);
|
2010-08-04 12:47:26 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-23 20:28:15 -07:00
|
|
|
nsIMEUpdatePreference
|
|
|
|
nsWindow::GetIMEUpdatePreference()
|
|
|
|
{
|
|
|
|
return nsIMEUpdatePreference(PR_TRUE, PR_TRUE);
|
|
|
|
}
|
|
|
|
|