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

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

English.lproj/APEInfo.rtfd: Partial documentation update for 1.4.2;
fixed many instances of outdated and incorrect information.

ICeCoffEE.m: Removed completed "to do" comments - that's what
OmniOutliner? and Trac are for. Fixed delimiters to make more sense.
Redid ICCF_ParseURL() to make more sense and strip invalid characters
from beginning of URL. Added note about deprecated getCString:.
Fixed ICCF_ServicesMenuItem() to work on Tiger; moved menu population
logic (where services menu delegate used) to new
ICCF_SetServicesMenu() in ICeCoffEESetServicesMenu.[hm]. Remove key
equivalents from services in ICCF_ConsolidateServicesMenu(). First
pass at a workaround for discontiguous selection: only trigger if
there is no selection. This will be fixed to use a timer.

ICeCoffEEServicePrefController: Fixed service population to work on
Tiger, though keyboard equivalents are not provided; will need to
switch to parsing output of CFServiceControllerCopyServicesEntries()
for that one.

ICeCoffEEWebKit.m: Removed Safari 1.0-1.2 support. Fixed incorrect
comment about -selectionRect? only being in Safari
1.1-1.2.

ICeCoffEESetServicesMenu.[hm]: Handle getting a usable services menu
for Panther and Tiger.

File size: 3.4 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- (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
41static NSEvent *downEvent = nil;
42static NSString *selectedString = nil;
43static NSRange selectedRange;
44
45- (void)mouseDown:(NSEvent *)e;
46{
47    [downEvent release]; downEvent = nil;
48    // don't want command-control-click, command-shift-click, etc. to trigger
49    if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) {
50        WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
51        if ([self respondsToSelector: @selector(selectedRange)]) {
52            // save selection: it may be deselected on super mouseDown
53            selectedRange = [(WebHTMLView *)self selectedRange];
54        }
55        [selectedString release]; selectedString = nil;
56        selectedString = [[bridge selectedString] retain];
57        downEvent = [e retain];
58    }
59    [super mouseDown: e];
60}
61
62- (void)mouseUp:(NSEvent *)e;
63{
64    [super mouseUp: e];
65    if (downEvent != nil) {
66        NSPoint downPt = [downEvent locationInWindow];
67        NSPoint upPt = [e locationInWindow];
68                [downEvent release]; downEvent = nil;
69        if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels)
70            return;
71
72        NS_DURING
73            WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
74            NSPoint viewClickPt = [self convertPoint: downPt fromView: nil];
75            NSDictionary *elementDict = [bridge elementAtPoint: viewClickPt];
76            ICLog(@"elementDict: %@", elementDict);
77            NSAssert([elementDict count] != 0, @"Internal error: Got empty element dictionary from WebHTMLView");
78            if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) {
79                ICLog(@"got a link");
80                NS_VOIDRETURN; // donÕt activate on links
81            }
82            if (selectedString == nil || [selectedString length] == 0) {
83                ICLog(@"no selected string");
84                NS_VOIDRETURN;
85            }
86            ICCF_StartIC();
87            ICCF_LaunchURL(selectedString, ICCF_KeyboardAction());
88            if (ICCF_prefs.textBlinkEnabled && [bridge respondsToSelector: @selector(selectNSRange:)]) {
89                [bridge selectNSRange: selectedRange];
90                int i;
91                NSRect selectionRect = [bridge selectionRect];
92                ICLog(@"selectedRange %@ selectionRect %@ textBlinkCount %d", NSStringFromRange(selectedRange), NSStringFromRect(selectionRect), ICCF_prefs.textBlinkCount);
93                for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
94                    [bridge deselectAll];
95                    [self setNeedsDisplayInRect: selectionRect];
96                    [self display];
97                    usleep(kICBlinkDelayUsecs);
98                    [bridge selectNSRange: selectedRange];
99                    [self setNeedsDisplayInRect: selectionRect];
100                    [self display];
101                    usleep(kICBlinkDelayUsecs);
102                }
103            }
104        NS_HANDLER
105            ICCF_HandleException(localException);
106        NS_ENDHANDLER
107
108        ICCF_StopIC();
109    }       
110}
111
112@end
Note: See TracBrowser for help on using the repository browser.