seed r531 - in trunk: examples examples/browser examples/lightsoff tests



Author: racarr
Date: Sun Dec 21 06:19:17 2008
New Revision: 531
URL: http://svn.gnome.org/viewvc/seed?rev=531&view=rev

Log:
Examples and tests are under MIT license. Except for lightsoff which is
under GPLv3. Also remerge browser in to SVN, which is also under GPLv3.

Added:
   trunk/examples/COPYING
   trunk/examples/browser/
   trunk/examples/browser/COPYING
   trunk/examples/browser/Makefile.am
   trunk/examples/browser/Makefile.am~
   trunk/examples/browser/browser-actions.js
   trunk/examples/browser/browser-bookmarks.js
   trunk/examples/browser/browser-find.js
   trunk/examples/browser/browser-main.js
   trunk/examples/browser/browser-menu.js
   trunk/examples/browser/browser-tab.js
   trunk/examples/browser/browser-toolbar.js
   trunk/examples/browser/main.js   (contents, props changed)
   trunk/examples/lightsoff/COPYING
   trunk/tests/COPYING
Modified:
   trunk/examples/Makefile.am
   trunk/tests/Makefile.am

Added: trunk/examples/COPYING
==============================================================================
--- (empty file)
+++ trunk/examples/COPYING	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,6 @@
+All examples in the toplevel directory (i.e. not including lightsoff or browser) are available under the MIT license.
+
+In addition the following subdirectories are under MIT license:
+	glib
+	clutter-shader
+	turtle

Modified: trunk/examples/Makefile.am
==============================================================================
--- trunk/examples/Makefile.am	(original)
+++ trunk/examples/Makefile.am	Sun Dec 21 06:19:17 2008
@@ -1,6 +1,7 @@
 SUBDIRS = lightsoff \
           clutter-shader \
           glib \
+          browser \
           turtle
 
 examplesdir=$(datadir)/doc/seed/examples
@@ -29,6 +30,7 @@
 	threaded-repl.js \
 	HACKING
 EXTRA_DIST = \
+	COPYING \
 	actions.js \
 	calculator.js \
 	clutter-cairo.js \

Added: trunk/examples/browser/COPYING
==============================================================================
--- (empty file)
+++ trunk/examples/browser/COPYING	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,11 @@
+--2008-12-21 01:14:23--  http://www.gnu.org/licenses/gpl-3.0.txt
+Resolving www.gnu.org... 199.232.41.10
+Connecting to www.gnu.org|199.232.41.10|:80... connected.
+HTTP request sent, awaiting response... 200 OK
+Length: 35147 (34K) [text/plain]
+Saving to: `gpl-3.0.txt'
+
+     0K .......... .......... .......... ....                 100%  363K=0.09s
+
+2008-12-21 01:14:23 (363 KB/s) - `gpl-3.0.txt' saved [35147/35147]
+

Added: trunk/examples/browser/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/examples/browser/Makefile.am	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,24 @@
+browserdir = $(datadir)/doc/seed/examples/browser
+browser_DATA = \
+	browser-actions.js \
+	browser-bookmarks.js \
+	browser-find.js \
+	browser-main.js \
+	browser-menu.js \
+	browser-tab.js \
+	browser-toolbar.js \
+	COPYING \
+	main.js
+EXTRA_DIST = \
+	browser-actions.js \
+	browser-bookmarks.js \
+	browser-find.js \
+	browser-main.js \
+	browser-menu.js \
+	browser-tab.js \
+	browser-toolbar.js \
+	COPYING \
+	main.jsx
+
+## File created by the gnome-build tools
+

Added: trunk/examples/browser/Makefile.am~
==============================================================================
--- (empty file)
+++ trunk/examples/browser/Makefile.am~	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,51 @@
+lightsoffdir = $(datadir)/doc/seed/examples/lightsoff
+lightsoff_DATA = \
+	board.js \
+	light.js \
+	main.js \
+	light-off.svg \
+	light-on.svg \
+	0.svg \
+	1.svg \
+	2.svg \
+	3.svg \
+	4.svg \
+	5.svg \
+	6.svg \
+	7.svg \
+	8.svg \
+	9.svg \
+	lcd-back.svg \
+	lcd-front.svg \
+	score.js \
+	lcd-off.svg \
+	menu.js \
+	arrow-l.svg \
+	arrow-r.svg \
+	arrow.js
+EXTRA_DIST = \
+	board.js \
+	light.js \
+	main.js \
+	light-off.svg \
+	light-on.svg \
+	0.svg \
+	1.svg \
+	2.svg \
+	3.svg \
+	4.svg \
+	5.svg \
+	6.svg \
+	7.svg \
+	8.svg \
+	9.svg \
+	lcd-back.svg \
+	lcd-front.svg \
+	score.js \
+	lcd-off.svg \
+	menu.js \
+	arrow-l.svg \
+	arrow-r.svg \
+	arrow.js
+## File created by the gnome-build tools
+

