mobileFX WebKitX ActiveX
Advanced Topics / HTML5 DOM to COM Events
In This Topic
    HTML5 DOM to COM Events
    In This Topic

    Selector based API

    WebKitX provides you access to HTML5 DOM through a robust CSS3 selector-based API. Selectors are used as arguments in editing and styling method calls and as targets in events. The ActiveX provides the selector of the currently selected element and the begin and end nodes of the current selection: ActiveElement, SelAnchorElement, SelFocusElement.

    Copy Code
    td:nth-of-type(3) > span:first-child

    Asynchronous DOM to COM Events

    HTML5 DOM Events are generated by WebKit Blink Engine and are copied into an immutable format before they are transmitted from CEFXClient process to WebKitX ActiveX. Once WebKitX ActiveX receives an event notification through IPC, it fires a COM Event with the copied data of HTML DOM event. Thus, CEFXClient process does not block waiting for your client code to handle the event. WebKitX DOM Events are Immutable, meaning that you can only read event data but you cannot cancel events, stop them from bubbling or prevent default behavior.

    Synchronous DOM to COM Events

    WebKitX as of version supports synchronous DOM to COM events by implementing CefMessageRouter circuit. Events generated from WebKit Blink Engine are serialized and passed from Rendering to Browser process, which transmits them to the ActiveX. The browser process waits for the ActiveX to handle the event, where you can also cancel event bubble or prevent event's default behavior.

    Please note that blocking Inter-process Communication (IPC) between 3 processes is not advisable for casual event handling and you should do so only if you need to cancel specific events. Synchronous DOM to COM Events are thread-safe and care has been placed in order to support this feature seamlessly in single-threaded Applications without deadlocks. For that purpose, synchronous events are serialized using mutex synchronization on entry, meaning that synchronous events occupy the IPC channel one at a time. Please contact us for more implementation details or if you need a different handling of DOM to COM events.


    Listening to DOM Events

    You can use addEventListener and removeEventListener for attaching and detaching on HTML DOM events. WebKitX offers two methods:


    The signature of the public methods is defined by OnEvent() event which is:



    EventData are a JSON string representation of DOM Event:

    Event Data
    Copy Code
      "eventName": "click",
      "eventType": "[object MouseEvent]",
      "altKey": false,
      "bubbles": true,
      "button": 0,
      "buttons": 0,
      "cancelBubble": false,
      "cancelable": true,
      "clientX": 86,
      "clientY": 178,
      "composed": true,
      "ctrlKey": false,
      "currentTarget": "",
      "defaultPrevented": false,
      "detail": 1,
      "eventPhase": 1,
      "fromElement": "",
      "isTrusted": true,
      "layerX": 86,
      "layerY": 178,
      "metaKey": false,
      "movementX": 0,
      "movementY": 0,
      "offsetX": 86,
      "offsetY": 89,
      "originalTarget": "",
      "pageX": 86,
      "pageY": 178,
      "path": "#lga",
      "relatedTarget": "",
      "returnValue": true,
      "screenX": 566,
      "screenY": 415,
      "shiftKey": false,
      "srcElement": "#lga",
      "sourceCapabilities": {},
      "target": "#lga",
      "timeStamp": 8625.205000000002,
      "toElement": "#lga",
      "type": "click",
      "which": 1,
      "x": 86,
      "y": 178,
      "region": null,


    DOM Events Handling Example

    WebKitX Events Sample demonstrates handling DOM events and reading values from Input elements. In the following code fragment are demonstrated the three (3) different methods you can use. The generic method, the AddressOf method that requires a Module, and the IDispatch method that requires an Object. The sample loads a INPUT element and a BUTTON and when you click the button it fires an event which is handled by VB6. The event handler code in VB6 uses WebKitX API to read the value of the INPUT.




    Firing Custom HTML5 Events - DispatchEvent()

    WebKitX DispatchEvent() method allows you to fire DOM events directly into JavaScript and handle those events by JavaScript event handlers. You can pass the target selector that will receive the event, the event name, event initialization parameters (bubbling, cancelable, composed) and an OLE/COM Variant that will be converted into a V8 JavaScript object and added in the details field of the Event object. Event execution can be both synchronous and asynchronous in terms of IPC tunneling, and it is always synchronous in terms of DOM.