Example #1
0
        private void button7_Click(object sender, EventArgs e)
        {
            //1. init html
            var initHtml = "<html><script>function doc_ready(){console.log('doc_ready');}</script><body onload=\"doc_ready()\"><div id=\"a\">A</div><div id=\"b\" style=\"background-color:blue\">B</div><div id=\"c\">c_node</div></body></html>";

            easeViewport.LoadHtmlString("", initHtml);
            //----------------------------------------------------------------
            //after load html page

            //load v8 if ready

#if DEBUG
            JsBridge.dbugTestCallbacks();
#endif
            //===============================================================

            //2. access dom

            var webdoc = easeViewport.GetHtmlDom() as LayoutFarm.WebDom.IHtmlDocument;
            //create js engine and context
            if (myengine == null)
            {
                var jstypeBuilder = new LayoutFarm.Scripting.MyJsTypeDefinitionBuilder();
                myengine = new JsEngine();
                myCtx    = myengine.CreateContext(jstypeBuilder);
            }

            System.Diagnostics.Stopwatch stwatch = new System.Diagnostics.Stopwatch();
            stwatch.Reset();
            stwatch.Start();
            myCtx.SetVariableAutoWrap("document", webdoc);
            myCtx.SetVariableAutoWrap("console", myWbConsole);
            string simplejs   = @"
                    (function(){
                        console.log('hello world!');
                        var domNodeA = document.getElementById('a');
                        var domNodeB = document.getElementById('b');
                        var domNodeC = document.getElementById('c');

                        var newText1 = document.createTextNode('... says hello world!');
                        domNodeA.appendChild(newText1);

                        for(var i=0;i<10;++i){
                            var newText2= document.createTextNode(i.toString());
                            domNodeA.appendChild(newText2);       
                        } 

                        var newDivNode= document.createElement('div');
                        newDivNode.appendChild(document.createTextNode('new div'));
                        newDivNode.attachEventListener('mousedown',function(){console.log('new div');});
                        domNodeB.appendChild(newDivNode);    
                        
                        domNodeC.innerHTML='<div> from inner html <span> from span</span> </div>';
                        console.log(domNodeC.innerHTML);
                    })();
                ";
            object testResult = myCtx.Execute(simplejs);
            stwatch.Stop();
            Console.WriteLine("met1 template:" + stwatch.ElapsedMilliseconds.ToString());
        }
Example #2
0
 internal void InitJsEngine()
 {
     if (myengine == null)
     {
         var jstypeBuilder = new LayoutFarm.Scripting.MyJsTypeDefinitionBuilder();
         myengine = new JsEngine();
         myCtx = myengine.CreateContext(jstypeBuilder);
     }
     myCtx.SetVariableAutoWrap("document", HtmlDoc);
     myCtx.SetVariableAutoWrap("console", Console);
 }
Example #3
0
 internal void InitJsEngine()
 {
     if (myengine == null)
     {
         var jstypeBuilder = new LayoutFarm.Scripting.MyJsTypeDefinitionBuilder();
         myengine = new JsEngine();
         myCtx    = myengine.CreateContext(jstypeBuilder);
     }
     myCtx.SetVariableAutoWrap("document", HtmlDoc);
     myCtx.SetVariableAutoWrap("console", Console);
 }
Example #4
0
        private void button5_Click(object sender, EventArgs e)
        {
            //1. init html
            var fileContent = "<html><body><div id=\"a\">A</div><div id=\"b\" style=\"background-color:blue\">B</div></body></html>";

            easeViewport.LoadHtmlString("", fileContent);
            //----------------------------------------------------------------
            //after load html page

            //test javascript ...

#if DEBUG
            JsBridge.dbugTestCallbacks();
#endif
            //===============================================================

            //2. access dom

            var webdoc = easeViewport.GetHtmlDom() as IHtmlDocument;
            //create js engine and context
            var jstypeBuilder = new LayoutFarm.Scripting.MyJsTypeDefinitionBuilder();
            using (JsEngine engine = new JsEngine())
                using (JsContext ctx = engine.CreateContext(jstypeBuilder))
                {
                    System.Diagnostics.Stopwatch stwatch = new System.Diagnostics.Stopwatch();
                    stwatch.Reset();
                    stwatch.Start();
                    ctx.SetVariableAutoWrap("document", webdoc);
                    string testsrc1 = "document.getElementById('a');";
                    object domNodeA = ctx.Execute(testsrc1);
                    string testsrc2 = "document.getElementById('b');";
                    object domNodeB = ctx.Execute(testsrc2);
                    stwatch.Stop();
                    Console.WriteLine("met1 template:" + stwatch.ElapsedMilliseconds.ToString());
                }

            ////3. get element by id
            //var domNodeA = webdoc.GetElementById("a");
            //var domNodeB = webdoc.GetElementById("b");

            //domNodeA.AddTextContent("Hello from A");
            //domNodeB.AddChild("div", div =>
            //{
            //    div.SetAttribute("style", "background-color:yellow");
            //    div.AddTextContent("Hello from B");
            //});

            //domNodeB.AttachMouseDownEvent(ev =>
            //{
            //    var domB = new EaseDomElement(domNodeB);
            //    domB.SetBackgroundColor(Color.Red);
            //    ev.StopPropagation();
            //    //domNodeB.SetAttribute("style", "background-color:red");
            //});
            //domNodeB.AttachMouseUpEvent(ev =>
            //{
            //    var domB = new EaseDomElement(domNodeB);
            //    domB.SetBackgroundColor(Color.Yellow);
            //    ev.StopPropagation();
            //    //domNodeB.SetAttribute("style", "background-color:red");
            //});
        }
