Bug 339127: Add "spellcheck" attribute to control spellchecking.

r=brettw
sr=sicking


git-svn-id: svn://10.0.0.236/trunk@205107 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pkasting%google.com
2006-07-29 00:04:40 +00:00
parent 8cb58cb1b5
commit 0f0eee34d2
18 changed files with 318 additions and 203 deletions

View File

@@ -107,8 +107,6 @@
#include "nsISelectElement.h"
#include "nsFrameSelection.h"
#include "nsISelectionPrivate.h"//for toStringwithformat code
#include "nsIInlineSpellChecker.h"
#include "nsIEditor.h"
#include "nsICharsetDetector.h"
#include "nsICharsetDetectionAdaptor.h"
@@ -156,8 +154,6 @@ 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
@@ -344,9 +340,6 @@ nsHTMLDocument::~nsHTMLDocument()
if (mIdAndNameHashTable.ops) {
PL_DHashTableFinish(&mIdAndNameHashTable);
}
nsContentUtils::UnregisterPrefCallback(PREF_DEFAULT_SPELLCHECK,
nsHTMLDocument::RealTimeSpellCallback, this);
}
NS_IMPL_ADDREF_INHERITED(nsHTMLDocument, nsDocument)
@@ -3707,11 +3700,7 @@ nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode)
rv = ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), PR_FALSE,
NS_LITERAL_STRING("false"), &unused);
if (NS_SUCCEEDED(rv)) {
nsContentUtils::RegisterPrefCallback(PREF_DEFAULT_SPELLCHECK,
nsHTMLDocument::RealTimeSpellCallback, this);
}
else {
if (NS_FAILED(rv)) {
// Editor setup failed. Editing is is not on after all.
editSession->TearDownEditorOnWindow(window);
@@ -3725,68 +3714,12 @@ 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<nsIEditor> editor;
aEditSession->GetEditorForWindow(aWindow, getter_AddRefs(editor));
if (editor) {
nsCOMPtr<nsIInlineSpellChecker> 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<nsIEditingSession> editSession = do_GetInterface(docshell);
if (editSession)
doc->SetEnableRealTimeSpell(window, editSession);
}
}
}
return 0;
}
nsresult
nsHTMLDocument::GetMidasCommandManager(nsICommandManager** aCmdMgr)
{