Changeset 167 for trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEWebKit.m
- Timestamp:
- 04/18/05 05:30:49 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEWebKit.m
r106 r167 11 11 12 12 // from WebCoreBridge.h 13 @interface WebCoreBridge 13 @interface WebCoreBridge : NSObject 14 14 15 15 - (NSDictionary *)elementAtPoint:(NSPoint)point; 16 17 - (void)setSelectionFrom:(id /* WebDOMNode */)start startOffset:(int)startOffset to:(id /* WebDOMNode */)end endOffset:(int) endOffset; 16 - (NSString *)selectedString; 18 17 - (void)deselectAll; 19 18 20 - (void)forceLayout; 21 22 - (NSString *)selectedString; 19 // only in Safari 1.0-1.2 20 - (void)setSelectionFrom:(id /* WebDOMNode */)start startOffset:(int)startOffset to:(id /* WebDOMNode */)end endOffset:(int) endOffset; 23 21 24 22 - (id /* WebDOMNode */)selectionStart; … … 27 25 - (int)selectionEndOffset; 28 26 27 // only in Safari 1.1-1.2 28 - (NSRect)selectionRect; 29 30 // only in Safari 1.3 31 - (void)selectNSRange:(NSRange)range; 32 29 33 @end 30 34 31 // from WebKit, not yet public32 @interface WebHTMLView 35 // from WebKit, private 36 @interface WebHTMLView : NSObject 33 37 34 38 - (WebCoreBridge *)_bridge; 35 - (NSDictionary *)_elementAtPoint:(NSPoint)point; 39 40 // only in Safari 1.3 41 - (NSRange)selectedRange; 36 42 37 43 @end … … 46 52 47 53 static NSEvent *downEvent = nil; 54 55 // used in Safari < 1.3 because there's no sane way to set the selection 48 56 typedef struct { 49 57 int startOffset; … … 52 60 id toNode; 53 61 } ICCF_WebCoreSelection; 54 static NSString *selectedString = nil; // XXX remove when we can do this properly55 62 56 63 static ICCF_WebCoreSelection selection = {nil, nil, 0, 0}; … … 61 68 ioSel->startOffset = [bridge selectionStartOffset]; 62 69 ioSel->endOffset = [bridge selectionEndOffset]; 63 if (ioSel->startOffset != 0 && ioSel->endOffset != 0) { 64 ioSel->fromNode = [[bridge selectionStart] retain]; 65 ioSel->toNode = [[bridge selectionEnd] retain]; 66 } 70 ioSel->fromNode = [[bridge selectionStart] retain]; 71 ioSel->toNode = [[bridge selectionEnd] retain]; 67 72 } 68 73 … … 75 80 endOffset: inSel->endOffset]; 76 81 } 82 // end Safari < 1.3 section 83 84 static NSString *selectedString = nil; 85 static NSRange selectedRange; 77 86 78 87 - (void)mouseDown:(NSEvent *)e; 79 88 { 89 [downEvent release]; downEvent = nil; 80 90 // don't want command-option-click, command-shift-click, etc. to trigger 81 91 if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) { 82 // save selection: it will be deselected on super mouseDown83 92 WebCoreBridge *bridge = [(WebHTMLView *)self _bridge]; 84 ICCF_GetWebCoreBridgeSelection(bridge, &selection); 85 ICLog(@"selection start %d@%@ end %d@%@ string %@", [bridge selectionStartOffset], [bridge selectionStart], [bridge selectionEndOffset], [bridge selectionEnd], [bridge selectedString]); 86 // XXX hack until we have something better 87 [selectedString release]; selectedString = nil; 88 selectedString = [[bridge selectedString] retain]; 89 downEvent = e; 90 } else { 91 downEvent = nil; 93 if ([self respondsToSelector: @selector(selectedRange)]) { 94 // Safari 1.3 save selection: it may be deselected on super mouseDown 95 selectedRange = [(WebHTMLView *)self selectedRange]; 96 } else if ([bridge respondsToSelector: @selector(selectionStartOffset)]) { 97 // Safari < 1.3 save selection: it will be deselected on super mouseDown 98 ICCF_GetWebCoreBridgeSelection(bridge, &selection); 99 ICLog(@"selection start %d@%@ end %d@%@ string %@", [bridge selectionStartOffset], [bridge selectionStart], [bridge selectionEndOffset], [bridge selectionEnd], [bridge selectedString]); 100 } 101 [selectedString release]; selectedString = nil; 102 selectedString = [[bridge selectedString] retain]; 103 downEvent = [e retain]; 92 104 } 93 105 [super mouseDown: e]; … … 100 112 NSPoint downPt = [downEvent locationInWindow]; 101 113 NSPoint upPt = [e locationInWindow]; 102 114 [downEvent release]; downEvent = nil; 103 115 if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels) 104 116 return; … … 107 119 WebCoreBridge *bridge = [(WebHTMLView *)self _bridge]; 108 120 NSPoint viewClickPt = [self convertPoint: downPt fromView: nil]; 109 NSDictionary *elementDict = [ (WebHTMLView *)self _elementAtPoint: viewClickPt];121 NSDictionary *elementDict = [bridge elementAtPoint: viewClickPt]; 110 122 ICLog(@"elementDict: %@", elementDict); 111 NSAssert([elementDict count] != 0, @" ShouldnÕt get empty element dictionary"); // XXX clarify123 NSAssert([elementDict count] != 0, @"Internal error: Got empty element dictionary from WebHTMLView"); 112 124 if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) { 113 125 ICLog(@"got a link"); 114 126 NS_VOIDRETURN; // donÕt activate on links 115 127 } 116 if (selectedString == nil || [selectedString length] == 0) 117 NS_VOIDRETURN; 118 // XXX works, but doesn't update 119 ICCF_StartIC(); 120 ICCF_LaunchURL(selectedString, ICCF_KeyboardAction()); 121 // breaks in Safari v62 and before 122 ICCF_SetWebCoreBridgeSelection(bridge, &selection); 123 if (ICCF_prefs.textBlinkEnabled) { 124 int i; 125 for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) { 126 [bridge deselectAll]; 127 usleep(kICBlinkDelayUsecs); 128 ICCF_SetWebCoreBridgeSelection(bridge, &selection); 129 usleep(kICBlinkDelayUsecs); 130 } 131 } 128 if (selectedString == nil || [selectedString length] == 0) { 129 ICLog(@"no selected string"); 130 NS_VOIDRETURN; 131 } 132 ICCF_StartIC(); 133 // ICCF_LaunchURL(selectedString, ICCF_KeyboardAction()); 134 if (ICCF_prefs.textBlinkEnabled && 135 [bridge respondsToSelector: @selector(selectNSRange:)]) { 136 // blink text in Safari 1.3 137 [bridge selectNSRange: selectedRange]; 138 int i; 139 NSRect selectionRect = [bridge selectionRect]; 140 ICLog(@"selectedRange %@ selectionRect %@ textBlinkCount %d", NSStringFromRange(selectedRange), NSStringFromRect(selectionRect), ICCF_prefs.textBlinkCount); 141 for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) { 142 [bridge deselectAll]; 143 [self setNeedsDisplayInRect: selectionRect]; 144 [self display]; 145 usleep(kICBlinkDelayUsecs); 146 [bridge selectNSRange: selectedRange]; 147 [self setNeedsDisplayInRect: selectionRect]; 148 [self display]; 149 usleep(kICBlinkDelayUsecs); 150 } 151 } else { 152 // select text in Safari 1.0-1.2 153 ICCF_SetWebCoreBridgeSelection(bridge, &selection); 154 if (ICCF_prefs.textBlinkEnabled && 155 [bridge respondsToSelector: @selector(selectionRect)]) { 156 // blink text in Safari 1.1/1.2 157 int i; 158 NSRect selectionRect = [bridge selectionRect]; 159 for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) { 160 [bridge deselectAll]; 161 [self setNeedsDisplayInRect: selectionRect]; 162 [self display]; 163 usleep(kICBlinkDelayUsecs); 164 ICCF_SetWebCoreBridgeSelection(bridge, &selection); 165 [self setNeedsDisplayInRect: selectionRect]; 166 [self display]; 167 usleep(kICBlinkDelayUsecs); 168 } 169 } 170 } 132 171 NS_HANDLER 133 172 ICCF_HandleException(localException); … … 135 174 136 175 ICCF_StopIC(); 137 // XXX need to release fromNode, toNode138 139 // [bridge forceLayout];140 // ICLog(@"force start %d end %d string %@", [bridge selectionStartOffset], [bridge selectionEndOffset], [bridge selectedString]);141 142 // check selected string, first143 // fabricate triple-click, examine selected string144 145 // setSelectionFrom:startOffset:to:endOffset:146 147 // ICCF_LaunchURLFromTextView(self);148 176 } 149 177 } 150 178 151 152 153 179 @end
Note:
See TracChangeset
for help on using the changeset viewer.