@seekskyworld/open-browser 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +15 -0
- package/Docs/Agent/346/265/217/350/247/210/345/231/250/346/200/273/344/275/223/346/236/266/346/236/204.md +58 -0
- package/Docs/THIRD-PARTY-NOTICES.md +12 -0
- package/Docs/open-browser-api.d.ts +291 -0
- package/Docs/open-browser/344/273/273/345/212/241/350/257/204/346/265/213/346/214/207/345/215/227.md +59 -0
- package/Docs/open-browser/351/232/220/347/247/201/344/270/216/345/274/200/346/272/220/345/256/241/350/256/241.md +37 -0
- package/Docs//346/216/247/345/210/266/345/217/260/345/210/206/347/273/204/344/270/216/346/216/245/347/256/241/346/226/271/346/241/210.md +31 -0
- package/Docs//350/267/250/345/271/263/345/217/260/350/257/225/347/224/250/344/270/216/345/217/221/350/241/214.md +84 -0
- package/LICENSE +200 -0
- package/README.md +159 -2
- package/README.zh-CN.md +166 -0
- package/SECURITY.md +9 -0
- package/access-registry.mjs +156 -0
- package/action-execution.mjs +385 -0
- package/activity-notifier.mjs +34 -0
- package/api-contract.mjs +134 -0
- package/browser-extension/icons/open-browser-128.png +0 -0
- package/browser-extension/icons/open-browser-16.png +0 -0
- package/browser-extension/icons/open-browser-32.png +0 -0
- package/browser-extension/icons/open-browser-48.png +0 -0
- package/browser-extension/icons/open-browser-wordmark.png +0 -0
- package/browser-extension/manifest.json +35 -0
- package/browser-extension/newtab.css +26 -0
- package/browser-extension/newtab.html +19 -0
- package/browser-extension/newtab.js +174 -0
- package/browser-extension/phase-labels.js +9 -0
- package/browser-extension/popup.css +19 -0
- package/browser-extension/popup.html +56 -0
- package/browser-extension/popup.js +405 -0
- package/browser-extension/tab-action.js +138 -0
- package/browser-extension/worker.js +281 -0
- package/browser-extension/workspace-title.js +15 -0
- package/build-profile.mjs +23 -0
- package/capability-matrix.mjs +21 -0
- package/chromium-host.mjs +209 -0
- package/chromium-shell.mjs +179 -0
- package/cli.mjs +141 -0
- package/contract-validation.mjs +27 -0
- package/control.mjs +107 -0
- package/desktop/Info.plist +13 -0
- package/desktop/Launcher.m +117 -0
- package/desktop/OBControlBar.h +7 -0
- package/desktop/OBControlBar.m +217 -0
- package/desktop/OBPageView.h +6 -0
- package/desktop/OBPageView.m +348 -0
- package/desktop/WorkspacePanel.h +16 -0
- package/desktop/WorkspacePanel.m +916 -0
- package/desktop/archive-release.py +129 -0
- package/desktop/brand-keychain.py +111 -0
- package/desktop/brand-locales.py +93 -0
- package/desktop/brand-macos-icons.py +24 -0
- package/desktop/brand-windows-icons.mjs +48 -0
- package/desktop/build-macos.mjs +112 -0
- package/desktop/build-managed-input.mjs +37 -0
- package/desktop/build-portable.mjs +95 -0
- package/desktop/build-profile.mjs +6 -0
- package/desktop/build.mjs +13 -0
- package/desktop/create-shortcut.ps1 +9 -0
- package/desktop/generate-icons.py +39 -0
- package/desktop/icons/open-browser.icns +0 -0
- package/desktop/icons/open-browser.ico +0 -0
- package/desktop/install-menu-entry.mjs +24 -0
- package/desktop/macos-entitlements.plist +12 -0
- package/desktop/notarize-macos.mjs +145 -0
- package/desktop/package-assets.mjs +34 -0
- package/desktop/package-macos.mjs +54 -0
- package/desktop/patches/chromium-macos-keychain-service.patch +18 -0
- package/desktop/patches/chromium-managed-input.patch +144 -0
- package/desktop/portable-archive.py +22 -0
- package/desktop/sign.mjs +77 -0
- package/desktop/smoke-portable.mjs +65 -0
- package/desktop/start-profile.mjs +5 -0
- package/desktop/start.mjs +34 -0
- package/desktop/verify-macos-release.mjs +61 -0
- package/desktop/verify-upgrade.mjs +74 -0
- package/desktop/verify-version.mjs +12 -0
- package/desktop-page.mjs +211 -0
- package/diagnostics.mjs +37 -0
- package/downloads.mjs +110 -0
- package/engine-service.mjs +1158 -0
- package/hosted/README.md +74 -0
- package/hosted/cli.mjs +17 -0
- package/hosted/directory.mjs +261 -0
- package/hosted/init.mjs +37 -0
- package/hosted/server.mjs +129 -0
- package/managed-input.mjs +138 -0
- package/managed-popup.mjs +54 -0
- package/mcp-http.mjs +84 -0
- package/mcp-server.mjs +41 -0
- package/mcp.mjs +5 -0
- package/network-policy.mjs +107 -0
- package/output-store.mjs +96 -0
- package/package.json +77 -4
- package/page-activity.mjs +188 -0
- package/page-dialogs.mjs +53 -0
- package/page-observation.mjs +318 -0
- package/paths.mjs +22 -0
- package/privacy-config.mjs +95 -0
- package/receipt-store.mjs +198 -0
- package/runtime.mjs +53 -0
- package/scheduler.mjs +70 -0
- package/sdk.mjs +193 -0
- package/service.mjs +290 -0
- package/site-workflow.mjs +115 -0
- package/skill-links.mjs +90 -0
- package/skills/open-browser/SKILL.macos.md +112 -0
- package/skills/open-browser/SKILL.md +107 -0
- package/skills/open-browser/SKILL.windows.md +112 -0
- package/skills/open-browser/scripts/bootstrap.mjs +213 -0
- package/skills/open-browser/scripts/open-browser +21 -0
- package/skills/open-browser/scripts/open-browser.cmd +9 -0
- package/skills/open-browser/workflows/login-export.json +10 -0
- package/skills/open-browser/workflows/upload-verify.json +8 -0
- package/studio/demo-site.mjs +111 -0
- package/studio/demo.css +1 -0
- package/studio/index.html +66 -0
- package/studio/index.mjs +57 -0
- package/studio/native-demo.mjs +124 -0
- package/studio/studio.css +119 -0
- package/studio/studio.js +438 -0
- package/tab-adoption.mjs +77 -0
- package/uploads.mjs +63 -0
- package/visual-page.mjs +306 -0
- package/workspace-lifecycle.mjs +238 -0
- package/workspace-state.mjs +107 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
#import "OBControlBar.h"
|
|
2
|
+
#import <CoreGraphics/CoreGraphics.h>
|
|
3
|
+
#import <sys/sysctl.h>
|
|
4
|
+
|
|
5
|
+
@interface OBPanel : NSPanel
|
|
6
|
+
@end
|
|
7
|
+
@implementation OBPanel
|
|
8
|
+
- (BOOL)canBecomeKeyWindow { return NO; }
|
|
9
|
+
- (BOOL)canBecomeMainWindow { return NO; }
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
@interface OBBarButton : NSButton
|
|
13
|
+
@property(copy) NSDictionary *binding;
|
|
14
|
+
@property(copy) NSDictionary *pressedBinding;
|
|
15
|
+
@end
|
|
16
|
+
@implementation OBBarButton
|
|
17
|
+
- (BOOL)acceptsFirstResponder { return NO; }
|
|
18
|
+
- (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; }
|
|
19
|
+
- (void)mouseDown:(NSEvent *)event {
|
|
20
|
+
self.pressedBinding = self.binding;
|
|
21
|
+
[super mouseDown:event];
|
|
22
|
+
self.pressedBinding = nil;
|
|
23
|
+
}
|
|
24
|
+
@end
|
|
25
|
+
|
|
26
|
+
static BOOL IsChildOfService(pid_t pid, pid_t servicePID) {
|
|
27
|
+
for (int i = 0; i < 8 && pid > 1; i++) {
|
|
28
|
+
if (pid == servicePID) return YES;
|
|
29
|
+
struct kinfo_proc info = {0};
|
|
30
|
+
size_t size = sizeof(info);
|
|
31
|
+
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
|
|
32
|
+
if (sysctl(mib, 4, &info, &size, NULL, 0) < 0 || size != sizeof(info)) return NO;
|
|
33
|
+
pid = info.kp_eproc.e_ppid;
|
|
34
|
+
}
|
|
35
|
+
return NO;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// WindowServer and chrome.windows both express these bounds in desktop points,
|
|
39
|
+
// measured from the top left of the primary display.
|
|
40
|
+
static BOOL FrontWindowMatches(pid_t pid, CGRect expected) {
|
|
41
|
+
NSArray *windows = CFBridgingRelease(CGWindowListCopyWindowInfo(
|
|
42
|
+
kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID));
|
|
43
|
+
for (NSDictionary *info in windows) {
|
|
44
|
+
if ([info[(id)kCGWindowOwnerPID] intValue] != pid || [info[(id)kCGWindowLayer] integerValue] != 0) continue;
|
|
45
|
+
CGRect bounds;
|
|
46
|
+
if (!CGRectMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)info[(id)kCGWindowBounds], &bounds)) continue;
|
|
47
|
+
return fabs(bounds.origin.x - expected.origin.x) <= 3 && fabs(bounds.origin.y - expected.origin.y) <= 3 &&
|
|
48
|
+
fabs(bounds.size.width - expected.size.width) <= 3 && fabs(bounds.size.height - expected.size.height) <= 3;
|
|
49
|
+
}
|
|
50
|
+
return NO;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static NSString *Text(id value) { return [value isKindOfClass:NSString.class] ? value : @""; }
|
|
54
|
+
|
|
55
|
+
@interface OBControlBar ()
|
|
56
|
+
@property(strong) OBPanel *panel;
|
|
57
|
+
@property(strong) NSTextField *agent, *status;
|
|
58
|
+
@property(strong) OBBarButton *button, *delivery;
|
|
59
|
+
@property(strong) NSView *dot;
|
|
60
|
+
@property(copy) NSDictionary *bar, *pending;
|
|
61
|
+
@property(copy) NSString *rootPrefix;
|
|
62
|
+
@property(copy) void (^send)(NSDictionary *);
|
|
63
|
+
@property pid_t servicePID;
|
|
64
|
+
@property(strong) NSTimer *timer;
|
|
65
|
+
@end
|
|
66
|
+
|
|
67
|
+
@implementation OBControlBar
|
|
68
|
+
- (instancetype)initWithEngineRoot:(NSURL *)root servicePID:(pid_t)pid send:(void (^)(NSDictionary *))send {
|
|
69
|
+
if (!(self = [super init])) return nil;
|
|
70
|
+
_servicePID = pid;
|
|
71
|
+
_rootPrefix = [root.URLByResolvingSymlinksInPath.path stringByAppendingString:@"/"];
|
|
72
|
+
_send = [send copy];
|
|
73
|
+
_panel = [[OBPanel alloc] initWithContentRect:NSMakeRect(0, 0, 248, 42)
|
|
74
|
+
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskNonactivatingPanel backing:NSBackingStoreBuffered defer:NO];
|
|
75
|
+
_panel.title = @"open-browser 控制条";
|
|
76
|
+
_panel.floatingPanel = YES;
|
|
77
|
+
_panel.level = NSFloatingWindowLevel;
|
|
78
|
+
_panel.hidesOnDeactivate = NO;
|
|
79
|
+
_panel.opaque = NO;
|
|
80
|
+
_panel.backgroundColor = NSColor.clearColor;
|
|
81
|
+
_panel.hasShadow = YES;
|
|
82
|
+
_panel.releasedWhenClosed = NO;
|
|
83
|
+
_panel.excludedFromWindowsMenu = YES;
|
|
84
|
+
_panel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorFullScreenAuxiliary | NSWindowCollectionBehaviorIgnoresCycle;
|
|
85
|
+
|
|
86
|
+
NSVisualEffectView *surface = [NSVisualEffectView new];
|
|
87
|
+
surface.material = NSVisualEffectMaterialPopover;
|
|
88
|
+
surface.state = NSVisualEffectStateActive;
|
|
89
|
+
surface.wantsLayer = YES;
|
|
90
|
+
surface.layer.cornerRadius = 13;
|
|
91
|
+
surface.layer.masksToBounds = YES;
|
|
92
|
+
_panel.contentView = surface;
|
|
93
|
+
_dot = [NSView new];
|
|
94
|
+
_dot.wantsLayer = YES;
|
|
95
|
+
_dot.layer.cornerRadius = 4;
|
|
96
|
+
[_dot.widthAnchor constraintEqualToConstant:8].active = YES;
|
|
97
|
+
[_dot.heightAnchor constraintEqualToConstant:8].active = YES;
|
|
98
|
+
_agent = [NSTextField labelWithString:@""];
|
|
99
|
+
_agent.font = [NSFont systemFontOfSize:13 weight:NSFontWeightSemibold];
|
|
100
|
+
_agent.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
101
|
+
[_agent setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationHorizontal];
|
|
102
|
+
_status = [NSTextField labelWithString:@""];
|
|
103
|
+
_status.font = [NSFont systemFontOfSize:12];
|
|
104
|
+
_status.textColor = NSColor.secondaryLabelColor;
|
|
105
|
+
_button = [OBBarButton buttonWithTitle:@"人工接管" target:self action:@selector(click:)];
|
|
106
|
+
_button.bezelStyle = NSBezelStyleRounded;
|
|
107
|
+
_button.controlSize = NSControlSizeSmall;
|
|
108
|
+
_button.focusRingType = NSFocusRingTypeNone;
|
|
109
|
+
_delivery = [OBBarButton buttonWithTitle:@"结束" target:self action:@selector(click:)];
|
|
110
|
+
_delivery.bezelStyle = NSBezelStyleRounded;
|
|
111
|
+
_delivery.controlSize = NSControlSizeSmall;
|
|
112
|
+
_delivery.toolTip = @"结束当前 Agent 任务并保留现有页面";
|
|
113
|
+
NSStackView *row = [NSStackView stackViewWithViews:@[_dot, _agent, _status, _button, _delivery]];
|
|
114
|
+
row.spacing = 8;
|
|
115
|
+
row.alignment = NSLayoutAttributeCenterY;
|
|
116
|
+
row.translatesAutoresizingMaskIntoConstraints = NO;
|
|
117
|
+
[surface addSubview:row];
|
|
118
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
119
|
+
[row.leadingAnchor constraintEqualToAnchor:surface.leadingAnchor constant:13],
|
|
120
|
+
[row.trailingAnchor constraintEqualToAnchor:surface.trailingAnchor constant:-10],
|
|
121
|
+
[row.centerYAnchor constraintEqualToAnchor:surface.centerYAnchor]
|
|
122
|
+
]];
|
|
123
|
+
NSNotificationCenter *events = NSWorkspace.sharedWorkspace.notificationCenter;
|
|
124
|
+
[events addObserver:self selector:@selector(frontChanged:) name:NSWorkspaceDidActivateApplicationNotification object:nil];
|
|
125
|
+
[events addObserver:self selector:@selector(frontChanged:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil];
|
|
126
|
+
return self;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
- (void)frontChanged:(NSNotification *)note { [self place]; }
|
|
130
|
+
|
|
131
|
+
- (BOOL)frontMatches:(CGRect)bounds {
|
|
132
|
+
NSRunningApplication *front = NSWorkspace.sharedWorkspace.frontmostApplication;
|
|
133
|
+
BOOL dev = [NSBundle.mainBundle.bundleIdentifier isEqual:@"local.open-browser.desktop-dev"];
|
|
134
|
+
NSString *engineID = dev ? @"local.open-browser-dev.chromium" : @"local.open-browser.chromium";
|
|
135
|
+
if (![front.bundleIdentifier isEqual:engineID] || front.hidden) return NO;
|
|
136
|
+
NSString *path = front.executableURL.URLByResolvingSymlinksInPath.path;
|
|
137
|
+
NSString *suffix = dev ? @"/open-browser-dev.app/Contents/MacOS/open-browser" : @"/open-browser.app/Contents/MacOS/open-browser";
|
|
138
|
+
return [path hasPrefix:self.rootPrefix] && [path hasSuffix:suffix] &&
|
|
139
|
+
IsChildOfService(front.processIdentifier, self.servicePID) && FrontWindowMatches(front.processIdentifier, bounds);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
- (void)place {
|
|
143
|
+
if (!self.bar) return;
|
|
144
|
+
CGRect bounds = CGRectMake([self.bar[@"left"] doubleValue], [self.bar[@"top"] doubleValue],
|
|
145
|
+
[self.bar[@"width"] doubleValue], [self.bar[@"height"] doubleValue]);
|
|
146
|
+
CGFloat viewport = MIN([self.bar[@"viewportWidth"] doubleValue], bounds.size.width);
|
|
147
|
+
if (![self frontMatches:bounds] || viewport < 150 || bounds.size.height < 120) { [self.panel orderOut:nil]; return; }
|
|
148
|
+
CGFloat textWidth = ceil(MIN(160, self.agent.intrinsicContentSize.width) + self.status.intrinsicContentSize.width +
|
|
149
|
+
self.button.intrinsicContentSize.width + self.delivery.intrinsicContentSize.width + 66);
|
|
150
|
+
CGFloat width = MIN(viewport - 12, MAX(175, textWidth));
|
|
151
|
+
NSScreen *primary = NSScreen.screens.firstObject;
|
|
152
|
+
if (!primary) { [self.panel orderOut:nil]; return; }
|
|
153
|
+
NSRect frame = NSMakeRect(round(CGRectGetMaxX(bounds) - viewport/2 - width/2),
|
|
154
|
+
round(NSMaxY(primary.frame) - CGRectGetMaxY(bounds) + 16), width, 40);
|
|
155
|
+
if (!NSEqualRects(self.panel.frame, frame)) [self.panel setFrame:frame display:YES];
|
|
156
|
+
if (!self.panel.visible) [self.panel orderFrontRegardless];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
- (void)update:(NSDictionary *)bar {
|
|
160
|
+
if (![bar isKindOfClass:NSDictionary.class] || !Text(bar[@"workspaceId"]).length ||
|
|
161
|
+
!Text(bar[@"pageId"]).length || !Text(bar[@"controlGeneration"]).length ||
|
|
162
|
+
![@[@"human", @"agent", @"transferring"] containsObject:Text(bar[@"mode"])]) bar = nil;
|
|
163
|
+
for (NSString *key in @[@"windowId", @"left", @"top", @"width", @"height", @"viewportWidth"]) {
|
|
164
|
+
if (![bar[key] isKindOfClass:NSNumber.class] || !isfinite([bar[key] doubleValue])) { bar = nil; break; }
|
|
165
|
+
}
|
|
166
|
+
self.bar = bar;
|
|
167
|
+
if (!bar) {
|
|
168
|
+
self.pending = nil;
|
|
169
|
+
self.button.binding = nil;
|
|
170
|
+
[self.timer invalidate]; self.timer = nil;
|
|
171
|
+
[self.panel orderOut:nil];
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
NSMutableDictionary *binding = [NSMutableDictionary dictionaryWithObject:@"desktop.bar.click" forKey:@"event"];
|
|
175
|
+
for (NSString *key in @[@"workspaceId", @"pageId", @"windowId", @"controlGeneration", @"mode"]) binding[key] = bar[key];
|
|
176
|
+
self.button.binding = binding;
|
|
177
|
+
NSMutableDictionary *delivery = [binding mutableCopy];
|
|
178
|
+
delivery[@"action"] = @"delivery";
|
|
179
|
+
self.delivery.binding = delivery;
|
|
180
|
+
if (![self.pending isEqual:binding]) self.pending = nil;
|
|
181
|
+
BOOL human = [bar[@"mode"] isEqual:@"human"], transferring = [bar[@"mode"] isEqual:@"transferring"];
|
|
182
|
+
NSDictionary *states = @{@"actionability":@"检查目标", @"dispatching":@"正在派发", @"waiting":@"等待页面", @"verifying":@"核对结果", @"dispatched":@"已派发", @"running":@"执行中", @"queued":@"已排队", @"idle":@"待命", @"completed":@"已完成",
|
|
183
|
+
@"needs_credential":@"等待凭据", @"needs_human_verification":@"需要人工验证", @"failed":@"失败", @"cancelled":@"已取消", @"outcome_unknown":@"待核实"};
|
|
184
|
+
self.agent.stringValue = Text(bar[@"agentName"]).length ? bar[@"agentName"] : @"Agent";
|
|
185
|
+
self.agent.toolTip = self.agent.stringValue;
|
|
186
|
+
self.status.stringValue = transferring ? @"交接中" : human ? @"人工控制" : states[Text(bar[@"phase"])] ?: @"待命";
|
|
187
|
+
self.button.bezelColor = !human && !transferring && [bar[@"inputBlocked"] boolValue] ? NSColor.systemOrangeColor : nil;
|
|
188
|
+
self.button.title = human ? @"交回 Agent" : @"人工接管";
|
|
189
|
+
self.delivery.enabled = !transferring;
|
|
190
|
+
self.button.enabled = !transferring && !self.pending;
|
|
191
|
+
NSColor *color = transferring ? NSColor.systemOrangeColor : human ? NSColor.systemGreenColor : NSColor.systemBlueColor;
|
|
192
|
+
self.dot.layer.backgroundColor = color.CGColor;
|
|
193
|
+
if (!self.timer) {
|
|
194
|
+
__weak typeof(self) owner = self;
|
|
195
|
+
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.35 repeats:YES block:^(NSTimer *timer) { [owner place]; }];
|
|
196
|
+
}
|
|
197
|
+
[self place];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
- (void)click:(OBBarButton *)button {
|
|
201
|
+
[self place];
|
|
202
|
+
NSDictionary *binding = button.pressedBinding ?: button.binding;
|
|
203
|
+
if (!binding || !button.enabled || !self.panel.visible || ![binding isEqual:button.binding]) return;
|
|
204
|
+
self.pending = binding;
|
|
205
|
+
button.enabled = NO;
|
|
206
|
+
self.send(binding);
|
|
207
|
+
__weak typeof(self) owner = self;
|
|
208
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
|
209
|
+
if (owner.pending == binding) { owner.pending = nil; [owner update:owner.bar]; }
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
- (void)stop {
|
|
214
|
+
[NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self];
|
|
215
|
+
[self update:nil];
|
|
216
|
+
}
|
|
217
|
+
@end
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
#import "OBPageView.h"
|
|
2
|
+
|
|
3
|
+
@interface OBPageView ()
|
|
4
|
+
@property (copy) WorkspaceCall call;
|
|
5
|
+
@property (copy) NSDictionary *handle;
|
|
6
|
+
@property (copy) NSString *mode;
|
|
7
|
+
@property (copy) NSString *generation;
|
|
8
|
+
@property (copy) NSString *documentID;
|
|
9
|
+
@property (strong) NSImage *image;
|
|
10
|
+
@property NSSize viewport;
|
|
11
|
+
@property NSUInteger epoch;
|
|
12
|
+
@property BOOL framePending;
|
|
13
|
+
@property BOOL inputPending;
|
|
14
|
+
@property (strong) NSTimer *timer;
|
|
15
|
+
@property (strong) NSTrackingArea *tracking;
|
|
16
|
+
@property (strong) NSMutableArray<NSDictionary *> *events;
|
|
17
|
+
@property (copy) NSString *marked;
|
|
18
|
+
@property NSRange markedSelection;
|
|
19
|
+
@property NSPoint caretPoint;
|
|
20
|
+
@end
|
|
21
|
+
|
|
22
|
+
@implementation OBPageView
|
|
23
|
+
- (instancetype)initWithCall:(WorkspaceCall)call {
|
|
24
|
+
if ((self = [super initWithFrame:NSZeroRect])) {
|
|
25
|
+
_call = [call copy];
|
|
26
|
+
_events = [NSMutableArray array];
|
|
27
|
+
[self setAccessibilityElement:YES];
|
|
28
|
+
[self setAccessibilityRole:NSAccessibilityImageRole];
|
|
29
|
+
[self setAccessibilityLabel:@"工作区网页"];
|
|
30
|
+
[self setAccessibilityIdentifier:@"open-browser-workspace-page"];
|
|
31
|
+
}
|
|
32
|
+
return self;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
- (BOOL)isFlipped { return YES; }
|
|
36
|
+
- (BOOL)acceptsFirstResponder { return [self.mode isEqual:@"human"]; }
|
|
37
|
+
- (BOOL)canShowPage {
|
|
38
|
+
return self.handle && self.window.isVisible && !self.window.isMiniaturized &&
|
|
39
|
+
(self.window.occlusionState & NSWindowOcclusionStateVisible) &&
|
|
40
|
+
!self.isHiddenOrHasHiddenAncestor && !NSIsEmptyRect(self.visibleRect);
|
|
41
|
+
}
|
|
42
|
+
- (BOOL)canInput {
|
|
43
|
+
return [self canShowPage] && self.documentID.length && self.generation.length &&
|
|
44
|
+
[self.mode isEqual:@"human"];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
- (void)clearComposition {
|
|
48
|
+
self.marked = nil;
|
|
49
|
+
[self.inputContext discardMarkedText];
|
|
50
|
+
self.needsDisplay = YES;
|
|
51
|
+
}
|
|
52
|
+
- (void)discardFrame {
|
|
53
|
+
self.documentID = nil;
|
|
54
|
+
self.image = nil;
|
|
55
|
+
[self.events removeAllObjects];
|
|
56
|
+
[self clearComposition];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
- (void)displayPage:(NSDictionary *)handle mode:(NSString *)mode generation:(NSString *)generation {
|
|
60
|
+
if ((self.handle == handle || [self.handle isEqual:handle]) &&
|
|
61
|
+
(self.mode == mode || [self.mode isEqual:mode]) &&
|
|
62
|
+
(self.generation == generation || [self.generation isEqual:generation])) return;
|
|
63
|
+
self.epoch++;
|
|
64
|
+
self.handle = handle;
|
|
65
|
+
self.mode = mode;
|
|
66
|
+
self.generation = generation;
|
|
67
|
+
[self discardFrame];
|
|
68
|
+
[self scheduleFrame:0];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
- (void)viewWillMoveToWindow:(NSWindow *)window {
|
|
72
|
+
NSNotificationCenter *center = NSNotificationCenter.defaultCenter;
|
|
73
|
+
if (self.window) [center removeObserver:self name:NSWindowDidChangeOcclusionStateNotification object:self.window];
|
|
74
|
+
if (window) [center addObserver:self selector:@selector(visibilityChanged:) name:NSWindowDidChangeOcclusionStateNotification object:window];
|
|
75
|
+
[super viewWillMoveToWindow:window];
|
|
76
|
+
}
|
|
77
|
+
- (void)viewDidMoveToWindow { [super viewDidMoveToWindow]; [self refreshVisibility]; }
|
|
78
|
+
- (void)viewDidHide { [super viewDidHide]; [self refreshVisibility]; }
|
|
79
|
+
- (void)viewDidUnhide { [super viewDidUnhide]; [self refreshVisibility]; }
|
|
80
|
+
- (void)visibilityChanged:(NSNotification *)note { [self refreshVisibility]; }
|
|
81
|
+
- (void)setFrameSize:(NSSize)size { [super setFrameSize:size]; [self scheduleFrame:0.04]; }
|
|
82
|
+
- (void)refreshVisibility {
|
|
83
|
+
if (![self canShowPage]) {
|
|
84
|
+
self.epoch++;
|
|
85
|
+
[self discardFrame];
|
|
86
|
+
}
|
|
87
|
+
[self scheduleFrame:0];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
- (void)scheduleFrame:(NSTimeInterval)delay {
|
|
91
|
+
[self.timer invalidate];
|
|
92
|
+
self.timer = nil;
|
|
93
|
+
if (self.framePending || ![self canShowPage]) return;
|
|
94
|
+
__weak OBPageView *weakSelf = self;
|
|
95
|
+
self.timer = [NSTimer timerWithTimeInterval:delay repeats:NO block:^(NSTimer *__unused timer) {
|
|
96
|
+
[weakSelf fetchFrame];
|
|
97
|
+
}];
|
|
98
|
+
[NSRunLoop.mainRunLoop addTimer:self.timer forMode:NSRunLoopCommonModes];
|
|
99
|
+
}
|
|
100
|
+
- (void)fetchFrame {
|
|
101
|
+
if (self.framePending || ![self canShowPage]) return;
|
|
102
|
+
NSMutableDictionary *request = self.handle.mutableCopy;
|
|
103
|
+
request[@"width"] = @(MAX(320, MIN(1920, lround(self.bounds.size.width))));
|
|
104
|
+
request[@"height"] = @(MAX(200, MIN(1200, lround(self.bounds.size.height))));
|
|
105
|
+
if (self.image && (self.viewport.width != [request[@"width"] doubleValue] ||
|
|
106
|
+
self.viewport.height != [request[@"height"] doubleValue])) [self discardFrame];
|
|
107
|
+
NSUInteger epoch = self.epoch;
|
|
108
|
+
self.framePending = YES;
|
|
109
|
+
self.call(@"pageFrame", request, ^(id frame, NSString *error) {
|
|
110
|
+
self.framePending = NO;
|
|
111
|
+
if (epoch != self.epoch || ![self canShowPage]) { [self scheduleFrame:0]; return; }
|
|
112
|
+
BOOL valid = !error && [frame isKindOfClass:NSDictionary.class] &&
|
|
113
|
+
[frame[@"documentId"] isKindOfClass:NSString.class] &&
|
|
114
|
+
[frame[@"controlGeneration"] isEqual:self.generation] &&
|
|
115
|
+
[frame[@"data"] isKindOfClass:NSString.class] &&
|
|
116
|
+
[frame[@"width"] doubleValue] > 0 && [frame[@"height"] doubleValue] > 0;
|
|
117
|
+
NSImage *image = nil;
|
|
118
|
+
if (valid) {
|
|
119
|
+
NSData *data = [[NSData alloc] initWithBase64EncodedString:frame[@"data"] options:0];
|
|
120
|
+
if (data) image = [[NSImage alloc] initWithData:data];
|
|
121
|
+
}
|
|
122
|
+
if (!image || ![self.documentID isEqual:frame[@"documentId"]]) [self discardFrame];
|
|
123
|
+
if (image) {
|
|
124
|
+
self.image = image;
|
|
125
|
+
self.documentID = frame[@"documentId"];
|
|
126
|
+
self.viewport = NSMakeSize([frame[@"width"] doubleValue], [frame[@"height"] doubleValue]);
|
|
127
|
+
self.needsDisplay = YES;
|
|
128
|
+
}
|
|
129
|
+
[self scheduleFrame:image ? ([self.mode isEqual:@"human"] ? 0.08 : 0.28) : 0.5];
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
- (NSRect)imageRect {
|
|
134
|
+
if (!self.image || self.viewport.width <= 0 || self.viewport.height <= 0) return NSZeroRect;
|
|
135
|
+
NSRect bounds = self.bounds;
|
|
136
|
+
CGFloat scale = MIN(bounds.size.width / self.viewport.width, bounds.size.height / self.viewport.height);
|
|
137
|
+
NSSize size = NSMakeSize(self.viewport.width * scale, self.viewport.height * scale);
|
|
138
|
+
return NSMakeRect(NSMidX(bounds) - size.width/2, NSMidY(bounds) - size.height/2, size.width, size.height);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
- (void)drawRect:(NSRect)dirty {
|
|
142
|
+
[NSColor.textBackgroundColor setFill];
|
|
143
|
+
NSRectFill(dirty);
|
|
144
|
+
[self.image drawInRect:[self imageRect] fromRect:NSZeroRect operation:NSCompositingOperationSourceOver
|
|
145
|
+
fraction:1 respectFlipped:YES hints:nil];
|
|
146
|
+
if (self.marked.length) {
|
|
147
|
+
[self.marked drawAtPoint:self.caretPoint withAttributes:@{
|
|
148
|
+
NSBackgroundColorAttributeName:NSColor.textBackgroundColor,
|
|
149
|
+
NSForegroundColorAttributeName:NSColor.textColor,
|
|
150
|
+
NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),
|
|
151
|
+
NSFontAttributeName:[NSFont systemFontOfSize:14]}];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
- (void)sendNextInput {
|
|
156
|
+
if (self.inputPending || !self.events.count || ![self canInput]) return;
|
|
157
|
+
NSDictionary *event = self.events.firstObject;
|
|
158
|
+
[self.events removeObjectAtIndex:0];
|
|
159
|
+
NSMutableDictionary *params = self.handle.mutableCopy;
|
|
160
|
+
params[@"documentId"] = self.documentID;
|
|
161
|
+
params[@"controlGeneration"] = self.generation;
|
|
162
|
+
params[@"event"] = event;
|
|
163
|
+
NSUInteger epoch = self.epoch;
|
|
164
|
+
self.inputPending = YES;
|
|
165
|
+
self.call(@"pageInput", params, ^(id __unused result, NSString *error) {
|
|
166
|
+
self.inputPending = NO;
|
|
167
|
+
if (error && epoch == self.epoch && [self.documentID isEqual:params[@"documentId"]]) {
|
|
168
|
+
self.epoch++;
|
|
169
|
+
[self discardFrame];
|
|
170
|
+
[self scheduleFrame:0];
|
|
171
|
+
}
|
|
172
|
+
[self sendNextInput];
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
- (void)enqueue:(NSDictionary *)event {
|
|
176
|
+
if (![self canInput]) return;
|
|
177
|
+
NSString *type = event[@"type"];
|
|
178
|
+
NSDictionary *last = self.events.lastObject;
|
|
179
|
+
if ([last[@"type"] isEqual:type] && [type isEqual:@"mouseMove"]) {
|
|
180
|
+
[self.events removeLastObject];
|
|
181
|
+
} else if ([last[@"type"] isEqual:type] && [type isEqual:@"wheel"] &&
|
|
182
|
+
[last[@"x"] isEqual:event[@"x"]] && [last[@"y"] isEqual:event[@"y"]]) {
|
|
183
|
+
NSMutableDictionary *combined = event.mutableCopy;
|
|
184
|
+
for (NSString *axis in @[@"deltaX", @"deltaY"]) {
|
|
185
|
+
CGFloat delta = [last[axis] doubleValue] + [event[axis] doubleValue];
|
|
186
|
+
combined[axis] = @(MAX(-10000, MIN(10000, delta)));
|
|
187
|
+
}
|
|
188
|
+
event = combined;
|
|
189
|
+
[self.events removeLastObject];
|
|
190
|
+
}
|
|
191
|
+
[self.events addObject:event];
|
|
192
|
+
[self sendNextInput];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
- (void)updateTrackingAreas {
|
|
196
|
+
[super updateTrackingAreas];
|
|
197
|
+
if (self.tracking) [self removeTrackingArea:self.tracking];
|
|
198
|
+
self.tracking = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:
|
|
199
|
+
NSTrackingMouseMoved|NSTrackingActiveInKeyWindow|NSTrackingInVisibleRect owner:self userInfo:nil];
|
|
200
|
+
[self addTrackingArea:self.tracking];
|
|
201
|
+
}
|
|
202
|
+
- (void)pointer:(NSEvent *)event type:(NSString *)type button:(NSString *)button {
|
|
203
|
+
if (![self canInput]) return;
|
|
204
|
+
NSPoint location = [self convertPoint:event.locationInWindow fromView:nil];
|
|
205
|
+
NSRect rect = [self imageRect];
|
|
206
|
+
if (NSIsEmptyRect(rect)) return;
|
|
207
|
+
if (!NSPointInRect(location, rect) && ![type isEqual:@"mouseUp"] &&
|
|
208
|
+
event.type != NSEventTypeLeftMouseDragged && event.type != NSEventTypeRightMouseDragged &&
|
|
209
|
+
event.type != NSEventTypeOtherMouseDragged) return;
|
|
210
|
+
CGFloat x = (location.x - NSMinX(rect)) * self.viewport.width / NSWidth(rect);
|
|
211
|
+
CGFloat y = (location.y - NSMinY(rect)) * self.viewport.height / NSHeight(rect);
|
|
212
|
+
NSMutableDictionary *payload = [@{@"type":type, @"x":@(MAX(0, MIN(self.viewport.width-1, x))),
|
|
213
|
+
@"y":@(MAX(0, MIN(self.viewport.height-1, y)))} mutableCopy];
|
|
214
|
+
if (button) {
|
|
215
|
+
payload[@"button"] = button;
|
|
216
|
+
payload[@"clickCount"] = @(MAX(1, MIN(3, event.clickCount)));
|
|
217
|
+
}
|
|
218
|
+
if ([type isEqual:@"mouseDown"]) {
|
|
219
|
+
[self.window makeFirstResponder:self];
|
|
220
|
+
self.caretPoint = location;
|
|
221
|
+
} else if ([type isEqual:@"wheel"]) {
|
|
222
|
+
CGFloat scale = event.hasPreciseScrollingDeltas ? 1 : 12;
|
|
223
|
+
payload[@"deltaX"] = @(-event.scrollingDeltaX * scale);
|
|
224
|
+
payload[@"deltaY"] = @(-event.scrollingDeltaY * scale);
|
|
225
|
+
}
|
|
226
|
+
[self enqueue:payload];
|
|
227
|
+
}
|
|
228
|
+
- (void)mouseMoved:(NSEvent *)e { [self pointer:e type:@"mouseMove" button:nil]; }
|
|
229
|
+
- (void)mouseDragged:(NSEvent *)e { [self mouseMoved:e]; }
|
|
230
|
+
- (void)rightMouseDragged:(NSEvent *)e { [self mouseMoved:e]; }
|
|
231
|
+
- (void)otherMouseDragged:(NSEvent *)e { [self mouseMoved:e]; }
|
|
232
|
+
- (void)mouseDown:(NSEvent *)e { [self pointer:e type:@"mouseDown" button:@"left"]; }
|
|
233
|
+
- (void)mouseUp:(NSEvent *)e { [self pointer:e type:@"mouseUp" button:@"left"]; }
|
|
234
|
+
- (void)rightMouseDown:(NSEvent *)e { [self pointer:e type:@"mouseDown" button:@"right"]; }
|
|
235
|
+
- (void)rightMouseUp:(NSEvent *)e { [self pointer:e type:@"mouseUp" button:@"right"]; }
|
|
236
|
+
- (void)otherMouseDown:(NSEvent *)e { if (e.buttonNumber == 2) [self pointer:e type:@"mouseDown" button:@"middle"]; }
|
|
237
|
+
- (void)otherMouseUp:(NSEvent *)e { if (e.buttonNumber == 2) [self pointer:e type:@"mouseUp" button:@"middle"]; }
|
|
238
|
+
- (void)scrollWheel:(NSEvent *)e { [self pointer:e type:@"wheel" button:nil]; }
|
|
239
|
+
|
|
240
|
+
- (NSString *)specialKey:(NSEvent *)e {
|
|
241
|
+
switch (e.keyCode) {
|
|
242
|
+
case 36: case 76: return @"Enter";
|
|
243
|
+
case 48: return @"Tab";
|
|
244
|
+
case 51: return @"Backspace";
|
|
245
|
+
case 53: return @"Escape";
|
|
246
|
+
case 115: return @"Home";
|
|
247
|
+
case 116: return @"PageUp";
|
|
248
|
+
case 117: return @"Delete";
|
|
249
|
+
case 119: return @"End";
|
|
250
|
+
case 121: return @"PageDown";
|
|
251
|
+
case 123: return @"ArrowLeft";
|
|
252
|
+
case 124: return @"ArrowRight";
|
|
253
|
+
case 125: return @"ArrowDown";
|
|
254
|
+
case 126: return @"ArrowUp";
|
|
255
|
+
default: return nil;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
- (void)keyEvent:(NSString *)type key:(NSString *)key {
|
|
259
|
+
[self enqueue:@{@"type":type, @"key":key}];
|
|
260
|
+
}
|
|
261
|
+
- (void)stroke:(NSString *)key flags:(NSEventModifierFlags)flags {
|
|
262
|
+
NSMutableArray<NSString *> *modifiers = [NSMutableArray array];
|
|
263
|
+
if (flags & NSEventModifierFlagCommand) [modifiers addObject:@"Meta"];
|
|
264
|
+
if (flags & NSEventModifierFlagControl) [modifiers addObject:@"Control"];
|
|
265
|
+
if (flags & NSEventModifierFlagOption) [modifiers addObject:@"Alt"];
|
|
266
|
+
if (flags & NSEventModifierFlagShift) [modifiers addObject:@"Shift"];
|
|
267
|
+
for (NSString *modifier in modifiers) [self keyEvent:@"keyDown" key:modifier];
|
|
268
|
+
[self keyEvent:@"keyDown" key:key];
|
|
269
|
+
[self keyEvent:@"keyUp" key:key];
|
|
270
|
+
for (NSString *modifier in modifiers.reverseObjectEnumerator) [self keyEvent:@"keyUp" key:modifier];
|
|
271
|
+
}
|
|
272
|
+
- (BOOL)performKeyEquivalent:(NSEvent *)e {
|
|
273
|
+
if (self.window.firstResponder == self && [self canInput] && (e.modifierFlags & NSEventModifierFlagCommand)) {
|
|
274
|
+
NSString *key = e.charactersIgnoringModifiers.lowercaseString;
|
|
275
|
+
if ([key isEqual:@"v"]) { [self paste:nil]; return YES; }
|
|
276
|
+
if ([key isEqual:@"a"] || [key isEqual:@"z"]) { [self stroke:key flags:e.modifierFlags]; return YES; }
|
|
277
|
+
}
|
|
278
|
+
return [super performKeyEquivalent:e];
|
|
279
|
+
}
|
|
280
|
+
- (void)paste:(id)sender {
|
|
281
|
+
if (![self canInput]) return;
|
|
282
|
+
NSString *s = [NSPasteboard.generalPasteboard stringForType:NSPasteboardTypeString];
|
|
283
|
+
if (s.length) [self insertText:s replacementRange:NSMakeRange(NSNotFound, 0)];
|
|
284
|
+
}
|
|
285
|
+
- (void)keyDown:(NSEvent *)e {
|
|
286
|
+
if (![self canInput]) return;
|
|
287
|
+
if (self.hasMarkedText) { [self interpretKeyEvents:@[e]]; return; }
|
|
288
|
+
NSString *key = [self specialKey:e];
|
|
289
|
+
if (key || (e.modifierFlags & (NSEventModifierFlagControl|NSEventModifierFlagCommand))) {
|
|
290
|
+
key = key ?: e.charactersIgnoringModifiers.lowercaseString;
|
|
291
|
+
if (key.length) [self stroke:key flags:e.modifierFlags];
|
|
292
|
+
} else if (![self.inputContext handleEvent:e] && e.characters.length) {
|
|
293
|
+
[self insertText:e.characters replacementRange:NSMakeRange(NSNotFound, 0)];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
- (void)insertText:(id)value {
|
|
297
|
+
[self insertText:value replacementRange:NSMakeRange(NSNotFound, 0)];
|
|
298
|
+
}
|
|
299
|
+
- (void)keyUp:(NSEvent *)event { /* Keystrokes are released with their modifiers in stroke:flags:. */ }
|
|
300
|
+
- (BOOL)resignFirstResponder {
|
|
301
|
+
[self clearComposition];
|
|
302
|
+
return [super resignFirstResponder];
|
|
303
|
+
}
|
|
304
|
+
- (void)insertText:(id)value replacementRange:(NSRange)replacementRange {
|
|
305
|
+
self.marked = nil;
|
|
306
|
+
NSString *text = [value isKindOfClass:NSAttributedString.class] ? [value string] : value;
|
|
307
|
+
// The private service accepts up to 8192 UTF-16 units per input. Preserve
|
|
308
|
+
// surrogate pairs when a paste crosses that boundary.
|
|
309
|
+
NSUInteger offset = 0;
|
|
310
|
+
while (offset < text.length) {
|
|
311
|
+
NSUInteger length = MIN(8192, text.length - offset);
|
|
312
|
+
if (offset + length < text.length && CFStringIsSurrogateHighCharacter([text characterAtIndex:offset + length - 1])) length--;
|
|
313
|
+
NSString *part = [text substringWithRange:NSMakeRange(offset, length)];
|
|
314
|
+
[self enqueue:@{@"type":@"text", @"text":part}];
|
|
315
|
+
offset += length;
|
|
316
|
+
}
|
|
317
|
+
self.needsDisplay = YES;
|
|
318
|
+
}
|
|
319
|
+
- (void)doCommandBySelector:(SEL)selector {
|
|
320
|
+
if (selector == @selector(noop:)) return;
|
|
321
|
+
NSString *key = @{@"insertNewline:":@"Enter", @"insertTab:":@"Tab", @"deleteBackward:":@"Backspace",
|
|
322
|
+
@"cancelOperation:":@"Escape", @"moveLeft:":@"ArrowLeft", @"moveRight:":@"ArrowRight",
|
|
323
|
+
@"moveUp:":@"ArrowUp", @"moveDown:":@"ArrowDown"}[NSStringFromSelector(selector)];
|
|
324
|
+
if (key) [self stroke:key flags:0];
|
|
325
|
+
}
|
|
326
|
+
- (void)setMarkedText:(id)value selectedRange:(NSRange)selection replacementRange:(NSRange)replacement {
|
|
327
|
+
if (![self canInput]) return;
|
|
328
|
+
self.marked = [value isKindOfClass:NSAttributedString.class] ? [value string] : value;
|
|
329
|
+
self.markedSelection = NSIntersectionRange(selection, NSMakeRange(0, self.marked.length));
|
|
330
|
+
self.needsDisplay = YES;
|
|
331
|
+
}
|
|
332
|
+
- (void)unmarkText { self.marked = nil; self.needsDisplay = YES; }
|
|
333
|
+
- (BOOL)hasMarkedText { return self.marked.length != 0; }
|
|
334
|
+
- (NSRange)markedRange { return self.hasMarkedText ? NSMakeRange(0, self.marked.length) : NSMakeRange(NSNotFound, 0); }
|
|
335
|
+
- (NSRange)selectedRange { return self.hasMarkedText ? self.markedSelection : NSMakeRange(0, 0); }
|
|
336
|
+
- (NSArray<NSAttributedStringKey> *)validAttributesForMarkedText { return @[]; }
|
|
337
|
+
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)range actualRange:(NSRangePointer)actual {
|
|
338
|
+
NSRange match = NSIntersectionRange(range, NSMakeRange(0, self.marked.length));
|
|
339
|
+
if (actual) *actual = match;
|
|
340
|
+
return match.length ? [[NSAttributedString alloc] initWithString:[self.marked substringWithRange:match]] : nil;
|
|
341
|
+
}
|
|
342
|
+
- (NSUInteger)characterIndexForPoint:(NSPoint)point { return NSNotFound; }
|
|
343
|
+
- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actual {
|
|
344
|
+
if (actual) *actual = self.selectedRange;
|
|
345
|
+
NSRect local = NSMakeRect(self.caretPoint.x, self.caretPoint.y, 1, 18);
|
|
346
|
+
return [self.window convertRectToScreen:[self convertRect:local toView:nil]];
|
|
347
|
+
}
|
|
348
|
+
@end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#import <AppKit/AppKit.h>
|
|
2
|
+
|
|
3
|
+
typedef void (^WorkspaceReply)(id result, NSString *error);
|
|
4
|
+
typedef void (^WorkspaceCall)(NSString *method, NSDictionary *params, WorkspaceReply reply);
|
|
5
|
+
|
|
6
|
+
@interface WorkspacePanel : NSObject
|
|
7
|
+
- (instancetype)initWithCall:(WorkspaceCall)call;
|
|
8
|
+
- (void)show;
|
|
9
|
+
- (void)focusAddress:(id)sender;
|
|
10
|
+
- (void)newTab:(id)sender;
|
|
11
|
+
- (void)home:(id)sender;
|
|
12
|
+
- (void)toggleSplit:(id)sender;
|
|
13
|
+
- (void)goBack:(id)sender;
|
|
14
|
+
- (void)goForward:(id)sender;
|
|
15
|
+
- (void)reloadPage:(id)sender;
|
|
16
|
+
@end
|