Ejemplo n.º 1
0
        public unsafe void InitAsChild(IntPtr handle, System.Drawing.Rectangle rect)
        {
            cef_window_info_t *pinfo = WindowInfo.FixedPtr;

            pinfo->parent_window = handle;
            pinfo->x             = rect.Left;
            pinfo->y             = rect.Top;
            pinfo->width         = rect.Width;
            pinfo->height        = rect.Height;

            CefWin.WriteDebugLine("Creating browser " + CefWin.ApplicationElapsed);

            Browser          = CefBrowser.CreateBrowserSync(WindowInfo, Client, Url, Settings);
            MainFrame        = Browser.GetMainFrame();
            BrowserHost      = Browser.GetHost();
            hostWindowHandle = BrowserHost.GetWindowHandle();

            CefWin.WriteDebugLine("Creating browser OK doc:" + Browser.HasDocument + " id:" + Browser.Identifier + ":" + MainFrame.Identifier + " " + CefWin.ApplicationElapsed);
            CefWin.WriteDebugLine("send msgfrombrowser");
            MainFrame.SendProcessMessage(cef_process_id_t.PID_RENDERER, "msgfrombrowser");

            //do not call here, document is not ready!
            //MainFrame.ExecuteJavaScript("console.log('hello CefLite')");

            //ShowDevTools();
        }
Ejemplo n.º 2
0
        public void ShowDevTools(IWin32Window parent = null)
        {
            CfxWindowInfo windowInfo = new CfxWindowInfo();

            if (parent == null)
            {
                windowInfo.Style        = WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE;
                windowInfo.ParentWindow = IntPtr.Zero;
                windowInfo.X            = 200;
                windowInfo.Y            = 200;
                windowInfo.Width        = 800;
                windowInfo.Height       = 600;
            }
            else
            {
                var handle = parent.Handle;
                var rect   = new RECT();
                User32.GetClientRect(handle, ref rect);
                windowInfo.SetAsChild(parent.Handle, 0, 0, rect.Width, rect.Height);
                windowInfo.ParentWindow = handle;
            }


            windowInfo.WindowName = "NanUI Developer Tools";



            BrowserHost.ShowDevTools(windowInfo, new DevToolBrowserClient(), new CfxBrowserSettings(), null);
        }
Ejemplo n.º 3
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            var pt = e.Location;

            GetPointInCurrentView(ref pt);

            CefMouseButtonType buttonType;

            switch (e.Button)
            {
            case MouseButtons.Right:
                buttonType = CefMouseButtonType.Right;
                break;

            case MouseButtons.Middle:
                buttonType = CefMouseButtonType.Middle;
                break;

            default:
                buttonType = CefMouseButtonType.Left;
                break;
            }

            BrowserHost?.SendMouseClickEvent(new CefMouseEvent(pt.X, pt.Y, GetMouseModifiers(e.Button)), buttonType, true, e.Clicks);
        }
Ejemplo n.º 4
0
 public void CloseDevTools()
 {
     if (_devtoolsForm != null && !_devtoolsForm.IsDisposed)
     {
         BrowserHost.CloseDevTools();
     }
 }
        void Attach(IntPtr rpHandle)
        {
            BrowserControl = new BrowserHost(rpHandle);
            OnPropertyChanged(nameof(BrowserControl));

            Navigator.Navigate(Preference.Instance.Browser.Homepage);
        }
Ejemplo n.º 6
0
 public void SendMouseMove(int x, int y, bool mouseLeave, CefEventFlags modifiers = CefEventFlags.None)
 {
     if (!IsBrowserInitialized)
     {
         return;
     }
     BrowserHost.SendMouseMoveEvent(x, y, mouseLeave, modifiers);
 }
 public void Run(BrowserHost host, PipeServer server)
 {
     if (buffer != null && buffer.Length > 0)
     {
         //Logr.Log("Send frame");
         server.SendData(PipeProto.BytesToProtoMessage(buffer, PipeProto.OPCODE_FRAME));
     }
 }
Ejemplo n.º 8
0
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            var pt = ScreenToWindow(e.Location);

            GetPointInCurrentView(ref pt);

            BrowserHost?.SendMouseWheelEvent(new CefMouseEvent(pt.X, pt.Y, GetMouseModifiers(e.Button)), 0, e.Delta);
        }
 protected override void OnGotFocus(System.EventArgs e)
 {
     base.OnGotFocus(e);
     if (BrowserHost != null)
     {
         BrowserHost.SetFocus(true);
     }
 }
Ejemplo n.º 10
0
        public void Constructor_ShouldSetBrowserConfigurationProperty()
        {
            // Act
            _sut = Substitute.ForPartsOf <BrowserHost>(_selenoHost, _browserConfiguration);

            // Assert
            _sut.Configuration.Should().BeSameAs(_browserConfiguration);
        }
