[webkit-changes] cvs commit: WebKit/WebView.subproj WebDefaultContextMenuDelegate.m WebHTMLView.m WebPDFView.h WebPDFView.m WebView.m

John sullivan at opensource.apple.com
Mon Jul 18 16:18:24 PDT 2005


sullivan    05/07/18 16:18:23

  Modified:    .        ChangeLog
               WebView.subproj WebDefaultContextMenuDelegate.m
                        WebHTMLView.m WebPDFView.h WebPDFView.m WebView.m
  Log:
          Reviewed by Darin Adler.
  
          - fixed these bugs:
          <rdar://problem/4158121> context menu in PDF view should contain the selection-based items like Copy
          <rdar://problem/4184691> WebPDFView should conform to the WebDocumentElement protocol
          <rdar://problem/4184663> "Search in Spotlight" is present but dimmed in context menu for plain-text documents
  
          * WebView.subproj/WebDefaultContextMenuDelegate.m:
          (-[WebDefaultUIDelegate contextMenuItemsForElement:defaultMenuItems:]):
          added ASSERT and comments
  
          * WebView.subproj/WebHTMLView.m:
          (-[WebHTMLView _searchWithGoogleFromMenu:]):
          removed this method (now handled by WebView)
          (-[WebHTMLView _searchWithSpotlightFromMenu:]):
          ditto
          (-[WebHTMLView validateUserInterfaceItem:]):
          removed validation for removed items. The validation wasn't necessary anyway, since we only put these items
          in the menu in the case where they should be enabled.
  
          * WebView.subproj/WebPDFView.h:
          now conforms to WebDocumentElement protocol (which lets [WebView elementAtPoint:] work better)
          * WebView.subproj/WebPDFView.m:
          (-[WebPDFView copy:]):
          added, hands off to PDFView, needed to enable Copy in context menu
          (-[WebPDFView _pointIsInSelection:]):
          new method, checks whether given point is in the selected bounds
          (-[WebPDFView elementAtPoint:]):
          add WebElementIsSelectedKey to returned element
          (-[WebPDFView menuForEvent:]):
          use actual point instead of dummy placeholder, now that we have code that pays attention to the point
  
          * WebView.subproj/WebView.m:
          (-[WebView _searchWithGoogleFromMenu:]):
          moved here from WebHTMLView so it will work for any documentView that conforms to WebDocumentText.
          Rewrote slightly to be non-WebHTMLView-specific. (This menu item was always enabled in Safari because
          Safari replaces its action, but it would not have been always enabled in other WebKit clients, though
          it should have been.)
          (-[WebView _searchWithSpotlightFromMenu:]):
          moved here from WebHTMLView so it will work for any documentView that conforms to WebDocumentText.
          Rewrote slightly to be non-WebHTMLView-specific.
  
  Revision  Changes    Path
  1.3235    +44 -0     WebKit/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebKit/ChangeLog,v
  retrieving revision 1.3234
  retrieving revision 1.3235
  diff -u -r1.3234 -r1.3235
  --- ChangeLog	18 Jul 2005 20:36:49 -0000	1.3234
  +++ ChangeLog	18 Jul 2005 23:18:19 -0000	1.3235
  @@ -1,5 +1,49 @@
   2005-07-18  John Sullivan  <sullivan at apple.com>
   
  +        Reviewed by Darin Adler.
  +
  +        - fixed these bugs:
  +        <rdar://problem/4158121> context menu in PDF view should contain the selection-based items like Copy
  +        <rdar://problem/4184691> WebPDFView should conform to the WebDocumentElement protocol
  +        <rdar://problem/4184663> "Search in Spotlight" is present but dimmed in context menu for plain-text documents
  +
  +        * WebView.subproj/WebDefaultContextMenuDelegate.m:
  +        (-[WebDefaultUIDelegate contextMenuItemsForElement:defaultMenuItems:]):
  +        added ASSERT and comments
  +
  +        * WebView.subproj/WebHTMLView.m:
  +        (-[WebHTMLView _searchWithGoogleFromMenu:]):
  +        removed this method (now handled by WebView)
  +        (-[WebHTMLView _searchWithSpotlightFromMenu:]):
  +        ditto
  +        (-[WebHTMLView validateUserInterfaceItem:]):
  +        removed validation for removed items. The validation wasn't necessary anyway, since we only put these items
  +        in the menu in the case where they should be enabled.
  +
  +        * WebView.subproj/WebPDFView.h:
  +        now conforms to WebDocumentElement protocol (which lets [WebView elementAtPoint:] work better)
  +        * WebView.subproj/WebPDFView.m:
  +        (-[WebPDFView copy:]):
  +        added, hands off to PDFView, needed to enable Copy in context menu
  +        (-[WebPDFView _pointIsInSelection:]):
  +        new method, checks whether given point is in the selected bounds
  +        (-[WebPDFView elementAtPoint:]):
  +        add WebElementIsSelectedKey to returned element
  +        (-[WebPDFView menuForEvent:]):
  +        use actual point instead of dummy placeholder, now that we have code that pays attention to the point
  +
  +        * WebView.subproj/WebView.m:
  +        (-[WebView _searchWithGoogleFromMenu:]):
  +        moved here from WebHTMLView so it will work for any documentView that conforms to WebDocumentText.
  +        Rewrote slightly to be non-WebHTMLView-specific. (This menu item was always enabled in Safari because
  +        Safari replaces its action, but it would not have been always enabled in other WebKit clients, though
  +        it should have been.)
  +        (-[WebView _searchWithSpotlightFromMenu:]):
  +        moved here from WebHTMLView so it will work for any documentView that conforms to WebDocumentText.
  +        Rewrote slightly to be non-WebHTMLView-specific.
  +
  +2005-07-18  John Sullivan  <sullivan at apple.com>
  +
           Reviewed by Richard Williamson.
           
           - fixed <rdar://problem/4184366> WebPDFView should conform to the WebDocumentSelection protocol
  
  
  
  1.83      +11 -1     WebKit/WebView.subproj/WebDefaultContextMenuDelegate.m
  
  Index: WebDefaultContextMenuDelegate.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebDefaultContextMenuDelegate.m,v
  retrieving revision 1.82
  retrieving revision 1.83
  diff -u -r1.82 -r1.83
  --- WebDefaultContextMenuDelegate.m	22 Jun 2005 21:32:09 -0000	1.82
  +++ WebDefaultContextMenuDelegate.m	18 Jul 2005 23:18:22 -0000	1.83
  @@ -234,10 +234,20 @@
   #ifndef OMIT_TIGER_FEATURES
               // Add Tiger-only items that act on selected text. Google search needn't be Tiger-only technically,
               // but it's a new Tiger-only feature to have it in the context menu by default.
  +            
  +            // The Spotlight and Google items are implemented in WebView, and require that the
  +            // current document view conforms to WebDocumentText
  +            ASSERT([[[webFrame frameView] documentView] conformsToProtocol:@protocol(WebDocumentText)]);
               [menuItems addObject:[self menuItemWithTag:WebMenuItemTagSearchInSpotlight]];
               [menuItems addObject:[self menuItemWithTag:WebMenuItemTagSearchInGoogle]];
               [menuItems addObject:[NSMenuItem separatorItem]];
  -            [menuItems addObject:[self menuItemWithTag:WebMenuItemTagLookUpInDictionary]];
  +
  +            // FIXME 4184640: The Look Up in Dictionary item is only implemented in WebHTMLView, and so is present but
  +            // dimmed for other cases where WebElementIsSelectedKey is present. It would probably 
  +            // be better not to include it in the menu if the documentView isn't a WebHTMLView, but that could break 
  +            // existing clients that have code that relies on it being present (unlikely for clients outside of Apple, 
  +            // but Safari has such code).
  +            [menuItems addObject:[self menuItemWithTag:WebMenuItemTagLookUpInDictionary]];            
               [menuItems addObject:[NSMenuItem separatorItem]];
   #endif
               [menuItems addObject:[self menuItemWithTag:WebMenuItemTagCopy]];
  
  
  
  1.459     +1 -25     WebKit/WebView.subproj/WebHTMLView.m
  
  Index: WebHTMLView.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebHTMLView.m,v
  retrieving revision 1.458
  retrieving revision 1.459
  diff -u -r1.458 -r1.459
  --- WebHTMLView.m	18 Jul 2005 20:36:53 -0000	1.458
  +++ WebHTMLView.m	18 Jul 2005 23:18:22 -0000	1.459
  @@ -1540,29 +1540,7 @@
   }
   
   #ifndef OMIT_TIGER_FEATURES
  -- (void)_searchWithGoogleFromMenu:(id)sender
  -{
  -    // This should only be called when there's a selection, but play it safe.
  -    if (![self _hasSelection]) {
  -        return;
  -    }
  -    
  -    NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
  -    if ([self writeSelectionToPasteboard:pboard types:[NSArray arrayWithObject:NSStringPboardType]]) {
  -        // FIXME: seems fragile to use the service by name, but this is what AppKit does
  -        NSPerformService(@"Search With Google", pboard);
  -    }
  -}
   
  -- (void)_searchWithSpotlightFromMenu:(id)sender
  -{
  -    // This should only be called when there's a selection, but play it safe.
  -    if (![self _hasSelection]) {
  -        return;
  -    }
  -
  -    (void)HISearchWindowShow((CFStringRef)[self selectedString], kNilOptions);
  -}
   - (void)_lookUpInDictionaryFromMenu:(id)sender
   {
       // This should only be called when there's a selection, but play it safe.
  @@ -1986,9 +1964,7 @@
           }
           return [self _canEdit];
   #ifndef OMIT_TIGER_FEATURES
  -    } else if (action == @selector(_searchWithSpotlightFromMenu:)
  -               || action == @selector(_searchWithGoogleFromMenu:)
  -               || action == @selector(_lookUpInDictionaryFromMenu:)) {
  +    } else if (action == @selector(_lookUpInDictionaryFromMenu:)) {
           return [self _hasSelection];
   #endif
       }
  
  
  
  1.10      +2 -1      WebKit/WebView.subproj/WebPDFView.h
  
  Index: WebPDFView.h
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebPDFView.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- WebPDFView.h	18 Jul 2005 20:36:53 -0000	1.9
  +++ WebPDFView.h	18 Jul 2005 23:18:22 -0000	1.10
  @@ -33,8 +33,9 @@
   
   @protocol _web_WebDocumentTextSizing;
   @protocol WebDocumentSelection;
  + at protocol WebDocumentElement;
   
  - at interface WebPDFView : NSView <WebDocumentView, WebDocumentSearching, WebDocumentText, _web_WebDocumentTextSizing, WebDocumentSelection>
  + at interface WebPDFView : NSView <WebDocumentView, WebDocumentSearching, WebDocumentText, _web_WebDocumentTextSizing, WebDocumentSelection, WebDocumentElement>
   {
       PDFView *PDFSubview;
       WebDataSource *dataSource;
  
  
  
  1.22      +21 -7     WebKit/WebView.subproj/WebPDFView.m
  
  Index: WebPDFView.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebPDFView.m,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- WebPDFView.m	18 Jul 2005 20:36:53 -0000	1.21
  +++ WebPDFView.m	18 Jul 2005 23:18:22 -0000	1.22
  @@ -113,6 +113,11 @@
       return PDFSubview;
   }
   
  +- (void)copy:(id)sender
  +{
  +    [PDFSubview copy:sender];
  +}
  +
   #define TEMP_PREFIX "/tmp/XXXXXX-"
   #define OBJC_TEMP_PREFIX @"/tmp/XXXXXX-"
   
  @@ -177,16 +182,27 @@
       return [super hitTest:point];
   }
   
  +- (BOOL)_pointIsInSelection:(NSPoint)point
  +{
  +    PDFPage *page = [PDFSubview pageForPoint:point nearest:NO];
  +    if (page == nil) {
  +        return NO;
  +    }
  +    
  +    NSRect selectionRect = [PDFSubview convertRect:[[PDFSubview currentSelection] boundsForPage:page] fromPage:page];
  +    
  +    return NSPointInRect(point, selectionRect);
  +}
  +
   - (NSDictionary *)elementAtPoint:(NSPoint)point
   {
       WebFrame *frame = [dataSource webFrame];
       ASSERT(frame);
   
  -    // FIXME 4158121: should determine whether the point is over a selection, and if so set WebElementIsSelectedKey
  -    // as in WebTextView.m. Would need to convert coordinates, and make sure that the code that checks
  -    // WebElementIsSelectedKey would work with PDF documents.
       return [NSDictionary dictionaryWithObjectsAndKeys:
  -        frame, WebElementFrameKey, nil];
  +        frame, WebElementFrameKey, 
  +        [NSNumber numberWithBool:[self _pointIsInSelection:point]], WebElementIsSelectedKey,
  +        nil];
   }
   
   - (NSMutableArray *)_menuItemsFromPDFKitForEvent:(NSEvent *)theEvent
  @@ -305,9 +321,7 @@
       // pass the items off to the WebKit context menu mechanism
       WebView *webView = [[dataSource webFrame] webView];
       ASSERT(webView);
  -    // Currently clicks anywhere in the PDF view are treated the same, so we just pass NSZeroPoint;
  -    // we implement elementAtPoint: here just to be slightly forward-looking.
  -    NSMenu *menu = [webView _menuForElement:[self elementAtPoint:NSZeroPoint] defaultItems:items];
  +    NSMenu *menu = [webView _menuForElement:[self elementAtPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil]] defaultItems:items];
       
       // The delegate has now had the opportunity to add items to the standard PDF-related items, or to
       // remove or modify some of the PDF-related items. In 10.4, the PDF context menu did not go through 
  
  
  
  1.293     +41 -0     WebKit/WebView.subproj/WebView.m
  
  Index: WebView.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebView.m,v
  retrieving revision 1.292
  retrieving revision 1.293
  diff -u -r1.292 -r1.293
  --- WebView.m	14 Jul 2005 02:43:52 -0000	1.292
  +++ WebView.m	18 Jul 2005 23:18:22 -0000	1.293
  @@ -3004,4 +3004,45 @@
       return responder;
   }
   
  +- (void)_searchWithGoogleFromMenu:(id)sender
  +{
  +    id documentView = [[[self mainFrame] frameView] documentView];
  +    if (![documentView conformsToProtocol:@protocol(WebDocumentText)]) {
  +        return;
  +    }
  +    
  +    NSString *selectedString = [(id <WebDocumentText>)documentView selectedString];
  +    if ([selectedString length] == 0) {
  +        return;
  +    }
  +    
  +    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithUniqueName];
  +    [pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
  +    NSMutableString *s = [selectedString mutableCopy];
  +    const unichar nonBreakingSpaceCharacter = 0xA0;
  +    NSString *nonBreakingSpaceString = [NSString stringWithCharacters:&nonBreakingSpaceCharacter length:1];
  +    [s replaceOccurrencesOfString:nonBreakingSpaceString withString:@" " options:0 range:NSMakeRange(0, [s length])];
  +    [pasteboard setString:s forType:NSStringPboardType];
  +    [s release];
  +    
  +    // FIXME: seems fragile to use the service by name, but this is what AppKit does
  +    NSPerformService(@"Search With Google", pasteboard);
  +}
  +
  +- (void)_searchWithSpotlightFromMenu:(id)sender
  +{
  +    id documentView = [[[self mainFrame] frameView] documentView];
  +    if (![documentView conformsToProtocol:@protocol(WebDocumentText)]) {
  +        return;
  +    }
  +    
  +    NSString *selectedString = [(id <WebDocumentText>)documentView selectedString];
  +    if ([selectedString length] == 0) {
  +        return;
  +    }
  +
  +    (void)HISearchWindowShow((CFStringRef)selectedString, kNilOptions);
  +}
  +
  +
   @end
  
  
  



More information about the webkit-changes mailing list