Changeset 455 for trunk/ICeCoffEE
- Timestamp:
- 03/27/08 20:49:14 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEWebKit.m
r449 r455 14 14 #import <unistd.h> 15 15 16 // XXX WebCoreFrameBridge is going away17 // (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 18 18 @interface WebCoreFrameBridge : NSObject 19 20 // XXX move to DOM-based accessors21 19 - (DOMRange *)convertNSRangeToDOMRange:(NSRange)range; 22 20 - (NSString *)stringForRange:(DOMRange *)range; 23 24 21 @end 25 22 … … 83 80 84 81 WebView *webView = [(WebHTMLView *)self _webView]; 85 BOOL isEditable = [webView isEditable]; 82 BOOL webViewIsEditable = [webView isEditable]; 83 BOOL elementIsEditable = YES; // don't restore 86 84 BOOL isContinuousSpellCheckingEnabled = NO, isGrammarCheckingEnabled = NO; 87 85 88 if ( isEditable) {86 if (webViewIsEditable) { 89 87 [webView setPolicyDelegate: policyDelegate]; 90 88 [policyDelegate release]; policyDelegate = nil; … … 97 95 98 96 @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"); 100 106 [webView setEditable: YES]; 101 107 … … 118 124 } 119 125 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 } 126 133 127 134 id link = [elementDict objectForKey: @"WebElementLinkURL"]; 128 135 NSString *url = [link isKindOfClass: [NSURL class]] ? [link absoluteString] : nil; 129 136 130 137 ICCF_StartIC(); 131 138 … … 134 141 if (url != nil) { 135 142 ICLog(@"got a link"); 136 if (! isEditable) {143 if (!elementIsEditable) { 137 144 ICCF_StopIC(); 138 145 return; … … 140 147 // XXX handle existing selection 141 148 domRange = [webView selectedDOMRange]; 142 [domRange selectNode: [elementDict objectForKey:@"WebElementDOMNode"]];149 [domRange selectNode: clickedNode]; 143 150 [webView setSelectedDOMRange: domRange affinity: NSSelectionAffinityDownstream]; 144 151 } else { 145 // may have become deselected in mouseDown146 152 if (!elementIsEditable) // may have become deselected in mouseDown 153 [webView setSelectedDOMRange: selectedRange affinity: NSSelectionAffinityDownstream]; 147 154 148 155 NSRange range = [ICeCoffEETrigger rangeForEvent: downEvent onTarget: (NSView<NSTextInput> *)self]; 149 150 156 NSAssert(range.location != NSNotFound, ICCF_LocalizedString(@"Sorry, ICeCoffEE was unable to find anything to select")); 151 157 158 WebCoreFrameBridge *bridge = [(WebHTMLView *)self _bridge]; 159 152 160 // 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 156 167 if (range.length == 0) { 157 168 range.length = 1; … … 184 195 [selectedRange release]; selectedRange = nil; 185 196 [downEvent release]; downEvent = nil; 186 if (! isEditable) {197 if (!elementIsEditable && !webViewIsEditable) { 187 198 [webView setEditable: NO]; 188 199 if (isContinuousSpellCheckingEnabled)
Note:
See TracChangeset
for help on using the changeset viewer.