Skip to content

Commit

Permalink
🚧 Theoretically working tab drag image
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Dec 10, 2023
1 parent 4c10c3b commit 720873b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/content/browser/components/tabs/tabDrag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,13 @@ export function createTabDrag(tab: Tab) {
const dropAfter = writable(false)

const dragOverEvent = dragOver(tab, dropBefore, dropAfter)
const setDataTransferEvent = (event: DragEvent) => {
const setDataTransferEvent = async (event: DragEvent) => {
event.dataTransfer?.setData(
TAB_DATA_TYPE,
JSON.stringify(tab.getDragRepresentation()),
)
const canvas = await tab.captureTabToCanvas()
if (canvas) event.dataTransfer?.setDragImage(canvas, 0, 0)
}
const dragLeaveEvent = () => {
dropBefore.set(false)
Expand Down
3 changes: 3 additions & 0 deletions src/content/browser/lib/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { lazyESModuleGetters } from '../../shared/TypedImportUtilities'

/*eslint sort-keys: "error"*/

export const resource = lazyESModuleGetters({
E10SUtils: 'resource://gre/modules/E10SUtils.sys.mjs',
NetUtil: 'resource://gre/modules/NetUtil.sys.mjs',
PageThumbs: 'resource://gre/modules/PageThumbs.sys.mjs',
WindowTracker: 'resource://app/modules/BrowserWindowTracker.sys.mjs',
})
18 changes: 18 additions & 0 deletions src/content/browser/lib/window/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { type Writable, get, writable } from 'svelte/store'
import { type BookmarkTreeNode, search } from '@shared/ExtBookmarkAPI'
import { type ViewableWritable, viewableWritable } from '@shared/svelteUtils'

import { resource } from '../resources'
import { spinLock } from '../spinlock'
import { createBrowser, getBrowserRemoteType, setURI } from '../xul/browser'
import { domContentLoaded } from '../xul/domevents'
Expand Down Expand Up @@ -248,6 +249,23 @@ export class Tab {
otherFindbar?.remove()
tab.findbar.set(undefined)
}

public async captureTabToCanvas(
canvas: HTMLCanvasElement | null = resource.PageThumbs.createCanvas(window),
) {
try {
await resource.PageThumbs.captureToCanvas(
this.browserElement,
canvas,
undefined,
)
} catch (e) {
console.error(e)
canvas = null
}

return canvas
}
}

type TabProgressListenerEventDefaults = {
Expand Down

0 comments on commit 720873b

Please sign in to comment.