示例#1
0
    public void TestConstructor()
    {
        increment = 0;
        IEventTarget eventTarget = (IEventTarget)doc.DocumentElement;

        // Add first event listener
        eventTarget.AddEventListener("mousemove", new EventListener(OnMouseMove), false);
        eventTarget.DispatchEvent(new Event("uievent", "mousemove", true, false));
        Assert.AreEqual(1, increment);

        // Add second event listener
        // "If multiple identical EventListeners are registered on the same EventTarget with the same
        //  parameters the duplicate instances are discarded. They do not cause the EventListener to
        //  be called twice and since they are discarded they do not need to be removed with the removeEventListener method."
        eventTarget.AddEventListener("mousemove", new EventListener(OnMouseMove), false);
        eventTarget.DispatchEvent(new Event("uievent", "mousemove", true, false));
        Assert.AreEqual(2, increment);

        // Remove first event listener
        eventTarget.RemoveEventListener("mousemove", new EventListener(OnMouseMove), false);
        eventTarget.DispatchEvent(new Event("uievent", "mousemove", true, false));
        Assert.AreEqual(2, increment);

        // Remove second event listener
        // "Calling removeEventListener with arguments which do not identify any currently registered EventListener on the EventTarget has no effect."
        eventTarget.RemoveEventListener("mousemove", new EventListener(OnMouseMove), false);
        eventTarget.DispatchEvent(new Event("uievent", "mousemove", true, false));
        Assert.AreEqual(2, increment);
    }
示例#2
0
        /// <summary>
        /// Add event listeners for on* events within the document
        /// </summary>
        private void InitializeEvents()
        {
            SvgDocument document = (SvgDocument)window.Document;

            document.NamespaceManager.AddNamespace("svg", "http://www.w3.org/2000/svg");

            XmlNodeList nodes = document.SelectNodes(@"//*[namespace-uri()='http://www.w3.org/2000/svg']
                                                   [local-name()='svg' or
                                                    local-name()='g' or
                                                    local-name()='defs' or
                                                    local-name()='symbol' or
                                                    local-name()='use' or
                                                    local-name()='switch' or
                                                    local-name()='image' or
                                                    local-name()='path' or
                                                    local-name()='rect' or
                                                    local-name()='circle' or
                                                    local-name()='ellipse' or
                                                    local-name()='line' or
                                                    local-name()='polyline' or
                                                    local-name()='polygon' or
                                                    local-name()='text' or
                                                    local-name()='tref' or
                                                    local-name()='tspan' or
                                                    local-name()='textPath' or
                                                    local-name()='altGlyph' or
                                                    local-name()='a' or
                                                    local-name()='foreignObject']
                                                /@*[name()='onfocusin' or
                                                    name()='onfocusout' or
                                                    name()='onactivate' or
                                                    name()='onclick' or
                                                    name()='onmousedown' or
                                                    name()='onmouseup' or
                                                    name()='onmouseover' or
                                                    name()='onmousemove' or
                                                    name()='onmouseout' or
                                                    name()='onload']", document.NamespaceManager);

            foreach (XmlNode node in nodes)
            {
                IAttribute att         = (IAttribute)node;
                IEventTarget targ      = (IEventTarget)att.OwnerElement;
                ScriptEventMonitor mon = new ScriptEventMonitor((VsaScriptEngine)GetScriptEngineByMimeType(""), att, window);
                string eventName       = null;
                switch (att.Name)
                {
                case "onfocusin":
                    eventName = "focusin";
                    break;

                case "onfocusout":
                    eventName = "focusout";
                    break;

                case "onactivate":
                    eventName = "activate";
                    break;

                case "onclick":
                    eventName = "click";
                    break;

                case "onmousedown":
                    eventName = "mousedown";
                    break;

                case "onmouseup":
                    eventName = "mouseup";
                    break;

                case "onmouseover":
                    eventName = "mouseover";
                    break;

                case "onmousemove":
                    eventName = "mousemove";
                    break;

                case "onmouseout":
                    eventName = "mouseout";
                    break;

                case "onload":
                    eventName = "SVGLoad";
                    break;
                }
                targ.AddEventListener(eventName, new EventListener(mon.EventHandler), false);
            }
        }