edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
* [Edbrowse-dev] Render
@ 2014-02-28 16:43 Karl Dahlke
  2014-02-28 17:44 ` Adam Thompson
  0 siblings, 1 reply; 9+ messages in thread
From: Karl Dahlke @ 2014-02-28 16:43 UTC (permalink / raw)
  To: Edbrowse-dev

Well this is thinking ahead to future versions of edbrowse,
with some of the anticipated redesign.
I'm thinking out lout if you will.

We want to build a tree of javascript objects, first built from html,
then perhaps modified by javascript functions, or even onclick or onchange
code as you interact with the web page.
Then a render function traverses this tree and builds the text buffer that you read.
This render function is called after every javascript invokation,
because you never know what javascript might do.
Add new paragraphs, tables, build new option lists, etc.
This is where we are headed,
and I was almost tempted to start writing render.cpp,
which would not interfere at all with anything going on now,
just a separate file with a function not currently called,
but intended for use in the future.
I was going to copy html.cpp to render.cpp,
and create the same text buffer, but not from html tags, rather from the
tree of javascript objects.
So I would step through the members of each object,
and if it's a text object paste the string into the growing buffer,
and for some other object like a form descend into that object
and do the same thing recursively, generating tags and/or text as we go.
So I start to picture thousands of lines of C++ code stepping through object members,
and rooting object pointers and rooting strings etc, and then it hits me.
A great idea!
Write render() as a javascript function, not in C.
Then just execute render() entirely in javascript.
Use document.write to crank out the text buffer,
and postprocess it at the end to break up long lines just like we do today.
No rooted object pointers, no rooted strings, it just runs.
And it runs the same way even if we switch to another js engine some day.
Completely portable.
So render.cpp is mostly a long string that is the render() function
in javascript, and I just pass it to the js engine for execution,
then the resulting document.write string is the text buffer.

Pretty slick, eh?

As time permits I may start to outline this javascript render function.
This requires some conventions about the object tree,
paragraph objects, text objects, etc; any enhancements
we need to make to dom, but all this has to be settled no matter
how we do it.
Render() will be a nontrivial, recursive javascript function,
but much cleaner and easier than the C counterpart would be.

Karl Dahlke

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [Edbrowse-dev]  Render
@ 2014-02-28 20:01 Karl Dahlke
  2014-02-28 22:04 ` Adam Thompson
  0 siblings, 1 reply; 9+ messages in thread
From: Karl Dahlke @ 2014-02-28 20:01 UTC (permalink / raw)
  To: Edbrowse-dev

> Hmmm, I wonder if we want to try and keep it away from javascript specifics,

I don't think you can, really, we always have to support javascript,
in whatever its form and syntax and semantics, we're always in there,
in the heart of it,
so why not write render in the language that we know we have to support,
stepping through all the objects that we know we have to have
corresponding tags for.
I don't see the advantage of transmuting all this to another tree in another
home-grown language and then transmuting it back as necessary
to work with javascript.

Also the tree is mostly made for us already.
The form object contains an element array.
This array holds the input tags.
Each input tag has a value and checked field and default,
and if it is a select, it has an array of options,
and each option has a checked field and value, and so on,
all that tree structure is there in javascript,
and has to be there or we aren't doing our job,
so render can just trace it as a javascript function.
The only thing we need to add is a text object.
If there is nothing on the web page but hello world,
no tags, no nothing,
we would have to invent a <P> paragraph tag or some such
to hold the text.
So yes some tweaking on our part,
but I do think much of the tree is already built in js and has to be so
and will always be so, so why not live in that world
when translating the tree back into a text buffer to browse.

> How'd this work with forms, event handlers and all the associated machinery?

I mentioned that forms already build a fairly substantial tree
of javascript objects for us.
It's all in place today.
And so do tables, with rows under tables and elements under rows,
and so on.
I think I implemented tables rows and cells as a js tree.
I was supppose to.
Anyways, an event handler is a function under a tag,
which becomes a js function under the corresponding object for that tag.
Just another leaf on the tree.
Nothing special here, just another member of that object.
And I already do this today for onsubmit onreset onchange onclick.
So again the js tree is already there.
We have to traverse it, and it's easier to traverse in js itself
then in any other outside language such as C.

