Bug 1282003 - (Part 3) Add screen ID to nsWindow and GeckoView to get the correct nsScreen and density. r=snorp

MozReview-Commit-ID: Cd9MS2I1RRQ

--HG--
extra : transplant_source : %27%C1%B7R%03%F9%CA%BC%8D%9D%8D%28u%FAU%92%B5%B7%0A%C2
This commit is contained in:
KuoE0 2016-09-29 14:23:56 +08:00
parent 2a9698fad6
commit 55ce4ad9bf
7 changed files with 54 additions and 23 deletions

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 ts=4 expandtab: */
/* 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/. */
@ -611,7 +612,15 @@ nsDeviceContext::FindScreen(nsIScreen** outScreen)
mScreenManager->ScreenForNativeWidget(mWidget->GetNativeData(NS_NATIVE_WINDOW),
outScreen);
}
else {
#ifdef MOZ_WIDGET_ANDROID
if (!(*outScreen)) {
nsCOMPtr<nsIScreen> screen = mWidget->GetWidgetScreen();
screen.forget(outScreen);
}
#endif
if (!(*outScreen)) {
mScreenManager->GetPrimaryScreen(outScreen);
}
}

View File

@ -1,4 +1,5 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* vim: ts=4 sw=4 expandtab:
* 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/. */
@ -48,6 +49,7 @@ public class GeckoView extends LayerView
private InputConnectionListener mInputConnectionListener;
private boolean onAttachedToWindowCalled;
private int screenId = 0; // default to the primary screen
@Override
public void handleMessage(final String event, final JSONObject message) {
@ -114,7 +116,7 @@ public class GeckoView extends LayerView
/* package */ Window() {}
static native void open(Window instance, GeckoView view, Object compositor,
String chromeURI, int width, int height);
String chromeURI, int width, int height, int screenId);
@Override protected native void disposeNative();
native void close();
@ -231,11 +233,12 @@ public class GeckoView extends LayerView
if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
Window.open(window, this, getCompositor(),
chromeURI, metrics.widthPixels, metrics.heightPixels);
chromeURI, metrics.widthPixels, metrics.heightPixels, screenId);
} else {
GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY, Window.class,
"open", window, GeckoView.class, this, Object.class, getCompositor(),
String.class, chromeURI, metrics.widthPixels, metrics.heightPixels);
String.class, chromeURI, metrics.widthPixels, metrics.heightPixels,
screenId);
}
}

View File

@ -3276,10 +3276,11 @@ public:
mozilla::jni::Object::Param,
mozilla::jni::String::Param,
int32_t,
int32_t,
int32_t> Args;
static constexpr char name[] = "open";
static constexpr char signature[] =
"(Lorg/mozilla/gecko/GeckoView$Window;Lorg/mozilla/gecko/GeckoView;Ljava/lang/Object;Ljava/lang/String;II)V";
"(Lorg/mozilla/gecko/GeckoView$Window;Lorg/mozilla/gecko/GeckoView;Ljava/lang/Object;Ljava/lang/String;III)V";
static const bool isStatic = true;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;

View File

