--- a/editor/composer/nsEditorSpellCheck.cpp
+++ b/editor/composer/nsEditorSpellCheck.cpp
@@ -26,17 +26,16 @@
#include "nsIDocument.h" // for nsIDocument
#include "nsIEditor.h" // for nsIEditor
#include "nsIHTMLEditor.h" // for nsIHTMLEditor
#include "nsILoadContext.h"
#include "nsISelection.h" // for nsISelection
#include "nsISpellChecker.h" // for nsISpellChecker, etc
#include "nsISupportsBase.h" // for nsISupports
#include "nsISupportsUtils.h" // for NS_ADDREF
-#include "nsITextServicesDocument.h" // for nsITextServicesDocument
#include "nsITextServicesFilter.h" // for nsITextServicesFilter
#include "nsIURI.h" // for nsIURI
#include "nsThreadUtils.h" // for GetMainThreadSerialEventTarget
#include "nsVariant.h" // for nsIWritableVariant, etc
#include "nsLiteralString.h" // for NS_LITERAL_STRING, etc
#include "nsMemory.h" // for nsMemory
#include "nsRange.h"
#include "nsReadableUtils.h" // for ToNewUnicode, EmptyString, etc
--- a/editor/txtsvc/TextServicesDocument.cpp
+++ b/editor/txtsvc/TextServicesDocument.cpp
@@ -90,33 +90,32 @@ TextServicesDocument::~TextServicesDocum
{
ClearOffsetTable(&mOffsetTable);
}
NS_IMPL_CYCLE_COLLECTING_ADDREF(TextServicesDocument)
NS_IMPL_CYCLE_COLLECTING_RELEASE(TextServicesDocument)
NS_INTERFACE_MAP_BEGIN(TextServicesDocument)
- NS_INTERFACE_MAP_ENTRY(nsITextServicesDocument)
NS_INTERFACE_MAP_ENTRY(nsIEditActionListener)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITextServicesDocument)
+ NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditActionListener)
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(TextServicesDocument)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION(TextServicesDocument,
mDOMDocument,
mSelCon,
mTextEditor,
mIterator,
mPrevTextBlock,
mNextTextBlock,
mExtent,
mTxtSvcFilter)
-NS_IMETHODIMP
+nsresult
TextServicesDocument::InitWithEditor(nsIEditor* aEditor)
{
nsCOMPtr<nsISelectionController> selCon;
nsCOMPtr<nsIDOMDocument> doc;
NS_ENSURE_TRUE(aEditor, NS_ERROR_NULL_POINTER);
LOCK_DOC(this);
@@ -179,31 +178,31 @@ TextServicesDocument::InitWithEditor(nsI
rv = aEditor->AddEditActionListener(this);
UNLOCK_DOC(this);
return rv;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::GetDocument(nsIDOMDocument** aDoc)
{
NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
*aDoc = nullptr; // init out param
NS_ENSURE_TRUE(mDOMDocument, NS_ERROR_NOT_INITIALIZED);
*aDoc = mDOMDocument;
NS_ADDREF(*aDoc);
return NS_OK;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::SetExtent(nsRange* aRange)
{
NS_ENSURE_ARG_POINTER(aRange);
NS_ENSURE_TRUE(mDOMDocument, NS_ERROR_FAILURE);
LOCK_DOC(this);
// We need to store a copy of aDOMRange since we don't
@@ -227,17 +226,17 @@ TextServicesDocument::SetExtent(nsRange*
rv = FirstBlock();
UNLOCK_DOC(this);
return rv;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::ExpandRangeToWordBoundaries(nsRange* aRange)
{
NS_ENSURE_ARG_POINTER(aRange);
// Get the end points of the range.
nsCOMPtr<nsINode> rngStartNode, rngEndNode;
int32_t rngStartOffset, rngEndOffset;
@@ -380,26 +379,26 @@ TextServicesDocument::ExpandRangeToWordB
rv = aRange->SetStartAndEnd(rngStartNode, rngStartOffset,
rngEndNode, rngEndOffset);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::SetFilter(nsITextServicesFilter* aFilter)
{
// Hang on to the filter so we can set it into the filtered iterator.
mTxtSvcFilter = aFilter;
return NS_OK;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::GetCurrentTextBlock(nsString *aStr)
{
NS_ENSURE_TRUE(aStr, NS_ERROR_NULL_POINTER);
aStr->Truncate();
NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
@@ -408,17 +407,17 @@ TextServicesDocument::GetCurrentTextBloc
nsresult rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
mExtent, aStr);
UNLOCK_DOC(this);
return rv;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::FirstBlock()
{
NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
LOCK_DOC(this);
nsresult rv = FirstTextNode(mIterator, &mIteratorStatus);
@@ -441,28 +440,28 @@ TextServicesDocument::FirstBlock()
}
UNLOCK_DOC(this);
// XXX Result of FirstTextNode() or GetFirstTextNodeInNextBlock().
return rv;
}
-NS_IMETHODIMP
-TextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus* aSelStatus,
+nsresult
+TextServicesDocument::LastSelectedBlock(BlockSelectionStatus* aSelStatus,
int32_t* aSelOffset,
int32_t* aSelLength)
{
NS_ENSURE_TRUE(aSelStatus && aSelOffset && aSelLength, NS_ERROR_NULL_POINTER);
LOCK_DOC(this);
mIteratorStatus = IteratorStatus::eDone;
- *aSelStatus = nsITextServicesDocument::eBlockNotFound;
+ *aSelStatus = BlockSelectionStatus::eBlockNotFound;
*aSelOffset = *aSelLength = -1;
if (!mSelCon || !mIterator) {
UNLOCK_DOC(this);
return NS_ERROR_FAILURE;
}
RefPtr<Selection> selection =
@@ -527,17 +526,17 @@ TextServicesDocument::LastSelectedBlock(
rv = GetSelection(aSelStatus, aSelOffset, aSelLength);
if (NS_FAILED(rv)) {
UNLOCK_DOC(this);
return rv;
}
- if (*aSelStatus == nsITextServicesDocument::eBlockContains) {
+ if (*aSelStatus == BlockSelectionStatus::eBlockContains) {
rv = SetSelectionInternal(*aSelOffset, *aSelLength, false);
}
} else {
// The caret isn't in a text node. Create an iterator
// based on a range that extends from the current caret
// position to the end of the document, then walk forwards
// till you find a text node, then find the beginning of it's block.
@@ -786,17 +785,17 @@ TextServicesDocument::LastSelectedBlock(
// If we get here, we didn't find any block before or inside
// the selection! Just return OK.
UNLOCK_DOC(this);
return NS_OK;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::PrevBlock()
{
NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
LOCK_DOC(this);
if (mIteratorStatus == IteratorStatus::eDone) {
return NS_OK;
@@ -850,17 +849,17 @@ TextServicesDocument::PrevBlock()
}
UNLOCK_DOC(this);
// XXX The result of GetFirstTextNodeInNextBlock() or NS_OK.
return rv;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::NextBlock()
{
NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
LOCK_DOC(this);
if (mIteratorStatus == IteratorStatus::eDone) {
return NS_OK;
@@ -921,17 +920,17 @@ TextServicesDocument::NextBlock()
}
UNLOCK_DOC(this);
// The result of GetFirstTextNodeInNextBlock() or NS_OK.
return rv;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::IsDone(bool* aIsDone)
{
NS_ENSURE_TRUE(aIsDone, NS_ERROR_NULL_POINTER);
*aIsDone = false;
NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
@@ -939,17 +938,17 @@ TextServicesDocument::IsDone(bool* aIsDo
*aIsDone = mIteratorStatus == IteratorStatus::eDone;
UNLOCK_DOC(this);
return NS_OK;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::SetSelection(int32_t aOffset,
int32_t aLength)
{
NS_ENSURE_TRUE(mSelCon && aOffset >= 0 && aLength >= 0, NS_ERROR_FAILURE);
LOCK_DOC(this);
nsresult rv = SetSelectionInternal(aOffset, aLength, true);
@@ -958,17 +957,17 @@ TextServicesDocument::SetSelection(int32
//**** KDEBUG ****
// printf("\n * Sel: (%2d, %4d) (%2d, %4d)\n", mSelStartIndex, mSelStartOffset, mSelEndIndex, mSelEndOffset);
//**** KDEBUG ****
return rv;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::ScrollSelectionIntoView()
{
NS_ENSURE_TRUE(mSelCon, NS_ERROR_FAILURE);
LOCK_DOC(this);
// After ScrollSelectionIntoView(), the pending notifications might be flushed
// and PresShell/PresContext/Frames may be dead. See bug 418470.
@@ -978,17 +977,17 @@ TextServicesDocument::ScrollSelectionInt
nsISelectionController::SELECTION_FOCUS_REGION,
nsISelectionController::SCROLL_SYNCHRONOUS);
UNLOCK_DOC(this);
return rv;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::DeleteSelection()
{
if (NS_WARN_IF(!mTextEditor) || NS_WARN_IF(!SelectionIsValid())) {
return NS_ERROR_FAILURE;
}
if (SelectionIsCollapsed()) {
return NS_OK;
@@ -1237,17 +1236,17 @@ TextServicesDocument::DeleteSelection()
// PrintOffsetTable();
//**** KDEBUG ****
UNLOCK_DOC(this);
return rv;
}
-NS_IMETHODIMP
+nsresult
TextServicesDocument::InsertText(const nsString* aText)
{
if (NS_WARN_IF(!aText)) {
return NS_ERROR_INVALID_ARG;
}
if (NS_WARN_IF(!mTextEditor) || NS_WARN_IF(!SelectionIsValid())) {
return NS_ERROR_FAILURE;
@@ -2144,23 +2143,23 @@ TextServicesDocument::SetSelectionIntern
//**** KDEBUG ****
// printf("\n * Sel: (%2d, %4d) (%2d, %4d)\n", mSelStartIndex, mSelStartOffset, mSelEndIndex, mSelEndOffset);
//**** KDEBUG ****
return NS_OK;
}
nsresult
-TextServicesDocument::GetSelection(TSDBlockSelectionStatus* aSelStatus,
+TextServicesDocument::GetSelection(BlockSelectionStatus* aSelStatus,
int32_t* aSelOffset,
int32_t* aSelLength)
{
NS_ENSURE_TRUE(aSelStatus && aSelOffset && aSelLength, NS_ERROR_NULL_POINTER);
- *aSelStatus = nsITextServicesDocument::eBlockNotFound;
+ *aSelStatus = BlockSelectionStatus::eBlockNotFound;
*aSelOffset = -1;
*aSelLength = -1;
NS_ENSURE_TRUE(mDOMDocument && mSelCon, NS_ERROR_FAILURE);
if (mIteratorStatus == IteratorStatus::eDone) {
return NS_OK;
}
@@ -2183,32 +2182,32 @@ TextServicesDocument::GetSelection(TSDBl
// UNLOCK_DOC(this);
// XXX The result of GetCollapsedSelection() or GetUncollapsedSelection().
return rv;
}
nsresult
-TextServicesDocument::GetCollapsedSelection(TSDBlockSelectionStatus* aSelStatus,
+TextServicesDocument::GetCollapsedSelection(BlockSelectionStatus* aSelStatus,
int32_t* aSelOffset,
int32_t* aSelLength)
{
nsCOMPtr<nsISelection> domSelection;
nsresult rv =
mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
getter_AddRefs(domSelection));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(domSelection, NS_ERROR_FAILURE);
RefPtr<Selection> selection = domSelection->AsSelection();
// The calling function should have done the GetIsCollapsed()
// check already. Just assume it's collapsed!
- *aSelStatus = nsITextServicesDocument::eBlockOutside;
+ *aSelStatus = BlockSelectionStatus::eBlockOutside;
*aSelOffset = *aSelLength = -1;
int32_t tableCount = mOffsetTable.Length();
if (!tableCount) {
return NS_OK;
}
@@ -2253,17 +2252,17 @@ TextServicesDocument::GetCollapsedSelect
for (int32_t i = 0; i < tableCount; i++) {
OffsetEntry* entry = mOffsetTable[i];
NS_ENSURE_TRUE(entry, NS_ERROR_FAILURE);
if (entry->mNode == parent &&
entry->mNodeOffset <= static_cast<int32_t>(offset) &&
static_cast<int32_t>(offset) <= entry->mNodeOffset + entry->mLength) {
- *aSelStatus = nsITextServicesDocument::eBlockContains;
+ *aSelStatus = BlockSelectionStatus::eBlockContains;
*aSelOffset = entry->mStrOffset + (offset - entry->mNodeOffset);
*aSelLength = 0;
return NS_OK;
}
}
// If we get here, we didn't find a text node entry
@@ -2368,17 +2367,17 @@ TextServicesDocument::GetCollapsedSelect
for (int32_t i = 0; i < tableCount; i++) {
OffsetEntry* entry = mOffsetTable[i];
NS_ENSURE_TRUE(entry, NS_ERROR_FAILURE);
if (entry->mNode == node &&
entry->mNodeOffset <= static_cast<int32_t>(offset) &&
static_cast<int32_t>(offset) <= entry->mNodeOffset + entry->mLength) {
- *aSelStatus = nsITextServicesDocument::eBlockContains;
+ *aSelStatus = BlockSelectionStatus::eBlockContains;
*aSelOffset = entry->mStrOffset + (offset - entry->mNodeOffset);
*aSelLength = 0;
// Now move the caret so that it is actually in the text node.
// We do this to keep things in sync.
//
// In most cases, the user shouldn't see any movement in the caret
// on screen.
@@ -2387,17 +2386,17 @@ TextServicesDocument::GetCollapsedSelect
}
}
return NS_ERROR_FAILURE;
}
nsresult
TextServicesDocument::GetUncollapsedSelection(
- TSDBlockSelectionStatus* aSelStatus,
+ BlockSelectionStatus* aSelStatus,
int32_t* aSelOffset,
int32_t* aSelLength)
{
RefPtr<nsRange> range;
OffsetEntry *entry;
nsCOMPtr<nsISelection> domSelection;
nsresult rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
@@ -2460,44 +2459,44 @@ TextServicesDocument::GetUncollapsedSele
if (e1s2 <= 0 && e2s1 >= 0) {
break;
}
}
// We're done if we didn't find an intersecting range.
if (rangeCount < 1 || e1s2 > 0 || e2s1 < 0) {
- *aSelStatus = nsITextServicesDocument::eBlockOutside;
+ *aSelStatus = BlockSelectionStatus::eBlockOutside;
*aSelOffset = *aSelLength = -1;
return NS_OK;
}
// Now that we have an intersecting range, find out more info:
e1s1 = nsContentUtils::ComparePoints(eStart->mNode, eStartOffset,
startContainer, startOffset);
e2s2 = nsContentUtils::ComparePoints(eEnd->mNode, eEndOffset,
endContainer, endOffset);
if (rangeCount > 1) {
// There are multiple selection ranges, we only deal
// with the first one that intersects the current,
// text block, so mark this a as a partial.
- *aSelStatus = nsITextServicesDocument::eBlockPartial;
+ *aSelStatus = BlockSelectionStatus::eBlockPartial;
} else if (e1s1 > 0 && e2s2 < 0) {
// The range extends beyond the start and
// end of the current text block.
- *aSelStatus = nsITextServicesDocument::eBlockInside;
+ *aSelStatus = BlockSelectionStatus::eBlockInside;
} else if (e1s1 <= 0 && e2s2 >= 0) {
// The current text block contains the entire
// range.
- *aSelStatus = nsITextServicesDocument::eBlockContains;
+ *aSelStatus = BlockSelectionStatus::eBlockContains;
} else {
// The range partially intersects the block.
- *aSelStatus = nsITextServicesDocument::eBlockPartial;
+ *aSelStatus = BlockSelectionStatus::eBlockPartial;
}
// Now create a range based on the intersection of the
// text block and range:
nsCOMPtr<nsINode> p1, p2;
int32_t o1, o2;
--- a/editor/txtsvc/TextServicesDocument.h
+++ b/editor/txtsvc/TextServicesDocument.h
@@ -5,47 +5,42 @@
#ifndef mozilla_TextServicesDocument_h
#define mozilla_TextServicesDocument_h
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIEditActionListener.h"
#include "nsISupportsImpl.h"
-#include "nsITextServicesDocument.h"
#include "nsStringFwd.h"
#include "nsTArray.h"
#include "nscore.h"
class nsIContent;
class nsIContentIterator;
class nsIDOMCharacterData;
class nsIDOMDocument;
class nsIDOMNode;
class nsIEditor;
class nsINode;
class nsISelection;
class nsISelectionController;
class nsITextServicesFilter;
-
-// 019718E3-CDB5-11d2-8D3C-000000000000
-#define NS_TEXTSERVICESDOCUMENT_CID \
- { 0x019718e3, 0xcdb5, 0x11d2, \
- { 0x8d, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
+class nsRange;
namespace mozilla {
class OffsetEntry;
class TextEditor;
/**
- * TODO: Explain what this class manages and rename it to better name.
+ * The TextServicesDocument presents the document in as a bunch of flattened
+ * text blocks. Each text block can be retrieved as an nsString.
*/
-class TextServicesDocument final : public nsITextServicesDocument
- , public nsIEditActionListener
+class TextServicesDocument final : public nsIEditActionListener
{
private:
enum class IteratorStatus : uint8_t
{
// No iterator (I), or iterator doesn't point to anything valid.
eDone = 0,
// I points to first text node (TN) in current block (CB).
eValid,
@@ -74,37 +69,159 @@ private:
protected:
virtual ~TextServicesDocument();
public:
TextServicesDocument();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
- NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(TextServicesDocument,
- nsITextServicesDocument)
+ NS_DECL_CYCLE_COLLECTION_CLASS(TextServicesDocument)
+
+ /**
+ * Initializes the text services document to use a particular editor. The
+ * text services document will use the DOM document and presentation shell
+ * used by the editor.
+ *
+ * @param aEditor The editor to use.
+ */
+ nsresult InitWithEditor(nsIEditor* aEditor);
+
+ /**
+ * Get the DOM document for the document in use.
+ *
+ * @return aDOMDocument The dom document.
+ */
+ nsresult GetDocument(nsIDOMDocument** aDOMDocument);
+
+ /**
+ * Sets the range/extent over which the text services document will iterate.
+ * Note that InitWithEditor() should have been called prior to calling this
+ * method. If this method is never called, the text services defaults to
+ * iterating over the entire document.
+ *
+ * @param aDOMRange The range to use. aDOMRange must point to a
+ * valid range object.
+ */
+ nsresult SetExtent(nsRange* aRange);
+
+ /**
+ * Expands the end points of the range so that it spans complete words. This
+ * call does not change any internal state of the text services document.
+ *
+ * @param aDOMRange The range to be expanded/adjusted.
+ */
+ nsresult ExpandRangeToWordBoundaries(nsRange* aRange);
+
+ /**
+ * Sets the filter to be used while iterating over content.
+ *
+ * @param aFilter The filter to be used while iterating over
+ * content.
+ */
+ nsresult SetFilter(nsITextServicesFilter* aFilter);
+
+ /**
+ * Returns the text in the current text block.
+ *
+ * @param aStr [OUT] This will contain the text.
+ */
+ nsresult GetCurrentTextBlock(nsString* aStr);
+
+ /**
+ * Tells the document to point to the first text block in the document. This
+ * method does not adjust the current cursor position or selection.
+ */
+ nsresult FirstBlock();
+
+ enum class BlockSelectionStatus
+ {
+ // There is no text block (TB) in or before the selection (S).
+ eBlockNotFound = 0,
+ // No TB in S, but found one before/after S.
+ eBlockOutside,
+ // S extends beyond the start and end of TB.
+ eBlockInside,
+ // TB contains entire S.
+ eBlockContains,
+ // S begins or ends in TB but extends outside of TB.
+ eBlockPartial,
+ };
- /* nsITextServicesDocument method implementations. */
- NS_IMETHOD InitWithEditor(nsIEditor* aEditor) override;
- NS_IMETHOD GetDocument(nsIDOMDocument** aDoc) override;
- NS_IMETHOD SetExtent(nsRange* aRange) override;
- NS_IMETHOD ExpandRangeToWordBoundaries(nsRange* aRange) override;
- NS_IMETHOD SetFilter(nsITextServicesFilter* aFilter) override;
- NS_IMETHOD GetCurrentTextBlock(nsString* aStr) override;
- NS_IMETHOD FirstBlock() override;
- NS_IMETHOD LastSelectedBlock(TSDBlockSelectionStatus* aSelStatus,
- int32_t* aSelOffset,
- int32_t* aSelLength) override;
- NS_IMETHOD PrevBlock() override;
- NS_IMETHOD NextBlock() override;
- NS_IMETHOD IsDone(bool* aIsDone) override;
- NS_IMETHOD SetSelection(int32_t aOffset, int32_t aLength) override;
- NS_IMETHOD ScrollSelectionIntoView() override;
- NS_IMETHOD DeleteSelection() override;
- NS_IMETHOD InsertText(const nsString* aText) override;
+ /**
+ * Tells the document to point to the last text block that contains the
+ * current selection or caret.
+ *
+ * @param aSelectionStatus [OUT] This will contain the text block
+ * selection status.
+ * @param aSelectionOffset [OUT] This will contain the offset into the
+ * string returned by GetCurrentTextBlock() where
+ * the selection begins.
+ * @param aLength [OUT] This will contain the number of
+ * characters that are selected in the string.
+ */
+ nsresult LastSelectedBlock(BlockSelectionStatus* aSelStatus,
+ int32_t* aSelOffset,
+ int32_t* aSelLength);
+
+ /**
+ * Tells the document to point to the text block before the current one.
+ * This method will return NS_OK, even if there is no previous block.
+ * Callers should call IsDone() to check if we have gone beyond the first
+ * text block in the document.
+ */
+ nsresult PrevBlock();
+
+ /**
+ * Tells the document to point to the text block after the current one.
+ * This method will return NS_OK, even if there is no next block. Callers
+ * should call IsDone() to check if we have gone beyond the last text block
+ * in the document.
+ */
+ nsresult NextBlock();
+
+ /**
+ * IsDone() will always set aIsDone == false unless the document contains
+ * no text, PrevBlock() was called while the document was already pointing
+ * to the first text block in the document, or NextBlock() was called while
+ * the document was already pointing to the last text block in the document.
+ *
+ * @param aIsDone [OUT] This will contain the result.
+ */
+ nsresult IsDone(bool* aIsDone);
+
+ /**
+ * SetSelection() allows the caller to set the selection based on an offset
+ * into the string returned by GetCurrentTextBlock(). A length of zero
+ * places the cursor at that offset. A positive non-zero length "n" selects
+ * n characters in the string.
+ *
+ * @param aOffset Offset into string returned by
+ * GetCurrentTextBlock().
+ * @param aLength Number of characters selected.
+ */
+ nsresult SetSelection(int32_t aOffset, int32_t aLength);
+
+ /**
+ * Scrolls the document so that the current selection is visible.
+ */
+ nsresult ScrollSelectionIntoView();
+
+ /**
+ * Deletes the text selected by SetSelection(). Calling DeleteSelection()
+ * with nothing selected, or with a collapsed selection (cursor) does
+ * nothing and returns NS_OK.
+ */
+ nsresult DeleteSelection();
+
+ /**
+ * Inserts the given text at the current cursor position. If there is a
+ * selection, it will be deleted before the text is inserted.
+ */
+ nsresult InsertText(const nsString* aText);
/* nsIEditActionListener method implementations. */
NS_DECL_NSIEDITACTIONLISTENER
static nsresult GetRangeEndPoints(nsRange* aRange,
nsINode** aStartContainer,
int32_t* aStartOffset,
nsINode** aEndContainer,
@@ -143,21 +260,21 @@ private:
static bool DidSkip(nsIContentIterator* aFilteredIter);
static void ClearDidSkip(nsIContentIterator* aFilteredIter);
static bool HasSameBlockNodeParent(nsIContent* aContent1,
nsIContent* aContent2);
nsresult SetSelectionInternal(int32_t aOffset, int32_t aLength,
bool aDoUpdate);
- nsresult GetSelection(TSDBlockSelectionStatus* aSelStatus,
+ nsresult GetSelection(BlockSelectionStatus* aSelStatus,
int32_t* aSelOffset, int32_t* aSelLength);
- nsresult GetCollapsedSelection(TSDBlockSelectionStatus* aSelStatus,
+ nsresult GetCollapsedSelection(BlockSelectionStatus* aSelStatus,
int32_t* aSelOffset, int32_t* aSelLength);
- nsresult GetUncollapsedSelection(TSDBlockSelectionStatus* aSelStatus,
+ nsresult GetUncollapsedSelection(BlockSelectionStatus* aSelStatus,
int32_t* aSelOffset, int32_t* aSelLength);
bool SelectionIsCollapsed();
bool SelectionIsValid();
static nsresult CreateOffsetTable(nsTArray<OffsetEntry*>* aOffsetTable,
nsIContentIterator* aIterator,
IteratorStatus* aIteratorStatus,
--- a/editor/txtsvc/moz.build
+++ b/editor/txtsvc/moz.build
@@ -8,18 +8,16 @@ XPIDL_SOURCES += [
'nsIInlineSpellChecker.idl',
'nsITextServicesFilter.idl',
]
XPIDL_MODULE = 'txtsvc'
EXPORTS += [
'nsISpellChecker.h',
- 'nsITextService.h',
- 'nsITextServicesDocument.h',
]
EXPORTS.mozilla += [
'TextServicesDocument.h',
]
UNIFIED_SOURCES += [
'nsFilteredContentIterator.cpp',
deleted file mode 100644
--- a/editor/txtsvc/nsITextService.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- 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 nsITextService_h__
-#define nsITextService_h__
-
-#include "nsISupports.h"
-
-class nsITextServicesDocument;
-
-/*
-TextService interface to outside world
-*/
-
-#define NS_ITEXTSERVICE_IID \
-{ /* 019718E0-CDB5-11d2-8D3C-000000000000 */ \
-0x019718e0, 0xcdb5, 0x11d2, \
-{ 0x8d, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
-
-
-/**
- *
- */
-class nsITextService : public nsISupports{
-public:
-
- NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEXTSERVICE_IID)
-
- /**
- *
- */
- NS_IMETHOD Init(nsITextServicesDocument *aDoc) = 0;
- NS_IMETHOD Execute() = 0;
- NS_IMETHOD GetMenuString(nsString &aString) = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsITextService, NS_ITEXTSERVICE_IID)
-
-#endif // nsITextService_h__
-
deleted file mode 100644
--- a/editor/txtsvc/nsITextServicesDocument.h
+++ /dev/null
@@ -1,185 +0,0 @@
-/* -*- 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 nsITextServicesDocument_h__
-#define nsITextServicesDocument_h__
-
-#include "nsISupports.h"
-#include "nsStringFwd.h"
-
-class nsIDOMDocument;
-class nsIEditor;
-class nsITextServicesFilter;
-class nsRange;
-
-/*
-TextServicesDocument interface to outside world
-*/
-
-#define NS_ITEXTSERVICESDOCUMENT_IID \
-{ /* 019718E1-CDB5-11d2-8D3C-000000000000 */ \
-0x019718e1, 0xcdb5, 0x11d2, \
-{ 0x8d, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
-
-
-/**
- * The nsITextServicesDocument presents the document in as a
- * bunch of flattened text blocks. Each text block can be retrieved
- * as an nsString (array of characters).
- */
-class nsITextServicesDocument : public nsISupports{
-public:
-
- NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEXTSERVICESDOCUMENT_IID)
-
- typedef enum { eDSNormal=0, eDSUndlerline } TSDDisplayStyle;
-
- typedef enum { eBlockNotFound=0, // There is no text block (TB) in or before the selection (S).
- eBlockOutside, // No TB in S, but found one before/after S.
- eBlockInside, // S extends beyond the start and end of TB.
- eBlockContains, // TB contains entire S.
- eBlockPartial // S begins or ends in TB but extends outside of TB.
- } TSDBlockSelectionStatus;
-
- /**
- * Get the DOM document for the document in use.
- * @return aDocument the dom document [OUT]
- */
- NS_IMETHOD GetDocument(nsIDOMDocument **aDocument) = 0;
-
- /**
- * Initializes the text services document to use a particular
- * editor. The text services document will use the DOM document
- * and presentation shell used by the editor.
- * @param aEditor is the editor to use. The editor is AddRef'd
- * by this method.
- */
- NS_IMETHOD InitWithEditor(nsIEditor *aEditor) = 0;
-
- /**
- * Sets the range/extent over which the text services document
- * will iterate. Note that InitWithEditor() should have been called prior to
- * calling this method. If this method is never called, the text services
- * defaults to iterating over the entire document.
- *
- * @param aDOMRange is the range to use. aDOMRange must point to a
- * valid range object.
- */
- NS_IMETHOD SetExtent(nsRange* aDOMRange) = 0;
-
- /**
- * Expands the end points of the range so that it spans complete words.
- * This call does not change any internal state of the text services document.
- *
- * @param aDOMRange the range to be expanded/adjusted.
- */
- NS_IMETHOD ExpandRangeToWordBoundaries(nsRange* aRange) = 0;
-
- /**
- * Sets the filter to be used while iterating over content.
- * @param aFilter filter to be used while iterating over content.
- */
- NS_IMETHOD SetFilter(nsITextServicesFilter *aFilter) = 0;
-
- /**
- * Returns the text in the current text block.
- * @param aStr will contain the text.
- */
-
- NS_IMETHOD GetCurrentTextBlock(nsString *aStr) = 0;
-
- /**
- * Tells the document to point to the first text block
- * in the document. This method does not adjust the current
- * cursor position or selection.
- */
-
- NS_IMETHOD FirstBlock() = 0;
-
- /**
- * Tells the document to point to the last text block that
- * contains the current selection or caret.
- * @param aSelectionStatus will contain the text block selection status
- * @param aSelectionOffset will contain the offset into the
- * string returned by GetCurrentTextBlock() where the selection
- * begins.
- * @param aLength will contain the number of characters that are
- * selected in the string.
- */
-
- NS_IMETHOD LastSelectedBlock(TSDBlockSelectionStatus *aSelectionStatus, int32_t *aSelectionOffset, int32_t *aSelectionLength) = 0;
-
- /**
- * Tells the document to point to the text block before
- * the current one. This method will return NS_OK, even
- * if there is no previous block. Callers should call IsDone()
- * to check if we have gone beyond the first text block in
- * the document.
- */
-
- NS_IMETHOD PrevBlock() = 0;
-
- /**
- * Tells the document to point to the text block after
- * the current one. This method will return NS_OK, even
- * if there is no next block. Callers should call IsDone()
- * to check if we have gone beyond the last text block
- * in the document.
- */
-
- NS_IMETHOD NextBlock() = 0;
-
- /**
- * IsDone() will always set aIsDone == false unless
- * the document contains no text, PrevBlock() was called
- * while the document was already pointing to the first
- * text block in the document, or NextBlock() was called
- * while the document was already pointing to the last
- * text block in the document.
- * @param aIsDone will contain the result.
- */
-
- NS_IMETHOD IsDone(bool *aIsDone) = 0;
-
- /**
- * SetSelection() allows the caller to set the selection
- * based on an offset into the string returned by
- * GetCurrentTextBlock(). A length of zero places the cursor
- * at that offset. A positive non-zero length "n" selects
- * n characters in the string.
- * @param aOffset offset into string returned by GetCurrentTextBlock().
- * @param aLength number characters selected.
- */
-
- NS_IMETHOD SetSelection(int32_t aOffset, int32_t aLength) = 0;
-
- /**
- * Scrolls the document so that the current selection is visible.
- */
-
- NS_IMETHOD ScrollSelectionIntoView() = 0;
-
- /**
- * Deletes the text selected by SetSelection(). Calling
- * DeleteSelection with nothing selected, or with a collapsed
- * selection (cursor) does nothing and returns NS_OK.
- */
-
- NS_IMETHOD DeleteSelection() = 0;
-
- /**
- * Inserts the given text at the current cursor position.
- * If there is a selection, it will be deleted before the
- * text is inserted.
- */
-
- NS_IMETHOD InsertText(const nsString *aText) = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsITextServicesDocument,
- NS_ITEXTSERVICESDOCUMENT_IID)
-
-#endif // nsITextServicesDocument_h__
-
deleted file mode 100644
--- a/editor/txtsvc/nsTextServicesFactory.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* 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/. */
-
-#include "nsIGenericFactory.h"
-
-#include "nsTextServicesDocument.h"
-#include "nsTextServicesCID.h"
-
-////////////////////////////////////////////////////////////////////////
-// Define the contructor function for the objects
-//
-// NOTE: This creates an instance of objects by using the default constructor
-//
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextServicesDocument)
-
-////////////////////////////////////////////////////////////////////////
-// Define a table of CIDs implemented by this module along with other
-// information like the function to create an instance, contractid, and
-// class name.
-//
-static const nsModuleComponentInfo components[] = {
- { nullptr, NS_TEXTSERVICESDOCUMENT_CID, "@mozilla.org/textservices/textservicesdocument;1", nsTextServicesDocumentConstructor },
-};
-
-////////////////////////////////////////////////////////////////////////
-// Implement the NSGetModule() exported function for your module
-// and the entire implementation of the module object.
-//
-NS_IMPL_NSGETMODULE(nsTextServicesModule, components)
--- a/extensions/spellcheck/src/mozSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozSpellChecker.cpp
@@ -454,45 +454,50 @@ mozSpellChecker::SetCurrentDictionaryFro
return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, __func__);
}
nsresult
mozSpellChecker::SetupDoc(int32_t *outBlockOffset)
{
nsresult rv;
- nsITextServicesDocument::TSDBlockSelectionStatus blockStatus;
+ TextServicesDocument::BlockSelectionStatus blockStatus;
int32_t selOffset;
int32_t selLength;
*outBlockOffset = 0;
if (!mFromStart) {
rv = mTextServicesDocument->LastSelectedBlock(&blockStatus, &selOffset,
&selLength);
- if (NS_SUCCEEDED(rv) && (blockStatus != nsITextServicesDocument::eBlockNotFound))
- {
- switch (blockStatus)
- {
- case nsITextServicesDocument::eBlockOutside: // No TB in S, but found one before/after S.
- case nsITextServicesDocument::eBlockPartial: // S begins or ends in TB but extends outside of TB.
+ if (NS_SUCCEEDED(rv) &&
+ blockStatus !=
+ TextServicesDocument::BlockSelectionStatus::eBlockNotFound) {
+ switch (blockStatus) {
+ // No TB in S, but found one before/after S.
+ case TextServicesDocument::BlockSelectionStatus::eBlockOutside:
+ // S begins or ends in TB but extends outside of TB.
+ case TextServicesDocument::BlockSelectionStatus::eBlockPartial:
// the TS doc points to the block we want.
*outBlockOffset = selOffset + selLength;
break;
- case nsITextServicesDocument::eBlockInside: // S extends beyond the start and end of TB.
+ // S extends beyond the start and end of TB.
+ case TextServicesDocument::BlockSelectionStatus::eBlockInside:
// we want the block after this one.
rv = mTextServicesDocument->NextBlock();
*outBlockOffset = 0;
break;
- case nsITextServicesDocument::eBlockContains: // TB contains entire S.
+ // TB contains entire S.
+ case TextServicesDocument::BlockSelectionStatus::eBlockContains:
*outBlockOffset = selOffset + selLength;
break;
- case nsITextServicesDocument::eBlockNotFound: // There is no text block (TB) in or before the selection (S).
+ // There is no text block (TB) in or before the selection (S).
+ case TextServicesDocument::BlockSelectionStatus::eBlockNotFound:
default:
NS_NOTREACHED("Shouldn't ever get this status");
}
}
// Failed to get last sel block. Just start at beginning
else {
rv = mTextServicesDocument->FirstBlock();
*outBlockOffset = 0;
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -104,18 +104,16 @@ using mozilla::dom::PushNotifier;
#include "AudioChannelAgent.h"
using mozilla::dom::AudioChannelAgent;
// Editor stuff
#include "nsEditorCID.h"
#include "mozilla/EditorController.h" //CID
#include "mozilla/HTMLEditor.h"
-#include "mozilla/TextServicesDocument.h"
-
#include "nsScriptSecurityManager.h"
#include "ContentPrincipal.h"
#include "SystemPrincipal.h"
#include "NullPrincipal.h"
#include "nsNetCID.h"
#if defined(MOZ_WIDGET_ANDROID)
#include "nsHapticFeedback.h"
#endif
@@ -202,18 +200,16 @@ using mozilla::dom::NotificationTelemetr
#define NS_HAPTICFEEDBACK_CID \
{ 0x1f15dbc8, 0xbfaa, 0x45de, \
{ 0x8a, 0x46, 0x08, 0xe2, 0xe2, 0x63, 0x26, 0xb0 } }
NS_GENERIC_FACTORY_CONSTRUCTOR(TextEditor)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParserUtils)
-NS_GENERIC_FACTORY_CONSTRUCTOR(TextServicesDocument)
-
NS_GENERIC_FACTORY_CONSTRUCTOR(HTMLEditor)
// Transformiix
/* 5d5d92cd-6bf8-11d9-bf4a-000a95dc234c */
#define TRANSFORMIIX_NODESET_CID \
{ 0x5d5d92cd, 0x6bf8, 0x11d9, { 0xbf, 0x4a, 0x0, 0x0a, 0x95, 0xdc, 0x23, 0x4c } }
#define TRANSFORMIIX_NODESET_CONTRACTID \
@@ -622,17 +618,16 @@ NS_DEFINE_NAMED_CID(NOTIFICATIONTELEMETR
NS_DEFINE_NAMED_CID(PUSHNOTIFIER_CID);
NS_DEFINE_NAMED_CID(WORKERDEBUGGERMANAGER_CID);
NS_DEFINE_NAMED_CID(NS_AUDIOCHANNELAGENT_CID);
NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_CID);
NS_DEFINE_NAMED_CID(NS_EDITORCONTROLLER_CID);
NS_DEFINE_NAMED_CID(NS_EDITINGCONTROLLER_CID);
NS_DEFINE_NAMED_CID(NS_EDITORCOMMANDTABLE_CID);
NS_DEFINE_NAMED_CID(NS_EDITINGCOMMANDTABLE_CID);
-NS_DEFINE_NAMED_CID(NS_TEXTSERVICESDOCUMENT_CID);
NS_DEFINE_NAMED_CID(NS_GEOLOCATION_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_GEOLOCATION_CID);
NS_DEFINE_NAMED_CID(NS_AUDIOCHANNEL_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_WEBSOCKETEVENT_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_FOCUSMANAGER_CID);
NS_DEFINE_NAMED_CID(NS_CONTENTSECURITYMANAGER_CID);
NS_DEFINE_NAMED_CID(CSPSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_CSPCONTEXT_CID);
@@ -877,17 +872,16 @@ static const mozilla::Module::CIDEntry k
{ &kPUSHNOTIFIER_CID, false, nullptr, PushNotifierConstructor },
{ &kWORKERDEBUGGERMANAGER_CID, true, nullptr, WorkerDebuggerManagerConstructor },
{ &kNS_AUDIOCHANNELAGENT_CID, true, nullptr, AudioChannelAgentConstructor },
{ &kNS_HTMLEDITOR_CID, false, nullptr, HTMLEditorConstructor },
{ &kNS_EDITORCONTROLLER_CID, false, nullptr, EditorControllerConstructor },
{ &kNS_EDITINGCONTROLLER_CID, false, nullptr, nsEditingControllerConstructor },
{ &kNS_EDITORCOMMANDTABLE_CID, false, nullptr, nsEditorCommandTableConstructor },
{ &kNS_EDITINGCOMMANDTABLE_CID, false, nullptr, nsEditingCommandTableConstructor },
- { &kNS_TEXTSERVICESDOCUMENT_CID, false, nullptr, TextServicesDocumentConstructor },
{ &kNS_GEOLOCATION_SERVICE_CID, false, nullptr, nsGeolocationServiceConstructor },
{ &kNS_GEOLOCATION_CID, false, nullptr, GeolocationConstructor },
{ &kNS_AUDIOCHANNEL_SERVICE_CID, false, nullptr, AudioChannelServiceConstructor },
{ &kNS_WEBSOCKETEVENT_SERVICE_CID, false, nullptr, WebSocketEventServiceConstructor },
{ &kNS_FOCUSMANAGER_CID, false, nullptr, CreateFocusManager },
#ifdef MOZ_WEBSPEECH_TEST_BACKEND
{ &kNS_FAKE_SPEECH_RECOGNITION_SERVICE_CID, false, nullptr, FakeSpeechRecognitionServiceConstructor },
#endif
@@ -998,17 +992,16 @@ static const mozilla::Module::ContractID
{ SERVICEWORKERMANAGER_CONTRACTID, &kSERVICEWORKERMANAGER_CID },
{ NOTIFICATIONTELEMETRYSERVICE_CONTRACTID, &kNOTIFICATIONTELEMETRYSERVICE_CID },
{ PUSHNOTIFIER_CONTRACTID, &kPUSHNOTIFIER_CID },
{ WORKERDEBUGGERMANAGER_CONTRACTID, &kWORKERDEBUGGERMANAGER_CID },
{ NS_AUDIOCHANNELAGENT_CONTRACTID, &kNS_AUDIOCHANNELAGENT_CID },
{ "@mozilla.org/editor/htmleditor;1", &kNS_HTMLEDITOR_CID },
{ "@mozilla.org/editor/editorcontroller;1", &kNS_EDITORCONTROLLER_CID },
{ "@mozilla.org/editor/editingcontroller;1", &kNS_EDITINGCONTROLLER_CID },
- { "@mozilla.org/textservices/textservicesdocument;1", &kNS_TEXTSERVICESDOCUMENT_CID },
{ "@mozilla.org/geolocation/service;1", &kNS_GEOLOCATION_SERVICE_CID },
{ "@mozilla.org/geolocation;1", &kNS_GEOLOCATION_CID },
{ "@mozilla.org/audiochannel/service;1", &kNS_AUDIOCHANNEL_SERVICE_CID },
{ "@mozilla.org/websocketevent/service;1", &kNS_WEBSOCKETEVENT_SERVICE_CID },
{ "@mozilla.org/focus-manager;1", &kNS_FOCUSMANAGER_CID },
#ifdef MOZ_WEBSPEECH_TEST_BACKEND
{ NS_SPEECH_RECOGNITION_SERVICE_CONTRACTID_PREFIX "fake", &kNS_FAKE_SPEECH_RECOGNITION_SERVICE_CID },
#endif