Bug 1430982 - part 8: Make EditorBase store inline spell checker as mozInlineSpellChecker rather than nsIInlineSpellChecker r?m_kato
EditorBase::mInlineSpellChecker is always an instance of mozInlineSpellChecker.
Fortunately, it's easy to expose mozInlineSpellChecker.h. So, making EditorBase
store it as mozInlineSpellChecker directly, EditorBase can access any of
mozInlineSpellChecker, EditorSpellCheck, mozSpellChecker and
TextServicesDocument with new accessors created by following patch.
MozReview-Commit-ID: 2oyS5tPeQcg
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -30,16 +30,17 @@
#include "mozInlineSpellChecker.h" // for mozInlineSpellChecker
#include "mozilla/CheckedInt.h" // for CheckedInt
#include "mozilla/EditAction.h" // for EditAction
#include "mozilla/EditorDOMPoint.h" // for EditorDOMPoint
#include "mozilla/EditorUtils.h" // for AutoRules, etc.
#include "mozilla/EditTransactionBase.h" // for EditTransactionBase
#include "mozilla/FlushType.h" // for FlushType::Frames
#include "mozilla/IMEStateManager.h" // for IMEStateManager
+#include "mozilla/mozInlineSpellChecker.h" // for mozInlineSpellChecker
#include "mozilla/Preferences.h" // for Preferences
#include "mozilla/RangeBoundary.h" // for RawRangeBoundary, RangeBoundary
#include "mozilla/dom/Selection.h" // for Selection, etc.
#include "mozilla/Services.h" // for GetObserverService
#include "mozilla/TextComposition.h" // for TextComposition
#include "mozilla/TextEvents.h"
#include "mozilla/dom/Element.h" // for Element, nsINode::AsElement
#include "mozilla/dom/HTMLBodyElement.h"
@@ -1362,18 +1363,17 @@ EditorBase::GetInlineSpellChecker(bool a
bool canSpell = mozInlineSpellChecker::CanEnableInlineSpellChecking();
if (!canSpell) {
*aInlineSpellChecker = nullptr;
return NS_ERROR_FAILURE;
}
nsresult rv;
if (!mInlineSpellChecker && autoCreate) {
- mInlineSpellChecker = do_CreateInstance(MOZ_INLINESPELLCHECKER_CONTRACTID, &rv);
- NS_ENSURE_SUCCESS(rv, rv);
+ mInlineSpellChecker = new mozInlineSpellChecker();
}
if (mInlineSpellChecker) {
rv = mInlineSpellChecker->Init(this);
if (NS_FAILED(rv)) {
mInlineSpellChecker = nullptr;
}
NS_ENSURE_SUCCESS(rv, rv);
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -29,27 +29,27 @@
#include "nsISupportsImpl.h" // for EditorBase::Release, etc.
#include "nsIWeakReferenceUtils.h" // for nsWeakPtr
#include "nsLiteralString.h" // for NS_LITERAL_STRING
#include "nsString.h" // for nsCString
#include "nsTArray.h" // for nsTArray and nsAutoTArray
#include "nsWeakReference.h" // for nsSupportsWeakReference
#include "nscore.h" // for nsresult, nsAString, etc.
+class mozInlineSpellChecker;
class nsAtom;
class nsIContent;
class nsIDOMDocument;
class nsIDOMEvent;
class nsIDOMEventListener;
class nsIDOMEventTarget;
class nsIDOMNode;
class nsIDocumentStateListener;
class nsIEditActionListener;
class nsIEditorObserver;
-class nsIInlineSpellChecker;
class nsINode;
class nsIPresShell;
class nsISupports;
class nsITransaction;
class nsIWidget;
class nsRange;
class nsTransactionManager;
@@ -1379,17 +1379,17 @@ protected:
eTriUnset,
eTriFalse,
eTriTrue
};
// MIME type of the doc we are editing.
nsCString mContentMIMEType;
- nsCOMPtr<nsIInlineSpellChecker> mInlineSpellChecker;
+ RefPtr<mozInlineSpellChecker> mInlineSpellChecker;
RefPtr<nsTransactionManager> mTxnMgr;
// Cached root node.
nsCOMPtr<Element> mRootElement;
// The form field as an event receiver.
nsCOMPtr<dom::EventTarget> mEventTarget;
nsCOMPtr<nsIDOMEventListener> mEventListener;
// Strong reference to placeholder for begin/end batch purposes.
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -4,16 +4,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/HTMLEditor.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/EditAction.h"
#include "mozilla/EditorDOMPoint.h"
#include "mozilla/EventStates.h"
+#include "mozilla/mozInlineSpellChecker.h"
#include "mozilla/TextEvents.h"
#include "nsCRT.h"
#include "nsUnicharUtils.h"
#include "HTMLEditorEventListener.h"
#include "HTMLEditRules.h"
--- a/extensions/spellcheck/src/moz.build
+++ b/extensions/spellcheck/src/moz.build
@@ -22,13 +22,14 @@ if CONFIG['MOZ_SYSTEM_HUNSPELL']:
else:
LOCAL_INCLUDES += ['../hunspell/src']
LOCAL_INCLUDES += [
'../hunspell/glue',
'/dom/base',
]
EXPORTS.mozilla += [
+ 'mozInlineSpellChecker.h',
'mozSpellChecker.h',
]
if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
CXXFLAGS += ['-Wno-error=shadow']
--- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp
@@ -37,16 +37,17 @@
#include "mozilla/EditAction.h"
#include "mozilla/EditorSpellCheck.h"
#include "mozilla/EditorUtils.h"
#include "mozilla/Services.h"
#include "mozilla/TextEditor.h"
#include "mozilla/dom/Selection.h"
#include "mozInlineSpellWordUtil.h"
#include "mozISpellI18NManager.h"
+#include "mozISpellI18NUtil.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsIDOMNode.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMKeyEvent.h"
@@ -1867,55 +1868,59 @@ mozInlineSpellChecker::HandleNavigationE
if (shouldPost) {
rv = ScheduleSpellCheck(Move(status));
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
-NS_IMETHODIMP mozInlineSpellChecker::HandleEvent(nsIDOMEvent* aEvent)
+NS_IMETHODIMP
+mozInlineSpellChecker::HandleEvent(nsIDOMEvent* aEvent)
{
nsAutoString eventType;
aEvent->GetType(eventType);
if (eventType.EqualsLiteral("blur")) {
- return Blur(aEvent);
+ return OnBlur(aEvent);
}
if (eventType.EqualsLiteral("click")) {
- return MouseClick(aEvent);
+ return OnMouseClick(aEvent);
}
if (eventType.EqualsLiteral("keypress")) {
- return KeyPress(aEvent);
+ return OnKeyPress(aEvent);
}
return NS_OK;
}
-nsresult mozInlineSpellChecker::Blur(nsIDOMEvent* aEvent)
+nsresult
+mozInlineSpellChecker::OnBlur(nsIDOMEvent* aEvent)
{
// force spellcheck on blur, for instance when tabbing out of a textbox
HandleNavigationEvent(true);
return NS_OK;
}
-nsresult mozInlineSpellChecker::MouseClick(nsIDOMEvent *aMouseEvent)
+nsresult
+mozInlineSpellChecker::OnMouseClick(nsIDOMEvent *aMouseEvent)
{
nsCOMPtr<nsIDOMMouseEvent>mouseEvent = do_QueryInterface(aMouseEvent);
NS_ENSURE_TRUE(mouseEvent, NS_OK);
// ignore any errors from HandleNavigationEvent as we don't want to prevent
// anyone else from seeing this event.
int16_t button;
mouseEvent->GetButton(&button);
HandleNavigationEvent(button != 0);
return NS_OK;
}
-nsresult mozInlineSpellChecker::KeyPress(nsIDOMEvent* aKeyEvent)
+nsresult
+mozInlineSpellChecker::OnKeyPress(nsIDOMEvent* aKeyEvent)
{
nsCOMPtr<nsIDOMKeyEvent>keyEvent = do_QueryInterface(aKeyEvent);
NS_ENSURE_TRUE(keyEvent, NS_OK);
uint32_t keyCode;
keyEvent->GetKeyCode(&keyCode);
// we only care about navigation keys that moved selection
--- a/extensions/spellcheck/src/mozInlineSpellChecker.h
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.h
@@ -1,43 +1,35 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef __mozinlinespellchecker_h__
-#define __mozinlinespellchecker_h__
-
-#include "mozilla/TextEditor.h"
-
-#include "mozISpellI18NUtil.h"
+#ifndef mozilla_mozInlineSpellChecker_h
+#define mozilla_mozInlineSpellChecker_h
#include "nsCycleCollectionParticipant.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMTreeWalker.h"
#include "nsIEditActionListener.h"
#include "nsIEditorSpellCheck.h"
#include "nsIInlineSpellChecker.h"
#include "nsRange.h"
#include "nsWeakReference.h"
-// X.h defines KeyPress
-#ifdef KeyPress
-#undef KeyPress
-#endif
-
+class InitEditorSpellCheckCallback;
class mozInlineSpellWordUtil;
class mozInlineSpellChecker;
+class mozISpellI18NUtil;
class mozInlineSpellResume;
-class InitEditorSpellCheckCallback;
class UpdateCurrentDictionaryCallback;
-class mozInlineSpellResume;
namespace mozilla {
class EditorSpellCheck;
+class TextEditor;
enum class EditAction : int32_t;
} // namespace mozilla
class mozInlineSpellStatus
{
public:
explicit mozInlineSpellStatus(mozInlineSpellChecker* aSpellChecker);
@@ -192,19 +184,19 @@ public:
NS_DECL_NSIDOMEVENTLISTENER
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(mozInlineSpellChecker, nsIDOMEventListener)
// returns true if there are any spell checking dictionaries available
static bool CanEnableInlineSpellChecking();
// update the cached value whenever the list of available dictionaries changes
static void UpdateCanEnableInlineSpellChecking();
- nsresult Blur(nsIDOMEvent* aEvent);
- nsresult MouseClick(nsIDOMEvent* aMouseEvent);
- nsresult KeyPress(nsIDOMEvent* aKeyEvent);
+ nsresult OnBlur(nsIDOMEvent* aEvent);
+ nsresult OnMouseClick(nsIDOMEvent* aMouseEvent);
+ nsresult OnKeyPress(nsIDOMEvent* aKeyEvent);
mozInlineSpellChecker();
// spell checks all of the words between two nodes
nsresult SpellCheckBetweenNodes(nsIDOMNode *aStartNode,
int32_t aStartOffset,
nsIDOMNode *aEndNode,
int32_t aEndOffset);
@@ -265,9 +257,9 @@ protected:
// track the number of pending spell checks and async operations that may lead
// to spell checks, notifying observers accordingly
void ChangeNumPendingSpellChecks(int32_t aDelta,
mozilla::TextEditor* aTextEditor = nullptr);
void NotifyObservers(const char* aTopic, mozilla::TextEditor* aTextEditor);
};
-#endif /* __mozinlinespellchecker_h__ */
+#endif // #ifndef mozilla_mozInlineSpellChecker_h