[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 |
|
---|
| 15 | - (NSDictionary *)elementAtPoint:(NSPoint)point;
|
---|
[167] | 16 | - (NSString *)selectedString;
|
---|
| 17 | - (NSRect)selectionRect;
|
---|
| 18 |
|
---|
| 19 | - (void)selectNSRange:(NSRange)range;
|
---|
[182] | 20 | - (void)deselectAll;
|
---|
[167] | 21 |
|
---|
[66] | 22 | @end
|
---|
| 23 |
|
---|
[167] | 24 | // from WebKit, private
|
---|
| 25 | @interface WebHTMLView : NSObject
|
---|
[66] | 26 |
|
---|
| 27 | - (WebCoreBridge *)_bridge;
|
---|
| 28 |
|
---|
[167] | 29 | - (NSRange)selectedRange;
|
---|
| 30 |
|
---|
[66] | 31 | @end
|
---|
| 32 |
|
---|
| 33 | @implementation ICeCoffEEWebKit
|
---|
| 34 |
|
---|
| 35 | - (NSMenu *)menuForEvent:(NSEvent *)e;
|
---|
| 36 | {
|
---|
| 37 | NSMenu *myMenu = [super menuForEvent: e];
|
---|
| 38 | return ICCF_MenuForEvent(self, myMenu, e);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | static NSEvent *downEvent = nil;
|
---|
[167] | 42 | static NSString *selectedString = nil;
|
---|
| 43 | static NSRange selectedRange;
|
---|
| 44 |
|
---|
[66] | 45 | - (void)mouseDown:(NSEvent *)e;
|
---|
| 46 | {
|
---|
[182] | 47 | [downEvent release]; downEvent = nil;
|
---|
| 48 | // don't want command-control-click, command-shift-click, etc. to trigger
|
---|
[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];
|
---|
[167] | 68 | [downEvent release]; downEvent = nil;
|
---|
[74] | 69 | if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels)
|
---|
[66] | 70 | return;
|
---|
| 71 |
|
---|
| 72 | NS_DURING
|
---|
| 73 | WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
|
---|
| 74 | NSPoint viewClickPt = [self convertPoint: downPt fromView: nil];
|
---|
[167] | 75 | NSDictionary *elementDict = [bridge elementAtPoint: viewClickPt];
|
---|
[66] | 76 | ICLog(@"elementDict: %@", elementDict);
|
---|
[167] | 77 | NSAssert([elementDict count] != 0, @"Internal error: Got empty element dictionary from WebHTMLView");
|
---|
[66] | 78 | if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) {
|
---|
| 79 | ICLog(@"got a link");
|
---|
| 80 | NS_VOIDRETURN; // donÕt activate on links
|
---|
| 81 | }
|
---|
[182] | 82 | if (selectedString == nil || [selectedString length] == 0) {
|
---|
| 83 | ICLog(@"no selected string");
|
---|
| 84 | NS_VOIDRETURN;
|
---|
| 85 | }
|
---|
| 86 | ICCF_StartIC();
|
---|
| 87 | ICCF_LaunchURL(selectedString, ICCF_KeyboardAction());
|
---|
| 88 | if (ICCF_prefs.textBlinkEnabled && [bridge respondsToSelector: @selector(selectNSRange:)]) {
|
---|
| 89 | [bridge selectNSRange: selectedRange];
|
---|
| 90 | int i;
|
---|
| 91 | NSRect selectionRect = [bridge selectionRect];
|
---|
| 92 | ICLog(@"selectedRange %@ selectionRect %@ textBlinkCount %d", NSStringFromRange(selectedRange), NSStringFromRect(selectionRect), ICCF_prefs.textBlinkCount);
|
---|
| 93 | for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
|
---|
| 94 | [bridge deselectAll];
|
---|
| 95 | [self setNeedsDisplayInRect: selectionRect];
|
---|
| 96 | [self display];
|
---|
| 97 | usleep(kICBlinkDelayUsecs);
|
---|
| 98 | [bridge selectNSRange: selectedRange];
|
---|
| 99 | [self setNeedsDisplayInRect: selectionRect];
|
---|
| 100 | [self display];
|
---|
| 101 | usleep(kICBlinkDelayUsecs);
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
[66] | 104 | NS_HANDLER
|
---|
| 105 | ICCF_HandleException(localException);
|
---|
| 106 | NS_ENDHANDLER
|
---|
| 107 |
|
---|
| 108 | ICCF_StopIC();
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | @end
|
---|