Added: trunk/examples/browser/browser-actions.js
==============================================================================
--- (empty file)
+++ trunk/examples/browser/browser-actions.js	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,324 @@
+function current_tab()
+{
+	return browser.get_nth_page(browser.page);
+}
+
+function go_back()
+{
+	current_tab().webView.go_back();
+	return false;
+}
+
+function go_forward()
+{
+	current_tab().webView.go_forward();
+	return false;
+}
+
+function go_up()
+{
+	current_tab().webView.open(get_up_url());
+	return false;
+}
+
+function refresh_page()
+{
+	current_tab().webView.reload();
+	return false;
+}
+
+function close_tab(button, tab)
+{
+	browser.remove_page(browser.page_num(tab));
+	//TODO: sometimes this destroy starts causing exceptions
+	tab.destroy();
+
+	if(!browser.get_n_pages())
+	{
+		browser.newTab().navigateTo(homePage);
+	}
+	
+	return false;
+}
+
+function browse(urlBar, tab)
+{
+	if (urlBar.text.search("://") < 0)
+	{
+		urlBar.text = "http://"; + urlBar.text;
+	}
+	
+	tab.webView.open(urlBar.text);
+	
+	return false;
+}
+
+function show_find()
+{
+	findBox.show();
+	findBox.entryBox.grab_focus();
+
+	return false;
+}
+
+function find(entry, event, box)
+{
+	//current_tab().webView.unmark_text_matches();
+	current_tab().webView.search_text("", box.caseSensitive.active, 
+									  true, true);
+	current_tab().webView.search_text(entry.text, box.caseSensitive.active, 
+									  true, true);
+
+	return false;
+}
+
+function show_about()
+{
+	// reuse window, formatting, centering, etc
+	about_window = new Gtk.Window();
+	var title_label = new Gtk.Label({label:"<span size='x-large'>" +
+									 "<b>Seed Browser 0.2</b></span>", 
+									 use_markup: true});
+	var under_label = new Gtk.Label({label:"A simple WebKit-based browser, " +
+									 "in Seed."});
+	var by_label = new Gtk.Label({label:"\251 2008, Seed maintainers"});
+
+	var close_button = Gtk.Button.new_from_stock(Gtk.STOCK_CLOSE);
+	close_button.signal.clicked.connect(function(){about_window.destroy()});
+
+	var vbox = new Gtk.VBox();
+	vbox.pack_start(title_label, true, true, 5);
+	vbox.pack_start(under_label, true, true, 5);
+	vbox.pack_start(by_label, true, true, 5);
+	vbox.pack_start(close_button, false, false, 5);
+	
+	about_window.add(vbox);
+	// instead of this, use packing once I find out how to do margins!
+	about_window.resize(300, 200);
+	about_window.show_all();
+	return false;
+}
+
+function get_up_url()
+{
+	Seed.print("Hey! This function currently causes a segmentation fault,\nso I'm just going to go ahead and do that now. KTHXBYE");
+	//this has a small, but harmless bug. not really a bug really, 
+	//but more of a tiny behavior inconsistency
+	//in that if you have a basic url like http://www.google.com with a trailing slash
+	//it stays with the trailing slash where as in every other case
+	//there is no trailing slash on the returned url
+	//i don't think this matters at all though and this is quite 
+	//a beastly and useless comment.
+
+	var curr_url = current_tab().webView.get_main_frame().get_uri().split("://",2);
+	var last = curr_url[1].lastIndexOf("/"); 
+
+	if ( curr_url[1].length == last+1 )
+		last = curr_url[1].substring(0,last).lastIndexOf("/");
+
+	if (last == -1)
+		last = curr_url[1].length;
+	return curr_url[0]+ "://" + curr_url[1].substring(0,last);
+}
+
+function create_action(nam, label, stock_id, accelerator, func)
+{
+	var new_action;
+	
+	if(label != null)
+		new_action = new Gtk.Action({name:nam, label:label,
+									 stock_id:stock_id});
+	else
+		new_action = new Gtk.Action({name:nam, 
+									 stock_id:stock_id});
+		
+	new_action.set_accel_group(accels);
+	
+	actions.add_action_with_accel(new_action, accelerator);
+		
+	new_action.connect_accelerator();
+	new_action.signal.activate.connect(func);
+	
+	return new_action;
+}
+
+function initialize_actions()
+{
+	actions = new Gtk.ActionGroup({name:"toolbar"});
+
+	accels = new Gtk.AccelGroup();
+	
+	new_tab_action = 
+		create_action("new", "New Tab", "gtk-new", "<Control>t", 
+					  function ()
+					  {
+						  browser.newTab().setWebView(new WebKit.WebView());
+						  browser.page = browser.get_n_pages() - 1;
+					  });
+	
+	close_tab_action = 
+		create_action("close", 
+					  "Close Tab", 
+					  "gtk-close", 
+					  "<Control>w", 
+					  close_tab);
+
+	go_back_action = 
+		create_action("go-back", 
+					  "Go Back", 
+					  "gtk-go-back", 
+					  "<Alt>Left", 
+					 go_back);
+
+	go_forward_action = 
+		create_action("go-forward", 
+					  "Go Forward", 
+					  "gtk-go-forward", 
+					  "<Alt>Right", 
+					 go_forward);
+
+	go_up_action = 
+		create_action("go-up", 
+					  "Go Up", 
+					  "gtk-go-up", 
+					  "<Alt>Up", 
+					 go_up);
+	
+	focus_urlbar_action = 
+		create_action("url", 
+					  "Focus URL Bar", 
+					  "", 
+					  "<Control>l", 
+					  function ()
+					  {
+						  current_tab().toolbar.urlBar.grab_focus();
+					  });
+	refresh_action = 
+		create_action("refresh", 
+					  "Refresh", 
+					  "gtk-reload", 
+					  "F5", 
+					 refresh_page);
+	
+	quit_action = 
+		create_action("quit",
+					  null,
+					  "gtk-quit", 
+					  null, 
+					  shutdown);
+	
+	cut_action = 
+		create_action("cut",
+					  null,
+					  "gtk-cut",
+					  null,
+					  function ()
+					  {
+						  current_tab().webView.cut_clipboard();
+					  });
+	
+	copy_action = 
+		create_action("copy",
+					  null,
+					  "gtk-copy",
+					  null,
+					  function ()
+					  {
+						  current_tab().webView.copy_clipboard();
+					  });
+	
+	paste_action =
+		create_action("paste", 
+					  null, 
+					  "gtk-paste", 
+					  null,
+					  function ()
+					  {
+						  current_tab().webView.paste_clipboard();
+					  });
+	
+	print_action = 
+		create_action("print", 
+					  null, 
+					  "gtk-print", 
+					  "<Control>p",
+					  function ()
+					  {
+						  current_tab().webView.execute_script("print()");
+					  });
+	
+	zoom_in_action = 
+		create_action("zoom-in", 
+					  null, 
+					  "gtk-zoom-in", 
+					  "<Control>plus", // TODO: needs to work for Ctrl-= also!!
+					  function ()
+					  {
+						var new_zoom_level = current_tab().webView.zoom_level + 0.1;
+						// FIXME: for some reason segfaults if try to zoom beyond here
+						if (new_zoom_level < 5.65)
+						  current_tab().webView.zoom_level = new_zoom_level;
+						  return false;
+					  });
+
+	zoom_out_action = 
+		create_action("zoom-out", 
+					  null, 
+					  "gtk-zoom-out", 
+					  "<Control>minus",
+					  function ()
+					  {
+						var new_zoom_level = current_tab().webView.zoom_level - 0.1;
+						if ( new_zoom_level > 0 )
+						  current_tab().webView.zoom_level = new_zoom_level;
+						  return false;
+					  });
+
+	zoom_zero_action = 
+		create_action("zoom-zero", 
+					  null, 
+					  "gtk-zoom-100", 
+					  "<Control>0",
+					  function ()
+					  {
+						  current_tab().webView.zoom_level = 1;
+
+						  return false;
+					  });
+
+	about_action =
+		create_action("about",
+					  null,
+					  "gtk-about", 
+					  null, 
+					  show_about);
+	
+	find_action = 
+		create_action("find",
+					  null, 
+					  "gtk-find", 
+					  null, 
+					  show_find);
+	
+	add_bookmark_action =
+		create_action("addbookmark",
+					  "Add Bookmark",
+					  "gtk-add",
+					  "<Ctrl>B",
+					  add_bookmark);
+	
+	// Someone needs to figure out how to use Tab in a key accel.
+	/*cycle_tabs_action = new Gtk.Action({name:"cycletabs", label:"Cycle Through Tabs",
+		                        tooltip:"Cycle Through Tabs"});
+	cycle_tabs_action.set_accel_group(accels);
+	cycle_tabs_action.connect_accelerator();
+	actions.add_action_with_accel(cycle_tabs_action, "<Control><Tab>");
+	cycle_tabs_action.signal.activate.connect(
+		function ()
+		{
+			
+		}
+	);*/
+	
+	return accels;
+}

