[66] | 1 | //
|
---|
| 2 | // ICeCoffEEWebKit.m
|
---|
| 3 | // ICeCoffEE APE
|
---|
| 4 | //
|
---|
| 5 | // Created by Nicholas Riley on Sun Jan 19 2003.
|
---|
| 6 | // Copyright (c) 2003 Nicholas Riley. All rights reserved.
|
---|
| 7 | //
|
---|
| 8 |
|
---|
| 9 | #import "ICeCoffEEWebKit.h"
|
---|
| 10 | #import <unistd.h>
|
---|
| 11 |
|
---|
[320] | 12 | // WebCoreBridge, from WebCoreBridge.h (Safari 2)
|
---|
| 13 | // Web(Core)FrameBridge, from WebCoreFrameBridge.h (Safari 3)
|
---|
[167] | 14 | @interface WebCoreBridge : NSObject
|
---|
[66] | 15 |
|
---|
[320] | 16 | // can only use setMarkedText:selectedRange: if WebHTMLView is editable
|
---|
| 17 | // or, should we move to DOM-based accessors, i.e. "setMarkDOMRange"?
|
---|
[167] | 18 | - (void)selectNSRange:(NSRange)range;
|
---|
| 19 |
|
---|
[66] | 20 | @end
|
---|
| 21 |
|
---|
[320] | 22 | // from WebKit, private -- XXX maybe I'm better off going back the other way, relying on public methods in the bridge?
|
---|
[167] | 23 | @interface WebHTMLView : NSObject
|
---|
[66] | 24 |
|
---|
[320] | 25 | - (NSString *)selectedString;
|
---|
| 26 | - (NSRect)selectionRect;
|
---|
| 27 | - (NSRect)_selectionRect; // Safari 2, supported in Safari 3 only for use with Mail
|
---|
| 28 | - (NSRange)selectedRange; // XXX same as selectedNSRange in WebCoreFrameBridge.h?
|
---|
| 29 | - (void)deselectAll;
|
---|
[66] | 30 |
|
---|
[320] | 31 | - (WebCoreBridge *)_bridge; /* WebFrameBridge in Safari 3 (see above) */
|
---|
[167] | 32 |
|
---|
[216] | 33 | - (NSDictionary *)elementAtPoint:(NSPoint)point;
|
---|
| 34 |
|
---|
[66] | 35 | @end
|
---|
| 36 |
|
---|
| 37 | @implementation ICeCoffEEWebKit
|
---|
| 38 |
|
---|
| 39 | - (NSMenu *)menuForEvent:(NSEvent *)e;
|
---|
| 40 | {
|
---|
| 41 | NSMenu *myMenu = [super menuForEvent: e];
|
---|
| 42 | return ICCF_MenuForEvent(self, myMenu, e);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | static NSEvent *downEvent = nil;
|
---|
[167] | 46 | static NSString *selectedString = nil;
|
---|
| 47 | static NSRange selectedRange;
|
---|
| 48 |
|
---|
[66] | 49 | - (void)mouseDown:(NSEvent *)e;
|
---|
| 50 | {
|
---|
[182] | 51 | [downEvent release]; downEvent = nil;
|
---|
[74] | 52 | if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) {
|
---|
[182] | 53 | if ([self respondsToSelector: @selector(selectedRange)]) {
|
---|
| 54 | // save selection: it may be deselected on super mouseDown
|
---|
| 55 | selectedRange = [(WebHTMLView *)self selectedRange];
|
---|
| 56 | }
|
---|
| 57 | [selectedString release]; selectedString = nil;
|
---|
[320] | 58 | selectedString = [[(WebHTMLView *)self selectedString] retain];
|
---|
[167] | 59 | downEvent = [e retain];
|
---|
[66] | 60 | }
|
---|
| 61 | [super mouseDown: e];
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | - (void)mouseUp:(NSEvent *)e;
|
---|
| 65 | {
|
---|
| 66 | [super mouseUp: e];
|
---|
| 67 | if (downEvent != nil) {
|
---|
| 68 | NSPoint downPt = [downEvent locationInWindow];
|
---|
| 69 | NSPoint upPt = [e locationInWindow];
|
---|
[74] | 70 | if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels)
|
---|
[66] | 71 | return;
|
---|
| 72 |
|
---|
| 73 | NS_DURING
|
---|
[216] | 74 | NSPoint viewClickPt = [self convertPoint: downPt fromView: nil];
|
---|
| 75 | NSDictionary *elementDict = [(WebHTMLView *)self elementAtPoint: viewClickPt];
|
---|
[66] | 76 | WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
|
---|
| 77 | ICLog(@"elementDict: %@", elementDict);
|
---|
[167] | 78 | NSAssert([elementDict count] != 0, @"Internal error: Got empty element dictionary from WebHTMLView");
|
---|
[66] | 79 | if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) {
|
---|
| 80 | ICLog(@"got a link");
|
---|
[320] | 81 | NS_VOIDRETURN; // don't activate on links
|
---|
[66] | 82 | }
|
---|
[182] | 83 | if (selectedString == nil || [selectedString length] == 0) {
|
---|
| 84 | ICLog(@"no selected string");
|
---|
| 85 | NS_VOIDRETURN;
|
---|
| 86 | }
|
---|
| 87 | ICCF_StartIC();
|
---|
[183] | 88 | BOOL canSetSelection = [bridge respondsToSelector: @selector(selectNSRange:)];
|
---|
| 89 | if (canSetSelection) {
|
---|
| 90 | // may have become deselected in mouseDown
|
---|
[182] | 91 | [bridge selectNSRange: selectedRange];
|
---|
[183] | 92 | }
|
---|
| 93 | if (ICCF_LaunchURL(selectedString, ICCF_KeyboardAction(downEvent)) && ICCF_prefs.textBlinkEnabled && canSetSelection) {
|
---|
[182] | 94 | int i;
|
---|
[320] | 95 | NSRect selectionRect;
|
---|
| 96 | if ([self respondsToSelector: @selector(selectionRect)])
|
---|
| 97 | selectionRect = [(WebHTMLView *)self selectionRect];
|
---|
| 98 | else
|
---|
| 99 | selectionRect = [(WebHTMLView *)self _selectionRect];
|
---|
[182] | 100 | ICLog(@"selectedRange %@ selectionRect %@ textBlinkCount %d", NSStringFromRange(selectedRange), NSStringFromRect(selectionRect), ICCF_prefs.textBlinkCount);
|
---|
| 101 | for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
|
---|
[320] | 102 | [(WebHTMLView *)self deselectAll];
|
---|
[182] | 103 | [self setNeedsDisplayInRect: selectionRect];
|
---|
| 104 | [self display];
|
---|
| 105 | usleep(kICBlinkDelayUsecs);
|
---|
| 106 | [bridge selectNSRange: selectedRange];
|
---|
| 107 | [self setNeedsDisplayInRect: selectionRect];
|
---|
| 108 | [self display];
|
---|
| 109 | usleep(kICBlinkDelayUsecs);
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
[66] | 112 | NS_HANDLER
|
---|
| 113 | ICCF_HandleException(localException);
|
---|
| 114 | NS_ENDHANDLER
|
---|
| 115 |
|
---|
[183] | 116 | [downEvent release]; downEvent = nil;
|
---|
[66] | 117 | ICCF_StopIC();
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | @end
|
---|