/// <summary> /// This method should be shared between Window and any HTMLElement /// </summary> /// <param name="eventTarget"></param> /// <param name="type"></param> /// <param name="listener"></param> /// <param name="useCapture"></param> public static void addEventListener(IEventTarget eventTarget, Dictionary<string, List<IEventRegistration>> events, string type, ScriptFunction listener, bool useCapture) { //events always contain event's names without 'on' prefix type = NormalizeEventName(type); EventRegistration eventRegistration = new EventRegistration((UserControl)eventTarget, type, listener, useCapture ? EventPhases.CAPTURING_PHASE : EventPhases.BUBBLING_PHASE); if (!events.ContainsKey(type)) { var eventRegistrations = new List<IEventRegistration>(); eventRegistrations.Add(eventRegistration); events.Add(type, eventRegistrations); } else { bool alreadySubscribed = false; foreach (IEventRegistration existingRegistration in events[type]) { if(existingRegistration.Listener.ToString() == listener.ToString() && existingRegistration.Target == eventTarget) { alreadySubscribed = true; break; } } if (!alreadySubscribed) { events[type].Add(eventRegistration); } } }
internal ReplaceUsingFunction(Regex regex, ScriptFunction function, string source) { this.function = function; this.cArgs = function.GetNumberOfFormalParameters(); bool flag = (function is Closure) && ((Closure) function).func.hasArgumentsObject; this.groupNumbers = null; this.source = source; if ((this.cArgs > 1) || flag) { string[] groupNames = regex.GetGroupNames(); int num = groupNames.Length - 1; if (flag) { this.cArgs = num + 3; } if (num > 0) { if (num > (this.cArgs - 1)) { num = this.cArgs - 1; } this.groupNumbers = new int[num]; for (int i = 0; i < num; i++) { this.groupNumbers[i] = regex.GroupNumberFromName(groupNames[i + 1]); } } } }
public EventRegistration(UserControl target, string type, ScriptFunction listener, EventPhases applyToPhase) { _target = target; _type = type; _listener = listener; _applyToPhase = applyToPhase; }
internal ReplaceUsingFunction(Regex regex, ScriptFunction function, String source) { this.function = function; this.cArgs = function.GetNumberOfFormalParameters(); bool hasArgumentsObject = (function is Closure) && ((Closure)function).func.hasArgumentsObject; this.groupNumbers = null; this.source = source; if (this.cArgs > 1 || hasArgumentsObject) { String[] groupNames = regex.GetGroupNames(); int cGroupNumbers = groupNames.Length - 1; if (hasArgumentsObject) this.cArgs = cGroupNumbers+3; if (cGroupNumbers > 0) { if (cGroupNumbers > this.cArgs - 1) cGroupNumbers = this.cArgs - 1; this.groupNumbers = new int[cGroupNumbers]; for (int i = 0; i < cGroupNumbers; i++) this.groupNumbers[i] = regex.GroupNumberFromName(groupNames[i+1]); } } }
/// <summary> /// Trigger some javascript event on the object /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="eventName"></param> public bool FireEvent(ScriptFunction sf, Event e, object scope) { object result = sf.Invoke(scope, new object[] {e}); //todo: check whether result is NULL? return result is bool ? (bool)result : false; }
internal SortHelper(ScriptFunction cmp) { this.cmp = cmp; }
internal JSPrototypeObject(ScriptObject parent, ScriptFunction constructor) : base(parent, typeof(JSPrototypeObject)) { this.constructor = constructor; this.noExpando = false; }
internal virtual void Sort(ScriptFunction compareFn){ QuickSort qs = new QuickSort(this, compareFn); uint length = this.len; if (length <= this.denseArrayLength) qs.SortArray(0, (int)length - 1); else qs.SortObject(0, length - 1); }
/// <summary> /// This method allows the removal of event listeners from the event target. If an EventListener is removed from an EventTarget while it is processing an event, it will not be triggered by the current actions. EventListeners can never be invoked after being removed. /// Calling removeEventListener with arguments which do not identify any currently registered EventListener on the EventTarget has no effect. /// </summary> /// <param name="type">Specifies the event type of the EventListener being removed.</param> /// <param name="listener">The EventListener parameter indicates the EventListener to be removed.</param> /// <param name="useCapture">Specifies whether the EventListener being removed was registered as a capturing listener or not. If a listener was registered twice, one with capture and one without, each must be removed separately. Removal of a capturing listener does not affect a non-capturing version of the same listener, and vice versa.</param> public void removeEventListener(string type, ScriptFunction listener, bool useCapture) { lock (sync) { EventModel.removeEventListener(this, type, listener, useCapture); } }
internal BuiltinFunction(String name, Object obj, MethodInfo method, ScriptFunction parent) : base(parent, name) { this.noExpando = false; ParameterInfo[] pars = method.GetParameters(); int n = this.ilength = pars.Length; Object[] attrs = method.GetCustomAttributes(Typeob.JSFunctionAttribute, false); JSFunctionAttribute attr = attrs.Length > 0 ? (JSFunctionAttribute)attrs[0] : new JSFunctionAttribute((JSFunctionAttributeEnum)0); JSFunctionAttributeEnum attrVal = attr.attributeValue; if ((attrVal & JSFunctionAttributeEnum.HasThisObject) != 0) this.ilength--; if ((attrVal & JSFunctionAttributeEnum.HasEngine) != 0) this.ilength--; if ((attrVal & JSFunctionAttributeEnum.HasVarArgs) != 0) this.ilength--; this.biFunc = attr.builtinFunction; if (this.biFunc == 0) this.method = new JSNativeMethod(method, obj, this.engine); else this.method = null; }
internal ReplaceDelegate(ScriptFunction fun, string string_obj) { this.fun = fun; this.string_obj = string_obj; }
internal override object GetDefaultValue(PreferredType preferred_type) { if (preferred_type == PreferredType.String) { ScriptFunction memberValue = this.GetMemberValue("toString") as ScriptFunction; if (memberValue != null) { object ob = memberValue.Call(new object[0], this); if (ob == null) { return(ob); } IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(ob); if ((iConvertible != null) && (iConvertible.GetTypeCode() != TypeCode.Object)) { return(ob); } } ScriptFunction function2 = this.GetMemberValue("valueOf") as ScriptFunction; if (function2 != null) { object obj3 = function2.Call(new object[0], this); if (obj3 != null) { IConvertible convertible2 = Microsoft.JScript.Convert.GetIConvertible(obj3); if ((convertible2 == null) || (convertible2.GetTypeCode() == TypeCode.Object)) { goto Label_015D; } } return(obj3); } } else if (preferred_type == PreferredType.LocaleString) { ScriptFunction function3 = this.GetMemberValue("toLocaleString") as ScriptFunction; if (function3 != null) { return(function3.Call(new object[0], this)); } } else { if ((preferred_type == PreferredType.Either) && (this is DateObject)) { return(this.GetDefaultValue(PreferredType.String)); } ScriptFunction function4 = this.GetMemberValue("valueOf") as ScriptFunction; if (function4 != null) { object obj4 = function4.Call(new object[0], this); if (obj4 == null) { return(obj4); } IConvertible convertible3 = Microsoft.JScript.Convert.GetIConvertible(obj4); if ((convertible3 != null) && (convertible3.GetTypeCode() != TypeCode.Object)) { return(obj4); } } ScriptFunction function5 = this.GetMemberValue("toString") as ScriptFunction; if (function5 != null) { object obj5 = function5.Call(new object[0], this); if (obj5 == null) { return(obj5); } IConvertible convertible4 = Microsoft.JScript.Convert.GetIConvertible(obj5); if ((convertible4 != null) && (convertible4.GetTypeCode() != TypeCode.Object)) { return(obj5); } } } Label_015D: return(this); }
internal override void Sort(ScriptFunction compareFn) { SortComparer comparer = new SortComparer(compareFn); Array.Sort(this.value, comparer); }
internal SortComparer(ScriptFunction compareFn) { this.compareFn = compareFn; }
public static void removeEventListener(IEventTarget eventTarget, string type, ScriptFunction listener, bool useCapture) { //events always contain event's names without 'on' prefix type = NormalizeEventName(type); Dictionary<string, List<IEventRegistration>> events = eventTarget.GetEventsCollection(); EventPhases phase = useCapture ? EventPhases.CAPTURING_PHASE : EventPhases.BUBBLING_PHASE; if (events.ContainsKey(type)) { IEventRegistration toRemove = null; foreach (IEventRegistration eventRegistration in events[type]) { if(eventRegistration.ApplyToPhase == phase) { toRemove = eventRegistration; break; } } if(toRemove != null) { events[type].Remove(toRemove); } } }
internal QuickSort(Object obj, ScriptFunction compareFn) { this.compareFn = compareFn; this.obj = obj; }
/// <summary> /// This method allows the registration of event listeners on the event target. /// </summary> /// <param name="type"></param> /// <param name="listener"></param> /// <param name="useCapture"></param> public void addEventListener(string type, ScriptFunction listener, bool useCapture) { if (!events.ContainsKey(type)) { var value = new List<ScriptFunction>(); value.Add(listener); events.Add(type, value); } else { events[type].Add(listener); } }
internal override void Sort(ScriptFunction compareFn) { if (!this.hydrated) { this.Hydrate(); } base.Sort(compareFn); }
internal override void Sort(ScriptFunction compareFn){ SortComparer sc = new SortComparer(compareFn); System.Array.Sort(this.value, sc); }
internal QuickSort(Object obj, ScriptFunction compareFn){ this.compareFn = compareFn; this.obj = obj; }
internal SortComparer(ScriptFunction compareFn){ this.compareFn = compareFn; }
public void addEventListener(string type, ScriptFunction listener, bool useCapture) { (_realObject).addEventListener(type, listener, useCapture); }
internal static CompareDelegate CompareDelegateFor(ScriptFunction fun) { if (fun == null) return new CompareDelegate (SortHelper.nativeCompare); SortHelper helper = new SortHelper (fun); return new CompareDelegate (helper.userCompare); }
internal virtual void Sort(ScriptFunction compareFn) { QuickSort sort = new QuickSort(this, compareFn); uint len = this.len; if (len <= this.denseArrayLength) { sort.SortArray(0, ((int) len) - 1); } else { sort.SortObject(0L, (long) (len - 1)); } }