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

Last change on this file since 74 was 74, checked in by Nicholas Riley, 21 years ago

ICeCoffEE 1.3b2 plus some changes for 1.3

File size: 4.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
14
15- (NSDictionary *)elementAtPoint:(NSPoint)point;
16
17- (void)setSelectionFrom:(id /* WebDOMNode */)start startOffset:(int)startOffset to:(id /* WebDOMNode */)end endOffset:(int) endOffset;
18- (void)deselectAll;
19
20- (void)forceLayout;
21
22- (NSString *)selectedString;
23
24- (id /* WebDOMNode */)selectionStart;
25- (int)selectionStartOffset;
26- (id /* WebDOMNode */)selectionEnd;
27- (int)selectionEndOffset;
28
29@end
30
31// from WebKit, not yet public
32@interface WebHTMLView
33
34- (WebCoreBridge *)_bridge;
35- (NSDictionary *)_elementAtPoint:(NSPoint)point;
36
37@end
38
39@implementation ICeCoffEEWebKit
40
41- (NSMenu *)menuForEvent:(NSEvent *)e;
42{
43 NSMenu *myMenu = [super menuForEvent: e];
44 return ICCF_MenuForEvent(self, myMenu, e);
45}
46
47static NSEvent *downEvent = nil;
48typedef struct {
49 int startOffset;
50 int endOffset;
51 id fromNode;
52 id toNode;
53} ICCF_WebCoreSelection;
54static NSString *selectedString = nil; // XXX remove when we can do this properly
55
56static ICCF_WebCoreSelection selection = {nil, nil, 0, 0};
57
58void ICCF_GetWebCoreBridgeSelection(WebCoreBridge *bridge, ICCF_WebCoreSelection *ioSel) {
59 [ioSel->fromNode release]; ioSel->fromNode = nil;
60 [ioSel->toNode release]; ioSel->toNode = nil;
61 ioSel->startOffset = [bridge selectionStartOffset];
62 ioSel->endOffset = [bridge selectionEndOffset];
63 if (ioSel->startOffset != 0 && ioSel->endOffset != 0) {
64 ioSel->fromNode = [[bridge selectionStart] retain];
65 ioSel->toNode = [[bridge selectionEnd] retain];
66 }
67}
68
69void ICCF_SetWebCoreBridgeSelection(WebCoreBridge *bridge, ICCF_WebCoreSelection *inSel) {
70 if (inSel->fromNode == nil || inSel->toNode == nil)
71 [bridge deselectAll];
72 [bridge setSelectionFrom: inSel->fromNode
73 startOffset: inSel->startOffset
74 to: inSel->toNode
75 endOffset: inSel->endOffset];
76}
77
78- (void)mouseDown:(NSEvent *)e;
79{
80 // don't want command-option-click, command-shift-click, etc. to trigger
81 if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) {
82 // save selection: it will be deselected on super mouseDown
83 WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
84 ICCF_GetWebCoreBridgeSelection(bridge, &selection);
85 // XXX hack until we have something better
86 [selectedString release]; selectedString = nil;
87 selectedString = [[bridge selectedString] retain];
88 downEvent = e;
89 } else {
90 downEvent = nil;
91 }
92 [super mouseDown: e];
93}
94
95- (void)mouseUp:(NSEvent *)e;
96{
97 [super mouseUp: e];
98 if (downEvent != nil) {
99 NSPoint downPt = [downEvent locationInWindow];
100 NSPoint upPt = [e locationInWindow];
101 downEvent = nil;
102 if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels)
103 return;
104
105 NS_DURING
106 WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
107 NSPoint viewClickPt = [self convertPoint: downPt fromView: nil];
108 NSDictionary *elementDict = [(WebHTMLView *)self _elementAtPoint: viewClickPt];
109 ICLog(@"elementDict: %@", elementDict);
110 NSAssert([elementDict count] != 0, @"ShouldnÕt get empty element dictionary"); // XXX clarify
111 if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) {
112 ICLog(@"got a link");
113 NS_VOIDRETURN; // donÕt activate on links
114 }
115 if (selectedString == nil || [selectedString length] == 0)
116 NS_VOIDRETURN;
117 // XXX works, but doesn't update
118 ICCF_StartIC();
119 ICCF_LaunchURL(selectedString, ICCF_OptionKeyIsDown());
120 ICCF_SetWebCoreBridgeSelection(bridge, &selection);
121 if (ICCF_prefs.textBlinkEnabled) {
122 int i;
123 for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
124 [bridge deselectAll];
125 usleep(kICBlinkDelayUsecs);
126 ICCF_SetWebCoreBridgeSelection(bridge, &selection);
127 usleep(kICBlinkDelayUsecs);
128 }
129 }
130 NS_HANDLER
131 ICCF_HandleException(localException);
132 NS_ENDHANDLER
133
134 ICCF_StopIC();
135
136 // ICLog(@"selection start %d end %d string %@", [bridge selectionStartOffset], [bridge selectionEndOffset], [bridge selectedString]);
137 // [bridge forceLayout];
138 // ICLog(@"force start %d end %d string %@", [bridge selectionStartOffset], [bridge selectionEndOffset], [bridge selectedString]);
139
140 // check selected string, first
141 // fabricate triple-click, examine selected string
142
143 // setSelectionFrom:startOffset:to:endOffset:
144
145 // ICCF_LaunchURLFromTextView(self);
146 }
147}
148
149
150
151@end
Note: See TracBrowser for help on using the repository browser.