Index: /CKEditor/branches/features/ff_extension/chrome.manifest
===================================================================
--- /CKEditor/branches/features/ff_extension/chrome.manifest	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/chrome.manifest	(revision 5932)
@@ -0,0 +1,4 @@
+content	mozeditor	content/	
+locale	mozeditor	en-US	locale/en-US/
+skin	mozeditor	classic/1.0	skin/
+overlay	chrome://browser/content/browser.xul	chrome://mozeditor/content/firefoxOverlay.xul 
Index: /CKEditor/branches/features/ff_extension/content/editor.css
===================================================================
--- /CKEditor/branches/features/ff_extension/content/editor.css	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/content/editor.css	(revision 5932)
@@ -0,0 +1,11 @@
+html, body { 
+	height: 100%;
+	padding: 0;
+	margin: 0;
+	background-color: #FFF;
+}
+
+form, form>div {
+	width: 100%;
+	height: 100%;
+}
Index: /CKEditor/branches/features/ff_extension/content/editor.html
===================================================================
--- /CKEditor/branches/features/ff_extension/content/editor.html	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/content/editor.html	(revision 5932)
@@ -0,0 +1,67 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+	<title>mozeditor - Editing content</title>
+	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+	<link href="editor.css" rel="stylesheet" type="text/css" />
+	<script type="text/javascript" src="./CKEditor/ckeditor_source.js"></script>
+</head>
+<body>
+
+	<form action="#">
+		<textarea id="contents"></textarea>
+		<script type="text/javascript">
+<!--
+
+var config = {};
+config.height = '100%'; // this doesnt' work properly in CKEditor
+config.customConfig = '../plugins/config.js';
+
+var args, data = '';
+if (document.location.protocol === 'chrome:')
+{
+	if (window.arguments)
+		args = window.arguments[0];
+	else
+		args = parent.parent.mozeditor.editorInfo;
+
+	data = args.data ;
+	config.baseHref = args.baseHref ;
+//	oFCKeditor.Config['EditorAreaStyles'] = '';
+	if (args.styleSheets)
+	{
+		config.contentsCss = args.styleSheets;
+//		oFCKeditor.Config['EditorAreaStyles'] = args.styles  ;
+	}
+	if (args.bodyId)
+		config.bodyId = args.bodyId ;
+	if (args.bodyClass)
+		config.bodyClass = args.bodyClass ;
+//	if (args.bodyStyle)
+//		oFCKeditor.Config['EditorAreaStyles'] = oFCKeditor.Config['EditorAreaStyles'] + ';\r\nbody {' + args.bodyStyle + '}' ;
+}
+
+var contents = document.getElementById("contents");
+contents.value = data;
+var editor = CKEDITOR.replace(contents, config);
+editor.on( 'afterCommandExec', function( event )
+{
+	if ( event.data.name == 'save' )
+		UpdateContent();
+});
+
+function UpdateContent()
+{
+	// get access to the window with all the code:
+//	var mainWindow = document.getElementById('FCKeditor1___Frame').contentWindow ;
+//	mainWindow.ChromePreferences.SavePreferences() ;
+	var value = editor.getData() ;
+	//Destroy
+	args.closeFunction( value ) ;
+	return false ;
+}
+//-->
+		</script>
+	</form>
+</body>
+</html>
Index: /CKEditor/branches/features/ff_extension/content/editorContainer.js
===================================================================
--- /CKEditor/branches/features/ff_extension/content/editorContainer.js	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/content/editorContainer.js	(revision 5932)
@@ -0,0 +1,37 @@
+function FillInHTMLTooltip(tipElement) {
+    var retVal = false;
+    if (tipElement.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul") {
+        return retVal;
+    }
+    const XLinkNS = "http://www.w3.org/1999/xlink";
+    var titleText = null;
+    var XLinkTitleText = null;
+    while (!titleText && !XLinkTitleText && tipElement) {
+        if (tipElement.nodeType == Node.ELEMENT_NODE) {
+            titleText = tipElement.getAttribute("title");
+            XLinkTitleText = tipElement.getAttributeNS(XLinkNS, "title");
+        }
+        tipElement = tipElement.parentNode;
+    }
+    var texts = [titleText, XLinkTitleText];
+    var tipNode = document.getElementById("aHTMLTooltip");
+    for (var i = 0; i < texts.length; ++i) {
+        var t = texts[i];
+        if (t && t.search(/\S/) >= 0) {
+            tipNode.setAttribute("label", t.replace(/\s+/g, " "));
+            retVal = true;
+        }
+    }
+    return retVal;
+}
+
+// This function takes care of passing the window.arguments to the editor.html window
+// If the open.dialog is called with editor.html instead of the .xul file it works automatically
+function mozeditor_SetupArgs(e) {
+	// Remove it so it's called only once
+	window.removeEventListener("DOMContentLoaded", mozeditor_SetupArgs, false);
+	// Add the property to the window object
+	document.getElementById("browser1").contentWindow.arguments = window.arguments ;
+}
+
+window.addEventListener("DOMContentLoaded", mozeditor_SetupArgs, false);
Index: /CKEditor/branches/features/ff_extension/content/editorContainer.xul
===================================================================
--- /CKEditor/branches/features/ff_extension/content/editorContainer.xul	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/content/editorContainer.xul	(revision 5932)
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+ <window 
+     title="MozEditor"
+     xmlns:html="http://www.w3.org/1999/xhtml"
+     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+     style="min-width:100px;min-height:100px;background-color:white;">
+
+	<iframe id="browser1" src="chrome://mozeditor/content/editor.html" tooltip="aHTMLTooltip" flex="1" />
+	<tooltip id="aHTMLTooltip" onpopupshowing="return FillInHTMLTooltip(document.tooltipNode);"/>
+	<script type="application/x-javascript" src="editorContainer.js"/>
+ </window>
Index: /CKEditor/branches/features/ff_extension/content/firefoxOverlay.js
===================================================================
--- /CKEditor/branches/features/ff_extension/content/firefoxOverlay.js	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/content/firefoxOverlay.js	(revision 5932)
@@ -0,0 +1,96 @@
+var mozeditor = {
+	dialog : null,
+
+	/**
+		Setup hook to configure the context menu
+	*/
+  onLoad: function() {
+    document.getElementById("contentAreaContextMenu").addEventListener("popupshowing",
+			function(e) { mozeditor.showContextMenu(e); }, false);
+  },
+
+	/**
+	 Show or hide the menuitem based on what the context menu is on
+	 see http://kb.mozillazine.org/Adding_items_to_menus
+	 Enable it only for textareas and editable iFrames
+	*/
+  showContextMenu: function(event) {
+		var target = gContextMenu.target;
+		var name = target.nodeName.toUpperCase();
+		var hideIt = (name != 'TEXTAREA') ;
+		document.getElementById("sep_mozeditor").hidden = hideIt ;
+		document.getElementById("context-mozeditor").hidden = hideIt ;
+  },
+
+	/**
+		Called from the context menu
+	*/
+  onMenuItemCommand: function(e) {
+		if (this.dialog && this.dialog.closed)
+			this.cleanUp();
+
+		if (this.editorInfo)
+		{
+			this.alert("Write Area is already enabled for another tab. Please, close that editor first.");
+			return;
+		}
+		var editorInfo;
+		var element = this.target = gContextMenu.target ;
+
+		editorInfo = {
+			data: element.value,
+			type: 'textarea',
+			baseHref : ''
+		};
+
+		// store the browser where the editor is being used.
+		// this way we can hide/show the bottom pane as needed.
+		editorInfo.browser = gBrowser.selectedBrowser;
+
+		// Arguments that will be sent to the editor
+		// store them in the object so they can be read by the editor
+		this.editorInfo = editorInfo;
+
+		this.openWindow(editorInfo);
+	},
+
+	openWindow: function(args) {
+		args.closeFunction = this.closeWindow;
+		// dialog=no to get the minimize and maximize buttons
+		this.dialog = window.openDialog('chrome://mozeditor/content/editorContainer.xul', "mozeditor", "width=780,height=500,resizable=yes,dialog=no", args ) ;
+	},
+
+	closeWindow: function(data) {
+		var element = mozeditor.target;
+
+		element.value = data ;
+
+		mozeditor.dialog.close() ;
+		mozeditor.cleanUp();
+	},
+
+
+	cleanUp: function() {
+		delete mozeditor.dialog;
+		delete mozeditor.editorInfo;
+		delete mozeditor.target;
+	},
+
+// Just for debug
+	_toConsole: function(msg) {
+		var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+                                  .getService(Components.interfaces.nsIPromptService);
+    promptService.alert(window, "Debug", msg);
+	},
+
+	alert: function(msg) {
+		var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+                                  .getService(Components.interfaces.nsIPromptService);
+    promptService.alert(window, "Write Area", msg);
+	}
+
+};
+
+window.addEventListener("load", function(e) { mozeditor.onLoad(e); }, false);
+
+
Index: /CKEditor/branches/features/ff_extension/content/firefoxOverlay.xul
===================================================================
--- /CKEditor/branches/features/ff_extension/content/firefoxOverlay.xul	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/content/firefoxOverlay.xul	(revision 5932)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<overlay id="mozeditor-overlay"
+         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+<!-- Our code -->
+	<script type="application/x-javascript" src="firefoxOverlay.js"/>
+
+	<popup id="contentAreaContextMenu">
+		<menuseparator id="sep_mozeditor" insertbefore="context-sep-paste"/>
+		<menuitem id="context-mozeditor" label="Edit in MozEditor"
+			accesskey="E"
+			insertbefore="context-sep-paste"
+			oncommand="mozeditor.onMenuItemCommand(event)"/>
+	</popup>
+<!-- /Our code -->
+
+</overlay>
Index: /CKEditor/branches/features/ff_extension/content/plugins/config.js
===================================================================
--- /CKEditor/branches/features/ff_extension/content/plugins/config.js	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/content/plugins/config.js	(revision 5932)
@@ -0,0 +1,16 @@
+/*
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
+For licensing, see LICENSE.html or http://ckeditor.com/license
+*/
+
+CKEDITOR.editorConfig = function( config )
+{
+	// we don't need this in chrome
+	config.removePlugins = 'maximize,resize,scayt,wsc';
+	// The content isn't editable in chrome: automatically so let's trick it for the moment by setting focus (and use that routine)
+	config.startupFocus = true;
+
+	// Define changes to default configuration here. For example:
+	// config.language = 'fr';
+	// config.uiColor = '#AADC6E';
+};
Index: /CKEditor/branches/features/ff_extension/install.rdf
===================================================================
--- /CKEditor/branches/features/ff_extension/install.rdf	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/install.rdf	(revision 5932)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
+ xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+  <Description about="urn:mozilla:install-manifest">
+
+	<em:id>mozeditor@cksource.com</em:id>
+	<em:name>MozEditor</em:name>
+	<em:description>Test extension for CKEditor in Firefox.</em:description>
+    
+	<em:version>0.1</em:version>
+	<em:creator>Alfonso</em:creator>
+	<em:iconURL>chrome://writearea/skin/writearea.png</em:iconURL>
+	<em:optionsURL>chrome://writearea/content/options.xul</em:optionsURL>
+
+	<!-- Firefox -->
+	<em:targetApplication>
+		<Description>
+			<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
+			<em:minVersion>3.5</em:minVersion>
+			<em:maxVersion>4.0b7</em:maxVersion>
+		</Description>
+	</em:targetApplication>
+
+  </Description>
+</RDF>
Index: /CKEditor/branches/features/ff_extension/readme.txt
===================================================================
--- /CKEditor/branches/features/ff_extension/readme.txt	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/readme.txt	(revision 5932)
@@ -0,0 +1,39 @@
+
+This contains a sample Firefox extension that opens CKEditor in a dialog with the context-menu of textareas.
+
+
+-====================-
+Install instructions:
+---------------------
+Usually a Firefox extension is deployed as a XPI (== .zip but just renamed), although for development 
+purposes it's easier to use the "proxy file" method
+
+Take a look at https://developer.mozilla.org/en/Setting_up_extension_development_environment for general
+recomendations about developing an extension for Firefox, and how to create a separate profile that doesn't
+interfere with general browsing.
+The point that it's important is https://developer.mozilla.org/en/Setting_up_extension_development_environment#Firefox_extension_proxy_file
+Following those steps in inverse order:
+1. Open the "extensions" folder in your profile (you can open about:support and it offers a button to open the profile 
+folder)
+2. Create a file named "mozeditor@cksource.com" (be careful with hidden extensions in windows)
+3. Using a text editor, put the path to this folder (including the last slash). For example D:\CKSource\ff_extension\
+
+Now launch Firefox again.
+It's very important to notice that by default Firefox is agressive caching the contents of extensions, so it's important to use
+preferences like
+nglayout.debug.disable_xul_cache = true 
+nglayout.debug.disable_xul_fastload = true (for FF4)
+(you have to create them in about:config, context menu -> New -> Boolean)
+
+If they are set correctly it's possible to edit the contents of the extension and when the dialog is launched again it can 
+pick up the changes without reloading Firefox. A useful extension about this is https://addons.mozilla.org/en-US/firefox/addon/7434/ 
+that provides an option to reload all the chrome.
+
+The CKEditor folder under content\ points to the SVN trunk, it doesn't have anything special.
+The editor.html file in content\ is loaded as an iframe in the dialog, and in fact it can be launched as a standalone page.
+
+-====================-
+Testing the extension:
+----------------------
+Open a page with a textarea, right click on it and you'll see an option to launch mozEditor, just select it and the dialog should launch
+with CKEditor running with chrome priviledges
Index: /CKEditor/branches/features/ff_extension/test.html
===================================================================
--- /CKEditor/branches/features/ff_extension/test.html	(revision 5932)
+++ /CKEditor/branches/features/ff_extension/test.html	(revision 5932)
@@ -0,0 +1,16 @@
+<!doctype html>
+<html><head>
+
+<style type="text/css">
+</style>
+
+</head>
+<body>
+<p>A simple textarea to help testing</p>
+<form>
+	<textarea id="comments" cols=90 rows=8></textarea><br>
+	<input type="text" name="data">
+</form>
+
+<div id="out"></div>
+</body></html>
