Skip to content

Commit

Permalink
Bug 1282003 - (Part 3) Add screen ID to nsWindow and GeckoView to get…
Browse files Browse the repository at this point in the history
… the correct nsScreen and density. r=snorp

MozReview-Commit-ID: Cd9MS2I1RRQ
  • Loading branch information
kuoe0 committed Sep 29, 2016
1 parent 6545a10 commit c2116ed
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 24 deletions.
11 changes: 10 additions & 1 deletion gfx/src/nsDeviceContext.cpp
Original file line number Diff line number Diff line change
@@ -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/. */
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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/. */
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -114,7 +116,7 @@ private static final class Window extends JNIObject {
/* package */ Window() {}

static native void open(Window instance, GeckoView view, Object compositor,
String chromeURI);
String chromeURI, int screenId);

@Override protected native void disposeNative();
native void close();
Expand Down Expand Up @@ -229,11 +231,11 @@ private void openWindow() {

if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
Window.open(window, this, getCompositor(),
chromeURI);
chromeURI, screenId);
} else {
GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY, Window.class,
"open", window, GeckoView.class, this, Object.class, getCompositor(),
String.class, chromeURI);
String.class, chromeURI, screenId);
}
}

Expand Down
5 changes: 3 additions & 2 deletions widget/android/GeneratedJNIWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3274,10 +3274,11 @@ class GeckoView::Window : public mozilla::jni::ObjectBase<Window>
Window::Param,
GeckoView::Param,
mozilla::jni::Object::Param,
mozilla::jni::String::Param> Args;
mozilla::jni::String::Param,
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;)V";
"(Lorg/mozilla/gecko/GeckoView$Window;Lorg/mozilla/gecko/GeckoView;Ljava/lang/Object;Ljava/lang/String;I)V";
static const bool isStatic = true;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
Expand Down
40 changes: 25 additions & 15 deletions widget/android/nsWindow.cpp
Original file line number Diff line number Diff line change
@@ -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/. */
Expand Down Expand Up @@ -344,7 +345,8 @@ class nsWindow::GeckoViewSupport final
static void Open(const jni::Class::LocalRef& aCls,
GeckoView::Window::Param aWindow,
GeckoView::Param aView, jni::Object::Param aCompositor,
jni::String::Param aChromeURI);
jni::String::Param aChromeURI,
int32_t screenId);

// Close and destroy the nsWindow.
void Close();
Expand Down Expand Up @@ -1318,7 +1320,8 @@ nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
GeckoView::Window::Param aWindow,
GeckoView::Param aView,
jni::Object::Param aCompositor,
jni::String::Param aChromeURI)
jni::String::Param aChromeURI,
int32_t aScreenId)
{
MOZ_ASSERT(NS_IsMainThread());

Expand Down Expand Up @@ -1349,6 +1352,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>(
Expand Down Expand Up @@ -1491,6 +1495,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),
Expand Down Expand Up @@ -1652,19 +1657,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
Expand Down Expand Up @@ -3596,7 +3593,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>
Expand Down
5 changes: 5 additions & 0 deletions widget/android/nsWindow.h
Original file line number Diff line number Diff line change
@@ -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/. */
Expand Down Expand Up @@ -45,8 +46,11 @@ class nsWindow : public nsBaseWidget
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,
Expand Down Expand Up @@ -165,6 +169,7 @@ class nsWindow : public nsBaseWidget
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;
Expand Down
4 changes: 1 addition & 3 deletions widget/nsBaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference
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,
Expand Down Expand Up @@ -339,9 +340,6 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference
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
{
Expand Down
5 changes: 5 additions & 0 deletions widget/nsIWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c2116ed

Please sign in to comment.