nsISelection 编辑

nsISelection

content/base/public/nsISelection.idlScriptable ??? Add brief description of Interface ??? Inherits from: nsISupports Last changed in Gecko 13.0 (Firefox 13.0 / Thunderbird 13.0 / SeaMonkey 2.10)

Interface for manipulating and querying the current selected range of nodes within the document.

Implemented by: ?????????????????????????????????????. To create an instance, use:

Implemented by: ????????????????????????????????????? as a service:

var selection = Components.classes["@mozilla.org/????????????????????????????"]
                .createInstance(Components.interfaces.nsISelection);

Method overview

void addRange(in nsIDOMRange range);
void collapse(in nsIDOMNode parentNode, in long offset);
[noscript,notxpcom,nostdcall] boolean collapsed();
void collapseNative(in nsIDOMNode parentNode, in long offset); Native code only!
void collapseToEnd();
void collapseToStart();
boolean containsNode(in nsIDOMNode node, in boolean partlyContained);
void deleteFromDocument();
void extend(in nsIDOMNode parentNode, in long offset);
void extendNative(in nsIDOMNode parentNode, in long offset); Native code only!
nsIDOMRange getRangeAt(in long index);
void modify(in DOMString alter, in DOMString direction, in DOMString granularity);
void removeAllRanges();
void removeRange(in nsIDOMRange range);
void selectAllChildren(in nsIDOMNode parentNode);
void selectionLanguageChange(in boolean langRTL);
DOMString toString();

Attributes

AttributeTypeDescription
anchorNodensIDOMNodeReturns the node in which the selection begins. Read only.
anchorOffsetlongThe offset within the (text) node where the selection begins. Read only.
focusNodensIDOMNodeReturns the node in which the selection ends. Read only.
focusOffsetlongThe offset within the (text) node where the selection ends. Read only.
isCollapsedbooleanIndicates if the selection is collapsed() or not. Read only.
rangeCountlongReturns the number of ranges in the selection. Read only.

Methods

addRange()

Adds a nsIDOMRange to the current selection.

void addRange(
  in nsIDOMRange range
);
Parameters
range
The nsIDOMRange to add

collapse()

Collapses the selection to a single point, at the specified offset in the given nsIDOMNode. When the selection is collapsed(), and the content is focused and editable, the caret will blink there.

void collapse(
  in nsIDOMNode parentNode,
  in long offset
);
Parameters
parentNode
The given nsIDOMNode where the selection will be set.
offset
Where in the given dom node to place the selection (the offset into the given node).

collapsed()

[noscript,notxpcom,nostdcall] boolean collapsed();
Native code only!

collapseNative

void collapseNative(
  in nsINode parentNode,
  in long offset
);
Parameters
parentNode
offset

collapseToEnd()

Collapses the whole selection to a single point at the end of the current selection (regardless of direction). If content is focused and editable, the caret will blink there.

void collapseToEnd();
Parameters

None

collapseToStart()

Collapses the whole selection to a single point at the start of the current selection (regardless of direction). If content is focused and editable, the caret will blink there.

void collapseToStart();

containsNode()

Indicates whether the nsIDOMNode is part of the selection. If partlyContained is set to PR_TRUE, the function returns true when some part of the node is part of the selection. If partlyContained is set to PR_FALSE, the function only returns true when the entire node is part of the selection.

boolean containsNode(
  in nsIDOMNode node,
  in boolean partlyContained
);
Parameters
node
The nsIDOMNode to look for
partlyContained
If partlyContained is set to PR_FALSE, the function only returns true when the entire node is part of the selection.
Return value

Whether or not the range contains the requested noe.

deleteFromDocument()

Deletes this selection from the document the nodes belong to.

void deleteFromDocument();

extend()

Extends the selection by moving the selection end to the specified nsIDOMNode and offset, preserving the selection begin position. The new selection end result will always be from the anchorNode to the new focusNode, regardless of direction.

void extend(
  in nsIDOMNode parentNode,
  in long offset
);
Parameters
parentNode
The node where the selection will be extended to.
offset
Where in the node to place the offset in the new selection end.
Native code only!

extendNative

void extendNative(
  in nsINode parentNode,
  in long offset
);
Parameters
parentNode
offset

getRangeAt()

Returns the nsIDOMRange at the specified index.

nsIDOMRange getRangeAt(
  in long index
);
Parameters
index
Return value

The nsIDOMRange requested

modify()

Modifies the selection. Note that the parameters are case-insensitive.

void modify(
  in DOMString alter,
  in DOMString direction,
  in DOMString granularity
);
Parameters
alter
Can be one of { "move", "extend()" }
  • "move" collapses the selection to the end of the selection and applies the movement direction/granularity to the collapsed() selection.
  • "extend()" leaves the start of the selection unchanged, and applies movement direction/granularity to the end of the selection.
direction
Can be one of { "forward", "backward", "left", "right" }
granularity
Can be one of { "character", "word", "line", "lineboundary" }

removeAllRanges()

Removes all nsIDOMRanges from the current selection.

void removeAllRanges();
Parameters

None

removeRange()

Removes a range from the current selection.

void removeRange(
  in nsIDOMRange range
);
Parameters
range

selectAllChildren()

Adds all children of the specified node to the selection.

void selectAllChildren(
  in nsIDOMNode parentNode
);
Parameters
parentNode
The parent of the children to be added to the selection.

selectionLanguageChange()

Modifies the cursor Bidi level after a change in keyboard direction.

void selectionLanguageChange(
  in boolean langRTL
);
Parameters
langRTL
Is PR_TRUE if the new language is right-to-left or PR_FALSE if the new language is left-to-right.

toString()

Returns the whole selection into a plain text string.

DOMString toString();

Remarks

 

See also

  •  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:62 次

字数:15151

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文