Skip to content

Commit

Permalink
✨ Implement zoom support
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Jan 5, 2024
1 parent 4097921 commit 86d3219
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/content/src/browser/components/keybindings/Keybindings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
pref="browser.keybinds.previousTab"
on:command={() => setCurrentTabIndex(getCurrentTabIndex() - 1)}
/>

<Keybinding
pref="browser.keybinds.zoomIn"
on:command={() =>
runOnCurrentTab((tab) => tab.zoom.update((zoom) => zoom + 0.1))}
/>
<Keybinding
pref="browser.keybinds.zoomOut"
on:command={() =>
runOnCurrentTab((tab) => tab.zoom.update((zoom) => zoom - 0.1))}
/>

{#each [1, 2, 3, 4, 5, 6, 7, 8] as tabNum}
<Keybinding
pref={`browser.keybinds.tab${tabNum}`}
Expand Down
4 changes: 4 additions & 0 deletions apps/content/src/browser/components/omnibox/Omnibox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import Bookmarks from './Bookmarks.svelte'
import { pageActions } from '@browser/lib/modules/EPageActionsBindings'
import PageAction from './PageAction.svelte'
import ZoomDisplay from './ZoomDisplay.svelte'
const suggestionsModule = import('@shared/search/suggestions')
Expand All @@ -22,6 +23,7 @@
let selectedSuggestion = 0
$: uri = tab.uri
$: zoom = tab.zoom
async function generateSuggestions() {
const { suggestions: suggestionsMethod } = await suggestionsModule
Expand Down Expand Up @@ -89,6 +91,8 @@
}}
/>

<ZoomDisplay zoom={$zoom} on:click={() => zoom.set(1)} />

{#each $pageActions as [_extId, pageAction]}
{#if pageAction.shouldShow($uri.asciiSpec, tab.getTabId())}
<PageAction {pageAction} />
Expand Down
24 changes: 24 additions & 0 deletions apps/content/src/browser/components/omnibox/ZoomDisplay.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script lang="ts">
export let zoom: number
</script>

{#if zoom != 1}
<button on:click>
{Math.round(zoom * 100)}%
</button>
{/if}

<style>
button {
background: var(--surface);
border: none;
cursor: pointer;
border-radius: 0.25rem;
height: 2rem;
margin-right: 0.125rem;
}
button:hover {
background: var(--surface-1);
}
</style>
10 changes: 10 additions & 0 deletions apps/content/src/browser/lib/window/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class Tab {
public loading = writable(false)
public loadingProgress = writable(0)

public zoom = writable(1)

/**
* This is used by the omnibox to determine if text input should be focused.
*/
Expand All @@ -59,6 +61,11 @@ export class Tab {
this.goToUri(uri)
this.title.set(uri.asciiHost)

this.zoom.subscribe(
(newZoom) =>
this.browserElement.browsingContext &&
(this.browserElement.fullZoom = newZoom),
)
this.uri.subscribe(async (uri) =>
this.bookmarkInfo.set(
await search({ url: uri.spec }).then((r) =>
Expand Down Expand Up @@ -156,6 +163,9 @@ export class Tab {
this.uri.set(event.aLocation)
this.canGoBack.set(this.browserElement.canGoBack)
this.canGoForward.set(this.browserElement.canGoForward)
this.zoom.set(
this.browserElement.browsingContext ? this.browserElement.fullZoom : 1,
)
})

this.progressListener.events.on('progressPercent', this.loadingProgress.set)
Expand Down
3 changes: 3 additions & 0 deletions apps/content/src/settings/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<StringPref pref="browser.keybinds.nextTab">Next tab</StringPref>
<StringPref pref="browser.keybinds.previousTab">Previous Tab</StringPref>

<StringPref pref="browser.keybinds.zoomIn">Zoom in</StringPref>
<StringPref pref="browser.keybinds.zoomOut">Zoom out</StringPref>

{#each [1, 2, 3, 4, 5, 6, 7, 8] as tabNum}
<StringPref pref={`browser.keybinds.tab${tabNum}`}
>Jump to tab {tabNum}</StringPref
Expand Down
2 changes: 2 additions & 0 deletions apps/misc/static/defaults/pref/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pref('browser.keybinds.newTab', 'accel+T');
pref('browser.keybinds.closeTab', 'accel+W');
pref('browser.keybinds.nextTab', 'accel+VK_TAB');
pref('browser.keybinds.previousTab', 'accel+shift+VK_TAB');
pref('browser.keybinds.zoomIn', 'accel+=');
pref('browser.keybinds.zoomOut', 'accel+-');
pref('browser.keybinds.tab1', 'accel+1');
pref('browser.keybinds.tab2', 'accel+2');
pref('browser.keybinds.tab3', 'accel+3');
Expand Down
2 changes: 2 additions & 0 deletions libs/link/types/globals/Elements.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ declare interface XULBrowserElement extends HTMLElement {
canGoForward: boolean
goForward()
reload()
fullZoom: number
browsingContext?: unknown
loadURI(uri: nsIURIType, params?: LoadURIOptions)
browserId: number
mInitialized: boolean
Expand Down

0 comments on commit 86d3219

Please sign in to comment.