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

Last change on this file since 106 was 106, checked in by Nicholas Riley, 19 years ago

ICeCoffEE 1.3.2b1

File size: 5.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// 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 ICLog(@"selection start %d@%@ end %d@%@ string %@", [bridge selectionStartOffset], [bridge selectionStart], [bridge selectionEndOffset], [bridge selectionEnd], [bridge selectedString]);
86 // XXX hack until we have something better
87 [selectedString release]; selectedString = nil;
88 selectedString = [[bridge selectedString] retain];
89 downEvent = e;
90 } else {
91 downEvent = nil;
92 }
93 [super mouseDown: e];
94}
95
96- (void)mouseUp:(NSEvent *)e;
97{
98 [super mouseUp: e];
99 if (downEvent != nil) {
100 NSPoint downPt = [downEvent locationInWindow];
101 NSPoint upPt = [e locationInWindow];
102 downEvent = nil;
103 if (abs(downPt.x - upPt.x) > kICHysteresisPixels && abs(downPt.y - upPt.y) > kICHysteresisPixels)
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 if (selectedString == nil || [selectedString length] == 0)
117 NS_VOIDRETURN;
118 // XXX works, but doesn't update
119 ICCF_StartIC();
120 ICCF_LaunchURL(selectedString, ICCF_KeyboardAction());
121 // breaks in Safari v62 and before
122 ICCF_SetWebCoreBridgeSelection(bridge, &selection);
123 if (ICCF_prefs.textBlinkEnabled) {
124 int i;
125 for (i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
126 [bridge deselectAll];
127 usleep(kICBlinkDelayUsecs);
128 ICCF_SetWebCoreBridgeSelection(bridge, &selection);
129 usleep(kICBlinkDelayUsecs);
130 }
131 }
132 NS_HANDLER
133 ICCF_HandleException(localException);
134 NS_ENDHANDLER
135
136 ICCF_StopIC();
137 // XXX need to release fromNode, toNode
138
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.