-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
510 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Background pages | ||
|
||
## Differences | ||
|
||
- Non-persistent background pages will not restart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# PageActions | ||
|
||
## Differences | ||
|
||
- `onClicked`: The first argument is the click info, not the `Tab` info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,47 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { nanoid } from 'nanoid' | ||
import { TAB_DATA_TYPE } from '@browser/components/tabs/tabDrag' | ||
|
||
import { resource } from '../resources' | ||
|
||
export const id = nanoid() | ||
export let id = -1 | ||
export const setId = (newId: number) => (id = newId) | ||
|
||
export const getWindowById = (id: string) => | ||
export const getWindowById = (id: number) => | ||
resource.WindowTracker.getWindowById(id) | ||
|
||
/** | ||
* If we want to detect drops outside of the window, we need to ensure that all | ||
* drops **within** a browser window are handled. | ||
* | ||
* This listens for all events with a type equivalent to {@link TAB_DATA_TYPE} | ||
* and makes sure they have an attached drop type. | ||
*/ | ||
export function initializeWindowDragOverHandler() { | ||
const handleDragEvent = (event: DragEvent) => { | ||
const rawDragRepresentation = event.dataTransfer?.getData(TAB_DATA_TYPE) | ||
if (!rawDragRepresentation) return | ||
|
||
// Set this to some drop event other than 'none' so we can detect drops | ||
// outside of the window in the tab's drag handler | ||
if (event.dataTransfer) event.dataTransfer.dropEffect = 'link' | ||
event.preventDefault() | ||
} | ||
|
||
window.addEventListener('dragover', handleDragEvent) | ||
window.addEventListener('drop', handleDragEvent) | ||
} | ||
|
||
/** | ||
* Ensures that the window tracker is aware of this window & that when it is | ||
* closed, the correct cleanup is performed. | ||
*/ | ||
export function registerWithWindowTracker() { | ||
resource.WindowTracker.registerWindow(window) | ||
window.addEventListener('unload', () => | ||
resource.WindowTracker.removeWindow(window), | ||
) | ||
|
||
window.addEventListener('focus', () => resource.WindowTracker.focusWindow(id)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { lazy } from './lazy' | ||
|
||
export type ClickModifiers = 'Shift' | 'Alt' | 'Command' | 'Ctrl' | 'MacCtrl' | ||
export const clickModifiersFromEvent = ( | ||
event: MouseEvent, | ||
): ClickModifiers[] => { | ||
const map = { | ||
shiftKey: 'Shift', | ||
altKey: 'Alt', | ||
metaKey: 'Command', | ||
ctrlKey: 'Ctrl', | ||
} as const | ||
|
||
const modifiers: ClickModifiers[] = (Object.keys(map) as (keyof typeof map)[]) | ||
.filter((key) => event[key]) | ||
.map((key) => map[key]) | ||
|
||
if (event.ctrlKey && lazy.AppConstants.platform === 'macosx') { | ||
modifiers.push('MacCtrl') | ||
} | ||
|
||
return modifiers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,68 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import mitt from 'resource://app/modules/mitt.sys.mjs' | ||
|
||
type Tab = unknown | ||
|
||
export type WindowTrackerEvents = { | ||
windowCreated: Window & typeof globalThis | ||
windowDestroyed: Window & typeof globalThis | ||
|
||
focus: Window & typeof globalThis | ||
} | ||
|
||
export const WindowTracker = { | ||
/** | ||
* @private | ||
*/ | ||
nextWindowId: 0, | ||
|
||
events: mitt<WindowTrackerEvents>(), | ||
|
||
registeredWindows: new Map<string, typeof window>(), | ||
activeWindow: null as number | null, | ||
registeredWindows: new Map<number, typeof window>(), | ||
|
||
/** | ||
* Registers a new browser window to be tracked | ||
* | ||
* @param w The window to register | ||
*/ | ||
registerWindow(w: typeof window) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
;(w as any).windowApi.id = this.nextWindowId++ | ||
this.registeredWindows.set((w as any).windowApi.id, w) | ||
this.events.emit('windowCreated', w) | ||
}, | ||
|
||
removeWindow(w: typeof window) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
this.registeredWindows.delete((w as any).windowApi.id) | ||
this.events.emit('windowDestroyed', w) | ||
}, | ||
|
||
getWindowById(wid: string) { | ||
getWindowById(wid: number) { | ||
return this.registeredWindows.get(wid) | ||
}, | ||
|
||
getWindowWithBrowser( | ||
browser: XULBrowserElement, | ||
): { window: Window & typeof globalThis; tab: Tab } | null { | ||
for (const window of this.registeredWindows.values()) { | ||
const tab = (window as any).windowApi.tabs.tabs.find( | ||
(t: Tab) => (t as any).getTabId() === browser.browserId, | ||
) | ||
if (tab) return { window, tab } | ||
} | ||
return null | ||
}, | ||
|
||
focusWindow(id: number) { | ||
this.activeWindow = id | ||
this.events.emit('focus', this.getActiveWindow()!) | ||
}, | ||
|
||
getActiveWindow(): (typeof window & typeof globalThis) | undefined { | ||
return this.registeredWindows.get(this.activeWindow ?? -1) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.