Bug 302050: inline spellchecking for textboxes backend. r=bryner sr=bzbarsky
This commit is contained in:
@@ -67,6 +67,7 @@
|
||||
#include "nsIScrollableFrame.h" //to turn off scroll bars
|
||||
#include "nsFormControlFrame.h" //for registering accesskeys
|
||||
#include "nsIDeviceContext.h" // to measure fonts
|
||||
#include "nsIInlineSpellChecker.h"
|
||||
|
||||
#include "nsIContent.h"
|
||||
#include "nsIAtom.h"
|
||||
@@ -132,6 +133,8 @@
|
||||
|
||||
#define DEFAULT_COLUMN_WIDTH 20
|
||||
|
||||
#define PREF_DEFAULT_SPELLCHECK "layout.textarea.spellcheckDefault"
|
||||
|
||||
#include "nsContentCID.h"
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
||||
@@ -1661,6 +1664,63 @@ nsTextControlFrame::CreateFrameFor(nsPresContext* aPresContext,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// nsTextControlFrame::SetEnableRealTimeSpell
|
||||
//
|
||||
// This enables or disables the spellchecker based on the given flag. It
|
||||
// will only create a spellcheck object if necessary.
|
||||
|
||||
void
|
||||
nsTextControlFrame::SetEnableRealTimeSpell(PRBool aEnabled)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_ASSERTION(!aEnabled || !IsPasswordTextControl(),
|
||||
"don't enable real time spell for password controls");
|
||||
|
||||
// The editor will lazily create the spell checker object if it has not been
|
||||
// created. We only want one created if we are turning it on, since not
|
||||
// created implies there's no spell checking yet.
|
||||
nsCOMPtr<nsIInlineSpellChecker> inlineSpellChecker;
|
||||
rv = mEditor->GetInlineSpellChecker(aEnabled,
|
||||
getter_AddRefs(inlineSpellChecker));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && inlineSpellChecker) {
|
||||
inlineSpellChecker->SetEnableRealTimeSpell(aEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
// nsTextControlFrame::SyncRealTimeSpell
|
||||
//
|
||||
// This function is called to update whether inline spell checking is enabled
|
||||
// for the control. It is called on initialization and when things happen
|
||||
// that might affect spellchecking (for example, if it gets enabled or
|
||||
// disabled).
|
||||
//
|
||||
// Multi-line text controls are spellchecked when the preference is set.
|
||||
// Everything else (including read-only textareas) are not spellchecked by
|
||||
// default.
|
||||
|
||||
void
|
||||
nsTextControlFrame::SyncRealTimeSpell()
|
||||
{
|
||||
PRBool readOnly = PR_FALSE;
|
||||
if (mEditor) {
|
||||
PRUint32 flags;
|
||||
mEditor->GetFlags(&flags);
|
||||
if (flags & nsIPlaintextEditor::eEditorReadonlyMask)
|
||||
readOnly = PR_TRUE;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
SetEnableRealTimeSpell(enable);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextControlFrame::InitEditor()
|
||||
{
|
||||
@@ -1745,6 +1805,8 @@ nsTextControlFrame::InitEditor()
|
||||
|
||||
transMgr->SetMaxTransactionCount(DEFAULT_UNDO_CAP);
|
||||
|
||||
SyncRealTimeSpell();
|
||||
|
||||
if (IsPasswordTextControl()) {
|
||||
// Disable undo for password textfields. Note that we want to do this at
|
||||
// the very end of InitEditor, so the calls to EnableUndo when setting the
|
||||
@@ -2811,6 +2873,7 @@ nsTextControlFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
||||
mSelCon->SetCaretEnabled(PR_TRUE);
|
||||
}
|
||||
mEditor->SetFlags(flags);
|
||||
SyncRealTimeSpell();
|
||||
}
|
||||
else if (mEditor && nsHTMLAtoms::disabled == aAttribute)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user