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

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

Initial import.

File size: 4.8 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_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 // XXX make hysterisis a constant
103 if (abs(downPt.x - upPt.x) > 4 && abs(downPt.y - upPt.y) > 4)
104 return;
105
106 NS_DURING
107 WebCoreBridge *bridge = [(WebHTMLView *)self _bridge];
108 NSPoint viewClickPt = [self convertPoint: downPt fromView: nil];
109 NSDictionary *elementDict = [(WebHTMLView *)self _elementAtPoint: viewClickPt];
110 ICLog(@"elementDict: %@", elementDict);
111 NSAssert([elementDict count] != 0, @"ShouldnÕt get empty element dictionary"); // XXX clarify
112 if ([elementDict objectForKey: @"WebElementLinkURL"] != nil) {
113 ICLog(@"got a link");
114 NS_VOIDRETURN; // donÕt activate on links
115 }
116 // XXX works, but doesn't update
117 if (selectedString == nil || [selectedString length] == 0)
118 NS_VOIDRETURN;
119 int i;
120 for (i = 0 ; i < 3 ; i++) {
121 [bridge deselectAll];
122 [self display];
123 usleep(60000);
124 ICCF_SetWebCoreBridgeSelection(bridge, &selection);
125 [self display];
126 usleep(60000);
127 }
128 ICCF_SetWebCoreBridgeSelection(bridge, &selection);
129 [self display];
130 ICCF_StartIC();
131 ICCF_LaunchURL(selectedString);
132 NS_HANDLER
133 ICCF_HandleException(localException);
134 NS_ENDHANDLER
135
136 ICCF_StopIC();
137
138 // ICLog(@"selection start %d end %d string %@", [bridge selectionStartOffset], [bridge selectionEndOffset], [bridge selectedString]);
139 // [bridge forceLayout];
140 // ICLog(@"force start %d end %d string %@", [bridge selectionStartOffset], [bridge selectionEndOffset], [bridge selectedString]);
141
142 // check selected string, first
143 // fabricate triple-click, examine selected string
144
145 // setSelectionFrom:startOffset:to:endOffset:
146
147 // ICCF_LaunchURLFromTextView(self);
148 }
149}
150
151
152
153@end
Note: See TracBrowser for help on using the repository browser.