зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1286925 - Add orientation change method in GeckoScreenOrientation; r=snorp
Add and use the onOrientationChanged native method in GeckoScreenOrientation in place of the screen orientation event in GeckoEvent.
This commit is contained in:
Родитель
deae801637
Коммит
0d2e7fcb1d
|
@ -5,6 +5,8 @@
|
|||
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.annotation.WrapForJNI;
|
||||
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.util.Log;
|
||||
|
@ -130,6 +132,9 @@ public class GeckoScreenOrientation {
|
|||
return update(getScreenOrientation(aAndroidOrientation, getRotation()));
|
||||
}
|
||||
|
||||
@WrapForJNI
|
||||
private static native void onOrientationChange(short screenOrientation, short angle);
|
||||
|
||||
/*
|
||||
* Update screen orientation given the screen orientation.
|
||||
*
|
||||
|
@ -152,9 +157,13 @@ public class GeckoScreenOrientation {
|
|||
} else if (aScreenOrientation == ScreenOrientation.LANDSCAPE) {
|
||||
aScreenOrientation = ScreenOrientation.LANDSCAPE_PRIMARY;
|
||||
}
|
||||
GeckoAppShell.sendEventToGecko(
|
||||
GeckoEvent.createScreenOrientationEvent(aScreenOrientation.value,
|
||||
getAngle()));
|
||||
|
||||
if (GeckoThread.isRunning()) {
|
||||
onOrientationChange(aScreenOrientation.value, getAngle());
|
||||
} else {
|
||||
GeckoThread.queueNativeCall(GeckoScreenOrientation.class, "onOrientationChange",
|
||||
aScreenOrientation.value, getAngle());
|
||||
}
|
||||
}
|
||||
GeckoAppShell.resetScreenSize();
|
||||
return true;
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* 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/. */
|
||||
|
||||
#ifndef GeckoScreenOrientation_h
|
||||
#define GeckoScreenOrientation_h
|
||||
|
||||
#include "GeneratedJNINatives.h"
|
||||
#include "nsAppShell.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIScreenManager.h"
|
||||
|
||||
#include "mozilla/Hal.h"
|
||||
#include "mozilla/dom/ScreenOrientation.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class GeckoScreenOrientation final
|
||||
: public widget::GeckoScreenOrientation::Natives<GeckoScreenOrientation>
|
||||
, public UsesGeckoThreadProxy
|
||||
{
|
||||
GeckoScreenOrientation() = delete;
|
||||
|
||||
public:
|
||||
static void
|
||||
OnOrientationChange(int16_t aOrientation, int16_t aAngle)
|
||||
{
|
||||
nsCOMPtr<nsIScreenManager> screenMgr =
|
||||
do_GetService("@mozilla.org/gfx/screenmanager;1");
|
||||
nsCOMPtr<nsIScreen> screen;
|
||||
|
||||
if (!screenMgr || NS_FAILED(screenMgr->GetPrimaryScreen(
|
||||
getter_AddRefs(screen))) || !screen) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsIntRect rect;
|
||||
int32_t colorDepth, pixelDepth;
|
||||
|
||||
if (NS_FAILED(screen->GetRect(&rect.x, &rect.y,
|
||||
&rect.width, &rect.height)) ||
|
||||
NS_FAILED(screen->GetColorDepth(&colorDepth)) ||
|
||||
NS_FAILED(screen->GetPixelDepth(&pixelDepth))) {
|
||||
return;
|
||||
}
|
||||
|
||||
hal::NotifyScreenConfigurationChange(hal::ScreenConfiguration(
|
||||
rect, static_cast<dom::ScreenOrientationInternal>(aOrientation),
|
||||
aAngle, colorDepth, pixelDepth));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GeckoScreenOrientation_h
|
|
@ -61,6 +61,7 @@
|
|||
|
||||
#include "ANRReporter.h"
|
||||
#include "GeckoNetworkManager.h"
|
||||
#include "GeckoScreenOrientation.h"
|
||||
#include "PrefsHelper.h"
|
||||
|
||||
#ifdef DEBUG_ANDROID_EVENTS
|
||||
|
@ -386,6 +387,7 @@ nsAppShell::nsAppShell()
|
|||
GeckoThreadSupport::Init();
|
||||
mozilla::ANRReporter::Init();
|
||||
mozilla::GeckoNetworkManager::Init();
|
||||
mozilla::GeckoScreenOrientation::Init();
|
||||
mozilla::PrefsHelper::Init();
|
||||
nsWindow::InitNatives();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче