improved quick tab switcher & general tab design/logic;

This commit is contained in:
Fabian Freund committed 2026-06-12 03:47:20 +02:00
1 parent 83c78b53d3
commit 3c5f472bdf
35 files changed
+2715 -768

No files matched your search

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:weblibre/core/logger.dart';
import 'package:weblibre/features/geckoview/domain/providers/restore_complete.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
part 'pending_tab_selection.g.dart';
/// Queues the selection of a tab that exists in the local DB but has not
/// been delivered by the native session restore yet (placeholder chips at
/// cold start). The queued tab is selected as soon as its native state
/// arrives; the queue clears itself if restore finishes without it.
@Riverpod(keepAlive: true)
class PendingTabSelection extends _$PendingTabSelection {
void queue(String tabId) {
if (state != tabId) {
state = tabId;
}
}
void clear() {
state = null;
}
@override
String? build() {
ref.listen(
tabStatesProvider,
(previous, next) {
final pendingTabId = state;
if (pendingTabId != null && next.containsKey(pendingTabId)) {
state = null;
unawaited(
ref.read(tabRepositoryProvider.notifier).selectTab(pendingTabId),
);
}
},
onError: (error, stackTrace) {
logger.e(
'Error listening to tabStatesProvider',
error: error,
stackTrace: stackTrace,
);
},
);
// Stale-tab safety: when restore finishes and the queued id never
// appeared, the tab no longer exists.
ref.listen(browserRestoreCompleteProvider, (previous, next) {
if (next &&
state != null &&
!ref.read(tabStatesProvider).containsKey(state)) {
state = null;
}
});
return null;
}
}
@@ -0,0 +1,80 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'pending_tab_selection.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
/// Queues the selection of a tab that exists in the local DB but has not
/// been delivered by the native session restore yet (placeholder chips at
/// cold start). The queued tab is selected as soon as its native state
/// arrives; the queue clears itself if restore finishes without it.
@ProviderFor(PendingTabSelection)
final pendingTabSelectionProvider = PendingTabSelectionProvider._();
/// Queues the selection of a tab that exists in the local DB but has not
/// been delivered by the native session restore yet (placeholder chips at
/// cold start). The queued tab is selected as soon as its native state
/// arrives; the queue clears itself if restore finishes without it.
final class PendingTabSelectionProvider
extends $NotifierProvider<PendingTabSelection, String?> {
/// Queues the selection of a tab that exists in the local DB but has not
/// been delivered by the native session restore yet (placeholder chips at
/// cold start). The queued tab is selected as soon as its native state
/// arrives; the queue clears itself if restore finishes without it.
PendingTabSelectionProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'pendingTabSelectionProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$pendingTabSelectionHash();
@$internal
@override
PendingTabSelection create() => PendingTabSelection();
/// {@macro riverpod.override_with_value}
Override overrideWithValue(String? value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<String?>(value),
);
}
}
String _$pendingTabSelectionHash() =>
r'761d5814b40b1003b59db09a0bb7ef370530b317';
/// Queues the selection of a tab that exists in the local DB but has not
/// been delivered by the native session restore yet (placeholder chips at
/// cold start). The queued tab is selected as soon as its native state
/// arrives; the queue clears itself if restore finishes without it.
abstract class _$PendingTabSelection extends $Notifier<String?> {
String? build();
@$mustCallSuper
@override
void runBuild() {
final ref = this.ref as $Ref<String?, String?>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<String?, String?>,
String?,
Object?,
Object?
>;
element.handleCreate(ref, build);
}
}
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:weblibre/core/logger.dart';
import 'package:weblibre/features/geckoview/domain/providers.dart';
part 'restore_complete.g.dart';
/// Mirrors the native `BrowserState.restoreComplete` flag: false until the
/// session restore has dispatched all persisted tabs into the BrowserStore.
/// While false, DB-cached tabs without a native state are rendered as
/// placeholders and the destructive tab DB sync is deferred.
@Riverpod(keepAlive: true)
class BrowserRestoreComplete extends _$BrowserRestoreComplete {
@override
bool build() {
final eventService = ref.watch(eventServiceProvider);
ref.listen(
fireImmediately: true,
engineReadyStateProvider,
(previous, next) async {
if (next) {
await GeckoTabService().syncEvents(onRestoreComplete: true);
}
},
onError: (error, stackTrace) {
logger.e(
'Error listening to engineReadyStateProvider',
error: error,
stackTrace: stackTrace,
);
},
);
final restoreCompleteSub = eventService.restoreCompleteEvents.listen(
(restoreComplete) {
if (restoreComplete != state) {
state = restoreComplete;
}
},
onError: (Object error, StackTrace stackTrace) {
logger.e(
'Error in restore complete events',
error: error,
stackTrace: stackTrace,
);
},
);
ref.onDispose(() async {
await restoreCompleteSub.cancel();
});
return eventService.restoreCompleteEvents.valueOrNull ?? false;
}
}
@@ -0,0 +1,80 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'restore_complete.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
/// Mirrors the native `BrowserState.restoreComplete` flag: false until the
/// session restore has dispatched all persisted tabs into the BrowserStore.
/// While false, DB-cached tabs without a native state are rendered as
/// placeholders and the destructive tab DB sync is deferred.
@ProviderFor(BrowserRestoreComplete)
final browserRestoreCompleteProvider = BrowserRestoreCompleteProvider._();
/// Mirrors the native `BrowserState.restoreComplete` flag: false until the
/// session restore has dispatched all persisted tabs into the BrowserStore.
/// While false, DB-cached tabs without a native state are rendered as
/// placeholders and the destructive tab DB sync is deferred.
final class BrowserRestoreCompleteProvider
extends $NotifierProvider<BrowserRestoreComplete, bool> {
/// Mirrors the native `BrowserState.restoreComplete` flag: false until the
/// session restore has dispatched all persisted tabs into the BrowserStore.
/// While false, DB-cached tabs without a native state are rendered as
/// placeholders and the destructive tab DB sync is deferred.
BrowserRestoreCompleteProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'browserRestoreCompleteProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$browserRestoreCompleteHash();
@$internal
@override
BrowserRestoreComplete create() => BrowserRestoreComplete();
/// {@macro riverpod.override_with_value}
Override overrideWithValue(bool value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<bool>(value),
);
}
}
String _$browserRestoreCompleteHash() =>
r'971ce7722781b3cb581cfa9ada0884e91f723b85';
/// Mirrors the native `BrowserState.restoreComplete` flag: false until the
/// session restore has dispatched all persisted tabs into the BrowserStore.
/// While false, DB-cached tabs without a native state are rendered as
/// placeholders and the destructive tab DB sync is deferred.
abstract class _$BrowserRestoreComplete extends $Notifier<bool> {
bool build();
@$mustCallSuper
@override
void runBuild() {
final ref = this.ref as $Ref<bool, bool>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<bool, bool>,
bool,
Object?,
Object?
>;
element.handleCreate(ref, build);
}
}
@@ -32,6 +32,8 @@ import 'package:weblibre/extensions/uri.dart';
import 'package:weblibre/features/geckoview/domain/entities/states/tab.dart';
import 'package:weblibre/features/geckoview/domain/entities/tab_container_selection.dart';
import 'package:weblibre/features/geckoview/domain/providers.dart';
import 'package:weblibre/features/geckoview/domain/providers/pending_tab_selection.dart';
import 'package:weblibre/features/geckoview/domain/providers/restore_complete.dart';
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_list.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
@@ -456,6 +458,14 @@ class TabRepository extends _$TabRepository {
}
Future<bool> selectTab(String tabId) async {
// The tab is still a pre-restore placeholder (known to the DB but not to
// the engine yet): queue the selection until the native state arrives.
if (!ref.read(browserRestoreCompleteProvider) &&
!ref.read(tabStatesProvider).containsKey(tabId)) {
ref.read(pendingTabSelectionProvider.notifier).queue(tabId);
return true;
}
final containerData = await ref
.read(tabDataRepositoryProvider.notifier)
.getTabContainerData(tabId);
@@ -768,6 +778,18 @@ class TabRepository extends _$TabRepository {
}
}
Future<void> _drainPendingIsolationCleanup() async {
if (_pendingIsolationCleanup.isEmpty) return;
final pending = Set<String>.of(_pendingIsolationCleanup);
_pendingIsolationCleanup.clear();
for (final contextId in pending) {
if (!ref.mounted) break;
await _cleanupIsolationContextIfEmpty(contextId);
}
}
Future<void> undoClose() {
// Suppress the next reclose pass: undo can resurrect a tab whose
// tombstone is still on disk (from a previous session); without this
@@ -1037,9 +1059,14 @@ class TabRepository extends _$TabRepository {
return;
}
//Only sync tabs if there has been a previous value or is not empty
//Only sync tabs if there has been a previous value or is not empty.
//Additionally require the native session restore to have completed:
//a partial pre-restore list (e.g. a share-intent tab arriving first)
//must not delete the cached rows of tabs that are still being
//restored.
final shouldSyncTabs =
next.value.isNotEmpty || (previous?.value.isNotEmpty ?? false);
ref.read(browserRestoreCompleteProvider) &&
(next.value.isNotEmpty || (previous?.value.isNotEmpty ?? false));
if (shouldSyncTabs) {
final syncTabsResult = await db.tabDao.syncTabs(
@@ -1054,14 +1081,7 @@ class TabRepository extends _$TabRepository {
// Process pending isolation context cleanups after syncTabs
// has deleted the rows, so the count check is accurate.
if (_pendingIsolationCleanup.isNotEmpty) {
final pending = Set<String>.of(_pendingIsolationCleanup);
_pendingIsolationCleanup.clear();
for (final contextId in pending) {
if (!ref.mounted) break;
await _cleanupIsolationContextIfEmpty(contextId);
}
}
await _drainPendingIsolationCleanup();
// One-shot orphan cleanup after tab list stabilizes (5s debounce).
// Also runs for DB-only contexts whose rows were already deleted
@@ -1084,6 +1104,26 @@ class TabRepository extends _$TabRepository {
},
);
// Catch up on the tab list emissions skipped while the restore-complete
// gate above was closed: reconcile the DB once against the current list.
ref.listen(browserRestoreCompleteProvider, (
previous,
restoreComplete,
) async {
if (restoreComplete && !(previous ?? false)) {
final currentTabs = ref.read(tabListProvider).value;
if (currentTabs.isNotEmpty) {
final syncTabsResult = await db.tabDao.syncTabs(
retainTabIds: currentTabs,
);
_pendingIsolationCleanup.addAll(
syncTabsResult.deletedIsolationContextIds,
);
await _drainPendingIsolationCleanup();
}
}
});
final tabStateDebouncer = Debouncer(const Duration(seconds: 1));
Map<String, TabState>? debounceStartValue;
@@ -41,7 +41,7 @@ final class TabRepositoryProvider
}
}
String _$tabRepositoryHash() => r'd7b67460388c264f477325266a3299fe6df2df07';
String _$tabRepositoryHash() => r'982b80b8ea7c694958bc10cc7e8e15310af6a238';
abstract class _$TabRepository extends $Notifier<void> {
void build();
@@ -28,6 +28,7 @@ import 'package:weblibre/features/bangs/data/models/bang_data.dart';
import 'package:weblibre/features/bangs/data/models/bang_key.dart';
import 'package:weblibre/features/bangs/domain/repositories/data.dart';
import 'package:weblibre/features/geckoview/domain/entities/states/tab.dart';
import 'package:weblibre/features/geckoview/domain/providers/restore_complete.dart';
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_list.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
@@ -38,6 +39,7 @@ import 'package:weblibre/features/geckoview/features/search/domain/entities/tab_
import 'package:weblibre/features/geckoview/features/tabs/data/database/definitions.drift.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/container_filter.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_entity.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_mode.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
import 'package:weblibre/features/geckoview/features/tabs/domain/providers.dart';
import 'package:weblibre/features/geckoview/features/tabs/domain/providers/selected_container.dart';
@@ -176,6 +178,51 @@ EquatableValue<Map<String, TabState>> containerTabStates(
});
}
/// Synthesizes a placeholder [TabState] from a cached DB row for tabs the
/// native session restore hasn't delivered yet. `TabIcon` falls back to the
/// URL-cached favicon when [TabState.icon] is null, so placeholder chips
/// still render with proper icons and titles.
TabState _placeholderTabState(TabData tab) {
return TabState.$default(tab.id).copyWith(
url: tab.url ?? TabState.defaultUrl,
title: tab.title ?? '',
parentId: tab.parentId,
tabMode: TabMode.fromDbValue(
tab.tabMode,
isolationContextId: tab.isolationContextId,
),
);
}
/// Whether [tab] may be shown as a pre-restore placeholder. Private tabs are
/// never session-restored, so their rows must not produce dangling chips.
bool _canShowAsPlaceholder(TabData tab) =>
tab.tabMode != TabModeDbValue.private;
/// Ids of DB-cached tabs whose native state hasn't arrived yet. Empty once
/// the session restore completed (afterwards a missing native state means
/// the tab is gone, not pending).
@Riverpod()
EquatableValue<Set<String>> pendingRestoreTabIds(Ref ref) {
final restoreComplete = ref.watch(browserRestoreCompleteProvider);
if (restoreComplete) {
return EquatableValue(const {});
}
final nativeTabIds = ref.watch(
tabStatesProvider.select((states) => EquatableValue(states.keys.toSet())),
);
final dbTabs =
ref.watch(watchTabsFifoProvider.select((value) => value.value)) ??
const <TabData>[];
return EquatableValue({
for (final tab in dbTabs)
if (_canShowAsPlaceholder(tab) && !nativeTabIds.value.contains(tab.id))
tab.id,
});
}
@Riverpod(keepAlive: true)
EquatableValue<List<TabStateWithContainer>> fifoTabStates(Ref ref) {
final containerData = ref
@@ -189,13 +236,20 @@ EquatableValue<List<TabStateWithContainer>> fifoTabStates(Ref ref) {
);
final tabStates = ref.watch(tabStatesProvider);
final placeholdersActive = !ref.watch(browserRestoreCompleteProvider);
TabState? stateFor(TabData tab) =>
tabStates[tab.id] ??
(placeholdersActive && _canShowAsPlaceholder(tab)
? _placeholderTabState(tab)
: null);
return EquatableValue([
if (sortedTabs != null)
for (final tab in sortedTabs)
if (tabStates.containsKey(tab.id))
if (stateFor(tab) case final state?)
(
tabStates[tab.id]!,
state,
tab.containerId.mapNotNull(
(containerId) => containerData?[containerId],
),
@@ -218,11 +272,43 @@ selectedContainerTabStatesWithContainer(Ref ref) {
(value) => Map.fromEntries(value.map((c) => MapEntry(c.id, c))),
);
final sortedTabs = ref.watch(
containerTabEntitiesProvider(filter).select((value) => value.value),
);
final tabStates = ref.watch(tabStatesProvider);
final placeholdersActive = !ref.watch(browserRestoreCompleteProvider);
final selectedContainerTabsData = placeholdersActive
? ref.watch(
watchContainerTabsDataProvider(
filter.containerId,
).select((value) => value.value),
) ??
const <TabData>[]
: const <TabData>[];
final sortedTabs = placeholdersActive
? [
for (final tab in selectedContainerTabsData)
DefaultTabEntity(
tabId: tab.id,
orderKey: tab.orderKey,
containerId: tab.containerId,
),
]
: ref.watch(
containerTabEntitiesProvider(filter).select((value) => value.value),
);
final tabDataById = placeholdersActive
? {for (final tab in selectedContainerTabsData) tab.id: tab}
: const <String, TabData>{};
TabState? stateForEntity(String tabId) {
final state = tabStates[tabId];
if (state != null) {
return state;
}
final tabData = tabDataById[tabId];
if (tabData != null && _canShowAsPlaceholder(tabData)) {
return _placeholderTabState(tabData);
}
return null;
}
final groupedItems = ref
.watch(groupedTabListItemsProvider(containerId: filter.containerId))
@@ -294,12 +380,15 @@ selectedContainerTabStatesWithContainer(Ref ref) {
final groupedOrder = {
for (var i = 0; i < orderedItems.length; i++) orderedItems[i].tabId: i,
};
final orderKeyById = {
for (final tabEntity in sortedTabs) tabEntity.tabId: tabEntity.orderKey,
};
var items = [
for (final tabEntity in sortedTabs)
if (tabStates.containsKey(tabEntity.tabId))
if (stateForEntity(tabEntity.tabId) case final state?)
(
tabStates[tabEntity.tabId]!,
state,
tabEntity.containerId.mapNotNull(
(containerId) => containerData?[containerId],
),
@@ -307,9 +396,15 @@ selectedContainerTabStatesWithContainer(Ref ref) {
];
items.sort((a, b) {
final aIndex = groupedOrder[a.$1.id] ?? orderedItems.length;
final bIndex = groupedOrder[b.$1.id] ?? orderedItems.length;
return aIndex.compareTo(bIndex);
final aIndex = groupedOrder[a.$1.id];
final bIndex = groupedOrder[b.$1.id];
if (aIndex != null && bIndex != null) {
return aIndex.compareTo(bIndex);
}
if (aIndex != null) return -1;
if (bIndex != null) return 1;
return (orderKeyById[a.$1.id] ?? '').compareTo(orderKeyById[b.$1.id] ?? '');
});
// Flat pinned-first: move all pinned tabs before unpinned regardless of
@@ -330,14 +425,9 @@ EquatableValue<List<TabStateWithContainer>> quickTabSwitcherTabStates(
Ref ref,
QuickTabSwitcherMode mode,
) {
final effectiveMode = ref.watch(
generalSettingsWithDefaultsProvider.select(
(settings) => settings.effectiveUiQuickTabSwitcherMode(),
),
);
final selectedTabId = ref.watch(selectedTabProvider);
final tabStates = switch (effectiveMode) {
final tabStates = switch (mode) {
QuickTabSwitcherMode.lastUsedTabs => ref.watch(fifoTabStatesProvider).value,
QuickTabSwitcherMode.containerTabs =>
ref.watch(selectedContainerTabStatesWithContainerProvider).value,
@@ -352,7 +442,7 @@ EquatableValue<List<TabStateWithContainer>> quickTabSwitcherTabStates(
tabViewFilterControllerProvider.select((v) => v.sortPinnedFirst),
);
return EquatableValue(switch (effectiveMode) {
return EquatableValue(switch (mode) {
QuickTabSwitcherMode.lastUsedTabs => () {
final filtered = tabStates
.where((state) => state.$1.id != selectedTabId)
@@ -378,11 +468,6 @@ Future<List<VisitInfo>> quickTabSwitcherHistorySuggestions(
Ref ref,
QuickTabSwitcherMode mode,
) async {
final effectiveMode = ref.watch(
generalSettingsWithDefaultsProvider.select(
(settings) => settings.effectiveUiQuickTabSwitcherMode(),
),
);
final showHistorySuggestions = ref.watch(
generalSettingsWithDefaultsProvider.select(
(settings) => settings.quickTabSwitcherShowHistorySuggestions,
@@ -395,7 +480,7 @@ Future<List<VisitInfo>> quickTabSwitcherHistorySuggestions(
final hasTabStates = ref.watch(
quickTabSwitcherTabStatesProvider(
effectiveMode,
mode,
).select((value) => value.value.isNotEmpty),
);
if (hasTabStates) {
@@ -407,28 +492,15 @@ Future<List<VisitInfo>> quickTabSwitcherHistorySuggestions(
.getVisitsPaginated(count: 25);
}
@Riverpod()
AsyncValue<bool> quickTabSwitcherHasResults(
/// Whether a single switcher row of [mode] has anything to render
/// (open tabs, or history suggestions as fallback).
AsyncValue<bool> _quickTabSwitcherRowHasResults(
Ref ref,
QuickTabSwitcherMode mode,
) {
final effectiveMode = ref.watch(
generalSettingsWithDefaultsProvider.select(
(settings) => settings.effectiveUiQuickTabSwitcherMode(),
),
);
final showQuickTabSwitcherBar = ref.watch(
generalSettingsWithDefaultsProvider.select(
(settings) => settings.tabBarShowQuickTabSwitcherBar,
),
);
if (!showQuickTabSwitcherBar) {
return const AsyncValue.data(false);
}
final hasResults = ref.watch(
quickTabSwitcherTabStatesProvider(
effectiveMode,
mode,
).select((value) => value.value.isNotEmpty),
);
@@ -437,10 +509,64 @@ AsyncValue<bool> quickTabSwitcherHasResults(
}
return ref
.watch(quickTabSwitcherHistorySuggestionsProvider(effectiveMode))
.watch(quickTabSwitcherHistorySuggestionsProvider(mode))
.whenData((visits) => visits.isNotEmpty);
}
/// Number of 48px rows the quick tab switcher bar currently occupies.
/// 0 hides the bar; feeds the toolbar height / GeckoView viewport math.
@Riverpod()
AsyncValue<int> quickTabSwitcherRowCount(Ref ref) {
final stackingMode = ref.watch(
generalSettingsWithDefaultsProvider.select(
(settings) => settings.effectiveTabBarStackingMode(),
),
);
switch (stackingMode) {
case TabBarStackingMode.disabled:
return const AsyncValue.data(0);
case TabBarStackingMode.lastUsedTabs:
return _quickTabSwitcherRowHasResults(
ref,
QuickTabSwitcherMode.lastUsedTabs,
).whenData((hasResults) => hasResults ? 1 : 0);
case TabBarStackingMode.containerTabs:
return _quickTabSwitcherRowHasResults(
ref,
QuickTabSwitcherMode.containerTabs,
).whenData((hasResults) => hasResults ? 1 : 0);
case TabBarStackingMode.accordion:
final hasContainers = ref.watch(
watchContainersWithCountProvider.select(
(value) => value.value?.isNotEmpty ?? false,
),
);
if (hasContainers) {
return const AsyncValue.data(1);
}
return _quickTabSwitcherRowHasResults(
ref,
QuickTabSwitcherMode.containerTabs,
).whenData((hasResults) => hasResults ? 1 : 0);
case TabBarStackingMode.twoLevel:
final containerRow = _quickTabSwitcherRowHasResults(
ref,
QuickTabSwitcherMode.containerTabs,
);
final mruRow = _quickTabSwitcherRowHasResults(
ref,
QuickTabSwitcherMode.lastUsedTabs,
);
// The bar shows both rows whenever either has content; an empty row
// renders blank within its slot.
return containerRow.whenData(
(hasContainerTabs) =>
(hasContainerTabs || (mruRow.value ?? false)) ? 2 : 0,
);
}
}
@Riverpod()
EquatableValue<List<TabEntity>> suggestedTabEntities(
Ref ref,
@@ -424,6 +424,65 @@ final class ContainerTabStatesFamily extends $Family
String toString() => r'containerTabStatesProvider';
}
/// Ids of DB-cached tabs whose native state hasn't arrived yet. Empty once
/// the session restore completed (afterwards a missing native state means
/// the tab is gone, not pending).
@ProviderFor(pendingRestoreTabIds)
final pendingRestoreTabIdsProvider = PendingRestoreTabIdsProvider._();
/// Ids of DB-cached tabs whose native state hasn't arrived yet. Empty once
/// the session restore completed (afterwards a missing native state means
/// the tab is gone, not pending).
final class PendingRestoreTabIdsProvider
extends
$FunctionalProvider<
EquatableValue<Set<String>>,
EquatableValue<Set<String>>,
EquatableValue<Set<String>>
>
with $Provider<EquatableValue<Set<String>>> {
/// Ids of DB-cached tabs whose native state hasn't arrived yet. Empty once
/// the session restore completed (afterwards a missing native state means
/// the tab is gone, not pending).
PendingRestoreTabIdsProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'pendingRestoreTabIdsProvider',
isAutoDispose: true,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$pendingRestoreTabIdsHash();
@$internal
@override
$ProviderElement<EquatableValue<Set<String>>> $createElement(
$ProviderPointer pointer,
) => $ProviderElement(pointer);
@override
EquatableValue<Set<String>> create(Ref ref) {
return pendingRestoreTabIds(ref);
}
/// {@macro riverpod.override_with_value}
Override overrideWithValue(EquatableValue<Set<String>> value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<EquatableValue<Set<String>>>(value),
);
}
}
String _$pendingRestoreTabIdsHash() =>
r'a7c1639478ebed7d887d9b1d1296757d829dcc6b';
@ProviderFor(fifoTabStates)
final fifoTabStatesProvider = FifoTabStatesProvider._();
@@ -474,7 +533,7 @@ final class FifoTabStatesProvider
}
}
String _$fifoTabStatesHash() => r'f8dc69382d307bc83193a3b839a16313e9c1ab69';
String _$fifoTabStatesHash() => r'a512f96119561096b9cc7d6920e82da6d460ce68';
@ProviderFor(selectedContainerTabStatesWithContainer)
final selectedContainerTabStatesWithContainerProvider =
@@ -529,7 +588,7 @@ final class SelectedContainerTabStatesWithContainerProvider
}
String _$selectedContainerTabStatesWithContainerHash() =>
r'e6fd0e1e0ca4cfb0a0a46e8ff4e63d41032bfad9';
r'6e215f983140f7980d84e3f3d05a8afe95e6f1e7';
@ProviderFor(quickTabSwitcherTabStates)
final quickTabSwitcherTabStatesProvider = QuickTabSwitcherTabStatesFamily._();
@@ -601,7 +660,7 @@ final class QuickTabSwitcherTabStatesProvider
}
String _$quickTabSwitcherTabStatesHash() =>
r'213c9c492055175de8fc684e0c9fb9a3530fbb6f';
r'f61847bd68385e799384adfa5bfe735544fedbf5';
final class QuickTabSwitcherTabStatesFamily extends $Family
with
@@ -684,7 +743,7 @@ final class QuickTabSwitcherHistorySuggestionsProvider
}
String _$quickTabSwitcherHistorySuggestionsHash() =>
r'2e689ce72aac6b5b5b41e0390b168b3fdf5d4251';
r'3446741dfedf6fda9ab61421c1b74370c7f43f5b';
final class QuickTabSwitcherHistorySuggestionsFamily extends $Family
with
@@ -708,89 +767,56 @@ final class QuickTabSwitcherHistorySuggestionsFamily extends $Family
String toString() => r'quickTabSwitcherHistorySuggestionsProvider';
}
@ProviderFor(quickTabSwitcherHasResults)
final quickTabSwitcherHasResultsProvider = QuickTabSwitcherHasResultsFamily._();
/// Number of 48px rows the quick tab switcher bar currently occupies.
/// 0 hides the bar; feeds the toolbar height / GeckoView viewport math.
final class QuickTabSwitcherHasResultsProvider
@ProviderFor(quickTabSwitcherRowCount)
final quickTabSwitcherRowCountProvider = QuickTabSwitcherRowCountProvider._();
/// Number of 48px rows the quick tab switcher bar currently occupies.
/// 0 hides the bar; feeds the toolbar height / GeckoView viewport math.
final class QuickTabSwitcherRowCountProvider
extends
$FunctionalProvider<
AsyncValue<bool>,
AsyncValue<bool>,
AsyncValue<bool>
>
with $Provider<AsyncValue<bool>> {
QuickTabSwitcherHasResultsProvider._({
required QuickTabSwitcherHasResultsFamily super.from,
required QuickTabSwitcherMode super.argument,
}) : super(
retry: null,
name: r'quickTabSwitcherHasResultsProvider',
isAutoDispose: true,
dependencies: null,
$allTransitiveDependencies: null,
);
$FunctionalProvider<AsyncValue<int>, AsyncValue<int>, AsyncValue<int>>
with $Provider<AsyncValue<int>> {
/// Number of 48px rows the quick tab switcher bar currently occupies.
/// 0 hides the bar; feeds the toolbar height / GeckoView viewport math.
QuickTabSwitcherRowCountProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'quickTabSwitcherRowCountProvider',
isAutoDispose: true,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$quickTabSwitcherHasResultsHash();
@override
String toString() {
return r'quickTabSwitcherHasResultsProvider'
''
'($argument)';
}
String debugGetCreateSourceHash() => _$quickTabSwitcherRowCountHash();
@$internal
@override
$ProviderElement<AsyncValue<bool>> $createElement($ProviderPointer pointer) =>
$ProviderElement<AsyncValue<int>> $createElement($ProviderPointer pointer) =>
$ProviderElement(pointer);
@override
AsyncValue<bool> create(Ref ref) {
final argument = this.argument as QuickTabSwitcherMode;
return quickTabSwitcherHasResults(ref, argument);
AsyncValue<int> create(Ref ref) {
return quickTabSwitcherRowCount(ref);
}
/// {@macro riverpod.override_with_value}
Override overrideWithValue(AsyncValue<bool> value) {
Override overrideWithValue(AsyncValue<int> value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<AsyncValue<bool>>(value),
providerOverride: $SyncValueProvider<AsyncValue<int>>(value),
);
}
@override
bool operator ==(Object other) {
return other is QuickTabSwitcherHasResultsProvider &&
other.argument == argument;
}
@override
int get hashCode {
return argument.hashCode;
}
}
String _$quickTabSwitcherHasResultsHash() =>
r'5c488c9933372350c9e87ca1b83145176823dc88';
final class QuickTabSwitcherHasResultsFamily extends $Family
with $FunctionalFamilyOverride<AsyncValue<bool>, QuickTabSwitcherMode> {
QuickTabSwitcherHasResultsFamily._()
: super(
retry: null,
name: r'quickTabSwitcherHasResultsProvider',
dependencies: null,
$allTransitiveDependencies: null,
isAutoDispose: true,
);
QuickTabSwitcherHasResultsProvider call(QuickTabSwitcherMode mode) =>
QuickTabSwitcherHasResultsProvider._(argument: mode, from: this);
@override
String toString() => r'quickTabSwitcherHasResultsProvider';
}
String _$quickTabSwitcherRowCountHash() =>
r'81a2bfbdc4dc88fdf2c66dd9f5bfd6d1ce73a073';
@ProviderFor(suggestedTabEntities)
final suggestedTabEntitiesProvider = SuggestedTabEntitiesFamily._();
@@ -47,6 +47,7 @@ import 'package:weblibre/features/geckoview/features/browser/presentation/provid
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/addon_popup_bottom_sheet.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/browser_modules/bottom_app_bar.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/browser_modules/browser_fab.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/browser_modules/browser_system_bars.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/browser_modules/browser_view.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/browser_modules/draggable_fab.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/sheets/view_tab.dart';
@@ -115,7 +116,13 @@ class _AnimatedToolbar extends HookWidget {
);
}, [position]);
return SlideTransition(position: slideAnimation, child: child);
// RepaintBoundary so the (heavy) toolbar content is rasterized once and
// merely re-composited at a new offset for each frame of the slide, instead
// of repainting the whole chip row + favicons + menus every animation tick.
return SlideTransition(
position: slideAnimation,
child: RepaintBoundary(child: child),
);
}
}
@@ -124,7 +131,7 @@ class _AnimatedToolbar extends HookWidget {
class _TabBar extends HookConsumerWidget {
final bool showMainToolbar;
final bool showContextualToolbar;
final bool showQuickTabSwitcherBar;
final int quickTabSwitcherRowCount;
final Stream<Offset>? pointerMoveEvents;
final TabBarPosition tabBarPosition;
final bool isSmallWebMode;
@@ -133,7 +140,7 @@ class _TabBar extends HookConsumerWidget {
const _TabBar({
required this.showMainToolbar,
required this.showContextualToolbar,
required this.showQuickTabSwitcherBar,
required this.quickTabSwitcherRowCount,
required this.tabBarPosition,
required this.pointerMoveEvents,
required this.isSmallWebMode,
@@ -220,7 +227,7 @@ class _TabBar extends HookConsumerWidget {
TabBarPosition.top => BrowserTopAppBar(
showMainToolbar: showMainToolbar,
showContextualToolbar: showContextualToolbar,
showQuickTabSwitcherBar: showQuickTabSwitcherBar,
quickTabSwitcherRowCount: quickTabSwitcherRowCount,
isSmallWebMode: isSmallWebMode,
enableGestures: enableGestures,
),
@@ -228,7 +235,7 @@ class _TabBar extends HookConsumerWidget {
displayedSheet: displayedSheet,
showMainToolbar: showMainToolbar,
showContextualToolbar: showContextualToolbar,
showQuickTabSwitcherBar: showQuickTabSwitcherBar,
quickTabSwitcherRowCount: quickTabSwitcherRowCount,
isSmallWebMode: isSmallWebMode,
),
};
@@ -527,23 +534,9 @@ class BrowserScreen extends HookConsumerWidget {
),
);
final showQuickTabSwitcherBar =
!isSmallWebActive &&
ref.watch(
generalSettingsWithDefaultsProvider.select(
(value) => value.tabBarShowQuickTabSwitcherBar,
),
);
final quickTabSwitcherMode = ref.watch(
generalSettingsWithDefaultsProvider.select(
(value) => value.effectiveUiQuickTabSwitcherMode(),
),
);
final quickTabSwitcherHasResults = ref.watch(
quickTabSwitcherHasResultsProvider(quickTabSwitcherMode),
);
final displayQuickTabSwitcherBar =
showQuickTabSwitcherBar && (quickTabSwitcherHasResults.value ?? false);
final quickTabSwitcherRowCount = isSmallWebActive
? 0
: ref.watch(quickTabSwitcherRowCountProvider).value ?? 0;
final autoHideTabBar =
!isSmallWebActive &&
@@ -652,7 +645,7 @@ class BrowserScreen extends HookConsumerWidget {
bottomAppBarContentSize = BrowserBottomAppBar(
showMainToolbar: tabBarPosition == TabBarPosition.bottom,
showContextualToolbar: showContextualToolbar,
showQuickTabSwitcherBar: displayQuickTabSwitcherBar,
quickTabSwitcherRowCount: quickTabSwitcherRowCount,
isSmallWebMode: false,
displayedSheet: displayedSheet,
).preferredSize;
@@ -666,7 +659,7 @@ class BrowserScreen extends HookConsumerWidget {
final topAppBarContentSize = BrowserTopAppBar(
showMainToolbar: tabBarPosition == TabBarPosition.top,
showContextualToolbar: showContextualToolbar,
showQuickTabSwitcherBar: displayQuickTabSwitcherBar,
quickTabSwitcherRowCount: quickTabSwitcherRowCount,
isSmallWebMode: isSmallWebActive,
enableGestures: !isSmallWebActive,
).preferredSize;
@@ -919,6 +912,20 @@ class BrowserScreen extends HookConsumerWidget {
},
),
// Layer 0.5: System bar tint — fills the status-bar/nav-bar
// inset regions with the active container color (or the tab bar
// surface fallback) and drives the system bar icon brightness.
// Sits above the browser content but below the toolbars, so the
// tab bar's transparent safe-area padding reveals the bottom
// strip and the top toolbar's SafeArea reveals the top strip.
if (!tabInFullScreen)
Positioned.fill(
child: BrowserSystemBars(
topInset: topSafeArea,
bottomInset: bottomSafeArea,
),
),
// Layer 1: Sheet (when displayed) - positioned above toolbar
if (sheetDisplayed)
Positioned(
@@ -973,7 +980,7 @@ class BrowserScreen extends HookConsumerWidget {
showMainToolbar:
tabBarPosition == TabBarPosition.bottom,
showContextualToolbar: showContextualToolbar,
showQuickTabSwitcherBar: displayQuickTabSwitcherBar,
quickTabSwitcherRowCount: quickTabSwitcherRowCount,
isSmallWebMode: false,
pointerMoveEvents:
tabBarPosition == TabBarPosition.bottom
@@ -1012,7 +1019,7 @@ class BrowserScreen extends HookConsumerWidget {
tabBarPosition: TabBarPosition.top,
showMainToolbar: true,
showContextualToolbar: showContextualToolbar,
showQuickTabSwitcherBar: displayQuickTabSwitcherBar,
quickTabSwitcherRowCount: quickTabSwitcherRowCount,
isSmallWebMode: isSmallWebActive,
enableGestures: !isSmallWebActive,
pointerMoveEvents: isSmallWebActive
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/widgets.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_mode.dart';
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
/// Closes [tabId] with the shared UX contract: confirm before closing the
/// last tab of an isolation group, then offer undo via snackbar.
Future<void> closeTabWithConfirmationAndUndo(
BuildContext context,
WidgetRef ref,
String tabId,
) async {
// Confirm before closing the last tab in an isolation group
final tabState = ref.read(tabStateProvider(tabId));
if (tabState != null && tabState.tabMode is IsolatedTabMode) {
final allStates = ref.read(tabStatesProvider);
final groupCount = allStates.values
.where((s) => s.isolationContextId == tabState.isolationContextId)
.length;
if (groupCount <= 1 && context.mounted) {
final confirmed = await ui_helper.confirmIsolatedTabClose(context);
if (!confirmed) return;
}
}
await ref.read(tabRepositoryProvider.notifier).closeTab(tabId);
if (context.mounted) {
ui_helper.showTabUndoClose(
context,
ref.read(tabRepositoryProvider.notifier).undoClose,
);
}
}
@@ -25,13 +25,12 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nullability/nullability.dart';
import 'package:weblibre/core/design/app_colors.dart';
import 'package:weblibre/features/addons/presentation/widgets/pinned_addon_bar.dart';
import 'package:weblibre/features/geckoview/domain/controllers/bottom_sheet.dart';
import 'package:weblibre/features/geckoview/domain/providers/restore_complete.dart';
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/entities/sheet.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/providers.dart';
@@ -41,12 +40,12 @@ import 'package:weblibre/features/geckoview/features/browser/features/contextual
import 'package:weblibre/features/geckoview/features/browser/features/contextual_toolbar/presentation/widgets/contextual_toolbar.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/controllers/tab_view_controllers.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/controllers/toolbar_visibility.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/utils/close_tab_helper.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/utils/tab_view_reorder.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/browser_modules/app_bar_title.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_icon.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_menu.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/browser_modules/quick_tab_switcher_accordion.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/browser_modules/quick_tab_switcher_chip.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_view/tab_context_menu_draggable.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_view/tab_depth_indicator.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_view/tab_view_item.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/toolbar_button.dart';
import 'package:weblibre/features/geckoview/features/readerview/presentation/controllers/readerable.dart';
@@ -60,14 +59,17 @@ import 'package:weblibre/features/geckoview/features/tabs/utils/container_colors
import 'package:weblibre/features/user/data/models/general_settings.dart';
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
import 'package:weblibre/features/web_search/domain/controllers/sandbox_capture_controller.dart';
import 'package:weblibre/presentation/hooks/scroll_to_active_chip.dart';
import 'package:weblibre/presentation/widgets/selectable_chips.dart';
import 'package:weblibre/presentation/widgets/url_icon.dart';
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
export 'package:weblibre/features/geckoview/features/browser/presentation/widgets/browser_modules/quick_tab_switcher_chip.dart'
show QuickTabSwitcherItem;
class BrowserTopAppBar extends StatelessWidget {
final bool showMainToolbar;
final bool showContextualToolbar;
final bool showQuickTabSwitcherBar;
final int quickTabSwitcherRowCount;
final bool isSmallWebMode;
final bool enableGestures;
@@ -78,7 +80,7 @@ class BrowserTopAppBar extends StatelessWidget {
super.key,
required this.showMainToolbar,
required this.showContextualToolbar,
required this.showQuickTabSwitcherBar,
required this.quickTabSwitcherRowCount,
required this.isSmallWebMode,
this.enableGestures = true,
}) {
@@ -86,7 +88,7 @@ class BrowserTopAppBar extends StatelessWidget {
showMainToolbar: showMainToolbar,
displayedSheet: null,
showContextualToolbar: false,
showQuickTabSwitcherBar: false,
quickTabSwitcherRowCount: 0,
isSmallWebMode: isSmallWebMode,
enableGestures: enableGestures,
hideMainToolbarButtonsDuplicatedInContextualToolbar:
@@ -107,7 +109,7 @@ class BrowserTopAppBar extends StatelessWidget {
class BrowserBottomAppBar extends StatelessWidget {
final bool showMainToolbar;
final bool showContextualToolbar;
final bool showQuickTabSwitcherBar;
final int quickTabSwitcherRowCount;
final bool isSmallWebMode;
final Sheet? displayedSheet;
final bool enableGestures;
@@ -120,7 +122,7 @@ class BrowserBottomAppBar extends StatelessWidget {
required this.showMainToolbar,
required this.displayedSheet,
required this.showContextualToolbar,
required this.showQuickTabSwitcherBar,
required this.quickTabSwitcherRowCount,
required this.isSmallWebMode,
this.enableGestures = true,
}) {
@@ -128,7 +130,7 @@ class BrowserBottomAppBar extends StatelessWidget {
displayedSheet: displayedSheet,
showMainToolbar: showMainToolbar,
showContextualToolbar: showContextualToolbar,
showQuickTabSwitcherBar: showQuickTabSwitcherBar,
quickTabSwitcherRowCount: quickTabSwitcherRowCount,
isSmallWebMode: isSmallWebMode,
enableGestures: enableGestures,
hideMainToolbarButtonsDuplicatedInContextualToolbar:
@@ -139,12 +141,14 @@ class BrowserBottomAppBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final bottomPadding = MediaQuery.of(context).padding.bottom;
final colorScheme = Theme.of(context).colorScheme;
return Material(
shadowColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
color: colorScheme.surfaceContainer,
// Transparent so the navigation-bar inset region behind this padding is
// filled by the BrowserSystemBars tint strip (matching the active
// container color), instead of a fixed surfaceContainer fill.
color: Colors.transparent,
child: Padding(
padding: EdgeInsets.only(bottom: bottomPadding),
child: SizedBox(height: _size.height, child: _tabBar),
@@ -158,7 +162,7 @@ class BrowserBottomAppBar extends StatelessWidget {
class BrowserTabBar extends HookConsumerWidget {
final bool showMainToolbar;
final bool showContextualToolbar;
final bool showQuickTabSwitcherBar;
final int quickTabSwitcherRowCount;
final Sheet? displayedSheet;
final bool hideMainToolbarButtonsDuplicatedInContextualToolbar;
final bool isSmallWebMode;
@@ -169,7 +173,7 @@ class BrowserTabBar extends HookConsumerWidget {
required this.showMainToolbar,
required this.displayedSheet,
required this.showContextualToolbar,
required this.showQuickTabSwitcherBar,
required this.quickTabSwitcherRowCount,
required this.isSmallWebMode,
required this.enableGestures,
this.hideMainToolbarButtonsDuplicatedInContextualToolbar = false,
@@ -183,7 +187,7 @@ class BrowserTabBar extends HookConsumerWidget {
(!showContextualToolbar || displayedSheet is! ViewTabsSheet);
bool get displayQuickTabSwitcher =>
showQuickTabSwitcherBar && displayedSheet is! ViewTabsSheet;
quickTabSwitcherRowCount > 0 && displayedSheet is! ViewTabsSheet;
double getToolbarHeight() {
var height = 0.0;
@@ -197,7 +201,7 @@ class BrowserTabBar extends HookConsumerWidget {
}
if (displayQuickTabSwitcher) {
height += quickTabSwitcherHeight;
height += quickTabSwitcherHeight * quickTabSwitcherRowCount;
}
return height;
@@ -242,7 +246,7 @@ class BrowserTabBar extends HookConsumerWidget {
).select((data) => data.value?.metadata.useCustomColor ?? false),
);
final quickTabSwitcherMode = settings.effectiveUiQuickTabSwitcherMode();
final stackingMode = settings.effectiveTabBarStackingMode();
final tabBarPosition = settings.tabBarPosition;
@@ -269,7 +273,7 @@ class BrowserTabBar extends HookConsumerWidget {
return BrowserTabBarView(
showMainToolbar: showMainToolbar,
showContextualToolbar: showContextualToolbar,
showQuickTabSwitcherBar: showQuickTabSwitcherBar,
showQuickTabSwitcherBar: quickTabSwitcherRowCount > 0,
displayAppBar: displayAppBar,
displayQuickTabSwitcher: displayQuickTabSwitcher,
backgroundColor: effectiveContainerPalette?.surfaceColor,
@@ -308,9 +312,30 @@ class BrowserTabBar extends HookConsumerWidget {
if (showMainToolbarNavigationButton)
NavigationMenuButton(selectedTabId: selectedTabId),
],
quickTabSwitcher: QuickTabSwitcher(
quickTabSwitcherMode: quickTabSwitcherMode,
),
quickTabSwitcher: switch (stackingMode) {
TabBarStackingMode.disabled => const SizedBox.shrink(),
TabBarStackingMode.lastUsedTabs => const QuickTabSwitcher(
quickTabSwitcherMode: QuickTabSwitcherMode.lastUsedTabs,
),
TabBarStackingMode.containerTabs => const QuickTabSwitcher(
quickTabSwitcherMode: QuickTabSwitcherMode.containerTabs,
),
TabBarStackingMode.accordion => const AccordionQuickTabSwitcher(),
// History fallback only on the MRU row, so empty-state history
// chips don't show twice.
TabBarStackingMode.twoLevel => const Column(
mainAxisSize: MainAxisSize.min,
children: [
QuickTabSwitcher(
quickTabSwitcherMode: QuickTabSwitcherMode.containerTabs,
enableHistoryFallback: false,
),
QuickTabSwitcher(
quickTabSwitcherMode: QuickTabSwitcherMode.lastUsedTabs,
),
],
),
},
contextualToolbar: ContextualToolbar(
selectedTabId: selectedTabId,
displayedSheet: displayedSheet,
@@ -472,107 +497,19 @@ class BrowserTabBarView extends StatelessWidget {
}
}
class QuickTabSwitcherItem with FastEquatable {
final Color? color;
final bool useCustomColor;
final String id;
final bool isActive;
final TabMode tabMode;
final bool isHistory;
final bool isPinned;
final bool isSandbox;
final int depth;
final String title;
final Uri url;
final Widget avatar;
QuickTabSwitcherItem({
required this.color,
required this.id,
required this.isActive,
required this.tabMode,
required this.isHistory,
required this.isPinned,
required this.title,
required this.url,
required this.avatar,
this.useCustomColor = false,
this.isSandbox = false,
this.depth = 0,
});
/// Builds a switcher entry for an open tab. [sandboxSourceUri] is the
/// canonical source URL when the tab is a sandbox capture (otherwise null),
/// so the bar shows the real site instead of the loopback capture URL.
factory QuickTabSwitcherItem.tab(
TabStateWithContainer state, {
required String? selectedTabId,
required Set<String> pinnedTabIds,
required Map<String, int> tabDepthById,
required Uri? sandboxSourceUri,
}) {
final (tab, container) = state;
return QuickTabSwitcherItem(
color: container?.color,
useCustomColor: container?.metadata.useCustomColor ?? false,
id: tab.id,
isActive: tab.id == selectedTabId,
title: sandboxSourceUri != null && tab.title.isEmpty
? sandboxSourceUri.authority
: tab.titleOrAuthority,
tabMode: tab.tabMode,
isHistory: false,
isPinned: pinnedTabIds.contains(tab.id),
isSandbox: sandboxSourceUri != null,
depth: tabDepthById[tab.id] ?? 0,
url: sandboxSourceUri ?? tab.url,
avatar: TabIcon(tabState: tab, iconSize: 20),
);
}
/// Builds a switcher entry for a history suggestion (shown only when there
/// are no open tabs in the active mode).
factory QuickTabSwitcherItem.history({
required String url,
required String? title,
}) {
final parsedUrl = Uri.parse(url);
return QuickTabSwitcherItem(
color: null,
id: url,
isActive: false,
title: title ?? parsedUrl.authority,
tabMode: TabMode.regular,
isHistory: true,
isPinned: false,
url: parsedUrl,
avatar: UrlIcon([parsedUrl], iconSize: 20),
);
}
@override
List<Object?> get hashParameters => [
color,
useCustomColor,
id,
isActive,
tabMode,
isHistory,
isPinned,
isSandbox,
depth,
title,
url,
avatar,
];
}
class QuickTabSwitcher extends HookConsumerWidget {
final QuickTabSwitcherMode quickTabSwitcherMode;
const QuickTabSwitcher({super.key, required this.quickTabSwitcherMode});
/// Whether the row falls back to history suggestion chips when it has no
/// open tabs. Disabled for the top row in two-level stacking so history
/// chips don't show twice.
final bool enableHistoryFallback;
const QuickTabSwitcher({
super.key,
required this.quickTabSwitcherMode,
this.enableHistoryFallback = true,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
@@ -584,9 +521,14 @@ class QuickTabSwitcher extends HookConsumerWidget {
(s) => s.quickTabSwitcherShowTitles,
),
);
final effectiveMode = ref.watch(
final titleMaxWidth = ref.watch(
generalSettingsWithDefaultsProvider.select(
(settings) => settings.effectiveUiQuickTabSwitcherMode(),
(s) => s.quickTabSwitcherTitleWidth,
),
);
final showCloseButtonOnAllTabs = ref.watch(
generalSettingsWithDefaultsProvider.select(
(s) => s.quickTabSwitcherShowCloseButtonOnAllTabs,
),
);
final tabBarDirection = ref.watch(
@@ -596,9 +538,15 @@ class QuickTabSwitcher extends HookConsumerWidget {
quickTabSwitcherTabStatesProvider(quickTabSwitcherMode),
);
final selectedTabId = ref.watch(selectedTabProvider);
final historySuggestions = ref
.watch(quickTabSwitcherHistorySuggestionsProvider(quickTabSwitcherMode))
.value;
final historySuggestions = enableHistoryFallback
? ref
.watch(
quickTabSwitcherHistorySuggestionsProvider(
quickTabSwitcherMode,
),
)
.value
: null;
final sandboxCaptureMap =
ref.watch(sandboxCaptureMapProvider).value ?? const {};
// Reorder is only meaningful when the bar renders the user's actual tab
@@ -616,7 +564,7 @@ class QuickTabSwitcher extends HookConsumerWidget {
final showHierarchicalTabs = hierarchyGlyphs > 0;
final selectedContainerId = ref.watch(selectedContainerProvider);
final hierarchyContainerId =
effectiveMode == QuickTabSwitcherMode.containerTabs
quickTabSwitcherMode == QuickTabSwitcherMode.containerTabs
? selectedContainerId
: null;
@@ -639,8 +587,14 @@ class QuickTabSwitcher extends HookConsumerWidget {
(value) => value.value ?? const <String>{},
),
);
final reorderEnabled =
effectiveMode == QuickTabSwitcherMode.containerTabs && canManualReorder;
final restoreComplete = ref.watch(browserRestoreCompleteProvider);
final nativeTabIds = ref
.watch(
tabStatesProvider.select(
(states) => EquatableValue(states.keys.toSet()),
),
)
.value;
final tabItems = tabStates.value
.map(
(state) => QuickTabSwitcherItem.tab(
@@ -651,9 +605,17 @@ class QuickTabSwitcher extends HookConsumerWidget {
sandboxSourceUri: parseSandboxSource(
sandboxCaptureMap[state.$1.id],
),
isPlaceholder:
!restoreComplete && !nativeTabIds.contains(state.$1.id),
),
)
.toList();
// Reorder is disabled while placeholders are present: the engine doesn't
// know those tabs yet, so a reorder couldn't be applied consistently.
final reorderEnabled =
quickTabSwitcherMode == QuickTabSwitcherMode.containerTabs &&
canManualReorder &&
!tabItems.any((item) => item.isPlaceholder);
final historyItems = (historySuggestions ?? [])
.map(
(visit) =>
@@ -673,7 +635,6 @@ class QuickTabSwitcher extends HookConsumerWidget {
final activeItemKey = useRef(GlobalKey());
final isUserScrolling = useRef(false);
final userScrollTimer = useRef<Timer?>(null);
final didRunInitialAutoScroll = useRef(false);
final scrollKey = PageStorageKey(
'quick_tab_switcher_${quickTabSwitcherMode.name}',
);
@@ -682,61 +643,15 @@ class QuickTabSwitcher extends HookConsumerWidget {
return userScrollTimer.value?.cancel;
}, []);
useEffect(() {
if (isUserScrolling.value) return null;
final isInitialAutoScroll = !didRunInitialAutoScroll.value;
didRunInitialAutoScroll.value = true;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (isInitialAutoScroll &&
chipScrollController.hasClients &&
chipScrollController.offset != 0) {
return;
}
final context = activeItemKey.value.currentContext;
if (context != null) {
unawaited(
Scrollable.ensureVisible(
context,
alignment: 0.5,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
),
);
} else if (chipScrollController.hasClients) {
final activeIndex = availableItems.indexWhere(
(item) => item.id == selectedTabId,
);
if (activeIndex < 0) return;
final totalItems = availableItems.length;
final maxExtent = chipScrollController.position.maxScrollExtent;
if (totalItems > 0 && maxExtent > 0) {
chipScrollController.jumpTo(
(activeIndex / totalItems * maxExtent).clamp(0.0, maxExtent),
);
WidgetsBinding.instance.addPostFrameCallback((_) {
final retryContext = activeItemKey.value.currentContext;
if (retryContext != null) {
unawaited(
Scrollable.ensureVisible(
retryContext,
alignment: 0.5,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
),
);
}
});
}
}
});
return null;
}, [selectedTabId]);
// Keep the active chip centered when the selection or ordering changes,
// even if it is far outside the lazily-built range.
useScrollToActiveChip<String>(
controller: chipScrollController,
activeChipKey: activeItemKey.value,
activeId: (activeItem?.isActive ?? false) ? activeItem?.id : null,
orderedIds: [for (final item in availableItems) item.id],
isUserScrolling: () => isUserScrolling.value,
);
return NotificationListener<UserScrollNotification>(
onNotification: (notification) {
@@ -765,7 +680,12 @@ class QuickTabSwitcher extends HookConsumerWidget {
showTitles: showTitles,
showIsolatedTabUi: showIsolatedTabUi,
hierarchyGlyphs: hierarchyGlyphs,
enablePinTabInMenu: effectiveMode == QuickTabSwitcherMode.containerTabs,
titleMaxWidth: titleMaxWidth,
showCloseButtonOnAllTabs: showCloseButtonOnAllTabs,
enablePinTabInMenu:
quickTabSwitcherMode == QuickTabSwitcherMode.containerTabs,
onCloseItem: (item) =>
closeTabWithConfirmationAndUndo(context, ref, item.id),
onSelected: (item) async {
if (!item.isHistory && item.isActive) {
return;
@@ -837,8 +757,11 @@ class QuickTabSwitcherView extends StatelessWidget {
required this.showTitles,
required this.showIsolatedTabUi,
this.hierarchyGlyphs = defaultQuickTabSwitcherHierarchyGlyphs,
this.titleMaxWidth = defaultQuickTabSwitcherTitleWidth,
this.showCloseButtonOnAllTabs = false,
required this.enablePinTabInMenu,
required this.onSelected,
this.onCloseItem,
this.onReorderItem,
this.reorderableItemCount = 0,
});
@@ -855,9 +778,20 @@ class QuickTabSwitcherView extends StatelessWidget {
/// into an icon + count badge. A value of 0 hides the indicator entirely.
final int hierarchyGlyphs;
/// Max width of a chip's title text.
final double titleMaxWidth;
/// Whether every tab chip shows a close button. The active tab's chip
/// always shows one when [onCloseItem] is set.
final bool showCloseButtonOnAllTabs;
final bool enablePinTabInMenu;
final Future<void> Function(QuickTabSwitcherItem item) onSelected;
/// Close handler backing the chips' close buttons. When null no close
/// buttons are shown at all.
final Future<void> Function(QuickTabSwitcherItem item)? onCloseItem;
/// When non-null, the first [reorderableItemCount] items are rendered as a
/// horizontal `ReorderableListView` driven by this callback. Otherwise the
/// view falls back to the non-reorderable `SelectableChips` layout.
@@ -869,10 +803,19 @@ class QuickTabSwitcherView extends StatelessWidget {
bool get _reorderEnabled => onReorderItem != null && reorderableItemCount > 0;
/// Whether [item]'s chip shows a close button.
bool _canShowCloseButton(QuickTabSwitcherItem item) =>
onCloseItem != null &&
!item.isHistory &&
!item.isPlaceholder &&
(showCloseButtonOnAllTabs || item.isActive);
@override
Widget build(BuildContext context) {
if (availableItems.isEmpty) {
return const SizedBox.shrink();
// Hold the 48px row slot: in two-level stacking an empty row must not
// collapse, since the toolbar height already accounts for both rows.
return const SizedBox(height: 48);
}
return Padding(
@@ -889,7 +832,7 @@ class QuickTabSwitcherView extends StatelessWidget {
Widget _buildSelectableChips(BuildContext context) {
return SelectableChips<QuickTabSwitcherItem, QuickTabSwitcherItem, String>(
enableDelete: false,
enableDelete: onCloseItem != null,
sortSelectedFirst: false,
maxCount: null,
scrollController: scrollController,
@@ -902,8 +845,11 @@ class QuickTabSwitcherView extends StatelessWidget {
decoration: _chipDecoration(context),
itemLabel: (item) => _chipLabel(context, item, activeItem?.id == item.id),
onSelected: onSelected,
onDeleted: (item) {
unawaited(onCloseItem?.call(item));
},
itemWrap: (child, item) =>
item.isHistory ? child : _wrapWithMenu(itemId: item.id, child: child),
item.isHistory ? child : _wrapWithMenu(item: item, child: child),
availableItems: availableItems,
);
}
@@ -928,15 +874,14 @@ class QuickTabSwitcherView extends StatelessWidget {
itemBuilder: (context, index) {
final item = availableItems[index];
final isSelected = activeItem?.id == item.id;
final chip = _ReorderableSwitcherChip(
final chip = QuickTabSwitcherChip(
item: item,
isSelected: isSelected,
showTitles: showTitles,
showIsolatedTabUi: showIsolatedTabUi,
selectedBorderColor: Theme.of(context).colorScheme.primary,
decoration: _chipDecoration(context),
label: _chipLabel(context, item, isSelected),
onTap: () => onSelected(item),
onDelete: _canShowCloseButton(item) ? () => onCloseItem!(item) : null,
);
final keyedForActive = isSelected && activeItemKey != null
? KeyedSubtree(key: activeItemKey, child: chip)
@@ -956,72 +901,26 @@ class QuickTabSwitcherView extends StatelessWidget {
);
}
Widget _wrapWithMenu({required String itemId, required Widget child}) {
return TabMenu(
selectedTabId: itemId,
enableFindInPage: false,
enableFetchFeeds: false,
enableDesktopMode: false,
enableReaderMode: false,
enableReloadButton: false,
enableNavigationButtons: false,
enableAddToHomeScreen: false,
Widget _wrapWithMenu({
required QuickTabSwitcherItem item,
required Widget child,
}) {
return wrapQuickTabSwitcherChipWithMenu(
itemId: item.id,
enabled: !item.isPlaceholder,
enablePinTab: enablePinTabInMenu,
builder: (context, controller, _) {
return InkWell(
onLongPress: () {
if (controller.isOpen) {
controller.close();
} else {
controller.open();
}
},
child: child,
);
},
child: child,
);
}
SelectableChipDecoration<QuickTabSwitcherItem> _chipDecoration(
BuildContext context,
) {
return SelectableChipDecoration(
color: (item, isSelected) => switch (item.color) {
final color? when isSelected => ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).selectedBackgroundColor,
final color? => ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).backgroundColor,
null => null,
},
side: (item, isSelected) => switch (item.color) {
final color? when isSelected => ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).selectedBorderSide,
final color? => ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).borderSide,
null => null,
},
labelPadding: (item) =>
(!showTitles &&
!item.isHistory &&
!item.isPinned &&
!item.isSandbox &&
(item.depth == 0 || hierarchyGlyphs == 0) &&
item.tabMode is! PrivateTabMode &&
item.tabMode is! IsolatedTabMode)
? EdgeInsets.zero
: null,
return buildQuickTabSwitcherChipDecoration(
context,
showTitles: showTitles,
hierarchyGlyphs: hierarchyGlyphs,
canDelete: _canShowCloseButton,
);
}
@@ -1030,145 +929,14 @@ class QuickTabSwitcherView extends StatelessWidget {
QuickTabSwitcherItem item,
bool isSelected,
) {
final appColors = AppColors.of(context);
final hasTitle = item.isHistory || showTitles;
final row = Row(
mainAxisSize: MainAxisSize.min,
children: [
if (item.depth > 0 && hierarchyGlyphs > 0)
Padding(
padding: const EdgeInsets.only(right: 6.0),
child: TabDepthIndicator(
depth: item.depth,
height: 24.0,
iconSize: 14.0,
horizontalPadding: 4.0,
maxInlineGlyphs: hierarchyGlyphs,
),
),
Padding(
padding: EdgeInsets.only(right: hasTitle ? 6.0 : 0.0),
child: item.avatar,
),
if (hasTitle)
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 64),
child: Text(item.title),
),
if (showIsolatedTabUi && item.tabMode is IsolatedTabMode)
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(
MdiIcons.snowflake,
color: appColors.isolatedTabTeal,
size: 20,
),
)
else if (item.tabMode is PrivateTabMode)
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(
MdiIcons.dominoMask,
color: appColors.privateTabPurple,
size: 20,
),
),
if (item.isSandbox)
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(
MdiIcons.archiveLockOutline,
color: Theme.of(context).colorScheme.tertiary,
size: 20,
),
),
if (item.isPinned)
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(
MdiIcons.pin,
color: Theme.of(context).colorScheme.primary,
size: 20,
),
),
if (item.isHistory)
const Padding(
padding: EdgeInsets.only(left: 8.0),
child: Icon(MdiIcons.history, size: 20),
),
],
);
return item.color.mapNotNull(
(color) => DefaultTextStyle.merge(
style: TextStyle(
color: isSelected
? ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).selectedForegroundColor
: ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).foregroundColor,
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w500,
),
child: row,
),
) ??
row;
}
}
/// FilterChip matching `SelectableChips`' visual contract, used in the
/// reorderable render path. Stateless wrapper so the parent
/// `ReorderableListView` can attach its drag-handle gesture recognizer.
class _ReorderableSwitcherChip extends StatelessWidget {
final QuickTabSwitcherItem item;
final bool isSelected;
final bool showTitles;
final bool showIsolatedTabUi;
final Color selectedBorderColor;
final SelectableChipDecoration<QuickTabSwitcherItem> decoration;
final Widget label;
final Future<void> Function() onTap;
const _ReorderableSwitcherChip({
required this.item,
required this.isSelected,
required this.showTitles,
required this.showIsolatedTabUi,
required this.selectedBorderColor,
required this.decoration,
required this.label,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final itemColor = decoration.color?.call(item, isSelected);
final side =
decoration.side?.call(item, isSelected) ??
(isSelected
? BorderSide(color: selectedBorderColor, width: 2.0)
: null);
final labelPadding = decoration.labelPadding?.call(item);
return Padding(
padding: const EdgeInsets.only(right: 8.0, top: 4.0),
child: FilterChip(
color: itemColor != null ? WidgetStatePropertyAll(itemColor) : null,
selected: false,
showCheckmark: false,
labelPadding: labelPadding,
onSelected: (_) {
unawaited(onTap());
},
label: label,
side: side,
),
return buildQuickTabSwitcherChipLabel(
context,
item,
isSelected: isSelected,
showTitles: showTitles,
showIsolatedTabUi: showIsolatedTabUi,
hierarchyGlyphs: hierarchyGlyphs,
titleMaxWidth: titleMaxWidth,
);
}
}
@@ -0,0 +1,124 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
import 'package:weblibre/features/geckoview/features/tabs/domain/providers.dart';
import 'package:weblibre/features/geckoview/features/tabs/utils/container_colors.dart';
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
/// Tints the status-bar (top) and navigation-bar (bottom) inset regions with
/// the active container's surface color, mirroring how the tab bar
/// ([BrowserBottomAppBar]) tints itself, and drives the system bar icon
/// brightness so the icons stay legible against the tint.
///
/// The app runs edge-to-edge, so on modern Android the native
/// `statusBarColor` / `navigationBarColor` window attributes are ignored — the
/// system bars are transparent and content draws behind them. The inset
/// regions are therefore filled in Flutter, and only the icon brightness is
/// forwarded to the platform through [SystemUiOverlayStyle].
///
/// Designed to be placed as a full-bleed ([Positioned.fill]) layer in the
/// browser [Stack], above the browser content but below the toolbars. The tab
/// bar's safe-area padding is transparent, so the bottom strip shows through
/// behind a visible bottom toolbar and remains visible when it is hidden.
class BrowserSystemBars extends HookConsumerWidget {
final double topInset;
final double bottomInset;
const BrowserSystemBars({
super.key,
required this.topInset,
required this.bottomInset,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final colorScheme = Theme.of(context).colorScheme;
final selectedTabId = ref.watch(selectedTabProvider);
final showContainerUi = ref.watch(
generalSettingsWithDefaultsProvider.select((s) => s.showContainerUi),
);
final containerColor = ref.watch(
watchTabContainerDataProvider(
selectedTabId,
).select((data) => data.value?.color),
);
final useCustomColor = ref.watch(
watchTabContainerDataProvider(
selectedTabId,
).select((data) => data.value?.metadata.useCustomColor ?? false),
);
final effectiveContainerColor = (showContainerUi && containerColor != null)
? containerColor
: null;
final palette = effectiveContainerColor != null
? ContainerColors.palette(
context,
effectiveContainerColor,
useCustomColor: useCustomColor,
)
: null;
// Mirror the tab bar's surfaceContainer fallback so the inset regions stay
// visually attached to the toolbar even when no container is active.
final tintColor = palette?.surfaceColor ?? colorScheme.surfaceContainer;
// Icons must contrast with whatever fills the inset region.
final iconBrightness =
ThemeData.estimateBrightnessForColor(tintColor) == Brightness.dark
? Brightness.light
: Brightness.dark;
return IgnorePointer(
child: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarIconBrightness: iconBrightness,
systemNavigationBarIconBrightness: iconBrightness,
// iOS reports the bar's own brightness rather than the icons'.
statusBarBrightness: iconBrightness == Brightness.light
? Brightness.dark
: Brightness.light,
),
child: Stack(
children: [
Positioned(
top: 0,
left: 0,
right: 0,
height: topInset,
child: ColoredBox(color: tintColor),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
height: bottomInset,
child: ColoredBox(color: tintColor),
),
],
),
),
);
}
}
@@ -0,0 +1,555 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';
import 'package:fading_scroll/fading_scroll.dart';
import 'package:fast_equatable/fast_equatable.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:weblibre/features/geckoview/domain/providers/restore_complete.dart';
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/providers.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/utils/close_tab_helper.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/browser_modules/quick_tab_switcher_chip.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/container_filter.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_entity.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
import 'package:weblibre/features/geckoview/features/tabs/domain/providers.dart';
import 'package:weblibre/features/geckoview/features/tabs/domain/providers/selected_container.dart';
import 'package:weblibre/features/geckoview/features/tabs/presentation/widgets/container_chip_content.dart';
import 'package:weblibre/features/geckoview/features/tabs/utils/container_colors.dart';
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
import 'package:weblibre/features/web_search/domain/controllers/sandbox_capture_controller.dart';
import 'package:weblibre/presentation/hooks/scroll_to_active_chip.dart';
import 'package:weblibre/presentation/widgets/inline_count_badge.dart';
/// Accordion stacking mode for the quick tab switcher bar: every available
/// container renders as a header chip and the selected container is
/// "expanded" — its tabs appear inline right after its header. Tapping
/// another header selects that container, collapsing the previous group.
class AccordionQuickTabSwitcher extends HookConsumerWidget {
const AccordionQuickTabSwitcher({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final scrollController = useScrollController();
final activeChipKey = useRef(GlobalKey());
final isUserScrolling = useRef(false);
final userScrollTimer = useRef<Timer?>(null);
useEffect(() {
return userScrollTimer.value?.cancel;
}, []);
final showTitles = ref.watch(
generalSettingsWithDefaultsProvider.select(
(s) => s.quickTabSwitcherShowTitles,
),
);
final showIsolatedTabUi = ref.watch(
generalSettingsWithDefaultsProvider.select((s) => s.showIsolatedTabUi),
);
final hierarchyGlyphs = ref.watch(
generalSettingsWithDefaultsProvider.select(
(s) => s.quickTabSwitcherHierarchyGlyphs,
),
);
final titleMaxWidth = ref.watch(
generalSettingsWithDefaultsProvider.select(
(s) => s.quickTabSwitcherTitleWidth,
),
);
final showCloseButtonOnAllTabs = ref.watch(
generalSettingsWithDefaultsProvider.select(
(s) => s.quickTabSwitcherShowCloseButtonOnAllTabs,
),
);
final containers =
ref.watch(
watchContainersWithCountProvider.select((value) => value.value),
) ??
const <ContainerDataWithCount>[];
final selectedContainerId = ref.watch(selectedContainerProvider);
final selectedTabId = ref.watch(selectedTabProvider);
final unassignedTabCount = ref.watch(
containerTabCountProvider(
// ignore: provider_parameters
ContainerFilterById(containerId: null),
).select((value) => value.value ?? 0),
);
final expandedTabStates = ref.watch(
selectedContainerTabStatesWithContainerProvider,
);
final pinnedTabIds = ref.watch(
watchPinnedTabIdsProvider.select(
(value) => value.value ?? const <String>{},
),
);
final sandboxCaptureMap =
ref.watch(sandboxCaptureMapProvider).value ?? const {};
final restoreComplete = ref.watch(browserRestoreCompleteProvider);
final nativeTabIds = ref
.watch(
tabStatesProvider.select(
(states) => EquatableValue(states.keys.toSet()),
),
)
.value;
final tabDepthById = ref
.watch(
groupedTabListItemsProvider(containerId: selectedContainerId).select((
value,
) {
return EquatableValue(<String, int>{
if (hierarchyGlyphs > 0)
for (final item in value.value)
if (item is TabListChildItem) item.tabId: item.depth,
});
}),
)
.value;
final expandedItems = expandedTabStates.value
.map(
(state) => QuickTabSwitcherItem.tab(
state,
selectedTabId: selectedTabId,
pinnedTabIds: pinnedTabIds,
tabDepthById: tabDepthById,
sandboxSourceUri: parseSandboxSource(
sandboxCaptureMap[state.$1.id],
),
isPlaceholder:
!restoreComplete && !nativeTabIds.contains(state.$1.id),
),
)
.toList();
final decoration = buildQuickTabSwitcherChipDecoration(
context,
showTitles: showTitles,
hierarchyGlyphs: hierarchyGlyphs,
// The tray is painted in the container color, so the active tab's normal
// (transparent) selected border would blend in; give it a thicker border
// in the container's outline color instead.
thickContainerSelectedBorder: true,
);
Future<void> selectContainer(String? containerId) async {
if (containerId != null) {
await ref
.read(selectedContainerProvider.notifier)
.setContainerId(containerId);
} else {
ref.read(selectedContainerProvider.notifier).clearContainer();
}
}
Widget buildTabChip(QuickTabSwitcherItem item) {
final isSelected = item.isActive;
final canClose =
!item.isPlaceholder && (showCloseButtonOnAllTabs || item.isActive);
final chip = QuickTabSwitcherChip(
item: item,
isSelected: isSelected,
selectedBorderColor: Theme.of(context).colorScheme.primary,
decoration: decoration,
label: buildQuickTabSwitcherChipLabel(
context,
item,
isSelected: isSelected,
showTitles: showTitles,
showIsolatedTabUi: showIsolatedTabUi,
hierarchyGlyphs: hierarchyGlyphs,
titleMaxWidth: titleMaxWidth,
),
// Spacing inside the expanded group is owned by the surrounding tray
// slice so the slices abut into one continuous background.
padding: EdgeInsets.zero,
onTap: () async {
if (item.isActive) {
return;
}
await ref.read(tabRepositoryProvider.notifier).selectTab(item.id);
},
onDelete: canClose
? () => closeTabWithConfirmationAndUndo(context, ref, item.id)
: null,
);
return wrapQuickTabSwitcherChipWithMenu(
itemId: item.id,
enabled: !item.isPlaceholder,
enablePinTab: true,
child: chip,
);
}
final showUnassignedGroup =
unassignedTabCount > 0 || selectedContainerId == null;
final entries = <_AccordionEntry>[
if (showUnassignedGroup)
_AccordionEntry.header(
container: null,
tabCount: unassignedTabCount,
isExpanded: selectedContainerId == null,
),
if (selectedContainerId == null)
...expandedItems.map(_AccordionEntry.tab),
for (final container in containers) ...[
_AccordionEntry.header(
container: container,
tabCount: container.tabCount ?? 0,
isExpanded: container.id == selectedContainerId,
),
if (container.id == selectedContainerId)
...expandedItems.map(_AccordionEntry.tab),
],
];
// The expanded container header plus its tabs form one contiguous run that
// is wrapped in a shared "tray" background so the group reads as a unit and
// its members are visually distinct from the standalone container headers.
// Each entry only knows which slice of that tray it paints; the slices abut
// into one continuous rounded surface.
final trayPositions = <_TrayPosition>[
for (var i = 0; i < entries.length; i++)
switch (entries[i]) {
_AccordionHeaderEntry(:final isExpanded) =>
!isExpanded
? _TrayPosition.none
: (i + 1 < entries.length &&
entries[i + 1] is _AccordionTabEntry
? _TrayPosition.start
: _TrayPosition.solo),
_AccordionTabEntry() =>
(i + 1 >= entries.length || entries[i + 1] is _AccordionHeaderEntry)
? _TrayPosition.end
: _TrayPosition.middle,
},
];
// The expanded group's tray is filled with the container's color so the
// whole group reads as "this container". The unassigned group has no color
// and falls back to a neutral surface.
ContainerDataWithCount? expandedContainer;
for (final container in containers) {
if (container.id == selectedContainerId) {
expandedContainer = container;
break;
}
}
final scheme = Theme.of(context).colorScheme;
final trayPalette = expandedContainer != null
? ContainerColors.palette(
context,
expandedContainer.color,
useCustomColor: expandedContainer.metadata.useCustomColor,
)
: null;
final trayFill = trayPalette?.containerColor ?? scheme.surfaceContainerHigh;
// The chip to keep centered: the active tab when it is part of the
// expanded group, otherwise the expanded container header as a fallback.
final activeTabEntryId = 'tab-$selectedTabId';
final hasActiveTab = entries.any((entry) => entry.id == activeTabEntryId);
String? expandedHeaderId;
for (final entry in entries) {
if (entry is _AccordionHeaderEntry && entry.isExpanded) {
expandedHeaderId = entry.id;
break;
}
}
final activeEntryId = hasActiveTab ? activeTabEntryId : expandedHeaderId;
// Keep the active chip (or expanded header fallback) centered when the
// selection or ordering changes, unless the user is scrolling themselves.
useScrollToActiveChip<String>(
controller: scrollController,
activeChipKey: activeChipKey.value,
activeId: activeEntryId,
orderedIds: [for (final entry in entries) entry.id],
isUserScrolling: () => isUserScrolling.value,
);
if (entries.isEmpty) {
// Hold the 48px row slot; the bar visibility is decided upstream by
// quickTabSwitcherRowCountProvider.
return const SizedBox(height: 48);
}
return NotificationListener<UserScrollNotification>(
onNotification: (notification) {
userScrollTimer.value?.cancel();
isUserScrolling.value = true;
userScrollTimer.value = Timer(const Duration(milliseconds: 1500), () {
isUserScrolling.value = false;
});
return false;
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: SizedBox(
height: 48,
width: double.maxFinite,
child: FadingScroll(
controller: scrollController,
fadingSize: 15,
builder: (context, controller) {
return ListView.builder(
key: const PageStorageKey('quick_tab_switcher_accordion'),
controller: controller,
scrollDirection: Axis.horizontal,
scrollCacheExtent: const ScrollCacheExtent.pixels(500),
itemCount: entries.length,
itemBuilder: (context, index) {
final entry = entries[index];
final child = switch (entry) {
_AccordionHeaderEntry() => _AccordionHeaderChip(
entry: entry,
onSelected: () => selectContainer(entry.container?.id),
),
_AccordionTabEntry(:final item) => buildTabChip(item),
};
return KeyedSubtree(
key: entry.id == activeEntryId
? activeChipKey.value
: ValueKey(entry.id),
child: _TraySlice(
position: trayPositions[index],
fill: trayFill,
child: child,
),
);
},
);
},
),
),
),
);
}
}
sealed class _AccordionEntry {
const _AccordionEntry();
factory _AccordionEntry.header({
required ContainerDataWithCount? container,
required int tabCount,
required bool isExpanded,
}) = _AccordionHeaderEntry;
factory _AccordionEntry.tab(QuickTabSwitcherItem item) = _AccordionTabEntry;
String get id;
}
/// A container group header chip; [container] is null for the pseudo-group
/// of tabs without a container.
class _AccordionHeaderEntry extends _AccordionEntry {
final ContainerDataWithCount? container;
final int tabCount;
final bool isExpanded;
const _AccordionHeaderEntry({
required this.container,
required this.tabCount,
required this.isExpanded,
});
@override
String get id => 'container-${container?.id}';
}
class _AccordionTabEntry extends _AccordionEntry {
final QuickTabSwitcherItem item;
const _AccordionTabEntry(this.item);
@override
String get id => 'tab-${item.id}';
}
/// Container group header, rendered as a solid container-colored box. The fill
/// is the same whether the container is selected (expanded) or not — selection
/// only adds the surrounding tray and the inline tabs, it never recolors the
/// header chip itself.
class _AccordionHeaderChip extends StatelessWidget {
final _AccordionHeaderEntry entry;
final VoidCallback onSelected;
const _AccordionHeaderChip({required this.entry, required this.onSelected});
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final container = entry.container;
// The header content sits on the container color, so it always uses the
// on-container foreground.
final Color fill;
final Color nullForeground;
final Color badgeBackground;
final Color badgeForeground;
if (container != null) {
final palette = ContainerColors.palette(
context,
container.color,
useCustomColor: container.metadata.useCustomColor,
);
fill = palette.containerColor;
nullForeground = palette.onContainerColor;
badgeBackground = palette.badgeBackgroundColor;
badgeForeground = palette.badgeForegroundColor;
} else {
fill = scheme.surfaceContainerHigh;
nullForeground = scheme.onSurfaceVariant;
badgeBackground = scheme.secondaryContainer;
badgeForeground = scheme.onSecondaryContainer;
}
final countBadge = entry.tabCount > 0
? InlineCountBadge(
count: entry.tabCount,
backgroundColor: badgeBackground,
foregroundColor: badgeForeground,
)
: null;
return FilterChip(
avatar: container != null
? buildContainerChipAvatar(context, container, true)
: Icon(MdiIcons.folderHidden, color: nullForeground),
label: container != null
? buildContainerChipLabel(
context,
container,
true,
trailing: countBadge,
)
: SizedBox(
height: 20,
child: Center(
child:
countBadge ??
DefaultTextStyle.merge(
style: TextStyle(color: nullForeground),
child: const SizedBox.shrink(),
),
),
),
// Same fill regardless of selection — the tray (added when expanded)
// is what signals the active container, not a header recolor.
color: WidgetStatePropertyAll(fill),
selected: false,
showCheckmark: false,
onSelected: (value) {
if (value) {
onSelected();
}
},
side: BorderSide(width: 2, color: fill),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
side: BorderSide(width: 2, color: fill),
),
);
}
}
/// Where a chip sits within the expanded container's tray, controlling which
/// rounded corners and edge padding its [_TraySlice] paints. [none] is a
/// standalone (collapsed) header that carries no tray.
enum _TrayPosition { none, solo, start, middle, end }
/// One slice of the shared tray behind an expanded group's chips. Adjacent
/// slices abut with matching height and seam padding so their fill merges into
/// a single continuous rounded, container-colored surface spanning the header
/// and its tabs.
class _TraySlice extends StatelessWidget {
final _TrayPosition position;
final Color fill;
final Widget child;
const _TraySlice({
required this.position,
required this.fill,
required this.child,
});
/// Corner radius of the chips, matched by the tray so it hugs the first and
/// last chip's edges exactly.
static const Radius _radius = Radius.circular(8.0);
@override
Widget build(BuildContext context) {
if (position == _TrayPosition.none) {
// Standalone container header: regular inter-chip spacing, vertically
// centered to line up with the tray slices.
return Padding(
padding: const EdgeInsets.fromLTRB(0.0, 2.0, 8.0, 2.0),
child: child,
);
}
final borderRadius = switch (position) {
_TrayPosition.solo => const BorderRadius.all(_radius),
_TrayPosition.start => const BorderRadius.horizontal(left: _radius),
_TrayPosition.end => const BorderRadius.horizontal(right: _radius),
_TrayPosition.middle || _TrayPosition.none => BorderRadius.zero,
};
final isRightEdge =
position == _TrayPosition.end || position == _TrayPosition.solo;
return Padding(
padding: EdgeInsets.only(
top: 2.0,
bottom: 2.0,
// Transparent gap after the tray so a following standalone header
// doesn't butt up against the rounded right edge.
right: isRightEdge ? 8.0 : 0.0,
),
child: SizedBox(
height: 44.0,
child: Container(
decoration: BoxDecoration(color: fill, borderRadius: borderRadius),
// A small inset on every side so the first/last chip get the same
// breathing room from the tray edge as the inter-chip seam gaps.
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: Center(child: child),
),
),
);
}
}
@@ -0,0 +1,404 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';
import 'package:fast_equatable/fast_equatable.dart';
import 'package:flutter/material.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:nullability/nullability.dart';
import 'package:weblibre/core/design/app_colors.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/providers.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_icon.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_menu.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_view/tab_depth_indicator.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_mode.dart';
import 'package:weblibre/features/geckoview/features/tabs/utils/container_colors.dart';
import 'package:weblibre/presentation/widgets/selectable_chips.dart';
import 'package:weblibre/presentation/widgets/url_icon.dart';
class QuickTabSwitcherItem with FastEquatable {
final Color? color;
final bool useCustomColor;
final String id;
final bool isActive;
final TabMode tabMode;
final bool isHistory;
final bool isPinned;
final bool isSandbox;
final int depth;
final String title;
final Uri url;
final Widget avatar;
/// True while the tab is only known from the local DB cache and the native
/// session restore hasn't delivered its state yet. Placeholders cannot be
/// closed or reordered.
final bool isPlaceholder;
QuickTabSwitcherItem({
required this.color,
required this.id,
required this.isActive,
required this.tabMode,
required this.isHistory,
required this.isPinned,
required this.title,
required this.url,
required this.avatar,
this.useCustomColor = false,
this.isSandbox = false,
this.depth = 0,
this.isPlaceholder = false,
});
/// Builds a switcher entry for an open tab. [sandboxSourceUri] is the
/// canonical source URL when the tab is a sandbox capture (otherwise null),
/// so the bar shows the real site instead of the loopback capture URL.
factory QuickTabSwitcherItem.tab(
TabStateWithContainer state, {
required String? selectedTabId,
required Set<String> pinnedTabIds,
required Map<String, int> tabDepthById,
required Uri? sandboxSourceUri,
bool isPlaceholder = false,
}) {
final (tab, container) = state;
return QuickTabSwitcherItem(
color: container?.color,
useCustomColor: container?.metadata.useCustomColor ?? false,
id: tab.id,
isActive: tab.id == selectedTabId,
title: sandboxSourceUri != null && tab.title.isEmpty
? sandboxSourceUri.authority
: tab.titleOrAuthority,
tabMode: tab.tabMode,
isHistory: false,
isPinned: pinnedTabIds.contains(tab.id),
isSandbox: sandboxSourceUri != null,
depth: tabDepthById[tab.id] ?? 0,
url: sandboxSourceUri ?? tab.url,
avatar: TabIcon(tabState: tab, iconSize: 20),
isPlaceholder: isPlaceholder,
);
}
/// Builds a switcher entry for a history suggestion (shown only when there
/// are no open tabs in the active mode).
factory QuickTabSwitcherItem.history({
required String url,
required String? title,
}) {
final parsedUrl = Uri.parse(url);
return QuickTabSwitcherItem(
color: null,
id: url,
isActive: false,
title: title ?? parsedUrl.authority,
tabMode: TabMode.regular,
isHistory: true,
isPinned: false,
url: parsedUrl,
avatar: UrlIcon([parsedUrl], iconSize: 20),
);
}
@override
List<Object?> get hashParameters => [
color,
useCustomColor,
id,
isActive,
tabMode,
isHistory,
isPinned,
isSandbox,
depth,
title,
url,
avatar,
isPlaceholder,
];
}
/// Visual contract shared by every quick tab switcher render path
/// ([SelectableChips], the reorderable list, and the accordion view).
SelectableChipDecoration<QuickTabSwitcherItem>
buildQuickTabSwitcherChipDecoration(
BuildContext context, {
required bool showTitles,
required int hierarchyGlyphs,
bool Function(QuickTabSwitcherItem item)? canDelete,
// When true, the selected item gets a thicker border in its container's
// outline color (instead of the usual transparent selected border). The
// accordion uses this so the active tab stays visible against its
// container-colored tray while matching the unselected chips' border color.
bool thickContainerSelectedBorder = false,
}) {
return SelectableChipDecoration(
color: (item, isSelected) => switch (item.color) {
final color? when isSelected => ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).selectedBackgroundColor,
final color? => ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).backgroundColor,
null => null,
},
side: (item, isSelected) => switch (item.color) {
final color? when isSelected => thickContainerSelectedBorder
? BorderSide(
color: ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).outlineColor,
width: 2.0,
)
: ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).selectedBorderSide,
final color? => ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).borderSide,
null => null,
},
labelPadding: (item) =>
(!showTitles &&
!item.isHistory &&
!item.isPinned &&
!item.isSandbox &&
(item.depth == 0 || hierarchyGlyphs == 0) &&
item.tabMode is! PrivateTabMode &&
item.tabMode is! IsolatedTabMode)
? EdgeInsets.zero
: null,
canDelete: canDelete,
deleteIcon: (_) => const Icon(Icons.close, size: 18),
);
}
Widget buildQuickTabSwitcherChipLabel(
BuildContext context,
QuickTabSwitcherItem item, {
required bool isSelected,
required bool showTitles,
required bool showIsolatedTabUi,
required int hierarchyGlyphs,
required double titleMaxWidth,
}) {
final appColors = AppColors.of(context);
final hasTitle = item.isHistory || showTitles;
final row = Row(
mainAxisSize: MainAxisSize.min,
children: [
if (item.depth > 0 && hierarchyGlyphs > 0)
Padding(
padding: const EdgeInsets.only(right: 6.0),
child: TabDepthIndicator(
depth: item.depth,
height: 20.0,
iconSize: 14.0,
horizontalPadding: 4.0,
maxInlineGlyphs: hierarchyGlyphs,
),
),
Padding(
padding: EdgeInsets.only(right: hasTitle ? 6.0 : 0.0),
child: item.avatar,
),
if (hasTitle)
ConstrainedBox(
constraints: BoxConstraints(maxWidth: titleMaxWidth),
child: Text(item.title),
),
if (showIsolatedTabUi && item.tabMode is IsolatedTabMode)
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(
MdiIcons.snowflake,
color: appColors.isolatedTabTeal,
size: 20,
),
)
else if (item.tabMode is PrivateTabMode)
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(
MdiIcons.dominoMask,
color: appColors.privateTabPurple,
size: 20,
),
),
if (item.isSandbox)
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(
MdiIcons.archiveLockOutline,
color: Theme.of(context).colorScheme.tertiary,
size: 20,
),
),
if (item.isPinned)
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(
MdiIcons.pin,
color: Theme.of(context).colorScheme.primary,
size: 20,
),
),
if (item.isHistory)
const Padding(
padding: EdgeInsets.only(left: 8.0),
child: Icon(MdiIcons.history, size: 20),
),
],
);
return item.color.mapNotNull(
(color) => DefaultTextStyle.merge(
style: TextStyle(
color: isSelected
? ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).selectedForegroundColor
: ContainerColors.palette(
context,
color,
useCustomColor: item.useCustomColor,
).foregroundColor,
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w500,
),
child: row,
),
) ??
row;
}
/// FilterChip matching [SelectableChips]' visual contract, used by render
/// paths that can't go through [SelectableChips] itself (the reorderable
/// list and the accordion view). Stateless wrapper so a parent
/// `ReorderableListView` can attach its drag-handle gesture recognizer.
class QuickTabSwitcherChip extends StatelessWidget {
final QuickTabSwitcherItem item;
final bool isSelected;
final Color selectedBorderColor;
final SelectableChipDecoration<QuickTabSwitcherItem> decoration;
final Widget label;
final Future<void> Function() onTap;
final Future<void> Function()? onDelete;
/// Outer spacing around the chip. Defaults to the standard inter-chip gap;
/// render paths that manage their own spacing (e.g. the accordion tray)
/// pass [EdgeInsets.zero].
final EdgeInsetsGeometry padding;
const QuickTabSwitcherChip({
super.key,
required this.item,
required this.isSelected,
required this.selectedBorderColor,
required this.decoration,
required this.label,
required this.onTap,
this.onDelete,
this.padding = const EdgeInsets.only(right: 8.0, top: 4.0),
});
@override
Widget build(BuildContext context) {
final itemColor = decoration.color?.call(item, isSelected);
final side =
decoration.side?.call(item, isSelected) ??
(isSelected
? BorderSide(color: selectedBorderColor, width: 2.0)
: null);
final labelPadding = decoration.labelPadding?.call(item);
return Padding(
padding: padding,
child: FilterChip(
color: itemColor != null ? WidgetStatePropertyAll(itemColor) : null,
selected: false,
showCheckmark: false,
labelPadding: labelPadding,
onSelected: (_) {
unawaited(onTap());
},
deleteIcon: decoration.deleteIcon?.call(item),
onDeleted: onDelete != null
? () {
unawaited(onDelete!());
}
: null,
label: label,
side: side,
),
);
}
}
/// Wraps a tab chip in the long-press [TabMenu] used across switcher views.
Widget wrapQuickTabSwitcherChipWithMenu({
required String itemId,
required bool enabled,
required bool enablePinTab,
required Widget child,
}) {
if (!enabled) {
return child;
}
return TabMenu(
selectedTabId: itemId,
enableFindInPage: false,
enableFetchFeeds: false,
enableDesktopMode: false,
enableReaderMode: false,
enableReloadButton: false,
enableNavigationButtons: false,
enableAddToHomeScreen: false,
enablePinTab: enablePinTab,
builder: (context, controller, _) {
return InkWell(
onLongPress: () {
if (controller.isOpen) {
controller.close();
} else {
controller.open();
}
},
child: child,
);
},
);
}
@@ -60,23 +60,33 @@ class TabIcon extends HookConsumerWidget {
return UrlIcon([sandboxSourceUri], iconSize: iconSize, cacheOnly: true);
}
return Skeletonizer(
enabled: icon.connectionState != ConnectionState.done,
child: Skeleton.replace(
replacement: Bone.icon(size: iconSize),
child: RepaintBoundary(
child:
icon.data.mapNotNull(
(image) => SafeRawImage(
image: image,
height: iconSize,
width: iconSize,
fallback: Icon(MdiIcons.web, size: iconSize),
),
) ??
Icon(MdiIcons.web, size: iconSize),
// While the icon future is still resolving, show the skeleton bone. This is
// the only state that needs the (comparatively expensive) Skeletonizer +
// Skeleton.replace machinery.
if (icon.connectionState != ConnectionState.done) {
return Skeletonizer(
enabled: true,
child: Skeleton.replace(
replacement: Bone.icon(size: iconSize),
child: SizedBox.square(dimension: iconSize),
),
),
);
}
// Resolved case (hit on virtually every rebuild once the favicon is known):
// render the image directly without wrapping it in Skeletonizer, which the
// rebuild profiler flagged as the most-rebuilt widget in the tab bar.
return RepaintBoundary(
child:
icon.data.mapNotNull(
(image) => SafeRawImage(
image: image,
height: iconSize,
width: iconSize,
fallback: Icon(MdiIcons.web, size: iconSize),
),
) ??
Icon(MdiIcons.web, size: iconSize),
);
}
}
@@ -36,6 +36,7 @@ import 'package:weblibre/features/geckoview/domain/providers/desktop_mode.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_session.dart';
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/utils/close_tab_helper.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/menu_item_buttons.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/navigation_buttons.dart';
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_view/dialogs/tab_parent_picker.dart';
@@ -764,36 +765,8 @@ class TabMenu extends HookConsumerWidget {
),
if (enableCloseTab)
MenuItemButton(
onPressed: () async {
// Confirm before closing the last tab in an isolation group
final tabState = ref.read(tabStateProvider(selectedTabId));
if (tabState != null && tabState.tabMode is IsolatedTabMode) {
final allStates = ref.read(tabStatesProvider);
final groupCount = allStates.values
.where(
(s) =>
s.isolationContextId == tabState.isolationContextId,
)
.length;
if (groupCount <= 1 && context.mounted) {
final confirmed = await ui_helper.confirmIsolatedTabClose(
context,
);
if (!confirmed) return;
}
}
await ref
.read(tabRepositoryProvider.notifier)
.closeTab(selectedTabId);
if (context.mounted) {
ui_helper.showTabUndoClose(
context,
ref.read(tabRepositoryProvider.notifier).undoClose,
);
}
},
onPressed: () =>
closeTabWithConfirmationAndUndo(context, ref, selectedTabId),
leadingIcon: const Icon(MdiIcons.tabMinus),
child: const Text('Close Tab'),
),
@@ -67,6 +67,7 @@ class RecentTabsSection extends ConsumerWidget {
iconSize: UrlListTile.iconSize,
),
containerColor: containerData?.color,
containerIcon: containerData?.metadata.iconData,
useCustomColor:
containerData?.metadata.useCustomColor ?? false,
onTap: () => onTabSelected(tabState.id),