diff --git a/mozilla/content/html/document/src/Makefile.in b/mozilla/content/html/document/src/Makefile.in
index 7dc7c7b1b58..bba2e10a174 100644
--- a/mozilla/content/html/document/src/Makefile.in
+++ b/mozilla/content/html/document/src/Makefile.in
@@ -75,6 +75,7 @@ REQUIRES = xpcom \
commandhandler \
composer \
editor \
+ txtsvc \
plugin \
$(NULL)
diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp
index 8554609cbc0..4a763d2390c 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.cpp
+++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp
@@ -106,6 +106,8 @@
#include "nsISelectElement.h"
#include "nsFrameSelection.h"
#include "nsISelectionPrivate.h"//for toStringwithformat code
+#include "nsIInlineSpellChecker.h"
+#include "nsIEditor.h"
#include "nsICharsetDetector.h"
#include "nsICharsetDetectionAdaptor.h"
@@ -153,6 +155,8 @@ const PRInt32 kBackward = 1;
#define ID_NOT_IN_DOCUMENT ((nsIContent *)2)
#define NAME_NOT_VALID ((nsBaseContentList*)1)
+#define PREF_DEFAULT_SPELLCHECK "layout.spellcheckDefault"
+
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
// Returns the name atom of aContent, if the content is a named item
@@ -339,6 +343,9 @@ nsHTMLDocument::~nsHTMLDocument()
if (mIdAndNameHashTable.ops) {
PL_DHashTableFinish(&mIdAndNameHashTable);
}
+
+ nsContentUtils::UnregisterPrefCallback(PREF_DEFAULT_SPELLCHECK,
+ nsHTMLDocument::RealTimeSpellCallback, this);
}
NS_IMPL_ADDREF_INHERITED(nsHTMLDocument, nsDocument)
@@ -3710,7 +3717,11 @@ nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode)
rv = ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), PR_FALSE,
NS_LITERAL_STRING("false"), &unused);
- if (NS_FAILED(rv)) {
+ if (NS_SUCCEEDED(rv)) {
+ nsContentUtils::RegisterPrefCallback(PREF_DEFAULT_SPELLCHECK,
+ nsHTMLDocument::RealTimeSpellCallback, this);
+ }
+ else {
// Editor setup failed. Editing is is not on after all.
editSession->TearDownEditorOnWindow(window);
@@ -3724,12 +3735,68 @@ nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode)
if (NS_SUCCEEDED(rv)) {
mEditingIsOn = PR_FALSE;
+ nsContentUtils::UnregisterPrefCallback(PREF_DEFAULT_SPELLCHECK,
+ nsHTMLDocument::RealTimeSpellCallback, this);
}
}
+ SetEnableRealTimeSpell(window, editSession);
+
return rv;
}
+void
+nsHTMLDocument::SetEnableRealTimeSpell(nsPIDOMWindow* aWindow,
+ nsIEditingSession* aEditSession)
+{
+ // enable inline spelling for design mode documents unless the
+ // pref disables it. Otherwise, disable inline spelling.
+ PRBool enabled = mEditingIsOn;
+
+ if (aWindow) {
+ if (enabled) {
+ // check if the spellchecking is enabled as long as the level is not 0
+ PRInt32 spellcheckLevel = nsContentUtils::GetIntPref(PREF_DEFAULT_SPELLCHECK, 0);
+ enabled = (spellcheckLevel != 0);
+ }
+
+ // get the editor for the window and enable inline spellchecking
+ nsCOMPtr editor;
+ aEditSession->GetEditorForWindow(aWindow, getter_AddRefs(editor));
+ if (editor) {
+ nsCOMPtr inlineSpellChecker;
+ nsresult rv = editor->GetInlineSpellChecker(enabled,
+ getter_AddRefs(inlineSpellChecker));
+
+ if (NS_SUCCEEDED(rv) && inlineSpellChecker) {
+ inlineSpellChecker->SetEnableRealTimeSpell(enabled);
+ }
+ }
+ }
+}
+
+// PrefCallback for real time spell pref
+// static
+int PR_CALLBACK nsHTMLDocument::RealTimeSpellCallback(const char* aPref, void* aContext)
+{
+ if (strcmp(aPref, PREF_DEFAULT_SPELLCHECK) == 0) {
+ nsHTMLDocument* doc = NS_STATIC_CAST(nsHTMLDocument*, aContext);
+ NS_ASSERTION(doc, "Pref callback: aContext was of an unexpected type");
+
+ nsPIDOMWindow *window = doc->GetWindow();
+ if (window) {
+ nsIDocShell *docshell = window->GetDocShell();
+ if (docshell) {
+ nsCOMPtr editSession = do_GetInterface(docshell);
+ if (editSession)
+ doc->SetEnableRealTimeSpell(window, editSession);
+ }
+ }
+ }
+
+ return 0;
+}
+
nsresult
nsHTMLDocument::GetMidasCommandManager(nsICommandManager** aCmdMgr)
{
diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h
index 5b24ae5ed59..7eda745eb8a 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.h
+++ b/mozilla/content/html/document/src/nsHTMLDocument.h
@@ -66,6 +66,7 @@ class nsIURI;
class nsIMarkupDocumentViewer;
class nsIDocumentCharsetInfo;
class nsICacheEntryDescriptor;
+class nsIEditingSession;
class nsHTMLDocument : public nsDocument,
public nsIHTMLDocument,
@@ -359,6 +360,11 @@ protected:
nsCOMPtr mWyciwygChannel;
+ void SetEnableRealTimeSpell(nsPIDOMWindow* aWindow,
+ nsIEditingSession* aEditSession);
+
+ static int PR_CALLBACK RealTimeSpellCallback(const char* aPref, void* aContext);
+
/* Midas implementation */
nsresult GetMidasCommandManager(nsICommandManager** aCommandManager);
PRBool ConvertToMidasInternalCommand(const nsAString & inCommandID,