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

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

ICeCoffEE.m: I was wrong in [319] about the selection extension stuff
being dumb; explain why in code, even though it's not fixed.
Implement some of the same parens support I did in Terminal. Update
for more robust service info dictionary format.

ICeCoffEEServicePrefController.m: Update for more robust service info
dictionary format.

ICeCoffEEServices.[hm]: Renamed from ICeCoffEESetServicesMenu.[hm],
since we do more now. Service info dictionary-creating code now makes
more sense and no longer has naming collision issues.

ICeCoffEEWebKit.m: Some preliminary Safari 3 compatibility stuff, not
quite working yet. An outstanding question - is it better to rely on
"public" WebCore API or private WebKit API? So far it seems the
latter is more stable.

English.lproj/APEInfo.rtfd: The Bored Zo has a name: use it. Remove
now-erroneous reference to SimpleText since TextEdit support is gone.

File size: 4.1 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// WebCoreBridge, from WebCoreBridge.h (Safari 2)
13// Web(Core)FrameBridge, from WebCoreFrameBridge.h (Safari 3)
14@interface WebCoreBridge : NSObject
15
16// can only use setMarkedText:selectedRange: if WebHTMLView is editable
17// or, should we move to DOM-based accessors, i.e. "setMarkDOMRange"?
18- (void)selectNSRange:(NSRange)range;
19
20@end
21
22// from WebKit, private -- XXX maybe I'm better off going back the other way, relying on public methods in the bridge?
23@interface WebHTMLView : NSObject
24
25- (NSString *)selectedString;
26- (NSRect)selectionRect;
27- (NSRect)_selectionRect; // Safari 2, supported in Safari 3 only for use with Mail
28- (NSRange)selectedRange; // XXX same as selectedNSRange in WebCoreFrameBridge.h?
29- (void)deselectAll;
30
31- (WebCoreBridge *)_bridge; /* WebFrameBridge in Safari 3 (see above) */
32
33- (NSDictionary *)elementAtPoint:(NSPoint)point;
34
35@end
36
37@implementation ICeCoffEEWebKit
38
39- (NSMenu *)menuForEvent:(NSEvent *)e;
40{
41 NSMenu *myMenu = [super menuForEvent: e];
42 return ICCF_MenuForEvent(self, myMenu, e);
43}
44
45static NSEvent *downEvent = nil;
46static NSString *selectedString = nil;
47static NSRange selectedRange;
48
49- (void)mouseDown:(NSEvent *)e;
50{
51 [downEvent release]; downEvent = nil;
52 if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) {
53 if ([self respondsToSelector: @selector(selectedRange)]) {
54 // save selection: it may be deselected on super mouseDown
55 selectedRange = [(WebHTMLView *)self selectedRange];
56 }
57 [selectedString release]; selectedString = nil;
58 selectedString = [[(WebHTMLView *)self selectedString] retain];
59 downEvent = [e retain];
60 }
61 [super mouseDown: e];
62}
63
64- (void)mouseUp:(NSEvent *)e;
65{
66 [super mouseUp: e];
67 if (downEvent != nil) {
68 NSPoint downPt = [downEvent locationInWindow];
69 NSPoint upPt = [e locationInWindow];
70 if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels)
71 return;
72
73 NS_DURING
74 NSPoint viewClickPt = [self convertPoint: downPt fromView: nil];
75 NSDictionary *elementDict = [(WebHTMLView *)self elementAtPoint: viewClickPt];
76 WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
77 ICLog(@"elementDict: %@", elementDict);
78 NSAssert([elementDict count] != 0, @"Internal error: Got empty element dictionary from WebHTMLView");
79 if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) {
80 ICLog(@"got a link");
81 NS_VOIDRETURN; // don't activate on links
82 }
83 if (selectedString == nil || [selectedString length] == 0) {
84 ICLog(@"no selected string");
85 NS_VOIDRETURN;
86 }
87 ICCF_StartIC();
88 BOOL canSetSelection = [bridge respondsToSelector: @selector(selectNSRange:)];
89 if (canSetSelection) {
90 // may have become deselected in mouseDown
91 [bridge selectNSRange: selectedRange];
92 }
93 if (ICCF_LaunchURL(selectedString, ICCF_KeyboardAction(downEvent)) && ICCF_prefs.textBlinkEnabled && canSetSelection) {
94 int i;
95 NSRect selectionRect;
96 if ([self respondsToSelector: @selector(selectionRect)])
97 selectionRect = [(WebHTMLView *)self selectionRect];
98 else
99 selectionRect = [(WebHTMLView *)self _selectionRect];
100 ICLog(@"selectedRange %@ selectionRect %@ textBlinkCount %d", NSStringFromRange(selectedRange), NSStringFromRect(selectionRect), ICCF_prefs.textBlinkCount);
101 for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
102 [(WebHTMLView *)self deselectAll];
103 [self setNeedsDisplayInRect: selectionRect];
104 [self display];
105 usleep(kICBlinkDelayUsecs);
106 [bridge selectNSRange: selectedRange];
107 [self setNeedsDisplayInRect: selectionRect];
108 [self display];
109 usleep(kICBlinkDelayUsecs);
110 }
111 }
112 NS_HANDLER
113 ICCF_HandleException(localException);
114 NS_ENDHANDLER
115
116 [downEvent release]; downEvent = nil;
117 ICCF_StopIC();
118 }
119}
120
121@end
Note: See TracBrowser for help on using the repository browser.