@ -1,4 +1,5 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* vim: set sw=4 ts=4 expandtab:
* 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/. */
@ -346,7 +347,8 @@ public:
GeckoView::Window::Param aWindow,
GeckoView::Param aView, jni::Object::Param aCompositor,
jni::String::Param aChromeURI,
int32_t aWidth, int32_t aHeight);
int32_t aWidth, int32_t aHeight,
int32_t screenId);
// Close and destroy the nsWindow.
void Close();
@ -1321,7 +1323,8 @@ nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
GeckoView::Param aView,
jni::Object::Param aCompositor,
jni::String::Param aChromeURI,
int32_t aWidth, int32_t aHeight)
int32_t aWidth, int32_t aHeight,
int32_t aScreenId)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1368,6 +1371,7 @@ nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
MOZ_ASSERT(widget);
const auto window = static_cast<nsWindow*>(widget.get());
window->SetScreenId(aScreenId);
// Attach a new GeckoView support object to the new window.
window->mGeckoViewSupport = mozilla::MakeUnique<GeckoViewSupport>(
@ -1510,6 +1514,7 @@ nsWindow::DumpWindows(const nsTArray<nsWindow*>& wins, int indent)
}
nsWindow::nsWindow() :
mScreenId(0), // Use 0 (primary screen) as the default value.
mIsVisible(false),
mParent(nullptr),
mAwaitingFullScreen(false),
@ -1671,19 +1676,11 @@ nsWindow::GetDPI()
double
nsWindow::GetDefaultScaleInternal()
{
static double density = 0.0;
if (density != 0.0) {
return density;
}
density = GeckoAppShell::GetDensity();
if (!density) {
density = 1.0;
}
return density;
nsCOMPtr<nsIScreen> screen = GetWidgetScreen();
MOZ_ASSERT(screen);
RefPtr<nsScreenAndroid> screenAndroid = (nsScreenAndroid*) screen.get();
return screenAndroid->GetDensity();
}
NS_IMETHODIMP
@ -3615,7 +3612,20 @@ nsWindow::UpdateZoomConstraints(const uint32_t& aPresShellId,
CompositorBridgeParent*
nsWindow::GetCompositorBridgeParent() const
{
return mCompositorSession ? mCompositorSession->GetInProcessBridge() : nullptr;
return mCompositorSession ? mCompositorSession->GetInProcessBridge() : nullptr;
}
already_AddRefed<nsIScreen>
nsWindow::GetWidgetScreen()
{
nsCOMPtr<nsIScreenManager> screenMgr =
do_GetService("@mozilla.org/gfx/screenmanager;1");
MOZ_ASSERT(screenMgr, "Failed to get nsIScreenManager");
nsCOMPtr<nsIScreen> screen;
screenMgr->ScreenForId(mScreenId, getter_AddRefs(screen));
return screen.forget();
}
jni::DependentRef<java::GeckoLayerClient>

View File

@ -1,4 +1,5 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* vim: set sw=4 ts=4 expandtab:
* 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/. */
@ -45,8 +46,11 @@ public:
NS_DECL_ISUPPORTS_INHERITED
static void InitNatives();
void SetScreenId(uint32_t aScreenId) { mScreenId = aScreenId; }
private:
uint32_t mScreenId;
// An Event subclass that guards against stale events.
template<typename Lambda,
bool IsStatic = Lambda::isStatic,
@ -165,6 +169,7 @@ public:
NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
nsEventStatus& aStatus) override;
nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent);
virtual already_AddRefed<nsIScreen> GetWidgetScreen() override;
virtual nsresult MakeFullScreen(bool aFullScreen,
nsIScreen* aTargetScreen = nullptr)
override;

View File

@ -183,6 +183,7 @@ public:
uint16_t aDuration,
nsISupports* aData,
nsIRunnable* aCallback) override;
virtual already_AddRefed<nsIScreen> GetWidgetScreen() override;
virtual nsresult MakeFullScreen(bool aFullScreen,
nsIScreen* aScreen = nullptr) override;
void InfallibleMakeFullScreen(bool aFullScreen,
@ -338,9 +339,6 @@ public:
return aClientSize;
}
// return the screen the widget is in.
already_AddRefed<nsIScreen> GetWidgetScreen();
// return true if this is a popup widget with a native titlebar
bool IsPopupWithTitleBar() const
{

View File

@ -1191,6 +1191,11 @@ class nsIWidget : public nsISupports
nsISupports* aData,
nsIRunnable* aCallback) = 0;
/**
* Return the screen the widget is in, or null if we don't know.
*/
virtual already_AddRefed<nsIScreen> GetWidgetScreen() = 0;
/**
* Put the toplevel window into or out of fullscreen mode.
* If aTargetScreen is given, attempt to go fullscreen on that screen,