Ejemplo n.º 11
0
        public override void MouseOut(UIMouseEvent evt)
        {
            BrowserHost.SendMouseClickEvent(mouseEvent, CfxMouseButtonType.Left, true, 1);
            BrowserHost.SendMouseMoveEvent(mouseEvent, true);

            TChromiumFX.Instance.FocusedBrowser = null;
            BrowserHost.SetFocus(false);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Begins a new composition or updates the existing composition. Blink has a
 /// special node (a composition node) that allows the input method to change
 /// text without affecting other DOM nodes. |text| is the optional text that
 /// will be inserted into the composition node. |underlines| is an optional set
 /// of ranges that will be underlined in the resulting text.
 /// |replacement_range| is an optional range of the existing text that will be
 /// replaced. |selection_range| is an optional range of the resulting text that
 /// will be selected after insertion or replacement. The |replacement_range|
 /// value is only used on OS X.
 /// This method may be called multiple times as the composition changes. When
 /// the client is done making changes the composition should either be canceled
 /// or completed. To cancel the composition call ImeCancelComposition. To
 /// complete the composition call either ImeCommitText or
 /// ImeFinishComposingText. Completion is usually signaled when:
 /// A. The client receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR
 /// flag (on Windows), or;
 /// B. The client receives a "commit" signal of GtkIMContext (on Linux), or;
 /// C. insertText of NSTextInput is called (on Mac).
 /// This method is only used when window rendering is disabled.
 /// </summary>
 public void ImeSetComposition(string text,
                               int underlinesCount,
                               CefCompositionUnderline underlines,
                               CefRange replacementRange,
                               CefRange selectionRange)
 {
     BrowserHost?.ImeSetComposition(text, underlinesCount, underlines, replacementRange, selectionRange);
 }
Ejemplo n.º 13
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            var pt = e.Location;

            GetPointInCurrentView(ref pt);

            BrowserHost?.SendMouseMoveEvent(new CefMouseEvent(pt.X, pt.Y, GetMouseModifiers(e.Button)), false);
        }
Ejemplo n.º 14
0
 public void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY,
                                 CefEventFlags modifiers = CefEventFlags.None)
 {
     if (!IsBrowserInitialized)
     {
         return;
     }
     BrowserHost.SendMouseWheelEvent(x, y, deltaX, deltaY, modifiers);
 }
Ejemplo n.º 15
0
 public void SendMouseClick(int x, int y, MouseButtonType buttonType, bool mouseUp,
                            CefEventFlags modifiers = CefEventFlags.None, int clickCount = 1)
 {
     if (!IsBrowserInitialized)
     {
         return;
     }
     BrowserHost.SendMouseClickEvent(x, y, buttonType, mouseUp, clickCount, modifiers);
     managedCefBrowserAdapter.SendFocusEvent(true);
 }
Ejemplo n.º 16
0
        private void Formium_FormDpiChanged(object sender, DpiChangedEventArgs e)
        {
            //RECT bounds = new RECT(e.Bounds);

            //var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(bounds));

            //Marshal.StructureToPtr(bounds, ptr, false);

            //User32.SendMessage(BrowserHandle, (uint)WindowsMessages.WM_DPICHANGED, Win32.MakeParam(new IntPtr(e.Dpi.Width), new IntPtr(e.Dpi.Height)), ptr);
            BrowserHost.NotifyScreenInfoChanged();
        }
Ejemplo n.º 17
0
        protected override void OnKeyUp(KeyEventArgs e)
        {
            e.Handled = true;

            BrowserHost?.SendKeyEvent(new CefKeyEvent
            {
                EventType      = CefKeyEventType.KeyUp,
                WindowsKeyCode = (int)e.KeyCode,
                Modifiers      = GetKeyboardModifiers(e.Modifiers)
            });
        }
Ejemplo n.º 18
0
 public void Close()
 {
     if (Browser != null)
     {
         BrowserHost.CloseBrowser(true);
         RemoveBrowserCore(Browser.Identifier);
         BrowserHost.Dispose();
         BrowserHost = null;
         Browser.Dispose();
         Browser = null;
     }
 }
Ejemplo n.º 19
0
    public static async Task <int> InvokeAsync(CommonConfiguration commonArgs,
                                               ILoggerFactory loggerFactory,
                                               ILogger logger,
                                               CancellationToken token)
    {
        var args = new BrowserArguments(commonArgs);

        args.Validate();
        var host = new BrowserHost(args, logger);
        await host.RunAsync(loggerFactory, token);

        return(0);
    }
Ejemplo n.º 20
0
        async void Attach(IntPtr rpHandle)
        {
            BrowserControl = new BrowserHost(rpHandle);
            OnPropertyChanged(nameof(BrowserControl));

            Attached?.Invoke();

            BrowserControl.SizeChanged += (s, e) => Resized?.Invoke(this, e.NewSize);

            await Task.Delay(2000);

            Navigator.Navigate(Preference.Instance.Browser.Homepage);
        }
