aboutsummaryrefslogtreecommitdiff
path: root/src/content/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/controllers')
-rw-r--r--src/content/controllers/FollowKeyController.ts21
-rw-r--r--src/content/controllers/FollowMasterController.ts31
-rw-r--r--src/content/controllers/FollowSlaveController.ts32
-rw-r--r--src/content/controllers/KeymapController.ts16
4 files changed, 93 insertions, 7 deletions
diff --git a/src/content/controllers/FollowKeyController.ts b/src/content/controllers/FollowKeyController.ts
new file mode 100644
index 0000000..eb45e01
--- /dev/null
+++ b/src/content/controllers/FollowKeyController.ts
@@ -0,0 +1,21 @@
+import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase';
+import Key from '../domains/Key';
+
+export default class FollowKeyController {
+ private followSlaveUseCase: FollowSlaveUseCase;
+
+ constructor({
+ followSlaveUseCase = new FollowSlaveUseCase(),
+ } = {}) {
+ this.followSlaveUseCase = followSlaveUseCase;
+ }
+
+ press(key: Key): boolean {
+ if (!this.followSlaveUseCase.isFollowMode()) {
+ return false;
+ }
+
+ this.followSlaveUseCase.sendKey(key);
+ return true;
+ }
+}
diff --git a/src/content/controllers/FollowMasterController.ts b/src/content/controllers/FollowMasterController.ts
new file mode 100644
index 0000000..89294ff
--- /dev/null
+++ b/src/content/controllers/FollowMasterController.ts
@@ -0,0 +1,31 @@
+import FollowMasterUseCase from '../usecases/FollowMasterUseCase';
+import * as messages from '../../shared/messages';
+
+export default class FollowMasterController {
+ private followMasterUseCase: FollowMasterUseCase;
+
+ constructor({
+ followMasterUseCase = new FollowMasterUseCase(),
+ } = {}) {
+ this.followMasterUseCase = followMasterUseCase;
+ }
+
+ followStart(m: messages.FollowStartMessage): void {
+ this.followMasterUseCase.startFollow(m.newTab, m.background);
+ }
+
+ responseCountTargets(
+ m: messages.FollowResponseCountTargetsMessage, sender: Window,
+ ): void {
+ this.followMasterUseCase.createSlaveHints(m.count, sender);
+ }
+
+ keyPress(message: messages.FollowKeyPressMessage): void {
+ if (message.key === '[' && message.ctrlKey) {
+ this.followMasterUseCase.cancelFollow();
+ } else {
+ this.followMasterUseCase.enqueue(message.key);
+ }
+ }
+}
+
diff --git a/src/content/controllers/FollowSlaveController.ts b/src/content/controllers/FollowSlaveController.ts
new file mode 100644
index 0000000..88dccf3
--- /dev/null
+++ b/src/content/controllers/FollowSlaveController.ts
@@ -0,0 +1,32 @@
+import * as messages from '../../shared/messages';
+import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase';
+
+export default class FollowSlaveController {
+ private usecase: FollowSlaveUseCase;
+
+ constructor({
+ usecase = new FollowSlaveUseCase(),
+ } = {}) {
+ this.usecase = usecase;
+ }
+
+ countTargets(m: messages.FollowRequestCountTargetsMessage): void {
+ this.usecase.countTargets(m.viewSize, m.framePosition);
+ }
+
+ createHints(m: messages.FollowCreateHintsMessage): void {
+ this.usecase.createHints(m.viewSize, m.framePosition, m.tags);
+ }
+
+ showHints(m: messages.FollowShowHintsMessage): void {
+ this.usecase.showHints(m.prefix);
+ }
+
+ activate(m: messages.FollowActivateMessage): void {
+ this.usecase.activate(m.tag, m.newTab, m.background);
+ }
+
+ clear(_m: messages.FollowRemoveHintsMessage) {
+ this.usecase.clear();
+ }
+}
diff --git a/src/content/controllers/KeymapController.ts b/src/content/controllers/KeymapController.ts
index 424292c..20c24c0 100644
--- a/src/content/controllers/KeymapController.ts
+++ b/src/content/controllers/KeymapController.ts
@@ -8,6 +8,8 @@ import FocusUseCase from '../usecases/FocusUseCase';
import ClipboardUseCase from '../usecases/ClipboardUseCase';
import BackgroundClient from '../client/BackgroundClient';
import MarkKeyyUseCase from '../usecases/MarkKeyUseCase';
+import FollowMasterClient, { FollowMasterClientImpl }
+ from '../client/FollowMasterClient';
import Key from '../domains/Key';
export default class KeymapController {
@@ -29,6 +31,8 @@ export default class KeymapController {
private markKeyUseCase: MarkKeyyUseCase;
+ private followMasterClient: FollowMasterClient;
+
constructor({
keymapUseCase = new KeymapUseCase(),
addonEnabledUseCase = new AddonEnabledUseCase(),
@@ -39,6 +43,7 @@ export default class KeymapController {
clipbaordUseCase = new ClipboardUseCase(),
backgroundClient = new BackgroundClient(),
markKeyUseCase = new MarkKeyyUseCase(),
+ followMasterClient = new FollowMasterClientImpl(window.top),
} = {}) {
this.keymapUseCase = keymapUseCase;
this.addonEnabledUseCase = addonEnabledUseCase;
@@ -49,6 +54,7 @@ export default class KeymapController {
this.clipbaordUseCase = clipbaordUseCase;
this.backgroundClient = backgroundClient;
this.markKeyUseCase = markKeyUseCase;
+ this.followMasterClient = followMasterClient;
}
// eslint-disable-next-line complexity, max-lines-per-function
@@ -96,13 +102,9 @@ export default class KeymapController {
case operations.SCROLL_END:
this.scrollUseCase.scrollToEnd();
break;
- // case operations.FOLLOW_START:
- // window.top.postMessage(JSON.stringify({
- // type: messages.FOLLOW_START,
- // newTab: operation.newTab,
- // background: operation.background,
- // }), '*');
- // break;
+ case operations.FOLLOW_START:
+ this.followMasterClient.startFollow(op.newTab, op.background);
+ break;
case operations.MARK_SET_PREFIX:
this.markKeyUseCase.enableSetMode();
break;