Changeset 455 for trunk/ICeCoffEE


Ignore:
Timestamp:
03/27/08 20:49:14 (17 years ago)
Author:
Nicholas Riley
Message:

Properly handle form fields and buttons; note WebCoreFrameBridge removal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEWebKit.m

    r449 r455  
    1414#import <unistd.h>
    1515
    16 // XXX WebCoreFrameBridge is going away
    17 // (see <http://trac.webkit.org/projects/webkit/wiki/Maintenance%20and%20architecture%20list>)
     16// Safari 3.1 and earlier (pre-r31014)
     17// eliminated in http://bugs.webkit.org/show_bug.cgi?id=17640
    1818@interface WebCoreFrameBridge : NSObject
    19 
    20 // XXX move to DOM-based accessors
    2119- (DOMRange *)convertNSRangeToDOMRange:(NSRange)range;
    2220- (NSString *)stringForRange:(DOMRange *)range;
    23 
    2421@end
    2522
     
    8380   
    8481    WebView *webView = [(WebHTMLView *)self _webView];
    85     BOOL isEditable = [webView isEditable];
     82    BOOL webViewIsEditable = [webView isEditable];
     83    BOOL elementIsEditable = YES; // don't restore
    8684    BOOL isContinuousSpellCheckingEnabled = NO, isGrammarCheckingEnabled = NO;
    8785
    88     if (isEditable) {
     86    if (webViewIsEditable) {
    8987        [webView setPolicyDelegate: policyDelegate];
    9088        [policyDelegate release]; policyDelegate = nil;
     
    9795
    9896    @try {
    99         if (!isEditable) {
     97        NSPoint viewClickPt = [webView convertPoint: downPt fromView: nil];
     98        NSDictionary *elementDict = [webView elementAtPoint: viewClickPt];
     99        ICLog(@"elementDict: %@", elementDict);
     100
     101        NSAssert([elementDict count] != 0, ICCF_LocalizedString(@"Sorry, ICeCoffEE was unable to find anything to select"));
     102
     103        elementIsEditable = [[elementDict objectForKey: @"WebElementIsContentEditableKey"] boolValue];
     104        if (!elementIsEditable) {
     105            NSAssert(!webViewIsEditable, @"Internal error: uneditable element inside editable WebView");
    100106            [webView setEditable: YES];
    101107       
     
    118124        }
    119125
    120         NSPoint viewClickPt = [webView convertPoint: downPt fromView: nil];
    121         NSDictionary *elementDict = [webView elementAtPoint: viewClickPt];
    122         NSLog(@"elementDict: %@", elementDict);
    123         NSAssert([elementDict count] != 0, ICCF_LocalizedString(@"Sorry, ICeCoffEE was unable to find anything to select"));
    124        
    125         WebCoreFrameBridge *bridge = [(WebHTMLView *)self _bridge];
     126        DOMNode *clickedNode = [elementDict objectForKey: @"WebElementDOMNode"];
     127       
     128        if (!elementIsEditable && ([clickedNode isKindOfClass: NSClassFromString(@"DOMHTMLInputElement")] ||
     129            [clickedNode isKindOfClass: NSClassFromString(@"DOMHTMLFieldSetElement")])) {
     130            ICLog(@"got an uneditable form field (e.g., button)");
     131            return;
     132        }
    126133
    127134        id link = [elementDict objectForKey: @"WebElementLinkURL"];
    128135        NSString *url = [link isKindOfClass: [NSURL class]] ? [link absoluteString] : nil;
    129 
     136       
    130137        ICCF_StartIC();
    131138       
     
    134141        if (url != nil) {
    135142            ICLog(@"got a link");
    136             if (!isEditable) {
     143            if (!elementIsEditable) {
    137144                ICCF_StopIC();
    138145                return;
     
    140147            // XXX handle existing selection
    141148            domRange = [webView selectedDOMRange];
    142             [domRange selectNode: [elementDict objectForKey:@"WebElementDOMNode"]];
     149            [domRange selectNode: clickedNode];
    143150            [webView setSelectedDOMRange: domRange affinity: NSSelectionAffinityDownstream];
    144151        } else {
    145             // may have become deselected in mouseDown
    146             [webView setSelectedDOMRange: selectedRange affinity: NSSelectionAffinityDownstream];
     152            if (!elementIsEditable) // may have become deselected in mouseDown
     153                [webView setSelectedDOMRange: selectedRange affinity: NSSelectionAffinityDownstream];
    147154           
    148155            NSRange range = [ICeCoffEETrigger rangeForEvent: downEvent onTarget: (NSView<NSTextInput> *)self];
    149            
    150156            NSAssert(range.location != NSNotFound, ICCF_LocalizedString(@"Sorry, ICeCoffEE was unable to find anything to select"));
    151157
     158            WebCoreFrameBridge *bridge = [(WebHTMLView *)self _bridge];
     159
    152160            // XXX limit to a reasonable size
    153             // NSRange fetchRange = [bridge convertDOMRangeToNSRange: [(WebHTMLView *)self _documentRange]];
    154             NSString *s = [bridge stringForRange: [(WebHTMLView *)self _documentRange]];
    155        
     161            NSString *s;
     162            if (elementIsEditable) // for form fields, range will be field-relative rather than document-relative
     163                s = [[(NSView<NSTextInput> *)self attributedSubstringFromRange: NSMakeRange(0, UINT_MAX)] string];
     164            else // sometimes attributedSubstringFromRange: returns nil
     165                s = [bridge stringForRange: [(WebHTMLView *)self _documentRange]];
     166           
    156167            if (range.length == 0) {
    157168                range.length = 1;
     
    184195        [selectedRange release]; selectedRange = nil;
    185196        [downEvent release]; downEvent = nil;
    186         if (!isEditable) {
     197        if (!elementIsEditable && !webViewIsEditable) {
    187198            [webView setEditable: NO];
    188199            if (isContinuousSpellCheckingEnabled)
Note: See TracChangeset for help on using the changeset viewer.