Revision: 3509 http://vexi.svn.sourceforge.net/vexi/?rev=3509&view=rev Author: clrg Date: 2009-05-26 02:18:29 +0000 (Tue, 26 May 2009)
Log Message: ----------- Refactor TrapChain into it's own file and rename WriteTrapChain Modified Paths: -------------- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp trunk/core/org.vexi.core/src/org/vexi/core/Surface.java Added Paths: ----------- trunk/core/org.vexi.core/src/org/vexi/core/WriteTrapChain.java Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2009-05-26 00:21:46 UTC (rev 3508) +++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2009-05-26 02:18:29 UTC (rev 3509) @@ -1410,7 +1410,7 @@ boolean display = JSU.toBoolean(value); if (test(DISPLAY) != display) { // fire pre-cascade visible traps - TrapChain trapchain = get(SC_visible) == value ? null : fireVisibleTraps(display); + WriteTrapChain trapchain = get(SC_visible) == value ? null : fireVisibleTraps(display); if (display) { set(DISPLAY); requestReflow(); @@ -1683,76 +1683,37 @@ return Surface.fromBox(b) != null; } - /** represents a chain of traps that may span multiple boxes */ - public static final class TrapChain { - int chainlength = 0; - JSExn exn; - - /** add a trap on 'b.prop' to the trap chain by executing pre-put of 'val' */ - public JS beforeCascade(Box b, JS prop, JS val) { - Trap t = b.wtrap(prop); - try { - if (t != null) { - chainlength++; - return Main.SCHEDULER.runBeforePut(t, val); - } - } catch (JSExn e) { - chainlength--; - exn = e; - } - return null; - } - - /** use to invoke internal finishTraps */ - public void finishTraps() throws JSExn { finishTraps(exn); } - - /** finish the trap chain represented by this object */ - private void finishTraps(JSExn exn) throws JSExn { - while (chainlength>0) { - try { - chainlength--; - Main.SCHEDULER.runAfterPut(exn); - exn = null; - } catch(JSExn e) { - exn = e; - } - } - // exception was not caught in JS, re-throw - 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) { + private final WriteTrapChain fireSurfaceTraps(JS val, WriteTrapChain trapchain) { if (test(SURFACE_TRAP)) { - if (trapchain == null) trapchain = new TrapChain(); - val = trapchain.beforeCascade(this, SC_surface, val); + if (trapchain == null) trapchain = new WriteTrapChain(); + val = trapchain.beforeCascade(wtrap(SC_surface), val); // interrupted by a JS exception - if (trapchain.exn != null) + if (trapchain.returnedNormally()) return trapchain; } int i=0; for (Box b = getChild(i); b!=null; b=getChild(++i)) { trapchain = b.fireSurfaceTraps(val, trapchain); // interrupted by a JS exception - if (trapchain != null && trapchain.exn != null) + if (trapchain != null && trapchain.returnedNormally()) return trapchain; } return trapchain; } /** function used by Platform.createSurface to invoke fireVisibleTraps */ - public final TrapChain fireVisibleTraps(boolean visible) { + public final WriteTrapChain fireVisibleTraps(boolean visible) { return fireVisibleTraps(visible ? JSU.T : JSU.F, null); } /** fires visible traps in a root-first traversal of a box tree */ - private final TrapChain fireVisibleTraps(JS val, TrapChain trapchain) { + private final WriteTrapChain fireVisibleTraps(JS val, WriteTrapChain trapchain) { if (test(VISIBLE_TRAP)) { - if (trapchain == null) trapchain = new TrapChain(); - val = trapchain.beforeCascade(this, SC_visible, val); + if (trapchain == null) trapchain = new WriteTrapChain(); + val = trapchain.beforeCascade(wtrap(SC_visible), val); // interrupted by a JS exception - if (trapchain.exn != null) + if (trapchain.returnedNormally()) return trapchain; } int i=0; @@ -1760,7 +1721,7 @@ if (b.test(DISPLAY)) { trapchain = b.fireVisibleTraps(val, trapchain); // interrupted by a JS exception - if (trapchain != null && trapchain.exn != null) + if (trapchain != null && trapchain.returnedNormally()) return trapchain; } } @@ -1819,7 +1780,7 @@ JS oldsurface = getSurfaceObject(); JS newsurface = getSurfaceObject(newparent); // call pre-cascade traps - TrapChain trapchain = oldsurface==newsurface ? null : fireSurfaceTraps(newsurface, null); + WriteTrapChain trapchain = oldsurface==newsurface ? null : fireSurfaceTraps(newsurface, null); trapchain = !test(DISPLAY) || (wasvisible == (newparent==null?false:newparent.isVisible())) ? trapchain : fireVisibleTraps(wasvisible?JSU.F:JSU.T, trapchain); Modified: trunk/core/org.vexi.core/src/org/vexi/core/Surface.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/Surface.java 2009-05-26 00:21:46 UTC (rev 3508) +++ trunk/core/org.vexi.core/src/org/vexi/core/Surface.java 2009-05-26 02:18:29 UTC (rev 3509) @@ -512,7 +512,7 @@ Surface old = fromBox(b); boolean firevisible = old==null && Box.testDisplay(b); // fire pre-cascade visible traps - Box.TrapChain trapchain = null; + WriteTrapChain trapchain = null; if (firevisible) trapchain = b.fireVisibleTraps(true); // get the platform implementation of surface Surface surface = Platform.createSurface(b, framed); Added: trunk/core/org.vexi.core/src/org/vexi/core/WriteTrapChain.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/WriteTrapChain.java (rev 0) +++ trunk/core/org.vexi.core/src/org/vexi/core/WriteTrapChain.java 2009-05-26 02:18:29 UTC (rev 3509) @@ -0,0 +1,49 @@ +// Copyright 2000-2008 the Contributors, as shown in the revision logs. +// Licensed under the GNU General Public License version 2 ("the License"). +// You may not use this file except in compliance with the License. + +package org.vexi.core; + +import org.ibex.js.JS; +import org.ibex.js.JSExn; +import org.ibex.js.JS.Trap; + +/** represents a chain of traps that may span multiple boxes */ +public final class WriteTrapChain { + int chainlength = 0; + JSExn exn; + + /** add a trap on 'b.prop' to the trap chain by executing pre-put of 'val' */ + public JS beforeCascade(Trap t, JS val) { + try { + if (t != null) { + chainlength++; + return Main.SCHEDULER.runBeforePut(t, val); + } + } catch (JSExn e) { + chainlength--; + exn = e; + } + return null; + } + + public boolean returnedNormally() { return exn==null; } + + /** use to invoke internal finishTraps */ + public void finishTraps() throws JSExn { finishTraps(exn); } + + /** finish the trap chain represented by this object */ + private void finishTraps(JSExn exn) throws JSExn { + while (chainlength>0) { + try { + chainlength--; + Main.SCHEDULER.runAfterPut(exn); + exn = null; + } catch(JSExn e) { + exn = e; + } + } + // exception was not caught in JS, re-throw + if (exn != null) throw exn; + } +} \ No newline at end of file Property changes on: trunk/core/org.vexi.core/src/org/vexi/core/WriteTrapChain.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn