Bug #278312 --> Initial framework for inline spell check

sr=bienvenu


git-svn-id: svn://10.0.0.236/trunk@168715 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
scott%scott-macgregor.org
2005-02-02 19:42:55 +00:00
parent 80283ef173
commit 70ed3115ee
4 changed files with 1402 additions and 1 deletions

View File

@@ -74,11 +74,13 @@ CPPSRCS = \
mozEnglishWordUtils.cpp \
mozGenericWordUtils.cpp \
mozSpellI18NManager.cpp \
mozInlineSpellChecker.cpp \
$(NULL)
EXTRA_DSO_LDOPTS = \
$(LIBS_DIR) \
$(MOZ_COMPONENT_LIBS) \
$(MOZ_UNICHARUTIL_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,183 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Inline Spellchecker
*
* The Initial Developer of the Original Code is Mozdev Group, Inc.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Neil Deakin (neil@mozdevgroup.com)
* Scott MacGregor (mscott@mozilla.org)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __mozinlinespellchecker_h__
#define __mozinlinespellchecker_h__
#include "nsIEditorSpellCheck.h"
#include "nsIEditActionListener.h"
#include "nsIInlineSpellChecker.h"
#include "nsITextServicesDocument.h"
#include "nsIDOMTreeWalker.h"
#include "nsWeakReference.h"
#include "nsIEditor.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsWeakReference.h"
class nsIDOMMouseEventListener;
class mozInlineSpellChecker : public nsIInlineSpellChecker, nsIEditActionListener, nsIDOMMouseListener, nsIDOMKeyListener,
nsSupportsWeakReference
{
private:
nsWeakPtr mEditor;
nsCOMPtr<nsIEditorSpellCheck> mSpellCheck;
nsCOMPtr<nsITextServicesDocument> mTextServicesDocument;
nsCOMPtr<nsIDOMTreeWalker> mTreeWalker;
nsCOMPtr<mozISpellI18NUtil> mConverter;
// we need to keep track of the current text position in the document
// so we can spell check the old word when the user clicks around the document.
nsCOMPtr<nsIDOMNode> mCurrentSelectionAnchorNode;
PRInt32 mCurrentSelectionOffset;
// TODO: these should be defined somewhere so that they don't have to be copied
// from editor!
enum OperationID
{
kOpIgnore = -1,
kOpNone = 0,
kOpUndo,
kOpRedo,
kOpInsertNode,
kOpCreateNode,
kOpDeleteNode,
kOpSplitNode,
kOpJoinNode,
kOpDeleteSelection,
kOpInsertBreak = 1000,
kOpInsertText = 1001,
kOpInsertIMEText = 1002,
kOpDeleteText = 1003,
kOpMakeList = 3001,
kOpIndent = 3002,
kOpOutdent = 3003,
kOpAlign = 3004,
kOpMakeBasicBlock = 3005,
kOpRemoveList = 3006,
kOpMakeDefListItem = 3007,
kOpInsertElement = 3008,
kOpInsertQuotation = 3009,
kOpSetTextProperty = 3010,
kOpRemoveTextProperty = 3011,
kOpHTMLPaste = 3012,
kOpLoadHTML = 3013,
kOpResetTextProperties = 3014,
kOpSetAbsolutePosition = 3015,
kOpRemoveAbsolutePosition = 3016,
kOpDecreaseZIndex = 3017,
kOpIncreaseZIndex = 3018
};
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIEDITACTIONLISTENER
NS_DECL_NSIINLINESPELLCHECKER
/*BEGIN implementations of mouseevent handler interface*/
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent);
/*END implementations of mouseevent handler interface*/
/* BEGIN interfaces in to the keylistener interface. */
NS_IMETHOD KeyDown(nsIDOMEvent* aKeyEvent);
NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent);
NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent);
/* END interfaces from nsIDOMKeyListener */
mozInlineSpellChecker();
virtual ~mozInlineSpellChecker();
// spell check the selected text specified by aSelection
nsresult SpellCheckSelection(nsISelection *aSelection,
nsISelection *aSpellCheckSelection);
// spell checks all of the words between two nodes
nsresult SpellCheckBetweenNodes(nsIDOMNode *aStartNode,
PRInt32 aStartOffset,
nsIDOMNode *aEndNode,
PRInt32 aEndOffset,
nsISelection *aSpellCheckSelection);
// examines the dom node in question and returns true if the inline spell
// checker should skip the node (i.e. the text is inside of a block quote
// or an e-mail signature...)
nsresult CheckShouldSpellCheck(nsIDOMNode *aNode, PRBool * aCheckSpelling);
nsresult AdjustSpellHighlighting(nsIDOMNode *aNode,
PRInt32 aOffset,
nsISelection *aSpellCheckSelection,
PRBool isDeletion);
// spell check the text contained within aRange
nsresult SpellCheckRange(nsIDOMRange *aRange, nsISelection *aSpellCheckSelection);
// helper routine to determine if a point is inside of a the passed in selection.
nsresult IsPointInSelection(nsISelection *aSelection,
nsIDOMNode *aNode,
PRInt32 aOffset,
nsIDOMRange **aRange);
nsresult CleanupRangesInSelection(nsISelection *aSelection);
nsresult RemoveCurrentWordFromSpellSelection(nsISelection *aSpellCheckSelection, nsIDOMRange * aWordRange);
// DOM and editor event registration helper routines
nsresult RegisterEventListeners();
nsresult UnregisterEventListeners();
nsresult HandleNavigationEvent(nsIDOMEvent * aEvent, PRBool aForceWordSpellCheck, PRInt32 aNewPositionOffset = 0);
// helper routine which expands a point in a text node out to the range for the containing word.
nsresult GenerateRangeForSurroundingWord(nsIDOMNode * aNode, PRInt32 aOffset, nsIDOMRange ** aWordRange);
// helper routine for determining if aNode/aOffset is an end of word delimiter.
PRBool EndOfAWord(nsIDOMNode *aNode, PRInt32 aOffset);
nsresult GetSpellCheckSelection(nsISelection ** aSpellCheckSelection);
nsresult SaveCurrentSelectionPosition();
};
#endif /* __mozinlinespellchecker_h__ */

View File

@@ -39,6 +39,7 @@
#include "nsIGenericFactory.h"
#include "mozSpellChecker.h"
#include "mozInlineSpellChecker.h"
#include "nsTextServicesCID.h"
#include "mozPersonalDictionary.h"
#include "mozSpellI18NManager.h"
@@ -48,6 +49,11 @@
0x8227F019, 0xAFC7, 0x461e, \
{ 0xB0, 0x30, 0x9F, 0x18, 0x5D, 0x7A, 0x0E, 0x29} }
#define MOZ_INLINESPELLCHECKER_CID \
{ /* 9FE5D975-09BD-44aa-A01A-66402EA28657 */ \
0x9fe5d975, 0x9bd, 0x44aa, \
{ 0xa0, 0x1a, 0x66, 0x40, 0x2e, 0xa2, 0x86, 0x57} }
////////////////////////////////////////////////////////////////////////
// Define the contructor function for the objects
//
@@ -57,6 +63,7 @@
NS_GENERIC_FACTORY_CONSTRUCTOR(mozSpellChecker)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozPersonalDictionary, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(mozSpellI18NManager)
NS_GENERIC_FACTORY_CONSTRUCTOR(mozInlineSpellChecker)
////////////////////////////////////////////////////////////////////////
// Define a table of CIDs implemented by this module along with other
@@ -66,7 +73,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(mozSpellI18NManager)
static nsModuleComponentInfo components[] = {
{ NULL, NS_SPELLCHECKER_CID, NS_SPELLCHECKER_CONTRACTID, mozSpellCheckerConstructor },
{ NULL, MOZ_PERSONALDICTIONARY_CID, MOZ_PERSONALDICTIONARY_CONTRACTID, mozPersonalDictionaryConstructor },
{ NULL, MOZ_SPELLI18NMANAGER_CID, MOZ_SPELLI18NMANAGER_CONTRACTID, mozSpellI18NManagerConstructor }
{ NULL, MOZ_SPELLI18NMANAGER_CID, MOZ_SPELLI18NMANAGER_CONTRACTID, mozSpellI18NManagerConstructor },
{ NULL, MOZ_INLINESPELLCHECKER_CID, MOZ_INLINESPELLCHECKER_CONTRACTID, mozInlineSpellCheckerConstructor }
};
////////////////////////////////////////////////////////////////////////