Reviewed by Darin
authorsullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2007 00:30:29 +0000 (00:30 +0000)
committersullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2007 00:30:29 +0000 (00:30 +0000)
        - WebKit part of <rdar://problem/5293820>, needed to support multiple matches in PDFs

        * WebView/WebDocumentInternal.h:
        Added WebMultipleTextMatches protocol, containing five methods that were formerly implemented in WebHTMLView
        * WebView/WebHTMLViewPrivate.h:
        Removed declarations for the methods that are now in WebMultipleTextMatches protocol

        * WebView/WebHTMLView.mm:
        (-[WebHTMLView markAllMatchesForText:caseSensitive:limit:]):
        moved this method into the WebDocumentInternalProtocols portion of the file
        (-[WebHTMLView setMarkedTextMatchesAreHighlighted:]):
        ditto
        (-[WebHTMLView markedTextMatchesAreHighlighted]):
        ditto
        (-[WebHTMLView unmarkAllTextMatches]):
        ditto
        (-[WebHTMLView rectsForTextMatches]):
        ditto

        * WebView/WebView.mm:
        (-[WebView canMarkAllTextMatches]):
        new method, returns YES only if the documentView of every frame implements WebMultipleTextMatches
        (-[WebView markAllMatchesForText:caseSensitive:highlight:limit:]):
        check for WebMultipleTextMatches protocol instead of checking for WebHTMLView class
        (-[WebView unmarkAllTextMatches]):
        ditto
        (-[WebView rectsForTextMatches]):
        ditto

        * WebView/WebViewPrivate.h:
        declared new method canMarkAllTextMatches

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@23774 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/WebView/WebDocumentInternal.h
WebKit/WebView/WebHTMLView.mm
WebKit/WebView/WebHTMLViewPrivate.h
WebKit/WebView/WebView.mm
WebKit/WebView/WebViewPrivate.h

index aa428fb..91ee876 100644 (file)
@@ -2,6 +2,42 @@
 
         Reviewed by Darin
         
 
         Reviewed by Darin
         
+        - WebKit part of <rdar://problem/5293820>, needed to support multiple matches in PDFs
+
+        * WebView/WebDocumentInternal.h:
+        Added WebMultipleTextMatches protocol, containing five methods that were formerly implemented in WebHTMLView
+        * WebView/WebHTMLViewPrivate.h:
+        Removed declarations for the methods that are now in WebMultipleTextMatches protocol
+        
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView markAllMatchesForText:caseSensitive:limit:]):
+        moved this method into the WebDocumentInternalProtocols portion of the file
+        (-[WebHTMLView setMarkedTextMatchesAreHighlighted:]):
+        ditto
+        (-[WebHTMLView markedTextMatchesAreHighlighted]):
+        ditto
+        (-[WebHTMLView unmarkAllTextMatches]):
+        ditto
+        (-[WebHTMLView rectsForTextMatches]):
+        ditto
+
+        * WebView/WebView.mm:
+        (-[WebView canMarkAllTextMatches]):
+        new method, returns YES only if the documentView of every frame implements WebMultipleTextMatches
+        (-[WebView markAllMatchesForText:caseSensitive:highlight:limit:]):
+        check for WebMultipleTextMatches protocol instead of checking for WebHTMLView class
+        (-[WebView unmarkAllTextMatches]):
+        ditto
+        (-[WebView rectsForTextMatches]):
+        ditto
+
+        * WebView/WebViewPrivate.h:
+        declared new method canMarkAllTextMatches
+
+2007-06-25  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Darin
+        
         Fixed <rdar://problem/5292259> Find on Page doesn't work (throws exception) on page that includes PDF in a subframe
 
         * WebView/WebView.mm:
         Fixed <rdar://problem/5292259> Find on Page doesn't work (throws exception) on page that includes PDF in a subframe
 
         * WebView/WebView.mm:
