Ejemplo n.º 1
0
        internal static Task <WebViewControlHost> CreateWebViewControlHostAsync(
            this WebViewControlProcess process,
            IntPtr hostWindowHandle,
            Rect bounds)
        {
            Verify.IsNotNull(process);
            Verify.IsFalse(hostWindowHandle == IntPtr.Zero);

            var rect = new Windows.Foundation.Rect(bounds.X, bounds.Y, bounds.Width, bounds.Height);

            return(process.CreateWebViewControlHostAsync(hostWindowHandle, rect));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="IWebView"/> within the context of <paramref name="process"/>.
        /// </summary>
        /// <param name="process">An instance of <see cref="WebViewControlProcess" />.</param>
        /// <param name="hostWindowHandle">The host window handle.</param>
        /// <param name="bounds">A <see cref="Rect" /> containing numerical values that represent the location and size of the control.</param>
        /// <returns>An <see cref="IWebView" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="hostWindowHandle"/> is equal to <see cref="IntPtr.Zero"/>, or
        /// <paramref name="process"/> is <see langword="null" />.
        /// </exception>
        internal static async Task <IWebView> CreateWebViewAsync(
            this WebViewControlProcess process,
            IntPtr hostWindowHandle,
            Rect bounds)
        {
            if (process is null)
            {
                throw new ArgumentNullException(nameof(process));
            }

            if (hostWindowHandle == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(hostWindowHandle));
            }

            return(new WebView(await process.CreateWebViewControlHostAsync(hostWindowHandle, bounds).ConfigureAwait(false)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a <see cref="IWebView"/> within the context of <paramref name="process"/> using the <paramref name="visual"/> to create a HWND and within the specified <paramref name="bounds"/>.
        /// </summary>
        /// <param name="process">An instance of <see cref="WebViewControlProcess" />.</param>
        /// <param name="visual">A <see cref="Visual"/> instance in which to create a HWND.</param>
        /// <param name="bounds">A <see cref="Rect" /> containing numerical values that represent the location and size of the control.</param>
        /// <returns>An asynchronous operation that completes with a <see cref="IWebView"/>.</returns>
        internal static async Task <IWebView> CreateWebViewAsync(this WebViewControlProcess process, Visual visual, Rect bounds)
        {
            HwndSource sourceHwnd;

            if (!visual.Dispatcher.CheckAccess())
            {
                sourceHwnd = visual.Dispatcher.Invoke(() => (HwndSource)PresentationSource.FromVisual(visual));
            }
            else
            {
                sourceHwnd = (HwndSource)PresentationSource.FromVisual(visual);
            }

            Verify.IsNotNull(sourceHwnd);

            var webViewControlHost = await process.CreateWebViewControlHostAsync(sourceHwnd?.Handle ?? IntPtr.Zero, bounds);

            return(!visual.Dispatcher.CheckAccess()
                ? visual.Dispatcher.Invoke(() => new WebView(webViewControlHost))
                : new WebView(webViewControlHost));
        }