mozilla

Revision 78745 of Creating Custom Events That Can Pass Data

  • Revision slug: Creating_Custom_Events_That_Can_Pass_Data
  • Revision title: Creating Custom Events That Can Pass Data
  • Revision id: 78745
  • Created:
  • Creator: Themystic
  • Is current revision? No
  • Comment

Revision Content

Objective

This page describes how to create Custom (C++) Events that can Pass Data. Meaning that you can add extra parameters and query them. One example is lets say you want ff to perform an action whenever something happens, but depending of severity of that event you will react with a different severity. Ok, so that's a great example but work with me.

Requirements

This is no easy task. In order to do this you must be able to do all of the following

What's In A Name

Despite whatever you may have heard in your english class there's a lot in a name. As of Bon Echo Alpha 2, if your do not start with "nsDOM" and their interfaces do not start with "nsIDOM" then you can forget about passing data. You will still be able to throw events but that is it.

The Trunk

You may have wondered why is it that you need to download (or check out) the source it's because you will have to modify the source. But wait does that mean my stuff won't work with anyone else's version of Firefox? Yes. Unless you get your patches into the trunk. Why isn't there a better way of doing this? That's a very good question.

mozilla/dom/public/nsIDOMClassInfo.h

The change you make here is really rather small but it is incredibly important. If you peruse nsIDOMClassInfo.h you'll find an enum named nsDOMClassInfoID. You'll want to add an entry to it. Your entry should be second last. The last one, eDOMClassInfoIDCount, is a counter. Your entry should look like this:

eDOMClassInfo_{truncated name}_id, 

Here's the fun part: Above I mentioned that you must name your events as nsDOM, well here you want to put the other part of the name (e.g. if you have an event named nsDOMMyFirstEvent your nsDOMClassInfoID entry would be eDOMClassInfo_MyFirstEvent_id).

mozilla/dom/src/base/nsDOMClassInfo.cpp

Added a few more macro calls:

  • around line 1000:
NS_DEFINE_CLASSINFO_DATA(strkGoBack, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) 
  • around line 2900:
DOM_CLASSINFO_MAP_BEGIN(strkGoBack, StrkIGoBack)
  DOM_CLASSINFO_MAP_ENTRY(StrkIGoBack)
DOM_CLASSINFO_MAP_END

Revision Source

<h3 name="Objective"> Objective </h3>
<p>This page describes how to create Custom (C++) Events that can Pass Data. Meaning that you can add extra parameters and query them. One example is lets say you want ff to perform an action whenever <em>something</em> happens, but depending of severity of that event you will react with a different severity. Ok, so that's a great example but work with me.
</p>
<h3 name="Requirements"> Requirements </h3>
<p>This is no easy task. In order to do this you must be able to do all of the following
</p>
<ul><li> <a href="en/Download_Mozilla_Source_Code">Download Mozilla Source Code</a>
</li><li> <a href="en/Build_Documentation">Build Mozilla</a>
</li><li> <a href="en/Creating_Custom_Firefox_Extensions_with_the_Mozilla_Build_System">Creating Custom Firefox Extensions with the Mozilla Build System</a>, this is the foundation for everything we'll do. I'll go over some (very little) of it so do this <em>first</em> then come back and do this tutorial.
</li></ul>
<h3 name="What.27s_In_A_Name"> What's In A Name </h3>
<p>Despite whatever you may have heard in your english class there's a lot in a name. As of Bon Echo Alpha 2, if your do not start with "nsDOM" and their interfaces do not start with "nsIDOM" then you can forget about passing data. You will still be able to throw events but that is it.
</p>
<h3 name="The_Trunk"> The Trunk </h3>
<p>You may have wondered why is it that you need to download (or check out) the source it's because you will have to modify the source. But wait does that mean my stuff won't work with anyone else's version of Firefox? Yes. Unless you get your patches into the trunk. Why isn't there a better way of doing this? That's a very good question.
</p>
<h4 name="mozilla.2Fdom.2Fpublic.2FnsIDOMClassInfo.h"> mozilla/dom/public/nsIDOMClassInfo.h </h4>
<p>The change you make here is really rather small but it is incredibly important. If you peruse nsIDOMClassInfo.h you'll find an enum named <a class="external" href="http://landfill.mozilla.org/mxr-test/mozilla1.8.x/ident?i=nsDOMClassInfoID">nsDOMClassInfoID</a>. You'll want to add an entry to it. Your entry should be second last. The last one, eDOMClassInfoIDCount, is a counter. Your entry should look like this:
</p>
<pre class="eval">eDOMClassInfo_{truncated name}_id, 
</pre>
<p>Here's the fun part: Above I mentioned that you must name your events as nsDOM, well here you want to put the other part of the name (e.g. if you have an event named nsDOMMyFirstEvent your nsDOMClassInfoID entry would be eDOMClassInfo_MyFirstEvent_id).
</p>
<h4 name="mozilla.2Fdom.2Fsrc.2Fbase.2FnsDOMClassInfo.cpp"> mozilla/dom/src/base/nsDOMClassInfo.cpp </h4>
<p>Added a few more macro calls:
</p>
<ul><li> around line 1000: 
</li></ul>
<pre class="eval">NS_DEFINE_CLASSINFO_DATA(strkGoBack, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) 
</pre>
<ul><li> around line 2900: 
</li></ul>
<pre class="eval">DOM_CLASSINFO_MAP_BEGIN(strkGoBack, StrkIGoBack)
  DOM_CLASSINFO_MAP_ENTRY(StrkIGoBack)
</pre>
<pre class="eval">DOM_CLASSINFO_MAP_END
</pre>
Revert to this revision