diff --git a/mozilla/editor/idl/nsIHTMLEditor.idl b/mozilla/editor/idl/nsIHTMLEditor.idl
index 9e27ecb68bb..6550065e637 100644
--- a/mozilla/editor/idl/nsIHTMLEditor.idl
+++ b/mozilla/editor/idl/nsIHTMLEditor.idl
@@ -51,7 +51,7 @@ interface nsIContentFilter;
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_EDITOR, 1)
%}
-[scriptable, uuid(4b0fd0d0-1dd2-11b2-bf2e-ef20fbca2c88)]
+[scriptable, uuid(afc36593-5787-4420-93d9-b2c0ccbf0cad)]
interface nsIHTMLEditor : nsISupports
{
@@ -600,5 +600,13 @@ interface nsIHTMLEditor : nsISupports
void checkSelectionStateForAnonymousButtons(in nsISelection aSelection);
boolean isAnonymousElement(in nsIDOMElement aElement);
+
+ /**
+ * A boolean indicating if a return key pressed in a paragraph creates
+ * another paragraph or just inserts a
at the caret
+ *
+ * @return true if CR in a paragraph creates a new paragraph
+ */
+ attribute boolean returnInParagraphCreatesNewParagraph;
};
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp
index 209ea0cf243..714b170a9e7 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -6288,10 +6288,18 @@ nsHTMLEditRules::ReturnInParagraph(nsISelection *aSelection,
*aCancel = PR_FALSE;
*aHandled = PR_FALSE;
- nsCOMPtr sibling;
- nsresult res = NS_OK;
+ nsCOMPtr parent;
+ PRInt32 offset;
+ nsresult res = nsEditor::GetNodeLocation(aNode, address_of(parent), &offset);
+ if (NS_FAILED(res)) return res;
+
+ PRBool doesCRCreateNewP;
+ res = mHTMLEditor->GetReturnInParagraphCreatesNewParagraph(&doesCRCreateNewP);
+ if (NS_FAILED(res)) return res;
+
+ PRBool newBRneeded = PR_FALSE;
+ nsCOMPtr sibling;
- // easy case, in a text node:
if (mHTMLEditor->IsTextNode(aNode))
{
nsCOMPtr textNode = do_QueryInterface(aNode);
@@ -6304,46 +6312,37 @@ nsHTMLEditRules::ReturnInParagraph(nsISelection *aSelection,
{
// is there a BR prior to it?
mHTMLEditor->GetPriorHTMLSibling(aNode, address_of(sibling));
- if (!sibling)
+ if (!sibling ||
+ !mHTMLEditor->IsVisBreak(sibling) || nsTextEditUtils::HasMozAttr(sibling))
{
- // no previous sib, so
- // just fall out to default of inserting a BR
- return res;
+ newBRneeded = PR_TRUE;
}
- if (mHTMLEditor->IsVisBreak(sibling) && !nsTextEditUtils::HasMozAttr(sibling))
- {
- // split para
- nsCOMPtr selNode = aNode;
- *aHandled = PR_TRUE;
- res = SplitParagraph(aPara, sibling, aSelection, address_of(selNode), &aOffset);
- }
- // else just fall out to default of inserting a BR
- return res;
}
- // at end of text node?
- if (aOffset == (PRInt32)strLength)
+ else if (aOffset == (PRInt32)strLength)
{
+ // we're at the end of text node...
// is there a BR after to it?
res = mHTMLEditor->GetNextHTMLSibling(aNode, address_of(sibling));
- if (!sibling)
+ if (!sibling ||
+ !mHTMLEditor->IsVisBreak(sibling) || nsTextEditUtils::HasMozAttr(sibling))
{
- // no next sib, so
- // just fall out to default of inserting a BR
- return res;
+ newBRneeded = PR_TRUE;
+ offset++;
}
- if (mHTMLEditor->IsVisBreak(sibling) && !nsTextEditUtils::HasMozAttr(sibling))
- {
- // split para
- nsCOMPtr selNode = aNode;
- *aHandled = PR_TRUE;
- res = SplitParagraph(aPara, sibling, aSelection, address_of(selNode), &aOffset);
- }
- // else just fall out to default of inserting a BR
- return res;
}
- // inside text node
- // just fall out to default of inserting a BR
- return res;
+ else
+ {
+ if (doesCRCreateNewP)
+ {
+ nsCOMPtr tmp;
+ res = mEditor->SplitNode(aNode, aOffset, getter_AddRefs(tmp));
+ if (NS_FAILED(res)) return res;
+ aNode = tmp;
+ }
+
+ newBRneeded = PR_TRUE;
+ offset++;
+ }
}
else
{
@@ -6359,18 +6358,26 @@ nsHTMLEditRules::ReturnInParagraph(nsISelection *aSelection,
if (NS_FAILED(res)) return res;
if (!nearNode || !mHTMLEditor->IsVisBreak(nearNode) || nsTextEditUtils::HasMozAttr(nearNode))
{
- // just fall out to default of inserting a BR
- return res;
+ newBRneeded = PR_TRUE;
}
}
- // else split para
- *aHandled = PR_TRUE;
- res = SplitParagraph(aPara, nearNode, aSelection, address_of(selNode), &aOffset);
+ if (!newBRneeded)
+ sibling = nearNode;
}
-
- return res;
-}
+ if (newBRneeded)
+ {
+ // if CR does not create a new P, default to BR creation
+ if (!doesCRCreateNewP)
+ return NS_OK;
+ nsCOMPtr brNode;
+ res = mHTMLEditor->CreateBR(parent, offset, address_of(brNode));
+ sibling = brNode;
+ }
+ nsCOMPtr selNode = aNode;
+ *aHandled = PR_TRUE;
+ return SplitParagraph(aPara, sibling, aSelection, address_of(selNode), &aOffset);
+}
///////////////////////////////////////////////////////////////////////////
// SplitParagraph: split a paragraph at selection point, possibly deleting a br
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
index b456544aab5..aa4e4134194 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
@@ -151,8 +151,9 @@ nsHTMLEditor::nsHTMLEditor()
: nsPlaintextEditor()
, mIgnoreSpuriousDragEvent(PR_FALSE)
, mTypeInState(nsnull)
-, mSelectedCellIndex(0)
+, mCRInParagraphCreatesParagraph(PR_FALSE)
, mHTMLCSSUtils(nsnull)
+, mSelectedCellIndex(0)
, mIsObjectResizingEnabled(PR_TRUE)
, mIsResizing(PR_FALSE)
, mIsAbsolutelyPositioningEnabled(PR_TRUE)
@@ -163,11 +164,6 @@ nsHTMLEditor::nsHTMLEditor()
, mIsInlineTableEditingEnabled(PR_TRUE)
, mGridSize(0)
{
- mBoldAtom = do_GetAtom("b");
- mItalicAtom = do_GetAtom("i");
- mUnderlineAtom = do_GetAtom("u");
- mFontAtom = do_GetAtom("font");
- mLinkAtom = do_GetAtom("a");
}
nsHTMLEditor::~nsHTMLEditor()
@@ -6114,3 +6110,16 @@ nsHTMLEditor::IsAnonymousElement(nsIDOMElement * aElement, PRBool * aReturn)
return NS_OK;
}
+nsresult
+nsHTMLEditor::SetReturnInParagraphCreatesNewParagraph(PRBool aCreatesNewParagraph)
+{
+ mCRInParagraphCreatesParagraph = aCreatesNewParagraph;
+ return NS_OK;
+}
+
+nsresult
+nsHTMLEditor::GetReturnInParagraphCreatesNewParagraph(PRBool *aCreatesNewParagraph)
+{
+ *aCreatesNewParagraph = mCRInParagraphCreatesParagraph;
+ return NS_OK;
+}
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h
index ec6437d22fb..074f8827ca6 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditor.h
+++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h
@@ -768,21 +768,12 @@ protected:
TypeInState* mTypeInState;
- nsCOMPtr mBoldAtom;
- nsCOMPtr mItalicAtom;
- nsCOMPtr mUnderlineAtom;
- nsCOMPtr mFontAtom;
- nsCOMPtr mLinkAtom;
-
nsCOMPtr mCachedNode;
-
- PRBool mCachedBoldStyle;
- PRBool mCachedItalicStyle;
- PRBool mCachedUnderlineStyle;
- nsString mCachedFontName;
- // Used to disable HTML formatting commands during HTML source editing
- PRBool mCanEditHTML;
+ PRPackedBool mCRInParagraphCreatesParagraph;
+
+ PRPackedBool mCSSAware;
+ nsHTMLCSSUtils *mHTMLCSSUtils;
// Used by GetFirstSelectedCell and GetNextSelectedCell
PRInt32 mSelectedCellIndex;
@@ -790,13 +781,9 @@ protected:
nsString mLastStyleSheetURL;
nsString mLastOverrideStyleSheetURL;
- PRBool mCSSAware;
- nsHTMLCSSUtils *mHTMLCSSUtils;
-
// Maintain a list of associated style sheets and their urls.
nsStringArray mStyleSheetURLs;
nsCOMArray mStyleSheets;
- PRInt32 mNumStyleSheets;
// an array for holding default style settings
nsVoidArray mDefaultStyles;
diff --git a/mozilla/editor/ui/composer.js b/mozilla/editor/ui/composer.js
index 2b5f4bead11..cae448a4048 100644
--- a/mozilla/editor/ui/composer.js
+++ b/mozilla/editor/ui/composer.js
@@ -134,3 +134,5 @@ pref("editor.disable_spell_checker", false);
pref("editor.dont_lock_spell_files", true);
#endif
#endif
+
+pref("editor.CR_creates_new_p", false);
diff --git a/mozilla/editor/ui/composer/content/editor.js b/mozilla/editor/ui/composer/content/editor.js
index 7aed0a7af13..b73f2a975ca 100644
--- a/mozilla/editor/ui/composer/content/editor.js
+++ b/mozilla/editor/ui/composer/content/editor.js
@@ -78,6 +78,8 @@ var gColorObj = { LastTextColor:"", LastBackgroundColor:"", LastHighlightColor:"
var gDefaultTextColor = "";
var gDefaultBackgroundColor = "";
var gCSSPrefListener;
+var gEditorToolbarPrefListener;
+var gReturnInParagraphPrefListener;
var gPrefs;
var gLocalFonts = null;
@@ -90,6 +92,8 @@ var gFontSizeNames = ["xx-small","x-small","small","medium","large","x-large","x
const nsIFilePicker = Components.interfaces.nsIFilePicker;
const kEditorToolbarPrefs = "editor.toolbars.showbutton.";
+const kUseCssPref = "editor.use_css";
+const kCRInParagraphsPref = "editor.CR_creates_new_p";
function ShowHideToolbarSeparators(toolbar) {
var childNodes = toolbar.childNodes;
@@ -123,55 +127,18 @@ function ShowHideToolbarButtons()
ShowHideToolbarSeparators(document.getElementById("FormatToolbar"));
}
-function AddToolbarPrefListener()
+function nsPrefListener(prefName)
{
- try {
- var pbi = GetPrefs().QueryInterface(Components.interfaces.nsIPrefBranchInternal);
- pbi.addObserver(kEditorToolbarPrefs, gEditorToolbarPrefListener, false);
- } catch(ex) {
- dump("Failed to observe prefs: " + ex + "\n");
- }
-}
-
-function RemoveToolbarPrefListener()
-{
- try {
- var pbi = GetPrefs().QueryInterface(Components.interfaces.nsIPrefBranchInternal);
- pbi.removeObserver(kEditorToolbarPrefs, gEditorToolbarPrefListener);
- } catch(ex) {
- dump("Failed to remove pref observer: " + ex + "\n");
- }
-}
-
-// Pref listener constants
-const gEditorToolbarPrefListener =
-{
- observe: function(subject, topic, prefName)
- {
- // verify that we're changing a button pref
- if (topic != "nsPref:changed")
- return;
-
- var id = prefName.substr(kEditorToolbarPrefs.length) + "Button";
- var button = document.getElementById(id);
- if (button) {
- button.hidden = !gPrefs.getBoolPref(prefName);
- ShowHideToolbarSeparators(button.parentNode);
- }
- }
-};
-
-function nsButtonPrefListener()
-{
- this.startup();
+ this.startup(prefName);
}
// implements nsIObserver
-nsButtonPrefListener.prototype =
+nsPrefListener.prototype =
{
- domain: "editor.use_css",
- startup: function()
+ domain: "",
+ startup: function(prefName)
{
+ this.domain = prefName;
try {
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
pbi.addObserver(this.domain, this, false);
@@ -194,27 +161,45 @@ nsButtonPrefListener.prototype =
return;
// verify that we're changing a button pref
if (topic != "nsPref:changed") return;
- if (prefName.substr(0, this.domain.length) != this.domain) return;
+
+ if (prefName.substr(0, kUseCssPref.length) == kUseCssPref)
+ {
+ var cmd = document.getElementById("cmd_highlight");
+ if (cmd) {
+ var prefs = GetPrefs();
+ var useCSS = prefs.getBoolPref(prefName);
+ var editor = GetCurrentEditor();
+ if (useCSS && editor) {
+ var mixedObj = {};
+ var state = editor.getHighlightColorState(mixedObj);
+ cmd.setAttribute("state", state);
+ cmd.collapsed = false;
+ }
+ else {
+ cmd.setAttribute("state", "transparent");
+ cmd.collapsed = true;
+ }
- var cmd = document.getElementById("cmd_highlight");
- if (cmd) {
- var prefs = GetPrefs();
- var useCSS = prefs.getBoolPref(prefName);
- var editor = GetCurrentEditor();
- if (useCSS && editor) {
- var mixedObj = {};
- var state = editor.getHighlightColorState(mixedObj);
- cmd.setAttribute("state", state);
- cmd.collapsed = false;
- }
- else {
- cmd.setAttribute("state", "transparent");
- cmd.collapsed = true;
+ if (editor)
+ editor.isCSSEnabled = useCSS;
}
-
+ }
+ else if (prefName.substr(0, kEditorToolbarPrefs.length) == kEditorToolbarPrefs)
+ {
+ var id = prefName.substr(kEditorToolbarPrefs.length) + "Button";
+ var button = document.getElementById(id);
+ if (button) {
+ button.hidden = !gPrefs.getBoolPref(prefName);
+ ShowHideToolbarSeparators(button.parentNode);
+ }
+ }
+ else if (prefName.substr(0, kCRInParagraphsPref.length) == kCRInParagraphsPref)
+ {
+ var crInParagraphCreatesParagraph = gPrefs.getBoolPref(prefName);
+ var editor = GetCurrentEditor();
if (editor)
- editor.isCSSEnabled = useCSS;
- }
+ editor.returnInParagraphCreatesNewParagraph = crInParagraphCreatesParagraph;
+ }
}
}
@@ -418,6 +403,9 @@ var gEditorDocumentObserver =
// Things for just the Web Composer application
if (IsWebComposer())
{
+ var prefs = GetPrefs();
+ editor.returnInParagraphCreatesNewParagraph = prefs.getBoolPref(kCRInParagraphsPref);
+
// Set focus to content window if not a mail composer
// Race conditions prevent us from setting focus here
// when loading a url into blank window
@@ -566,15 +554,17 @@ function EditorStartup()
SetupComposerWindowCommands();
ShowHideToolbarButtons();
- AddToolbarPrefListener();
+ gEditorToolbarPrefListener = new nsPrefListener(kEditorToolbarPrefs);
- gCSSPrefListener = new nsButtonPrefListener();
+ gCSSPrefListener = new nsPrefListener(kUseCssPref);
+ gReturnInParagraphPrefListener = new nsPrefListener(kCRInParagraphsPref);
// hide Highlight button if we are in an HTML editor with CSS mode off
+ // and tell the editor if a CR in a paragraph creates a new paragraph
+ var prefs = GetPrefs();
var cmd = document.getElementById("cmd_highlight");
if (cmd) {
- var prefs = GetPrefs();
- var useCSS = prefs.getBoolPref("editor.use_css");
+ var useCSS = prefs.getBoolPref(kUseCssPref);
if (!useCSS && is_HTMLEditor) {
cmd.collapsed = true;
}
@@ -692,8 +682,9 @@ function EditorResetFontAndColorAttributes()
function EditorShutdown()
{
- RemoveToolbarPrefListener();
+ gEditorToolbarPrefListener.shutdown();
gCSSPrefListener.shutdown();
+ gReturnInParagraphPrefListener.shutdown();
try {
var commandManager = GetCurrentCommandManager();
@@ -1332,7 +1323,7 @@ function GetBackgroundElementWithColor()
else
{
var prefs = GetPrefs();
- var IsCSSPrefChecked = prefs.getBoolPref("editor.use_css");
+ var IsCSSPrefChecked = prefs.getBoolPref(kUseCssPref);
if (IsCSSPrefChecked && IsHTMLEditor())
{
var selection = editor.selection;
diff --git a/mozilla/editor/ui/composer/content/pref-composer.xul b/mozilla/editor/ui/composer/content/pref-composer.xul
index a068eb063e8..82b96f7be68 100644
--- a/mozilla/editor/ui/composer/content/pref-composer.xul
+++ b/mozilla/editor/ui/composer/content/pref-composer.xul
@@ -49,7 +49,7 @@
@@ -187,9 +187,18 @@
+
+
+
+
+
diff --git a/mozilla/editor/ui/composer/locale/en-US/pref-composer.dtd b/mozilla/editor/ui/composer/locale/en-US/pref-composer.dtd
index 4e6fd9edd17..3fa9bc62464 100644
--- a/mozilla/editor/ui/composer/locale/en-US/pref-composer.dtd
+++ b/mozilla/editor/ui/composer/locale/en-US/pref-composer.dtd
@@ -39,3 +39,6 @@
+
+
+