summaryrefslogtreecommitdiff
path: root/editor/txtsvc/nsITextServicesDocument.h
blob: 8b9d9e506020ad53606f2c15ee10168baa60ca59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* -*- 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"

class nsIDOMDocument;
class nsIDOMRange;
class nsIEditor;
class nsString;
class nsITextServicesFilter;

/*
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(nsIDOMRange* 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(nsIDOMRange *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__