From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- widget/windows/OSKInputPaneManager.cpp | 101 +++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 widget/windows/OSKInputPaneManager.cpp (limited to 'widget/windows/OSKInputPaneManager.cpp') diff --git a/widget/windows/OSKInputPaneManager.cpp b/widget/windows/OSKInputPaneManager.cpp new file mode 100644 index 0000000000..293a84cd28 --- /dev/null +++ b/widget/windows/OSKInputPaneManager.cpp @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sts=2 sw=2 et cin: */ +/* 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/. */ + +#define NTDDI_VERSION NTDDI_WIN10_RS1 + +#include "OSKInputPaneManager.h" +#include "nsDebug.h" + +#ifndef __MINGW32__ +# include +# include +# include + +using namespace ABI::Windows::UI::ViewManagement; +using namespace Microsoft::WRL; +using namespace Microsoft::WRL::Wrappers; +#endif + +namespace mozilla { +namespace widget { + +#ifndef __MINGW32__ +static ComPtr GetInputPane(HWND aHwnd) { + ComPtr inputPaneInterop; + HRESULT hr = RoGetActivationFactory( + HStringReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(), + IID_PPV_ARGS(&inputPaneInterop)); + if (NS_WARN_IF(FAILED(hr))) { + return nullptr; + } + + ComPtr inputPane; + hr = inputPaneInterop->GetForWindow(aHwnd, IID_PPV_ARGS(&inputPane)); + if (NS_WARN_IF(FAILED(hr))) { + return nullptr; + } + + ComPtr inputPane2; + inputPane.As(&inputPane2); + return inputPane2; +} + +# ifdef DEBUG +static bool IsInputPaneVisible(ComPtr& aInputPane2) { + ComPtr inputPaneControl; + aInputPane2.As(&inputPaneControl); + if (NS_WARN_IF(!inputPaneControl)) { + return false; + } + boolean visible = false; + inputPaneControl->get_Visible(&visible); + return visible; +} + +static bool IsForegroundApp() { + HWND foregroundWnd = ::GetForegroundWindow(); + if (!foregroundWnd) { + return false; + } + DWORD pid; + ::GetWindowThreadProcessId(foregroundWnd, &pid); + return pid == ::GetCurrentProcessId(); +} +# endif +#endif + +// static +void OSKInputPaneManager::ShowOnScreenKeyboard(HWND aWnd) { +#ifndef __MINGW32__ + ComPtr inputPane2 = GetInputPane(aWnd); + if (!inputPane2) { + return; + } + boolean result; + inputPane2->TryShow(&result); + NS_WARNING_ASSERTION( + result || !IsForegroundApp() || IsInputPaneVisible(inputPane2), + "IInputPane2::TryShow is failure"); +#endif +} + +// static +void OSKInputPaneManager::DismissOnScreenKeyboard(HWND aWnd) { +#ifndef __MINGW32__ + ComPtr inputPane2 = GetInputPane(aWnd); + if (!inputPane2) { + return; + } + boolean result; + inputPane2->TryHide(&result); + NS_WARNING_ASSERTION( + result || !IsForegroundApp() || !IsInputPaneVisible(inputPane2), + "IInputPane2::TryHide is failure"); +#endif +} + +} // namespace widget +} // namespace mozilla -- cgit v1.2.3