2010-11-24 10:22:40 -08:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07: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-03 13:56:36 -07:00
|
|
|
|
|
|
|
#include <android/log.h>
|
2010-08-25 22:52:08 -07:00
|
|
|
#include <math.h>
|
2011-12-21 11:05:23 -08:00
|
|
|
#include <unistd.h>
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/MiscEvents.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-09-25 04:21:16 -07:00
|
|
|
#include "mozilla/TouchEvents.h"
|
|
|
|
|
2010-11-24 10:22:40 -08:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
#include "mozilla/unused.h"
|
2011-06-07 00:38:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-02-27 11:31:29 -08:00
|
|
|
#include "mozilla/layers/RenderTrace.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2010-11-24 10:22:40 -08:00
|
|
|
|
|
|
|
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"
|
2011-11-08 11:58:37 -08:00
|
|
|
#include "nsFocusManager.h"
|
2012-08-15 11:52:42 -07:00
|
|
|
#include "nsIWidgetListener.h"
|
2013-01-04 19:12:24 -08:00
|
|
|
#include "nsViewManager.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
|
|
|
|
2011-10-14 11:11:22 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
#include "Layers.h"
|
2013-04-25 15:25:33 -07:00
|
|
|
#include "mozilla/layers/LayerManagerComposite.h"
|
2013-04-27 23:46:30 -07:00
|
|
|
#include "mozilla/layers/AsyncCompositionManager.h"
|
2013-08-20 16:00:57 -07:00
|
|
|
#include "mozilla/layers/APZCTreeManager.h"
|
2010-06-25 17:52:37 -07:00
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
2014-01-07 12:02:18 -08:00
|
|
|
#include "ScopedGLHelpers.h"
|
|
|
|
#include "mozilla/layers/CompositorOGL.h"
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
#include "AndroidBridge.h"
|
2013-11-12 10:41:01 -08:00
|
|
|
#include "AndroidBridgeUtilities.h"
|
2012-04-19 10:49:31 -07:00
|
|
|
#include "android_npapi.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-10-10 17:40:17 -07:00
|
|
|
#include "imgIEncoder.h"
|
|
|
|
|
2013-09-23 10:25:00 -07:00
|
|
|
#include "nsString.h"
|
2013-09-23 06:33:31 -07:00
|
|
|
#include "GeckoProfiler.h" // For PROFILER_LABEL
|
2011-11-09 17:39:29 -08:00
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
using namespace mozilla;
|
2013-04-05 01:49:00 -07:00
|
|
|
using namespace mozilla::dom;
|
2011-11-27 03:51:52 -08:00
|
|
|
using namespace mozilla::widget;
|
2013-04-26 10:24:28 -07:00
|
|
|
using namespace mozilla::layers;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
|
|
|
|
|
|
|
|
// The dimensions of the current android view
|
2011-12-15 15:45:52 -08:00
|
|
|
static gfxIntSize gAndroidBounds = gfxIntSize(0, 0);
|
2011-01-14 12:36:19 -08:00
|
|
|
static gfxIntSize gAndroidScreenBounds;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2013-04-17 14:39:13 -07:00
|
|
|
#include "mozilla/layers/AsyncPanZoomController.h"
|
2012-03-13 21:15:11 -07:00
|
|
|
#include "mozilla/layers/CompositorChild.h"
|
|
|
|
#include "mozilla/layers/CompositorParent.h"
|
2013-04-24 11:42:40 -07:00
|
|
|
#include "mozilla/layers/LayerTransactionParent.h"
|
2011-12-21 11:05:23 -08:00
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
2010-11-24 10:22:40 -08:00
|
|
|
class ContentCreationNotifier;
|
2013-08-13 06:31:32 -07:00
|
|
|
static StaticRefPtr<ContentCreationNotifier> gContentCreationNotifier;
|
2013-05-30 11:26:02 -07:00
|
|
|
|
2010-11-24 10:22:40 -08:00
|
|
|
// A helper class to send updates when content processes
|
|
|
|
// are created. Currently an update for the screen size is sent.
|
2013-05-30 11:26:02 -07:00
|
|
|
class ContentCreationNotifier MOZ_FINAL : public nsIObserver
|
2010-11-24 10:22:40 -08:00
|
|
|
{
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aData)
|
2010-11-24 10:22:40 -08:00
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "ipc:content-created")) {
|
2011-08-02 12:35:42 -07:00
|
|
|
nsCOMPtr<nsIObserver> cpo = do_QueryInterface(aSubject);
|
|
|
|
ContentParent* cp = static_cast<ContentParent*>(cpo.get());
|
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");
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
gContentCreationNotifier = nullptr;
|
2010-11-24 10:22:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(ContentCreationNotifier,
|
|
|
|
nsIObserver)
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool gMenu;
|
|
|
|
static bool 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-09-08 15:19:11 -07:00
|
|
|
static bool sFailedToCreateGLContext = false;
|
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
|
|
|
|
2012-04-20 09:49:50 -07:00
|
|
|
nsWindow*
|
|
|
|
nsWindow::TopWindow()
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
if (!gTopLevelWindows.IsEmpty())
|
|
|
|
return gTopLevelWindows[0];
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::LogWindow(nsWindow *win, int index, int indent)
|
|
|
|
{
|
2013-01-25 11:33:40 -08:00
|
|
|
#if defined(DEBUG) || defined(FORCE_ALOG)
|
2010-06-03 13:56:36 -07:00
|
|
|
char spaces[] = " ";
|
|
|
|
spaces[indent < 20 ? indent : 20] = 0;
|
2012-05-26 08:07:24 -07:00
|
|
|
ALOG("%s [% 2d] 0x%08x [parent 0x%08x] [% 3d,% 3dx% 3d,% 3d] vis %d type %d",
|
2010-06-03 13:56:36 -07:00
|
|
|
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);
|
2013-01-25 11:33:40 -08:00
|
|
|
#endif
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DumpWindows()
|
|
|
|
{
|
|
|
|
DumpWindows(gTopLevelWindows);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DumpWindows(const nsTArray<nsWindow*>& wins, int indent)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t 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() :
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsVisible(false),
|
2012-07-30 07:20:58 -07:00
|
|
|
mParent(nullptr),
|
|
|
|
mFocus(nullptr),
|
2012-11-01 13:11:02 -07:00
|
|
|
mIMEComposing(false),
|
|
|
|
mIMEMaskSelectionUpdate(false),
|
2012-11-13 14:27:19 -08:00
|
|
|
mIMEMaskTextUpdate(false),
|
2013-01-09 08:57:48 -08:00
|
|
|
mIMEMaskEventsCount(1), // Mask IME events since there's no focus yet
|
2013-03-05 07:24:35 -08:00
|
|
|
mIMEUpdatingContext(false),
|
2013-01-09 08:57:48 -08:00
|
|
|
mIMESelectionChanged(false)
|
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)
|
2012-07-30 07:20:58 -07:00
|
|
|
top->mFocus = nullptr;
|
2010-06-03 13:56:36 -07:00
|
|
|
ALOG("nsWindow %p destructor", (void*)this);
|
2013-01-10 08:21:10 -08:00
|
|
|
if (mLayerManager == sLayerManager) {
|
|
|
|
// If this window was the one that created the global OMTC layer manager
|
|
|
|
// and compositor, then we should null those out.
|
2013-10-10 13:42:52 -07:00
|
|
|
SetCompositor(nullptr, nullptr, nullptr);
|
2013-01-10 08:21:10 -08:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-06-03 13:56:36 -07:00
|
|
|
nsWindow::IsTopLevel()
|
|
|
|
{
|
|
|
|
return mWindowType == eWindowType_toplevel ||
|
|
|
|
mWindowType == eWindowType_dialog ||
|
|
|
|
mWindowType == eWindowType_invisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *aContext,
|
2010-06-03 13:56:36 -07: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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:53:09 -07:00
|
|
|
BaseCreate(nullptr, mBounds, aContext, aInitData);
|
2010-06-03 13:56:36 -07: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;
|
|
|
|
}
|
|
|
|
|
2012-12-21 08:33:28 -08:00
|
|
|
#ifdef DEBUG_ANDROID_WIDGET
|
|
|
|
DumpWindows();
|
|
|
|
#endif
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Destroy(void)
|
|
|
|
{
|
2011-11-22 12:31:49 -08:00
|
|
|
nsBaseWidget::mOnDestroyCalled = true;
|
|
|
|
|
2012-05-26 08:06:25 -07:00
|
|
|
while (mChildren.Length()) {
|
2010-06-03 13:56:36 -07:00
|
|
|
// why do we still have children?
|
2012-05-26 08:06:25 -07:00
|
|
|
ALOG("### Warning: Destroying window %p and reparenting child %p to null!", (void*)this, (void*)mChildren[0]);
|
2012-07-30 07:20:58 -07:00
|
|
|
mChildren[0]->SetParent(nullptr);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsTopLevel())
|
|
|
|
gTopLevelWindows.RemoveElement(this);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
SetParent(nullptr);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-11-22 12:29:54 -08:00
|
|
|
nsBaseWidget::OnDestroy();
|
|
|
|
|
2012-12-21 08:33:28 -08:00
|
|
|
#ifdef DEBUG_ANDROID_WIDGET
|
|
|
|
DumpWindows();
|
|
|
|
#endif
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ConfigureChildren(const nsTArray<nsIWidget::Configuration>& config)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < config.Length(); ++i) {
|
2010-06-03 13:56:36 -07:00
|
|
|
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 07:59:28 -07:00
|
|
|
false);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-09 17:39:29 -08:00
|
|
|
void
|
|
|
|
nsWindow::RedrawAll()
|
|
|
|
{
|
2012-09-04 15:06:22 -07:00
|
|
|
if (mFocus && mFocus->mWidgetListener) {
|
2012-12-17 19:42:02 -08:00
|
|
|
mFocus->mWidgetListener->RequestRepaint();
|
2012-09-04 15:06:22 -07:00
|
|
|
}
|
2011-11-09 17:39:29 -08:00
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07: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
|
2012-05-26 08:07:24 -07:00
|
|
|
// children.
|
2010-06-03 13:56:36 -07:00
|
|
|
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 09:49:50 -07:00
|
|
|
if (FindTopLevel() == nsWindow::TopWindow())
|
2011-11-09 17:39:29 -08:00
|
|
|
RedrawAll();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-04 06:02:29 -07:00
|
|
|
double
|
|
|
|
nsWindow::GetDefaultScaleInternal()
|
|
|
|
{
|
2013-09-17 17:45:03 -07:00
|
|
|
static double density = 0.0;
|
|
|
|
|
|
|
|
if (density != 0.0) {
|
|
|
|
return density;
|
2013-07-04 06:02:29 -07:00
|
|
|
}
|
2013-09-17 17:45:03 -07:00
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
density = GeckoAppShell::GetDensity();
|
2013-09-17 17:45:03 -07:00
|
|
|
|
|
|
|
if (!density) {
|
|
|
|
density = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return density;
|
2013-07-04 06:02:29 -07:00
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::Show(bool aState)
|
2010-06-03 13:56:36 -07: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-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.
|
2011-10-17 07:59:28 -07:00
|
|
|
Resize(0, 0, gAndroidBounds.width, gAndroidBounds.height, false);
|
2011-02-14 17:01:01 -08:00
|
|
|
BringToFront();
|
2012-04-20 09:49:50 -07:00
|
|
|
} else if (nsWindow::TopWindow() == this) {
|
2011-02-14 17:01:01 -08:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
2012-04-20 09:49:50 -07:00
|
|
|
} else if (FindTopLevel() == nsWindow::TopWindow()) {
|
2011-11-09 17:39:29 -08:00
|
|
|
RedrawAll();
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-08-29 11:29:39 -07:00
|
|
|
#ifdef DEBUG_ANDROID_WIDGET
|
2010-06-03 13:56:36 -07:00
|
|
|
DumpWindows();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::SetModal(bool aState)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::SetModal %d ignored", (void*)this, aState);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-19 01:57:50 -07:00
|
|
|
bool
|
|
|
|
nsWindow::IsVisible() const
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-07-19 01:57:50 -07:00
|
|
|
return mIsVisible;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::ConstrainPosition(bool aAllowSlop,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t *aX,
|
|
|
|
int32_t *aY)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
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
|
2012-12-12 01:57:38 -08:00
|
|
|
nsWindow::Move(double aX,
|
|
|
|
double aY)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
if (IsTopLevel())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return Resize(aX,
|
|
|
|
aY,
|
|
|
|
mBounds.width,
|
|
|
|
mBounds.height,
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-12 01:57:38 -08:00
|
|
|
nsWindow::Resize(double aWidth,
|
|
|
|
double aHeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRepaint)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
return Resize(mBounds.x,
|
|
|
|
mBounds.y,
|
|
|
|
aWidth,
|
|
|
|
aHeight,
|
|
|
|
aRepaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-12 01:57:38 -08:00
|
|
|
nsWindow::Resize(double aX,
|
|
|
|
double aY,
|
|
|
|
double aWidth,
|
|
|
|
double aHeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRepaint)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-12-12 01:57:38 -08:00
|
|
|
ALOG("nsWindow[%p]::Resize [%f %f %f %f] (repaint %d)", (void*)this, aX, aY, aWidth, aHeight, aRepaint);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool needSizeDispatch = aWidth != mBounds.width || aHeight != mBounds.height;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
mBounds.x = NSToIntRound(aX);
|
|
|
|
mBounds.y = NSToIntRound(aY);
|
|
|
|
mBounds.width = NSToIntRound(aWidth);
|
|
|
|
mBounds.height = NSToIntRound(aHeight);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
if (needSizeDispatch)
|
|
|
|
OnSizeChanged(gfxIntSize(aWidth, aHeight));
|
|
|
|
|
|
|
|
// Should we skip honoring aRepaint here?
|
2012-04-20 09:49:50 -07:00
|
|
|
if (aRepaint && FindTopLevel() == nsWindow::TopWindow())
|
2011-11-09 17:39:29 -08:00
|
|
|
RedrawAll();
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::SetZIndex(int32_t aZIndex)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::SetZIndex %d ignored", (void*)this, aZIndex);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aActivate)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::SetSizeMode(int32_t aMode)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2010-06-16 10:20:54 -07:00
|
|
|
switch (aMode) {
|
|
|
|
case nsSizeMode_Minimized:
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::MoveTaskToBack();
|
2010-06-16 10:20:54 -07:00
|
|
|
break;
|
2010-11-08 18:11:13 -08:00
|
|
|
case nsSizeMode_Fullscreen:
|
2011-10-17 07:59:28 -07:00
|
|
|
MakeFullScreen(true);
|
2010-11-08 18:11:13 -08:00
|
|
|
break;
|
2010-06-16 10:20:54 -07:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::Enable(bool aState)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
ALOG("nsWindow[%p]::Enable %d ignored", (void*)this, aState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-22 22:19:08 -07:00
|
|
|
bool
|
|
|
|
nsWindow::IsEnabled() const
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-07-22 22:19:08 -07:00
|
|
|
return true;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-12-23 19:52:21 -08:00
|
|
|
nsWindow::Invalidate(const nsIntRect &aRect)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2013-04-17 14:39:12 -07:00
|
|
|
AndroidGeckoEvent *event = AndroidGeckoEvent::MakeDrawEvent(aRect);
|
2011-11-09 17:39:29 -08:00
|
|
|
nsAppShell::gAppShell->PostEvent(event);
|
2010-06-03 13:56:36 -07: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-28 23:19:26 -07:00
|
|
|
nsWindow::SetFocus(bool aRaise)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-07-30 17:42:26 -07:00
|
|
|
if (!aRaise) {
|
2010-06-03 13:56:36 -07:00
|
|
|
ALOG("nsWindow::SetFocus: can't set focus without raising, ignoring aRaise = false!");
|
2012-07-30 17:42:26 -07:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
|
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()
|
|
|
|
{
|
2011-11-08 11:58:37 -08: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 09:49:50 -07:00
|
|
|
if (existingTopWindow && FindTopLevel() == nsWindow::TopWindow())
|
2010-06-03 13:56:36 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!IsTopLevel()) {
|
|
|
|
FindTopLevel()->BringToFront();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-22 12:31:49 -08:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsWindow *oldTop = nullptr;
|
2011-11-22 12:31:49 -08:00
|
|
|
nsWindow *newTop = this;
|
2010-06-03 13:56:36 -07:00
|
|
|
if (!gTopLevelWindows.IsEmpty())
|
|
|
|
oldTop = gTopLevelWindows[0];
|
|
|
|
|
|
|
|
gTopLevelWindows.RemoveElement(this);
|
|
|
|
gTopLevelWindows.InsertElementAt(0, this);
|
|
|
|
|
|
|
|
if (oldTop) {
|
2012-08-15 11:52:42 -07:00
|
|
|
nsIWidgetListener* listener = oldTop->GetWidgetListener();
|
|
|
|
if (listener) {
|
|
|
|
listener->WindowDeactivated();
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-11-22 12:31:49 -08: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];
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener) {
|
|
|
|
mWidgetListener->WindowActivated();
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-08-09 09:08:19 -07:00
|
|
|
// force a window resize
|
2011-11-22 12:31:49 -08:00
|
|
|
nsAppShell::gAppShell->ResendLastResizeEvent(newTop);
|
2011-11-09 17:39:29 -08:00
|
|
|
RedrawAll();
|
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
|
2013-10-01 20:46:03 -07:00
|
|
|
nsWindow::DispatchEvent(WidgetGUIEvent* aEvent,
|
2010-06-03 13:56:36 -07:00
|
|
|
nsEventStatus &aStatus)
|
|
|
|
{
|
|
|
|
aStatus = DispatchEvent(aEvent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
2013-10-01 20:46:03 -07:00
|
|
|
nsWindow::DispatchEvent(WidgetGUIEvent* aEvent)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-08-15 11:53:09 -07:00
|
|
|
if (mWidgetListener) {
|
|
|
|
nsEventStatus status = mWidgetListener->HandleEvent(aEvent, mUseAttachedEvents);
|
2010-08-20 17:07:26 -07:00
|
|
|
|
2010-09-23 20:59:26 -07:00
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_COMPOSITION_START:
|
2012-11-01 13:11:02 -07:00
|
|
|
MOZ_ASSERT(!mIMEComposing);
|
2011-10-17 07:59:28 -07:00
|
|
|
mIMEComposing = true;
|
2010-09-23 20:59:26 -07:00
|
|
|
break;
|
|
|
|
case NS_COMPOSITION_END:
|
2012-11-01 13:11:02 -07:00
|
|
|
MOZ_ASSERT(mIMEComposing);
|
2011-10-17 07:59:28 -07:00
|
|
|
mIMEComposing = false;
|
2012-11-01 13:11:02 -07:00
|
|
|
mIMEComposingText.Truncate();
|
2010-09-23 20:59:26 -07:00
|
|
|
break;
|
|
|
|
case NS_TEXT_TEXT:
|
2012-11-01 13:11:02 -07:00
|
|
|
MOZ_ASSERT(mIMEComposing);
|
2013-10-17 23:10:24 -07:00
|
|
|
mIMEComposingText = aEvent->AsTextEvent()->theText;
|
2010-09-23 20:59:26 -07:00
|
|
|
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
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::MakeFullScreen(bool aFullScreen)
|
2010-11-08 18:11:13 -08:00
|
|
|
{
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::SetFullScreen(aFullScreen);
|
2010-11-08 18:11:13 -08:00
|
|
|
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*
|
2013-04-24 11:42:40 -07:00
|
|
|
nsWindow::GetLayerManager(PLayerTransactionChild*, LayersBackend, LayerManagerPersistence,
|
2011-08-12 07:12:03 -07:00
|
|
|
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;
|
|
|
|
}
|
2013-02-28 10:28:23 -08:00
|
|
|
// for OMTC allow use of the single layer manager/compositor
|
|
|
|
// shared across all windows
|
2013-03-04 10:32:20 -08:00
|
|
|
if (ShouldUseOffMainThreadCompositing()) {
|
2013-02-28 10:28:23 -08:00
|
|
|
return sLayerManager;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-20 15:45:07 -07:00
|
|
|
nsWindow::CreateLayerManager(int aCompositorWidth, int aCompositorHeight)
|
2013-02-28 10:28:23 -08:00
|
|
|
{
|
|
|
|
if (mLayerManager) {
|
|
|
|
return;
|
|
|
|
}
|
2010-09-08 15:19:11 -07:00
|
|
|
|
2012-12-21 08:33:28 -08:00
|
|
|
nsWindow *topLevelWindow = FindTopLevel();
|
|
|
|
if (!topLevelWindow || topLevelWindow->mWindowType == eWindowType_invisible) {
|
|
|
|
// don't create a layer manager for an invisible top-level window
|
2013-02-28 10:28:23 -08:00
|
|
|
return;
|
2010-09-08 15:19:11 -07:00
|
|
|
}
|
2012-06-13 12:54:02 -07:00
|
|
|
|
2012-11-15 10:55:15 -08:00
|
|
|
mUseLayersAcceleration = ComputeShouldAccelerate(mUseLayersAcceleration);
|
2012-06-13 12:54:02 -07:00
|
|
|
|
2013-03-04 10:32:20 -08:00
|
|
|
if (ShouldUseOffMainThreadCompositing()) {
|
2013-01-10 08:21:10 -08:00
|
|
|
if (sLayerManager) {
|
2013-02-28 10:28:23 -08:00
|
|
|
return;
|
2013-01-10 08:21:10 -08:00
|
|
|
}
|
2013-03-20 15:45:07 -07:00
|
|
|
CreateCompositor(aCompositorWidth, aCompositorHeight);
|
2012-02-03 18:35:58 -08:00
|
|
|
if (mLayerManager) {
|
2013-01-10 08:21:10 -08:00
|
|
|
// for OMTC create a single layer manager and compositor that will be
|
|
|
|
// used for all windows.
|
|
|
|
SetCompositor(mLayerManager, mCompositorParent, mCompositorChild);
|
2013-03-20 15:45:07 -07:00
|
|
|
sCompositorPaused = false;
|
2013-02-28 10:28:23 -08:00
|
|
|
return;
|
2012-02-03 18:35:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here, then off main thread compositing failed to initialize.
|
2012-02-02 11:16:59 -08:00
|
|
|
sFailedToCreateGLContext = true;
|
2012-02-01 11:15:52 -08:00
|
|
|
}
|
2010-09-08 15:19:11 -07:00
|
|
|
|
2013-02-28 10:28:23 -08:00
|
|
|
if (!mUseLayersAcceleration || sFailedToCreateGLContext) {
|
2010-09-08 15:19:11 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
void
|
|
|
|
nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
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()) {
|
2011-08-09 09:08:19 -07:00
|
|
|
case AndroidGeckoEvent::FORCED_RESIZE:
|
|
|
|
win->mBounds.width = 0;
|
|
|
|
win->mBounds.height = 0;
|
|
|
|
// also resize the children
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < win->mChildren.Length(); i++) {
|
2011-08-09 09:08:19 -07:00
|
|
|
win->mChildren[i]->mBounds.width = 0;
|
|
|
|
win->mChildren[i]->mBounds.height = 0;
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
case AndroidGeckoEvent::SIZE_CHANGED: {
|
2012-11-29 08:14:14 -08:00
|
|
|
const nsTArray<nsIntPoint>& points = ae->Points();
|
2012-02-24 07:51:41 -08:00
|
|
|
NS_ASSERTION(points.Length() == 2, "Size changed does not have enough coordinates");
|
2012-01-24 16:31:33 -08:00
|
|
|
|
2012-02-13 14:17:12 -08:00
|
|
|
int nw = points[0].x;
|
|
|
|
int nh = points[0].y;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-08-09 09:08:19 -07:00
|
|
|
if (ae->Type() == AndroidGeckoEvent::FORCED_RESIZE || nw != gAndroidBounds.width ||
|
2011-01-14 12:36:19 -08:00
|
|
|
nh != gAndroidBounds.height) {
|
|
|
|
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,
|
2012-03-19 07:06:24 -07:00
|
|
|
false);
|
2011-01-14 12:36:19 -08:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2012-01-24 16:31:33 -08:00
|
|
|
int newScreenWidth = points[1].x;
|
|
|
|
int newScreenHeight = points[1].y;
|
2011-01-14 12:36:19 -08: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 12:35:42 -07:00
|
|
|
nsTArray<ContentParent*> cplist;
|
|
|
|
ContentParent::GetAll(cplist);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < cplist.Length(); ++i)
|
2011-08-02 12:35:42 -07:00
|
|
|
unused << cplist[i]->SendScreenSizeChanged(gAndroidScreenBounds);
|
2011-01-14 12:36:19 -08: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;
|
|
|
|
|
2013-08-13 06:31:32 -07:00
|
|
|
nsRefPtr<ContentCreationNotifier> notifier = new ContentCreationNotifier;
|
2011-10-17 07:59:28 -07:00
|
|
|
if (NS_SUCCEEDED(obs->AddObserver(notifier, "ipc:content-created", false))) {
|
|
|
|
if (NS_SUCCEEDED(obs->AddObserver(notifier, "xpcom-shutdown", false)))
|
2011-01-14 12:36:19 -08:00
|
|
|
gContentCreationNotifier = notifier;
|
|
|
|
else
|
|
|
|
obs->RemoveObserver(notifier, "ipc:content-created");
|
2010-11-24 10:22:40 -08:00
|
|
|
}
|
2012-01-24 16:31:33 -08:00
|
|
|
break;
|
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()) {
|
2012-01-24 16:31:33 -08:00
|
|
|
nsIntPoint pt(0,0);
|
2012-11-29 08:14:14 -08:00
|
|
|
const nsTArray<nsIntPoint>& points = ae->Points();
|
2012-01-24 16:31:33 -08:00
|
|
|
if (points.Length() > 0) {
|
|
|
|
pt = points[0];
|
|
|
|
}
|
2013-01-15 04:22:03 -08:00
|
|
|
pt.x = clamped(pt.x, 0, std::max(gAndroidBounds.width - 1, 0));
|
|
|
|
pt.y = clamped(pt.y, 0, std::max(gAndroidBounds.height - 1, 0));
|
2010-10-27 13:10:15 -07:00
|
|
|
nsWindow *target = win->FindWindowForPoint(pt);
|
2010-06-03 13:56:36 -07:00
|
|
|
#if 0
|
2012-01-24 16:31:33 -08:00
|
|
|
ALOG("MOTION_EVENT %f,%f -> %p (visible: %d children: %d)", pt.x, pt.y, (void*)target,
|
2010-06-03 13:56:36 -07:00
|
|
|
target ? target->mIsVisible : 0,
|
|
|
|
target ? target->mChildren.Length() : 0);
|
|
|
|
|
|
|
|
DumpWindows();
|
|
|
|
#endif
|
2010-07-07 14:34:12 -07:00
|
|
|
if (target) {
|
2012-01-24 16:31:33 -08:00
|
|
|
bool preventDefaultActions = target->OnMultitouchEvent(ae);
|
|
|
|
if (!preventDefaultActions && ae->Count() < 2)
|
2012-06-15 15:34:22 -07:00
|
|
|
target->OnMouseEvent(ae);
|
2010-07-07 14:34:12 -07:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-02 13:18:21 -07:00
|
|
|
case AndroidGeckoEvent::NATIVE_GESTURE_EVENT: {
|
|
|
|
nsIntPoint pt(0,0);
|
2012-11-29 08:14:14 -08:00
|
|
|
const nsTArray<nsIntPoint>& points = ae->Points();
|
2012-10-02 13:18:21 -07:00
|
|
|
if (points.Length() > 0) {
|
|
|
|
pt = points[0];
|
|
|
|
}
|
2013-01-15 04:22:03 -08:00
|
|
|
pt.x = clamped(pt.x, 0, std::max(gAndroidBounds.width - 1, 0));
|
|
|
|
pt.y = clamped(pt.y, 0, std::max(gAndroidBounds.height - 1, 0));
|
2012-10-02 13:18:21 -07:00
|
|
|
nsWindow *target = win->FindWindowForPoint(pt);
|
|
|
|
|
|
|
|
target->OnNativeGestureEvent(ae);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
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:
|
2012-02-27 11:31:29 -08:00
|
|
|
layers::renderTraceEventStart("Global draw start", "414141");
|
2010-10-27 13:10:15 -07:00
|
|
|
win->OnDraw(ae);
|
2012-02-27 11:31:29 -08:00
|
|
|
layers::renderTraceEventEnd("414141");
|
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;
|
|
|
|
|
2013-03-29 07:54:01 -07:00
|
|
|
case AndroidGeckoEvent::IME_KEY_EVENT:
|
|
|
|
// Keys synthesized by Java IME code are saved in the mIMEKeyEvents
|
|
|
|
// array until the next IME_REPLACE_TEXT event, at which point
|
|
|
|
// these keys are dispatched in sequence.
|
|
|
|
if (win->mFocus) {
|
|
|
|
win->mFocus->mIMEKeyEvents.AppendElement(*ae);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-03-20 15:45:07 -07:00
|
|
|
case AndroidGeckoEvent::COMPOSITOR_CREATE:
|
|
|
|
win->CreateLayerManager(ae->Width(), ae->Height());
|
|
|
|
break;
|
|
|
|
|
2012-03-28 15:00:32 -07:00
|
|
|
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.
|
2013-01-10 08:21:10 -08:00
|
|
|
if (!sCompositorPaused) {
|
|
|
|
win->RedrawAll();
|
|
|
|
}
|
2012-03-28 15:00:32 -07:00
|
|
|
break;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnAndroidEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
|
|
|
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-28 23:19:26 -07:00
|
|
|
bool
|
2010-06-03 13:56:36 -07:00
|
|
|
nsWindow::DrawTo(gfxASurface *targetSurface)
|
2011-11-14 19:12:14 -08:00
|
|
|
{
|
|
|
|
nsIntRect boundsRect(0, 0, mBounds.width, mBounds.height);
|
|
|
|
return DrawTo(targetSurface, boundsRect);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-11-09 17:39:29 -08:00
|
|
|
nsWindow::DrawTo(gfxASurface *targetSurface, const nsIntRect &invalidRect)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-02-27 11:31:29 -08:00
|
|
|
mozilla::layers::RenderTraceScope trace("DrawTo", "717171");
|
2013-03-14 04:17:49 -07:00
|
|
|
if (!mIsVisible || !mWidgetListener || !GetLayerManager(nullptr))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-11-22 12:31:49 -08:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
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
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t coveringChildIndex = -1;
|
|
|
|
for (uint32_t i = 0; i < mChildren.Length(); ++i) {
|
2010-06-25 17:52:37 -07:00
|
|
|
if (mChildren[i]->mBounds.IsEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mChildren[i]->mBounds.Contains(boundsRect)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
coveringChildIndex = int32_t(i);
|
2010-06-25 17:52:37 -07:00
|
|
|
}
|
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) {
|
2012-08-15 11:52:42 -07:00
|
|
|
nsIntRegion region = invalidRect;
|
2011-11-17 19:20:29 -08:00
|
|
|
|
2013-01-28 11:34:08 -08:00
|
|
|
mWidgetListener->WillPaintWindow(this);
|
2013-01-28 11:34:03 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
switch (GetLayerManager(nullptr)->GetBackendType()) {
|
2012-07-18 09:31:40 -07:00
|
|
|
case mozilla::layers::LAYERS_BASIC: {
|
2012-02-02 19:28:22 -08:00
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
|
|
|
|
|
|
|
|
{
|
2012-02-27 11:31:29 -08:00
|
|
|
mozilla::layers::RenderTraceScope trace2("Basic DrawTo", "727272");
|
2010-07-15 14:08:04 -07:00
|
|
|
AutoLayerManagerSetup
|
2012-07-30 17:42:26 -07:00
|
|
|
setupLayerManager(this, ctx, mozilla::layers::BUFFER_NONE);
|
2011-11-17 19:20:29 -08:00
|
|
|
|
2013-05-23 07:49:18 -07:00
|
|
|
mWidgetListener->PaintWindow(this, region);
|
2010-06-25 17:52:37 -07:00
|
|
|
}
|
|
|
|
break;
|
2010-06-28 23:42:28 -07:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2013-05-09 14:02:50 -07:00
|
|
|
case mozilla::layers::LAYERS_CLIENT: {
|
2013-05-23 07:49:18 -07:00
|
|
|
mWidgetListener->PaintWindow(this, region);
|
2013-05-09 14:02:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid layer manager");
|
|
|
|
}
|
|
|
|
|
2013-01-28 11:34:03 -08:00
|
|
|
mWidgetListener->DidPaintWindow();
|
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
// 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();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = coveringChildIndex; i < mChildren.Length(); ++i) {
|
2010-06-25 17:52:37 -07:00
|
|
|
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));
|
|
|
|
|
2011-11-09 17:39:29 -08:00
|
|
|
bool ok = mChildren[i]->DrawTo(targetSurface, invalidRect);
|
2010-06-25 17:52:37 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-03 13:56:36 -07: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-02 19:28:22 -08:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
|
2012-07-12 18:35:19 -07:00
|
|
|
AutoLocalJNIFrame jniFrame;
|
2012-05-04 08:08:47 -07:00
|
|
|
|
2012-03-28 15:00:32 -07: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-15 15:45:52 -08:00
|
|
|
return;
|
2012-02-03 15:48:26 -08:00
|
|
|
}
|
2011-12-15 15:45:52 -08:00
|
|
|
|
2013-07-04 06:53:25 -07:00
|
|
|
int bytesPerPixel = 2;
|
2014-01-23 10:26:40 -08:00
|
|
|
gfxImageFormat format = gfxImageFormat::RGB16_565;
|
2013-07-04 06:53:25 -07:00
|
|
|
if (AndroidBridge::Bridge()->GetScreenDepth() == 24) {
|
|
|
|
bytesPerPixel = 4;
|
2014-01-23 10:26:40 -08:00
|
|
|
format = gfxImageFormat::RGB24;
|
2013-07-04 06:53:25 -07:00
|
|
|
}
|
|
|
|
|
2012-02-27 11:31:29 -08:00
|
|
|
layers::renderTraceEventStart("Get surface", "424545");
|
2013-07-04 06:53:25 -07:00
|
|
|
static unsigned char bits2[32 * 32 * 4];
|
2012-02-02 19:28:22 -08:00
|
|
|
nsRefPtr<gfxImageSurface> targetSurface =
|
2013-07-04 06:53:25 -07:00
|
|
|
new gfxImageSurface(bits2, gfxIntSize(32, 32), 32 * bytesPerPixel, format);
|
2012-02-27 11:31:29 -08:00
|
|
|
layers::renderTraceEventEnd("Get surface", "424545");
|
2012-02-02 19:28:22 -08:00
|
|
|
|
2012-02-27 11:31:29 -08:00
|
|
|
layers::renderTraceEventStart("Widget draw to", "434646");
|
2012-02-03 15:48:26 -08:00
|
|
|
if (targetSurface->CairoStatus()) {
|
2012-02-02 20:24:49 -08:00
|
|
|
ALOG("### Failed to create a valid surface from the bitmap");
|
2012-02-17 06:16:14 -08:00
|
|
|
} else {
|
2012-05-03 09:34:02 -07:00
|
|
|
DrawTo(targetSurface, ae->Rect());
|
2011-11-14 19:12:14 -08:00
|
|
|
}
|
2012-02-27 11:31:29 -08:00
|
|
|
layers::renderTraceEventEnd("Widget draw to", "434646");
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnSizeChanged(const gfxIntSize& aSize)
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
ALOG("nsWindow: %p OnSizeChanged [%d %d]", (void*)this, aSize.width, aSize.height);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
mBounds.width = aSize.width;
|
|
|
|
mBounds.height = aSize.height;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener) {
|
|
|
|
mWidgetListener->WindowResized(this, aSize.width, aSize.height);
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-01 20:46:03 -07:00
|
|
|
nsWindow::InitEvent(WidgetGUIEvent& event, nsIntPoint* aPoint)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
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 *
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::GetNativeData(uint32_t aDataType)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
switch (aDataType) {
|
2013-10-10 13:42:52 -07:00
|
|
|
// used by GLContextProviderEGL, nullptr is EGL_DEFAULT_DISPLAY
|
2010-06-25 17:52:37 -07:00
|
|
|
case NS_NATIVE_DISPLAY:
|
2013-10-10 13:42:52 -07:00
|
|
|
return nullptr;
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
case NS_NATIVE_WIDGET:
|
|
|
|
return (void *) this;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-15 15:34:22 -07:00
|
|
|
nsWindow::OnMouseEvent(AndroidGeckoEvent *ae)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-05-26 08:06:55 -07:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
|
2013-10-15 14:11:39 -07:00
|
|
|
WidgetMouseEvent event = ae->MakeMouseEvent(this);
|
|
|
|
if (event.message == NS_EVENT_NULL) {
|
|
|
|
// invalid event type, abort
|
2011-11-22 12:31:49 -08:00
|
|
|
return;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
2013-10-15 14:11:39 -07:00
|
|
|
|
|
|
|
// XXX add the double-click handling logic here
|
|
|
|
DispatchEvent(&event);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2012-01-24 16:31:33 -08:00
|
|
|
bool nsWindow::OnMultitouchEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2012-05-26 08:06:55 -07:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
|
2013-04-03 23:08:16 -07:00
|
|
|
// End any composition in progress in case the touch event listener
|
|
|
|
// modifies the input field value (see bug 856155)
|
|
|
|
RemoveIMEComposition();
|
|
|
|
|
2012-04-07 00:09:26 -07: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;
|
2013-04-17 14:39:10 -07:00
|
|
|
|
2013-09-26 23:20:57 -07:00
|
|
|
WidgetTouchEvent event = ae->MakeTouchEvent(this);
|
2013-04-17 14:39:10 -07:00
|
|
|
if (event.message != NS_EVENT_NULL) {
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
// We check mMultipleActionsPrevented because that's what <input type=range>
|
|
|
|
// sets when someone starts dragging the thumb. It doesn't set the status
|
|
|
|
// because it doesn't want to prevent the code that gives the input focus
|
|
|
|
// from running.
|
|
|
|
preventDefaultActions = (status == nsEventStatus_eConsumeNoDefault ||
|
|
|
|
event.mFlags.mMultipleActionsPrevented);
|
|
|
|
isDownEvent = (event.message == NS_TOUCH_START);
|
2012-04-07 00:09:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyDefaultPrevented(defaultPrevented);
|
2012-04-07 00:09:26 -07:00
|
|
|
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) {
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyDefaultPrevented(true);
|
2012-04-07 00:09:26 -07:00
|
|
|
sDefaultPreventedNotified = true;
|
|
|
|
} else {
|
|
|
|
sDefaultPreventedNotified = false;
|
2012-01-24 16:31:33 -08:00
|
|
|
}
|
|
|
|
}
|
2012-04-07 00:09:26 -07:00
|
|
|
sLastWasDownEvent = isDownEvent;
|
|
|
|
|
|
|
|
return preventDefaultActions;
|
2012-01-24 16:31:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-02 13:18:21 -07:00
|
|
|
nsWindow::OnNativeGestureEvent(AndroidGeckoEvent *ae)
|
2010-07-07 14:34:12 -07:00
|
|
|
{
|
2012-10-02 13:18:21 -07:00
|
|
|
nsIntPoint pt(ae->Points()[0].x,
|
|
|
|
ae->Points()[0].y);
|
|
|
|
double delta = ae->X();
|
|
|
|
int msg = 0;
|
|
|
|
|
2013-04-17 14:39:11 -07:00
|
|
|
switch (ae->Action()) {
|
2012-10-02 13:18:21 -07:00
|
|
|
case AndroidMotionEvent::ACTION_MAGNIFY_START:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY_START;
|
|
|
|
mStartDist = delta;
|
|
|
|
mLastDist = delta;
|
|
|
|
break;
|
|
|
|
case AndroidMotionEvent::ACTION_MAGNIFY:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY_UPDATE;
|
|
|
|
delta -= mLastDist;
|
|
|
|
mLastDist += delta;
|
|
|
|
break;
|
|
|
|
case AndroidMotionEvent::ACTION_MAGNIFY_END:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY;
|
|
|
|
delta -= mStartDist;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
DispatchGestureEvent(msg, 0, delta, pt, ae->Time());
|
2010-08-25 22:52:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::DispatchGestureEvent(uint32_t msg, uint32_t direction, double delta,
|
|
|
|
const nsIntPoint &refPoint, uint64_t time)
|
2010-08-25 22:52:08 -07:00
|
|
|
{
|
2013-09-26 23:20:57 -07:00
|
|
|
WidgetSimpleGestureEvent event(true, msg, this, direction, delta);
|
2010-07-07 14:34:12 -07:00
|
|
|
|
2012-04-24 20:00:02 -07:00
|
|
|
event.modifiers = 0;
|
2010-08-25 22:52:08 -07:00
|
|
|
event.time = time;
|
2013-08-02 00:05:16 -07:00
|
|
|
event.refPoint = LayoutDeviceIntPoint::FromUntyped(refPoint);
|
2010-07-07 14:34:12 -07:00
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2012-01-24 16:31:33 -08:00
|
|
|
|
|
|
|
void
|
2013-10-01 00:23:02 -07:00
|
|
|
nsWindow::DispatchMotionEvent(WidgetInputEvent &event, AndroidGeckoEvent *ae,
|
2012-01-24 16:31:33 -08:00
|
|
|
const nsIntPoint &refPoint)
|
|
|
|
{
|
|
|
|
nsIntPoint offset = WidgetToScreenOffset();
|
|
|
|
|
2013-12-17 18:25:10 -08:00
|
|
|
event.modifiers = ae->DOMModifiers();
|
2012-01-24 16:31:33 -08:00
|
|
|
event.time = ae->Time();
|
|
|
|
|
|
|
|
// XXX possibly bound the range of event.refPoint here.
|
|
|
|
// some code may get confused.
|
2013-08-02 00:05:16 -07:00
|
|
|
event.refPoint = LayoutDeviceIntPoint::FromUntyped(refPoint - offset);
|
2012-01-24 16:31:33 -08:00
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2012-04-19 13:34:03 -07:00
|
|
|
static unsigned int ConvertAndroidKeyCodeToDOMKeyCode(int androidKeyCode)
|
|
|
|
{
|
|
|
|
// Special-case alphanumeric keycodes because they are most common.
|
2013-04-22 11:24:43 -07:00
|
|
|
if (androidKeyCode >= AKEYCODE_A &&
|
|
|
|
androidKeyCode <= AKEYCODE_Z) {
|
|
|
|
return androidKeyCode - AKEYCODE_A + NS_VK_A;
|
2012-04-19 13:34:03 -07:00
|
|
|
}
|
|
|
|
|
2013-04-22 11:24:43 -07:00
|
|
|
if (androidKeyCode >= AKEYCODE_0 &&
|
|
|
|
androidKeyCode <= AKEYCODE_9) {
|
|
|
|
return androidKeyCode - AKEYCODE_0 + NS_VK_0;
|
2012-04-19 13:34:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (androidKeyCode) {
|
2012-04-24 20:47:46 -07:00
|
|
|
// KEYCODE_UNKNOWN (0) ... KEYCODE_HOME (3)
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_BACK: return NS_VK_ESCAPE;
|
2012-04-24 20:47:46 -07:00
|
|
|
// KEYCODE_CALL (5) ... KEYCODE_POUND (18)
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_DPAD_UP: return NS_VK_UP;
|
|
|
|
case AKEYCODE_DPAD_DOWN: return NS_VK_DOWN;
|
|
|
|
case AKEYCODE_DPAD_LEFT: return NS_VK_LEFT;
|
|
|
|
case AKEYCODE_DPAD_RIGHT: return NS_VK_RIGHT;
|
|
|
|
case AKEYCODE_DPAD_CENTER: return NS_VK_RETURN;
|
|
|
|
case AKEYCODE_VOLUME_UP: return NS_VK_VOLUME_UP;
|
|
|
|
case AKEYCODE_VOLUME_DOWN: return NS_VK_VOLUME_DOWN;
|
2013-02-04 15:27:56 -08:00
|
|
|
// KEYCODE_VOLUME_POWER (26) ... KEYCODE_Z (54)
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_COMMA: return NS_VK_COMMA;
|
|
|
|
case AKEYCODE_PERIOD: return NS_VK_PERIOD;
|
|
|
|
case AKEYCODE_ALT_LEFT: return NS_VK_ALT;
|
|
|
|
case AKEYCODE_ALT_RIGHT: return NS_VK_ALT;
|
|
|
|
case AKEYCODE_SHIFT_LEFT: return NS_VK_SHIFT;
|
|
|
|
case AKEYCODE_SHIFT_RIGHT: return NS_VK_SHIFT;
|
|
|
|
case AKEYCODE_TAB: return NS_VK_TAB;
|
|
|
|
case AKEYCODE_SPACE: return NS_VK_SPACE;
|
2012-04-19 13:34:03 -07:00
|
|
|
// KEYCODE_SYM (63) ... KEYCODE_ENVELOPE (65)
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_ENTER: return NS_VK_RETURN;
|
|
|
|
case AKEYCODE_DEL: return NS_VK_BACK; // Backspace
|
|
|
|
case AKEYCODE_GRAVE: return NS_VK_BACK_QUOTE;
|
2012-04-19 13:34:03 -07:00
|
|
|
// KEYCODE_MINUS (69)
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_EQUALS: return NS_VK_EQUALS;
|
|
|
|
case AKEYCODE_LEFT_BRACKET: return NS_VK_OPEN_BRACKET;
|
|
|
|
case AKEYCODE_RIGHT_BRACKET: return NS_VK_CLOSE_BRACKET;
|
|
|
|
case AKEYCODE_BACKSLASH: return NS_VK_BACK_SLASH;
|
|
|
|
case AKEYCODE_SEMICOLON: return NS_VK_SEMICOLON;
|
2012-04-19 13:34:03 -07:00
|
|
|
// KEYCODE_APOSTROPHE (75)
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_SLASH: return NS_VK_SLASH;
|
2013-02-04 15:27:56 -08:00
|
|
|
// KEYCODE_AT (77) ... KEYCODE_MEDIA_FAST_FORWARD (90)
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_MUTE: return NS_VK_VOLUME_MUTE;
|
|
|
|
case AKEYCODE_PAGE_UP: return NS_VK_PAGE_UP;
|
|
|
|
case AKEYCODE_PAGE_DOWN: return NS_VK_PAGE_DOWN;
|
2012-04-19 13:34:03 -07:00
|
|
|
// KEYCODE_PICTSYMBOLS (94) ... KEYCODE_BUTTON_MODE (110)
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_ESCAPE: return NS_VK_ESCAPE;
|
|
|
|
case AKEYCODE_FORWARD_DEL: return NS_VK_DELETE;
|
|
|
|
case AKEYCODE_CTRL_LEFT: return NS_VK_CONTROL;
|
|
|
|
case AKEYCODE_CTRL_RIGHT: return NS_VK_CONTROL;
|
|
|
|
case AKEYCODE_CAPS_LOCK: return NS_VK_CAPS_LOCK;
|
|
|
|
case AKEYCODE_SCROLL_LOCK: return NS_VK_SCROLL_LOCK;
|
2012-04-19 13:34:03 -07:00
|
|
|
// KEYCODE_META_LEFT (117) ... KEYCODE_FUNCTION (119)
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_SYSRQ: return NS_VK_PRINTSCREEN;
|
|
|
|
case AKEYCODE_BREAK: return NS_VK_PAUSE;
|
|
|
|
case AKEYCODE_MOVE_HOME: return NS_VK_HOME;
|
|
|
|
case AKEYCODE_MOVE_END: return NS_VK_END;
|
|
|
|
case AKEYCODE_INSERT: return NS_VK_INSERT;
|
2012-04-19 13:34:03 -07:00
|
|
|
// KEYCODE_FORWARD (125) ... KEYCODE_MEDIA_RECORD (130)
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_F1: return NS_VK_F1;
|
|
|
|
case AKEYCODE_F2: return NS_VK_F2;
|
|
|
|
case AKEYCODE_F3: return NS_VK_F3;
|
|
|
|
case AKEYCODE_F4: return NS_VK_F4;
|
|
|
|
case AKEYCODE_F5: return NS_VK_F5;
|
|
|
|
case AKEYCODE_F6: return NS_VK_F6;
|
|
|
|
case AKEYCODE_F7: return NS_VK_F7;
|
|
|
|
case AKEYCODE_F8: return NS_VK_F8;
|
|
|
|
case AKEYCODE_F9: return NS_VK_F9;
|
|
|
|
case AKEYCODE_F10: return NS_VK_F10;
|
|
|
|
case AKEYCODE_F11: return NS_VK_F11;
|
|
|
|
case AKEYCODE_F12: return NS_VK_F12;
|
|
|
|
case AKEYCODE_NUM_LOCK: return NS_VK_NUM_LOCK;
|
|
|
|
case AKEYCODE_NUMPAD_0: return NS_VK_NUMPAD0;
|
|
|
|
case AKEYCODE_NUMPAD_1: return NS_VK_NUMPAD1;
|
|
|
|
case AKEYCODE_NUMPAD_2: return NS_VK_NUMPAD2;
|
|
|
|
case AKEYCODE_NUMPAD_3: return NS_VK_NUMPAD3;
|
|
|
|
case AKEYCODE_NUMPAD_4: return NS_VK_NUMPAD4;
|
|
|
|
case AKEYCODE_NUMPAD_5: return NS_VK_NUMPAD5;
|
|
|
|
case AKEYCODE_NUMPAD_6: return NS_VK_NUMPAD6;
|
|
|
|
case AKEYCODE_NUMPAD_7: return NS_VK_NUMPAD7;
|
|
|
|
case AKEYCODE_NUMPAD_8: return NS_VK_NUMPAD8;
|
|
|
|
case AKEYCODE_NUMPAD_9: return NS_VK_NUMPAD9;
|
|
|
|
case AKEYCODE_NUMPAD_DIVIDE: return NS_VK_DIVIDE;
|
|
|
|
case AKEYCODE_NUMPAD_MULTIPLY: return NS_VK_MULTIPLY;
|
|
|
|
case AKEYCODE_NUMPAD_SUBTRACT: return NS_VK_SUBTRACT;
|
|
|
|
case AKEYCODE_NUMPAD_ADD: return NS_VK_ADD;
|
|
|
|
case AKEYCODE_NUMPAD_DOT: return NS_VK_DECIMAL;
|
|
|
|
case AKEYCODE_NUMPAD_COMMA: return NS_VK_SEPARATOR;
|
|
|
|
case AKEYCODE_NUMPAD_ENTER: return NS_VK_RETURN;
|
|
|
|
case AKEYCODE_NUMPAD_EQUALS: return NS_VK_EQUALS;
|
2012-04-19 13:34:03 -07:00
|
|
|
// KEYCODE_NUMPAD_LEFT_PAREN (162) ... KEYCODE_CALCULATOR (210)
|
|
|
|
|
2013-04-23 20:49:48 -07:00
|
|
|
// Needs to confirm the behavior. If the key switches the open state
|
|
|
|
// of Japanese IME (or switches input character between Hiragana and
|
|
|
|
// Roman numeric characters), then, it might be better to use
|
|
|
|
// NS_VK_KANJI which is used for Alt+Zenkaku/Hankaku key on Windows.
|
|
|
|
case AKEYCODE_ZENKAKU_HANKAKU: return 0;
|
|
|
|
case AKEYCODE_EISU: return NS_VK_EISU;
|
|
|
|
case AKEYCODE_MUHENKAN: return NS_VK_NONCONVERT;
|
|
|
|
case AKEYCODE_HENKAN: return NS_VK_CONVERT;
|
|
|
|
case AKEYCODE_KATAKANA_HIRAGANA: return 0;
|
|
|
|
case AKEYCODE_YEN: return NS_VK_BACK_SLASH; // Same as other platforms.
|
|
|
|
case AKEYCODE_RO: return NS_VK_BACK_SLASH; // Same as other platforms.
|
|
|
|
case AKEYCODE_KANA: return NS_VK_KANA;
|
|
|
|
case AKEYCODE_ASSIST: return NS_VK_HELP;
|
|
|
|
|
2013-10-12 10:59:50 -07:00
|
|
|
// the A key is the action key for gamepad devices.
|
|
|
|
case AKEYCODE_BUTTON_A: return NS_VK_RETURN;
|
|
|
|
|
2012-04-19 13:34:03 -07:00
|
|
|
default:
|
|
|
|
ALOG("ConvertAndroidKeyCodeToDOMKeyCode: "
|
|
|
|
"No DOM keycode for Android keycode %d", androidKeyCode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-10 08:14:54 -08:00
|
|
|
static KeyNameIndex
|
|
|
|
ConvertAndroidKeyCodeToKeyNameIndex(AndroidGeckoEvent& aAndroidGeckoEvent)
|
2013-04-23 20:49:48 -07:00
|
|
|
{
|
2013-12-10 08:14:54 -08:00
|
|
|
int keyCode = aAndroidGeckoEvent.KeyCode();
|
2013-04-23 20:49:48 -07:00
|
|
|
// Special-case alphanumeric keycodes because they are most common.
|
2013-12-10 08:14:54 -08:00
|
|
|
if (keyCode >= AKEYCODE_A && keyCode <= AKEYCODE_Z) {
|
|
|
|
return KEY_NAME_INDEX_USE_STRING;
|
2013-04-23 20:49:48 -07:00
|
|
|
}
|
|
|
|
|
2013-12-10 08:14:54 -08:00
|
|
|
if (keyCode >= AKEYCODE_0 && keyCode <= AKEYCODE_9) {
|
|
|
|
return KEY_NAME_INDEX_USE_STRING;
|
2013-04-23 20:49:48 -07:00
|
|
|
}
|
|
|
|
|
2013-12-10 08:14:54 -08:00
|
|
|
switch (keyCode) {
|
2013-04-23 20:49:48 -07:00
|
|
|
|
|
|
|
#define NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX(aNativeKey, aKeyNameIndex) \
|
|
|
|
case aNativeKey: return aKeyNameIndex;
|
|
|
|
|
|
|
|
#include "NativeKeyToDOMKeyName.h"
|
|
|
|
|
|
|
|
#undef NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX
|
|
|
|
|
|
|
|
// KEYCODE_0 (7) ... KEYCODE_9 (16)
|
|
|
|
case AKEYCODE_STAR: // '*' key
|
|
|
|
case AKEYCODE_POUND: // '#' key
|
|
|
|
|
|
|
|
// KEYCODE_A (29) ... KEYCODE_Z (54)
|
|
|
|
|
|
|
|
case AKEYCODE_COMMA: // ',' key
|
|
|
|
case AKEYCODE_PERIOD: // '.' key
|
2013-12-10 08:14:54 -08:00
|
|
|
case AKEYCODE_SPACE:
|
2013-04-23 20:49:48 -07:00
|
|
|
case AKEYCODE_GRAVE: // '`' key
|
|
|
|
case AKEYCODE_MINUS: // '-' key
|
|
|
|
case AKEYCODE_EQUALS: // '=' key
|
|
|
|
case AKEYCODE_LEFT_BRACKET: // '[' key
|
|
|
|
case AKEYCODE_RIGHT_BRACKET: // ']' key
|
|
|
|
case AKEYCODE_BACKSLASH: // '\' key
|
|
|
|
case AKEYCODE_SEMICOLON: // ';' key
|
|
|
|
case AKEYCODE_APOSTROPHE: // ''' key
|
|
|
|
case AKEYCODE_SLASH: // '/' key
|
|
|
|
case AKEYCODE_AT: // '@' key
|
|
|
|
case AKEYCODE_PLUS: // '+' key
|
|
|
|
|
|
|
|
case AKEYCODE_NUMPAD_0:
|
|
|
|
case AKEYCODE_NUMPAD_1:
|
|
|
|
case AKEYCODE_NUMPAD_2:
|
|
|
|
case AKEYCODE_NUMPAD_3:
|
|
|
|
case AKEYCODE_NUMPAD_4:
|
|
|
|
case AKEYCODE_NUMPAD_5:
|
|
|
|
case AKEYCODE_NUMPAD_6:
|
|
|
|
case AKEYCODE_NUMPAD_7:
|
|
|
|
case AKEYCODE_NUMPAD_8:
|
|
|
|
case AKEYCODE_NUMPAD_9:
|
2013-12-10 08:14:54 -08:00
|
|
|
case AKEYCODE_NUMPAD_DIVIDE:
|
|
|
|
case AKEYCODE_NUMPAD_MULTIPLY:
|
|
|
|
case AKEYCODE_NUMPAD_SUBTRACT:
|
|
|
|
case AKEYCODE_NUMPAD_ADD:
|
|
|
|
case AKEYCODE_NUMPAD_DOT:
|
|
|
|
case AKEYCODE_NUMPAD_COMMA:
|
|
|
|
case AKEYCODE_NUMPAD_EQUALS:
|
2013-04-23 20:49:48 -07:00
|
|
|
case AKEYCODE_NUMPAD_LEFT_PAREN:
|
|
|
|
case AKEYCODE_NUMPAD_RIGHT_PAREN:
|
|
|
|
|
|
|
|
case AKEYCODE_YEN: // yen sign key
|
|
|
|
case AKEYCODE_RO: // Japanese Ro key
|
2013-12-10 08:14:54 -08:00
|
|
|
return KEY_NAME_INDEX_USE_STRING;
|
2013-04-23 20:49:48 -07:00
|
|
|
|
|
|
|
case AKEYCODE_SOFT_LEFT:
|
|
|
|
case AKEYCODE_SOFT_RIGHT:
|
|
|
|
case AKEYCODE_CALL:
|
|
|
|
case AKEYCODE_ENDCALL:
|
|
|
|
case AKEYCODE_SYM: // Symbol modifier
|
|
|
|
case AKEYCODE_NUM: // XXX Not sure
|
|
|
|
case AKEYCODE_HEADSETHOOK:
|
|
|
|
case AKEYCODE_FOCUS:
|
|
|
|
case AKEYCODE_NOTIFICATION: // XXX Not sure
|
|
|
|
case AKEYCODE_PICTSYMBOLS:
|
|
|
|
|
|
|
|
case AKEYCODE_BUTTON_A:
|
|
|
|
case AKEYCODE_BUTTON_B:
|
|
|
|
case AKEYCODE_BUTTON_C:
|
|
|
|
case AKEYCODE_BUTTON_X:
|
|
|
|
case AKEYCODE_BUTTON_Y:
|
|
|
|
case AKEYCODE_BUTTON_Z:
|
|
|
|
case AKEYCODE_BUTTON_L1:
|
|
|
|
case AKEYCODE_BUTTON_R1:
|
|
|
|
case AKEYCODE_BUTTON_L2:
|
|
|
|
case AKEYCODE_BUTTON_R2:
|
|
|
|
case AKEYCODE_BUTTON_THUMBL:
|
|
|
|
case AKEYCODE_BUTTON_THUMBR:
|
|
|
|
case AKEYCODE_BUTTON_START:
|
|
|
|
case AKEYCODE_BUTTON_SELECT:
|
|
|
|
case AKEYCODE_BUTTON_MODE:
|
|
|
|
|
|
|
|
case AKEYCODE_MUTE: // mutes the microphone
|
|
|
|
case AKEYCODE_MEDIA_CLOSE:
|
|
|
|
|
|
|
|
case AKEYCODE_ZOOM_IN:
|
|
|
|
case AKEYCODE_ZOOM_OUT:
|
|
|
|
case AKEYCODE_DVR:
|
|
|
|
case AKEYCODE_TV_POWER:
|
|
|
|
case AKEYCODE_TV_INPUT:
|
|
|
|
case AKEYCODE_STB_POWER:
|
|
|
|
case AKEYCODE_STB_INPUT:
|
|
|
|
case AKEYCODE_AVR_POWER:
|
|
|
|
case AKEYCODE_AVR_INPUT:
|
|
|
|
|
|
|
|
case AKEYCODE_BUTTON_1:
|
|
|
|
case AKEYCODE_BUTTON_2:
|
|
|
|
case AKEYCODE_BUTTON_3:
|
|
|
|
case AKEYCODE_BUTTON_4:
|
|
|
|
case AKEYCODE_BUTTON_5:
|
|
|
|
case AKEYCODE_BUTTON_6:
|
|
|
|
case AKEYCODE_BUTTON_7:
|
|
|
|
case AKEYCODE_BUTTON_8:
|
|
|
|
case AKEYCODE_BUTTON_9:
|
|
|
|
case AKEYCODE_BUTTON_10:
|
|
|
|
case AKEYCODE_BUTTON_11:
|
|
|
|
case AKEYCODE_BUTTON_12:
|
|
|
|
case AKEYCODE_BUTTON_13:
|
|
|
|
case AKEYCODE_BUTTON_14:
|
|
|
|
case AKEYCODE_BUTTON_15:
|
|
|
|
case AKEYCODE_BUTTON_16:
|
|
|
|
|
|
|
|
case AKEYCODE_LANGUAGE_SWITCH:
|
|
|
|
case AKEYCODE_MANNER_MODE:
|
|
|
|
case AKEYCODE_3D_MODE:
|
|
|
|
case AKEYCODE_CONTACTS:
|
|
|
|
case AKEYCODE_CALENDAR:
|
|
|
|
case AKEYCODE_MUSIC:
|
|
|
|
case AKEYCODE_CALCULATOR:
|
|
|
|
|
|
|
|
case AKEYCODE_ZENKAKU_HANKAKU:
|
|
|
|
case AKEYCODE_KATAKANA_HIRAGANA:
|
|
|
|
return KEY_NAME_INDEX_Unidentified;
|
|
|
|
|
2013-12-10 08:14:54 -08:00
|
|
|
case AKEYCODE_UNKNOWN:
|
|
|
|
MOZ_ASSERT(
|
|
|
|
aAndroidGeckoEvent.Action() != AKEY_EVENT_ACTION_MULTIPLE,
|
|
|
|
"Don't call this when action is AKEY_EVENT_ACTION_MULTIPLE!");
|
|
|
|
// It's actually an unknown key if the action isn't ACTION_MULTIPLE.
|
|
|
|
// However, it might cause text input. So, let's check the value.
|
|
|
|
return aAndroidGeckoEvent.DOMPrintableKeyValue() ?
|
|
|
|
KEY_NAME_INDEX_USE_STRING : KEY_NAME_INDEX_Unidentified;
|
|
|
|
|
2013-04-23 20:49:48 -07:00
|
|
|
default:
|
|
|
|
ALOG("ConvertAndroidKeyCodeToKeyNameIndex: "
|
2013-12-10 08:14:54 -08:00
|
|
|
"No DOM key name index for Android keycode %d", keyCode);
|
2013-04-23 20:49:48 -07:00
|
|
|
return KEY_NAME_INDEX_Unidentified;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 10:49:31 -07:00
|
|
|
static void InitPluginEvent(ANPEvent* pluginEvent, ANPKeyActions keyAction,
|
|
|
|
AndroidGeckoEvent& key)
|
|
|
|
{
|
|
|
|
int androidKeyCode = key.KeyCode();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t domKeyCode = ConvertAndroidKeyCodeToDOMKeyCode(androidKeyCode);
|
2012-04-19 10:49:31 -07:00
|
|
|
|
|
|
|
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-03 13:56:36 -07:00
|
|
|
void
|
2013-10-01 00:22:58 -07:00
|
|
|
nsWindow::InitKeyEvent(WidgetKeyboardEvent& event, AndroidGeckoEvent& key,
|
2012-04-19 10:49:31 -07:00
|
|
|
ANPEvent* pluginEvent)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2013-12-10 08:14:54 -08:00
|
|
|
event.mKeyNameIndex = ConvertAndroidKeyCodeToKeyNameIndex(key);
|
|
|
|
if (event.mKeyNameIndex == KEY_NAME_INDEX_USE_STRING) {
|
|
|
|
int keyValue = key.DOMPrintableKeyValue();
|
|
|
|
if (keyValue) {
|
2014-01-04 07:02:17 -08:00
|
|
|
event.mKeyValue = static_cast<char16_t>(keyValue);
|
2013-12-10 08:14:54 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
uint32_t domKeyCode = ConvertAndroidKeyCodeToDOMKeyCode(key.KeyCode());
|
2012-04-19 10:49:31 -07:00
|
|
|
|
|
|
|
if (event.message == NS_KEY_PRESS) {
|
|
|
|
// Android gives us \n, so filter out some control characters.
|
2013-03-29 07:54:01 -07:00
|
|
|
int charCode = key.UnicodeChar();
|
|
|
|
if (!charCode) {
|
|
|
|
charCode = key.BaseUnicodeChar();
|
|
|
|
}
|
|
|
|
event.isChar = (charCode >= ' ');
|
|
|
|
event.charCode = event.isChar ? charCode : 0;
|
2012-04-19 10:49:31 -07:00
|
|
|
event.keyCode = (event.charCode > 0) ? 0 : domKeyCode;
|
2013-10-10 13:42:52 -07:00
|
|
|
event.pluginEvent = nullptr;
|
2012-04-19 10:49:31 -07:00
|
|
|
} 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 12:50:46 -07:00
|
|
|
}
|
2012-04-19 10:49:31 -07:00
|
|
|
|
2013-12-17 18:25:10 -08:00
|
|
|
event.modifiers = key.DOMModifiers();
|
|
|
|
if (gMenu) {
|
|
|
|
event.modifiers |= MODIFIER_CONTROL;
|
|
|
|
}
|
|
|
|
// For keypress, if the unicode char already has modifiers applied, we
|
|
|
|
// don't specify extra modifiers. If UnicodeChar() != BaseUnicodeChar()
|
|
|
|
// it means UnicodeChar() already has modifiers applied.
|
|
|
|
// Note that on Android 4.x, Alt modifier isn't set when the key input
|
|
|
|
// causes text input even while right Alt key is pressed. However, this
|
|
|
|
// is necessary for Android 2.3 compatibility.
|
|
|
|
if (event.message == NS_KEY_PRESS &&
|
|
|
|
key.UnicodeChar() && key.UnicodeChar() != key.BaseUnicodeChar()) {
|
|
|
|
event.modifiers &= ~(MODIFIER_ALT | MODIFIER_CONTROL | MODIFIER_META);
|
2013-03-29 07:54:01 -07:00
|
|
|
}
|
2013-11-07 03:17:33 -08:00
|
|
|
|
|
|
|
event.mIsRepeat =
|
|
|
|
(event.message == NS_KEY_DOWN || event.message == NS_KEY_PRESS) &&
|
|
|
|
(!!(key.Flags() & AKEY_EVENT_FLAG_LONG_PRESS) || !!key.RepeatCount());
|
2012-09-12 17:48:29 -07:00
|
|
|
event.location = key.DomKeyLocation();
|
2010-06-03 13:56:36 -07:00
|
|
|
event.time = key.Time();
|
2010-10-16 05:15:54 -07:00
|
|
|
|
|
|
|
if (gMenu)
|
2011-10-17 07:59:28 -07:00
|
|
|
gMenuConsumed = true;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::HandleSpecialKey(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2011-11-22 12:31:49 -08:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2010-06-03 13:56:36 -07:00
|
|
|
nsCOMPtr<nsIAtom> command;
|
2013-04-22 11:24:43 -07:00
|
|
|
bool isDown = ae->Action() == AKEY_EVENT_ACTION_DOWN;
|
|
|
|
bool isLongPress = !!(ae->Flags() & AKEY_EVENT_FLAG_LONG_PRESS);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doCommand = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t keyCode = ae->KeyCode();
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
if (isDown) {
|
|
|
|
switch (keyCode) {
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_BACK:
|
2010-11-12 15:58:29 -08:00
|
|
|
if (isLongPress) {
|
2011-10-14 11:11:22 -07:00
|
|
|
command = nsGkAtoms::Clear;
|
2011-10-17 07:59:28 -07:00
|
|
|
doCommand = true;
|
2010-11-12 15:58:29 -08:00
|
|
|
}
|
|
|
|
break;
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_MENU:
|
2011-10-17 07:59:28 -07:00
|
|
|
gMenu = 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) {
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_BACK: {
|
2013-07-24 23:09:28 -07:00
|
|
|
// XXX Where is the keydown event for this??
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent pressEvent(true, NS_KEY_PRESS, this);
|
2012-04-19 10:49:31 -07:00
|
|
|
ANPEvent pluginEvent;
|
|
|
|
InitKeyEvent(pressEvent, *ae, &pluginEvent);
|
2010-06-03 13:56:36 -07:00
|
|
|
DispatchEvent(&pressEvent);
|
|
|
|
return;
|
|
|
|
}
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_MENU:
|
2011-10-17 07:59:28 -07:00
|
|
|
gMenu = false;
|
2010-10-16 05:15:54 -07:00
|
|
|
if (!gMenuConsumed) {
|
2011-10-14 11:11:22 -07:00
|
|
|
command = nsGkAtoms::Menu;
|
2011-10-17 07:59:28 -07:00
|
|
|
doCommand = true;
|
2010-10-16 05:15:54 -07:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
break;
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_SEARCH:
|
2011-10-14 11:11:22 -07:00
|
|
|
command = nsGkAtoms::Search;
|
2011-10-17 07:59:28 -07:00
|
|
|
doCommand = true;
|
2010-06-03 13:56:36 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ALOG("Unknown special key code!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (doCommand) {
|
2013-09-26 23:20:54 -07:00
|
|
|
WidgetCommandEvent event(true, nsGkAtoms::onAppCommand, command, this);
|
2010-06-03 13:56:36 -07:00
|
|
|
InitEvent(event);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnKeyEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2011-11-22 12:31:49 -08:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2012-11-01 13:11:02 -07:00
|
|
|
RemoveIMEComposition();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t msg;
|
2010-06-03 13:56:36 -07:00
|
|
|
switch (ae->Action()) {
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEY_EVENT_ACTION_DOWN:
|
2010-06-03 13:56:36 -07:00
|
|
|
msg = NS_KEY_DOWN;
|
|
|
|
break;
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEY_EVENT_ACTION_UP:
|
2010-06-03 13:56:36 -07:00
|
|
|
msg = NS_KEY_UP;
|
|
|
|
break;
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEY_EVENT_ACTION_MULTIPLE:
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent event(true, NS_TEXT_TEXT, this);
|
2010-06-03 13:56:36 -07:00
|
|
|
event.theText.Assign(ae->Characters());
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
ALOG("Unknown key action event!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-22 11:24:43 -07:00
|
|
|
bool firePress = ae->Action() == AKEY_EVENT_ACTION_DOWN;
|
2010-06-03 13:56:36 -07:00
|
|
|
switch (ae->KeyCode()) {
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_SHIFT_LEFT:
|
|
|
|
case AKEYCODE_SHIFT_RIGHT:
|
|
|
|
case AKEYCODE_ALT_LEFT:
|
|
|
|
case AKEYCODE_ALT_RIGHT:
|
|
|
|
case AKEYCODE_CTRL_LEFT:
|
|
|
|
case AKEYCODE_CTRL_RIGHT:
|
2010-12-21 14:36:28 -08:00
|
|
|
firePress = false;
|
2010-06-03 13:56:36 -07:00
|
|
|
break;
|
2013-04-22 11:24:43 -07:00
|
|
|
case AKEYCODE_BACK:
|
|
|
|
case AKEYCODE_MENU:
|
|
|
|
case AKEYCODE_SEARCH:
|
2010-06-03 13:56:36 -07:00
|
|
|
HandleSpecialKey(ae);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-21 14:36:28 -08:00
|
|
|
nsEventStatus status;
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent event(true, msg, this);
|
2012-04-19 10:49:31 -07:00
|
|
|
ANPEvent pluginEvent;
|
|
|
|
InitKeyEvent(event, *ae, &pluginEvent);
|
2010-12-21 14:36:28 -08:00
|
|
|
DispatchEvent(&event, status);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-11-22 12:31:49 -08:00
|
|
|
if (Destroyed())
|
|
|
|
return;
|
2013-07-24 23:09:28 -07:00
|
|
|
if (!firePress || status == nsEventStatus_eConsumeNoDefault) {
|
2010-12-21 14:36:28 -08:00
|
|
|
return;
|
2013-07-24 23:09:28 -07:00
|
|
|
}
|
2010-12-21 14:36:28 -08:00
|
|
|
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent pressEvent(true, NS_KEY_PRESS, this);
|
2012-04-19 10:49:31 -07:00
|
|
|
InitKeyEvent(pressEvent, *ae, &pluginEvent);
|
2011-08-29 11:29:39 -07:00
|
|
|
#ifdef DEBUG_ANDROID_WIDGET
|
2012-04-24 20:00:02 -07: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
|
|
|
}
|
|
|
|
|
2011-08-29 11:29:39 -07:00
|
|
|
#ifdef DEBUG_ANDROID_IME
|
2010-08-04 12:47:26 -07:00
|
|
|
#define ALOGIME(args...) ALOG(args)
|
|
|
|
#else
|
2013-01-25 11:33:40 -08:00
|
|
|
#define ALOGIME(args...) ((void)0)
|
2010-08-04 12:47:26 -07:00
|
|
|
#endif
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2012-11-01 13:11:02 -07:00
|
|
|
static nscolor
|
2012-12-06 11:35:59 -08:00
|
|
|
ConvertAndroidColor(uint32_t argb)
|
2012-11-01 13:11:02 -07:00
|
|
|
{
|
2012-12-06 11:35:59 -08:00
|
|
|
return NS_RGBA((argb & 0x00ff0000) >> 16,
|
|
|
|
(argb & 0x0000ff00) >> 8,
|
|
|
|
(argb & 0x000000ff),
|
|
|
|
(argb & 0xff000000) >> 24);
|
2012-11-01 13:11:02 -07:00
|
|
|
}
|
|
|
|
|
2012-11-01 13:11:03 -07:00
|
|
|
class AutoIMEMask {
|
|
|
|
private:
|
|
|
|
bool mOldMask, *mMask;
|
|
|
|
public:
|
|
|
|
AutoIMEMask(bool &mask) : mOldMask(mask), mMask(&mask) {
|
|
|
|
mask = true;
|
|
|
|
}
|
|
|
|
~AutoIMEMask() {
|
|
|
|
*mMask = mOldMask;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-11-01 13:11:02 -07:00
|
|
|
/*
|
|
|
|
Remove the composition but leave the text content as-is
|
|
|
|
*/
|
2010-08-04 12:47:26 -07:00
|
|
|
void
|
2012-11-01 13:11:02 -07:00
|
|
|
nsWindow::RemoveIMEComposition()
|
Backout 533faa3c50ed, 718abc1bd4ad, af2d5272c06b, ad5554e1345d, c9ef1b41b829, d3a825311d11, 0a51bcb3eb9e, a01a327e8ec4, 973b0ed30b8b, 39851bbcfaa1 & a92d2d2a3b0e (bug 805162), d4884aab5ce6, 06fcbaf40cb4, daccc3fe7c70, 881eb2a2906e, 76232441ae06, 01ae34fa1b3f & 5f405fc4e323 (bug 783092), a03d8d4db1c2, 49beb3801192, 174634554a97, 0bd27e755a83, 19e8f151ca67, a6604e038bc0, ed3b8237e76e & 082cf8d72554 (bug 785945) for bustage or conflicting with backout of said bustage on a CLOSED TREE
2012-10-31 17:16:35 -07:00
|
|
|
{
|
2012-11-01 13:11:02 -07:00
|
|
|
// Remove composition on Gecko side
|
|
|
|
if (!mIMEComposing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2012-11-01 13:11:03 -07:00
|
|
|
AutoIMEMask selMask(mIMEMaskSelectionUpdate);
|
|
|
|
AutoIMEMask textMask(mIMEMaskTextUpdate);
|
2012-11-01 13:11:02 -07:00
|
|
|
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent textEvent(true, NS_TEXT_TEXT, this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(textEvent, nullptr);
|
|
|
|
textEvent.theText = mIMEComposingText;
|
|
|
|
DispatchEvent(&textEvent);
|
|
|
|
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent event(true, NS_COMPOSITION_END, this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(event, nullptr);
|
|
|
|
DispatchEvent(&event);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnIMEEvent(AndroidGeckoEvent *ae)
|
|
|
|
{
|
2012-11-01 13:11:02 -07:00
|
|
|
MOZ_ASSERT(!mIMEMaskTextUpdate);
|
|
|
|
MOZ_ASSERT(!mIMEMaskSelectionUpdate);
|
|
|
|
/*
|
|
|
|
Rules for managing IME between Gecko and Java:
|
|
|
|
|
|
|
|
* Gecko controls the text content, and Java shadows the Gecko text
|
|
|
|
through text updates
|
|
|
|
* Java controls the selection, and Gecko shadows the Java selection
|
|
|
|
through set selection events
|
|
|
|
* Java controls the composition, and Gecko shadows the Java
|
|
|
|
composition through update composition events
|
|
|
|
*/
|
2011-11-22 12:31:49 -08:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
2012-11-13 14:27:19 -08:00
|
|
|
|
|
|
|
if (ae->Action() == AndroidGeckoEvent::IME_ACKNOWLEDGE_FOCUS) {
|
2012-11-16 08:41:54 -08:00
|
|
|
MOZ_ASSERT(mIMEMaskEventsCount > 0);
|
|
|
|
mIMEMaskEventsCount--;
|
2013-02-01 11:50:03 -08:00
|
|
|
if (!mIMEMaskEventsCount) {
|
|
|
|
// The focusing handshake sequence is complete, and Java is waiting
|
|
|
|
// on Gecko. Now we can notify Java of the newly focused content
|
|
|
|
mIMETextChanges.Clear();
|
|
|
|
mIMESelectionChanged = false;
|
2013-03-05 22:14:34 -08:00
|
|
|
// NotifyIMEOfTextChange also notifies selection
|
2013-02-01 11:50:03 -08:00
|
|
|
// Use 'INT32_MAX / 2' here because subsequent text changes might
|
|
|
|
// combine with this text change, and overflow might occur if
|
|
|
|
// we just use INT32_MAX
|
2013-03-05 22:14:34 -08:00
|
|
|
NotifyIMEOfTextChange(0, INT32_MAX / 2, INT32_MAX / 2);
|
2013-02-01 11:50:03 -08:00
|
|
|
FlushIMEChanges();
|
|
|
|
}
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIME(AndroidBridge::NOTIFY_IME_REPLY_EVENT);
|
2012-11-13 14:27:19 -08:00
|
|
|
return;
|
2013-03-05 07:24:35 -08:00
|
|
|
} else if (ae->Action() == AndroidGeckoEvent::IME_UPDATE_CONTEXT) {
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIMEContext(mInputContext.mIMEState.mEnabled,
|
2013-03-05 07:24:35 -08:00
|
|
|
mInputContext.mHTMLInputType,
|
|
|
|
mInputContext.mHTMLInputInputmode,
|
|
|
|
mInputContext.mActionHint);
|
|
|
|
mIMEUpdatingContext = false;
|
|
|
|
return;
|
2012-11-13 14:27:26 -08:00
|
|
|
}
|
2012-11-16 08:41:54 -08:00
|
|
|
if (mIMEMaskEventsCount > 0) {
|
2012-11-13 14:27:19 -08:00
|
|
|
// Still reply to events, but don't do anything else
|
|
|
|
if (ae->Action() == AndroidGeckoEvent::IME_SYNCHRONIZE ||
|
2012-11-13 14:27:26 -08:00
|
|
|
ae->Action() == AndroidGeckoEvent::IME_REPLACE_TEXT) {
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIME(AndroidBridge::NOTIFY_IME_REPLY_EVENT);
|
2012-11-13 14:27:19 -08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
switch (ae->Action()) {
|
2012-12-05 08:09:56 -08:00
|
|
|
case AndroidGeckoEvent::IME_FLUSH_CHANGES:
|
|
|
|
{
|
|
|
|
FlushIMEChanges();
|
|
|
|
}
|
|
|
|
break;
|
2012-11-01 13:11:02 -07:00
|
|
|
case AndroidGeckoEvent::IME_SYNCHRONIZE:
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-12-05 08:09:56 -08:00
|
|
|
FlushIMEChanges();
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIME(AndroidBridge::NOTIFY_IME_REPLY_EVENT);
|
2012-10-31 14:35:31 -07:00
|
|
|
}
|
2012-11-01 13:11:02 -07:00
|
|
|
break;
|
|
|
|
case AndroidGeckoEvent::IME_REPLACE_TEXT:
|
2012-10-31 14:35:31 -07:00
|
|
|
{
|
2012-11-01 13:11:02 -07:00
|
|
|
/*
|
|
|
|
Replace text in Gecko thread from ae->Start() to ae->End()
|
|
|
|
with the string ae->Characters()
|
|
|
|
|
|
|
|
Selection updates are masked so the result of our temporary
|
|
|
|
selection event is not passed on to Java
|
|
|
|
|
|
|
|
Text updates are passed on, so the Java text can shadow the
|
|
|
|
Gecko text
|
|
|
|
*/
|
2012-11-01 13:11:03 -07:00
|
|
|
AutoIMEMask selMask(mIMEMaskSelectionUpdate);
|
2012-11-01 13:11:02 -07:00
|
|
|
RemoveIMEComposition();
|
|
|
|
{
|
2013-10-01 00:23:01 -07:00
|
|
|
WidgetSelectionEvent event(true, NS_SELECTION_SET, this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(event, nullptr);
|
|
|
|
event.mOffset = uint32_t(ae->Start());
|
|
|
|
event.mLength = uint32_t(ae->End() - ae->Start());
|
|
|
|
event.mExpandToClusterBoundary = false;
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
2013-03-29 07:54:01 -07:00
|
|
|
|
|
|
|
if (!mIMEKeyEvents.IsEmpty()) {
|
|
|
|
for (uint32_t i = 0; i < mIMEKeyEvents.Length(); i++) {
|
|
|
|
OnKeyEvent(&mIMEKeyEvents[i]);
|
|
|
|
}
|
|
|
|
mIMEKeyEvents.Clear();
|
|
|
|
FlushIMEChanges();
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIME(AndroidBridge::NOTIFY_IME_REPLY_EVENT);
|
2013-03-29 07:54:01 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-01 13:11:02 -07:00
|
|
|
{
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent event(true, NS_COMPOSITION_START, this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(event, nullptr);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
{
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent event(true, NS_TEXT_TEXT, this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(event, nullptr);
|
|
|
|
event.theText = ae->Characters();
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
{
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent event(true, NS_COMPOSITION_END, this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(event, nullptr);
|
|
|
|
event.data = ae->Characters();
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
2012-12-05 08:09:56 -08:00
|
|
|
FlushIMEChanges();
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIME(AndroidBridge::NOTIFY_IME_REPLY_EVENT);
|
2012-11-01 13:11:02 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AndroidGeckoEvent::IME_SET_SELECTION:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Set Gecko selection to ae->Start() to ae->End()
|
|
|
|
|
|
|
|
Selection updates are masked to prevent Java from being
|
|
|
|
notified of the new selection
|
|
|
|
*/
|
2012-11-01 13:11:03 -07:00
|
|
|
AutoIMEMask selMask(mIMEMaskSelectionUpdate);
|
2013-03-29 07:54:01 -07:00
|
|
|
RemoveIMEComposition();
|
2013-10-01 00:23:01 -07:00
|
|
|
WidgetSelectionEvent selEvent(true, NS_SELECTION_SET, this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(selEvent, nullptr);
|
2012-10-31 14:35:31 -07:00
|
|
|
|
2012-11-01 13:11:02 -07:00
|
|
|
int32_t start = ae->Start(), end = ae->End();
|
|
|
|
|
|
|
|
if (start < 0 || end < 0) {
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetQueryContentEvent event(true, NS_QUERY_SELECTED_TEXT,
|
|
|
|
this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(event, nullptr);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
MOZ_ASSERT(event.mSucceeded && !event.mWasAsync);
|
|
|
|
|
|
|
|
if (start < 0)
|
|
|
|
start = int32_t(event.GetSelectionStart());
|
|
|
|
if (end < 0)
|
|
|
|
end = int32_t(event.GetSelectionEnd());
|
|
|
|
}
|
|
|
|
|
|
|
|
selEvent.mOffset = std::min(start, end);
|
|
|
|
selEvent.mLength = std::max(start, end) - selEvent.mOffset;
|
|
|
|
selEvent.mReversed = start > end;
|
|
|
|
selEvent.mExpandToClusterBoundary = false;
|
|
|
|
|
|
|
|
DispatchEvent(&selEvent);
|
2010-08-04 12:47:26 -07:00
|
|
|
}
|
2012-11-01 13:11:02 -07:00
|
|
|
break;
|
|
|
|
case AndroidGeckoEvent::IME_ADD_COMPOSITION_RANGE:
|
2010-08-04 12:47:26 -07:00
|
|
|
{
|
2013-10-01 00:22:59 -07:00
|
|
|
TextRange range;
|
2012-11-01 13:11:02 -07:00
|
|
|
range.mStartOffset = ae->Start();
|
|
|
|
range.mEndOffset = ae->End();
|
|
|
|
range.mRangeType = ae->RangeType();
|
|
|
|
range.mRangeStyle.mDefinedStyles = ae->RangeStyles();
|
2012-12-06 11:35:59 -08:00
|
|
|
range.mRangeStyle.mLineStyle = ae->RangeLineStyle();
|
|
|
|
range.mRangeStyle.mIsBoldLine = ae->RangeBoldLine();
|
2012-11-01 13:11:02 -07:00
|
|
|
range.mRangeStyle.mForegroundColor =
|
|
|
|
ConvertAndroidColor(uint32_t(ae->RangeForeColor()));
|
|
|
|
range.mRangeStyle.mBackgroundColor =
|
|
|
|
ConvertAndroidColor(uint32_t(ae->RangeBackColor()));
|
2012-12-06 11:35:59 -08:00
|
|
|
range.mRangeStyle.mUnderlineColor =
|
|
|
|
ConvertAndroidColor(uint32_t(ae->RangeLineColor()));
|
2012-11-01 13:11:02 -07:00
|
|
|
mIMERanges.AppendElement(range);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
2012-11-01 13:11:02 -07:00
|
|
|
break;
|
|
|
|
case AndroidGeckoEvent::IME_UPDATE_COMPOSITION:
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-11-01 13:11:02 -07:00
|
|
|
/*
|
|
|
|
Update the composition from ae->Start() to ae->End() using
|
|
|
|
information from added ranges. This is only used for
|
|
|
|
visual indication and does not affect the text content.
|
|
|
|
Only the offsets are specified and not the text content
|
|
|
|
to eliminate the possibility of this event altering the
|
|
|
|
text content unintentionally.
|
|
|
|
|
|
|
|
Selection and text updates are masked so the result of
|
|
|
|
temporary events are not passed on to Java
|
|
|
|
*/
|
2012-11-01 13:11:03 -07:00
|
|
|
AutoIMEMask selMask(mIMEMaskSelectionUpdate);
|
|
|
|
AutoIMEMask textMask(mIMEMaskTextUpdate);
|
2012-11-01 13:11:02 -07:00
|
|
|
RemoveIMEComposition();
|
2010-08-04 12:47:26 -07:00
|
|
|
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent event(true, NS_TEXT_TEXT, this);
|
2012-07-30 07:20:58 -07:00
|
|
|
InitEvent(event, nullptr);
|
2010-08-04 12:47:26 -07:00
|
|
|
|
|
|
|
event.rangeArray = mIMERanges.Elements();
|
|
|
|
event.rangeCount = mIMERanges.Length();
|
|
|
|
|
2012-11-01 13:11:02 -07:00
|
|
|
{
|
2013-10-01 00:23:01 -07:00
|
|
|
WidgetSelectionEvent event(true, NS_SELECTION_SET, this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(event, nullptr);
|
|
|
|
event.mOffset = uint32_t(ae->Start());
|
|
|
|
event.mLength = uint32_t(ae->End() - ae->Start());
|
|
|
|
event.mExpandToClusterBoundary = false;
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
{
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetQueryContentEvent queryEvent(true,
|
|
|
|
NS_QUERY_SELECTED_TEXT,
|
|
|
|
this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(queryEvent, nullptr);
|
|
|
|
DispatchEvent(&queryEvent);
|
|
|
|
MOZ_ASSERT(queryEvent.mSucceeded && !queryEvent.mWasAsync);
|
|
|
|
event.theText = queryEvent.mReply.mString;
|
|
|
|
}
|
|
|
|
{
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent event(true, NS_COMPOSITION_START, this);
|
2012-11-01 13:11:02 -07:00
|
|
|
InitEvent(event, nullptr);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2011-09-22 02:17:40 -07:00
|
|
|
if (mIMEComposing &&
|
2012-11-01 13:11:02 -07:00
|
|
|
event.theText != mIMEComposingText) {
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent compositionUpdate(true,
|
|
|
|
NS_COMPOSITION_UPDATE,
|
|
|
|
this);
|
2012-07-30 07:20:58 -07:00
|
|
|
InitEvent(compositionUpdate, nullptr);
|
2011-09-22 02:17:40 -07:00
|
|
|
compositionUpdate.data = event.theText;
|
|
|
|
DispatchEvent(&compositionUpdate);
|
2011-11-22 12:31:49 -08:00
|
|
|
if (Destroyed())
|
|
|
|
return;
|
2011-09-22 02:17:40 -07:00
|
|
|
}
|
|
|
|
|
2012-06-01 09:48:13 -07:00
|
|
|
#ifdef DEBUG_ANDROID_IME
|
|
|
|
const NS_ConvertUTF16toUTF8 theText8(event.theText);
|
|
|
|
const char* text = theText8.get();
|
|
|
|
ALOGIME("IME: IME_SET_TEXT: text=\"%s\", length=%u, range=%u",
|
|
|
|
text, event.theText.Length(), mIMERanges.Length());
|
|
|
|
#endif // DEBUG_ANDROID_IME
|
2010-08-04 12:47:26 -07:00
|
|
|
|
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
|
|
|
}
|
2012-11-01 13:11:02 -07:00
|
|
|
break;
|
|
|
|
case AndroidGeckoEvent::IME_REMOVE_COMPOSITION:
|
Backout 533faa3c50ed, 718abc1bd4ad, af2d5272c06b, ad5554e1345d, c9ef1b41b829, d3a825311d11, 0a51bcb3eb9e, a01a327e8ec4, 973b0ed30b8b, 39851bbcfaa1 & a92d2d2a3b0e (bug 805162), d4884aab5ce6, 06fcbaf40cb4, daccc3fe7c70, 881eb2a2906e, 76232441ae06, 01ae34fa1b3f & 5f405fc4e323 (bug 783092), a03d8d4db1c2, 49beb3801192, 174634554a97, 0bd27e755a83, 19e8f151ca67, a6604e038bc0, ed3b8237e76e & 082cf8d72554 (bug 785945) for bustage or conflicting with backout of said bustage on a CLOSED TREE
2012-10-31 17:16:35 -07:00
|
|
|
{
|
2013-02-18 11:06:04 -08:00
|
|
|
/*
|
|
|
|
* Remove any previous composition. This is only used for
|
|
|
|
* visual indication and does not affect the text content.
|
|
|
|
*
|
|
|
|
* Selection and text updates are masked so the result of
|
|
|
|
* temporary events are not passed on to Java
|
|
|
|
*/
|
|
|
|
AutoIMEMask selMask(mIMEMaskSelectionUpdate);
|
|
|
|
AutoIMEMask textMask(mIMEMaskTextUpdate);
|
2012-11-01 13:11:02 -07:00
|
|
|
RemoveIMEComposition();
|
|
|
|
mIMERanges.Clear();
|
Backout 533faa3c50ed, 718abc1bd4ad, af2d5272c06b, ad5554e1345d, c9ef1b41b829, d3a825311d11, 0a51bcb3eb9e, a01a327e8ec4, 973b0ed30b8b, 39851bbcfaa1 & a92d2d2a3b0e (bug 805162), d4884aab5ce6, 06fcbaf40cb4, daccc3fe7c70, 881eb2a2906e, 76232441ae06, 01ae34fa1b3f & 5f405fc4e323 (bug 783092), a03d8d4db1c2, 49beb3801192, 174634554a97, 0bd27e755a83, 19e8f151ca67, a6604e038bc0, ed3b8237e76e & 082cf8d72554 (bug 785945) for bustage or conflicting with backout of said bustage on a CLOSED TREE
2012-10-31 17:16:35 -07:00
|
|
|
}
|
2012-11-01 13:11:02 -07:00
|
|
|
break;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow *
|
|
|
|
nsWindow::FindWindowForPoint(const nsIntPoint& pt)
|
|
|
|
{
|
|
|
|
if (!mBounds.Contains(pt))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
// children mBounds are relative to their parent
|
|
|
|
nsIntPoint childPoint(pt.x - mBounds.x, pt.y - mBounds.y);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mChildren.Length(); ++i) {
|
2010-06-03 13:56:36 -07:00
|
|
|
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) {
|
2012-06-29 01:32:21 -07:00
|
|
|
mIdleService->ResetIdleTimeOut(0);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 12:47:26 -07:00
|
|
|
NS_IMETHODIMP
|
2013-03-05 22:14:34 -08:00
|
|
|
nsWindow::NotifyIME(NotificationToIME aNotification)
|
2010-08-04 12:47:26 -07:00
|
|
|
{
|
2013-03-05 22:14:34 -08:00
|
|
|
switch (aNotification) {
|
|
|
|
case REQUEST_TO_COMMIT_COMPOSITION:
|
|
|
|
//ALOGIME("IME: REQUEST_TO_COMMIT_COMPOSITION: s=%d", aState);
|
|
|
|
RemoveIMEComposition();
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIME(REQUEST_TO_COMMIT_COMPOSITION);
|
2013-03-05 22:14:34 -08:00
|
|
|
return NS_OK;
|
|
|
|
case REQUEST_TO_CANCEL_COMPOSITION:
|
|
|
|
ALOGIME("IME: REQUEST_TO_CANCEL_COMPOSITION");
|
|
|
|
|
|
|
|
// Cancel composition on Gecko side
|
|
|
|
if (mIMEComposing) {
|
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent textEvent(true, NS_TEXT_TEXT, this);
|
2013-03-05 22:14:34 -08:00
|
|
|
InitEvent(textEvent, nullptr);
|
|
|
|
DispatchEvent(&textEvent);
|
|
|
|
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent compEvent(true, NS_COMPOSITION_END,
|
|
|
|
this);
|
2013-03-05 22:14:34 -08:00
|
|
|
InitEvent(compEvent, nullptr);
|
|
|
|
DispatchEvent(&compEvent);
|
|
|
|
}
|
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIME(REQUEST_TO_CANCEL_COMPOSITION);
|
2013-03-05 22:14:34 -08:00
|
|
|
return NS_OK;
|
|
|
|
case NOTIFY_IME_OF_FOCUS:
|
|
|
|
ALOGIME("IME: NOTIFY_IME_OF_FOCUS");
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIME(NOTIFY_IME_OF_FOCUS);
|
2013-03-05 22:14:34 -08:00
|
|
|
return NS_OK;
|
|
|
|
case NOTIFY_IME_OF_BLUR:
|
|
|
|
ALOGIME("IME: NOTIFY_IME_OF_BLUR");
|
|
|
|
|
|
|
|
// Mask events because we lost focus. On the next focus event,
|
|
|
|
// Gecko will notify Java, and Java will send an acknowledge focus
|
|
|
|
// event back to Gecko. That is where we unmask event handling
|
|
|
|
mIMEMaskEventsCount++;
|
|
|
|
mIMEComposing = false;
|
|
|
|
mIMEComposingText.Truncate();
|
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIME(NOTIFY_IME_OF_BLUR);
|
2013-03-05 22:14:34 -08:00
|
|
|
return NS_OK;
|
|
|
|
case NOTIFY_IME_OF_SELECTION_CHANGE:
|
|
|
|
if (mIMEMaskSelectionUpdate) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALOGIME("IME: NOTIFY_IME_OF_SELECTION_CHANGE");
|
|
|
|
|
|
|
|
PostFlushIMEChanges();
|
|
|
|
mIMESelectionChanged = true;
|
|
|
|
return NS_OK;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2010-08-04 12:47:26 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsWindow::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2013-03-27 08:32:34 -07:00
|
|
|
nsWindow *top = TopWindow();
|
|
|
|
if (top && top->mFocus && this != top->mFocus) {
|
|
|
|
// We are using an IME event later to notify Java, and the IME event
|
|
|
|
// will be processed by the focused window. Therefore, to ensure the
|
|
|
|
// IME event uses the correct mInputContext, we need to let the focused
|
|
|
|
// window process SetInputContext
|
|
|
|
top->mFocus->SetInputContext(aContext, aAction);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:53 -08: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 12:47:26 -07:00
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
mInputContext = aContext;
|
2011-04-20 05:47:40 -07:00
|
|
|
|
|
|
|
// Ensure that opening the virtual keyboard is allowed for this specific
|
2011-11-27 03:51:52 -08:00
|
|
|
// InputContext depending on the content.ime.strict.policy pref
|
2011-11-27 03:51:53 -08:00
|
|
|
if (aContext.mIMEState.mEnabled != IMEState::DISABLED &&
|
|
|
|
aContext.mIMEState.mEnabled != IMEState::PLUGIN &&
|
2011-11-27 03:51:52 -08:00
|
|
|
Preferences::GetBool("content.ime.strict_policy", false) &&
|
2011-11-27 03:51:53 -08:00
|
|
|
!aAction.ContentGotFocusByTrustedCause() &&
|
|
|
|
!aAction.UserMightRequestOpenVKB()) {
|
2011-11-27 03:51:52 -08:00
|
|
|
return;
|
2011-04-20 05:47:40 -07:00
|
|
|
}
|
|
|
|
|
2013-03-05 07:24:35 -08:00
|
|
|
IMEState::Enabled enabled = aContext.mIMEState.mEnabled;
|
2012-05-24 08:03:07 -07:00
|
|
|
|
|
|
|
// 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) {
|
2013-03-05 07:24:35 -08:00
|
|
|
enabled = IMEState::DISABLED;
|
2012-05-24 08:03:07 -07:00
|
|
|
}
|
|
|
|
|
2013-03-05 07:24:35 -08:00
|
|
|
mInputContext.mIMEState.mEnabled = enabled;
|
|
|
|
|
2013-08-14 08:32:44 -07:00
|
|
|
if (enabled == IMEState::ENABLED && aAction.UserMightRequestOpenVKB()) {
|
|
|
|
// Don't reset keyboard when we should simply open the vkb
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIME(AndroidBridge::NOTIFY_IME_OPEN_VKB);
|
2013-08-14 08:32:44 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-05 07:24:35 -08:00
|
|
|
if (mIMEUpdatingContext) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-17 14:39:12 -07:00
|
|
|
AndroidGeckoEvent *event = AndroidGeckoEvent::MakeIMEEvent(
|
2013-03-05 07:24:35 -08:00
|
|
|
AndroidGeckoEvent::IME_UPDATE_CONTEXT);
|
|
|
|
nsAppShell::gAppShell->PostEvent(event);
|
|
|
|
mIMEUpdatingContext = true;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
NS_IMETHODIMP_(InputContext)
|
|
|
|
nsWindow::GetInputContext()
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2013-03-27 08:32:34 -07:00
|
|
|
nsWindow *top = TopWindow();
|
|
|
|
if (top && top->mFocus && this != top->mFocus) {
|
|
|
|
// We let the focused window process SetInputContext,
|
|
|
|
// so we should let it process GetInputContext as well.
|
|
|
|
return top->mFocus->GetInputContext();
|
|
|
|
}
|
|
|
|
InputContext context = mInputContext;
|
|
|
|
context.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
|
2012-10-26 16:35:21 -07:00
|
|
|
// We assume that there is only one context per process on Android
|
2013-03-27 08:32:34 -07:00
|
|
|
context.mNativeIMEContext = nullptr;
|
|
|
|
return context;
|
2010-08-04 12:47:26 -07:00
|
|
|
}
|
|
|
|
|
2012-12-05 08:09:56 -08:00
|
|
|
void
|
|
|
|
nsWindow::PostFlushIMEChanges()
|
|
|
|
{
|
2013-01-09 08:57:48 -08:00
|
|
|
if (!mIMETextChanges.IsEmpty() || mIMESelectionChanged) {
|
2012-12-05 08:09:56 -08:00
|
|
|
// Already posted
|
|
|
|
return;
|
|
|
|
}
|
2013-04-17 14:39:12 -07:00
|
|
|
AndroidGeckoEvent *event = AndroidGeckoEvent::MakeIMEEvent(
|
|
|
|
AndroidGeckoEvent::IME_FLUSH_CHANGES);
|
2012-12-05 08:09:56 -08:00
|
|
|
nsAppShell::gAppShell->PostEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::FlushIMEChanges()
|
|
|
|
{
|
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip(this);
|
|
|
|
for (uint32_t i = 0; i < mIMETextChanges.Length(); i++) {
|
|
|
|
IMEChange &change = mIMETextChanges[i];
|
|
|
|
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetQueryContentEvent event(true, NS_QUERY_TEXT_CONTENT, this);
|
2012-12-05 08:09:56 -08:00
|
|
|
InitEvent(event, nullptr);
|
|
|
|
event.InitForQueryTextContent(change.mStart,
|
|
|
|
change.mNewEnd - change.mStart);
|
|
|
|
DispatchEvent(&event);
|
|
|
|
if (!event.mSucceeded)
|
|
|
|
return;
|
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIMEChange(event.mReply.mString,
|
2012-12-05 08:09:56 -08:00
|
|
|
change.mStart,
|
|
|
|
change.mOldEnd,
|
|
|
|
change.mNewEnd);
|
|
|
|
}
|
|
|
|
mIMETextChanges.Clear();
|
|
|
|
|
2013-01-09 08:57:48 -08:00
|
|
|
if (mIMESelectionChanged) {
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetQueryContentEvent event(true, NS_QUERY_SELECTED_TEXT, this);
|
2013-01-09 08:57:48 -08:00
|
|
|
InitEvent(event, nullptr);
|
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
if (!event.mSucceeded)
|
|
|
|
return;
|
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoAppShell::NotifyIMEChange(EmptyString(),
|
2013-09-09 05:57:36 -07:00
|
|
|
(int32_t) event.GetSelectionStart(),
|
|
|
|
(int32_t) event.GetSelectionEnd(), -1);
|
2013-01-09 08:57:48 -08:00
|
|
|
mIMESelectionChanged = false;
|
2012-12-05 08:09:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 12:47:26 -07:00
|
|
|
NS_IMETHODIMP
|
2013-03-05 22:14:34 -08:00
|
|
|
nsWindow::NotifyIMEOfTextChange(uint32_t aStart,
|
|
|
|
uint32_t aOldEnd,
|
|
|
|
uint32_t aNewEnd)
|
2010-08-04 12:47:26 -07:00
|
|
|
{
|
2012-11-01 13:11:02 -07:00
|
|
|
if (mIMEMaskTextUpdate)
|
Backout 533faa3c50ed, 718abc1bd4ad, af2d5272c06b, ad5554e1345d, c9ef1b41b829, d3a825311d11, 0a51bcb3eb9e, a01a327e8ec4, 973b0ed30b8b, 39851bbcfaa1 & a92d2d2a3b0e (bug 805162), d4884aab5ce6, 06fcbaf40cb4, daccc3fe7c70, 881eb2a2906e, 76232441ae06, 01ae34fa1b3f & 5f405fc4e323 (bug 783092), a03d8d4db1c2, 49beb3801192, 174634554a97, 0bd27e755a83, 19e8f151ca67, a6604e038bc0, ed3b8237e76e & 082cf8d72554 (bug 785945) for bustage or conflicting with backout of said bustage on a CLOSED TREE
2012-10-31 17:16:35 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2013-03-05 22:14:34 -08:00
|
|
|
ALOGIME("IME: NotifyIMEOfTextChange: s=%d, oe=%d, ne=%d",
|
2012-11-01 13:11:02 -07:00
|
|
|
aStart, aOldEnd, aNewEnd);
|
Backout 533faa3c50ed, 718abc1bd4ad, af2d5272c06b, ad5554e1345d, c9ef1b41b829, d3a825311d11, 0a51bcb3eb9e, a01a327e8ec4, 973b0ed30b8b, 39851bbcfaa1 & a92d2d2a3b0e (bug 805162), d4884aab5ce6, 06fcbaf40cb4, daccc3fe7c70, 881eb2a2906e, 76232441ae06, 01ae34fa1b3f & 5f405fc4e323 (bug 783092), a03d8d4db1c2, 49beb3801192, 174634554a97, 0bd27e755a83, 19e8f151ca67, a6604e038bc0, ed3b8237e76e & 082cf8d72554 (bug 785945) for bustage or conflicting with backout of said bustage on a CLOSED TREE
2012-10-31 17:16:35 -07:00
|
|
|
|
2012-11-01 13:11:03 -07:00
|
|
|
/* Make sure Java's selection is up-to-date */
|
2013-01-09 08:57:48 -08:00
|
|
|
mIMESelectionChanged = false;
|
2013-03-05 22:14:34 -08:00
|
|
|
NotifyIME(NOTIFY_IME_OF_SELECTION_CHANGE);
|
2012-12-05 08:09:56 -08:00
|
|
|
PostFlushIMEChanges();
|
|
|
|
|
|
|
|
mIMETextChanges.AppendElement(IMEChange(aStart, aOldEnd, aNewEnd));
|
|
|
|
// Now that we added a new range we need to go back and
|
|
|
|
// update all the ranges before that.
|
|
|
|
// Ranges that have offsets which follow this new range
|
|
|
|
// need to be updated to reflect new offsets
|
|
|
|
int32_t delta = (int32_t)(aNewEnd - aOldEnd);
|
|
|
|
for (int32_t i = mIMETextChanges.Length() - 2; i >= 0; i--) {
|
|
|
|
IMEChange &previousChange = mIMETextChanges[i];
|
|
|
|
if (previousChange.mStart > (int32_t)aOldEnd) {
|
|
|
|
previousChange.mStart += delta;
|
|
|
|
previousChange.mOldEnd += delta;
|
|
|
|
previousChange.mNewEnd += delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now go through all ranges to merge any ranges that are connected
|
|
|
|
// srcIndex is the index of the range to merge from
|
|
|
|
// dstIndex is the index of the range to potentially merge into
|
|
|
|
int32_t srcIndex = mIMETextChanges.Length() - 1;
|
|
|
|
int32_t dstIndex = srcIndex;
|
|
|
|
|
|
|
|
while (--dstIndex >= 0) {
|
|
|
|
IMEChange &src = mIMETextChanges[srcIndex];
|
|
|
|
IMEChange &dst = mIMETextChanges[dstIndex];
|
|
|
|
// When merging a more recent change into an older
|
|
|
|
// change, we need to compare recent change's (start, oldEnd)
|
|
|
|
// range to the older change's (start, newEnd)
|
|
|
|
if (src.mOldEnd < dst.mStart || dst.mNewEnd < src.mStart) {
|
|
|
|
// No overlap between ranges
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// When merging two ranges, there are generally four posibilities:
|
|
|
|
// [----(----]----), (----[----]----),
|
|
|
|
// [----(----)----], (----[----)----]
|
|
|
|
// where [----] is the first range and (----) is the second range
|
|
|
|
// As seen above, the start of the merged range is always the lesser
|
|
|
|
// of the two start offsets. OldEnd and NewEnd then need to be
|
|
|
|
// adjusted separately depending on the case. In any case, the change
|
|
|
|
// in text length of the merged range should be the sum of text length
|
|
|
|
// changes of the two original ranges, i.e.,
|
|
|
|
// newNewEnd - newOldEnd == newEnd1 - oldEnd1 + newEnd2 - oldEnd2
|
|
|
|
dst.mStart = std::min(dst.mStart, src.mStart);
|
|
|
|
if (src.mOldEnd < dst.mNewEnd) {
|
|
|
|
// New range overlaps or is within previous range; merge
|
|
|
|
dst.mNewEnd += src.mNewEnd - src.mOldEnd;
|
|
|
|
} else { // src.mOldEnd >= dst.mNewEnd
|
|
|
|
// New range overlaps previous range; merge
|
|
|
|
dst.mOldEnd += src.mOldEnd - dst.mNewEnd;
|
|
|
|
dst.mNewEnd = src.mNewEnd;
|
|
|
|
}
|
|
|
|
// src merged to dst; delete src.
|
|
|
|
mIMETextChanges.RemoveElementAt(srcIndex);
|
|
|
|
// Any ranges that we skip over between src and dst are not mergeable
|
|
|
|
// so we can safely continue the merge starting at dst
|
|
|
|
srcIndex = dstIndex;
|
|
|
|
}
|
2010-08-04 12:47:26 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-23 20:28:15 -07:00
|
|
|
nsIMEUpdatePreference
|
|
|
|
nsWindow::GetIMEUpdatePreference()
|
|
|
|
{
|
2013-07-11 00:46:34 -07:00
|
|
|
int8_t notifications = (nsIMEUpdatePreference::NOTIFY_SELECTION_CHANGE |
|
|
|
|
nsIMEUpdatePreference::NOTIFY_TEXT_CHANGE);
|
|
|
|
return nsIMEUpdatePreference(notifications, true);
|
2010-09-23 20:28:15 -07:00
|
|
|
}
|
|
|
|
|
2012-02-09 19:47:50 -08:00
|
|
|
void
|
2013-12-08 17:40:59 -08:00
|
|
|
nsWindow::DrawWindowUnderlay(LayerManagerComposite* aManager, nsIntRect aRect)
|
2012-05-04 08:08:47 -07:00
|
|
|
{
|
2012-07-13 14:34:58 -07:00
|
|
|
JNIEnv *env = GetJNIForThread();
|
2012-02-10 23:03:02 -08:00
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2012-02-10 23:03:02 -08:00
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoLayerClient* client = AndroidBridge::Bridge()->GetLayerClient();
|
|
|
|
if (!client || client->isNull()) {
|
|
|
|
ALOG_BRIDGE("Exceptional Exit: %s", __PRETTY_FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject frameObj = client->CreateFrame();
|
|
|
|
NS_ABORT_IF_FALSE(frameObj, "No frame object!");
|
|
|
|
if (!frameObj) {
|
|
|
|
ALOG_BRIDGE("Exceptional Exit: %s", __PRETTY_FUNCTION__);
|
2013-11-12 10:41:01 -08:00
|
|
|
return;
|
2013-11-12 10:41:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
mLayerRendererFrame.Init(env, frameObj);
|
|
|
|
if (!WidgetPaintsBackground()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-12 10:41:01 -08:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
gl::GLContext* gl = static_cast<CompositorOGL*>(aManager->GetCompositor())->gl();
|
|
|
|
gl::ScopedGLState scopedScissorTestState(gl, LOCAL_GL_SCISSOR_TEST);
|
|
|
|
gl::ScopedScissorRect scopedScissorRectState(gl);
|
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
client->ActivateProgram();
|
2013-11-19 07:56:09 -08:00
|
|
|
if (!mLayerRendererFrame.BeginDrawing(&jniFrame)) return;
|
|
|
|
if (!mLayerRendererFrame.DrawBackground(&jniFrame)) return;
|
2013-11-12 10:41:01 -08:00
|
|
|
client->DeactivateProgram(); // redundant, but in case somebody adds code after this...
|
2012-02-09 19:47:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-12-08 17:40:59 -08:00
|
|
|
nsWindow::DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect)
|
2012-05-04 08:08:47 -07:00
|
|
|
{
|
2013-09-23 06:33:31 -07:00
|
|
|
PROFILER_LABEL("nsWindow", "DrawWindowOverlay");
|
2013-11-19 07:56:09 -08:00
|
|
|
JNIEnv *env = GetJNIForThread();
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2012-05-04 08:08:47 -07:00
|
|
|
|
2012-02-09 23:55:13 -08:00
|
|
|
NS_ABORT_IF_FALSE(!mLayerRendererFrame.isNull(),
|
|
|
|
"Frame should have been created in DrawWindowUnderlay()!");
|
2012-02-10 23:03:02 -08:00
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
GeckoLayerClient* client = AndroidBridge::Bridge()->GetLayerClient();
|
2012-02-13 14:52:30 -08:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
gl::GLContext* gl = static_cast<CompositorOGL*>(aManager->GetCompositor())->gl();
|
|
|
|
gl::ScopedGLState scopedScissorTestState(gl, LOCAL_GL_SCISSOR_TEST);
|
|
|
|
gl::ScopedScissorRect scopedScissorRectState(gl);
|
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
client->ActivateProgram();
|
2013-11-19 07:56:09 -08:00
|
|
|
if (!mLayerRendererFrame.DrawForeground(&jniFrame)) return;
|
|
|
|
if (!mLayerRendererFrame.EndDrawing(&jniFrame)) return;
|
2013-11-12 10:41:01 -08:00
|
|
|
client->DeactivateProgram();
|
2013-11-19 07:56:09 -08:00
|
|
|
mLayerRendererFrame.Dispose(env);
|
2012-02-09 19:47:50 -08:00
|
|
|
}
|
2012-03-13 21:15:11 -07:00
|
|
|
|
|
|
|
// off-main-thread compositor fields and functions
|
|
|
|
|
2013-08-13 06:32:03 -07:00
|
|
|
StaticRefPtr<mozilla::layers::APZCTreeManager> nsWindow::sApzcTreeManager;
|
|
|
|
StaticRefPtr<mozilla::layers::LayerManager> nsWindow::sLayerManager;
|
|
|
|
StaticRefPtr<mozilla::layers::CompositorParent> nsWindow::sCompositorParent;
|
|
|
|
StaticRefPtr<mozilla::layers::CompositorChild> nsWindow::sCompositorChild;
|
2013-02-28 10:28:23 -08:00
|
|
|
bool nsWindow::sCompositorPaused = true;
|
2012-03-13 21:15:11 -07:00
|
|
|
|
|
|
|
void
|
2013-01-10 08:21:10 -08:00
|
|
|
nsWindow::SetCompositor(mozilla::layers::LayerManager* aLayerManager,
|
|
|
|
mozilla::layers::CompositorParent* aCompositorParent,
|
2012-07-13 08:25:29 -07:00
|
|
|
mozilla::layers::CompositorChild* aCompositorChild)
|
2012-03-13 21:15:11 -07:00
|
|
|
{
|
2013-01-10 08:21:10 -08:00
|
|
|
sLayerManager = aLayerManager;
|
2012-03-13 21:15:11 -07:00
|
|
|
sCompositorParent = aCompositorParent;
|
2012-03-28 15:00:32 -07:00
|
|
|
sCompositorChild = aCompositorChild;
|
2012-03-13 21:15:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::ScheduleComposite()
|
|
|
|
{
|
|
|
|
if (sCompositorParent) {
|
|
|
|
sCompositorParent->ScheduleRenderOnCompositorThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-04-20 08:46:30 -07:00
|
|
|
nsWindow::ScheduleResumeComposition(int width, int height)
|
2012-03-13 21:15:11 -07:00
|
|
|
{
|
2013-01-10 08:21:10 -08:00
|
|
|
if (sCompositorParent && sCompositorParent->ScheduleResumeOnCompositorThread(width, height)) {
|
|
|
|
sCompositorPaused = false;
|
2012-03-13 21:15:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 12:13:17 -08:00
|
|
|
void
|
|
|
|
nsWindow::ForceIsFirstPaint()
|
|
|
|
{
|
|
|
|
if (sCompositorParent) {
|
|
|
|
sCompositorParent->ForceIsFirstPaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 09:23:47 -07:00
|
|
|
float
|
|
|
|
nsWindow::ComputeRenderIntegrity()
|
|
|
|
{
|
|
|
|
if (sCompositorParent) {
|
2013-12-08 17:40:59 -08:00
|
|
|
return sCompositorParent->ComputeRenderIntegrity();
|
2012-10-25 09:23:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1.f;
|
|
|
|
}
|
|
|
|
|
2012-08-28 22:48:43 -07:00
|
|
|
bool
|
|
|
|
nsWindow::WidgetPaintsBackground()
|
|
|
|
{
|
|
|
|
static bool sWidgetPaintsBackground = true;
|
|
|
|
static bool sWidgetPaintsBackgroundPrefCached = false;
|
|
|
|
|
|
|
|
if (!sWidgetPaintsBackgroundPrefCached) {
|
|
|
|
sWidgetPaintsBackgroundPrefCached = true;
|
|
|
|
mozilla::Preferences::AddBoolVarCache(&sWidgetPaintsBackground,
|
|
|
|
"android.widget_paints_background",
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sWidgetPaintsBackground;
|
|
|
|
}
|
|
|
|
|
2012-08-13 03:10:10 -07:00
|
|
|
bool
|
|
|
|
nsWindow::NeedsPaint()
|
|
|
|
{
|
2013-03-14 04:17:49 -07:00
|
|
|
if (sCompositorPaused || FindTopLevel() != nsWindow::TopWindow() || !GetLayerManager(nullptr)) {
|
2012-08-13 03:10:10 -07:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-22 21:46:36 -08:00
|
|
|
return nsIWidget::NeedsPaint();
|
2012-08-13 03:10:10 -07:00
|
|
|
}
|
|
|
|
|
2013-04-26 10:24:28 -07:00
|
|
|
CompositorParent*
|
2013-04-17 14:39:13 -07:00
|
|
|
nsWindow::NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight)
|
|
|
|
{
|
2013-07-30 11:03:40 -07:00
|
|
|
return new CompositorParent(this, true, aSurfaceWidth, aSurfaceHeight);
|
2013-04-17 14:39:13 -07:00
|
|
|
}
|
2013-07-30 11:03:43 -07:00
|
|
|
|
|
|
|
mozilla::layers::APZCTreeManager*
|
|
|
|
nsWindow::GetAPZCTreeManager()
|
|
|
|
{
|
|
|
|
if (!sApzcTreeManager) {
|
|
|
|
CompositorParent* compositor = sCompositorParent;
|
|
|
|
if (!compositor) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
uint64_t rootLayerTreeId = compositor->RootLayerTreeId();
|
|
|
|
CompositorParent::SetControllerForLayerTree(rootLayerTreeId, AndroidBridge::Bridge());
|
|
|
|
sApzcTreeManager = CompositorParent::GetAPZCTreeManager(rootLayerTreeId);
|
|
|
|
}
|
|
|
|
return sApzcTreeManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
nsWindow::RootLayerTreeId()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(sCompositorParent);
|
|
|
|
return sCompositorParent->RootLayerTreeId();
|
|
|
|
}
|