Example #1
0
        // Sends an event called |event_name| to javascript, with an event.detail that contains
        // the fields and values of the |detail| structure.
        public void DispatchToJS(JSEvent e)
        {
            JObject ev = new JObject();

            ev["type"]   = e.EventName();
            ev["detail"] = JObject.FromObject(e);
            DispatchEvent(ev);
        }
Example #2
0
 // Sends an event called |event_name| to javascript, with an event.detail that contains
 // the fields and values of the |detail| structure.
 public void DispatchToJS(JSEvent e) {
   dispatch_string_builder_.Append("document.dispatchEvent(new CustomEvent('");
   dispatch_string_builder_.Append(e.EventName());
   dispatch_string_builder_.Append("', { detail: ");
   dispatch_serializer_.Serialize(dispatch_json_writer_, e);
   dispatch_string_builder_.Append(" }));");
   this.Overlay.Renderer.ExecuteScript(dispatch_string_builder_.ToString());
   dispatch_string_builder_.Clear();
 }
Example #3
0
        public bool HandleEvent(JSEvent e)
        {
            try
            {
                Debug.WriteLine("Listeners loop starts here");
                var callFrame = new mdr.CallFrame();
                callFrame.PassedArgsCount = 1;
                callFrame.Arg0.Set(e);
                callFrame.Signature = new mdr.DFunctionSignature(ref callFrame, 1);
                callFrame.This      = e.CurrentTarget;
                mdr.DFunction handler;
                bool          eventPropagationStopped = false;
                if (_listeners == null)
                {
                    return(false);
                }
                Debug.WriteLine("Listeners loop with " + _listeners.Count + "  listeners");


                //The event listener loop (inner loop)
                for (var i = 0; i < _listeners.Count; ++i)
                {
                    handler            = _listeners[i];
                    callFrame.Function = handler;

                    if (handler != null)
                    {
                        if (_useCaptures.Contains(handler))
                        {
                            e.Phase = JSEvent.Phases.Captureing;
                            //TODO: Capturing
                        }
                        callFrame.Function.Call(ref callFrame);

                        if (e.PropagationStopped)
                        {
                            eventPropagationStopped = true;
                        }
                        if (e.ImmediatePropagationStopped)
                        {
                            eventPropagationStopped = true;
                            break;
                        }
                    }
                }

                return(eventPropagationStopped);
            }
            catch (System.Exception ex)
            {
                Diagnostics.WriteException(ex, "when processing event");
                return(false);
            }
        }
        public static mdr.DProperty CreateProperty(string propertyName)
        {
            EventTypes type = JSEvent.GetPropertyEventType(propertyName);

            if (type == EventTypes.ZoommInvalid)
            {
                throw new Exception(String.Format("Unimplemented EventHandlerProperty {0}", propertyName));
            }
            else
            {
                return(new EventHandlerProperty(type));
            }
        }
 // Sends an event called |event_name| to javascript, with an event.detail that contains
 // the fields and values of the |detail| structure.
 public void DispatchToJS(JSEvent e)
 {
     // DispatchToJS can be called from multiple threads (both fast and main).
     // OverlayMessage also calls this, which can be on other threads as well.
     // Could consider adding per-thread builders in TLS to avoid a lock, but maybe overkill.
     lock (this.dispatch_lock_) {
         dispatch_string_builder_.Append("document.dispatchEvent(new CustomEvent('");
         dispatch_string_builder_.Append(e.EventName());
         dispatch_string_builder_.Append("', { detail: ");
         dispatch_serializer_.Serialize(dispatch_json_writer_, e);
         dispatch_string_builder_.Append(" }));");
         this.Overlay.Renderer.ExecuteScript(dispatch_string_builder_.ToString());
         dispatch_string_builder_.Clear();
     }
 }
Example #6
0
 IntPtr setInterval(int count, IntPtr args)
 {
     object[] data = vm.Deserialize(count, args);
     JSFunctionPtr ptr = data[0] as JSFunctionPtr;
     if (!eventthreadrunning)
     {
         eventthreadrunning = true;
         System.Threading.Thread mthread = new Thread(eventthread);
         mthread.Start();
     }
     JSEvent tt = new JSEvent();
     JSMarshaller marshal = new JSMarshaller();
     marshal.args = new object[0];
     marshal.DeleteAfterExecution = false;
     marshal.ptr = ptr;
     tt.marshaller = marshal;
     tt.timeout = (int)data[1];
     tt.repeating = true;
     events.Add(tt);
     eventTimer.Set();
     intervals.Add(ivalid, ptr);
     ivalid++;
     return vm.Serialize(this, ivalid-1);
 }
Example #7
0
        public bool HandleEvent(JSEvent e)
        {
            try
            {
                Debug.WriteLine("Listeners loop starts here");
                var callFrame = new mdr.CallFrame();
                callFrame.PassedArgsCount = 1;
                callFrame.Arg0.Set(e);
                callFrame.Signature = new mdr.DFunctionSignature(ref callFrame, 1);
                callFrame.This = e.CurrentTarget;
                mdr.DFunction handler;
                bool eventPropagationStopped = false;
                if (_listeners == null)
                {
                    return false;
                }
                Debug.WriteLine("Listeners loop with " + _listeners.Count + "  listeners");


                //The event listener loop (inner loop)
                for (var i = 0; i < _listeners.Count; ++i)
                {
                    handler = _listeners[i];
                    callFrame.Function = handler;

                    if (handler != null)
                    {
                        if (_useCaptures.Contains(handler))
                        {
                            e.Phase = JSEvent.Phases.Captureing;
                            //TODO: Capturing 
                        }
                        callFrame.Function.Call(ref callFrame);

                        if (e.PropagationStopped)
                        {
                            eventPropagationStopped = true;
                        }
                        if (e.ImmediatePropagationStopped)
                        {
                            eventPropagationStopped = true;
                            break;
                        }

                    }
                }

                return eventPropagationStopped;
            }
            catch (System.Exception ex)
            {
              Diagnostics.WriteException(ex, "when processing event");
              return false;
            }
        }
        /// <summary>
        /// コンストラクタ。
        /// </summary>
        public CanvasContext(TextEditorComponent textEditorComponent, IJSInProcessRuntime jsRuntime, JSEvent jsEvent)
        {
            _textEditorComponent = textEditorComponent;
            _jsRuntime           = jsRuntime;

            _textEditorComponent.Created += size =>
            {
                jsEvent.RegisterActionListener("TextEditorComponent.resize", args => Resize?.Invoke(ToSize(args)));
                jsEvent.RegisterActionListener("TextEditorComponent.mousedown", args => MouseDown?.Invoke(ToMouseState(args)));
                jsEvent.RegisterActionListener("TextEditorComponent.mouseup", args => MouseUp?.Invoke(ToMouseState(args)));
                jsEvent.RegisterActionListener("TextEditorComponent.mousemove", args => MouseMove?.Invoke(ToMouseState(args)));
                jsEvent.RegisterActionListener("TextEditorComponent.mousewheel", args => MouseWheel?.Invoke(ToMouseState(args)));
                jsEvent.RegisterActionListener("TextEditorComponent.render", _ => RenderFrame?.Invoke(new RenderingContext(_textEditorComponent)));
                jsEvent.RegisterActionListener("InputMethod.focusin", args => GotFocus?.Invoke());
                jsEvent.RegisterActionListener("InputMethod.focusout", args => LostFocus?.Invoke());

                Created?.Invoke(size);
            };
        }