Backed out changeset 9d8b4c0b99ed (bug 1945683) for causing btime failures. CLOSED...
[gecko.git] / dom / base / nsISelectionController.idl
blob4952c0fb7dbc317e3061bf18b5de52a9be8b49dd
1 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsISelectionDisplay.idl"
9 %{C++
10 using SelectionRegion = short;
12 namespace mozilla {
13 namespace dom {
14 class Selection;
15 } // namespace dom
17 struct ScrollAxis;
18 enum class ScrollFlags : uint8_t;
19 enum class SelectionScrollMode : uint8_t;
21 // RawSelectionType should be used to store nsISelectionController::SELECTION_*.
22 using RawSelectionType = short;
24 // SelectionTypeMask should be used to store bit-mask of selection types.
25 // The value can be retrieved with ToSelectionTypeMask() and checking if
26 // a selection type is in a mask with |SelectionType & SelectionTypeMask|.
27 using SelectionTypeMask = uint16_t;
29 // SelectionType should be used in internal handling because of type safe.
30 enum class SelectionType : RawSelectionType;
32 } // namespace mozilla
36 interface nsIContent;
37 interface nsISelectionDisplay;
39 webidl Node;
40 webidl Selection;
42 [builtinclass, scriptable, uuid(3801c9d4-8e69-4bfc-9edb-b58278621f8f)]
43 interface nsISelectionController : nsISelectionDisplay
45 // Begin of RawSelectionType values.
46 const short SELECTION_NONE = 0;
47 // Corresponds to the Selection exposed via window.getSelection() and
48 // document.getSelection().
49 const short SELECTION_NORMAL = 1;
50 // Corresponds to the Selection used for spellchecking in <textarea>s and
51 // "contentEditable" elements.
52 const short SELECTION_SPELLCHECK = 2;
53 const short SELECTION_IME_RAWINPUT = 3;
54 const short SELECTION_IME_SELECTEDRAWTEXT = 4;
55 const short SELECTION_IME_CONVERTEDTEXT = 5;
56 const short SELECTION_IME_SELECTEDCONVERTEDTEXT = 6;
57 // For accessibility API usage
58 const short SELECTION_ACCESSIBILITY = 7;
59 const short SELECTION_FIND = 8;
60 const short SELECTION_URLSECONDARY = 9;
61 const short SELECTION_URLSTRIKEOUT = 10;
62 const short SELECTION_TARGET_TEXT = 11;
63 // Custom Highlight API
64 // (see https://drafts.csswg.org/css-highlight-api-1/#enumdef-highlighttype)
65 const short SELECTION_HIGHLIGHT = 12;
66 // End of RawSelectionType values.
67 const short NUM_SELECTIONTYPES = 13;
69 // SelectionRegion values:
70 const short SELECTION_ANCHOR_REGION = 0;
71 const short SELECTION_FOCUS_REGION = 1;
72 const short SELECTION_WHOLE_SELECTION = 2;
73 const short NUM_SELECTION_REGIONS = 3;
75 const short SELECTION_OFF = 0;
76 const short SELECTION_HIDDEN =1;//>HIDDEN displays selection
77 const short SELECTION_ON = 2;
78 const short SELECTION_DISABLED = 3;
79 const short SELECTION_ATTENTION = 4;
81 /**
82 * SetDisplaySelection will set the display mode for the selection. OFF,ON,DISABLED
84 void setDisplaySelection(in short toggle);
86 /**
87 * GetDisplaySelection will get the display mode for the selection. OFF,ON,DISABLED
89 short getDisplaySelection();
91 /**
92 * GetSelection will return the selection that the presentation
93 * shell may implement.
95 * @param aType This will hold the type of selection. This value must be one
96 * of RawSelectionType values.
97 * @param _return will hold the return value
99 [binaryname(GetSelectionFromScript)]
100 Selection getSelection(in short type);
103 * Return the selection object corresponding to a selection type.
105 [noscript,nostdcall,notxpcom,binaryname(GetSelection)]
106 Selection getDOMSelection(in short aType);
109 * Called when the selection controller should take the focus.
111 * This will take care to hide the previously-focused selection, show this
112 * selection, and repaint both.
114 [noscript,nostdcall,notxpcom]
115 void selectionWillTakeFocus();
118 * Called when the selection controller has lost the focus.
120 * This will take care to hide and repaint the selection.
122 [noscript,nostdcall,notxpcom]
123 void selectionWillLoseFocus();
125 cenum ControllerScrollFlags : 8 {
126 // Scrolls the selection into view before returning.
127 SCROLL_SYNCHRONOUS = 1 << 1,
128 // Only the first ancestor will be scrolled into view.
129 // Note that this flushes layout, and thus can run script.
130 // See bug 418470 comment 12.
131 SCROLL_FIRST_ANCESTOR_ONLY = 1 << 2,
132 // Scrolls even if overflow is set to hidden.
133 SCROLL_OVERFLOW_HIDDEN = 1 << 3,
134 // No flag scrolls to nearest, vertically.
135 SCROLL_VERTICAL_NEAREST = 0,
136 SCROLL_VERTICAL_START = 1 << 4,
137 SCROLL_VERTICAL_CENTER = 1 << 5,
138 SCROLL_VERTICAL_END = 1 << 6,
142 * ScrollSelectionIntoView scrolls a region of the selection,
143 * so that it is visible in the scrolled view.
145 * @param aType the selection to scroll into view. This value must be one
146 * of RawSelectionType values.
147 * @param aRegion the region inside the selection to scroll into view. //SelectionRegion
148 * @param aFlags the scroll flags.
150 void scrollSelectionIntoView(in short type, in short region, in nsISelectionController_ControllerScrollFlags flags);
153 * RepaintSelection repaints the selection specified by aType.
155 * @param aType specifies the selection to repaint.
157 void repaintSelection(in short type);
160 * Set the caret as enabled or disabled. An enabled caret will
161 * draw or blink when made visible. A disabled caret will never show up.
162 * Can be called any time.
163 * @param aEnable true to enable caret. false to disable.
164 * @return always NS_OK
166 void setCaretEnabled(in boolean enabled);
169 * Set the caret readonly or not. An readonly caret will
170 * draw but not blink when made visible.
171 * @param aReadOnly true to enable caret. false to disable.
172 * @return always NS_OK
174 void setCaretReadOnly(in boolean readOnly);
177 * Gets the current state of the caret.
178 * @param aEnabled [OUT] set to the current caret state, as set by SetCaretEnabled
179 * @return if aOutEnabled==null, returns NS_ERROR_INVALID_ARG
180 * else NS_OK
182 boolean getCaretEnabled();
185 * This is true if the caret is enabled, visible, and currently blinking.
186 * This is still true when the caret is enabled, visible, but in its "off"
187 * blink cycle.
189 readonly attribute boolean caretVisible;
192 * Show the caret even in selections. By default the caret is hidden unless the
193 * selection is collapsed. Use this function to show the caret even in selections.
194 * @param aVisibility true to show the caret in selections. false to hide.
195 * @return always NS_OK
197 void setCaretVisibilityDuringSelection(in boolean visibility);
199 /** CharacterMove will move the selection one character forward/backward in the document.
200 * this will also have the effect of collapsing the selection if the aExtend = false
201 * the "point" of selection that is extended is considered the "focus" point.
202 * or the last point adjusted by the selection.
203 * @param aForward forward or backward if false
204 * @param aExtend should it collapse the selection of extend it?
206 void characterMove(in boolean forward, in boolean extend);
208 /** PhysicalMove will move the selection one "unit" in a given direction
209 * within the document.
210 * this will also have the effect of collapsing the selection if the aExtend = false
211 * the "point" of selection that is extended is considered the "focus" point.
212 * or the last point adjusted by the selection.
213 * @param aDirection
214 * @param aAmount character/line; word/lineBoundary
215 * @param aExtend should it collapse the selection of extend it?
217 void physicalMove(in short direction, in short amount, in boolean extend);
220 * nsFrameSelection::PhysicalMove depends on the ordering of these values;
221 * do not change without checking there!
223 const short MOVE_LEFT = 0;
224 const short MOVE_RIGHT = 1;
225 const short MOVE_UP = 2;
226 const short MOVE_DOWN = 3;
228 /** WordMove will move the selection one word forward/backward in the document.
229 * this will also have the effect of collapsing the selection if the aExtend = false
230 * the "point" of selection that is extended is considered the "focus" point.
231 * or the last point adjusted by the selection.
232 * @param aForward forward or backward if false
233 * @param aExtend should it collapse the selection of extend it?
235 void wordMove(in boolean forward, in boolean extend);
237 /** LineMove will move the selection one line forward/backward in the document.
238 * this will also have the effect of collapsing the selection if the aExtend = false
239 * the "point" of selection that is extended is considered the "focus" point.
240 * or the last point adjusted by the selection.
241 * @param aForward forward or backward if false
242 * @param aExtend should it collapse the selection of extend it?
244 void lineMove(in boolean forward, in boolean extend);
246 /** IntraLineMove will move the selection to the front of the line or end of the line
247 * in the document.
248 * this will also have the effect of collapsing the selection if the aExtend = false
249 * the "point" of selection that is extended is considered the "focus" point.
250 * or the last point adjusted by the selection.
251 * @param aForward forward or backward if false
252 * @param aExtend should it collapse the selection of extend it?
254 void intraLineMove(in boolean forward, in boolean extend);
256 /** PageMove will move the selection one page forward/backward in the document.
257 * this will also have the effect of collapsing the selection if the aExtend = false
258 * the "point" of selection that is extended is considered the "focus" point.
259 * or the last point adjusted by the selection.
260 * @param aForward forward or backward if false
261 * @param aExtend should it collapse the selection of extend it?
263 [can_run_script]
264 void pageMove(in boolean forward, in boolean extend);
266 /** CompleteScroll will move page view to the top or bottom of the document
267 * @param aForward forward or backward if false
269 void completeScroll(in boolean forward);
271 /** CompleteMove will move page view to the top or bottom of the document
272 * this will also have the effect of collapsing the selection if the aExtend = false
273 * the "point" of selection that is extended is considered the "focus" point.
274 * or the last point adjusted by the selection.
275 * @param aForward forward or backward if false
276 * @param aExtend should it collapse the selection of extend it?
278 [can_run_script]
279 void completeMove(in boolean forward, in boolean extend);
282 /** ScrollPage will scroll the page without affecting the selection.
283 * @param aForward scroll forward or backwards in selection
285 void scrollPage(in boolean forward);
287 /** ScrollLine will scroll line up or down dependent on the boolean
288 * @param aForward scroll forward or backwards in selection
290 void scrollLine(in boolean forward);
292 /** ScrollCharacter will scroll right or left dependent on the boolean
293 * @param aRight if true will scroll right. if not will scroll left.
295 void scrollCharacter(in boolean right);
297 %{C++
298 // Like the XPCOM method, but more convenient and flexible for C++ callers. Implemented in Selection.h
299 // TODO: Use `MOZ_CAN_RUN_SCRIPT`, but it's a bit tricky because whether it
300 // can run script depends on the SelectionScrollMode.
301 MOZ_CAN_RUN_SCRIPT_BOUNDARY inline nsresult ScrollSelectionIntoView(
302 mozilla::SelectionType, SelectionRegion,
303 const mozilla::ScrollAxis& aVertical, const mozilla::ScrollAxis& aHorizontal,
304 mozilla::ScrollFlags, mozilla::SelectionScrollMode);
305 MOZ_CAN_RUN_SCRIPT_BOUNDARY inline nsresult ScrollSelectionIntoView(
306 mozilla::SelectionType, SelectionRegion,
307 mozilla::SelectionScrollMode);
310 %{C++
312 namespace mozilla {
314 // SelectionType should be used in internal handling code as it is type safe.
315 enum class SelectionType : RawSelectionType {
316 eInvalid = -1,
317 eNone = nsISelectionController::SELECTION_NONE,
318 eNormal = nsISelectionController::SELECTION_NORMAL,
319 eSpellCheck = nsISelectionController::SELECTION_SPELLCHECK,
320 eIMERawClause = nsISelectionController::SELECTION_IME_RAWINPUT,
321 eIMESelectedRawClause = nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT,
322 eIMEConvertedClause = nsISelectionController::SELECTION_IME_CONVERTEDTEXT,
323 eIMESelectedClause =
324 nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT,
325 eAccessibility = nsISelectionController::SELECTION_ACCESSIBILITY,
326 eFind = nsISelectionController::SELECTION_FIND,
327 eURLSecondary = nsISelectionController::SELECTION_URLSECONDARY,
328 eURLStrikeout = nsISelectionController::SELECTION_URLSTRIKEOUT,
329 eTargetText = nsISelectionController::SELECTION_TARGET_TEXT,
330 eHighlight = nsISelectionController::SELECTION_HIGHLIGHT,
333 // kPresentSelectionTypes is selection types which may be displayed.
334 // I.e., selection types except eNone.
335 static const SelectionType kPresentSelectionTypes[] = {
336 SelectionType::eNormal,
337 SelectionType::eSpellCheck,
338 SelectionType::eIMERawClause,
339 SelectionType::eIMESelectedRawClause,
340 SelectionType::eIMEConvertedClause,
341 SelectionType::eIMESelectedClause,
342 SelectionType::eAccessibility,
343 SelectionType::eFind,
344 SelectionType::eURLSecondary,
345 SelectionType::eURLStrikeout,
346 SelectionType::eTargetText,
347 SelectionType::eHighlight,
350 // Please include mozilla/dom/Selection.h for the following APIs.
351 constexpr bool IsValidRawSelectionType(RawSelectionType aRawSelectionType);
352 constexpr SelectionType ToSelectionType(RawSelectionType aRawSelectionType);
353 constexpr RawSelectionType ToRawSelectionType(SelectionType aSelectionType);
354 constexpr SelectionTypeMask ToSelectionTypeMask(SelectionType aSelectionType);
356 } // namespace mozilla