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

Last change on this file since 388 was 388, checked in by Nicholas Riley, 12 years ago

APEMain.m: Note missing Xcode 3 support. Add Terminal 2.0 support.

English.lproj/APE Manager plugin.nib:

English.lproj/APEInfo.rtfd:

ICeCoffEE.[hm]: Bring triggering window and app to front if error
dialog displayed in ICCF_HandleException. Remove initial word
selection. Launch preexisting selection if present. Remove 10.3
support. Update for new ICeCoffEETrigger API. Rename downEvent
parameter for consistency.

ICeCoffEE.xcodeproj: Added files.

ICeCoffEEParser.m: Handle multiline URLs.

ICeCoffEETTView.[hm]: Terminal 2.0 support (thank you for having a
usable NSTextInput implementation!)

ICeCoffEETTViewTrigger.[hm]: ICeCoffEETrigger implementation for
TTView. Can't set range as we do for NSTextView because you can't
have an arbitrary empty selection range in Terminal, so we pass it
directly to ICCF_LaunchURLFromTTView.

ICeCoffEETerminal.[hm]: Fix capitalization on ICeCoffEETermSubviewSuper.
Pass downEvent to ICCF_HandleException so it can bring the triggering
window to the front.

ICeCoffEETextViewTrigger.[hm]: Moved from ICeCoffEETrigger.

ICeCoffEETrigger.[hm]: Now an abstract superclass. Replace direct
access to ICCF_sharedTrigger with +cancel. Create 0-character range
(if click outside selectedRange) or save selectedRange. Move
debugging logs here from ICeCoffEE.m. Add description method.

ICeCoffEEWebKit.m: Pass downEvent to ICCF_HandleException so it can
bring the triggering window to the front.

Installer components/ui/ui.plist: Updated for 1.5d3.

TestParser?.m: Handle multiline URLs; newlines are printed as \ and
tabs as >. Implement ICCF_StringByRemovingCharactersInSet, which will
move elsewhere once Internet Config support is removed.

VERSION.xcconfig: Updated for 1.5d3.

urls.plist: Test for multiline URLs.

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, downEvent);
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.