From 3b899855fa1f3443d2029ca6beaba8bd6f1b12f3 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 6 Nov 2024 10:43:21 -0800 Subject: [PATCH 1/2] Export MS.RN.Color ctor in Office dll (#14082) * Export MS.RN.Color ctor in Office dll * Change files * Implement TxScreenToClient and TxClientToScreen * format --------- Co-authored-by: React-Native-Windows Bot <53619745+rnbot@users.noreply.github.com> --- ...-22ea5da8-4ee5-4ec6-bac3-1c62cabf01f7.json | 7 ++++ vnext/Desktop/module.g.cpp | 7 ++++ .../ComponentView.Experimental.interop.h | 14 +++++++ .../Fabric/ComponentView.cpp | 8 ++++ .../Fabric/ComponentView.h | 6 ++- .../CompositionRootAutomationProvider.cpp | 40 ++++--------------- .../WindowsModalHostViewComponentView.cpp | 3 +- .../Fabric/Composition/ReactNativeIsland.cpp | 23 +++++++++++ .../Fabric/Composition/ReactNativeIsland.h | 3 ++ .../Fabric/Composition/RootComponentView.cpp | 20 ++++++++++ .../Fabric/Composition/RootComponentView.h | 3 ++ .../WindowsTextInputComponentView.cpp | 14 +++++-- 12 files changed, 110 insertions(+), 38 deletions(-) create mode 100644 change/react-native-windows-22ea5da8-4ee5-4ec6-bac3-1c62cabf01f7.json create mode 100644 vnext/Microsoft.ReactNative.Cxx/ComponentView.Experimental.interop.h diff --git a/change/react-native-windows-22ea5da8-4ee5-4ec6-bac3-1c62cabf01f7.json b/change/react-native-windows-22ea5da8-4ee5-4ec6-bac3-1c62cabf01f7.json new file mode 100644 index 00000000000..d7f0e6ee5f1 --- /dev/null +++ b/change/react-native-windows-22ea5da8-4ee5-4ec6-bac3-1c62cabf01f7.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Export MS.RN.Color ctor in Office dll", + "packageName": "react-native-windows", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Desktop/module.g.cpp b/vnext/Desktop/module.g.cpp index 789fa1b564b..70f6be14ca3 100644 --- a/vnext/Desktop/module.g.cpp +++ b/vnext/Desktop/module.g.cpp @@ -6,6 +6,7 @@ #include "pch.h" #include "winrt/base.h" void* winrt_make_Microsoft_Internal_TestController(); +void* winrt_make_Microsoft_ReactNative_Color(); void* winrt_make_Microsoft_ReactNative_ReactNativeIsland(); #ifdef USE_WINUI3 void *winrt_make_Microsoft_ReactNative_Composition_ImageFailedResponse(); @@ -39,6 +40,9 @@ void *winrt_make_Microsoft_ReactNative_Composition_StreamImageResponse() { void *winrt_make_Microsoft_ReactNative_Composition_Experimental_UriBrushFactoryImageResponse() { winrt::throw_hresult(E_NOTIMPL); } +void* winrt_make_Microsoft_ReactNative_Color() { + winrt::throw_hresult(E_NOTIMPL); +} void* winrt_make_Microsoft_ReactNative_ReactNativeIsland() { winrt::throw_hresult(E_NOTIMPL); } @@ -69,6 +73,9 @@ void* __stdcall winrt_get_activation_factory([[maybe_unused]] std::wstring_view { return winrt_make_Microsoft_Internal_TestController(); } + if (requal(name, L"Microsoft.ReactNative.Color")) { + return winrt_make_Microsoft_ReactNative_Color(); + } if (requal(name, L"Microsoft.ReactNative.ReactNativeIsland")) { return winrt_make_Microsoft_ReactNative_ReactNativeIsland(); } diff --git a/vnext/Microsoft.ReactNative.Cxx/ComponentView.Experimental.interop.h b/vnext/Microsoft.ReactNative.Cxx/ComponentView.Experimental.interop.h new file mode 100644 index 00000000000..ff765e047fa --- /dev/null +++ b/vnext/Microsoft.ReactNative.Cxx/ComponentView.Experimental.interop.h @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#pragma once + +namespace Microsoft::ReactNative::Composition::Experimental { + +// This interface will be removed once we complete internal transitions to ContentIsland, and new APIs for hosting +// popups/new windows from a ContentIsland +struct __declspec(uuid("2A60D68A-57B8-43CA-B1BA-2FAF0FCB344B")) IComponentViewInterop : IUnknown { + virtual HWND GetHwndForParenting() noexcept = 0; +}; + +} // namespace Microsoft::ReactNative::Composition::Experimental diff --git a/vnext/Microsoft.ReactNative/Fabric/ComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/ComponentView.cpp index 8d5e5b8d008..00a1e05df43 100644 --- a/vnext/Microsoft.ReactNative/Fabric/ComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/ComponentView.cpp @@ -363,6 +363,14 @@ RECT ComponentView::getClientRect() const noexcept { return {}; } +winrt::Windows::Foundation::Point ComponentView::ScreenToLocal(winrt::Windows::Foundation::Point pt) noexcept { + return rootComponentView()->ConvertScreenToLocal(pt); +} + +winrt::Windows::Foundation::Point ComponentView::LocalToScreen(winrt::Windows::Foundation::Point pt) noexcept { + return rootComponentView()->ConvertLocalToScreen(pt); +} + // The offset from this elements parent to its children (accounts for things like scroll position) facebook::react::Point ComponentView::getClientOffset() const noexcept { assert(false); diff --git a/vnext/Microsoft.ReactNative/Fabric/ComponentView.h b/vnext/Microsoft.ReactNative/Fabric/ComponentView.h index 66fe76f09b2..074bac0a445 100644 --- a/vnext/Microsoft.ReactNative/Fabric/ComponentView.h +++ b/vnext/Microsoft.ReactNative/Fabric/ComponentView.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -77,7 +78,8 @@ struct UnmountChildComponentViewArgs : public UnmountChildComponentViewArgsT { +struct ComponentView + : public ComponentViewT { ComponentView(facebook::react::Tag tag, winrt::Microsoft::ReactNative::ReactContext const &reactContext); virtual std::vector supplementalComponentDescriptorProviders() noexcept; @@ -105,6 +107,8 @@ struct ComponentView : public ComponentViewT { // returns true if the fn ever returned true bool runOnChildren(bool forward, Mso::Functor &fn) noexcept; virtual RECT getClientRect() const noexcept; + winrt::Windows::Foundation::Point ScreenToLocal(winrt::Windows::Foundation::Point pt) noexcept; + winrt::Windows::Foundation::Point LocalToScreen(winrt::Windows::Foundation::Point pt) noexcept; // The offset from this elements parent to its children (accounts for things like scroll position) virtual facebook::react::Point getClientOffset() const noexcept; virtual void onLosingFocus(const winrt::Microsoft::ReactNative::LosingFocusEventArgs &args) noexcept; diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp index fffe2197274..5bf4135f57c 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp @@ -189,40 +189,16 @@ HRESULT __stdcall CompositionRootAutomationProvider::ElementProviderFromPoint( *pRetVal = nullptr; if (auto rootView = rootComponentView()) { -#ifdef USE_WINUI3 - if (m_island) { - auto cc = m_island.CoordinateConverter(); - auto local = cc.ConvertScreenToLocal( - winrt::Windows::Graphics::PointInt32{static_cast(x), static_cast(y)}); - auto provider = rootView->UiaProviderFromPoint( - {static_cast(local.X * m_island.RasterizationScale()), - static_cast(local.Y * m_island.RasterizationScale())}); - auto spFragment = provider.try_as(); - if (spFragment) { - *pRetVal = spFragment.detach(); - } - - return S_OK; + auto local = rootView->ConvertScreenToLocal({static_cast(x), static_cast(y)}); + auto provider = rootView->UiaProviderFromPoint( + {static_cast(local.X * rootView->LayoutMetrics().PointScaleFactor), + static_cast(local.Y * rootView->LayoutMetrics().PointScaleFactor)}); + auto spFragment = provider.try_as(); + if (spFragment) { + *pRetVal = spFragment.detach(); } -#endif - if (m_hwnd) { - if (!IsWindow(m_hwnd)) { - // TODO: Add support for non-HWND based hosting - assert(false); - return E_FAIL; - } - - POINT clientPoint{static_cast(x), static_cast(y)}; - ScreenToClient(m_hwnd, &clientPoint); - - auto provider = rootView->UiaProviderFromPoint(clientPoint); - auto spFragment = provider.try_as(); - if (spFragment) { - *pRetVal = spFragment.detach(); - return S_OK; - } - } + return S_OK; } AddRef(); diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp index d4be4afbd20..f583149aa3d 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp @@ -76,7 +76,8 @@ void WindowsModalHostComponentView::EnsureModalCreated() { // get the root hwnd m_prevWindowID = winrt::Microsoft::ReactNative::ReactCoreInjection::GetTopLevelWindowId(m_reactContext.Properties().Handle()); - auto roothwnd = reinterpret_cast(m_prevWindowID); + + auto roothwnd = GetHwndForParenting(); m_hwnd = CreateWindow( c_modalWindowClassName, diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp index ce44ca56a1d..6bb4c8fe33d 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp @@ -360,6 +360,29 @@ winrt::IInspectable ReactNativeIsland::GetUiaProvider() noexcept { return m_uiaProvider; } +winrt::Windows::Foundation::Point ReactNativeIsland::ConvertScreenToLocal( + winrt::Windows::Foundation::Point pt) noexcept { + if (m_island) { + auto pp = m_island.CoordinateConverter().ConvertScreenToLocal( + winrt::Windows::Graphics::PointInt32{static_cast(pt.X), static_cast(pt.Y)}); + return {static_cast(pp.X), static_cast(pp.Y)}; + } + POINT p{static_cast(pt.X), static_cast(pt.Y)}; + ScreenToClient(m_hwnd, &p); + return {static_cast(p.x) / m_scaleFactor, static_cast(p.y) / m_scaleFactor}; +} + +winrt::Windows::Foundation::Point ReactNativeIsland::ConvertLocalToScreen( + winrt::Windows::Foundation::Point pt) noexcept { + if (m_island) { + auto pp = m_island.CoordinateConverter().ConvertLocalToScreen(pt); + return {static_cast(pp.X), static_cast(pp.Y)}; + } + POINT p{static_cast(pt.X * m_scaleFactor), static_cast(pt.Y * m_scaleFactor)}; + ClientToScreen(m_hwnd, &p); + return {static_cast(p.x), static_cast(p.y)}; +} + void ReactNativeIsland::SetWindow(uint64_t hwnd) noexcept { m_hwnd = reinterpret_cast(hwnd); } diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h index b74be73460b..c51aa7bd610 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h @@ -114,6 +114,9 @@ struct ReactNativeIsland void SetWindow(uint64_t hwnd) noexcept; int64_t SendMessage(uint32_t msg, uint64_t wParam, int64_t lParam) noexcept; + winrt::Windows::Foundation::Point ConvertScreenToLocal(winrt::Windows::Foundation::Point pt) noexcept; + winrt::Windows::Foundation::Point ConvertLocalToScreen(winrt::Windows::Foundation::Point pt) noexcept; + bool CapturePointer( const winrt::Microsoft::ReactNative::Composition::Input::Pointer &pointer, facebook::react::Tag tag) noexcept; diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp index 7847e9ec5d5..45d4a49dc1f 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp @@ -248,6 +248,26 @@ float RootComponentView::FontSizeMultiplier() const noexcept { return 1.0f; } +winrt::Windows::Foundation::Point RootComponentView::ConvertScreenToLocal( + winrt::Windows::Foundation::Point pt) noexcept { + if (auto rootView = m_wkRootView.get()) { + return winrt::get_self(rootView) + ->ConvertScreenToLocal(pt); + } + assert(false); + return {}; +} + +winrt::Windows::Foundation::Point RootComponentView::ConvertLocalToScreen( + winrt::Windows::Foundation::Point pt) noexcept { + if (auto rootView = m_wkRootView.get()) { + return winrt::get_self(rootView) + ->ConvertLocalToScreen(pt); + } + assert(false); + return {}; +} + winrt::Microsoft::UI::Content::ContentIsland RootComponentView::parentContentIsland() noexcept { if (auto rootView = m_wkRootView.get()) { return winrt::get_self(rootView)->Island(); diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h b/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h index ddd61b7e7fa..3043faec6ec 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h @@ -38,6 +38,9 @@ struct RootComponentView : RootComponentViewT { //@cmember Converts screen coordinates of a specified point to the client coordinates BOOL TxScreenToClient(LPPOINT lppt) override { - assert(false); - return {}; + winrt::Windows::Foundation::Point pt{static_cast(lppt->x), static_cast(lppt->y)}; + auto localpt = m_outer->ScreenToLocal(pt); + lppt->x = static_cast(localpt.X); + lppt->y = static_cast(localpt.Y); + return true; } //@cmember Converts the client coordinates of a specified point to screen coordinates BOOL TxClientToScreen(LPPOINT lppt) override { - assert(false); - return {}; + winrt::Windows::Foundation::Point pt{static_cast(lppt->x), static_cast(lppt->y)}; + auto screenpt = m_outer->LocalToScreen(pt); + lppt->x = static_cast(screenpt.X); + lppt->y = static_cast(screenpt.Y); + return true; } //@cmember Request host to activate text services From aa9156b4c024eca973efa71374211587128e1ec3 Mon Sep 17 00:00:00 2001 From: Andrew <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 6 Nov 2024 10:44:54 -0800 Subject: [PATCH 2/2] change file --- ...act-native-windows-22ea5da8-4ee5-4ec6-bac3-1c62cabf01f7.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change/react-native-windows-22ea5da8-4ee5-4ec6-bac3-1c62cabf01f7.json b/change/react-native-windows-22ea5da8-4ee5-4ec6-bac3-1c62cabf01f7.json index d7f0e6ee5f1..4889628aa4b 100644 --- a/change/react-native-windows-22ea5da8-4ee5-4ec6-bac3-1c62cabf01f7.json +++ b/change/react-native-windows-22ea5da8-4ee5-4ec6-bac3-1c62cabf01f7.json @@ -1,5 +1,5 @@ { - "type": "prerelease", + "type": "patch", "comment": "Export MS.RN.Color ctor in Office dll", "packageName": "react-native-windows", "email": "30809111+acoates-ms@users.noreply.github.com",