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