//called when data for any output pin is requested
        public void Update(int SpreadMax)
        {
            if (this.FTextureOutput[0] == null)
            {
                this.FTextureOutput[0] = new DX11Resource <DX11DynamicTexture2D>();
            }

            if (!init)
            {
                width  = DEFAULT_WIDTH;
                height = DEFAULT_HEIGHT;

                lifeSpanHandler = new CfxLifeSpanHandler();
                lifeSpanHandler.OnAfterCreated += lifeSpanHandler_OnAfterCreated;
                lifeSpanHandler.OnBeforePopup  += lifeSpanHandler_OnBeforePopup;

                renderHandler                    = new CfxRenderHandler();
                renderHandler.GetViewRect       += renderHandler_GetViewRect;
                renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
                renderHandler.OnPaint           += renderHandler_OnPaint;

                loadHandler                       = new CfxLoadHandler();
                loadHandler.OnLoadError          += loadHandler_OnLoadError;
                loadHandler.OnLoadingStateChange += loadHandler_OnLoadingStateChange;

                requestHandler = new CfxRequestHandler();
                requestHandler.OnBeforeBrowse       += requestHandler_OnBeforeBrowse;
                requestHandler.OnBeforeResourceLoad += requestHandler_OnBeforeResourceLoad;


                displayHandler = new CfxDisplayHandler();
                displayHandler.OnConsoleMessage += displayHandler_OnConsoleMessage;
                client = new CfxClient();
                client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
                client.GetRenderHandler   += (sender, e) => e.SetReturnValue(renderHandler);
                client.GetLoadHandler     += (sender, e) => e.SetReturnValue(loadHandler);
                client.GetRequestHandler  += (sender, e) => e.SetReturnValue(requestHandler);;
                client.GetDisplayHandler  += (sender, e) => e.SetReturnValue(displayHandler);;



                settings = new CfxBrowserSettings();
                settings.WindowlessFrameRate = 60;
                settings.Webgl                       = CfxState.Enabled;
                settings.Plugins                     = CfxState.Enabled;
                settings.ApplicationCache            = CfxState.Enabled;
                settings.CaretBrowsing               = CfxState.Enabled;
                settings.Javascript                  = CfxState.Enabled;
                settings.FileAccessFromFileUrls      = CfxState.Enabled;
                settings.UniversalAccessFromFileUrls = CfxState.Enabled;
                settings.WebSecUrity                 = CfxState.Disabled;

                visitor        = new CfxStringVisitor();
                visitor.Visit += visitor_Visit;

                // set path to js
                string lpPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "livepage");


                LIVEPAGE_LOAD_FUNC =
                    File.ReadAllText(Path.Combine(lpPath, "load.js")) +
                    File.ReadAllText(Path.Combine(lpPath, "live_resource.js")) +
                    File.ReadAllText(Path.Combine(lpPath, "livepage.js"));

                LIVEPAGE_UNLOAD_FUNC = File.ReadAllText(Path.Combine(lpPath, "unload.js"));

                mouseEvent = new CfxMouseEvent();
                keyCode    = new List <int>();

                createBrowser = true;
                invalidate    = true;
                init          = true;
            }

            if (FTransparentIn.IsChanged)
            {
                createBrowser = true;
            }

            if (createBrowser)
            {
                var windowInfo = new CfxWindowInfo();
                windowInfo.SetAsWindowless(FTransparentIn[0]);
                //windowInfo.WindowlessRenderingEnabled = true;
                //windowInfo.TransparentPaintingEnabled = false;

                if (browser != null)
                {
                    browser.Host.CloseBrowser(true);
                    browser = null;
                }

                CfxBrowserHost.CreateBrowser(windowInfo, client, "", settings, null);

                createBrowser = false;
            }

            if (FMethodIn.IsChanged)
            {
                if (method == null || method.Length != FMethodIn.SliceCount)
                {
                    method = new bool[FMethodIn.SliceCount];
                }
                FResultOut.SliceCount = FMethodIn.SliceCount;
                FMethodOut.SliceCount = FMethodIn.SliceCount;
            }

            if (FLivePageIn.IsChanged)
            {
                ExecuteJavascript(FLivePageIn[0] ? LIVEPAGE_LOAD_FUNC : LIVEPAGE_UNLOAD_FUNC);
            }

            if (FZoomLevelIn.IsChanged)
            {
                zoomLevel = VMath.Map(FZoomLevelIn[0], 0, 1, 0, 10, TMapMode.Clamp);
            }

            for (int i = 0; i < FMethodOut.SliceCount; i++)
            {
                FMethodOut[i] = method[i];
                method[i]     = false;
            }

            if (browser != null)
            {
                if (FShowDevToolsIn.IsChanged && FShowDevToolsIn[0])
                {
                    CfxWindowInfo windowInfo = new CfxWindowInfo();

                    windowInfo.Style        = WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE;
                    windowInfo.ParentWindow = IntPtr.Zero;
                    windowInfo.WindowName   = "DevTools";
                    windowInfo.X            = 200;
                    windowInfo.Y            = 200;
                    windowInfo.Width        = 800;
                    windowInfo.Height       = 600;

                    browser.Host.ShowDevTools(windowInfo, new CfxClient(), new CfxBrowserSettings(), null);
                }


                // mouse
                if (FTouchIn.IsChanged && FTouchIn.SliceCount > 0)
                {
                    mouseEvent.X = (int)VMath.Map(FTouchIn[0].x, -1, 1, 0, width, TMapMode.Float);
                    mouseEvent.Y = (int)VMath.Map(FTouchIn[0].y, 1, -1, 0, height, TMapMode.Float);

                    if (!isTouch)
                    {
                        browser.Host.SendMouseClickEvent(mouseEvent, CfxMouseButtonType.Left, false, 1);
                    }
                    else
                    {
                        browser.Host.SendMouseMoveEvent(mouseEvent, false);
                    }
                    isTouch = true;
                }
                if (isTouch && FTouchIn.SliceCount == 0)
                {
                    browser.Host.SendMouseClickEvent(mouseEvent, CfxMouseButtonType.Left, true, 1);
                    isTouch = false;
                }



                // keyboard
                for (int i = 0; i < keyCode.Count; i++)
                {
                    if (!FKeyCodeIn.Contains(keyCode[i]))
                    {
                        CfxKeyEvent keyEvent = new CfxKeyEvent();

                        keyEvent.Type           = CfxKeyEventType.Keyup;
                        keyEvent.WindowsKeyCode = keyCode[i];
                        keyEvent.NativeKeyCode  = keyCode[i];

                        browser.Host.SendKeyEvent(keyEvent);

                        keyCode.RemoveAt(i);
                        i--;
                    }
                }

                if (FKeyCharIn.SliceCount > 0 && FKeyCodeIn.SliceCount > 0)
                {
                    int count = Math.Max(FKeyCharIn.SliceCount, FKeyCodeIn.SliceCount);
                    for (int i = 0; i < count; i++)
                    {
                        int code = FKeyCodeIn[i];
                        if (code >= 0 && FKeyEventTypeIn[i] != KeyNotificationKind.KeyUp && !keyCode.Contains(code))
                        {
                            CfxKeyEvent keyEvent = new CfxKeyEvent();

                            keyEvent.Type           = CfxKeyEventType.Keydown;
                            keyEvent.WindowsKeyCode = code;
                            keyEvent.NativeKeyCode  = code;

                            browser.Host.SendKeyEvent(keyEvent);
                        }

                        short ch = (short)(FKeyCharIn[i].Length > 0 ? FKeyCharIn[i][0] : 0);
                        if (ch > 0)
                        {
                            CfxKeyEvent keyEvent = new CfxKeyEvent();

                            keyEvent.Type                = CfxKeyEventType.Char;
                            keyEvent.Character           = ch;
                            keyEvent.UnmodifiedCharacter = ch;
                            keyEvent.WindowsKeyCode      = ch;
                            keyEvent.NativeKeyCode       = ch;

                            browser.Host.SendKeyEvent(keyEvent);
                        }
                    }
                }


                if (FReloadIn[0])
                {
                    browser.ReloadIgnoreCache();
                }

                if (zoomLevel != browser.Host.ZoomLevel)
                {
                    browser.Host.ZoomLevel = zoomLevel;
                }

                if (FUpdateDomIn[0])
                {
                    browser.MainFrame.GetSource(visitor);
                }

                if (isDocumentReady)
                {
                    if (FBindIn.IsChanged && FBindIn[0] && FMethodIn.SliceCount > 0)
                    {
                        BindFunctions(FObjectIn[0], FMethodIn.ToArray());
                    }

                    if (FScrollToIn.IsChanged)
                    {
                        scroll = FScrollToIn[0];

                        ExecuteJavascript(
                            string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                          @"window.scrollTo({0} *  document.body.scrollWidth, {1} * document.body.scrollHeight);",
                                          scroll.x,
                                          scroll.y
                                          )
                            );
                    }
                }

                if (FExecuteIn[0])
                {
                    ExecuteJavascript(FJavaScriptIn[0]);
                }

                if (FEvaluateJavaScriptIn[0])
                {
                    EvaluateJavascript(FJavaScriptIn[0], (value, exception) =>
                    {
                        FResultJSOut[0] = CfrV8ValueToString(value);
                    });
                }
            }


            if (FWidthIn.IsChanged || FHeightIn.IsChanged)
            {
                if (FWidthIn.SliceCount > 0 && FHeightIn.SliceCount > 0 && FWidthIn[0] > 0 && FHeightIn[0] > 0)
                {
                    lock (bLock)
                    {
                        width  = FWidthIn[0];
                        height = FHeightIn[0];

                        image        = new byte[width * height * 4];
                        isImageReady = false;
                    }

                    if (browser != null)
                    {
                        browser.Host.WasResized();
                    }

                    invalidate = true;
                }
            }

            FIsLoadingOut[0] = !isDocumentReady;

            this.Mouse    = FMouseIn[0];
            this.Keyboard = FKeyboardIn[0];

            //CfxRuntime.DoMessageLoopWork();
        }
Esempio n. 2
0
 /// <summary>
 /// 重新加载当前页面,并忽略任何缓存数据
 /// </summary>
 public void ReloadIgnoreCache()
 {
     _currentBrowser.ReloadIgnoreCache();
 }