blob: ac168e7747bcc6bc9b9df0f1bdb69bca411bbec4 [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
Jack Franklin3a802602022-07-13 08:39:427import {type TabbedPane} from './TabbedPane.js';
8import {type ToolbarItem, type 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
Jan Scheffler8ce0cbb2021-04-05 20:34:3721 isTransient(): boolean;
22
23 toolbarItems(): Promise<ToolbarItem[]>;
24
25 widget(): Promise<Widget>;
26
27 disposeView(): void|Promise<void>;
28}
29
30export class SimpleView extends VBox implements View {
Simon Zünd48a1ec52022-03-31 09:51:0831 readonly #title: Platform.UIString.LocalizedString;
Danil Somsikov96f4b2f2024-01-19 12:52:0832 readonly #viewId: Lowercase<string>;
Simon Zünd140d8122022-03-30 10:12:5633
Danil Somsikov96f4b2f2024-01-19 12:52:0834 constructor(title: Platform.UIString.LocalizedString, isWebComponent?: boolean, viewId?: Lowercase<string>) {
Jan Scheffler8ce0cbb2021-04-05 20:34:3735 super(isWebComponent);
Simon Zünd48a1ec52022-03-31 09:51:0836 this.#title = title;
Danil Somsikov96f4b2f2024-01-19 12:52:0837 if (viewId) {
38 if (!Platform.StringUtilities.isExtendedKebabCase(viewId)) {
39 throw new Error(`Invalid view ID '${viewId}'`);
40 }
41 }
42 this.#viewId = viewId ?? Platform.StringUtilities.toKebabCase(title);
Jan Scheffler8ce0cbb2021-04-05 20:34:3743 }
44
45 viewId(): string {
Simon Zünd140d8122022-03-30 10:12:5646 return this.#viewId;
Jan Scheffler8ce0cbb2021-04-05 20:34:3747 }
48
Simon Zünd48a1ec52022-03-31 09:51:0849 title(): Platform.UIString.LocalizedString {
50 return this.#title;
Jan Scheffler8ce0cbb2021-04-05 20:34:3751 }
52
53 isCloseable(): boolean {
54 return false;
55 }
56
57 isTransient(): boolean {
58 return false;
59 }
60
61 toolbarItems(): Promise<ToolbarItem[]> {
62 return Promise.resolve([]);
63 }
64
65 widget(): Promise<Widget> {
Simon Zünd48a1ec52022-03-31 09:51:0866 return Promise.resolve(this);
Jan Scheffler8ce0cbb2021-04-05 20:34:3767 }
68
69 revealView(): Promise<void> {
70 return ViewManager.instance().revealView(this);
71 }
72
73 disposeView(): void {
74 }
Alex Rudenkoec400262021-10-05 06:03:0875
76 isPreviewFeature(): boolean {
77 return false;
78 }
Jan Scheffler8ce0cbb2021-04-05 20:34:3779}
80
81export interface ViewLocation {
82 appendApplicableItems(locationName: string): void;
83 appendView(view: View, insertBefore?: View|null): void;
84 showView(view: View, insertBefore?: View|null, userGesture?: boolean): Promise<void>;
85 removeView(view: View): void;
86 widget(): Widget;
87}
88
89export interface TabbedViewLocation extends ViewLocation {
90 tabbedPane(): TabbedPane;
91 enableMoreTabsButton(): ToolbarMenuButton;
92}
93
94export interface ViewLocationResolver {
95 resolveLocation(location: string): ViewLocation|null;
96}