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]; }); }
/// <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); }
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]); }); }
/// <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); } }
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]); }
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); } }
public FieldContext(FormContext formContext) { FormContext = formContext; _onBlurHandler = Element_OnBlur; _onChangeHandler = Element_OnChange; _onInputHandler = Element_OnInput; _onPropertyChangeHandler = Element_OnPropertyChange; }
public HelloWorld(DOMElement te) { this.te = te; te.InnerHTML = "hello"; DomEventHandler handler = new DomEventHandler(DoSomething); DomEvent.AddHandler(te, "click", handler); }
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 } })); }
/// <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); } }
/// <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 }); } }
/// <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 }); } }
/// <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 }); }
/// <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 }); }
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); }
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; }
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"); }
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); }
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); } }
public static void RemoveContextMenu(this IElement element, DomEventHandler handler) => element.RemoveEventListener("contextmenu", handler);
public static void AddContextMenu(this IElement element, DomEventHandler handler) => element.AddEventListener("contextmenu", handler);
public static void RemoveUnload(this IElement element, DomEventHandler handler) => element.RemoveEventListener("unload", handler);
public static void AddUnload(this IElement element, DomEventHandler handler) => element.AddEventListener("unload", handler);
public static void RemoveFocusOut(this IElement element, DomEventHandler handler) => element.RemoveEventListener("focusout", handler);
void IEventTarget.RemoveEventListener(string type, DomEventHandler callback, bool capture) => _host.RemoveEventListener(type, callback, capture);
public void RemoveEventListener(string type, DomEventHandler callback = null, bool capture = false) { }
public void AddEventListener(string type, DomEventHandler callback = null, bool capture = false) { throw new NotImplementedException(); }
public RegisteredEventListener(String type, DomEventHandler callback, Boolean isCaptured) { Type = type; Callback = callback; IsCaptured = isCaptured; }
public void RemoveEventListener(String type, DomEventHandler callback = null, Boolean capture = false) { _host.RemoveEventListener(type, callback, capture); }
///<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) { }
///<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) { }
public void AddEventListener(String type, DomEventHandler callback = null, Boolean capture = false) { _window.AddEventListener(type, callback, capture); }
public static void AddFocusOut(this IElement element, DomEventHandler handler) => element.AddEventListener("focusout", handler);