> it places a lot of dependancy on something
> beyond our control, i.e. the stability or otherwise of a js library.

Well I'd be writing render() in javascript itself, not dependent on any library.
As long as there is a call to
executeJavascriptCode(const char *code)
then we're ok.

The language of js, i mean for loops and if statements etc, isn't going to change.
The objects in the js tree might change, but probably expand in a backward compatible way,
and guess what, we have to support all those changes anyways.
>From html to objects and the semantics of those objects,
from start to end.
And render would have to support the new objects and tags,  whatever language it is written in.
So it would be easiest if it was written in js where the tree lives.
I'm thinking so anyways.


Karl Dahlke

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [Edbrowse-dev]   Render
@ 2014-02-28 23:32 Karl Dahlke
  2014-03-01 13:35 ` Adam Thompson
  0 siblings, 1 reply; 9+ messages in thread
From: Karl Dahlke @ 2014-02-28 23:32 UTC (permalink / raw)
  To: Edbrowse-dev

> Also, how are you going to make this function called every time js does anything?

Already done.
jSyncup is called before every js action, and jsdw is called afterword.
It's already bracketed.
And we have to do that anyways, to see what changes js made to our buffer
and report them back to the user.
These are things you just "see" in a regular browser.
"Oh - I clicked this button and now there's something new there."
We have to report it, and I made a first stab at it,
but we have to do better.
Like jsrt when you push the calc button it tells you that a line was updated.

> Primarily because I know of no way of protecting this js render function from
> being zapped by an unfortunately crafted page.

Like malice?

> At the moment if js does stupid things and breaks the js dom that's not nice
> if it completely destroys our method for rendering the buffer that's
> not only difficult to debug but also means you end up with an empty page.

Yes, a great point made in one sentence.
You couldn't turn js completely off, as you do today,
it would still have to be on long enough to build the objects from html like today,
but not run any scripts, then traverse the objects to render the page,
which is a funny flavor of off, not entirely off.
And if js was off because some other session hogged all the js memory,
well then we're up the creek eh?
Really annoying that the js pool is a fixed size.
So yes there's more to think about here.
Damn, I really liked the idea too!
Well we have time to mull it over and talk it out.

I found this in a tutorial long ago and bookmarked it.
It's the kind of thing we should support.
See how tables and cells and paragraphs and just about anything
on the web page can be built by javascript, not just by html tags?

https://developer.mozilla.org/en/docs/Traversing_an_HTML_table_with_JavaScript_and_DOM_Interfaces

Most web pages aren't that crazy but some are, and more and more web pages
at least build little partswith js,
like building the secondary menu based on your selection in a primary menu.
That happens all the time.
I wrote such a website for my work; I wrote a website
I couldn't even use with edbrowse. Ironic.
Anyways, I wonder, how long can we say
"Gee we need to render html even if js won't run",
will the day come when there just aren't many web pages left
that have any meaning without js?
Not trying to cause trouble, just wondering.
So anyways all this dynamic creation, perhaps well after the page is parsed,
perhaps because you pushed a button,
all this dynamism we must support.

html tags become js objects.
js scripts make more objects or change these objects.
js objects become things on the screen, or in our case the text buffer.

User pushes a button.
js function makes new objects or changes the objects.
js tree of objects implies a new buffer.
compare with the old buffer and report any differences.
Wait for next user input or action.


Karl Dahlke

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-03-13 10:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-28 16:43 [Edbrowse-dev] Render Karl Dahlke
2014-02-28 17:44 ` Adam Thompson
2014-02-28 19:16   ` Chris Brannon
2014-02-28 20:01 Karl Dahlke
2014-02-28 22:04 ` Adam Thompson
2014-02-28 23:32 Karl Dahlke
2014-03-01 13:35 ` Adam Thompson
2014-03-12 16:57   ` Chris Brannon
2014-03-13 10:45     ` Adam Thompson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).