Revision: 3168 http://vexi.svn.sourceforge.net/vexi/?rev=3168&view=rev Author: clrg Date: 2008-11-03 13:12:12 +0000 (Mon, 03 Nov 2008)
Log Message: ----------- Tidy up and fix some issues with the chained traps Modified Paths: -------------- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp trunk/core/org.vexi.core/src/org/vexi/plat/Platform.java Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2008-11-03 11:36:48 UTC (rev 3167) +++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2008-11-03 13:12:12 UTC (rev 3168) @@ -1261,7 +1261,7 @@ boolean display = JSU.toBoolean(value); if (test(DISPLAY) != display) { // fire pre-cascade visible traps - VisibleCascade visitraps = get(SC_visible) == value ? null : fireVisibleTraps(display, null); + TrapChain trapchain = get(SC_visible) == value ? null : fireVisibleTraps(display); if (display) { set(DISPLAY); requestReflow(); @@ -1269,7 +1269,7 @@ clear(DISPLAY); } // fire post-cascade visible traps - if (visitraps!=null) visitraps.finishTraps(); + if (trapchain!=null) trapchain.finishTraps(); setParentConstrain(); setParentPlace(); // force dirty in case box size/position do not change @@ -1479,10 +1479,36 @@ private final int getIndexInParent() { return parent == null ? 0 : parent.indexNode(this); } public boolean hasParent() { return parent!=null; } - // firing surface traps - final SurfaceCascade fireSurfaceTraps(JS val, SurfaceCascade trapchain) { + /** represents a chain of traps that may span multiple boxes */ + public static final class TrapChain { + TrapChain next; + JSExn exn; + + public TrapChain(TrapChain trapchain) { next = trapchain; } + + public JS beforeCascade(Box b, JS prop, JS val) { + Trap t = b.wtrap(prop); + try { + if (t != null) return Main.SCHEDULER.runBeforePut(t, val); + } catch (JSExn e) { + exn = e; + } + return null; + } + + public void finishTraps() throws JSExn { finishTraps(exn); } + private void finishTraps(JSExn exn) throws JSExn { + Main.SCHEDULER.runAfterPut(exn); + if (next!=null) next.finishTraps(); + else if (exn!=null) throw exn; + } + } + + /** fires surface traps in a root-first traversal of a box tree */ + private final TrapChain fireSurfaceTraps(JS val, TrapChain trapchain) { if (test(SURFACE_TRAP)) { - trapchain = new SurfaceCascade(val, trapchain); + trapchain = new TrapChain(trapchain); + val = trapchain.beforeCascade(this, SC_surface, val); if (trapchain.exn!=null) return trapchain; } for (int i=0; i<treeSize(); i++) { @@ -1493,28 +1519,12 @@ return trapchain; } - final class SurfaceCascade { - SurfaceCascade next; - Trap trap; - JSExn exn; - - SurfaceCascade(JS val, SurfaceCascade trapchain) { - trap = wtrap(SC_surface); - exn = prePutTriggerTrapsAndCatchExceptions(trap, SC_surface, val); - next = trapchain; - } - - public void finishTraps() { finishTraps(exn); } - private void finishTraps(JSExn exn) { - postPutTriggerTrapsAndCatchExceptions(trap, SC_surface, exn); - if (next!=null) next.finishTraps(exn); - } - } - - // firing visible traps - public final VisibleCascade fireVisibleTraps(boolean val, VisibleCascade trapchain) { + /** fires visible traps in a root-first traversal of a box tree */ + public final TrapChain fireVisibleTraps(boolean visible) { return fireVisibleTraps(visible?JSU.T:JSU.F, null); } + private final TrapChain fireVisibleTraps(JS val, TrapChain trapchain) { if (test(VISIBLE_TRAP)) { - trapchain = new VisibleCascade(val, trapchain); + trapchain = new TrapChain(trapchain); + val = trapchain.beforeCascade(this, SC_visible, val); if (trapchain.exn!=null) return trapchain; } for (int i=0; i<treeSize(); i++) { @@ -1526,24 +1536,6 @@ } return trapchain; } - - public final class VisibleCascade { - VisibleCascade next; - Trap trap; - JSExn exn; - - VisibleCascade(boolean val, VisibleCascade trapchain) { - trap = wtrap(SC_visible); - exn = prePutTriggerTrapsAndCatchExceptions(trap, SC_visible, val?JSU.T:JSU.F); - next = trapchain; - } - - public void finishTraps() { finishTraps(exn); } - private void finishTraps(JSExn exn) { - postPutTriggerTrapsAndCatchExceptions(trap, SC_visible, exn); - if (next!=null) next.finishTraps(exn); - } - } // Tree Manipulation ///////////////////////////////////////////////////////////////////// @@ -1582,10 +1574,10 @@ JS oldsurface = parent==null ? null : parent.getAndTriggerTraps(SC_surface); JS newsurface = newparent==null ? null : newparent.getAndTriggerTraps(SC_surface); // call pre-cascade traps - SurfaceCascade surftraps = oldsurface==newsurface ? null : fireSurfaceTraps(newsurface, null); - VisibleCascade visitraps = + TrapChain trapchain = oldsurface==newsurface ? null : fireSurfaceTraps(newsurface, null); + trapchain = !test(DISPLAY) || (wasvisible == (newparent==null?false:newparent.isVisible())) - ? null : fireVisibleTraps(!wasvisible, null); + ? trapchain : fireVisibleTraps(wasvisible?JSU.F:JSU.T, trapchain); // remove from old parent if (parent != null) { if (wasvisible) dirty(); @@ -1609,8 +1601,7 @@ } } // call post-cascade traps - if (visitraps!=null) visitraps.finishTraps(); - if (surftraps!=null) surftraps.finishTraps(); + if (trapchain!=null) trapchain.finishTraps(); // destroying a surface if (parent == null && newparent == null) { Surface surface = Surface.fromBox(this); Modified: trunk/core/org.vexi.core/src/org/vexi/plat/Platform.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/plat/Platform.java 2008-11-03 11:36:48 UTC (rev 3167) +++ trunk/core/org.vexi.core/src/org/vexi/plat/Platform.java 2008-11-03 13:12:12 UTC (rev 3168) @@ -135,7 +135,7 @@ public static Surface createSurface(Box b, boolean framed) throws JSExn { Surface old = Surface.fromBox(b); // fire pre-cascade visible traps - Box.VisibleCascade visitraps = b.fireVisibleTraps(true, null); + Box.TrapChain trapchain = b.fireVisibleTraps(true); // get the platform implementation of surface Surface ret = platform._createSurface(b, framed); // clean up old Surface @@ -143,7 +143,7 @@ // add to the surfaces list Surface.allSurfaces.addElement(ret); // fire post-cascade visible traps - if (visitraps!=null) visitraps.finishTraps(); + if (trapchain!=null) trapchain.finishTraps(); // add a fully dirty so the entire surface is drawn ret.dirty(0, 0, b.width, b.height); try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn