Reviewed by Tim Hatcher.
Bug 23185: add a currentRange method to the WebTextIterator SPI
https://bugs.webkit.org/show_bug.cgi?id=23185
rdar://problem/6455834
I also noticed a garbage-collection-related threading issue that I fixed, and
that the SPI for getting text was unnecessarily inefficient, so I fixed that too.
* WebView/WebTextIterator.h: Moved currentNode and currentText into a "deprecated"
category. Added currentTextPointer and currentTextLength.
* WebView/WebTextIterator.mm: Changed m_textIterator into an OwnPtr, and also
used _textIterator to be consistent with ObjC rather than C++ naming.
(+[WebTextIteratorPrivate initialize]): Added. Calls WebCoreObjCFinalizeOnMainThread,
since the finalize method here works with main-thread only WebCore objects.
(-[WebTextIterator initWithRange:]): Changed since _textIterator is an OwnPtr now.
(-[WebTextIterator advance]): Changed name of m_textIterator. Removed null assertion,
since I don't think it provides much value.
(-[WebTextIterator atEnd]): Ditto.
(-[WebTextIterator currentRange]): Added.
(-[WebTextIterator currentTextPointer]): Added.
(-[WebTextIterator currentTextLength]): Added.
(-[WebTextIterator currentNode]): Did same as above, but also put into new category.
(-[WebTextIterator currentText]): Ditto.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@39715
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2009-01-08 Darin Adler <darin@apple.com>
+
+ Reviewed by Tim Hatcher.
+
+ Bug 23185: add a currentRange method to the WebTextIterator SPI
+ https://bugs.webkit.org/show_bug.cgi?id=23185
+ rdar://problem/6455834
+
+ I also noticed a garbage-collection-related threading issue that I fixed, and
+ that the SPI for getting text was unnecessarily inefficient, so I fixed that too.
+
+ * WebView/WebTextIterator.h: Moved currentNode and currentText into a "deprecated"
+ category. Added currentTextPointer and currentTextLength.
+
+ * WebView/WebTextIterator.mm: Changed m_textIterator into an OwnPtr, and also
+ used _textIterator to be consistent with ObjC rather than C++ naming.
+ (+[WebTextIteratorPrivate initialize]): Added. Calls WebCoreObjCFinalizeOnMainThread,
+ since the finalize method here works with main-thread only WebCore objects.
+ (-[WebTextIterator initWithRange:]): Changed since _textIterator is an OwnPtr now.
+ (-[WebTextIterator advance]): Changed name of m_textIterator. Removed null assertion,
+ since I don't think it provides much value.
+ (-[WebTextIterator atEnd]): Ditto.
+ (-[WebTextIterator currentRange]): Added.
+ (-[WebTextIterator currentTextPointer]): Added.
+ (-[WebTextIterator currentTextLength]): Added.
+ (-[WebTextIterator currentNode]): Did same as above, but also put into new category.
+ (-[WebTextIterator currentText]): Ditto.
+
2009-01-08 Eric Carlson <eric.carlson@apple.com>
Reviewed by Adele Peterson.
/*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import <Foundation/Foundation.h>
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
+#define WebNSUInteger unsigned int
+#else
+#define WebNSUInteger NSUInteger
+#endif
@class DOMRange;
@class DOMNode;
@class WebTextIteratorPrivate;
-@interface WebTextIterator : NSObject
-{
+@interface WebTextIterator : NSObject {
@private
WebTextIteratorPrivate *_private;
}
- (id)initWithRange:(DOMRange *)range;
/*!
- @method advance:
+ @method advance
@abstract Makes the WebTextIterator iterate to the next visible text element.
*/
- (void)advance;
/*!
- @method currentNode:
- @result The current DOMNode in the WebTextIterator.
+ @method atEnd
+ @result YES if the WebTextIterator has reached the end of the DOMRange.
*/
-- (DOMNode *)currentNode;
+- (BOOL)atEnd;
/*!
- @method currentText:
- @result The current text in the WebTextIterator.
+ @method currentRange
+ @result A range, indicating the position within the document of the current text.
*/
-- (NSString *)currentText;
+- (DOMRange *)currentRange;
/*!
- @method atEnd:
- @result YES if the WebTextIterator has reached the end of the DOMRange.
+ @method currentTextPointer
+ @result A pointer to the current text. The pointer becomes invalid after any modification is made to the document; it must be used right away.
*/
-- (BOOL)atEnd;
+- (const unichar *)currentTextPointer;
+
+/*!
+ @method currentTextLength
+ @result lengthPtr Length of the current text.
+ */
+- (WebNSUInteger)currentTextLength;
+
+@end
+
+@interface WebTextIterator (WebTextIteratorDeprecated)
+/*!
+ @method currentNode
+ @abstract A convenience method that finds the first node in currentRange; it's almost always better to use currentRange instead.
+ @result The current DOMNode in the WebTextIterator
+ */
+- (DOMNode *)currentNode;
+
+/*!
+ @method currentText
+ @abstract A convenience method that makes an NSString out of the current text; it's almost always better to use currentTextPointer and currentTextLength instead.
+ @result The current text in the WebTextIterator.
+ */
+- (NSString *)currentText;
@end
+
+#undef WebNSUInteger
#import "DOMNodeInternal.h"
#import "DOMRangeInternal.h"
+#import <JavaScriptCore/Vector.h>
#import <WebCore/TextIterator.h>
-#import <wtf/Vector.h>
+#import <WebCore/WebCoreObjCExtras.h>
+using namespace JSC;
using namespace WebCore;
-@interface WebTextIteratorPrivate : NSObject
-{
+@interface WebTextIteratorPrivate : NSObject {
@public
- TextIterator* m_textIterator;
+ OwnPtr<TextIterator> _textIterator;
}
@end
@implementation WebTextIteratorPrivate
-- (void)dealloc
-{
- delete m_textIterator;
- [super dealloc];
-}
-
-- (void)finalize
++ (void)initialize
{
- delete m_textIterator;
- [super finalize];
+#ifndef BUILDING_ON_TIGER
+ WebCoreObjCFinalizeOnMainThread(self);
+#endif
}
@end
return self;
_private = [[WebTextIteratorPrivate alloc] init];
- _private->m_textIterator = new TextIterator([range _range], true, false);
+ _private->_textIterator.set(new TextIterator([range _range], true, false));
return self;
}
- (void)advance
{
- ASSERT(_private->m_textIterator);
-
- if (_private->m_textIterator->atEnd())
- return;
-
- _private->m_textIterator->advance();
+ _private->_textIterator->advance();
}
-- (DOMNode *)currentNode
+- (BOOL)atEnd
{
- ASSERT(_private->m_textIterator);
-
- return [DOMNode _wrapNode:_private->m_textIterator->node()];
+ return _private->_textIterator->atEnd();
}
-- (NSString *)currentText
+- (DOMRange *)currentRange
{
- ASSERT(_private->m_textIterator);
-
- return [NSString stringWithCharacters:_private->m_textIterator->characters() length:_private->m_textIterator->length()];
+ return [DOMRange _wrapRange:_private->_textIterator->range().get()];
}
-- (BOOL)atEnd
+- (const unichar *)currentTextPointer
{
- ASSERT(_private->m_textIterator);
-
- return _private->m_textIterator->atEnd();
+ return _private->_textIterator->characters();
+}
+
+- (NSUInteger)currentTextLength
+{
+ return _private->_textIterator->length();
+}
+
+@end
+
+@implementation WebTextIterator (WebTextIteratorDeprecated)
+
+- (DOMNode *)currentNode
+{
+ return [DOMNode _wrapNode:_private->_textIterator->node()];
+}
+
+- (NSString *)currentText
+{
+ return [NSString stringWithCharacters:_private->_textIterator->characters() length:_private->_textIterator->length()];
}
@end