diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-19 09:34:40 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-19 09:34:40 +0900 |
commit | 4be04628e19392d8da9688d538cc3374e91005d8 (patch) | |
tree | 5c2299f6b85bf96dc9df65ddd7c27aef01b0ed69 /src/content/components/top-content | |
parent | e0c4182f14f908d13c8c814c7bc2b48a1791f881 (diff) |
Remove unused components
Diffstat (limited to 'src/content/components/top-content')
-rw-r--r-- | src/content/components/top-content/follow-controller.ts | 181 | ||||
-rw-r--r-- | src/content/components/top-content/index.ts | 47 |
2 files changed, 0 insertions, 228 deletions
diff --git a/src/content/components/top-content/follow-controller.ts b/src/content/components/top-content/follow-controller.ts deleted file mode 100644 index 43c917e..0000000 --- a/src/content/components/top-content/follow-controller.ts +++ /dev/null @@ -1,181 +0,0 @@ -import * as followControllerActions from '../../actions/follow-controller'; -import * as messages from '../../../shared/messages'; -import MessageListener from '../../MessageListener'; -import HintKeyProducer from '../../hint-key-producer'; - -import { SettingRepositoryImpl } from '../../repositories/SettingRepository'; -import FollowSlaveClient, { FollowSlaveClientImpl } - from '../../client/FollowSlaveClient'; - -let settingRepository = new SettingRepositoryImpl(); - -export default class FollowController { - private win: Window; - - private store: any; - - private state: { - enabled?: boolean; - newTab?: boolean; - background?: boolean; - keys?: string, - }; - - private keys: string[]; - - private producer: HintKeyProducer | null; - - constructor(win: Window, store: any) { - this.win = win; - this.store = store; - this.state = {}; - this.keys = []; - this.producer = null; - - new MessageListener().onWebMessage(this.onMessage.bind(this)); - - store.subscribe(() => { - this.update(); - }); - } - - onMessage(message: messages.Message, sender: Window) { - switch (message.type) { - case messages.FOLLOW_START: - return this.store.dispatch( - followControllerActions.enable(message.newTab, message.background)); - case messages.FOLLOW_RESPONSE_COUNT_TARGETS: - return this.create(message.count, sender); - case messages.FOLLOW_KEY_PRESS: - return this.keyPress(message.key, message.ctrlKey); - } - } - - update(): void { - let prevState = this.state; - this.state = this.store.getState().followController; - - if (!prevState.enabled && this.state.enabled) { - this.count(); - } else if (prevState.enabled && !this.state.enabled) { - this.remove(); - } else if (prevState.keys !== this.state.keys) { - this.updateHints(); - } - } - - updateHints(): void { - let shown = this.keys.filter((key) => { - return key.startsWith(this.state.keys as string); - }); - if (shown.length === 1) { - this.activate(); - this.store.dispatch(followControllerActions.disable()); - } - - this.broadcastMessage((c: FollowSlaveClient) => { - c.filterHints(this.state.keys!!); - }); - } - - activate(): void { - this.broadcastMessage((c: FollowSlaveClient) => { - c.activateIfExists( - this.state.keys!!, - this.state.newTab!!, - this.state.background!!); - }); - } - - keyPress(key: string, ctrlKey: boolean): boolean { - if (key === '[' && ctrlKey) { - this.store.dispatch(followControllerActions.disable()); - return true; - } - switch (key) { - case 'Enter': - this.activate(); - this.store.dispatch(followControllerActions.disable()); - break; - case 'Esc': - this.store.dispatch(followControllerActions.disable()); - break; - case 'Backspace': - case 'Delete': - this.store.dispatch(followControllerActions.backspace()); - break; - default: - if (this.hintchars().includes(key)) { - this.store.dispatch(followControllerActions.keyPress(key)); - } - break; - } - return true; - } - - count() { - this.producer = new HintKeyProducer(this.hintchars()); - let doc = this.win.document; - let viewWidth = this.win.innerWidth || doc.documentElement.clientWidth; - let viewHeight = this.win.innerHeight || doc.documentElement.clientHeight; - let frameElements = this.win.document.querySelectorAll('iframe'); - - new FollowSlaveClientImpl(this.win).requestHintCount( - { width: viewWidth, height: viewHeight }, - { x: 0, y: 0 }); - - for (let ele of Array.from(frameElements)) { - let { left: frameX, top: frameY } = ele.getBoundingClientRect(); - new FollowSlaveClientImpl(ele.contentWindow!!).requestHintCount( - { width: viewWidth, height: viewHeight }, - { x: frameX, y: frameY }, - ); - } - } - - create(count: number, sender: Window) { - let produced = []; - for (let i = 0; i < count; ++i) { - produced.push((this.producer as HintKeyProducer).produce()); - } - this.keys = this.keys.concat(produced); - - let doc = this.win.document; - let viewWidth = this.win.innerWidth || doc.documentElement.clientWidth; - let viewHeight = this.win.innerHeight || doc.documentElement.clientHeight; - let pos = { x: 0, y: 0 }; - if (sender !== window) { - let frameElements = this.win.document.querySelectorAll('iframe'); - let ele = Array.from(frameElements).find(e => e.contentWindow === sender); - if (!ele) { - // elements of the sender is gone - return; - } - let { left: frameX, top: frameY } = ele.getBoundingClientRect(); - pos = { x: frameX, y: frameY }; - } - new FollowSlaveClientImpl(sender).createHints( - { width: viewWidth, height: viewHeight }, - pos, - produced, - ); - } - - remove() { - this.keys = []; - this.broadcastMessage((c: FollowSlaveClient) => { - c.clearHints(); - }); - } - - private hintchars() { - return settingRepository.get().properties.hintchars; - } - - private broadcastMessage(f: (clinet: FollowSlaveClient) => void) { - let windows = [window.self].concat(Array.from(window.frames as any)); - windows - .map(w => new FollowSlaveClientImpl(w)) - .forEach(c => f(c)); - } -} diff --git a/src/content/components/top-content/index.ts b/src/content/components/top-content/index.ts deleted file mode 100644 index 0f07653..0000000 --- a/src/content/components/top-content/index.ts +++ /dev/null @@ -1,47 +0,0 @@ -import CommonComponent from '../common'; -import FollowController from './follow-controller'; -import * as consoleFrames from '../../console-frames'; -import * as messages from '../../../shared/messages'; -import MessageListener from '../../MessageListener'; -import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase'; -import { ScrollPresenterImpl } from '../../presenters/ScrollPresenter'; - -let addonEnabledUseCase = new AddonEnabledUseCase(); -let scrollPresenter = new ScrollPresenterImpl(); - -export default class TopContent { - private win: Window; - - constructor(win: Window, store: any) { - this.win = win; - - new CommonComponent(win, store); // eslint-disable-line no-new - new FollowController(win, store); // eslint-disable-line no-new - - // TODO make component - consoleFrames.initialize(this.win.document); - - new MessageListener().onWebMessage(this.onWebMessage.bind(this)); - new MessageListener().onBackgroundMessage( - this.onBackgroundMessage.bind(this)); - } - - onWebMessage(message: messages.Message) { - switch (message.type) { - case messages.CONSOLE_UNFOCUS: - this.win.focus(); - consoleFrames.blur(window.document); - } - } - - onBackgroundMessage(message: messages.Message) { - let addonEnabled = addonEnabledUseCase.getEnabled(); - - switch (message.type) { - case messages.ADDON_ENABLED_QUERY: - return Promise.resolve(addonEnabled); - case messages.TAB_SCROLL_TO: - return scrollPresenter.scrollTo(message.x, message.y, false); - } - } -} |