mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 600880 - Fix screen.width and screen.height on Android. r=cjones a=blocking-fennec
This commit is contained in:
parent
605c2ac798
commit
9f58935c14
@ -201,6 +201,9 @@ ConsoleListener::Observe(nsIConsoleMessage* aMessage)
|
||||
ContentChild* ContentChild::sSingleton;
|
||||
|
||||
ContentChild::ContentChild()
|
||||
#ifdef ANDROID
|
||||
: mScreenSize(0, 0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
@ -570,5 +573,16 @@ ContentChild::RecvAccelerationChanged(const double& x, const double& y,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::RecvScreenSizeChanged(const gfxIntSize& size)
|
||||
{
|
||||
#ifdef ANDROID
|
||||
mScreenSize = size;
|
||||
#else
|
||||
NS_RUNTIMEABORT("Message currently only expected on android");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -130,6 +130,11 @@ public:
|
||||
virtual bool RecvAccelerationChanged(const double& x, const double& y,
|
||||
const double& z);
|
||||
|
||||
virtual bool RecvScreenSizeChanged(const gfxIntSize &size);
|
||||
#ifdef ANDROID
|
||||
gfxIntSize GetScreenSize() { return mScreenSize; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
NS_OVERRIDE
|
||||
virtual void ActorDestroy(ActorDestroyReason why);
|
||||
@ -145,6 +150,9 @@ private:
|
||||
|
||||
InfallibleTArray<nsAutoPtr<AlertObserver> > mAlertObservers;
|
||||
nsRefPtr<ConsoleListener> mConsoleListener;
|
||||
#ifdef ANDROID
|
||||
gfxIntSize mScreenSize;
|
||||
#endif
|
||||
|
||||
static ContentChild* sSingleton;
|
||||
|
||||
|
@ -124,6 +124,9 @@ ContentParent::GetSingleton(PRBool aForceNew)
|
||||
threadInt->GetObserver(getter_AddRefs(parent->mOldObserver));
|
||||
threadInt->SetObserver(parent);
|
||||
}
|
||||
if (obs) {
|
||||
obs->NotifyObservers(nsnull, "ipc:content-created", nsnull);
|
||||
}
|
||||
}
|
||||
}
|
||||
return gSingleton;
|
||||
|
@ -59,6 +59,7 @@ using OverrideMapping;
|
||||
using IPC::URI;
|
||||
using IPC::Permission;
|
||||
using mozilla::null_t;
|
||||
using gfxIntSize;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -113,6 +114,8 @@ child:
|
||||
|
||||
AccelerationChanged(double x, double y, double z);
|
||||
|
||||
ScreenSizeChanged(gfxIntSize size);
|
||||
|
||||
parent:
|
||||
PNecko();
|
||||
PCrashReporter();
|
||||
|
@ -104,3 +104,4 @@ LOCAL_INCLUDES += \
|
||||
-I$(srcdir) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
@ -40,9 +40,20 @@
|
||||
#include <android/log.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef MOZ_IPC
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/unused.h"
|
||||
|
||||
using mozilla::dom::ContentParent;
|
||||
using mozilla::dom::ContentChild;
|
||||
using mozilla::unused;
|
||||
#endif
|
||||
|
||||
#include "nsAppShell.h"
|
||||
#include "nsIdleService.h"
|
||||
#include "nsWindow.h"
|
||||
#include "nsIObserverService.h"
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsIRenderingContext.h"
|
||||
@ -72,6 +83,43 @@ NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
|
||||
// The dimensions of the current android view
|
||||
static gfxIntSize gAndroidBounds;
|
||||
|
||||
#ifdef MOZ_IPC
|
||||
class ContentCreationNotifier;
|
||||
static nsCOMPtr<ContentCreationNotifier> gContentCreationNotifier;
|
||||
// A helper class to send updates when content processes
|
||||
// are created. Currently an update for the screen size is sent.
|
||||
class ContentCreationNotifier : public nsIObserver
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const PRUnichar* aData)
|
||||
{
|
||||
if (!strcmp(aTopic, "ipc:content-created")) {
|
||||
ContentParent *cp = ContentParent::GetSingleton(PR_FALSE);
|
||||
NS_ABORT_IF_FALSE(cp, "Must have content process if notified of its creation");
|
||||
unused << cp->SendScreenSizeChanged(gAndroidBounds);
|
||||
} else if (!strcmp(aTopic, "xpcom-shutdown")) {
|
||||
nsCOMPtr<nsIObserverService>
|
||||
obs(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (obs) {
|
||||
obs->RemoveObserver(static_cast<nsIObserver*>(this),
|
||||
"xpcom-shutdown");
|
||||
obs->RemoveObserver(static_cast<nsIObserver*>(this),
|
||||
"ipc:content-created");
|
||||
}
|
||||
gContentCreationNotifier = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(ContentCreationNotifier,
|
||||
nsIObserver)
|
||||
#endif
|
||||
|
||||
static PRBool gLeftShift;
|
||||
static PRBool gRightShift;
|
||||
static PRBool gLeftAlt;
|
||||
@ -702,6 +750,27 @@ nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
|
||||
gTopLevelWindows[i]->Resize(gAndroidBounds.width, gAndroidBounds.height, PR_TRUE);
|
||||
}
|
||||
|
||||
#ifdef MOZ_IPC
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
if (!gContentCreationNotifier) {
|
||||
nsCOMPtr<nsIObserverService> obs =
|
||||
do_GetService("@mozilla.org/observer-service;1");
|
||||
if (obs) {
|
||||
nsCOMPtr<ContentCreationNotifier> notifier = new ContentCreationNotifier;
|
||||
if (NS_SUCCEEDED(obs->AddObserver(notifier, "ipc:content-created", PR_FALSE))) {
|
||||
if (NS_SUCCEEDED(obs->AddObserver(notifier, "xpcom-shutdown", PR_FALSE)))
|
||||
gContentCreationNotifier = notifier;
|
||||
else {
|
||||
obs->RemoveObserver(notifier, "ipc:content-created");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ContentParent *cp = ContentParent::GetSingleton(PR_FALSE);
|
||||
if (cp)
|
||||
unused << cp->SendScreenSizeChanged(gAndroidBounds);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
@ -982,6 +1051,11 @@ nsWindow::SetInitialAndroidBounds(const gfxIntSize& sz)
|
||||
gfxIntSize
|
||||
nsWindow::GetAndroidBounds()
|
||||
{
|
||||
#ifdef MOZ_IPC
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
return ContentChild::GetSingleton()->GetScreenSize();
|
||||
}
|
||||
#endif
|
||||
return gAndroidBounds;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user