Make it possible to enable spell-check for text inputs too (not just

textareas).  Make the pref controlling the whole thing live.  Bug 151040, patch
by Julian Pellico <jpellico@yahoo.com>, r=bzbarsky, sr=bryner


git-svn-id: svn://10.0.0.236/trunk@189459 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bzbarsky%mit.edu 2006-02-09 03:50:53 +00:00
parent dc08eb2271
commit 992aec0bc9
5 changed files with 43 additions and 6 deletions

View File

@ -434,7 +434,8 @@ pref("browser.backspace_action", 0);
// this will automatically enable inline spellchecking (if it is available) for
// multi-line text entry controls <textarea>s in HTML
pref("layout.textarea.spellcheckDefault", true);
// 0 = spellcheck nothing, 1 = check multi-line controls, 2 = check multi/single line controls
pref("layout.spellcheckDefault", 1);
pref("view_source.editor.path", "");
pref("view_source.editor.external", false);

View File

@ -175,6 +175,11 @@ NS_IMETHODIMP mozEnglishWordUtils::FindNextWord(const PRUnichar *word, PRUint32
const PRUnichar *startWord=p;
if(p<endbuf){
// XXX These loops should be modified to handle non-BMP characters.
// if previous character is a word character, need to advance out of the word
if (offset > 0 && ucIsAlpha(*(p-1))) {
while (p < endbuf && ucIsAlpha(*p))
p++;
}
while((p < endbuf) && (!ucIsAlpha(*p)))
{
p++;

View File

@ -48,6 +48,7 @@
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsWeakReference.h"
#include "mozISpellI18NUtil.h"
class nsIDOMMouseEventListener;

View File

@ -133,7 +133,7 @@
#define DEFAULT_COLUMN_WIDTH 20
#define PREF_DEFAULT_SPELLCHECK "layout.textarea.spellcheckDefault"
#define PREF_DEFAULT_SPELLCHECK "layout.spellcheckDefault"
#include "nsContentCID.h"
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
@ -1422,6 +1422,8 @@ nsTextControlFrame::PreDestroy(nsPresContext* aPresContext)
NS_IMETHODIMP
nsTextControlFrame::Destroy(nsPresContext* aPresContext)
{
nsContentUtils::UnregisterPrefCallback(PREF_DEFAULT_SPELLCHECK,
nsTextControlFrame::RealTimeSpellCallback, this);
if (!mDidPreDestroy) {
PreDestroy(aPresContext);
}
@ -1705,14 +1707,32 @@ nsTextControlFrame::SyncRealTimeSpell()
}
PRBool enable = PR_FALSE;
if (!readOnly && !IsSingleLineTextControl()) {
// multi-line text control: check the pref to see what the default should be
// GetBoolPref defaults the value to PR_FALSE is the pref is not set
enable = nsContentUtils::GetBoolPref(PREF_DEFAULT_SPELLCHECK);
if (!readOnly) {
// check the pref to see what the default should be, default is 0: never spellcheck
PRInt32 spellcheckLevel = nsContentUtils::GetIntPref(PREF_DEFAULT_SPELLCHECK, 0);
switch (spellcheckLevel) {
case SpellcheckAllTextFields:
enable = PR_TRUE;
break;
case SpellcheckMultiLineOnly:
enable = !IsSingleLineTextControl();
break;
}
}
SetEnableRealTimeSpell(enable);
}
// PrefCallback for real time spell pref
// static
int PR_CALLBACK nsTextControlFrame::RealTimeSpellCallback(const char* aPref, void* aContext)
{
if (strcmp(aPref, PREF_DEFAULT_SPELLCHECK) == 0) {
nsTextControlFrame* frame = NS_STATIC_CAST(nsTextControlFrame*, aContext);
NS_ASSERTION(frame, "Pref callback: aContext was of an unexpected type");
frame->SyncRealTimeSpell();
}
return 0;
}
nsresult
nsTextControlFrame::InitEditor()
@ -1799,6 +1819,8 @@ nsTextControlFrame::InitEditor()
transMgr->SetMaxTransactionCount(DEFAULT_UNDO_CAP);
SyncRealTimeSpell();
nsContentUtils::RegisterPrefCallback(PREF_DEFAULT_SPELLCHECK,
nsTextControlFrame::RealTimeSpellCallback, this);
if (IsPasswordTextControl()) {
// Disable undo for password textfields. Note that we want to do this at

View File

@ -50,6 +50,7 @@
#include "nsWeakReference.h" //for service and presshell pointers
#include "nsIScrollableViewProvider.h"
#include "nsIPhonetic.h"
#include "nsContentUtils.h"
class nsISupportsArray;
class nsIEditor;
@ -184,6 +185,12 @@ public: //for methods who access nsTextControlFrame directly
/* called to free up native keybinding services */
static NS_HIDDEN_(void) ShutDown();
enum SpellcheckDefaultState {
SpellcheckNone = 0,
SpellcheckMultiLineOnly = 1,
SpellcheckAllTextFields = 2
};
protected:
/**
@ -265,6 +272,7 @@ private:
void SetEnableRealTimeSpell(PRBool aEnabled);
void SyncRealTimeSpell();
static int PR_CALLBACK RealTimeSpellCallback(const char* aPref, void* aContext);
private:
nsCOMPtr<nsIEditor> mEditor;