index 0182821..1426526 100644 (file)
 #import <WebKit/WebDocumentPrivate.h>
 #import <WebKit/WebHTMLView.h>
 
 #import <WebKit/WebDocumentPrivate.h>
 #import <WebKit/WebHTMLView.h>
 
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
+#define WebNSUInteger unsigned int
+#else
+#define WebNSUInteger NSUInteger
+#endif
+
 /*!
 @protocol _WebDocumentTextSizing
 @discussion Optional protocol for making text larger and smaller.
 /*!
 @protocol _WebDocumentTextSizing
 @discussion Optional protocol for making text larger and smaller.
 - (NSDictionary *)elementAtPoint:(NSPoint)point allowShadowContent:(BOOL)allow;
 @end
 
 - (NSDictionary *)elementAtPoint:(NSPoint)point allowShadowContent:(BOOL)allow;
 @end
 
+@protocol WebMultipleTextMatches <NSObject>
+- (void)setMarkedTextMatchesAreHighlighted:(BOOL)newValue;
+- (BOOL)markedTextMatchesAreHighlighted;
+- (WebNSUInteger)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag limit:(WebNSUInteger)limit;
+- (void)unmarkAllTextMatches;
+- (NSArray *)rectsForTextMatches;
+@end
+
+
 /* Used to save and restore state in the view, typically when going back/forward */
 @protocol _WebDocumentViewState <NSObject>
 - (NSPoint)scrollPoint;
 /* Used to save and restore state in the view, typically when going back/forward */
 @protocol _WebDocumentViewState <NSObject>
 - (NSPoint)scrollPoint;
@@ -69,5 +84,5 @@
 - (void)setViewState:(id)statePList;
 @end
 
 - (void)setViewState:(id)statePList;
 @end
 
-@interface WebHTMLView (WebDocumentInternalProtocols) <WebDocumentElement>
+@interface WebHTMLView (WebDocumentInternalProtocols) <WebDocumentElement, WebMultipleTextMatches>
 @end
 @end
index 12f7ec0..155382b 100644 (file)
@@ -1587,31 +1587,6 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart)
     frame->setWindowHasFocus(frame == focusedFrame && windowOrSheetIsKey);
 }
 
     frame->setWindowHasFocus(frame == focusedFrame && windowOrSheetIsKey);
 }
 
-- (unsigned)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag limit:(unsigned)limit
-{
-    return [[self _bridge] markAllMatchesForText:string caseSensitive:caseFlag limit:limit];
-}
-
-- (void)setMarkedTextMatchesAreHighlighted:(BOOL)newValue
-{
-    [[self _bridge] setMarkedTextMatchesAreHighlighted:newValue];
-}
-
-- (BOOL)markedTextMatchesAreHighlighted
-{
-    return [[self _bridge] markedTextMatchesAreHighlighted];
-}
-
-- (void)unmarkAllTextMatches
-{
-    return [[self _bridge] unmarkAllTextMatches];
-}
-
-- (NSArray *)rectsForTextMatches
-{
-    return [[self _bridge] rectsForTextMatches];
-}
-
 - (void)_writeSelectionToPasteboard:(NSPasteboard *)pasteboard
 {
     ASSERT([self _hasSelection]);
 - (void)_writeSelectionToPasteboard:(NSPasteboard *)pasteboard
 {
     ASSERT([self _hasSelection]);
@@ -5986,6 +5961,31 @@ BOOL isTextInput(Frame *coreFrame)
     return nil;
 }
 
     return nil;
 }
 
