Results 1 to 2 of 2

Thread: Implemetation of dispatchEvent for custom JavaScript object

  1. #1
    Join Date
    Sep 2012
    Location
    Kharkiv
    Posts
    17
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Implemetation of dispatchEvent for custom JavaScript object

    There is a need to create in C++ an object which implements EventTarget DOM interface and export it to JavaScript.
    I already managed to implement addEventListener and removeEventListener methods. But I still need to implement dispatchEvent.
    In my implementation I just store JavaScript function names as QString and then call them using evaluateJavaScript() when correspondent event happens.
    But I faced the problem that when JavaScript event is fired then event object which is passed to event handler has to have target field.
    But unfortunately in JavaScript it is read only. So I'm stuck with the problem how to say JavaScript that target of the event is my object.
    Usually target is set automatically in JavaScript when web element dispatches correspondent event.

    To clarify why do I need this. Currently I'm trying to add audioTracks and videoTracks methods of HTML5 video tag which are currently are unsupported by WebKit.
    That is, I want make it possible to support the following JavaScript code:
    Qt Code:
    1. p = document.getElementById("player");
    2. p.audioTracks.addEventListener("addtrack", evt_handler, false);
    To copy to clipboard, switch view to plain text mode 
    where "player" corresponds to <video> element.
    audioTracks have to implement the next interface:
    Qt Code:
    1. interface AudioTrackList : EventTarget {
    2. readonly attribute unsigned long length;
    3. getter AudioTrack (unsigned long index);
    4. AudioTrack? getTrackById(DOMString id);
    5.  
    6. attribute EventHandler onchange;
    7. attribute EventHandler onaddtrack;
    8. attribute EventHandler onremovetrack;
    9. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2012
    Location
    Kharkiv
    Posts
    17
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Implemetation of dispatchEvent for custom JavaScript object

    Export of audioTracks object I do in the following way:
    Qt Code:
    1. element().webFrame()->addToJavaScriptWindowObject("mediaTracks", m_media_tracks);
    2. element().evaluateJavaScript(QString("this.audioTracks = mediaTracks.audioTracks;"));
    To copy to clipboard, switch view to plain text mode 
    May be it is possible to make audioTracks available in JavaScript as a separate web element (e.g. inherit it from QWebElement)? But how in that case I can add to it my custom functionality?

Similar Threads

  1. Access Object Created by javascript in qml
    By alizadeh91 in forum Qt Quick
    Replies: 6
    Last Post: 23rd February 2012, 15:06
  2. Replies: 9
    Last Post: 29th November 2010, 12:12
  3. Mapping JavaScript object to QT (and vice versa)
    By leoalvesmachado in forum Newbie
    Replies: 2
    Last Post: 30th June 2010, 19:00
  4. add custom HTML attribute by javascript in QtWebKit
    By sand.fj.wen in forum Qt Programming
    Replies: 3
    Last Post: 17th April 2009, 07:25
  5. Replies: 3
    Last Post: 14th October 2008, 21:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.