Added: trunk/examples/browser/browser-bookmarks.js
==============================================================================
--- (empty file)
+++ trunk/examples/browser/browser-bookmarks.js	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,54 @@
+Seed.import_namespace("GLib");
+
+var bookmark_path = GLib.get_home_dir() + "/.seed_browser_bookmarks.db";
+
+//check if the bookmarks db exists and if there are permissions
+
+var new_db = (!GLib.file_test(bookmark_path, GLib.FileTest.Exists));
+
+bookmarks_db = new sqlite.Database(bookmark_path);
+
+if(new_db)
+	bookmarks_db.exec("create table bookmarks (key INTEGER PRIMARY KEY, url TEXT, name TEXT);");
+
+function populate_bookmarks_menu()
+{
+	bookmarks_db.exec("select * from bookmarks",
+		function(results)
+	    {
+			var new_bookmark_item = Gtk.MenuItem.new_with_label(results["name"]);
+			new_bookmark_item.tooltip_text = results["url"];
+			new_bookmark_item.signal.activate.connect(select_bookmark, null, results);
+			menu.bookmarksMenu.append(new_bookmark_item);
+		});
+
+}
+
+function add_bookmark()
+{
+	// This right here is the second largest security vulnerability I've ever knowingly written.
+	// TODO: ROBB, we need a substitution api...
+	// Also it's just stupid, because it'll break on quotes, etc. And we all know sanitizing your SQL yourself is retarded.
+
+	var b_url = current_tab().webView.get_main_frame().get_uri();
+	//var b_name = current_tab().webView.get_main_frame().get_title();
+	var b_name = current_tab().titleLabel.label;
+	//var b_name = b_url; // ^ something about in arguments makes this not work FIXIT. the gir says no args.
+	bookmarks_db.exec("insert into bookmarks (url, name) values ('" + b_url + "','" + b_name + "');");
+	bookmarks_db.exec("select * from bookmarks where url='" + b_url + "' AND name='" + b_name + "';",
+					  function(results){g_results=results}); // TODO: there's a better way to do this.
+	// RACERACERACE
+	// probably need to save IDs-to-menuitems so we can destroy them if we want, etc...
+	// todo: how do we get the ID out when we insert??
+	var new_bookmark_item = Gtk.MenuItem.new_with_label(b_name);
+	new_bookmark_item.tooltip_text = b_url;
+	new_bookmark_item.signal.activate.connect(select_bookmark, g_results);
+	new_bookmark_item.show_all();
+
+	menu.bookmarksMenu.append(new_bookmark_item);
+}
+
+function select_bookmark(menuItem, results)
+{
+	current_tab().navigateTo(results["url"]);
+}

Added: trunk/examples/browser/browser-find.js
==============================================================================
--- (empty file)
+++ trunk/examples/browser/browser-find.js	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,39 @@
+// TODO: escape in the text field should hide it, not search more!
+
+FindBoxType = {
+	parent: Gtk.HBox.type,
+	name: "FindBox",
+	instance_init: function(klass)
+	{
+		var closeButton = new Gtk.Button();
+		closeButton.set_image(new Gtk.Image({stock: "gtk-close", 
+				icon_size: Gtk.IconSize.Menu}));
+		closeButton.signal.clicked.connect(
+			function ()
+            {
+				this.entryBox.text = "";
+				this.hide();
+            }, this);
+		closeButton.set_relief(Gtk.ReliefStyle.None);
+
+		var findLabel = new Gtk.Label({label:"Find: "});
+		this.entryBox = new Gtk.Entry();
+		this.entryBox.signal.key_release_event.connect(find, this);
+
+		this.caseSensitive = new Gtk.CheckButton({label:"Match case"});
+/*		this.caseSensitive.signal.toggled.connect(
+			function (a,b) 
+            { 
+				// BROKEN.
+				current_tab().webView.unmark_text_matches();
+				find(this, 0, b); 
+				return false; 
+				},  this);*/
+
+		this.pack_start(closeButton);
+		this.pack_start(findLabel);
+		this.pack_start(this.entryBox, true, true);
+		this.pack_start(this.caseSensitive, false, false, 10);
+	}};
+
+FindBox = new GType(FindBoxType);

