зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1757647 - Simplify WindowsUIUtils tablet mode stuff. r=saschanaz
No need for it to use so much XPCOM. Differential Revision: https://phabricator.services.mozilla.com/D139986
This commit is contained in:
Родитель
ef3106ee6b
Коммит
4f96521a7c
|
@ -9,7 +9,7 @@
|
|||
interface mozIDOMWindowProxy;
|
||||
interface imgIContainer;
|
||||
|
||||
[scriptable, uuid(aa8a0ecf-96a1-418c-b80e-f24ae18bbedc)]
|
||||
[scriptable, builtinclass, uuid(aa8a0ecf-96a1-418c-b80e-f24ae18bbedc)]
|
||||
interface nsIWindowsUIUtils : nsISupports
|
||||
{
|
||||
readonly attribute long systemSmallIconSize;
|
||||
|
@ -27,11 +27,6 @@ interface nsIWindowsUIUtils : nsISupports
|
|||
*/
|
||||
readonly attribute boolean inTabletMode;
|
||||
|
||||
/**
|
||||
* Update the tablet mode state
|
||||
*/
|
||||
void updateTabletModeState();
|
||||
|
||||
/**
|
||||
* Share URL
|
||||
*/
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "nsWindow.h"
|
||||
#include "WinUtils.h"
|
||||
#include "nsIWindowsRegKey.h"
|
||||
#include "nsIWindowsUIUtils.h"
|
||||
#include "WindowsUIUtils.h"
|
||||
|
||||
#ifdef ACCESSIBILITY
|
||||
# include "nsAccessibilityService.h"
|
||||
|
@ -944,15 +944,7 @@ bool IMEHandler::IsKeyboardPresentOnSlate() {
|
|||
|
||||
// static
|
||||
bool IMEHandler::IsInTabletMode() {
|
||||
nsCOMPtr<nsIWindowsUIUtils> uiUtils(
|
||||
do_GetService("@mozilla.org/windows-ui-utils;1"));
|
||||
if (NS_WARN_IF(!uiUtils)) {
|
||||
Preferences::SetString(kOskDebugReason,
|
||||
L"IITM: nsIWindowsUIUtils not available.");
|
||||
return false;
|
||||
}
|
||||
bool isInTabletMode = false;
|
||||
uiUtils->GetInTabletMode(&isInTabletMode);
|
||||
bool isInTabletMode = WindowsUIUtils::GetInTabletMode();
|
||||
if (isInTabletMode) {
|
||||
Preferences::SetString(kOskDebugReason, L"IITM: GetInTabletMode=true.");
|
||||
} else {
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "mozilla/WindowsVersion.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsIContentPolicy.h"
|
||||
#include "nsIWindowsUIUtils.h"
|
||||
#include "WindowsUIUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
#include "mozilla/Logging.h"
|
||||
|
@ -1858,17 +1858,6 @@ WinUtils::GetPowerPlatformRole() {
|
|||
return power_determine_platform_role(POWER_PLATFORM_ROLE_V2);
|
||||
}
|
||||
|
||||
static bool IsWindows10TabletMode() {
|
||||
nsCOMPtr<nsIWindowsUIUtils> uiUtils(
|
||||
do_GetService("@mozilla.org/windows-ui-utils;1"));
|
||||
if (NS_WARN_IF(!uiUtils)) {
|
||||
return false;
|
||||
}
|
||||
bool isInTabletMode = false;
|
||||
uiUtils->GetInTabletMode(&isInTabletMode);
|
||||
return isInTabletMode;
|
||||
}
|
||||
|
||||
static bool CallGetAutoRotationState(AR_STATE* aRotationState) {
|
||||
typedef BOOL(WINAPI * GetAutoRotationStateFunc)(PAR_STATE pState);
|
||||
static GetAutoRotationStateFunc get_auto_rotation_state_func =
|
||||
|
@ -1891,7 +1880,7 @@ static bool IsTabletDevice() {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (IsWindows10TabletMode()) {
|
||||
if (WindowsUIUtils::GetInTabletMode()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -134,13 +134,12 @@ IDataPackage4 : public IInspectable {
|
|||
|
||||
using namespace mozilla;
|
||||
|
||||
WindowsUIUtils::WindowsUIUtils() : mInTabletMode(eTabletModeUnknown) {}
|
||||
enum class TabletModeState : uint8_t { Unknown, Off, On };
|
||||
static TabletModeState sInTabletModeState;
|
||||
|
||||
WindowsUIUtils::WindowsUIUtils() = default;
|
||||
WindowsUIUtils::~WindowsUIUtils() = default;
|
||||
|
||||
/*
|
||||
* Implement the nsISupports methods...
|
||||
*/
|
||||
NS_IMPL_ISUPPORTS(WindowsUIUtils, nsIWindowsUIUtils)
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -229,27 +228,31 @@ WindowsUIUtils::SetWindowIconNoData(mozIDOMWindowProxy* aWindow) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
WindowsUIUtils::GetInTabletMode(bool* aResult) {
|
||||
if (mInTabletMode == eTabletModeUnknown) {
|
||||
UpdateTabletModeState();
|
||||
bool WindowsUIUtils::GetInTabletMode() {
|
||||
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
|
||||
if (sInTabletModeState == TabletModeState::Unknown) {
|
||||
UpdateInTabletMode();
|
||||
}
|
||||
*aResult = mInTabletMode == eTabletModeOn;
|
||||
return NS_OK;
|
||||
return sInTabletModeState == TabletModeState::On;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
WindowsUIUtils::UpdateTabletModeState() {
|
||||
WindowsUIUtils::GetInTabletMode(bool* aResult) {
|
||||
*aResult = GetInTabletMode();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void WindowsUIUtils::UpdateInTabletMode() {
|
||||
#ifndef __MINGW32__
|
||||
if (!IsWin10OrLater()) {
|
||||
return NS_OK;
|
||||
return;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIWindowMediator> winMediator(
|
||||
do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
|
@ -264,7 +267,7 @@ WindowsUIUtils::UpdateTabletModeState() {
|
|||
|
||||
rv = appShell->GetHiddenDOMWindow(getter_AddRefs(navWin));
|
||||
if (NS_FAILED(rv) || !navWin) {
|
||||
return rv;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -272,7 +275,7 @@ WindowsUIUtils::UpdateTabletModeState() {
|
|||
widget = widget::WidgetUtils::DOMWindowToWidget(win);
|
||||
|
||||
if (!widget) {
|
||||
return NS_ERROR_FAILURE;
|
||||
return;
|
||||
}
|
||||
|
||||
HWND winPtr = (HWND)widget->GetNativeData(NS_NATIVE_WINDOW);
|
||||
|
@ -282,31 +285,33 @@ WindowsUIUtils::UpdateTabletModeState() {
|
|||
HStringReference(RuntimeClass_Windows_UI_ViewManagement_UIViewSettings)
|
||||
.Get(),
|
||||
&uiViewSettingsInterop);
|
||||
if (SUCCEEDED(hr)) {
|
||||
ComPtr<IUIViewSettings> uiViewSettings;
|
||||
hr = uiViewSettingsInterop->GetForWindow(winPtr,
|
||||
IID_PPV_ARGS(&uiViewSettings));
|
||||
if (SUCCEEDED(hr)) {
|
||||
UserInteractionMode mode;
|
||||
hr = uiViewSettings->get_UserInteractionMode(&mode);
|
||||
if (SUCCEEDED(hr)) {
|
||||
TabletModeState oldTabletModeState = mInTabletMode;
|
||||
mInTabletMode = (mode == UserInteractionMode_Touch) ? eTabletModeOn
|
||||
: eTabletModeOff;
|
||||
if (mInTabletMode != oldTabletModeState) {
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
mozilla::services::GetObserverService();
|
||||
observerService->NotifyObservers(
|
||||
nullptr, "tablet-mode-change",
|
||||
((mInTabletMode == eTabletModeOn) ? u"tablet-mode"
|
||||
: u"normal-mode"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (FAILED(hr)) {
|
||||
return;
|
||||
}
|
||||
ComPtr<IUIViewSettings> uiViewSettings;
|
||||
hr = uiViewSettingsInterop->GetForWindow(winPtr,
|
||||
IID_PPV_ARGS(&uiViewSettings));
|
||||
if (FAILED(hr)) {
|
||||
return;
|
||||
}
|
||||
UserInteractionMode mode;
|
||||
hr = uiViewSettings->get_UserInteractionMode(&mode);
|
||||
if (FAILED(hr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TabletModeState oldTabletModeState = sInTabletModeState;
|
||||
sInTabletModeState = mode == UserInteractionMode_Touch ? TabletModeState::On
|
||||
: TabletModeState::Off;
|
||||
if (sInTabletModeState != oldTabletModeState) {
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
mozilla::services::GetObserverService();
|
||||
observerService->NotifyObservers(nullptr, "tablet-mode-change",
|
||||
sInTabletModeState == TabletModeState::On
|
||||
? u"tablet-mode"
|
||||
: u"normal-mode");
|
||||
}
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifndef __MINGW32__
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
using SharePromise =
|
||||
mozilla::MozPromise<bool, nsresult, /* IsExclusive */ true>;
|
||||
|
||||
enum TabletModeState { eTabletModeUnknown = 0, eTabletModeOff, eTabletModeOn };
|
||||
|
||||
class WindowsUIUtils final : public nsIWindowsUIUtils {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -25,10 +23,11 @@ class WindowsUIUtils final : public nsIWindowsUIUtils {
|
|||
static RefPtr<SharePromise> Share(nsAutoString aTitle, nsAutoString aText,
|
||||
nsAutoString aUrl);
|
||||
|
||||
static void UpdateInTabletMode();
|
||||
static bool GetInTabletMode();
|
||||
|
||||
protected:
|
||||
~WindowsUIUtils();
|
||||
|
||||
TabletModeState mInTabletMode;
|
||||
};
|
||||
|
||||
#endif // mozilla_widget_WindowsUIUtils_h__
|
||||
|
|
|
@ -188,7 +188,7 @@
|
|||
#include "nsIWinTaskbar.h"
|
||||
#define NS_TASKBAR_CONTRACTID "@mozilla.org/windows-taskbar;1"
|
||||
|
||||
#include "nsIWindowsUIUtils.h"
|
||||
#include "WindowsUIUtils.h"
|
||||
|
||||
#include "nsWindowDefs.h"
|
||||
|
||||
|
@ -5199,8 +5199,7 @@ bool nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam,
|
|||
gfxDWriteFont::UpdateSystemTextVars();
|
||||
break;
|
||||
}
|
||||
if (lParam) {
|
||||
auto lParamString = reinterpret_cast<const wchar_t*>(lParam);
|
||||
if (auto lParamString = reinterpret_cast<const wchar_t*>(lParam)) {
|
||||
if (!wcscmp(lParamString, L"ImmersiveColorSet")) {
|
||||
// This affects system colors (-moz-win-accentcolor), so gotta pass
|
||||
// the style flag.
|
||||
|
@ -5220,14 +5219,7 @@ bool nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam,
|
|||
!wcscmp(lParamString, L"ConvertibleSlateMode") ||
|
||||
!wcscmp(lParamString, L"SystemDockMode")) {
|
||||
NotifyThemeChanged(widget::ThemeChangeKind::MediaQueriesOnly);
|
||||
|
||||
if (IsWin10OrLater()) {
|
||||
nsCOMPtr<nsIWindowsUIUtils> uiUtils(
|
||||
do_GetService("@mozilla.org/windows-ui-utils;1"));
|
||||
if (uiUtils) {
|
||||
uiUtils->UpdateTabletModeState();
|
||||
}
|
||||
}
|
||||
WindowsUIUtils::UpdateInTabletMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче