[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;
|
---|
[74] | 48 | if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) {
|
---|
[66] | 49 | WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
|
---|
[182] | 50 | if ([self respondsToSelector: @selector(selectedRange)]) {
|
---|
| 51 | // save selection: it may be deselected on super mouseDown
|
---|
| 52 | selectedRange = [(WebHTMLView *)self selectedRange];
|
---|
| 53 | }
|
---|
| 54 | [selectedString release]; selectedString = nil;
|
---|
| 55 | selectedString = [[bridge selectedString] retain];
|
---|
[167] | 56 | downEvent = [e retain];
|
---|
[66] | 57 | }
|
---|
| 58 | [super mouseDown: e];
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | - (void)mouseUp:(NSEvent *)e;
|
---|
| 62 | {
|
---|
| 63 | [super mouseUp: e];
|
---|
| 64 | if (downEvent != nil) {
|
---|
| 65 | NSPoint downPt = [downEvent locationInWindow];
|
---|
| 66 | NSPoint upPt = [e locationInWindow];
|
---|
[74] | 67 | if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels)
|
---|
[66] | 68 | return;
|
---|
| 69 |
|
---|
| 70 | NS_DURING
|
---|
| 71 | WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
|
---|
| 72 | NSPoint viewClickPt = [self convertPoint: downPt fromView: nil];
|
---|
[167] | 73 | NSDictionary *elementDict = [bridge elementAtPoint: viewClickPt];
|
---|
[66] | 74 | ICLog(@"elementDict: %@", elementDict);
|
---|
[167] | 75 | NSAssert([elementDict count] != 0, @"Internal error: Got empty element dictionary from WebHTMLView");
|
---|
[66] | 76 | if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) {
|
---|
| 77 | ICLog(@"got a link");
|
---|
| 78 | NS_VOIDRETURN; // donÕt activate on links
|
---|
| 79 | }
|
---|
[182] | 80 | if (selectedString == nil || [selectedString length] == 0) {
|
---|
| 81 | ICLog(@"no selected string");
|
---|
| 82 | NS_VOIDRETURN;
|
---|
| 83 | }
|
---|
| 84 | ICCF_StartIC();
|
---|
[183] | 85 | BOOL canSetSelection = [bridge respondsToSelector: @selector(selectNSRange:)];
|
---|
| 86 | if (canSetSelection) {
|
---|
| 87 | // may have become deselected in mouseDown
|
---|
[182] | 88 | [bridge selectNSRange: selectedRange];
|
---|
[183] | 89 | }
|
---|
| 90 | if (ICCF_LaunchURL(selectedString, ICCF_KeyboardAction(downEvent)) && ICCF_prefs.textBlinkEnabled && canSetSelection) {
|
---|
[182] | 91 | int i;
|
---|
| 92 | NSRect selectionRect = [bridge selectionRect];
|
---|
| 93 | ICLog(@"selectedRange %@ selectionRect %@ textBlinkCount %d", NSStringFromRange(selectedRange), NSStringFromRect(selectionRect), ICCF_prefs.textBlinkCount);
|
---|
| 94 | for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
|
---|
| 95 | [bridge deselectAll];
|
---|
| 96 | [self setNeedsDisplayInRect: selectionRect];
|
---|
| 97 | [self display];
|
---|
| 98 | usleep(kICBlinkDelayUsecs);
|
---|
| 99 | [bridge selectNSRange: selectedRange];
|
---|
| 100 | [self setNeedsDisplayInRect: selectionRect];
|
---|
| 101 | [self display];
|
---|
| 102 | usleep(kICBlinkDelayUsecs);
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
[66] | 105 | NS_HANDLER
|
---|
| 106 | ICCF_HandleException(localException);
|
---|
| 107 | NS_ENDHANDLER
|
---|
| 108 |
|
---|
[183] | 109 | [downEvent release]; downEvent = nil;
|
---|
[66] | 110 | ICCF_StopIC();
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | @end
|
---|