Added: trunk/examples/browser/browser-main.js
==============================================================================
--- (empty file)
+++ trunk/examples/browser/browser-main.js	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,24 @@
+TabbedBrowserType = {
+	parent: Gtk.Notebook.type,
+	name: "TabbedBrowser",
+	class_init: function(klass, prototype)
+	{
+		prototype.newTab = function ()
+		{
+			var tab = new BrowserTab();
+			
+			this.append_page(tab, tab.title);
+			this.set_tab_reorderable(tab, true);
+			
+			if(selectTabOnCreation)
+				this.page = this.get_n_pages() - 1;
+			
+			return tab;
+		}
+	},
+	instance_init: function(klass)
+	{
+		this.scrollable = true;
+	}};
+
+TabbedBrowser = new GType(TabbedBrowserType);

Added: trunk/examples/browser/browser-menu.js
==============================================================================
--- (empty file)
+++ trunk/examples/browser/browser-menu.js	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,130 @@
+FileMenuType = {
+	parent: Gtk.Menu.type,
+	name: "FileMenu",
+	instance_init: function(klass)
+	{
+		this.newTabItem = new_tab_action.create_menu_item();
+		//this.openItem = new Gtk.MenuItem({"child": new Gtk.Label({"label": "Open..."})});
+		//this.saveAsItem = new Gtk.MenuItem({"child": new Gtk.Label({"label": "Save As..."})});
+		this.closeItem = close_tab_action.create_menu_item();
+		this.quitItem = quit_action.create_menu_item();
+		this.printItem = print_action.create_menu_item();
+
+		this.append(this.newTabItem);
+		//this.append(this.openItem);
+		//this.append(this.saveAsItem);
+		this.append(this.closeItem);
+		this.append(new Gtk.SeparatorMenuItem());
+		this.append(this.printItem);	
+		this.append(new Gtk.SeparatorMenuItem());
+		this.append(this.quitItem);
+	}};
+
+FileMenu = new GType(FileMenuType);
+
+EditMenuType = {
+	parent: Gtk.Menu.type,
+	name: "EditMenu",
+	class_init: function(klass, prototype)
+	{
+	},
+	instance_init: function(klass)
+	{
+		this.cutItem = cut_action.create_menu_item();
+		this.copyItem = copy_action.create_menu_item();
+		this.pasteItem = paste_action.create_menu_item();
+		this.findItem = find_action.create_menu_item();
+		
+		this.append(this.cutItem);
+		this.append(this.copyItem);
+		this.append(this.pasteItem);
+		this.append(new Gtk.SeparatorMenuItem());
+		this.append(this.findItem);
+	}};
+
+EditMenu = new GType(EditMenuType);
+
+BookmarksMenuType = {
+	parent: Gtk.Menu.type,
+	name: "BookmarksMenu",
+	class_init: function(klass, prototype)
+	{
+	},
+	instance_init: function(klass)
+	{
+		this.addBookmarkItem = add_bookmark_action.create_menu_item();
+		this.append(this.addBookmarkItem);
+		this.append(new Gtk.SeparatorMenuItem());
+	}};
+
+BookmarksMenu = new GType(BookmarksMenuType);
+
+HelpMenuType = {
+	parent: Gtk.Menu.type,
+	name: "HelpMenu",
+	class_init: function(klass, prototype)
+	{
+	},
+	instance_init: function(klass)
+	{
+		this.aboutTabItem = about_action.create_menu_item();
+		this.append(this.aboutTabItem);
+	}};
+
+HelpMenu = new GType(HelpMenuType);
+
+
+ViewMenuType = {
+	parent: Gtk.Menu.type,
+	name: "ViewMenu",
+	instance_init: function(klass)
+	{
+		this.zoomInTabItem = zoom_in_action.create_menu_item();
+		this.append(this.zoomInTabItem);
+
+		this.zoomOutTabItem = zoom_out_action.create_menu_item();
+		this.append(this.zoomOutTabItem);
+
+		this.zoomZeroTabItem = zoom_zero_action.create_menu_item();
+		this.append(this.zoomZeroTabItem);
+	}};
+
+ViewMenu = new GType(ViewMenuType);
+
+
+BrowserMenuType = {
+	parent: Gtk.MenuBar.type,
+	name: "BrowserMenu",
+	class_init: function(klass, prototype)
+	{
+	},
+	instance_init: function(klass)
+	{
+		// Toplevel menus
+		this.fileMenu = new FileMenu();
+		this.editMenu = new EditMenu();
+		this.bookmarksMenu = new BookmarksMenu();
+		this.helpMenu = new HelpMenu();
+		this.viewMenu = new ViewMenu();
+		
+		this.fileItem = new Gtk.MenuItem({"child": new Gtk.Label({"label": "File"})});
+		this.editItem = new Gtk.MenuItem({"child": new Gtk.Label({"label": "Edit"})});
+		this.viewItem = new Gtk.MenuItem({"child": new Gtk.Label({"label": "View"})});
+		this.bookmarksItem = new Gtk.MenuItem({"child": new Gtk.Label({"label": "Bookmarks"})});
+		this.helpItem = new Gtk.MenuItem({"child": new Gtk.Label({"label": "Help"})});
+		
+		this.fileItem.submenu = this.fileMenu;
+		this.editItem.submenu = this.editMenu;
+		this.viewItem.submenu = this.viewMenu;
+		this.bookmarksItem.submenu = this.bookmarksMenu;
+		this.helpItem.submenu = this.helpMenu;
+		
+		this.append(this.fileItem);
+		this.append(this.editItem);
+		this.append(this.viewItem);
+		this.append(this.bookmarksItem);
+		this.append(this.helpItem);
+	}};
+
+BrowserMenu = new GType(BrowserMenuType);
+

