Add HTML Range initializer that accepts start and end boundaries

This commit is contained in:
iska
2017-01-08 09:32:15 +01:00
parent e48ccf42ca
commit 395ce5e981
2 changed files with 23 additions and 2 deletions
+14
View File
@@ -82,6 +82,20 @@ typedef NS_ENUM(unsigned short, HTMLRangeComparisonMethod)
*/
- (instancetype)initWithDowcument:(HTMLDocument *)document;
/**
Initializes a new range instance for the given document and boundaries.
@param document The HTML doucment for which the range will be constructed.
@param startContainer The node for the start boundary
@param startOffset The offset of the start boundary
@param endContainer The node for the end boundary
@param endOffset The offset of the end boundary
@return A new HTML Range instance.
*/
- (instancetype)initWithDowcument:(HTMLDocument *)document
startContainer:(HTMLNode *)startContainer startOffset:(NSUInteger)startOffset
endContainer:(HTMLNode *)endContainer endOffset:(NSUInteger)endOffset;
/**
Sets the start boundary.
+9 -2
View File
@@ -24,13 +24,20 @@
#pragma mark - Lifecycle
- (instancetype)initWithDowcument:(HTMLDocument *)document
{
return [self initWithDowcument:document startContainer:document startOffset:0 endContainer:document endOffset:0];
}
- (instancetype)initWithDowcument:(HTMLDocument *)document
startContainer:(HTMLNode *)startContainer startOffset:(NSUInteger)startOffset
endContainer:(HTMLNode *)endContainer endOffset:(NSUInteger)endOffset
{
self = [super init];
if (self) {
_ownerDocument = document;
[_ownerDocument attachRange:self];
[self setStartNode:document startOffset:0];
[self setEndNode:document endOffset:0];
[self setStartNode:startContainer startOffset:startOffset];
[self setEndNode:endContainer endOffset:endOffset];
}
return self;
}