/// <summary>
 /// Asynchronously wait for the Chromium widget window to be created for the given ChromiumWebBrowser,
 /// and when created hook into its Windows message loop.
 /// </summary>
 /// <param name="browser">The browser to intercept Windows messages for.</param>
 /// <param name="forwardAction">This action will be called whenever a Windows message is received.</param>
 internal static void MessageLoop(ChromiumWebBrowser browser, Action <Message> forwardAction)
 {
     Task.Run(() =>
     {
         try
         {
             bool foundWidget = false;
             while (!foundWidget)
             {
                 browser?.Invoke((Action)(async() =>
                 {
                     IntPtr chromeWidgetHostHandle;
                     if (BrowserWidgetHandleFinder.TryFindHandle(browser, out chromeWidgetHostHandle))
                     {
                         foundWidget = true;
                         _ = new BrowserWidgetMessageInterceptor(browser, chromeWidgetHostHandle, forwardAction);
                     }
                     else
                     {
                         // Chrome hasn't yet set up its message-loop window.
                         await Task.Delay(10);
                     }
                 }));
             }
         }
         catch
         {
             // Errors are likely to occur if browser is disposed, and no good way to check from another thread
         }
     });
 }
Ejemplo n.º 2
0
 private void OnBrowserInitializedChanged(object sender, EventArgs args)
 {
     if (IsBrowserInitialized)
     {
         BrowserWidgetMessageInterceptor.MessageLoop(this, (message) =>
         {
             if (message.Msg == (int)Event.LeftButtonDown)
             {
                 var point       = new Point(message.LParam.ToInt32());
                 var dragHandler = DragHandler as BrowserDragHandler;
                 if (dragHandler != null && dragHandler.DraggableRegion.IsVisible(point))
                 {
                     Native.ReleaseCapture();
                     SendHandleMessage();
                 }
             }
         });
     }
 }