diff --git a/shell/platform/windows/client_wrapper/flutter_view_controller.cc b/shell/platform/windows/client_wrapper/flutter_view_controller.cc index 5e47d8c3821ca..b3bd963c9c1a7 100644 --- a/shell/platform/windows/client_wrapper/flutter_view_controller.cc +++ b/shell/platform/windows/client_wrapper/flutter_view_controller.cc @@ -11,12 +11,12 @@ namespace flutter { #ifdef WINUWP FlutterViewController::FlutterViewController( - ABI::Windows::UI::Core::CoreWindow* window, + ABI::Windows::ApplicationModel::Core::CoreApplicationView* applicationview, ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args, const DartProject& project) { engine_ = std::make_unique(project); - controller_ = FlutterDesktopViewControllerCreateFromCoreWindow( - window, args, engine_->RelinquishEngine()); + controller_ = FlutterDesktopViewControllerCreateFromCoreApplicationView( + applicationview, args, engine_->RelinquishEngine()); if (!controller_) { std::cerr << "Failed to create view controller." << std::endl; return; diff --git a/shell/platform/windows/client_wrapper/include/flutter/flutter_view.h b/shell/platform/windows/client_wrapper/include/flutter/flutter_view.h index 057d905308eb4..52945676d7ef6 100644 --- a/shell/platform/windows/client_wrapper/include/flutter/flutter_view.h +++ b/shell/platform/windows/client_wrapper/include/flutter/flutter_view.h @@ -20,7 +20,12 @@ class FlutterView { FlutterView(FlutterView const&) = delete; FlutterView& operator=(FlutterView const&) = delete; -#ifndef WINUWP +#ifdef WINUWP + // Returns the backing CoreApplicationView for the view. + ABI::Windows::ApplicationModel::Core::CoreApplicationView* GetNativeWindow() { + return FlutterDesktopViewGetCoreApplicationView(view_); + } +#else // Returns the backing HWND for the view. HWND GetNativeWindow() { return FlutterDesktopViewGetHWND(view_); } #endif diff --git a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h index 66808fc1351f9..b9fce9ec31e1c 100644 --- a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h +++ b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h @@ -47,7 +47,8 @@ class FlutterViewController { // |IActivatedEventArgs| will be used to configure the engine switches. Can // be set to nullptr. explicit FlutterViewController( - ABI::Windows::UI::Core::CoreWindow* window, + ABI::Windows::ApplicationModel::Core::CoreApplicationView* + applicationview, ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args, const DartProject& project); #endif diff --git a/shell/platform/windows/flutter_window_win32.cc b/shell/platform/windows/flutter_window_win32.cc index b0e5d88a1e71f..aa75f30ac087f 100644 --- a/shell/platform/windows/flutter_window_win32.cc +++ b/shell/platform/windows/flutter_window_win32.cc @@ -81,6 +81,10 @@ WindowsRenderTarget FlutterWindowWin32::GetRenderTarget() { return WindowsRenderTarget(GetWindowHandle()); } +PlatformWindow FlutterWindowWin32::GetPlatformWindow() { + return GetWindowHandle(); +} + float FlutterWindowWin32::GetDpiScale() { return static_cast(GetCurrentDPI()) / static_cast(base_dpi); } diff --git a/shell/platform/windows/flutter_window_win32.h b/shell/platform/windows/flutter_window_win32.h index a73ba88112871..d4fe0f5623c52 100644 --- a/shell/platform/windows/flutter_window_win32.h +++ b/shell/platform/windows/flutter_window_win32.h @@ -86,6 +86,9 @@ class FlutterWindowWin32 : public WindowWin32, public WindowBindingHandler { // |FlutterWindowBindingHandler| WindowsRenderTarget GetRenderTarget() override; + // |FlutterWindowBindingHandler| + PlatformWindow GetPlatformWindow() override; + // |FlutterWindowBindingHandler| float GetDpiScale() override; diff --git a/shell/platform/windows/flutter_window_winuwp.cc b/shell/platform/windows/flutter_window_winuwp.cc index 447477fc3db2d..bace4d7529b10 100644 --- a/shell/platform/windows/flutter_window_winuwp.cc +++ b/shell/platform/windows/flutter_window_winuwp.cc @@ -10,10 +10,13 @@ namespace flutter { static constexpr double kControllerScrollMultiplier = 3; FlutterWindowWinUWP::FlutterWindowWinUWP( - ABI::Windows::UI::Core::CoreWindow* window) { - winrt::Windows::UI::Core::CoreWindow cw{nullptr}; - winrt::copy_from_abi(cw, window); - window_ = cw; + ABI::Windows::ApplicationModel::Core::CoreApplicationView* + applicationview) { + winrt::Windows::ApplicationModel::Core::CoreApplicationView cav{nullptr}; + winrt::copy_from_abi(cav, applicationview); + + application_view_ = cav; + window_ = application_view_.CoreWindow(); SetEventHandlers(); @@ -46,6 +49,10 @@ WindowsRenderTarget FlutterWindowWinUWP::GetRenderTarget() { #endif } +PlatformWindow FlutterWindowWinUWP::GetPlatformWindow() { + return application_view_; +} + void FlutterWindowWinUWP::ApplyInverseDpiScalingTransform() { // Apply inverse transform to negate built in DPI scaling in order to render // at native scale. diff --git a/shell/platform/windows/flutter_window_winuwp.h b/shell/platform/windows/flutter_window_winuwp.h index 9870b96d759e6..8cb4455568950 100644 --- a/shell/platform/windows/flutter_window_winuwp.h +++ b/shell/platform/windows/flutter_window_winuwp.h @@ -5,12 +5,13 @@ #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_UWP_FLUTTER_WINDOW_H_ #define FLUTTER_SHELL_PLATFORM_WINDOWS_UWP_FLUTTER_WINDOW_H_ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include "flutter/shell/platform/embedder/embedder.h" #include "flutter/shell/platform/windows/display_helper_winuwp.h" @@ -25,7 +26,8 @@ namespace flutter { // Specifically handles window events within windows. class FlutterWindowWinUWP : public WindowBindingHandler { public: - explicit FlutterWindowWinUWP(ABI::Windows::UI::Core::CoreWindow* window); + explicit FlutterWindowWinUWP( + ABI::Windows::ApplicationModel::Core::CoreApplicationView* window); virtual ~FlutterWindowWinUWP(); @@ -35,6 +37,9 @@ class FlutterWindowWinUWP : public WindowBindingHandler { // |WindowBindingHandler| WindowsRenderTarget GetRenderTarget() override; + // |FlutterWindowBindingHandler| + PlatformWindow GetPlatformWindow() override; + // |WindowBindingHandler| float GetDpiScale() override; @@ -119,6 +124,10 @@ class FlutterWindowWinUWP : public WindowBindingHandler { // Backing CoreWindow. nullptr if not set. winrt::Windows::UI::Core::CoreWindow window_{nullptr}; + // CoreApplicationView that owns window_. nullptr if not set. + winrt::Windows::ApplicationModel::Core::CoreApplicationView application_view_{ + nullptr}; + // Pointer to a FlutterWindowsView that can be // used to update engine windowing and input state. WindowBindingHandlerDelegate* binding_handler_delegate_; diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index 9babba5ce38a6..9b8b7d80473cf 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -128,9 +128,20 @@ FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar( EngineFromHandle(engine)->texture_registrar()); } +#ifdef WINUWP +ABI::Windows::ApplicationModel::Core::CoreApplicationView* +FlutterDesktopViewGetCoreApplicationView(FlutterDesktopViewRef view) { + return static_cast< + ABI::Windows::ApplicationModel::Core::CoreApplicationView*>( + winrt::get_abi(ViewFromHandle(view)->GetPlatformWindow())); +} +#endif + +#ifndef WINUWP HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view) { - return std::get(*ViewFromHandle(view)->GetRenderTarget()); + return ViewFromHandle(view)->GetPlatformWindow(); } +#endif FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView( FlutterDesktopPluginRegistrarRef registrar) { diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index aeac73f9d0b84..d4b2f056af6f9 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -487,6 +487,10 @@ WindowsRenderTarget* FlutterWindowsView::GetRenderTarget() const { return render_target_.get(); } +PlatformWindow FlutterWindowsView::GetPlatformWindow() const { + return binding_handler_->GetPlatformWindow(); +} + FlutterWindowsEngine* FlutterWindowsView::GetEngine() { return engine_.get(); } diff --git a/shell/platform/windows/flutter_windows_view.h b/shell/platform/windows/flutter_windows_view.h index 8b3ef7153a7a5..f70d1b1aa62d6 100644 --- a/shell/platform/windows/flutter_windows_view.h +++ b/shell/platform/windows/flutter_windows_view.h @@ -59,6 +59,9 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate, // Return the currently configured WindowsRenderTarget. WindowsRenderTarget* GetRenderTarget() const; + // Return the currently configured PlatformWindow. + PlatformWindow GetPlatformWindow() const; + // Returns the engine backing this view. FlutterWindowsEngine* GetEngine(); diff --git a/shell/platform/windows/flutter_windows_winuwp.cc b/shell/platform/windows/flutter_windows_winuwp.cc index 90363154fc207..274eb48cdeb2b 100644 --- a/shell/platform/windows/flutter_windows_winuwp.cc +++ b/shell/platform/windows/flutter_windows_winuwp.cc @@ -41,12 +41,12 @@ std::vector SplitCommaSeparatedString(const std::string& s) { } FlutterDesktopViewControllerRef -FlutterDesktopViewControllerCreateFromCoreWindow( - ABI::Windows::UI::Core::CoreWindow* window, +FlutterDesktopViewControllerCreateFromCoreApplicationView( + ABI::Windows::ApplicationModel::Core::CoreApplicationView* application_view, ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args, FlutterDesktopEngineRef engine) { std::unique_ptr window_wrapper = - std::make_unique(window); + std::make_unique(application_view); auto state = std::make_unique(); state->view = diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 76802ba567116..14f8ea464aaaf 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -77,11 +77,11 @@ typedef struct { // FlutterDesktopViewControllerDestroy. Returns a null pointer in the event of // an error. #ifdef WINUWP -// The CoreWindow implementation accepts a pointer to the host CoreWindow -// and view hookup is performed in the construction path. +// The CoreApplicationView implementation accepts a pointer to the host +// CoreApplicationView and view hookup is performed in the construction path. FLUTTER_EXPORT FlutterDesktopViewControllerRef -FlutterDesktopViewControllerCreateFromCoreWindow( - ABI::Windows::UI::Core::CoreWindow* window, +FlutterDesktopViewControllerCreateFromCoreApplicationView( + ABI::Windows::ApplicationModel::Core::CoreApplicationView* window, ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args, FlutterDesktopEngineRef engine); #else //! WINUWP @@ -192,7 +192,12 @@ FlutterDesktopEngineGetTextureRegistrar( // ========== View ========== -#ifndef WINUWP +#ifdef WINUWP +// Return backing CoreApplicationView for manipulation of CoreWindow and +// CoreTitleBar in host application. +FLUTTER_EXPORT ABI::Windows::ApplicationModel::Core::CoreApplicationView* +FlutterDesktopViewGetCoreApplicationView(FlutterDesktopViewRef view); +#else // Return backing HWND for manipulation in host application. FLUTTER_EXPORT HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view); #endif diff --git a/shell/platform/windows/testing/mock_window_binding_handler.h b/shell/platform/windows/testing/mock_window_binding_handler.h index bac12fe0655fd..d3619df55ceae 100644 --- a/shell/platform/windows/testing/mock_window_binding_handler.h +++ b/shell/platform/windows/testing/mock_window_binding_handler.h @@ -25,6 +25,7 @@ class MockWindowBindingHandler : public WindowBindingHandler { MOCK_METHOD1(SetView, void(WindowBindingHandlerDelegate* view)); MOCK_METHOD0(GetRenderTarget, WindowsRenderTarget()); + MOCK_METHOD0(GetPlatformWindow, PlatformWindow()); MOCK_METHOD0(GetDpiScale, float()); MOCK_METHOD0(OnWindowResized, void()); MOCK_METHOD0(GetPhysicalWindowBounds, PhysicalWindowBounds()); diff --git a/shell/platform/windows/window_binding_handler.h b/shell/platform/windows/window_binding_handler.h index 674d6990b56e8..f699bda24fe70 100644 --- a/shell/platform/windows/window_binding_handler.h +++ b/shell/platform/windows/window_binding_handler.h @@ -15,6 +15,7 @@ #include "flutter/shell/platform/windows/window_binding_handler_delegate.h" #ifdef WINUWP +#include #include #endif @@ -28,6 +29,16 @@ struct PhysicalWindowBounds { size_t height; }; +// Type representing an underlying platform window. +#ifdef WINUWP +using PlatformWindow = + winrt::Windows::ApplicationModel::Core::CoreApplicationView; +#else +using PlatformWindow = HWND; +#endif + +// Type representing a platform object that can be accepted by the Angle +// rendering layer to bind to and render pixels into. #ifdef WINUWP using WindowsRenderTarget = std::variant