Added: trunk/examples/browser/browser-tab.js
==============================================================================
--- (empty file)
+++ trunk/examples/browser/browser-tab.js	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,156 @@
+function title_changed(webView, webFrame, title, tab)
+{
+	if(title.length > 25)
+		title = title.slice(0,25) + "...";
+	
+	tab.titleLabel.label = title;
+	return false;
+}
+
+function url_changed(webView, webFrame, tab)
+{
+	tab.toolbar.back.sensitive = webView.can_go_back();
+	tab.toolbar.forward.sensitive = webView.can_go_forward();
+	tab.toolbar.urlBar.text = webFrame.get_uri();
+	return false;
+}
+
+function new_tab_requested(webView, webFrame, newWebView)
+{
+	newWebView = new WebKit.WebView();
+	newWebView.signal.web_view_ready.connect(new_tab_ready);
+	return newWebView;
+}
+
+function new_tab_ready(webView)
+{
+	browser.newTab().setWebView(webView);	
+	return false;
+}
+
+BrowserTabType = {
+	parent: Gtk.VBox.type,
+	name: "BrowserTab",
+	class_init: function(klass, prototype)
+	{
+		prototype.navigateTo = function (location)
+		{
+			if(!this.webView)
+				this.setWebView(new WebKit.WebView());
+			
+			this.webView.open(location);
+			this.show_all();
+		}
+		
+		prototype.setWebView = function (webView)
+		{
+			if(this.webView)
+				return;
+			
+			this.webView = webView;
+			
+			this.webView.set_scroll_adjustments(null, null);
+			this.webView.signal.title_changed.connect(title_changed, this);
+			this.webView.signal.load_committed.connect(url_changed, this);
+			this.webView.signal.create_web_view.connect(new_tab_requested, this);
+			this.webView.signal.web_view_ready.connect(new_tab_ready, this);
+			
+			this.webView.full_content_zoom = true;
+			
+			this.webView.signal.load_started.connect(
+				function()
+          		{
+					// At least on the Eee, the progress bar is bigger than the
+					// default status bar, so the status bar size changes when we hide/show 
+          			progressBar.show();
+					progressBar.fraction = 0;
+					// Questionable UI decision.
+					progressBar.pulse();
+           		});
+			this.webView.signal.load_progress_changed.connect(
+				function(view, progress)
+           		{
+					progressBar.fraction = progress/100;
+           		});
+           	this.webView.signal.load_finished.connect(
+           		function()
+           		{
+           			progressBar.hide();
+           		});
+					
+			this.webView.signal.hovering_over_link.connect(
+				function(view, link, uri)
+         		{
+					status.pop(hoverContextId);
+					status.push(hoverContextId, uri);
+           		});
+			
+			this.toolbar.urlBar.signal.activate.connect(browse, this);
+			this.toolbar.back.sensitive = this.webView.can_go_back();
+			this.toolbar.forward.sensitive = this.webView.can_go_forward();
+
+			
+			webView.set_settings(webKitSettings);
+			var inspector = webView.get_inspector();
+
+			inspector.signal.inspect_web_view.connect(
+				function()
+				{
+					w = new Gtk.Window();
+					s = new Gtk.ScrolledWindow();
+					w.set_title("Inspector");
+			
+					w.set_default_size(400, 300);
+
+					view = new WebKit.WebView();
+					s.add(view);
+					w.add(s);
+			
+					w.show_all();
+			
+					return view;
+				}
+			);
+			
+			
+			var scrollView = new Gtk.ScrolledWindow();
+			scrollView.smooth_scroll = true;
+			scrollView.add(this.webView);
+			scrollView.set_policy(Gtk.PolicyType.Automatic,
+								  Gtk.PolicyType.Automatic);
+			this.pack_start(scrollView, true, true);
+			this.show_all();
+		}
+	},
+	instance_init: function(klass)
+	{
+		this.webView = null;
+		
+		this.toolbar = new BrowserToolbar();
+
+		this.pack_start(this.toolbar);
+	
+		var closeButton = new Gtk.Button();
+		closeButton.set_image(new Gtk.Image({stock: "gtk-close", 
+				icon_size: Gtk.IconSize.Menu}));
+		closeButton.signal.clicked.connect(close_tab, this);
+		closeButton.set_relief(Gtk.ReliefStyle.None);
+	
+		this.progress = new Gtk.ProgressBar({fraction: 0.5});
+	
+		this.title = new Gtk.HBox();
+		this.titleLabel = new Gtk.Label({label:"Untitled"})
+		this.title.pack_start(this.titleLabel);
+		this.title.pack_start(closeButton);
+		this.title.show_all();
+		
+/*		forker_pipe.write("fork");
+		this.pid = parseInt(forker_pipe.read());
+		Seed.print("new pid: " + this.pid);*/
+		
+		
+		this.show_all();
+		this.toolbar.urlBar.grab_focus();
+	}};
+
+BrowserTab = new GType(BrowserTabType);

