1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/.
6 * The origin of this IDL file is
7 * https://w3c.github.io/selection-api/#selection-interface
9 * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
10 * liability, trademark and document use rules apply.
16 readonly attribute Node? anchorNode;
18 readonly attribute unsigned long anchorOffset;
20 readonly attribute Node? focusNode;
22 readonly attribute unsigned long focusOffset;
23 readonly attribute boolean isCollapsed;
25 readonly attribute boolean areNormalAndCrossShadowBoundaryRangesCollapsed;
27 * Returns the number of ranges in the selection.
29 readonly attribute unsigned long rangeCount;
30 readonly attribute DOMString type;
31 readonly attribute DOMString direction;
33 * Returns the range at the specified index. Throws if the index is
37 Range getRangeAt(unsigned long index);
39 * Adds a range to the current selection.
41 [Throws, BinaryName="addRangeJS"]
42 undefined addRange(Range range);
44 * Removes a range from the current selection.
46 [Throws, BinaryName="removeRangeAndUnselectFramesAndNotifyListeners"]
47 undefined removeRange(Range range);
49 * Removes all ranges from the current selection.
52 undefined removeAllRanges();
53 [Throws, BinaryName="RemoveAllRanges"]
56 [Pref="dom.shadowdom.selection_across_boundary_enabled"]
57 sequence<StaticRange> getComposedRanges(ShadowRoot... shadowRoots);
59 [Throws, BinaryName="collapseJS"]
60 undefined collapse(Node? node, optional unsigned long offset = 0);
61 [Throws, BinaryName="collapseJS"]
62 undefined setPosition(Node? node, optional unsigned long offset = 0);
63 [Throws, BinaryName="collapseToStartJS"]
64 undefined collapseToStart();
65 [Throws, BinaryName="collapseToEndJS"]
66 undefined collapseToEnd();
67 [Throws, BinaryName="extendJS"]
68 undefined extend(Node node, optional unsigned long offset = 0);
69 [Throws, BinaryName="setBaseAndExtentJS"]
70 undefined setBaseAndExtent(Node anchorNode,
71 unsigned long anchorOffset,
73 unsigned long focusOffset);
74 [Throws, BinaryName="selectAllChildrenJS"]
75 undefined selectAllChildren(Node node);
77 undefined deleteFromDocument();
79 boolean containsNode(Node node,
80 optional boolean allowPartialContainment = false);
81 stringifier DOMString ();
84 // Additional methods not currently in the spec
85 partial interface Selection {
87 undefined modify(DOMString alter, DOMString direction,
88 DOMString granularity);
91 // Additional chrome-only methods.
92 interface nsISelectionListener;
93 partial interface Selection {
95 * A true value means "selection after newline"; false means "selection before
96 * newline" when a selection is positioned "between lines".
98 [ChromeOnly,Throws, BinaryName=interlinePositionJS]
99 attribute boolean interlinePosition;
102 attribute short? caretBidiLevel;
105 DOMString toStringWithFormat(DOMString formatType, unsigned long flags, long wrapColumn);
107 undefined addSelectionListener(nsISelectionListener newListener);
109 undefined removeSelectionListener(nsISelectionListener listenerToRemove);
111 [ChromeOnly,BinaryName="rawType"]
112 readonly attribute short selectionType;
115 * Return array of ranges intersecting with the given DOM interval.
117 [ChromeOnly,Throws,Pref="dom.testing.selection.GetRangesForInterval"]
118 sequence<Range> GetRangesForInterval(Node beginNode, long beginOffset, Node endNode, long endOffset,
119 boolean allowAdjacent);
122 * Scrolls a region of the selection, so that it is visible in
125 * @param aRegion the region inside the selection to scroll into view
126 * (see selection region constants defined in
127 * nsISelectionController).
128 * @param aIsSynchronous when true, scrolls the selection into view
129 * before returning. If false, posts a request which
130 * is processed at some point after the method returns.
131 * @param aVPercent how to align the frame vertically.
132 * @param aHPercent how to align the frame horizontally.
135 undefined scrollIntoView(short aRegion, boolean aIsSynchronous, short aVPercent, short aHPercent);
138 * setColors() sets custom colors for the selection.
139 * Currently, this is supported only when the selection type is SELECTION_FIND.
140 * Otherwise, throws an exception.
142 * @param aForegroundColor The foreground color of the selection.
143 * If this is "currentColor", foreground color
144 * isn't changed by this selection.
145 * @param aBackgroundColor The background color of the selection.
146 * If this is "transparent", background color is
148 * @param aAltForegroundColor The alternative foreground color of the
150 * If aBackgroundColor doesn't have sufficient
151 * contrast with its around or foreground color
152 * if "currentColor" is specified, alternative
153 * colors are used if it have higher contrast.
154 * @param aAltBackgroundColor The alternative background color of the
158 undefined setColors(DOMString aForegroundColor, DOMString aBackgroundColor,
159 DOMString aAltForegroundColor, DOMString aAltBackgroundColor);
162 * resetColors() forget the customized colors which were set by setColors().
165 undefined resetColors();