From 21c73b77c3f8e9d9f2e98debe8e90c434de4efbe Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 12 Sep 2011 11:43:06 -0400 Subject: [PATCH] adding forward and backward movement --- web-world/impl.rkt | 5 +++ web-world/js-impl.js | 94 +++++++++++++++++++++++++++++++++++++++ web-world/racket-impl.rkt | 22 +++++++++ 3 files changed, 121 insertions(+) diff --git a/web-world/impl.rkt b/web-world/impl.rkt index 0d541c1..f0f8b27 100644 --- a/web-world/impl.rkt +++ b/web-world/impl.rkt @@ -48,6 +48,11 @@ view-down? view-down + + view-forward? + view-forward + view-backward? + view-backward view-text update-view-text diff --git a/web-world/js-impl.js b/web-world/js-impl.js index f5f2ea6..d2a11e1 100644 --- a/web-world/js-impl.js +++ b/web-world/js-impl.js @@ -324,6 +324,60 @@ view.focus = view.focus.children(':first'); }); }; + + + MockView.prototype.forward = function() { + return this.act( + function(cursor) { + return cursor.succ(); + }, + function(eventHandlers) { + return eventHandlers; + }, + function(view) { + if (view.focus.children().length > 0) { + view.focus = view.focus.children(':first'); + } else if (view.focus.next().length > 0) { + view.focus = view.focus.next(); + } else { + while (true) { + view.focus = view.focus.parent(); + if (view.focus.next().length > 0) { + view.focus = view.focus.next(); + return; + } + } + } + }); + }; + + MockView.prototype.backward = function() { + return this.act( + function(cursor) { + return cursor.pred(); + }, + function(eventHandlers) { + return eventHandlers; + }, + function(view) { + if (view.focus.prev().length > 0) { + view.focus = view.focus.prev(); + while (view.focus.children().length > 0) { + view.focus = view.focus.children(':last'); + } + } else { + view.focus = view.focus.parent(); + } + + }); + }; + + + + + + + var mockViewIdGensym = 0; @@ -489,6 +543,13 @@ return this.cursor.canRight(); }; + MockView.prototype.isForwardMovementOk = function() { + return this.cursor.canSucc(); + }; + + MockView.prototype.isBackwardMovementOk = function() { + return this.cursor.canPred(); + }; ////////////////////////////////////////////////////////////////////// @@ -1620,6 +1681,21 @@ return view.down(); }); + EXPORTS['view-forward'] = makePrimitiveProcedure( + 'view-forward', + 1, + function(MACHINE) { + var view = checkMockView(MACHINE, 'view-forward', 0); + return view.forward(); + }); + + EXPORTS['view-backward'] = makePrimitiveProcedure( + 'view-backward', + 1, + function(MACHINE) { + var view = checkMockView(MACHINE, 'view-backward', 0); + return view.backward(); + }); EXPORTS['view-left?'] = makePrimitiveProcedure( @@ -1655,6 +1731,24 @@ }); + EXPORTS['view-forward?'] = makePrimitiveProcedure( + 'view-down?', + 1, + function(MACHINE) { + var view = checkMockView(MACHINE, 'view-forward?', 0); + return view.isForwardMovementOk(); + }); + + EXPORTS['view-backward?'] = makePrimitiveProcedure( + 'view-backward?', + 1, + function(MACHINE) { + var view = checkMockView(MACHINE, 'view-backward?', 0); + return view.isBackwardMovementOk(); + }); + + + diff --git a/web-world/racket-impl.rkt b/web-world/racket-impl.rkt index 667ed6b..632132f 100644 --- a/web-world/racket-impl.rkt +++ b/web-world/racket-impl.rkt @@ -9,6 +9,12 @@ view-focus? view-focus view-left view-right view-up view-down view-left? view-right? view-up? view-down? + + view-forward? + view-forward + view-backward? + view-backward + view-text update-view-text view-attr update-view-attr view-css update-view-css @@ -25,6 +31,9 @@ view-insert-right view-insert-left + + + view-remove open-output-element @@ -111,6 +120,19 @@ (define (view-down? v) (error 'view-down? "Please run in JavaScript context")) +(define (view-forward? v) + (error 'view-forward? "Please run in JavaScript context")) + +(define (view-backward? v) + (error 'view-backward? "Please run in JavaScript context")) + +(define (view-forward v) + (error 'view-forward "Please run in JavaScript context")) + +(define (view-backward v) + (error 'view-backward "Please run in JavaScript context")) + +