blob: daef9bb2d752f54ad53bb14b7d7a1551ef39f86d [file] [log] [blame]
Jan Scheffler8ce0cbb2021-04-05 20:34:371// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Danil Somsikov96f4b2f2024-01-19 12:52:085import * as Platform from '../../core/platform/platform.js';
Simon Zünd48a1ec52022-03-31 09:51:086
Danil Somsikov68068772024-10-11 19:42:247import type {TabbedPane} from './TabbedPane.js';
8import type {ToolbarItem, ToolbarMenuButton} from './Toolbar.js';
Jan Scheffler8ce0cbb2021-04-05 20:34:379import {ViewManager} from './ViewManager.js';
Jack Franklin3a802602022-07-13 08:39:4210import {VBox, type Widget} from './Widget.js';
Simon Zünd48a1ec52022-03-31 09:51:0811
Jan Scheffler8ce0cbb2021-04-05 20:34:3712export interface View {
13 viewId(): string;
14
Simon Zünd48a1ec52022-03-31 09:51:0815 title(): Platform.UIString.LocalizedString;
Jan Scheffler8ce0cbb2021-04-05 20:34:3716
17 isCloseable(): boolean;
18
Alex Rudenkoec400262021-10-05 06:03:0819 isPreviewFeature(): boolean;
20
Kim-Anh Tran6a4440e2024-06-04 11:52:1721 iconName(): string|undefined;
22
Jan Scheffler8ce0cbb2021-04-05 20:34:3723 isTransient(): boolean;
24
25 toolbarItems(): Promise<ToolbarItem[]>;
26
27 widget(): Promise<Widget>;
28
29 disposeView(): void|Promise<void>;
30}
31
32export class SimpleView extends VBox implements View {
Simon Zünd48a1ec52022-03-31 09:51:0833 readonly #title: Platform.UIString.LocalizedString;
Danil Somsikov96f4b2f2024-01-19 12:52:0834 readonly #viewId: Lowercase<string>;
Simon Zünd140d8122022-03-30 10:12:5635
Danil Somsikov96f4b2f2024-01-19 12:52:0836 constructor(title: Platform.UIString.LocalizedString, isWebComponent?: boolean, viewId?: Lowercase<string>) {
Jan Scheffler8ce0cbb2021-04-05 20:34:3737 super(isWebComponent);
Simon Zünd48a1ec52022-03-31 09:51:0838 this.#title = title;
Danil Somsikov96f4b2f2024-01-19 12:52:0839 if (viewId) {
40 if (!Platform.StringUtilities.isExtendedKebabCase(viewId)) {
41 throw new Error(`Invalid view ID '${viewId}'`);
42 }
43 }
44 this.#viewId = viewId ?? Platform.StringUtilities.toKebabCase(title);
Jan Scheffler8ce0cbb2021-04-05 20:34:3745 }
46
47 viewId(): string {
Simon Zünd140d8122022-03-30 10:12:5648 return this.#viewId;
Jan Scheffler8ce0cbb2021-04-05 20:34:3749 }
50
Simon Zünd48a1ec52022-03-31 09:51:0851 title(): Platform.UIString.LocalizedString {
52 return this.#title;
Jan Scheffler8ce0cbb2021-04-05 20:34:3753 }
54
55 isCloseable(): boolean {
56 return false;
57 }
58
59 isTransient(): boolean {
60 return false;
61 }
62
63 toolbarItems(): Promise<ToolbarItem[]> {
64 return Promise.resolve([]);
65 }
66
67 widget(): Promise<Widget> {
Simon Zünd48a1ec52022-03-31 09:51:0868 return Promise.resolve(this);
Jan Scheffler8ce0cbb2021-04-05 20:34:3769 }
70
71 revealView(): Promise<void> {
72 return ViewManager.instance().revealView(this);
73 }
74
75 disposeView(): void {
76 }
Alex Rudenkoec400262021-10-05 06:03:0877
78 isPreviewFeature(): boolean {
79 return false;
80 }
Kim-Anh Tran6a4440e2024-06-04 11:52:1781
82 iconName(): string|undefined {
83 return undefined;
84 }
Jan Scheffler8ce0cbb2021-04-05 20:34:3785}
86
87export interface ViewLocation {
88 appendApplicableItems(locationName: string): void;
89 appendView(view: View, insertBefore?: View|null): void;
90 showView(view: View, insertBefore?: View|null, userGesture?: boolean): Promise<void>;
91 removeView(view: View): void;
92 widget(): Widget;
93}
94
95export interface TabbedViewLocation extends ViewLocation {
96 tabbedPane(): TabbedPane;
97 enableMoreTabsButton(): ToolbarMenuButton;
98}
99
100export interface ViewLocationResolver {
101 resolveLocation(location: string): ViewLocation|null;
102}