Ejemplo n.º 21
0
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            e.Handled = true;

            BrowserHost?.SendKeyEvent(new CefKeyEvent
            {
                EventType            = CefKeyEventType.Char,
                WindowsKeyCode       = (int)e.KeyChar,
                FocusOnEditableField = true,
                Character            = e.KeyChar
            });
            ;
        }
Ejemplo n.º 22
0
        internal void CloseBrowser()
        {
            unsafe
            {
                if (Browser != null && typeof(CefBrowser).GetField("_self", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(Browser) is Pointer self && Pointer.Unbox(self) != null)
                {
                    BrowserHost?.CloseBrowser(true);
                    BrowserHost?.Dispose();
                    Browser?.Dispose();

                    Dispose();
                }
            }
        }
Ejemplo n.º 23
0
        public UIWebBrowser(string URL = "about:blank")
        {
            this.URL = URL;

            Register();

            OnSizeChanged += size =>
            {
                BrowserHost?.WasResized();

                int width = (int)size.Width, height = (int)size.Height;
                arr     = new byte[width * height * 4];
                texture = new Texture2D(Main.graphics.GraphicsDevice, width, height);
            };
            renderHandler.OnPaint += (sender, args) => { Marshal.Copy(args.Buffer, arr, 0, args.Width * args.Height * 4); };
        }
Ejemplo n.º 24
0
        public void Dispose()
        {
            if (_devtoolsForm != null)
            {
                if (!_devtoolsForm.IsDisposed)
                {
                    _devtoolsForm.Dispose();
                }
                _devtoolsForm = null;
            }

            if (BrowserHost == null)
            {
                return;
            }

            BrowserHost.CloseBrowser();
        }
        /// <summary>
        /// Search for |searchText|. |forward| indicates whether to search forward or
        /// backward within the page. |matchCase| indicates whether the search should
        /// be case-sensitive.
        /// Returns the identifier for this find operation (see also CfxFindHandler),
        /// or -1 if the browser has not yet been created.
        /// </summary>
        public int Find(string searchText, bool forward, bool matchCase)
        {
            if (BrowserHost == null)
            {
                return(-1);
            }
            var findNext = currentFindText == searchText && currentMatchCase == matchCase;

            if (!findNext)
            {
                currentFindText  = searchText;
                currentMatchCase = matchCase;
                ++findId;
            }

            BrowserHost.Find(findId, searchText, forward, matchCase, findNext);
            return(findId);
        }
Ejemplo n.º 26
0
        public void HandleAfterCreated(CefBrowser browser)
        {
            int width = 0, height = 0;

            bool hasAlreadyBeenInitialized = false;

            _mainUiDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
            {
                if (Browser != null)
                {
                    hasAlreadyBeenInitialized = true;
                }
                else
                {
                    Browser     = browser;
                    BrowserHost = Browser.GetHost();
                    // _browserHost.SetFocus(IsFocused);

                    width  = (int)_browserWidth;
                    height = (int)_browserHeight;
                }
            }));

            // Make sure we don't initialize ourselves more than once. That seems to break things.
            if (hasAlreadyBeenInitialized)
            {
                return;
            }

            if (width > 0 && height > 0)
            {
                BrowserHost.WasResized();
            }

            //          mainUiDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
            //          {
            //              if (!string.IsNullOrEmpty(this.initialUrl))
            //              {
            //                  NavigateTo(this.initialUrl);
            //                  this.initialUrl = string.Empty;
            //              }
            //          }));
        }
Ejemplo n.º 27
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_tooltipTimer != null)
                {
                    _tooltipTimer.Stop();
                }

                if (_browserPageImage != null)
                {
                    _browserPageImage.Source = null;
                    _browserPageImage        = null;
                }

                if (_browserPageBitmap != null)
                {
                    _browserPageBitmap = null;
                }

                //                  if (this.browserPageD3dImage != null)
                //                      this.browserPageD3dImage = null;

                // TODO: What's the right way of disposing the browser instance?
                if (BrowserHost != null)
                {
                    BrowserHost.CloseBrowser();
                    BrowserHost = null;
                }

                if (Browser != null)
                {
                    Browser.Dispose();
                    Browser = null;
                }
            }

            _disposed = true;
        }
Ejemplo n.º 28
0
        public void Run(BrowserHost host, PipeServer server)
        {
            string data = "{\"gameObject\" : \"" + gameObject + "\",\"method\" :\"" + method + "\",\"param\" :\"" + param + "\"}";

            server.SendData(PipeProto.BytesToProtoMessage(Encoding.UTF8.GetBytes(data), PipeProto.OPCODE_SCRIPT));
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Download the file at |url| using CefDownloadHandler.
 /// </summary>
 public void StartDownload(string url)
 {
     BrowserHost?.StartDownload(url);
 }
Ejemplo n.º 30
0
 public void SetUp()
 {
     _selenoHost           = new SelenoHost();
     _browserConfiguration = new BrowserConfiguration();
     _sut = Substitute.ForPartsOf <BrowserHost>(_selenoHost, _browserConfiguration);
 }