Added: trunk/examples/browser/browser-toolbar.js
==============================================================================
--- (empty file)
+++ trunk/examples/browser/browser-toolbar.js	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,25 @@
+BrowserToolbarType = {
+	parent: Gtk.HBox.type,
+	name: "BrowserToolbar",
+	instance_init: function(klass)
+	{
+		this.urlBar = new Gtk.Entry();
+		this.searchBar = new Gtk.Entry();
+	
+		this.back = new Gtk.ToolButton({stock_id:"gtk-go-back"});
+		this.forward = new Gtk.ToolButton({stock_id:"gtk-go-forward"});
+		this.refresh = new Gtk.ToolButton({stock_id:"gtk-refresh"});
+	
+		this.back.signal.clicked.connect(go_back);
+		this.forward.signal.clicked.connect(go_forward);
+		this.refresh.signal.clicked.connect(refresh_page);
+
+		this.pack_start(this.back);
+		this.pack_start(this.forward);
+		this.pack_start(this.refresh);
+
+		this.pack_start(this.urlBar, true, true);
+		this.pack_start(this.searchBar, false, false, 5);
+	}};
+
+BrowserToolbar = new GType(BrowserToolbarType);

Added: trunk/examples/browser/main.js
==============================================================================
--- (empty file)
+++ trunk/examples/browser/main.js	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,112 @@
+#!/usr/bin/env seed
+
+
+Seed.import_namespace("Gtk");
+Seed.import_namespace("WebKit");
+Seed.import_namespace("Multiprocessing");
+Seed.import_namespace("sqlite");
+
+/*var forker_pipes = new Multiprocessing.Pipe();
+var forker_pid = Seed.fork();
+if (forker_pid == 0)
+{
+	var children = new Object;
+	Seed.print("*** Initializing forker \n");
+	Seed.print(forker_pipes[0].read());
+	forker_pipes[0].write("And the other direction!");
+	
+	forker_pipes[0].add_watch(1,
+			  function(source, condition)
+			  {
+				  var message = source.read();
+				  Seed.print("*** forker communication from main: " + message);
+				  if (message == "fork\n")
+				  {
+					  var child_pipes = new Multiprocessing.Pipe();
+					  child_pid = Seed.fork();
+					  if (child_pid == 0)
+					  {
+					  }
+					  else
+					  {
+						  source.write(child_pid);
+					  }
+				  }
+				  return true;
+			  });
+	
+	Gtk.main();
+}
+*/
+/* Todo (priority order):
+	* Ctrl-click-open-in-new-tab?
+	* Bookmark editing/deleting/dropdown on creation allowing you to change the name!!
+	* History
+	* Search bar
+	* Zoom
+	* View source (or is web inspector enough? it's nicer than anything I can do)
+	* Save / open local files
+	* cookies?? do they not happen magically?
+	* favicon
+	* Settings manager
+*/
+
+// Configuration
+var homePage = "http://www.google.com";;
+var selectTabOnCreation = false;
+var webKitSettings = new WebKit.WebSettings({enable_developer_extras: true});
+
+Seed.include("browser-bookmarks.js");
+Seed.include("browser-actions.js");
+Seed.include("browser-toolbar.js");
+Seed.include("browser-tab.js");
+Seed.include("browser-menu.js");
+Seed.include("browser-main.js");
+Seed.include("browser-find.js");
+
+Gtk.init(null, null);
+
+function shutdown()
+{
+	// TODO: make this signaly... or something. wrapper function is silly.
+	bookmarks_db.close();
+	Gtk.main_quit();
+}
+
+/*forker_pipes[1].write("Testing communication from main to forker,"+
+					  " received");
+Seed.print(forker_pipes[1].read());
+forker_pipe = forker_pipes[1];*/
+
+var window = new Gtk.Window({title: "Browser"});
+window.signal.hide.connect(shutdown);
+window.resize(800,500);
+window.add_accel_group(initialize_actions());
+
+var status = new Gtk.Statusbar();
+// Small race condition with progressBar of sorts.
+// ^^ /what/?
+var progressBar = new Gtk.ProgressBar();
+var menu = new BrowserMenu();
+var findBox = new FindBox();
+
+var browserBox = new Gtk.VBox();
+
+populate_bookmarks_menu();
+
+var browser = new TabbedBrowser();
+hoverContextId = status.get_context_id("hover");
+browser.newTab().navigateTo(homePage);
+
+
+status.pack_end(progressBar, false, false, 0);
+
+browserBox.pack_start(menu);
+browserBox.pack_start(browser, true, true);
+browserBox.pack_start(findBox);
+browserBox.pack_start(status, false, false, 0);
+
+window.add(browserBox);
+window.show_all();
+findBox.hide();
+Gtk.main();

