source: trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEWebKit.m@ 167

Last change on this file since 167 was 167, checked in by Nicholas Riley, 17 years ago

ICeCoffEE 1.4 and preliminary 1.4.1 changes. Sorry, I forgot to
commit version 1.4 when it was released, so the precise source for
that release has been lost.

See the release notes for details of what changed in these versions.
1.4 was a significant feature release; 1.4.1 is a bug fix for 10.3.9,
incorporating up-to-date Unsanity Installer and APE.

package-ICeCoffEE.sh: use xcodebuild instead of pbxbuild.

File size: 5.9 KB
Line 
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- (void)deselectAll;
18
19// only in Safari 1.0-1.2
20- (void)setSelectionFrom:(id /* WebDOMNode */)start startOffset:(int)startOffset to:(id /* WebDOMNode */)end endOffset:(int) endOffset;
21
22- (id /* WebDOMNode */)selectionStart;
23- (int)selectionStartOffset;
24- (id /* WebDOMNode */)selectionEnd;
25- (int)selectionEndOffset;
26
27// only in Safari 1.1-1.2
28- (NSRect)selectionRect;
29
30// only in Safari 1.3
31- (void)selectNSRange:(NSRange)range;
32
33@end
34
35// from WebKit, private
36@interface WebHTMLView : NSObject
37
38- (WebCoreBridge *)_bridge;
39
40// only in Safari 1.3
41- (NSRange)selectedRange;
42
43@end
44
45@implementation ICeCoffEEWebKit
46
47- (NSMenu *)menuForEvent:(NSEvent *)e;
48{
49 NSMenu *myMenu = [super menuForEvent: e];
50 return ICCF_MenuForEvent(self, myMenu, e);
51}
52
53static NSEvent *downEvent = nil;
54
55// used in Safari < 1.3 because there's no sane way to set the selection
56typedef struct {
57 int startOffset;
58 int endOffset;
59 id fromNode;
60 id toNode;
61} ICCF_WebCoreSelection;
62
63static ICCF_WebCoreSelection selection = {nil, nil, 0, 0};
64
65void ICCF_GetWebCoreBridgeSelection(WebCoreBridge *bridge, ICCF_WebCoreSelection *ioSel) {
66 [ioSel->fromNode release]; ioSel->fromNode = nil;
67 [ioSel->toNode release]; ioSel->toNode = nil;
68 ioSel->startOffset = [bridge selectionStartOffset];
69 ioSel->endOffset = [bridge selectionEndOffset];
70 ioSel->fromNode = [[bridge selectionStart] retain];
71 ioSel->toNode = [[bridge selectionEnd] retain];
72}
73
74void ICCF_SetWebCoreBridgeSelection(WebCoreBridge *bridge, ICCF_WebCoreSelection *inSel) {
75 if (inSel->fromNode == nil || inSel->toNode == nil)
76 [bridge deselectAll];
77 [bridge setSelectionFrom: inSel->fromNode
78 startOffset: inSel->startOffset
79 to: inSel->toNode
80 endOffset: inSel->endOffset];
81}
82// end Safari < 1.3 section
83
84static NSString *selectedString = nil;
85static NSRange selectedRange;
86
87- (void)mouseDown:(NSEvent *)e;
88{
89 [downEvent release]; downEvent = nil;
90 // don't want command-option-click, command-shift-click, etc. to trigger
91 if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) {
92 WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
93 if ([self respondsToSelector: @selector(selectedRange)]) {
94 // Safari 1.3 save selection: it may be deselected on super mouseDown
95 selectedRange = [(WebHTMLView *)self selectedRange];
96 } else if ([bridge respondsToSelector: @selector(selectionStartOffset)]) {
97 // Safari < 1.3 save selection: it will be deselected on super mouseDown
98 ICCF_GetWebCoreBridgeSelection(bridge, &selection);
99 ICLog(@"selection start %d@%@ end %d@%@ string %@", [bridge selectionStartOffset], [bridge selectionStart], [bridge selectionEndOffset], [bridge selectionEnd], [bridge selectedString]);
100 }
101 [selectedString release]; selectedString = nil;
102 selectedString = [[bridge selectedString] retain];
103 downEvent = [e retain];
104 }
105 [super mouseDown: e];
106}
107
108- (void)mouseUp:(NSEvent *)e;
109{
110 [super mouseUp: e];
111 if (downEvent != nil) {
112 NSPoint downPt = [downEvent locationInWindow];
113 NSPoint upPt = [e locationInWindow];
114 [downEvent release]; downEvent = nil;
115 if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels)
116 return;
117
118 NS_DURING
119 WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
120 NSPoint viewClickPt = [self convertPoint: downPt fromView: nil];
121 NSDictionary *elementDict = [bridge elementAtPoint: viewClickPt];
122 ICLog(@"elementDict: %@", elementDict);
123 NSAssert([elementDict count] != 0, @"Internal error: Got empty element dictionary from WebHTMLView");
124 if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) {
125 ICLog(@"got a link");
126 NS_VOIDRETURN; // donÕt activate on links
127 }
128 if (selectedString == nil || [selectedString length] == 0) {
129 ICLog(@"no selected string");
130 NS_VOIDRETURN;
131 }
132 ICCF_StartIC();
133 // ICCF_LaunchURL(selectedString, ICCF_KeyboardAction());
134 if (ICCF_prefs.textBlinkEnabled &&
135 [bridge respondsToSelector: @selector(selectNSRange:)]) {
136 // blink text in Safari 1.3
137 [bridge selectNSRange: selectedRange];
138 int i;
139 NSRect selectionRect = [bridge selectionRect];
140 ICLog(@"selectedRange %@ selectionRect %@ textBlinkCount %d", NSStringFromRange(selectedRange), NSStringFromRect(selectionRect), ICCF_prefs.textBlinkCount);
141 for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
142 [bridge deselectAll];
143 [self setNeedsDisplayInRect: selectionRect];
144 [self display];
145 usleep(kICBlinkDelayUsecs);
146 [bridge selectNSRange: selectedRange];
147 [self setNeedsDisplayInRect: selectionRect];
148 [self display];
149 usleep(kICBlinkDelayUsecs);
150 }
151 } else {
152 // select text in Safari 1.0-1.2
153 ICCF_SetWebCoreBridgeSelection(bridge, &selection);
154 if (ICCF_prefs.textBlinkEnabled &&
155 [bridge respondsToSelector: @selector(selectionRect)]) {
156 // blink text in Safari 1.1/1.2
157 int i;
158 NSRect selectionRect = [bridge selectionRect];
159 for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
160 [bridge deselectAll];
161 [self setNeedsDisplayInRect: selectionRect];
162 [self display];
163 usleep(kICBlinkDelayUsecs);
164 ICCF_SetWebCoreBridgeSelection(bridge, &selection);
165 [self setNeedsDisplayInRect: selectionRect];
166 [self display];
167 usleep(kICBlinkDelayUsecs);
168 }
169 }
170 }
171 NS_HANDLER
172 ICCF_HandleException(localException);
173 NS_ENDHANDLER
174
175 ICCF_StopIC();
176 }
177}
178
179@end
Note: See TracBrowser for help on using the repository browser.