+- (unsigned)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag limit:(unsigned)limit
+{
+    return [[self _bridge] markAllMatchesForText:string caseSensitive:caseFlag limit:limit];
+}
+
+- (void)setMarkedTextMatchesAreHighlighted:(BOOL)newValue
+{
+    [[self _bridge] setMarkedTextMatchesAreHighlighted:newValue];
+}
+
+- (BOOL)markedTextMatchesAreHighlighted
+{
+    return [[self _bridge] markedTextMatchesAreHighlighted];
+}
+
+- (void)unmarkAllTextMatches
+{
+    return [[self _bridge] unmarkAllTextMatches];
+}
+
+- (NSArray *)rectsForTextMatches
+{
+    return [[self _bridge] rectsForTextMatches];
+}
+
 @end
 
 // This is used by AppKit and is included here so that WebDataProtocolScheme is only defined once.
 @end
 
 // This is used by AppKit and is included here so that WebDataProtocolScheme is only defined once.
index 1b0c902..26285fc 100644 (file)
 // SPI for DumpRenderTree
 - (void)_updateActiveState;
 
 // SPI for DumpRenderTree
 - (void)_updateActiveState;
 
-// Support for displaying multiple text matches.
-// These methods might end up moving into a protocol, so different document types can specify
-// whether or not they implement the protocol.
-// These methods are still in flux; don't rely on them yet.
-- (unsigned)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag limit:(unsigned)limit;
-- (void)unmarkAllTextMatches;
-- (void)setMarkedTextMatchesAreHighlighted:(BOOL)newValue;
-- (BOOL)markedTextMatchesAreHighlighted;
-- (NSArray *)rectsForTextMatches;
 @end
 @end
index a06d1b7..216dbe2 100644 (file)
@@ -2903,18 +2903,31 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
     return [[[self mainFrame] _bridge] aeDescByEvaluatingJavaScriptFromString:script];
 }
 
     return [[[self mainFrame] _bridge] aeDescByEvaluatingJavaScriptFromString:script];
 }
 