Example #5
0
        private void button7_Click(object sender, EventArgs e)
        {

            //1. init html
            var initHtml = "<html><script>function doc_ready(){console.log('doc_ready');}</script><body onload=\"doc_ready()\"><div id=\"a\">A</div><div id=\"b\" style=\"background-color:blue\">B</div><div id=\"c\">c_node</div></body></html>";
            easeViewport.LoadHtmlString("", initHtml);
            //----------------------------------------------------------------
            //after load html page 

            //load v8 if ready

#if DEBUG
            JsBridge.dbugTestCallbacks();
#endif
            //===============================================================

            //2. access dom  

            var webdoc = easeViewport.GetHtmlDom() as LayoutFarm.WebDom.IHtmlDocument;
            //create js engine and context
            if (myengine == null)
            {
                var jstypeBuilder = new LayoutFarm.Scripting.MyJsTypeDefinitionBuilder();
                myengine = new JsEngine();
                myCtx = myengine.CreateContext(jstypeBuilder);
            }

            System.Diagnostics.Stopwatch stwatch = new System.Diagnostics.Stopwatch();
            stwatch.Reset();
            stwatch.Start();
            myCtx.SetVariableAutoWrap("document", webdoc);
            myCtx.SetVariableAutoWrap("console", myWbConsole);
            string simplejs = @"
                    (function(){
                        console.log('hello world!');
                        var domNodeA = document.getElementById('a');
                        var domNodeB = document.getElementById('b');
                        var domNodeC = document.getElementById('c');

                        var newText1 = document.createTextNode('... says hello world!');
                        domNodeA.appendChild(newText1);

                        for(var i=0;i<10;++i){
                            var newText2= document.createTextNode(i.toString());
                            domNodeA.appendChild(newText2);       
                        } 

                        var newDivNode= document.createElement('div');
                        newDivNode.appendChild(document.createTextNode('new div'));
                        newDivNode.attachEventListener('mousedown',function(){console.log('new div');});
                        domNodeB.appendChild(newDivNode);    
                        
                        domNodeC.innerHTML='<div> from inner html <span> from span</span> </div>';
                        console.log(domNodeC.innerHTML);
                    })();
                ";
            object testResult = myCtx.Execute(simplejs);
            stwatch.Stop();
            Console.WriteLine("met1 template:" + stwatch.ElapsedMilliseconds.ToString());
        }
Example #6
0
        private void button5_Click(object sender, EventArgs e)
        {

            //1. init html
            var fileContent = "<html><body><div id=\"a\">A</div><div id=\"b\" style=\"background-color:blue\">B</div></body></html>";
            easeViewport.LoadHtmlString("", fileContent);
            //----------------------------------------------------------------
            //after load html page 

            //test javascript ... 

#if DEBUG
            JsBridge.dbugTestCallbacks();
#endif
            //===============================================================

            //2. access dom  

            var webdoc = easeViewport.GetHtmlDom() as IHtmlDocument;
            //create js engine and context
            var jstypeBuilder = new LayoutFarm.Scripting.MyJsTypeDefinitionBuilder();
            using (JsEngine engine = new JsEngine())
            using (JsContext ctx = engine.CreateContext(jstypeBuilder))
            {
                System.Diagnostics.Stopwatch stwatch = new System.Diagnostics.Stopwatch();
                stwatch.Reset();
                stwatch.Start();
                ctx.SetVariableAutoWrap("document", webdoc);
                string testsrc1 = "document.getElementById('a');";
                object domNodeA = ctx.Execute(testsrc1);
                string testsrc2 = "document.getElementById('b');";
                object domNodeB = ctx.Execute(testsrc2);
                stwatch.Stop();
                Console.WriteLine("met1 template:" + stwatch.ElapsedMilliseconds.ToString());
            }

            ////3. get element by id 
            //var domNodeA = webdoc.GetElementById("a");
            //var domNodeB = webdoc.GetElementById("b");

            //domNodeA.AddTextContent("Hello from A");
            //domNodeB.AddChild("div", div =>
            //{
            //    div.SetAttribute("style", "background-color:yellow");
            //    div.AddTextContent("Hello from B");
            //});

            //domNodeB.AttachMouseDownEvent(ev =>
            //{
            //    var domB = new EaseDomElement(domNodeB);
            //    domB.SetBackgroundColor(Color.Red);
            //    ev.StopPropagation();
            //    //domNodeB.SetAttribute("style", "background-color:red");
            //});
            //domNodeB.AttachMouseUpEvent(ev =>
            //{
            //    var domB = new EaseDomElement(domNodeB);
            //    domB.SetBackgroundColor(Color.Yellow);
            //    ev.StopPropagation();
            //    //domNodeB.SetAttribute("style", "background-color:red");
            //}); 
        }