From a76646eb76b01b5f1b5f0507b1c4bcd4202f1f11 Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:41:15 +0000 Subject: [PATCH] 2003/11/13 07:46:41 darcs-hash:20040130074115-2ba56-d0eacf6b706142fe8bef4d50fef7e36c5a62c4df.gz --- src/org/xwt/Box.java | 20 ++++++++------- src/org/xwt/BoxTree.java | 20 +++++++-------- src/org/xwt/HTTP.java | 4 +-- src/org/xwt/Picture.java | 8 +++--- src/org/xwt/Platform.java | 2 +- src/org/xwt/Res.java | 23 +++++++++-------- src/org/xwt/SOAP.java | 6 ++--- src/org/xwt/Surface.java | 2 +- src/org/xwt/Template.java | 12 ++++----- src/org/xwt/XMLRPC.java | 2 +- src/org/xwt/XWT.java | 40 ++++++++++++++--------------- src/org/xwt/js/JS.java | 4 +-- src/org/xwt/js/JSContext.java | 7 +++-- src/org/xwt/js/JSFunction.java | 45 +++++++++++++++++---------------- src/org/xwt/js/JSScope.java | 17 ++++++++----- src/org/xwt/js/JSTrap.java | 10 ++++---- src/org/xwt/translators/Freetype.java | 27 ++++++++++++-------- src/org/xwt/translators/MSPack.java | 2 +- 18 files changed, 133 insertions(+), 118 deletions(-) diff --git a/src/org/xwt/Box.java b/src/org/xwt/Box.java index 475b380..a76c25d 100644 --- a/src/org/xwt/Box.java +++ b/src/org/xwt/Box.java @@ -152,8 +152,7 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { } } - public void putAndTriggerTraps(Object key, Object value) { - // FIXME + public void putAndTriggerJSTraps(Object key, Object value) { } /** update MOUSEINSIDE, check for Enter/Leave/Move */ @@ -164,7 +163,7 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { if (isinside) set(MOUSEINSIDE); else clear(MOUSEINSIDE); if (!wasinside && !isinside) return; - if (isinside && test(CURSOR)) getRoot().cursor = (String)boxToCursor.get(this); + if (isinside && test(CURSOR)) Surface.fromBox(getRoot()).cursor = (String)boxToCursor.get(this); if (!wasinside && isinside && getTrap("Enter") != null) putAndTriggerJSTraps("Enter", T); else if (wasinside && !isinside && getTrap("Leave") != null) putAndTriggerJSTraps("Leave", T); else if (wasinside && isinside && (mousex != oldmousex || mousey != oldmousey) && getTrap("Move")!= null) @@ -240,7 +239,7 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { dirty(); try { if (sizechange) putAndTriggerJSTraps("SizeChange", T); Surface.abort = true; } catch (Exception e) { Log.log(this, e); } - try { if (poschange) pputAndTriggerJSTraps("PosChange", T); Surface.abort = true; } + try { if (poschange) putAndTriggerJSTraps("PosChange", T); Surface.abort = true; } catch (Exception e) { Log.log(this, e); } /* } @@ -533,8 +532,8 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { int mousex = globalToLocalX(surface.mousex); int mousey = globalToLocalY(surface.mousey); for(Box c = prevSibling(); c != null; c = c.prevSibling()) - if (c.inside(mousex - c.x, mousey - c.y)) { JSTrap.putAndTriggerJSTraps(c, name, value); return; } - if (parent != null) JSTrap.putAndTriggerJSTraps(parent, name, value); + if (c.inside(mousex - c.x, mousey - c.y)) { c.putAndTriggerJSTraps(name, value); return; } + if (parent != null) parent.putAndTriggerJSTraps(name, value); } private static int stringToColor(String s) { @@ -613,14 +612,17 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { protected Box left = null; protected Box right = null; - protected Box parent_ = null; // not to be confused with Box.parent_! protected Box rootChild = null; + protected Box peerTree_parent = null; + public abstract Box peerTree_leftmost(); + public abstract Box peerTree_rightmost(); + public abstract Box insertBeforeMe(Box cell); + public abstract Box insertAfterMe(Box cell); protected abstract Box fixAfterInsertion(); protected abstract Box fixAfterDeletion(); - protected abstract Box rightmost(); - protected abstract Box leftmost(); protected abstract Box rotateLeft(); protected abstract Box rotateRight(); + protected abstract int numPeerChildren(); } diff --git a/src/org/xwt/BoxTree.java b/src/org/xwt/BoxTree.java index ef84541..9f89ece 100644 --- a/src/org/xwt/BoxTree.java +++ b/src/org/xwt/BoxTree.java @@ -330,7 +330,7 @@ public final class BoxTree extends Box { removeNode(); parent = null; if (oldparent != null) { Box b = oldparent; MARK_REFLOW_b; } - if (oldparent != null) oldparent.putAndInvokeTraps("childremoved", this); + if (oldparent != null) oldparent.putAndTriggerJSTraps("childremoved", this); } /** Returns ith child */ @@ -372,22 +372,22 @@ public final class BoxTree extends Box { } if (redirect == null) { - if (value == null) putAndTriggerTraps("childremoved", getChild(i)); + if (value == null) putAndTriggerJSTraps("childremoved", getChild(i)); else Log.logJS(this, "attempt to add/remove children to/from a node with a null redirect"); } else if (redirect != this) { - if (value != null) putAndTriggerTraps("childadded", b); + if (value != null) putAndTriggerJSTraps("childadded", value); redirect.put(i, value); if (value == null) { - Box b = (Box)redirect.get(new Integer(i)) : (Box)value; - if (b != null) putAndTriggerTraps("childremoved", b); + Box b = (Box)redirect.get(new Integer(i)); + if (b != null) putAndTriggerJSTraps("childremoved", b); } } else if (value == null) { - if (i < 0 || i > numChildren()) return; + if (i < 0 || i > numchildren) return; Box b = getChild(i); b.remove(); - putAndTriggerTraps("childremoved", b); + putAndTriggerJSTraps("childremoved", b); } else { Box b = (Box)value; @@ -412,15 +412,15 @@ public final class BoxTree extends Box { numchildren++; Box before = getChild(i); - if (before == null) root.peerTree_rightmost().insertAfterMe(b); + if (before == null) rootChild.peerTree_rightmost().insertAfterMe(b); else before.insertBeforeMe(b); // need both of these in case child was already uncalc'ed MARK_REFLOW_b; MARK_REFLOW; - b.dirty(); - putAndTriggerTraps("childadded", b); + b.dirty(); + putAndTriggerJSTraps("childadded", b); } } } diff --git a/src/org/xwt/HTTP.java b/src/org/xwt/HTTP.java index 84e5abb..2b42f97 100644 --- a/src/org/xwt/HTTP.java +++ b/src/org/xwt/HTTP.java @@ -283,7 +283,7 @@ public class HTTP { org.xwt.js.JSArray args = new org.xwt.js.JSArray(); args.addElement(url.toString()); args.addElement(url.getHost()); - Object obj = pacFunc.call(args); + Object obj = pacFunc.call(null, args); if (Log.verbose) Log.log(this, " PAC script returned \"" + obj + "\""); pac = obj.toString(); } catch (Throwable e) { @@ -779,7 +779,7 @@ public class HTTP { } JSFunction scr = JS.parse("PAC script at " + url, 0, new StringReader(script)); - scr.cloneWithNewJSScope(proxyAutoConfigRootJSScope).call(new JSArray()); + scr.cloneWithNewParentJSScope(proxyAutoConfigRootJSScope).call(null, new JSArray()); return (JSCallable)proxyAutoConfigRootJSScope.get("FindProxyForURL"); } catch (Exception e) { if (Log.on) { diff --git a/src/org/xwt/Picture.java b/src/org/xwt/Picture.java index 942bf03..3168390 100644 --- a/src/org/xwt/Picture.java +++ b/src/org/xwt/Picture.java @@ -30,7 +30,7 @@ public abstract class Picture { public abstract int getWidth(); /** Pictures, cache keyed by Res instance */ - private static Cache cache = new Cache(); + private static Cache cache = new Cache(100); private static GIF gif = new GIF(); /** turns a resource into a Picture.Source and passes it to the callback */ @@ -45,9 +45,9 @@ public abstract class Picture { try { Picture ret = null; InputStream pbis = new ByteArrayInputStream(b); - if ((b[0] & 0xff) == 'G') ret = gif.fromInputStream(pbis, r.getDescriptiveName()); - else if ((b[0] & 0xff) == 137) ret = new PNG().fromInputStream(pbis, r.getDescriptiveName()); - else if ((b[0] & 0xff) == 0xff) ret = Platform.decodeJPEG(pbis, r.getDescriptiveName()); + if ((b[0] & 0xff) == 'G') ret = gif.fromInputStream(pbis, "some picture"); + else if ((b[0] & 0xff) == 137) ret = new PNG().fromInputStream(pbis, "some picture"); + else if ((b[0] & 0xff) == 0xff) ret = Platform.decodeJPEG(pbis, "some picture"); else throw new JS.Exn("couldn't figure out image type from first byte"); ret.res = r; cache.put(r, ret); diff --git a/src/org/xwt/Platform.java b/src/org/xwt/Platform.java index 1640779..9c1d429 100644 --- a/src/org/xwt/Platform.java +++ b/src/org/xwt/Platform.java @@ -226,7 +226,7 @@ public class Platform { /** displays a platform-specific "open file" dialog and returns the chosen filename, or null if the user hit cancel */ protected String _fileDialog(String suggestedFileName, boolean write) { return null; } - public static void fileDialog(String suggestedFileName, boolean write) throws JS.Exn { + public static String fileDialog(String suggestedFileName, boolean write) throws org.xwt.js.JS.Exn { return platform._fileDialog(suggestedFileName, write); } diff --git a/src/org/xwt/Res.java b/src/org/xwt/Res.java index b2ae73b..df0813f 100644 --- a/src/org/xwt/Res.java +++ b/src/org/xwt/Res.java @@ -19,8 +19,8 @@ public abstract class Res extends JS { public static Res fromString(String url) { if (url.startsWith("http://")) return new HTTP(url); else if (url.startsWith("https://")) return new HTTP(url); - else if (url.startsWith("data:")) return new ByteArray(Base64.decode(url.substring(5))); - else if (url.startsWith("utf8:")) return new ByteArray(url.substring(5).getBytes()); + else if (url.startsWith("data:")) return new ByteArray(Base64.decode(url.substring(5)), null); + else if (url.startsWith("utf8:")) return new ByteArray(url.substring(5).getBytes(), null); throw new JS.Exn("invalid resource specifier " + url); } @@ -57,8 +57,8 @@ public abstract class Res extends JS { // Caching ////////////////////////////////////////////////////////////////////// - private static class NotCacheableException extends Exception { } - private static NotCacheableException notCacheable = new NotCacheableException(); + public static class NotCacheableException extends Exception { } + public static NotCacheableException notCacheable = new NotCacheableException(); /** if it makes sense to cache a resource, the resource must return a unique key */ public String getCacheKey() throws NotCacheableException { throw notCacheable; } @@ -68,9 +68,12 @@ public abstract class Res extends JS { public static class CachedRes extends Res { private Res parent; private boolean disk = false; - public String getCacheKey() throws NotCacheableException { return parent.getCacheKey(); } + private String key; + public String getCacheKey() throws NotCacheableException { return key; } private Hash cachedInputStreams = new Hash(); - public CachedRes(Res p, String s, boolean d) { this.parent = p; this.disk = d; } + public CachedRes(Res p, String s, boolean d) throws NotCacheableException { + this.parent = p; this.disk = d; this.key = p.getCacheKey(); + } public InputStream getInputStream(String path) throws IOException { CachedInputStream cis = (CachedInputStream)cachedInputStreams.get(path); if (cis == null) { @@ -80,7 +83,7 @@ public abstract class Res extends JS { java.io.File.separatorChar + ".xwt" + java.io.File.separatorChar + "caches" + java.io.File.separatorChar + - new String(Base64.encode(parent.getCacheKey().getBytes()))); + new String(Base64.encode(key.getBytes()))); Log.log(this, "caching resource in " + f); new java.io.File(f.getParent()).mkdirs(); if (f.exists()) return new FileInputStream(f); @@ -98,7 +101,7 @@ public abstract class Res extends JS { /** HTTP or HTTPS resource */ public static class HTTP extends Res { private String url; - HTTP(String url) { while (url.endsWith('/')) url = url.substring(0, url.length() - 1); this.url = url; } + HTTP(String url) { while (url.endsWith("/")) url = url.substring(0, url.length() - 1); this.url = url; } public String getCacheKey() throws NotCacheableException { return url; } public InputStream getInputStream(String path) throws IOException { return new org.xwt.HTTP(url + path).GET(); } } @@ -107,7 +110,7 @@ public abstract class Res extends JS { public static class ByteArray extends Res { private byte[] bytes; private String cacheKey = null; - ByteArray(byte[] bytes, String cacheKey) { this.bytes = bytes; this.cacheKey = cacheKey; }} + ByteArray(byte[] bytes, String cacheKey) { this.bytes = bytes; this.cacheKey = cacheKey; } public String getCacheKey() throws NotCacheableException { return cacheKey; } public InputStream getInputStream(String path) throws IOException { if (!"".equals(path)) throw new JS.Exn("can't get subresources of a byte[] resource"); @@ -119,7 +122,7 @@ public abstract class Res extends JS { public static class File extends Res { private String path; File(String path) { - while (path.endsWith(java.io.File.separatorChar)) path = path.substring(0, path.length() - 1); + while (path.endsWith(java.io.File.separatorChar + "")) path = path.substring(0, path.length() - 1); this.path = path; } public String getCacheKey() throws NotCacheableException { throw notCacheable; } // already on the disk! diff --git a/src/org/xwt/SOAP.java b/src/org/xwt/SOAP.java index 59fc5c0..4ffb8a0 100644 --- a/src/org/xwt/SOAP.java +++ b/src/org/xwt/SOAP.java @@ -92,7 +92,7 @@ class SOAP extends XMLRPC { } else if (me instanceof byte[]) { objects.removeElementAt(objects.size() - 1); - objects.addElement(new Res.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())))); + objects.addElement(new Res.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())), null)); content.reset(); } else if (me instanceof Integer) { @@ -233,7 +233,7 @@ class SOAP extends XMLRPC { Enumeration e = j.keys(); while(e.hasMoreElements()) { Object key = e.nextElement(); - appendObject(key, j.get(key), sb); + appendObject((String)key, j.get(key), sb); } sb.append("\r\n"); @@ -259,7 +259,7 @@ class SOAP extends XMLRPC { Enumeration e = ((JS)args.elementAt(0)).keys(); while(e.hasMoreElements()) { Object key = e.nextElement(); - appendObject(key, ((JS)args.elementAt(0)).get(key), content); + appendObject((String)key, ((JS)args.elementAt(0)).get(key), content); } } content.append(" \r\n"); diff --git a/src/org/xwt/Surface.java b/src/org/xwt/Surface.java index a187981..b0b8df1 100644 --- a/src/org/xwt/Surface.java +++ b/src/org/xwt/Surface.java @@ -232,7 +232,7 @@ public abstract class Surface extends PixelBuffer { protected final void SizeChange(final int width, final int height) { Scheduler.add(new Message() { public void perform() { if (width == root.width && height == root.height) return; - root.set(REFLOW); + root.set(root.REFLOW); do { abort = false; root.reflow(width, height); } while(abort); }}); abort = true; diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index 6956027..9a324d2 100644 --- a/src/org/xwt/Template.java +++ b/src/org/xwt/Template.java @@ -97,7 +97,7 @@ public class Template { if (staticscript == null) return staticJSScope; JSFunction temp = staticscript; staticscript = null; - JSContext.invoke(temp.cloneWithNewParentJSSCope(staticJSScope)); + temp.cloneWithNewParentJSScope(staticJSScope).call(new JSArray()); return staticJSScope; } @@ -121,15 +121,15 @@ public class Template { for (int i=0; children != null && iunpauseable context. */ public Object call(JSArray args) { - Context cx = new JSContext(this, false); + JSContext cx = new JSContext(this, false); cx.invoke(args); return cx.stack.pop(); } @@ -89,7 +90,7 @@ public class JSFunction extends JSCallable implements ByteCodes, Tokens { /** returns false if the thread has been paused */ static Object eval(final JSContext cx) throws JS.Exn { - final initialPauseCount = cx.pausecount; + final int initialPauseCount = cx.pausecount; OUTER: for(;; cx.pc++) { try { if (cx.f == null || cx.pc >= cx.f.size) return cx.stack.pop(); @@ -193,22 +194,22 @@ public class JSFunction extends JSCallable implements ByteCodes, Tokens { cx.pc = ((TryMarker)o).finallyLoc - 1; continue OUTER; } else if (o instanceof CallMarker) { - if (cx.scope instanceof JSTrapScope) { - JSTrapScope ts = (JSTrapScope)cx.scope; + if (cx.scope instanceof JSTrap.JSTrapScope) { + JSTrap.JSTrapScope ts = (JSTrap.JSTrapScope)cx.scope; if (!ts.cascadeHappened) { ts.cascadeHappened = true; JSTrap t = ts.t.next; while (t != null && t.f.numFormalArgs == 0) t = t.next; if (t == null) { - ts.trappee.put(key, val); - if (cx.pausecount > initialPauseCount) return; // we were paused + ((JS)ts.t.trapee).put(t.name, ts.val); + if (cx.pausecount > initialPauseCount) return null; // we were paused } else { cx.stack.push(o); JSArray args = new JSArray(); args.addElement(ts.val); - cx.stack.push(ta); + cx.stack.push(args); cx.f = t.f; - cx.scope = new JSTrap.JSTrapScope(cx.f.parentJSScope, ts.val); + cx.scope = new JSTrap.JSTrapScope(cx.f.parentJSScope, t, ts.val); cx.pc = -1; break; } @@ -235,28 +236,28 @@ public class JSFunction extends JSCallable implements ByteCodes, Tokens { if (key == null) throw je("tried to assign \"" + (val==null?"(null)":val.toString()) + "\" to the null key"); JSTrap t = null; - if (o instanceof JSTrap.JSTrappable) { - t = ((JSTrap.JSTrappable)o).getTrap(v); + if (target instanceof JSTrap.JSTrappable) { + t = ((JSTrap.JSTrappable)target).getTrap(val); while (t != null && t.f.numFormalArgs == 0) t = t.next; - } else if (o instanceof JSTrap.JSTrapScope && key.equals("cascade")) { - JSTrap.JSTrapScope ts = (JSTrap.JSTrapScope)o; + } else if (target instanceof JSTrap.JSTrapScope && key.equals("cascade")) { + JSTrap.JSTrapScope ts = (JSTrap.JSTrapScope)target; t = ts.t.next; ts.cascadeHappened = true; while (t != null && t.f.numFormalArgs == 0) t = t.next; - if (t == null) o = ts.t.trappee; + if (t == null) target = ts.t.trapee; } if (t != null) { cx.stack.push(new CallMarker(cx)); JSArray args = new JSArray(); args.addElement(val); - cx.stack.push(ta); + cx.stack.push(args); cx.f = t.f; - cx.scope = new JSTrap.JSTrapScope(cx.f.parentJSScope, val); + cx.scope = new JSTrap.JSTrapScope(cx.f.parentJSScope, t, val); cx.pc = -1; break; } ((JS)target).put(key, val); - if (cx.pausecount > initialPauseCount) return; // we were paused + if (cx.pausecount > initialPauseCount) return null; // we were paused cx.stack.push(val); break; } @@ -284,23 +285,23 @@ public class JSFunction extends JSCallable implements ByteCodes, Tokens { if (o instanceof JSTrap.JSTrappable) { t = ((JSTrap.JSTrappable)o).getTrap(v); while (t != null && t.f.numFormalArgs != 0) t = t.next; - } else if (o instanceof JSTrap.JSTrapScope && key.equals("cascade")) { + } else if (o instanceof JSTrap.JSTrapScope && v.equals("cascade")) { t = ((JSTrap.JSTrapScope)o).t.next; while (t != null && t.f.numFormalArgs != 0) t = t.next; - if (t == null) o = ((JSTrap.JSTrapScope)o).t.trappee; + if (t == null) o = ((JSTrap.JSTrapScope)o).t.trapee; } if (t != null) { cx.stack.push(new CallMarker(cx)); JSArray args = new JSArray(); - cx.stack.push(ta); + cx.stack.push(args); cx.f = t.f; - cx.scope = new JSTrap.JSTrapScope(cx.f.parentJSScope, null); + cx.scope = new JSTrap.JSTrapScope(cx.f.parentJSScope, t, null); ((JSTrap.JSTrapScope)cx.scope).cascadeHappened = true; cx.pc = -1; break; } ret = ((JS)o).get(v); - if (cx.pausecount > initialPauseCount) return; // we were paused + if (cx.pausecount > initialPauseCount) return null; // we were paused cx.stack.push(ret); break; } @@ -354,7 +355,7 @@ public class JSFunction extends JSCallable implements ByteCodes, Tokens { JSArray arguments = new JSArray(); for(int j=numArgs - 1; j >= 0; j--) arguments.setElementAt(cx.stack.pop(), j); ret = c.call(method, arguments); - if (cx.pausecount > initialPauseCount) return; // we were paused + if (cx.pausecount > initialPauseCount) return null; // we were paused break; } } diff --git a/src/org/xwt/js/JSScope.java b/src/org/xwt/js/JSScope.java index bdf8233..8327ea1 100644 --- a/src/org/xwt/js/JSScope.java +++ b/src/org/xwt/js/JSScope.java @@ -44,18 +44,22 @@ public class JSScope extends JSCallable { return super.get(key); } + public Object call(Object method, JSArray args) { + if (method.equals("stringFromCharCode")) return stringFromCharCode(args); + else throw new JS.Exn("method not found"); + } + public Object call1(Object method, Object arg0) { //#switch(method) - case "parseInt": return parseInt(arg0, 0); + case "parseInt": return parseInt(arg0, N(0)); case "isNaN": { double d = toDouble(arg0); return d == d ? F : T; } - case "isFinite": { double d = toDouble(arg0); return (d == d && !Double.isFinite(d)) ? T : F; } + case "isFinite": { double d = toDouble(arg0); return (d == d && !Double.isInfinite(d)) ? T : F; } case "decodeURI": throw new JS.Exn("unimplemented"); case "decodeURIComponent": throw new JS.Exn("unimplemented"); case "encodeURI": throw new JS.Exn("unimplemented"); case "encodeURIComponent": throw new JS.Exn("unimplemented"); case "escape": throw new JS.Exn("unimplemented"); case "unescape": throw new JS.Exn("unimplemented"); - case "stringFromCharCode": return stringFromCharCode(arg0); //#end return null; } @@ -65,13 +69,14 @@ public class JSScope extends JSCallable { return null; } - private Object stringFromCharCode(Object arg) { + private Object stringFromCharCode(JSArray args) { char buf[] = new char[args.length()]; - for(int i=0;i