+- (BOOL)canMarkAllTextMatches
+{
+    WebFrame *frame = [self mainFrame];
+    do {
+        id <WebDocumentView> view = [[frame frameView] documentView];
+        if (view && ![view conformsToProtocol:@protocol(WebMultipleTextMatches)])
+            return NO;
+        
+        frame = incrementFrame(frame, YES, NO);
+    } while (frame);
+    
+    return YES;
+}
+
 - (WebNSUInteger)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag highlight:(BOOL)highlight limit:(WebNSUInteger)limit
 {
     WebFrame *frame = [self mainFrame];
     unsigned matchCount = 0;
     do {
         id <WebDocumentView> view = [[frame frameView] documentView];
 - (WebNSUInteger)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag highlight:(BOOL)highlight limit:(WebNSUInteger)limit
 {
     WebFrame *frame = [self mainFrame];
     unsigned matchCount = 0;
     do {
         id <WebDocumentView> view = [[frame frameView] documentView];
-        // FIXME: introduce a protocol, or otherwise make this work with other types
-        if ([view isKindOfClass:[WebHTMLView class]]) {
-            [(WebHTMLView *)view setMarkedTextMatchesAreHighlighted:highlight];
+        if ([view conformsToProtocol:@protocol(WebMultipleTextMatches)]) {
+            [(NSView <WebMultipleTextMatches>*)view  setMarkedTextMatchesAreHighlighted:highlight];
         
             ASSERT(limit == 0 || matchCount < limit);
         
             ASSERT(limit == 0 || matchCount < limit);
-            matchCount += [(WebHTMLView *)view markAllMatchesForText:string caseSensitive:caseFlag limit:limit == 0 ? 0 : limit - matchCount];
+            matchCount += [(NSView <WebMultipleTextMatches>*)view markAllMatchesForText:string caseSensitive:caseFlag limit:limit == 0 ? 0 : limit - matchCount];
 
             // Stop looking if we've reached the limit. A limit of 0 means no limit.
             if (limit > 0 && matchCount >= limit)
 
             // Stop looking if we've reached the limit. A limit of 0 means no limit.
             if (limit > 0 && matchCount >= limit)
@@ -2932,9 +2945,8 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
     WebFrame *frame = [self mainFrame];
     do {
         id <WebDocumentView> view = [[frame frameView] documentView];
     WebFrame *frame = [self mainFrame];
     do {
         id <WebDocumentView> view = [[frame frameView] documentView];
-        // FIXME: introduce a protocol, or otherwise make this work with other types
-        if ([view isKindOfClass:[WebHTMLView class]])
-            [(WebHTMLView *)view unmarkAllTextMatches];
+        if ([view conformsToProtocol:@protocol(WebMultipleTextMatches)])
+            [(NSView <WebMultipleTextMatches>*)view unmarkAllTextMatches];
         
         frame = incrementFrame(frame, YES, NO);
     } while (frame);
         
         frame = incrementFrame(frame, YES, NO);
     } while (frame);
@@ -2946,23 +2958,22 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
     WebFrame *frame = [self mainFrame];
     do {
         id <WebDocumentView> view = [[frame frameView] documentView];
     WebFrame *frame = [self mainFrame];
     do {
         id <WebDocumentView> view = [[frame frameView] documentView];
-        // FIXME: introduce a protocol, or otherwise make this work with other types
-        if ([view isKindOfClass:[WebHTMLView class]]) {
-            WebHTMLView *htmlView = (WebHTMLView *)view;
-            NSRect htmlViewVisibleRect = [htmlView visibleRect];
-            NSArray *originalRects = [htmlView rectsForTextMatches];
+        if ([view conformsToProtocol:@protocol(WebMultipleTextMatches)]) {
+            NSView <WebMultipleTextMatches> *documentView = (NSView <WebMultipleTextMatches> *)view;
+            NSRect documentViewVisibleRect = [documentView visibleRect];
+            NSArray *originalRects = [documentView rectsForTextMatches];
             unsigned rectCount = [originalRects count];
             unsigned rectIndex;
             NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
             for (rectIndex = 0; rectIndex < rectCount; ++rectIndex) {
                 NSRect r = [[originalRects objectAtIndex:rectIndex] rectValue];
             unsigned rectCount = [originalRects count];
             unsigned rectIndex;
             NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
             for (rectIndex = 0; rectIndex < rectCount; ++rectIndex) {
                 NSRect r = [[originalRects objectAtIndex:rectIndex] rectValue];
-                // Clip rect to HTMLView's visible rect so rect is confined to subframe
-                r = NSIntersectionRect(r, htmlViewVisibleRect);
+                // Clip rect to document view's visible rect so rect is confined to subframe
+                r = NSIntersectionRect(r, documentViewVisibleRect);
                 if (NSIsEmptyRect(r))
                     continue;
                 
                 // Convert rect to our coordinate system
                 if (NSIsEmptyRect(r))
                     continue;
                 
                 // Convert rect to our coordinate system
-                r = [htmlView convertRect:r toView:self];
+                r = [documentView convertRect:r toView:self];
                 [result addObject:[NSValue valueWithRect:r]];
                 if (rectIndex % 10 == 0) {
                     [pool drain];
                 [result addObject:[NSValue valueWithRect:r]];
                 if (rectIndex % 10 == 0) {
                     [pool drain];
index 9f91d57..c525d21 100644 (file)
@@ -227,6 +227,7 @@ typedef enum {
 // These methods might end up moving into a protocol, so different document types can specify
 // whether or not they implement the protocol. For now we'll just deal with HTML.
 // These methods are still in flux; don't rely on them yet.
 // These methods might end up moving into a protocol, so different document types can specify
 // whether or not they implement the protocol. For now we'll just deal with HTML.
 // These methods are still in flux; don't rely on them yet.
+- (BOOL)canMarkAllTextMatches;
 - (WebNSUInteger)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag highlight:(BOOL)highlight limit:(WebNSUInteger)limit;
 - (void)unmarkAllTextMatches;
 - (NSArray *)rectsForTextMatches;
 - (WebNSUInteger)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag highlight:(BOOL)highlight limit:(WebNSUInteger)limit;
 - (void)unmarkAllTextMatches;
 - (NSArray *)rectsForTextMatches;