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
|
---|
13 | @interface WebCoreBridge : NSObject
|
---|
14 |
|
---|
15 | - (NSString *)selectedString;
|
---|
16 | - (NSRect)selectionRect;
|
---|
17 |
|
---|
18 | - (void)selectNSRange:(NSRange)range;
|
---|
19 | - (void)deselectAll;
|
---|
20 |
|
---|
21 | @end
|
---|
22 |
|
---|
23 | // from WebKit, private
|
---|
24 | @interface WebHTMLView : NSObject
|
---|
25 |
|
---|
26 | - (WebCoreBridge *)_bridge;
|
---|
27 |
|
---|
28 | - (NSRange)selectedRange;
|
---|
29 |
|
---|
30 | - (NSDictionary *)elementAtPoint:(NSPoint)point;
|
---|
31 |
|
---|
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;
|
---|
43 | static NSString *selectedString = nil;
|
---|
44 | static NSRange selectedRange;
|
---|
45 |
|
---|
46 | - (void)mouseDown:(NSEvent *)e;
|
---|
47 | {
|
---|
48 | [downEvent release]; downEvent = nil;
|
---|
49 | if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) {
|
---|
50 | WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
|
---|
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];
|
---|
57 | downEvent = [e retain];
|
---|
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];
|
---|
68 | if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels)
|
---|
69 | return;
|
---|
70 |
|
---|
71 | NS_DURING
|
---|
72 | NSPoint viewClickPt = [self convertPoint: downPt fromView: nil];
|
---|
73 | NSDictionary *elementDict = [(WebHTMLView *)self elementAtPoint: viewClickPt];
|
---|
74 | WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
|
---|
75 | ICLog(@"elementDict: %@", elementDict);
|
---|
76 | NSAssert([elementDict count] != 0, @"Internal error: Got empty element dictionary from WebHTMLView");
|
---|
77 | if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) {
|
---|
78 | ICLog(@"got a link");
|
---|
79 | NS_VOIDRETURN; // donÕt activate on links
|
---|
80 | }
|
---|
81 | if (selectedString == nil || [selectedString length] == 0) {
|
---|
82 | ICLog(@"no selected string");
|
---|
83 | NS_VOIDRETURN;
|
---|
84 | }
|
---|
85 | ICCF_StartIC();
|
---|
86 | BOOL canSetSelection = [bridge respondsToSelector: @selector(selectNSRange:)];
|
---|
87 | if (canSetSelection) {
|
---|
88 | // may have become deselected in mouseDown
|
---|
89 | [bridge selectNSRange: selectedRange];
|
---|
90 | }
|
---|
91 | if (ICCF_LaunchURL(selectedString, ICCF_KeyboardAction(downEvent)) && ICCF_prefs.textBlinkEnabled && canSetSelection) {
|
---|
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 | }
|
---|
106 | NS_HANDLER
|
---|
107 | ICCF_HandleException(localException);
|
---|
108 | NS_ENDHANDLER
|
---|
109 |
|
---|
110 | [downEvent release]; downEvent = nil;
|
---|
111 | ICCF_StopIC();
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | @end
|
---|