Range class
The Range object represents a fragment of a document that can contain nodes and parts of text nodes in a given document.
A range can be created using the Document.createRange
method of the Document
object. Range objects can also be retrieved by using the Selection.getRangeAt
method of the Selection
object.
@DomName('Range')
@Unstable
class Range native "Range" {
factory Range() => document.$dom_createRange();
factory Range.fromPoint(Point point) =>
document.$dom_caretRangeFromPoint(point.x, point.y);
@DomName('Range.END_TO_END')
@DocsEditable
static const int END_TO_END = 2;
@DomName('Range.END_TO_START')
@DocsEditable
static const int END_TO_START = 3;
@DomName('Range.NODE_AFTER')
@DocsEditable
@Experimental // nonstandard
static const int NODE_AFTER = 1;
@DomName('Range.NODE_BEFORE')
@DocsEditable
@Experimental // nonstandard
static const int NODE_BEFORE = 0;
@DomName('Range.NODE_BEFORE_AND_AFTER')
@DocsEditable
@Experimental // nonstandard
static const int NODE_BEFORE_AND_AFTER = 2;
@DomName('Range.NODE_INSIDE')
@DocsEditable
@Experimental // nonstandard
static const int NODE_INSIDE = 3;
@DomName('Range.START_TO_END')
@DocsEditable
static const int START_TO_END = 1;
@DomName('Range.START_TO_START')
@DocsEditable
static const int START_TO_START = 0;
@DomName('Range.collapsed')
@DocsEditable
final bool collapsed;
@DomName('Range.commonAncestorContainer')
@DocsEditable
final Node commonAncestorContainer;
@DomName('Range.endContainer')
@DocsEditable
final Node endContainer;
@DomName('Range.endOffset')
@DocsEditable
final int endOffset;
@DomName('Range.startContainer')
@DocsEditable
final Node startContainer;
@DomName('Range.startOffset')
@DocsEditable
final int startOffset;
@DomName('Range.cloneContents')
@DocsEditable
DocumentFragment cloneContents() native;
@DomName('Range.cloneRange')
@DocsEditable
Range cloneRange() native;
@DomName('Range.collapse')
@DocsEditable
void collapse(bool toStart) native;
@DomName('Range.compareNode')
@DocsEditable
@deprecated // deprecated
int compareNode(Node refNode) native;
@DomName('Range.comparePoint')
@DocsEditable
int comparePoint(Node refNode, int offset) native;
@DomName('Range.createContextualFragment')
@DocsEditable
DocumentFragment createContextualFragment(String html) native;
@DomName('Range.deleteContents')
@DocsEditable
void deleteContents() native;
@DomName('Range.detach')
@DocsEditable
void detach() native;
@DomName('Range.expand')
@DocsEditable
@Experimental // non-standard
void expand(String unit) native;
@DomName('Range.extractContents')
@DocsEditable
DocumentFragment extractContents() native;
@DomName('Range.getBoundingClientRect')
@DocsEditable
Rect getBoundingClientRect() native;
@DomName('Range.getClientRects')
@DocsEditable
@Returns('_ClientRectList')
@Creates('_ClientRectList')
List<Rect> getClientRects() native;
@DomName('Range.insertNode')
@DocsEditable
void insertNode(Node newNode) native;
@DomName('Range.intersectsNode')
@DocsEditable
@deprecated // deprecated
bool intersectsNode(Node refNode) native;
@DomName('Range.isPointInRange')
@DocsEditable
bool isPointInRange(Node refNode, int offset) native;
@DomName('Range.selectNode')
@DocsEditable
void selectNode(Node refNode) native;
@DomName('Range.selectNodeContents')
@DocsEditable
void selectNodeContents(Node refNode) native;
@DomName('Range.setEnd')
@DocsEditable
void setEnd(Node refNode, int offset) native;
@DomName('Range.setEndAfter')
@DocsEditable
void setEndAfter(Node refNode) native;
@DomName('Range.setEndBefore')
@DocsEditable
void setEndBefore(Node refNode) native;
@DomName('Range.setStart')
@DocsEditable
void setStart(Node refNode, int offset) native;
@DomName('Range.setStartAfter')
@DocsEditable
void setStartAfter(Node refNode) native;
@DomName('Range.setStartBefore')
@DocsEditable
void setStartBefore(Node refNode) native;
@DomName('Range.surroundContents')
@DocsEditable
void surroundContents(Node newParent) native;
@DomName('Range.toString')
@DocsEditable
String toString() native;
/**
* Checks if createContextualFragment is supported.
*
* See also:
*
* * [createContextualFragment]
*/
static bool get supportsCreateContextualFragment =>
JS('bool', '("createContextualFragment" in window.Range.prototype)');
}
Extends
Interceptor > Range
Static Properties
Constructors
factory Range() #
factory Range() => document.$dom_createRange();
Properties
final bool collapsed #
boolean indicating whether the range's start and end points are at the same position.
final bool collapsed
final int endOffset #
final int endOffset
final int hashCode #
Get a hash code for this object.
All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator ==. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.
If a subclass overrides hashCode it should override the
equality operator as well to maintain consistency.
int get hashCode => Primitives.objectHashCode(this);
final Type runtimeType #
A representation of the runtime type of the object.
Type get runtimeType => getRuntimeType(this);
Operators
bool operator ==(other) #
The equality operator.
The default behavior for all Objects is to return true if and
only if this and
other are the same object.
If a subclass overrides the equality operator it should override
the hashCode method as well to maintain consistency.
bool operator ==(other) => identical(this, other);
Methods
DocumentFragment cloneContents() #
DocumentFragment
copying the nodes of a Range.
@DomName('Range.cloneContents')
@DocsEditable
DocumentFragment cloneContents() native;
Range cloneRange() #
@DomName('Range.cloneRange')
@DocsEditable
Range cloneRange() native;
void collapse(bool toStart) #
@DomName('Range.collapse')
@DocsEditable
void collapse(bool toStart) native;
int comparePoint(Node refNode, int offset) #
@DomName('Range.comparePoint')
@DocsEditable
int comparePoint(Node refNode, int offset) native;
DocumentFragment createContextualFragment(String html) #
DocumentFragment
created from a given string of code.
@DomName('Range.createContextualFragment')
@DocsEditable
DocumentFragment createContextualFragment(String html) native;
void deleteContents() #
void detach() #
@DomName('Range.detach')
@DocsEditable
void detach() native;
void expand(String unit) #
@DomName('Range.expand')
@DocsEditable
@Experimental // non-standard
void expand(String unit) native;
DocumentFragment extractContents() #
DocumentFragment
.
@DomName('Range.extractContents')
@DocsEditable
DocumentFragment extractContents() native;
Rect getBoundingClientRect() #
ClientRect
object which bounds the entire contents of the range; this would be the union of all the rectangles returned by range.getClientRects()
.
@DomName('Range.getBoundingClientRect')
@DocsEditable
Rect getBoundingClientRect() native;
List<Rect> getClientRects() #
ClientRect
objects that aggregates the results of Element.getClientRects()
for all the elements in the range.
@DomName('Range.getClientRects')
@DocsEditable
@Returns('_ClientRectList')
@Creates('_ClientRectList')
List<Rect> getClientRects() native;
bool intersectsNode(Node refNode) #
boolean indicating whether the given node intersects the range.
@DomName('Range.intersectsNode')
@DocsEditable
@deprecated // deprecated
bool intersectsNode(Node refNode) native;
bool isPointInRange(Node refNode, int offset) #
boolean indicating whether the given point is in the range.
@DomName('Range.isPointInRange')
@DocsEditable
bool isPointInRange(Node refNode, int offset) native;
dynamic noSuchMethod(Invocation invocation) #
noSuchMethod is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to noSuchMethod in an Invocation.
If noSuchMethod returns a value, that value becomes the result of
the original invocation.
The default behavior of noSuchMethod is to throw a
noSuchMethodError.
dynamic noSuchMethod(Invocation invocation) {
throw new NoSuchMethodError(
this,
_symbolToString(invocation.memberName),
invocation.positionalArguments,
_symbolMapToStringMap(invocation.namedArguments));
}
void setEnd(Node refNode, int offset) #
@DomName('Range.setEnd')
@DocsEditable
void setEnd(Node refNode, int offset) native;
void setStart(Node refNode, int offset) #
@DomName('Range.setStart')
@DocsEditable
void setStart(Node refNode, int offset) native;
This page includes content from the
Mozilla Foundation that is graciously
licensed under a
Creative Commons: Attribution-Sharealike license.
Mozilla has no other association with Dart or dartlang.org. We
encourage you to improve the web by
contributing to
The Mozilla Developer Network.