Infrequently Noted

Alex Russell on browsers, standards, and the process of progress.

Neat

Good ideas are rarely convenient.

I've been trying to figure out ways to clean up the requirements that NW places on body tags for pages. Similarly, I've been trying to figure out ways to make keystroke events fire for the "selected" component, and nothing else, and today it hit me.

Instead of writing:

onLoad="__NW_env__.init();"
onmousemove="__NW_env__.setCurrXY(event);
onmousedown=" __NW_env__.selectAndResize(event);
onmouseup="__NW_env__.unsetSelectedComponent();"
onmouseover="__NW_env__.setTooltips(event);"
onmouseout="__NW_env__.disolveTooltips();"

for each body tag, we should be able to something like:

onLoad="__NW_env__.onLoad(event);" //console omitted
onmousemove="__NW_env__.onMouseMove(event);
onmousedown=" __NW_env__.onMouseDown(event);
onmouseup="__NW_env__.onMouseUp(event);"
onmouseover="__NW_env__.onMouseOver(event);"
onmouseout="__NW_env__.onMouseOut(event);"

etc...

and let each of those member functions of the environment core handle the dispatching. Better yet:

onLoad="NW_onLoad(event);"
onmousemove="NW_onMouseMove(event);
onmousedown=" NW_onMouseDown(event);
onmouseup="NW_onMouseUp(event);"
onmouseover="NW_onMouseOver(event);"
onmouseout="NW_onMouseOut(event);"

etc...

should also work, again dispatching each event to the proper functions and objects. I think such an approach will clean up environment pages considerably. But the part that's really exciting of my revelation was that for each of these new functions (likely memebers of NW_env), there should be an array of function pointers that widgets and components can add to and remove from at will. Each time said event fires, all of these FPs should also be called. Basically, each event will get it's own "registry" of function pointers. By doing this, we could put a bit of code in the component selection code that will allow us to "register" the selected component's keystroke handlers with the global event handler for keystrokes. The global handler can intercept any environment-level keystrokes, while passing the rest on to the registered FPs.

Modifications required to the core to make this happen:

  1. event specific wrapper functions in __NW_env__, register/unregister functions for FPs to each event.
  2. modifications to the setSelectedComponent() function to support FP registering
  3. modifications to the component class to support keystroke functions and registering with sub-components. Only top-level components should be registering with the environment, so sub-components should be able to register with the top-level comp for inclusion in the chain.
  4. modify earth days to include an extra 12 hours in order to have time to implement this.

The really exciting (I think) part about this approach is that it's going to let us do really neat effects based on events (movement, keystrokes, etc...) that would have required much more elaborate changes previously. In this way, we're exposing infinately extensible "hooks" into each event via the environment core. This way we can keep the environment pages clean and still give ourselves enough flexibility moving forward.

And I just finished the environment page tutorial. Damnit.