Added: trunk/examples/lightsoff/COPYING
==============================================================================
--- (empty file)
+++ trunk/examples/lightsoff/COPYING	Sun Dec 21 06:19:17 2008
@@ -0,0 +1,11 @@
+--2008-12-21 01:14:23--  http://www.gnu.org/licenses/gpl-3.0.txt
+Resolving www.gnu.org... 199.232.41.10
+Connecting to www.gnu.org|199.232.41.10|:80... connected.
+HTTP request sent, awaiting response... 200 OK
+Length: 35147 (34K) [text/plain]
+Saving to: `gpl-3.0.txt'
+
+     0K .......... .......... .......... ....                 100%  363K=0.09s
+
+2008-12-21 01:14:23 (363 KB/s) - `gpl-3.0.txt' saved [35147/35147]
+

Added: trunk/tests/COPYING
==============================================================================
--- (empty file)
+++ trunk/tests/COPYING	Sun Dec 21 06:19:17 2008
@@ -0,0 +1 @@
+Any code in these tests is to be considered under the MIT license.

Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am	(original)
+++ trunk/tests/Makefile.am	Sun Dec 21 06:19:17 2008
@@ -1,4 +1,5 @@
 EXTRA_DIST = \
+    COPYING \
     argv.js \
     closure-finalization.js \
     native-closure-exception.js \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]