Skip to content

Commit

Permalink
[0.74] Export MS.RN.Color ctor in Office dll (#14088)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* change file

---------

Co-authored-by: React-Native-Windows Bot <[email protected]>
  • Loading branch information
acoates-ms and rnbot authored Nov 6, 2024
1 parent 69968e4 commit 15286b6
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Export MS.RN.Color ctor in Office dll",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions vnext/Desktop/module.g.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions vnext/Microsoft.ReactNative/Fabric/ComponentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion vnext/Microsoft.ReactNative/Fabric/ComponentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/LayoutMetrics.h>

#include <ComponentView.Experimental.interop.h>
#include <Fabric/Composition/Theme.h>
#include <uiautomationcore.h>
#include <winrt/Microsoft.ReactNative.Composition.Input.h>
Expand Down Expand Up @@ -77,7 +78,8 @@ struct UnmountChildComponentViewArgs : public UnmountChildComponentViewArgsT<Unm
uint32_t m_index;
};

struct ComponentView : public ComponentViewT<ComponentView> {
struct ComponentView
: public ComponentViewT<ComponentView, ::Microsoft::ReactNative::Composition::Experimental::IComponentViewInterop> {
ComponentView(facebook::react::Tag tag, winrt::Microsoft::ReactNative::ReactContext const &reactContext);

virtual std::vector<facebook::react::ComponentDescriptorProvider> supplementalComponentDescriptorProviders() noexcept;
Expand Down Expand Up @@ -105,6 +107,8 @@ struct ComponentView : public ComponentViewT<ComponentView> {
// returns true if the fn ever returned true
bool runOnChildren(bool forward, Mso::Functor<bool(ComponentView &)> &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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(x), static_cast<int32_t>(y)});
auto provider = rootView->UiaProviderFromPoint(
{static_cast<LONG>(local.X * m_island.RasterizationScale()),
static_cast<LONG>(local.Y * m_island.RasterizationScale())});
auto spFragment = provider.try_as<IRawElementProviderFragment>();
if (spFragment) {
*pRetVal = spFragment.detach();
}

return S_OK;
auto local = rootView->ConvertScreenToLocal({static_cast<float>(x), static_cast<float>(y)});
auto provider = rootView->UiaProviderFromPoint(
{static_cast<LONG>(local.X * rootView->LayoutMetrics().PointScaleFactor),
static_cast<LONG>(local.Y * rootView->LayoutMetrics().PointScaleFactor)});
auto spFragment = provider.try_as<IRawElementProviderFragment>();
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<LONG>(x), static_cast<LONG>(y)};
ScreenToClient(m_hwnd, &clientPoint);

auto provider = rootView->UiaProviderFromPoint(clientPoint);
auto spFragment = provider.try_as<IRawElementProviderFragment>();
if (spFragment) {
*pRetVal = spFragment.detach();
return S_OK;
}
}
return S_OK;
}

AddRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HWND>(m_prevWindowID);

auto roothwnd = GetHwndForParenting();

m_hwnd = CreateWindow(
c_modalWindowClassName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(pt.X), static_cast<int32_t>(pt.Y)});
return {static_cast<float>(pp.X), static_cast<float>(pp.Y)};
}
POINT p{static_cast<LONG>(pt.X), static_cast<LONG>(pt.Y)};
ScreenToClient(m_hwnd, &p);
return {static_cast<float>(p.x) / m_scaleFactor, static_cast<float>(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<float>(pp.X), static_cast<float>(pp.Y)};
}
POINT p{static_cast<LONG>(pt.X * m_scaleFactor), static_cast<LONG>(pt.Y * m_scaleFactor)};
ClientToScreen(m_hwnd, &p);
return {static_cast<float>(p.x), static_cast<float>(p.y)};
}

void ReactNativeIsland::SetWindow(uint64_t hwnd) noexcept {
m_hwnd = reinterpret_cast<HWND>(hwnd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>(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<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>(rootView)
->ConvertLocalToScreen(pt);
}
assert(false);
return {};
}

winrt::Microsoft::UI::Content::ContentIsland RootComponentView::parentContentIsland() noexcept {
if (auto rootView = m_wkRootView.get()) {
return winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>(rootView)->Island();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct RootComponentView : RootComponentViewT<RootComponentView, ViewComponentVi

RootComponentView *rootComponentView() const noexcept override;

winrt::Windows::Foundation::Point ConvertScreenToLocal(winrt::Windows::Foundation::Point pt) noexcept;
winrt::Windows::Foundation::Point ConvertLocalToScreen(winrt::Windows::Foundation::Point pt) noexcept;

winrt::Microsoft::UI::Content::ContentIsland parentContentIsland() noexcept;

// Index that visuals can be inserted into OuterVisual for debugging UI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,20 @@ struct CompTextHost : public winrt::implements<CompTextHost, ITextHost> {

//@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<float>(lppt->x), static_cast<float>(lppt->y)};
auto localpt = m_outer->ScreenToLocal(pt);
lppt->x = static_cast<LONG>(localpt.X);
lppt->y = static_cast<LONG>(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<float>(lppt->x), static_cast<float>(lppt->y)};
auto screenpt = m_outer->LocalToScreen(pt);
lppt->x = static_cast<LONG>(screenpt.X);
lppt->y = static_cast<LONG>(screenpt.Y);
return true;
}

//@cmember Request host to activate text services
Expand Down

0 comments on commit 15286b6

Please sign in to comment.