Dart API Referencedart:htmlRange

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

const int END_TO_END #

static const int END_TO_END = 2

const int END_TO_START #

static const int END_TO_START = 3

const int NODE_AFTER #

static const int NODE_AFTER = 1

const int NODE_BEFORE #

static const int NODE_BEFORE = 0

const int NODE_BEFORE_AND_AFTER #

static const int NODE_BEFORE_AND_AFTER = 2

const int NODE_INSIDE #

static const int NODE_INSIDE = 3

const int START_TO_END #

static const int START_TO_END = 1

const int START_TO_START #

static const int START_TO_START = 0

final bool supportsCreateContextualFragment #

Checks if createContextualFragment is supported.

See also:

static bool get supportsCreateContextualFragment =>
   JS('bool', '("createContextualFragment" in window.Range.prototype)');

Constructors

factory Range() #

factory Range() => document.$dom_createRange();

factory Range.fromPoint(Point point) #

factory Range.fromPoint(Point point) =>
   document.$dom_caretRangeFromPoint(point.x, point.y);

Properties

final bool collapsed #

Returns a boolean indicating whether the range's start and end points are at the same position.
final bool collapsed

final Node commonAncestorContainer #

Returns the deepest Node  that contains the startContainer and endContainer Nodes.
final Node commonAncestorContainer

final Node endContainer #

Returns the Node  within which the Range ends.
final Node endContainer

final int endOffset #

Returns a number representing where in the endContainer the Range ends.
final int endOffset

final int hashCode #

inherited from Interceptor

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.

docs inherited from Object
int get hashCode => Primitives.objectHashCode(this);

final Type runtimeType #

inherited from Interceptor

A representation of the runtime type of the object.

docs inherited from Object
Type get runtimeType => getRuntimeType(this);

final Node startContainer #

Returns the Node  within which the Range starts.
final Node startContainer

final int startOffset #

Returns a number representing where in the startContainer the Range starts.
final int startOffset

Operators

bool operator ==(other) #

inherited from Interceptor

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.

docs inherited from Object
bool operator ==(other) => identical(this, other);

Methods

DocumentFragment cloneContents() #

Returns a DocumentFragment  copying the nodes of a Range.
@DomName('Range.cloneContents')
@DocsEditable
DocumentFragment cloneContents() native;

Range cloneRange() #

Returns a Range object with boundary points identical to the cloned Range.
@DomName('Range.cloneRange')
@DocsEditable
Range cloneRange() native;

void collapse(bool toStart) #

Collapses the Range to one of its boundary points.
@DomName('Range.collapse')
@DocsEditable
void collapse(bool toStart) native;

int compareNode(Node refNode) #

Returns a constant representing whether the Node is before, after, inside, or surrounding the range.
@DomName('Range.compareNode')
@DocsEditable
@deprecated // deprecated
int compareNode(Node refNode) native;

int comparePoint(Node refNode, int offset) #

Returns -1, 0, or 1 indicating whether the point occurs before, inside, or after the range.
@DomName('Range.comparePoint')
@DocsEditable
int comparePoint(Node refNode, int offset) native;

DocumentFragment createContextualFragment(String html) #

Returns a DocumentFragment  created from a given string of code.
@DomName('Range.createContextualFragment')
@DocsEditable
DocumentFragment createContextualFragment(String html) native;

void deleteContents() #

Removes the contents of a Range from the Document .
@DomName('Range.deleteContents')
@DocsEditable
void deleteContents() native;

void detach() #

Releases Range from use to improve performance.
@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() #

Moves contents of a Range from the document tree into a DocumentFragment .
@DomName('Range.extractContents')
@DocsEditable
DocumentFragment extractContents() native;

Rect getBoundingClientRect() #

Returns a 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() #

Returns a list of 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;

void insertNode(Node newNode) #

Insert a Node  at the start of a Range.
@DomName('Range.insertNode')
@DocsEditable
void insertNode(Node newNode) native;

bool intersectsNode(Node refNode) #

Returns a 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) #

Returns a 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) #

inherited from Interceptor

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.

docs inherited from Object
dynamic noSuchMethod(Invocation invocation) {
 throw new NoSuchMethodError(
     this,
     _symbolToString(invocation.memberName),
     invocation.positionalArguments,
     _symbolMapToStringMap(invocation.namedArguments));
}

void selectNode(Node refNode) #

Sets the Range to contain the Node  and its contents.
@DomName('Range.selectNode')
@DocsEditable
void selectNode(Node refNode) native;

void selectNodeContents(Node refNode) #

Sets the Range to contain the contents of a Node .
@DomName('Range.selectNodeContents')
@DocsEditable
void selectNodeContents(Node refNode) native;

void setEnd(Node refNode, int offset) #

Sets the end position of a Range.
@DomName('Range.setEnd')
@DocsEditable
void setEnd(Node refNode, int offset) native;

void setEndAfter(Node refNode) #

Sets the end position of a Range relative to another Node .
@DomName('Range.setEndAfter')
@DocsEditable
void setEndAfter(Node refNode) native;

void setEndBefore(Node refNode) #

Sets the end position of a Range relative to another Node .
@DomName('Range.setEndBefore')
@DocsEditable
void setEndBefore(Node refNode) native;

void setStart(Node refNode, int offset) #

Sets the start position of a Range.
@DomName('Range.setStart')
@DocsEditable
void setStart(Node refNode, int offset) native;

void setStartAfter(Node refNode) #

Sets the start position of a Range relative to another Node .
@DomName('Range.setStartAfter')
@DocsEditable
void setStartAfter(Node refNode) native;

void setStartBefore(Node refNode) #

Sets the start position of a Range relative to another Node .
@DomName('Range.setStartBefore')
@DocsEditable
void setStartBefore(Node refNode) native;

void surroundContents(Node newParent) #

Moves content of a Range into a new Node .
@DomName('Range.surroundContents')
@DocsEditable
void surroundContents(Node newParent) native;

String toString() #

Returns a string representation of this object.

docs inherited from Object
@DomName('Range.toString')
@DocsEditable
String toString() 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.