[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 |
|
---|
| 12 | // from WebCoreBridge.h
|
---|
[167] | 13 | @interface WebCoreBridge : NSObject
|
---|
[66] | 14 |
|
---|
[167] | 15 | - (NSString *)selectedString;
|
---|
| 16 | - (NSRect)selectionRect;
|
---|
| 17 |
|
---|
| 18 | - (void)selectNSRange:(NSRange)range;
|
---|
[182] | 19 | - (void)deselectAll;
|
---|
[167] | 20 |
|
---|
[66] | 21 | @end
|
---|
| 22 |
|
---|
[167] | 23 | // from WebKit, private
|
---|
| 24 | @interface WebHTMLView : NSObject
|
---|
[66] | 25 |
|
---|
| 26 | - (WebCoreBridge *)_bridge;
|
---|
| 27 |
|
---|
[167] | 28 | - (NSRange)selectedRange;
|
---|
| 29 |
|
---|
[216] | 30 | - (NSDictionary *)elementAtPoint:(NSPoint)point;
|
---|
| 31 |
|
---|
[66] | 32 | @end
|
---|
| 33 |
|
---|
| 34 | @implementation ICeCoffEEWebKit
|
---|
| 35 |
|
---|
| 36 | - (NSMenu *)menuForEvent:(NSEvent *)e;
|
---|
| 37 | {
|
---|
| 38 | NSMenu *myMenu = [super menuForEvent: e];
|
---|
| 39 | return ICCF_MenuForEvent(self, myMenu, e);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | static NSEvent *downEvent = nil;
|
---|
[167] | 43 | static NSString *selectedString = nil;
|
---|
| 44 | static NSRange selectedRange;
|
---|
| 45 |
|
---|
[66] | 46 | - (void)mouseDown:(NSEvent *)e;
|
---|
| 47 | {
|
---|
[182] | 48 | [downEvent release]; downEvent = nil;
|
---|
[74] | 49 | if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) {
|
---|
[66] | 50 | WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
|
---|
[182] | 51 | if ([self respondsToSelector: @selector(selectedRange)]) {
|
---|
| 52 | // save selection: it may be deselected on super mouseDown
|
---|
| 53 | selectedRange = [(WebHTMLView *)self selectedRange];
|
---|
| 54 | }
|
---|
| 55 | [selectedString release]; selectedString = nil;
|
---|
| 56 | selectedString = [[bridge selectedString] retain];
|
---|
[167] | 57 | downEvent = [e retain];
|
---|
[66] | 58 | }
|
---|
| 59 | [super mouseDown: e];
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | - (void)mouseUp:(NSEvent *)e;
|
---|
| 63 | {
|
---|
| 64 | [super mouseUp: e];
|
---|
| 65 | if (downEvent != nil) {
|
---|
| 66 | NSPoint downPt = [downEvent locationInWindow];
|
---|
| 67 | NSPoint upPt = [e locationInWindow];
|
---|
[74] | 68 | if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels)
|
---|
[66] | 69 | return;
|
---|
| 70 |
|
---|
| 71 | NS_DURING
|
---|
[216] | 72 | NSPoint viewClickPt = [self convertPoint: downPt fromView: nil];
|
---|
| 73 | NSDictionary *elementDict = [(WebHTMLView *)self elementAtPoint: viewClickPt];
|
---|
[66] | 74 | WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
|
---|
| 75 | ICLog(@"elementDict: %@", elementDict);
|
---|
[167] | 76 | NSAssert([elementDict count] != 0, @"Internal error: Got empty element dictionary from WebHTMLView");
|
---|
[66] | 77 | if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) {
|
---|
| 78 | ICLog(@"got a link");
|
---|
| 79 | NS_VOIDRETURN; // donÕt activate on links
|
---|
| 80 | }
|
---|
[182] | 81 | if (selectedString == nil || [selectedString length] == 0) {
|
---|
| 82 | ICLog(@"no selected string");
|
---|
| 83 | NS_VOIDRETURN;
|
---|
| 84 | }
|
---|
| 85 | ICCF_StartIC();
|
---|
[183] | 86 | BOOL canSetSelection = [bridge respondsToSelector: @selector(selectNSRange:)];
|
---|
| 87 | if (canSetSelection) {
|
---|
| 88 | // may have become deselected in mouseDown
|
---|
[182] | 89 | [bridge selectNSRange: selectedRange];
|
---|
[183] | 90 | }
|
---|
| 91 | if (ICCF_LaunchURL(selectedString, ICCF_KeyboardAction(downEvent)) && ICCF_prefs.textBlinkEnabled && canSetSelection) {
|
---|
[182] | 92 | int i;
|
---|
| 93 | NSRect selectionRect = [bridge selectionRect];
|
---|
| 94 | ICLog(@"selectedRange %@ selectionRect %@ textBlinkCount %d", NSStringFromRange(selectedRange), NSStringFromRect(selectionRect), ICCF_prefs.textBlinkCount);
|
---|
| 95 | for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
|
---|
| 96 | [bridge deselectAll];
|
---|
| 97 | [self setNeedsDisplayInRect: selectionRect];
|
---|
| 98 | [self display];
|
---|
| 99 | usleep(kICBlinkDelayUsecs);
|
---|
| 100 | [bridge selectNSRange: selectedRange];
|
---|
| 101 | [self setNeedsDisplayInRect: selectionRect];
|
---|
| 102 | [self display];
|
---|
| 103 | usleep(kICBlinkDelayUsecs);
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
[66] | 106 | NS_HANDLER
|
---|
| 107 | ICCF_HandleException(localException);
|
---|
| 108 | NS_ENDHANDLER
|
---|
| 109 |
|
---|
[183] | 110 | [downEvent release]; downEvent = nil;
|
---|
[66] | 111 | ICCF_StopIC();
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | @end
|
---|