Implementation Analysis of HTML5 video in WebKit (5)-transfer of video events in WebKit

Source: Internet
Author: User
Every element of HTML allows JavaScript to process certain events. For example, attribute settings such as onclick = "clickbutton.
As described in the following blog, each element in WebKit has its own JS binding implementation: [WebKit] Is Javascript
Three methods of adding a new DOM object with binding and implementing video elements, you can check the implementation in jshtmlmediaelement. cpp and jshtmlvideoelement. cpp.
Here we will only talk about the event processing mechanism. This is how to call the corresponding processing functions of javascript when an event occurs in WebKit.
In addition to common HTML Dom node events, video elements also have some specific events, such as played, paused, and ended. These can be seen in jshtmlmediaelement. cpp: static const hashtablevalue jshtmlmediaelementtablevalues []
= {"Error", dontdelete | readonly,
(Intptr_t) static_cast <propertyslot: getvaluefunc> (jshtmlmediaelementerror ),
(Intptr_t) 0, nointrinsic}, {"played", dontdelete | readonly,
(Intptr_t) static_cast <propertyslot: getvaluefunc> (jshtmlmediaelementplayed ),
(Intptr_t) 0, nointrinsic}, {"seekable", dontdelete | readonly,
(Intptr_t) static_cast <propertyslot: getvaluefunc> (jshtmlmediaelementseekable ),
(Intptr_t) 0, nointrinsic}, {"ended", dontdelete | readonly,
(Intptr_t) static_cast <propertyslot: getvaluefunc> (jshtmlmediaelementended ),
(Intptr_t) 0, nointrinsic },...
Do you still remember how WebKit parses video attributes? See here: Implementation Analysis of HTML5 video in WebKit (1)-the basic structure and htmlmediaelement & mediaplayer are also in the htmlmediaelement: parseattribute function, the following code snippet is available :...... else if (attrname = onabortattr) setattributeeventlistener (eventnames (). abortevent, createattributeeventlistener (this, ATTR); else if (attrname = onbeforeloadattr) setattributeeventlistener (eventnames (). beforeloadevent, createattributeeventlistener (this, ATTR); setattr Ibuteeventlistener () is to add the newly specified event handler function to the eventtarget object's hash table (eventlistenermap) through eventtarget: addeventlistener ). Its second parameter is an eventlistener, which is responsible for final execution of this event processing function. To trigger an event, use the following method: If (m_networkstate = network_loading | m_networkstate = network_idle) scheduleevent (eventnames (). abortevent); the above Code indicates that if the condition is true, an abort event will be triggered to JavaScript. Scheduleevent is mainly used to create an eventtarget object and add it to the queue of the so-called genericeventqueue for asynchronous execution. At execution time (genericeventqueue: timerfired (), it is then executed by eventtarget. Check the registered event handler function and execute the JavaScript function. The following is a complete sequence diagram for your reference ( Note that when the inheritance relationship of htmlmediaelement is returned to node, you will see that htmlmediaelement is also inherited from eventtarget.): For reprint, please indicate the source: http://blog.csdn.net/horkychen#: Implementation Analysis of HTML5 video in WebKit (4)
-Video loading and playback Sequence

Next article: Implementation Analysis of HTML5 video in WebKit (6)-Safari video Mechanism Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.