- some refactoring cleanup in the selection/searching code
* Misc.subproj/WebSearchableTextView.h:
moved WebDocumentSelection protocol conformation to this class, was in subclass WebTextView
* Misc.subproj/WebSearchableTextView.m:
(-[WebSearchableTextView selectionRect]):
new method (moved here from Safari) to return a single rect encompassing all selected text
(-[WebSearchableTextView pasteboardTypesForSelection]):
moved here from WebTextView
(-[WebSearchableTextView writeSelectionWithPasteboardTypes:toPasteboard:]):
ditto
* WebView.subproj/WebDocumentInternal.h:
moved WebDocumentSelection protocol out of here
* WebView.subproj/WebDocumentPrivate.h:
moved WebDocumentSelection protocol into here, added selectionRect method
* WebView.subproj/WebHTMLView.m:
(-[WebHTMLView selectionRect]):
new method, calls existing bridge method formerly called by _selectionRect
(-[WebHTMLView _selectionRect]):
now calls [self selectionRect]. We can't just delete _selectionRect because it's used by Mail.
* WebView.subproj/WebHTMLViewPrivate.h:
removed _selectionRect since it's in WebDocumentSelection now
* WebView.subproj/WebTextView.h:
removed WebDocumentSelection from protocol list since it's in superclass now
* WebView.subproj/WebTextView.m:
removed old WebDocumentSelection methods because they are in superclass now
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9820
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2005-07-18 John Sullivan <sullivan@apple.com>
+
+ Reviewed by Chris Blumenberg.
+
+ - some refactoring cleanup in the selection/searching code
+
+ * Misc.subproj/WebSearchableTextView.h:
+ moved WebDocumentSelection protocol conformation to this class, was in subclass WebTextView
+ * Misc.subproj/WebSearchableTextView.m:
+ (-[WebSearchableTextView selectionRect]):
+ new method (moved here from Safari) to return a single rect encompassing all selected text
+ (-[WebSearchableTextView pasteboardTypesForSelection]):
+ moved here from WebTextView
+ (-[WebSearchableTextView writeSelectionWithPasteboardTypes:toPasteboard:]):
+ ditto
+
+ * WebView.subproj/WebDocumentInternal.h:
+ moved WebDocumentSelection protocol out of here
+
+ * WebView.subproj/WebDocumentPrivate.h:
+ moved WebDocumentSelection protocol into here, added selectionRect method
+
+ * WebView.subproj/WebHTMLView.m:
+ (-[WebHTMLView selectionRect]):
+ new method, calls existing bridge method formerly called by _selectionRect
+ (-[WebHTMLView _selectionRect]):
+ now calls [self selectionRect]. We can't just delete _selectionRect because it's used by Mail.
+
+ * WebView.subproj/WebHTMLViewPrivate.h:
+ removed _selectionRect since it's in WebDocumentSelection now
+
+ * WebView.subproj/WebTextView.h:
+ removed WebDocumentSelection from protocol list since it's in superclass now
+
+ * WebView.subproj/WebTextView.m:
+ removed old WebDocumentSelection methods because they are in superclass now
+
2005-07-15 Adele Peterson <adele@apple.com>
Written by Trey Matteson <trey@usa.net>
#import <Cocoa/Cocoa.h>
@protocol WebDocumentSearching;
+@protocol WebDocumentSelection;
-@interface WebSearchableTextView : NSTextView <WebDocumentSearching>
+@interface WebSearchableTextView : NSTextView <WebDocumentSearching, WebDocumentSelection>
@end
*/
#import "WebSearchableTextView.h"
-#import "WebDocument.h"
+#import "WebDocumentPrivate.h"
@interface NSString (_Web_StringTextFinding)
- (NSRange)findString:(NSString *)string selectedRange:(NSRange)selectedRange options:(unsigned)mask wrap:(BOOL)wrapFlag;
}
}
+- (NSRect)selectionRect
+{
+ // Note that this method would work for any NSTextView; some day we might want to use it
+ // for an NSTextView that isn't a WebTextView.
+ NSRect result = NSZeroRect;
+
+ // iterate over multiple selected ranges
+ NSEnumerator *rangeEnumerator = [[self selectedRanges] objectEnumerator];
+ NSValue *rangeAsValue;
+ while ((rangeAsValue = [rangeEnumerator nextObject]) != nil) {
+ NSRange range = [rangeAsValue rangeValue];
+ unsigned rectCount;
+ NSRectArray rectArray = [[self layoutManager] rectArrayForCharacterRange:range
+ withinSelectedCharacterRange:range
+ inTextContainer:[self textContainer]
+ rectCount:&rectCount];
+ unsigned i;
+ // iterate over multiple rects in each selected range
+ for (i = 0; i < rectCount; ++i) {
+ NSRect rect = rectArray[i];
+ if (NSEqualRects(result, NSZeroRect)) {
+ result = rect;
+ } else {
+ result = NSUnionRect(result, rect);
+ }
+ }
+ }
+
+ return result;
+}
+
+- (NSArray *)pasteboardTypesForSelection
+{
+ return [self writablePasteboardTypes];
+}
+
+- (void)writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard
+{
+ [self writeSelectionToPasteboard:pasteboard types:types];
+}
+
@end
@implementation NSString (_Web_StringTextFinding)
@protocol WebDocumentElement <NSObject>
- (NSDictionary *)elementAtPoint:(NSPoint)point;
@end
-
-@protocol WebDocumentSelection <NSObject>
-- (NSArray *)pasteboardTypesForSelection;
-- (void)writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard;
-@end
@protocol WebDocumentDOM <NSObject>
- (DOMDocument *)DOMDocument;
@end
+
+@protocol WebDocumentSelection <NSObject>
+- (NSArray *)pasteboardTypesForSelection;
+- (void)writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard;
+- (NSRect)selectionRect;
+@end
[super _web_layoutIfNeededRecursive:displayRect testDirtyRect:NO];
}
-- (NSRect)_selectionRect
-{
- return [[self _bridge] selectionRect];
-}
-
- (void)_startAutoscrollTimer: (NSEvent *)triggerEvent
{
if (_private->autoscrollTimer == nil) {
}
}
+// FIXME: _selectionRect is deprecated in favor of selectionRect, which is in protocol WebDocumentSelection.
+// We can't remove this yet because it's still in use by Mail.
+- (NSRect)_selectionRect
+{
+ return [self selectionRect];
+}
+
- (void)_stopAutoscrollTimer
{
NSTimer *timer = _private->autoscrollTimer;
[[self _bridge] jumpToSelection];
}
+- (NSRect)selectionRect
+{
+ return [[self _bridge] selectionRect];
+}
+
- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item
{
SEL action = [item action];
- (WebPluginController *)_pluginController;
+// FIXME: _selectionRect is deprecated in favor of selectionRect, which is in protocol WebDocumentSelection.
+// We can't remove this yet because it's still in use by Mail.
- (NSRect)_selectionRect;
- (void)_startAutoscrollTimer:(NSEvent *)event;
@class WebDataSource;
-@interface WebTextView : WebSearchableTextView <WebDocumentView, WebDocumentText, WebDocumentElement, WebDocumentSelection>
+@interface WebTextView : WebSearchableTextView <WebDocumentView, WebDocumentText, WebDocumentElement>
{
float _textSizeMultiplier;
}
return [webView _menuForElement:[self _elementAtWindowPoint:[event locationInWindow]] defaultItems:nil];
}
-- (NSArray *)pasteboardTypesForSelection
-{
- return [self writablePasteboardTypes];
-}
-
-- (void)writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard
-{
- [self writeSelectionToPasteboard:pasteboard types:types];
-}
-
// This approach could be relaxed when dealing with 3228554
- (BOOL)resignFirstResponder
{