diff --git a/SampleApps/WebView2APISample/App.cpp b/SampleApps/WebView2APISample/App.cpp index 0093733d..70f549f1 100644 --- a/SampleApps/WebView2APISample/App.cpp +++ b/SampleApps/WebView2APISample/App.cpp @@ -101,6 +101,10 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmd { creationModeId = IDM_CREATION_MODE_WINDOWED; } + else if (NEXT_PARAM_CONTAINS(L"allowhostinput")) + { + creationModeId = IDM_CREATION_MODE_HOST_INPUT_PROCESSING; + } else if (NEXT_PARAM_CONTAINS(L"visualdcomp")) { creationModeId = IDM_CREATION_MODE_VISUAL_DCOMP; diff --git a/SampleApps/WebView2APISample/AppWindow.cpp b/SampleApps/WebView2APISample/AppWindow.cpp index 1d85aebb..7fceeb78 100644 --- a/SampleApps/WebView2APISample/AppWindow.cpp +++ b/SampleApps/WebView2APISample/AppWindow.cpp @@ -27,6 +27,7 @@ #include "FileComponent.h" #include "ProcessComponent.h" #include "Resource.h" +#include "ScenarioAcceleratorKeyPressed.h" #include "ScenarioAddHostObject.h" #include "ScenarioAuthentication.h" #include "ScenarioClientCertificateRequested.h" @@ -40,7 +41,6 @@ #include "ScenarioIFrameDevicePermission.h" #include "ScenarioNavigateWithWebResourceRequest.h" #include "ScenarioNonClientRegionSupport.h" -#include "ScenarioAcceleratorKeyPressed.h" #include "ScenarioNotificationReceived.h" #include "ScenarioPermissionManagement.h" #include "ScenarioSharedBuffer.h" @@ -729,6 +729,7 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam) CloseAppWindow(); return true; case IDM_CREATION_MODE_WINDOWED: + case IDM_CREATION_MODE_HOST_INPUT_PROCESSING: case IDM_CREATION_MODE_VISUAL_DCOMP: case IDM_CREATION_MODE_TARGET_DCOMP: case IDM_CREATION_MODE_VISUAL_WINCOMP: @@ -794,7 +795,8 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam) case IDM_SCENARIO_CLEAR_BROWSING_DATA_AUTOFILL: { return ClearBrowsingData(( - COREWEBVIEW2_BROWSING_DATA_KINDS)(COREWEBVIEW2_BROWSING_DATA_KINDS_GENERAL_AUTOFILL | COREWEBVIEW2_BROWSING_DATA_KINDS_PASSWORD_AUTOSAVE)); + COREWEBVIEW2_BROWSING_DATA_KINDS)(COREWEBVIEW2_BROWSING_DATA_KINDS_GENERAL_AUTOFILL | + COREWEBVIEW2_BROWSING_DATA_KINDS_PASSWORD_AUTOSAVE)); } case IDM_SCENARIO_CLEAR_BROWSING_DATA_BROWSING_HISTORY: { @@ -1390,7 +1392,8 @@ HRESULT AppWindow::OnCreateEnvironmentCompleted( } m_webViewEnvironment = environment; - if (m_webviewOption.entry == WebViewCreateEntry::EVER_FROM_CREATE_WITH_OPTION_MENU + if (m_webviewOption.entry == WebViewCreateEntry::EVER_FROM_CREATE_WITH_OPTION_MENU || + m_creationModeId == IDM_CREATION_MODE_HOST_INPUT_PROCESSING ) { return CreateControllerWithOptions(); @@ -1470,6 +1473,19 @@ HRESULT AppWindow::CreateControllerWithOptions() } //! [ScriptLocaleSetting] + //! [AllowHostInputProcessing] + if (m_creationModeId == IDM_CREATION_MODE_HOST_INPUT_PROCESSING) + { + wil::com_ptr + webView2ExperimentalControllerOptions2; + if (SUCCEEDED( + options->QueryInterface(IID_PPV_ARGS(&webView2ExperimentalControllerOptions2)))) + { + CHECK_FAILURE( + webView2ExperimentalControllerOptions2->put_AllowHostInputProcessing(TRUE)); + } + } + //! [AllowHostInputProcessing] if (m_dcompDevice || m_wincompCompositor) { //! [OnCreateCoreWebView2ControllerCompleted] @@ -2346,8 +2362,7 @@ void AppWindow::UpdateCreationModeMenu() { HMENU hMenu = GetMenu(m_mainWindow); CheckMenuRadioItem( - hMenu, IDM_CREATION_MODE_WINDOWED, - IDM_CREATION_MODE_VISUAL_WINCOMP, + hMenu, IDM_CREATION_MODE_WINDOWED, IDM_CREATION_MODE_HOST_INPUT_PROCESSING, m_creationModeId, MF_BYCOMMAND); } diff --git a/SampleApps/WebView2APISample/ControlComponent.cpp b/SampleApps/WebView2APISample/ControlComponent.cpp index f1c00455..cc463df6 100644 --- a/SampleApps/WebView2APISample/ControlComponent.cpp +++ b/SampleApps/WebView2APISample/ControlComponent.cpp @@ -370,7 +370,7 @@ void ControlComponent::NavigateToAddressBar() } else { - // Otherwise treat it as a web search. + // Otherwise treat it as a web search. std::wstring urlEscaped(2048, ' '); DWORD dwEscaped = (DWORD)urlEscaped.length(); UrlEscapeW(uri.c_str(), &urlEscaped[0], &dwEscaped, URL_ESCAPE_ASCII_URI_COMPONENT); diff --git a/SampleApps/WebView2APISample/ScenarioNonClientRegionSupport.cpp b/SampleApps/WebView2APISample/ScenarioNonClientRegionSupport.cpp index 1d884bf7..3188b7fc 100644 --- a/SampleApps/WebView2APISample/ScenarioNonClientRegionSupport.cpp +++ b/SampleApps/WebView2APISample/ScenarioNonClientRegionSupport.cpp @@ -21,13 +21,12 @@ ScenarioNonClientRegionSupport::ScenarioNonClientRegionSupport(AppWindow* appWin controller.try_query(); if (compController) { - m_compController5 = - compController.try_query(); + m_compController4 = compController.try_query(); } CHECK_FAILURE(m_webView->get_Settings(&m_settings)); - m_experimentalSettings = m_settings.try_query(); + m_settings9 = m_settings.try_query(); CHECK_FAILURE(m_webView->add_NavigationStarting( Callback( @@ -36,22 +35,19 @@ ScenarioNonClientRegionSupport::ScenarioNonClientRegionSupport(AppWindow* appWin { wil::unique_cotaskmem_string uri; CHECK_FAILURE(args->get_Uri(&uri)); - CHECK_FEATURE_RETURN(m_experimentalSettings); + CHECK_FEATURE_RETURN(m_settings9); BOOL enabled = 0; - CHECK_FAILURE( - m_experimentalSettings->get_IsNonClientRegionSupportEnabled(&enabled)); + CHECK_FAILURE(m_settings9->get_IsNonClientRegionSupportEnabled(&enabled)); if (uri.get() == m_sampleUri && !enabled) { - CHECK_FAILURE( - m_experimentalSettings->put_IsNonClientRegionSupportEnabled(TRUE)); + CHECK_FAILURE(m_settings9->put_IsNonClientRegionSupportEnabled(TRUE)); AddChangeListener(); } else if (uri.get() != m_sampleUri && enabled) { - CHECK_FAILURE( - m_experimentalSettings->put_IsNonClientRegionSupportEnabled(FALSE)); + CHECK_FAILURE(m_settings9->put_IsNonClientRegionSupportEnabled(FALSE)); } return S_OK; }) @@ -79,20 +75,19 @@ ScenarioNonClientRegionSupport::ScenarioNonClientRegionSupport(AppWindow* appWin //! [AddChangeListener] void ScenarioNonClientRegionSupport::AddChangeListener() { - if (m_compController5) + if (m_compController4) { - CHECK_FAILURE(m_compController5->add_NonClientRegionChanged( - Callback( + CHECK_FAILURE(m_compController4->add_NonClientRegionChanged( + Callback( [this]( ICoreWebView2CompositionController* sender, - ICoreWebView2ExperimentalNonClientRegionChangedEventArgs* args) -> HRESULT + ICoreWebView2NonClientRegionChangedEventArgs* args) -> HRESULT { COREWEBVIEW2_NON_CLIENT_REGION_KIND region = COREWEBVIEW2_NON_CLIENT_REGION_KIND_NOWHERE; args->get_RegionKind(®ion); - wil::com_ptr - regionsCollection; - m_compController5->QueryNonClientRegion(region, ®ionsCollection); + wil::com_ptr regionsCollection; + m_compController4->QueryNonClientRegion(region, ®ionsCollection); UINT32 count = 0; regionsCollection->get_Count(&count); RECT rect; @@ -108,9 +103,9 @@ ScenarioNonClientRegionSupport::~ScenarioNonClientRegionSupport() { CHECK_FAILURE(m_webView->remove_NavigationStarting(m_navigationStartingToken)); CHECK_FAILURE(m_webView->remove_ContentLoading(m_ContentLoadingToken)); - if (m_compController5) + if (m_compController4) { CHECK_FAILURE( - m_compController5->remove_NonClientRegionChanged(m_nonClientRegionChanged)); + m_compController4->remove_NonClientRegionChanged(m_nonClientRegionChanged)); } } \ No newline at end of file diff --git a/SampleApps/WebView2APISample/ScenarioNonClientRegionSupport.h b/SampleApps/WebView2APISample/ScenarioNonClientRegionSupport.h index 368abe70..3db0d145 100644 --- a/SampleApps/WebView2APISample/ScenarioNonClientRegionSupport.h +++ b/SampleApps/WebView2APISample/ScenarioNonClientRegionSupport.h @@ -21,8 +21,9 @@ class ScenarioNonClientRegionSupport : public ComponentBase AppWindow* m_appWindow; wil::com_ptr m_webView; wil::com_ptr m_settings; - wil::com_ptr m_experimentalSettings; - wil::com_ptr m_compController5; + + wil::com_ptr m_settings9; + wil::com_ptr m_compController4; std::wstring m_sampleUri; EventRegistrationToken m_navigationStartingToken = {}; diff --git a/SampleApps/WebView2APISample/SettingsComponent.cpp b/SampleApps/WebView2APISample/SettingsComponent.cpp index 4627bc70..e3966fdf 100644 --- a/SampleApps/WebView2APISample/SettingsComponent.cpp +++ b/SampleApps/WebView2APISample/SettingsComponent.cpp @@ -1293,15 +1293,15 @@ bool SettingsComponent::HandleWindowMessage( { //![ToggleNonClientRegionSupportEnabled] BOOL nonClientRegionSupportEnabled; - wil::com_ptr experimentalSettings; - experimentalSettings = m_settings.try_query(); - CHECK_FEATURE_RETURN(experimentalSettings); + wil::com_ptr settings; + settings = m_settings.try_query(); + CHECK_FEATURE_RETURN(settings); - CHECK_FAILURE(experimentalSettings->get_IsNonClientRegionSupportEnabled( - &nonClientRegionSupportEnabled)); + CHECK_FAILURE( + settings->get_IsNonClientRegionSupportEnabled(&nonClientRegionSupportEnabled)); if (nonClientRegionSupportEnabled) { - CHECK_FAILURE(experimentalSettings->put_IsNonClientRegionSupportEnabled(FALSE)); + CHECK_FAILURE(settings->put_IsNonClientRegionSupportEnabled(FALSE)); MessageBox( nullptr, L"Non-client region support will be disabled after the next navigation", @@ -1309,7 +1309,7 @@ bool SettingsComponent::HandleWindowMessage( } else { - CHECK_FAILURE(experimentalSettings->put_IsNonClientRegionSupportEnabled(TRUE)); + CHECK_FAILURE(settings->put_IsNonClientRegionSupportEnabled(TRUE)); MessageBox( nullptr, L"Non-client region support will be enabled after the next navigation", diff --git a/SampleApps/WebView2APISample/ViewComponent.cpp b/SampleApps/WebView2APISample/ViewComponent.cpp index 93f8eec9..775ed251 100644 --- a/SampleApps/WebView2APISample/ViewComponent.cpp +++ b/SampleApps/WebView2APISample/ViewComponent.cpp @@ -209,17 +209,16 @@ ViewComponent::ViewComponent( bool ViewComponent::HandleWindowMessage( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT* result) { - wil::com_ptr compositionController5; + wil::com_ptr compositionController4; if (m_compositionController) { - compositionController5 = - m_compositionController - .try_query(); + compositionController4 = + m_compositionController.try_query(); } //! [DraggableRegions1] - if (message == WM_NCHITTEST && compositionController5) + if (message == WM_NCHITTEST && compositionController4) { POINT point{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; ScreenToClient(hWnd, &point); @@ -230,7 +229,7 @@ bool ViewComponent::HandleWindowMessage( COREWEBVIEW2_NON_CLIENT_REGION_KIND region = COREWEBVIEW2_NON_CLIENT_REGION_KIND_NOWHERE; - CHECK_FAILURE(compositionController5->GetNonClientRegionAtPoint(point, ®ion)); + CHECK_FAILURE(compositionController4->GetNonClientRegionAtPoint(point, ®ion)); *result = region; return true; } diff --git a/SampleApps/WebView2APISample/WebView2APISample.rc b/SampleApps/WebView2APISample/WebView2APISample.rc index c0078707..07f8fe4c 100644 --- a/SampleApps/WebView2APISample/WebView2APISample.rc +++ b/SampleApps/WebView2APISample/WebView2APISample.rc @@ -101,6 +101,7 @@ BEGIN POPUP "WebView Creation Mode" BEGIN MENUITEM "Windowed", IDM_CREATION_MODE_WINDOWED + MENUITEM "Windowed - HostInputProcessing", IDM_CREATION_MODE_HOST_INPUT_PROCESSING MENUITEM "Visual - DComp", IDM_CREATION_MODE_VISUAL_DCOMP MENUITEM "Target - DComp", IDM_CREATION_MODE_TARGET_DCOMP MENUITEM "Visual - WinComp", IDM_CREATION_MODE_VISUAL_WINCOMP @@ -294,6 +295,7 @@ BEGIN MENUITEM "Virtual Host Mapping For Pop Up Window", IDM_SCENARIO_VIRTUAL_HOST_MAPPING_POP_UP_WINDOW MENUITEM "Web Messaging", IDM_SCENARIO_POST_WEB_MESSAGE MENUITEM "WebView Event Monitor", IDM_SCENARIO_WEB_VIEW_EVENT_MONITOR + MENUITEM "Dropped file path", IDM_SCENARIO_DROPPED_FILE_PATH MENUITEM "Accelerator Key Pressed", IDM_SCENARIO_ACCELERATOR_KEY_PRESSED END POPUP "&Audio" diff --git a/SampleApps/WebView2APISample/WebView2APISample.vcxproj b/SampleApps/WebView2APISample/WebView2APISample.vcxproj index 86aeb6bb..64df7948 100644 --- a/SampleApps/WebView2APISample/WebView2APISample.vcxproj +++ b/SampleApps/WebView2APISample/WebView2APISample.vcxproj @@ -452,13 +452,13 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + diff --git a/SampleApps/WebView2APISample/assets/AppStartPage.html b/SampleApps/WebView2APISample/assets/AppStartPage.html index 2c7b2f6d..fb8f56fa 100644 --- a/SampleApps/WebView2APISample/assets/AppStartPage.html +++ b/SampleApps/WebView2APISample/assets/AppStartPage.html @@ -8,6 +8,10 @@ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } + html { + color-scheme: light dark; + } + /* This style is used when the app cannot make the background transparent. It will enable this style by executing script. diff --git a/SampleApps/WebView2APISample/packages.config b/SampleApps/WebView2APISample/packages.config index 6f082d4e..a1f4e011 100644 --- a/SampleApps/WebView2APISample/packages.config +++ b/SampleApps/WebView2APISample/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/SampleApps/WebView2APISample/resource.h b/SampleApps/WebView2APISample/resource.h index a444fd7b..af713ed8 100644 --- a/SampleApps/WebView2APISample/resource.h +++ b/SampleApps/WebView2APISample/resource.h @@ -173,6 +173,7 @@ #define IDM_SCENARIO_PRINT_TO_PRINTER 2032 #define IDM_SCENARIO_PRINT_TO_PDF_STREAM 2033 #define IDM_SCENARIO_SHARED_BUFFER 2034 +#define IDM_SCENARIO_DROPPED_FILE_PATH 2035 #define IDM_PERMISSION_MANAGEMENT 2036 #define IDM_SCENARIO_CLEAR_CUSTOM_DATA_PARTITION 2037 #define IDM_SCENARIO_NON_CLIENT_REGION_SUPPORT 2038 @@ -182,6 +183,7 @@ #define IDM_CREATION_MODE_VISUAL_DCOMP 3001 #define IDM_CREATION_MODE_TARGET_DCOMP 3002 #define IDM_CREATION_MODE_VISUAL_WINCOMP 3003 +#define IDM_CREATION_MODE_HOST_INPUT_PROCESSING 3006 #define ID_BLOCKEDSITES 32773 #define ID_SETTINGS_NAVIGATETOSTRING 32774 #define ID_ADD_INITIALIZE_SCRIPT 32775 diff --git a/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj b/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj index 4e4c870b..f9cb9e12 100644 --- a/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj +++ b/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj @@ -25,7 +25,7 @@ AnyCPU - + diff --git a/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs b/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs index e162de8d..95129b52 100644 --- a/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs +++ b/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs @@ -118,6 +118,8 @@ public partial class MainWindow : Window public static RoutedCommand ProgrammaticSaveAsCommand = new RoutedCommand(); public static RoutedCommand ToggleSilentCommand = new RoutedCommand(); public static RoutedCommand ThrottlingControlCommand = new RoutedCommand(); + public static RoutedCommand FileExplorerCommand = new RoutedCommand(); + #endregion commands bool _isNavigating = false; @@ -3313,6 +3315,9 @@ string GetJSONStringField(string jsonMessage, string fieldName) return jsonMessage.Substring(start, end); } + void FileExplorerExecuted(object target, ExecutedRoutedEventArgs e) + { + } void ThrottlingControlExecuted(object target, ExecutedRoutedEventArgs e) { } diff --git a/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj b/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj index 0b4ec122..cdc97525 100644 --- a/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj +++ b/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj @@ -61,7 +61,7 @@ - +