예제 #1
0
        static INode as_INode(this object e)
        {
            if (e != null)
            {
                // every browser names the Node type differently?

                // what about comments?
                if (Expando.InternalIsMember(e, "nodeType"))
                {
                    var nodeType = (int)Expando.InternalGetMember(e, "nodeType");

                    if (nodeType != 0)
                    {
                        return((INode)e);
                    }
                }

                // not yet?
                // see also: X:\jsc.svn\core\ScriptCoreLib\JavaScript\WebGL\WebGLRenderingContext.cs
                //if (Expando.InternalIsMember(e, "canvas"))
                //{
                //    return as_INode(Expando.InternalGetMember(e, "canvas"));
                //}
            }



            return(null);
        }
예제 #2
0
        public INode[] selectNodes(string path)
        {
            var native = ((__IXMLDocument_Native)(object)this);

            if (IActiveX.IsSupported)
            {
                return(native.selectNodes(path));
            }

            if (Expando.InternalIsMember(this, "selectNodes"))
            {
                return(native.selectNodes(path));
            }

            return((INode[])
                   new IFunction("sXPath", @"
    var oEvaluator = new XPathEvaluator();
    var oResult = oEvaluator.evaluate(sXPath, this, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
    var aNodes = new Array();

    if (oResult != null) 
    {
        var oElement = oResult.iterateNext();

        while(oElement) 
        {
            aNodes.push(oElement);
            oElement = oResult.iterateNext();
        }
    }

    return aNodes;
").apply(this, path));
        }
예제 #3
0
        public void InternalEvent(bool bAttach, global::System.Delegate e, EventNames n)
        {
            // http://help.dottoro.com/ljrtxexf.php

            IFunction z = ((BCLImplementation.System.__Delegate)(object) e).InvokePointer;

            // does IE9 define both functions?

            if (bAttach)
            {
                if (Expando.InternalIsMember(this, "addEventListener"))
                {
                    // https://developer.mozilla.org/en-US/docs/DOM/element.addEventListener
                    addEventListener(n.EventListener, z);

                    if (n.EventListenerAlt != null)
                    {
                        addEventListener(n.EventListenerAlt, z);
                    }
                }
                else if (Expando.InternalIsMember(this, "attachEvent"))
                {
                    attachEvent(n.Event, z);

                    if (n.EventAlt != null)
                    {
                        attachEvent(n.EventAlt, z);
                    }
                }

                return;
            }

            #region remove
            if (Expando.InternalIsMember(this, "removeEventListener"))
            {
                removeEventListener(n.EventListener, z, false);

                if (n.EventListenerAlt != null)
                {
                    removeEventListener(n.EventListenerAlt, z, false);
                }
            }
            else if (Expando.InternalIsMember(this, "detachEvent"))
            {
                detachEvent(n.Event, z);

                if (n.EventAlt != null)
                {
                    detachEvent(n.EventAlt, z);
                }
            }
            #endregion
        }
예제 #4
0
        public static Task <IFunction> ByName(string name, object target = null)
        {
            // X:\jsc.svn\examples\javascript\test\TestChromeStackFrames\TestChromeStackFrames\Application.cs

            // X:\jsc.svn\examples\javascript\Test\TestHistoryForwardEvent\TestHistoryForwardEvent\Application.cs
            Console.WriteLine("enter IFunction.ByName " + new { name });

            // X:\jsc.svn\core\ScriptCoreLib.Async\ScriptCoreLib.Async\JavaScript\DOM\HistoryExtensions.cs

            // tested by
            // X:\jsc.svn\examples\javascript\WorkerInsideSecondaryApplication\WorkerInsideSecondaryApplicationWithStateReplaceTwice\Application.cs

            if (target == null)
            {
                target = Native.self;
            }

            var x = new TaskCompletionSource <IFunction>();

            Action y = delegate
            {
                if (Expando.InternalIsMember(target, name))
                {
                    // should wo typecheck that member?
                    var f = (IFunction)Expando.InternalGetMember(target, name);

                    x.SetResult(f);
                    return;
                }

                // ?
            };

            y();

            if (!x.Task.IsCompleted)
            {
                new Timer(
                    t =>
                {
                    y();

                    if (x.Task.IsCompleted)
                    {
                        t.Stop();
                    }
                }
                    ).StartInterval(15);
            }

            return(x.Task);
        }
예제 #5
0
 public void RemoveRule(int index)
 {
     if (Expando.InternalIsMember(this, "removeRule"))
     {
         this.removeRule(index);
     }
     else if (Expando.InternalIsMember(this, "deleteRule"))
     {
         this.deleteRule(index);
     }
     else
     {
         throw new System.NotSupportedException("RemoveRule");
     }
 }
예제 #6
0
        public CSSStyleRule AddRule(string selectorText, string declaration, int index)
        {
            //34ms __get_item IStyleSheet { selectorText = @media print } view-source:35342
            //35ms AddRule { selectorText = @media print, Length = 0 } view-source:35342
            //38ms AddRule { selectorText = 0, Length = 1 } view-source:35342
            //39ms IStyleSheetRule.AddRule error { text = 0{/**/} }

            // https://developer.mozilla.org/en-US/docs/Web/CSS/@media
            // http://davidwalsh.name/add-rules-stylesheets

            if (Expando.InternalIsMember(this, "insertRule"))
            {
                // I/Web Console(32117): IStyleSheetRule.AddRule error { text = @media print{/**/} }


                var text = selectorText + "{" + declaration + "}";



                try
                {
                    this.insertRule(text, index);
                }
                catch
                {
                    // tested by
                    // X:\jsc.svn\examples\javascript\Test\TestCSSPrint\TestCSSPrint\Application.cs


                    Console.WriteLine("IStyleSheetRule.AddRule error " + new { text });
                    throw;
                }

                return(this.Rules[index]);
            }

            if (Expando.InternalIsMember(this, "addRule"))
            {
                this.addRule(selectorText, declaration, index);
                return(this.Rules[index]);
            }



            throw new System.Exception("fault at IStyleSheetRule.AddRule");
        }
예제 #7
0
        public INode selectSingleNode(string path)
        {
            var native = ((__IXMLDocument_Native)(object)this);

            if (IActiveX.IsSupported)
            {
                return(native.selectSingleNode(path));
            }

            // opera: http://www.opera.com/docs/changelogs/windows/902/
            if (Expando.InternalIsMember(this, "selectSingleNode"))
            {
                return(native.selectSingleNode(path));
            }

            return((INode)
                   new IFunction("elementPath", @"
       var xpe = new XPathEvaluator();
           var nsResolver = xpe.createNSResolver( this.ownerDocument == null ? this.documentElement : this.ownerDocument.documentElement);
           var results = xpe.evaluate(elementPath,this,nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE, null);
           return results.singleNodeValue;             
            ").apply(this, path));
        }
예제 #8
0
파일: Native.cs 프로젝트: wclwksn/code
        static Native()
        {
            //at ScriptCoreLib.JavaScript.Native.__Uint8ClampedArray() in x:\jsc.svn\core\ScriptCoreLib\JavaScript\WebGL\Uint8ClampedArray.cs:line 19
            //at ScriptCoreLib.JavaScript.Native..cctor() in x:\jsc.svn\core\ScriptCoreLib\JavaScript\Native.cs:line 185

            __Uint8ClampedArray();


            __RTCPeerConnection();


            // what is it?
            if (Expando.InternalIsMember(self, "document") &&
                Expando.InternalIsMember(self, "screen"))
            {
                // should be a window with a document
                window = (IWindow)self;

                document = window.document;
                screen   = window.screen;

                // were ApplicationWebserviceFields decrypted befoe this point?
                __ToBase64String();

                // https:// !!!

                __initialize_identity();


                return;
            }



            // are all browsers reporting it as the same type?
            // what if it could have multiple names?
            Native.serviceworker = self as ServiceWorkerGlobalScope;
            // X:\jsc.svn\examples\javascript\Test\TestServiceWorkerRegistrations\TestServiceWorkerRegistrations\Application.cs

            if (Native.serviceworker == null)
            {
                // ok detect other modes...


                if (Expando.InternalIsMember(self, "importScripts"))
                {
                    if (Expando.InternalIsMember(self, "postMessage"))
                    {
                        // now what. are we running as a web worker?
                        // WorkerGlobalScope
                        // DedicatedWorkerGlobalScope
                        // DedicatedWorkerContext

                        worker = (DedicatedWorkerGlobalScope)self;
                        return;
                    }

                    // now what. are we running as a web worker?
                    // WorkerGlobalScope
                    // DedicatedWorkerGlobalScope
                    // DedicatedWorkerContext

                    sharedworker = (SharedWorkerGlobalScope)self;
                }
            }
        }