source: releases/ICeCoffEE/1.4.4b1/ICeCoffEE/ICeCoffEEWebKit.m@ 336

Last change on this file since 336 was 336, checked in by Nicholas Riley, 15 years ago

VERSION: Starting with 1.4.4b1, should be close to final.

ICeCoffEEServicePrefController.m: Display correct key equivalents, backported from [319].

ICeCoffEEWebKit.m: Fix Safari 3 beta compatibility; better comment WebKit interfaces.

Info-APE Module.plist: Update version to 1.4.4b1.

ICeCoffEE.xcodeproj: Remove obsolete WebKit header.

English.lproj/APEInfo.rtfd: Backported updates from [320]; release notes.

English.lproj/InfoPlist.strings: Update version to 1.4.4b1.

English.lproj/Localizable.strings: Fix an "APE Manager" reference I didn't catch before.

ape_install: Updated to APE 2.0.3.

ui.plist: Update version to 1.4.4b1.

Info-APEManagerPrefPane.plist: Update version to 1.4.4b1.

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