public DomEventInstance(DomNodeInstance node, EventInfo eventInfo)
        {
            Getter = new ClrFunctionInstance(node.Engine, (thisObject, arguments) => _function ?? JsValue.Null);
            Setter = new ClrFunctionInstance(node.Engine, (thisObject, arguments) =>
            {
                if (_handler != null)
                {
                    eventInfo.RemoveEventHandler(node.Value, _handler);
                    _handler = null;
                    _function = null;
                }

                if (arguments[0].Is<FunctionInstance>())
                {
                    _function = arguments[0].As<FunctionInstance>();
                    _handler = (s, ev) => 
                    {
                        var sender = s.ToJsValue(node.Context);
                        var args = ev.ToJsValue(node.Context);
                        _function.Call(sender, new [] { args });
                    };
                    eventInfo.AddEventHandler(node.Value, _handler);
                }

                return arguments[0];
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Asynchronously loads a document from the provider <paramref name="url"/> address.
        /// </summary>
        /// <param name="url"></param>
        /// <returns>The loaded document instance.</returns>
        public async Task <WebLoaderResult> LoadAsync(string url)
        {
            // If the route was redirected
            var redirected = false;

            // Prepare the requester callback
            DomEventHandler requesterCallback = (object s, AngleSharp.Dom.Events.Event e)
                                                => Requester_Requested(e as AngleSharp.Dom.Events.RequestEvent, ref redirected);

            // Hook into requested event to monitor a single request in the requester
            Requester.Requested += requesterCallback;

            // Create a browsing context for the request
            var context = BrowsingContext.New(Configuration);

            // Create the result
            var result = new WebLoaderResult
            {
                Redirected = redirected,
                Document   = await context.OpenAsync(url),
            };

            // Once loaded, release hook
            Requester.Requested -= requesterCallback;

            // Return the document once loaded
            return(result);
        }
Exemplo n.º 3
0
        public void EventsCapturingDispatchHandler()
        {
            var evName      = "click";
            var element     = document.QuerySelector("img");
            var args        = document.CreateEvent("event");
            var beforeOther = true;

            args.Init(evName, true, true);
            DomEventHandler listener1 = (s, ev) =>
            {
                Assert.AreEqual(evName, ev.Type);
                Assert.AreEqual(EventPhase.AtTarget, ev.Phase);
                Assert.AreEqual(element, ev.CurrentTarget);
                Assert.AreEqual(element, ev.OriginalTarget);
                Assert.IsFalse(beforeOther);
            };
            DomEventHandler listener2 = (s, ev) =>
            {
                Assert.AreEqual(evName, ev.Type);
                Assert.AreEqual(EventPhase.Capturing, ev.Phase);
                Assert.AreEqual(element.Parent, ev.CurrentTarget);
                Assert.AreEqual(element, ev.OriginalTarget);
                beforeOther = false;
            };

            element.AddEventListener(evName, listener1);
            element.Parent.AddEventListener(evName, listener2, true);
            element.Dispatch(args);
        }
        public DomEventInstance(DomNodeInstance node, EventInfo eventInfo = null)
        {
            Getter = new ClrFunctionInstance(node.Engine, (thisObject, arguments) => _function ?? JsValue.Null);
            Setter = new ClrFunctionInstance(node.Engine, (thisObject, arguments) =>
            {
                if (_handler != null)
                {
                    if (eventInfo != null)
                    {
                        eventInfo.RemoveEventHandler(node.Value, _handler);
                    }

                    _handler  = null;
                    _function = null;
                }

                if (arguments[0].Is <FunctionInstance>())
                {
                    _function = arguments[0].As <FunctionInstance>();
                    _handler  = (s, ev) =>
                    {
                        var sender = s.ToJsValue(node.Context);
                        var args   = ev.ToJsValue(node.Context);
                        _function.Call(sender, new [] { args });
                    };

                    if (eventInfo != null)
                    {
                        eventInfo.AddEventHandler(node.Value, _handler);
                    }
                }

                return(arguments[0]);
            });
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns a task that is completed once the event is fired.
        /// </summary>
        /// <typeparam name="TEventTarget">The event target type.</typeparam>
        /// <param name="node">The node that fires the event.</param>
        /// <param name="eventName">The name of the event to be awaited.</param>
        /// <returns>The awaitable task returning the event arguments.</returns>
        public static async Task <Event> AwaitEventAsync <TEventTarget>(this TEventTarget node, String eventName)
            where TEventTarget : IEventTarget
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (eventName == null)
            {
                throw new ArgumentNullException(nameof(eventName));
            }

            var             completion = new TaskCompletionSource <Event>();
            DomEventHandler handler    = (s, ev) => completion.TrySetResult(ev);

            node.AddEventListener(eventName, handler);

            try
            {
                return(await completion.Task.ConfigureAwait(false));
            }
            finally
            {
                node.RemoveEventListener(eventName, handler);
            }
        }
Exemplo n.º 6
0
        private JsValue SetEventHandler(JsValue thisObject, JsValue[] arguments)
        {
            var node = thisObject.As <DomNodeInstance>();

            if (node != null)
            {
                if (_handler != null)
                {
                    _eventInfo?.RemoveEventHandler(node.Value, _handler);
                    _handler  = null;
                    _function = null;
                }

                if (arguments[0].Is <FunctionInstance>())
                {
                    _function = arguments[0].As <FunctionInstance>();
                    _handler  = (s, ev) =>
                    {
                        var sender = s.ToJsValue(_engine);
                        var args   = ev.ToJsValue(_engine);
                        _function.Call(sender, new[] { args });
                    };

                    _eventInfo?.AddEventHandler(node.Value, _handler);
                }
            }

            return(arguments[0]);
        }
Exemplo n.º 7
0
        void HandleDownloadActivity()
        {
            dynamic domDocument = this.webBrowser.Document;

            if (domDocument == null)
            {
                return;
            }

            if (loading || loaded)
            {
                return;
            }

            this.loading = true;

            if (domDocument.readyState == "complete")
            {
                DomDocumetCompleteHandler(domDocument);
            }
            else
            {
                DomEventHandler handler = null;
                handler = new DomEventHandler(delegate
                {
                    if (domDocument.readyState == "complete")
                    {
                        domDocument.detachEvent("onreadystatechange", handler);
                        DomDocumetCompleteHandler(domDocument);
                    }
                });
                domDocument.attachEvent("onreadystatechange", handler);
            }
        }
Exemplo n.º 8
0
        public FieldContext(FormContext formContext) {
            FormContext = formContext;

            _onBlurHandler = Element_OnBlur;
            _onChangeHandler = Element_OnChange;
            _onInputHandler = Element_OnInput;
            _onPropertyChangeHandler = Element_OnPropertyChange;
        }
Exemplo n.º 9
0
		public HelloWorld(DOMElement te)
		{
			
			this.te = te;
			te.InnerHTML = "hello";
			DomEventHandler handler = new DomEventHandler(DoSomething);
			DomEvent.AddHandler(te, "click", handler);
			
		}
Exemplo n.º 10
0
        public FieldContext(FormContext formContext)
        {
            FormContext = formContext;

            _onBlurHandler           = Element_OnBlur;
            _onChangeHandler         = Element_OnChange;
            _onInputHandler          = Element_OnInput;
            _onPropertyChangeHandler = Element_OnPropertyChange;
        }
Exemplo n.º 11
0
        protected void AddEventHandler(string eventName, DomEventHandler handler)
        {
            var eventHandlerId = ++nextEventHandlerId;

            eventHandlersMap.Add(eventHandlerId, handler);
            AddEventListener(Json.Serialize(new Dictionary <string, string> {
                { "id", _id }, { "eventHandlerId", eventHandlerId.ToString() }, { "eventName", eventName }
            }));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Returns a task that is completed once the event is fired.
        /// </summary>
        /// <typeparam name="TEventTarget">The event target type.</typeparam>
        /// <param name="node">The node that fires the event.</param>
        /// <param name="eventName">The name of the event to be awaited.</param>
        /// <returns>The awaitable task returning the event arguments.</returns>
        public static async Task <Event> AwaitEvent <TEventTarget>(this TEventTarget node, String eventName)
            where TEventTarget : IEventTarget
        {
            var             completion = new TaskCompletionSource <Event>();
            DomEventHandler handler    = (s, ev) => completion.TrySetResult(ev);

            node.AddEventListener(eventName, handler);

            try { return(await completion.Task); }
            finally { node.RemoveEventListener(eventName, handler); }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Removes an event listener from the Node.
 /// </summary>
 /// <param name="type">
 /// A string representing the event type being removed.
 /// </param>
 /// <param name="callback">
 /// The listener parameter indicates the EventListener function to be
 /// removed.
 /// </param>
 /// <param name="capture">
 /// Specifies whether the EventListener being removed was registered as
 /// a capturing listener or not.
 /// </param>
 public void RemoveEventListener(String type, DomEventHandler callback = null, Boolean capture = false)
 {
     if (callback != null && _listeners != null)
     {
         _listeners.Remove(new RegisteredEventListener
         {
             Type       = type,
             Callback   = callback,
             IsCaptured = capture
         });
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Register an event handler of a specific event type on the Node.
 /// </summary>
 /// <param name="type">
 /// A string representing the event type to listen for.
 /// </param>
 /// <param name="callback">
 /// The listener parameter indicates the EventListener function to be
 /// added.
 /// </param>
 /// <param name="capture">
 /// True indicates that the user wishes to initiate capture. After
 /// initiating capture, all events of the specified type will be
 /// dispatched to the registered listener before being dispatched to
 /// any Node beneath it in the DOM tree. Events which are bubbling
 /// upward through the tree will not trigger a listener designated to
 /// use capture.
 /// </param>
 public void AddEventListener(String type, DomEventHandler callback = null, Boolean capture = false)
 {
     if (callback != null)
     {
         Listeners.Add(new RegisteredEventListener
         {
             Type = type,
             Callback = callback,
             IsCaptured = capture
         });
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// Removes an event listener from the Node.
        /// </summary>
        /// <param name="type">
        /// A string representing the event type being removed.
        /// </param>
        /// <param name="callback">
        /// The listener parameter indicates the EventListener function to be
        /// removed.
        /// </param>
        /// <param name="capture">
        /// Specifies whether the EventListener being removed was registered as
        /// a capturing listener or not.
        /// </param>
        public void RemoveEventListener(String type, DomEventHandler callback = null, Boolean capture = false)
        {
            if (callback == null)
                return;

            _listeners.Remove(new RegisteredEventListener
            {
                Type = type,
                Callback = callback,
                IsCaptured = capture
            });
        }
Exemplo n.º 16
0
        /// <summary>
        /// Register an event handler of a specific event type on the Node.
        /// </summary>
        /// <param name="type">
        /// A string representing the event type to listen for.
        /// </param>
        /// <param name="callback">
        /// The listener parameter indicates the EventListener function to be
        /// added.
        /// </param>
        /// <param name="capture">
        /// True indicates that the user wishes to initiate capture. After
        /// initiating capture, all events of the specified type will be
        /// dispatched to the registered listener before being dispatched to
        /// any Node beneath it in the DOM tree. Events which are bubbling
        /// upward through the tree will not trigger a listener designated to
        /// use capture.
        /// </param>
        public void AddEventListener(String type, DomEventHandler callback = null, Boolean capture = false)
        {
            if (callback == null)
            {
                return;
            }

            Listeners.Add(new RegisteredEventListener
            {
                Type       = type,
                Callback   = callback,
                IsCaptured = capture
            });
        }
Exemplo n.º 17
0
        public void EventsAddHandler()
        {
            var evName  = "click";
            var element = document.QuerySelector("img");
            var args    = document.CreateEvent("event");

            args.Init(evName, true, true);
            var             count     = 0;
            DomEventHandler listener1 = (s, ev) => count++;

            element.AddEventListener(evName, listener1);
            element.Dispatch(args);
            Assert.AreEqual(1, count);
            Assert.AreEqual(evName, args.Type);
            Assert.IsFalse(args.IsTrusted);
        }
Exemplo n.º 18
0
        public FormContext(FormElement formElement, DOMElement validationSummaryElement) {
            FormElement = formElement;
            _validationSummaryElement = validationSummaryElement;

            Type.SetField(formElement, _formValidationTag, this);

            // need to retrieve the actual <ul> element, since that will be dynamically modified
            if (validationSummaryElement != null) {
                DOMElementCollection ulElements = validationSummaryElement.GetElementsByTagName("ul");
                if (ulElements.Length > 0) {
                    _validationSummaryULElement = ulElements[0];
                }
            }

            _onClickHandler = Form_OnClick;
            _onSubmitHandler = Form_OnSubmit;
        }
Exemplo n.º 19
0
		public Controller(View view)
		{
			if (Instance == null)
			{
				Instance = this;
				this.view = view;
			}
			this.oldOnFocus = this.view.uiEventName.OnFocus;
			this.view.uiEventName.OnFocus = OnEventNameFocus;
			this.oldTransformReceivedSuggestions = this.view.uiEventName.TransformReceivedSuggestions;
			this.view.uiEventName.TransformReceivedSuggestions = TransformReceivedSuggestions;
			this.oldItemChosen = this.view.uiEventName.ItemChosen;
			this.view.uiEventName.ItemChosen = ItemChosen;
			view.uiEventName.Parameters.Set("returnInfo", true);
			DomEvent.AddHandler(view.uiContainer, "keydown", OnContainerKeyDown);
			DomEvent.AddHandler(view.uiAdd, "click", OnAddClick);
			Misc.AddHoverText(view.uiSummary, "click to select an event");
		}
Exemplo n.º 20
0
        public FormContext(FormElement formElement, DOMElement validationSummaryElement)
        {
            FormElement = formElement;
            _validationSummaryElement = validationSummaryElement;

            Type.SetField(formElement, _formValidationTag, this);

            // need to retrieve the actual <ul> element, since that will be dynamically modified
            if (validationSummaryElement != null)
            {
                DOMElementCollection ulElements = validationSummaryElement.GetElementsByTagName("ul");
                if (ulElements.Length > 0)
                {
                    _validationSummaryULElement = ulElements[0];
                }
            }

            _onClickHandler  = Form_OnClick;
            _onSubmitHandler = Form_OnSubmit;
        }
Exemplo n.º 21
0
        public void EventsCustomHandlerViaConstructor()
        {
            var evName    = "myevent";
            var element   = document.QuerySelector("img");
            var args      = new CustomEvent();
            var mydetails = new object();

            args.Init(evName, true, true, mydetails);
            DomEventHandler listener = (s, ev) =>
            {
                Assert.AreEqual(args, ev);
                Assert.AreEqual(evName, ev.Type);
                Assert.AreEqual(EventPhase.AtTarget, ev.Phase);
                Assert.AreEqual(element, ev.CurrentTarget);
                Assert.AreEqual(element, ev.OriginalTarget);
                Assert.AreEqual(mydetails, args.Details);
            };

            element.AddEventListener(evName, listener);
            element.Dispatch(args);
        }
Exemplo n.º 22
0
 private void HandleDownloadActivity()
 {
     try
     {
         mshtml.HTMLDocument domDocument = (mshtml.HTMLDocument) this._webBrowser.Document;
         if (domDocument == null)
         {
             return;
         }
         if (_isLoading || _isLoaded)
         {
             return;
         }
         this._isLoading = true;
         if (domDocument.readyState == "complete")
         {
             DomDocumentCompleteHandler(domDocument);
         }
         else
         {
             DomEventHandler handler = null;
             handler = new DomEventHandler(delegate
             {
                 if (domDocument.readyState == "complete")
                 {
                     domDocument.detachEvent("onreadystatechange", handler);
                     DomDocumentCompleteHandler(domDocument);
                 }
             });
             domDocument.attachEvent("onreadystatechange", handler);
         }
     }
     catch (Exception ex)
     {
         AppLog.LogException(ex);
     }
 }
Exemplo n.º 23
0
 public static void RemoveContextMenu(this IElement element, DomEventHandler handler) =>
 element.RemoveEventListener("contextmenu", handler);
Exemplo n.º 24
0
 public static void AddContextMenu(this IElement element, DomEventHandler handler) =>
 element.AddEventListener("contextmenu", handler);
Exemplo n.º 25
0
 public static void RemoveUnload(this IElement element, DomEventHandler handler) =>
 element.RemoveEventListener("unload", handler);
Exemplo n.º 26
0
 public static void AddUnload(this IElement element, DomEventHandler handler) =>
 element.AddEventListener("unload", handler);
Exemplo n.º 27
0
 public static void RemoveFocusOut(this IElement element, DomEventHandler handler) =>
 element.RemoveEventListener("focusout", handler);
Exemplo n.º 28
0
 void IEventTarget.RemoveEventListener(string type, DomEventHandler callback, bool capture) => _host.RemoveEventListener(type, callback, capture);
Exemplo n.º 29
0
 public void RemoveEventListener(string type, DomEventHandler callback = null, bool capture = false)
 {
 }
Exemplo n.º 30
0
 public void AddEventListener(string type, DomEventHandler callback = null, bool capture = false)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 31
0
 public RegisteredEventListener(String type, DomEventHandler callback, Boolean isCaptured)
 {
     Type       = type;
     Callback   = callback;
     IsCaptured = isCaptured;
 }
Exemplo n.º 32
0
 public void RemoveEventListener(String type, DomEventHandler callback = null, Boolean capture = false)
 {
     _host.RemoveEventListener(type, callback, capture);
 }
Exemplo n.º 33
0
 ///<summary>
 ///Removes a DOM event handler from the element that exposes the event.
 ///</summary>
 ///<param name="element">The element that exposes the event.</param>
 ///<param name="eventName">The name of the event. Do not include the "on" prefix. For example, specify "click" instead of "onclick".</param>
 ///<param name="handler">The client function that is called when the event occurs.</param>
 public static void removeHandler(HtmlElement element, string eventName, DomEventHandler handler) { }
Exemplo n.º 34
0
 ///<summary>
 ///Removes a DOM event handler from the singleton object represented by a type.
 ///(Eg. Window and Document)
 ///</summary>
 ///<param name="type">The element that exposes the event.</param>
 ///<param name="eventName">The name of the event. Do not include the "on" prefix. For example, specify "click" instead of "onclick".</param>
 ///<param name="handler">The client function that is called when the event occurs.</param>
 public static void removeHandler(System.Type type, string eventName, DomEventHandler handler) { }
Exemplo n.º 35
0
 public void AddEventListener(String type, DomEventHandler callback = null, Boolean capture = false)
 {
     _window.AddEventListener(type, callback, capture);
 }
Exemplo n.º 36
0
 public static void AddFocusOut(this IElement element, DomEventHandler handler) =>
 element.AddEventListener("focusout", handler);
Exemplo n.º 37
0
 public void RemoveEventListener(String type, DomEventHandler callback = null, Boolean capture = false)
 {
     _host.RemoveEventListener(type, callback, capture);
 }
 public void AddEventListener(String type, DomEventHandler callback = null, Boolean capture = false)
 {
     _window.AddEventListener(type, callback, capture);
 }