1 /* -*- Mode: C++; 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/. */
6 #include
"nsISupports.idl"
8 /* THIS IS A PUBLIC INTERFACE */
11 interface nsIDOMRange
;
15 * Interface for manipulating and querying the current selected range
16 * of nodes within the document.
21 [builtinclass
, uuid(e0a4d4b3
-f34e
-44bd
-b1f2
-4e3bde9b6915
)]
22 interface nsISelection
: nsISupports
25 * Returns the node in which the selection begins.
27 readonly attribute nsIDOMNode anchorNode
;
30 * The offset within the (text) node where the selection begins.
32 readonly attribute
long anchorOffset
;
35 * Returns the node in which the selection ends.
37 readonly attribute nsIDOMNode focusNode
;
40 * The offset within the (text) node where the selection ends.
42 readonly attribute
long focusOffset
;
45 * Indicates if the selection is collapsed or not.
47 readonly attribute
boolean isCollapsed
;
48 [noscript
,notxpcom
,nostdcall
] boolean collapsed
();
51 * Returns the number of ranges in the selection.
53 readonly attribute
long rangeCount
;
56 * Returns the range at the specified index.
58 nsIDOMRange getRangeAt
(in long index
);
61 * Collapses the selection to a single point, at the specified offset
62 * in the given DOM node. When the selection is collapsed, and the content
63 * is focused and editable, the caret will blink there.
64 * @param parentNode The given dom node where the selection will be set
65 * @param offset Where in given dom node to place the selection (the offset into the given node)
67 void collapse
(in nsIDOMNode parentNode
, in long offset
);
68 [noscript
] void collapseNative
(in nsINode parentNode
, in long offset
);
71 * Extends the selection by moving the selection end to the specified node and offset,
72 * preserving the selection begin position. The new selection end result will always
73 * be from the anchorNode to the new focusNode, regardless of direction.
74 * @param parentNode The node where the selection will be extended to
75 * @param offset Where in node to place the offset in the new selection end
77 void extend
(in nsIDOMNode parentNode
, in long offset
);
78 [noscript
] void extendNative
(in nsINode parentNode
, in long offset
);
81 * Collapses the whole selection to a single point at the start
82 * of the current selection (irrespective of direction). If content
83 * is focused and editable, the caret will blink there.
85 void collapseToStart
();
88 * Collapses the whole selection to a single point at the end
89 * of the current selection (irrespective of direction). If content
90 * is focused and editable, the caret will blink there.
95 * Indicates whether the node is part of the selection. If partlyContained
96 * is set to PR_TRUE, the function returns true when some part of the node
97 * is part of the selection. If partlyContained is set to PR_FALSE, the
98 * function only returns true when the entire node is part of the selection.
100 boolean containsNode
(in nsIDOMNode node
, in boolean partlyContained
);
103 * Adds all children of the specified node to the selection.
104 * @param parentNode the parent of the children to be added to the selection.
106 void selectAllChildren
(in nsIDOMNode parentNode
);
109 * Adds a range to the current selection.
111 void addRange
(in nsIDOMRange
range);
114 * Removes a range from the current selection.
116 void removeRange
(in nsIDOMRange
range);
119 * Removes all ranges from the current selection.
121 void removeAllRanges
();
124 * Deletes this selection from document the nodes belong to.
126 void deleteFromDocument
();
129 * Returns the whole selection into a plain text string.
131 DOMString toString
();
134 * Modifies the selection. Note that the parameters are case-insensitive.
136 * @param alter can be one of { "move", "extend" }
137 * - "move" collapses the selection to the end of the selection and
138 * applies the movement direction/granularity to the collapsed
140 * - "extend" leaves the start of the selection unchanged, and applies
141 * movement direction/granularity to the end of the selection.
142 * @param direction can be one of { "forward", "backward", "left", "right" }
143 * @param granularity can be one of { "character", "word",
144 * "line", "lineboundary" }
146 * @returns NS_ERROR_NOT_IMPLEMENTED if the granularity is "sentence",
147 * "sentenceboundary", "paragraph", "paragraphboundary", or
148 * "documentboundary". Returns NS_ERROR_INVALID_ARG if alter, direction,
149 * or granularity has an unrecognized value.
151 void modify
(in DOMString alter
, in DOMString direction
,
152 in DOMString granularity
);