blob: c8e69bb3068807fb776ad9b66f06155a80766194 [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
Simon Zünd48a1ec52022-03-31 09:51:085import type * as Platform from '../../core/platform/platform.js';
6
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:4210
11import {VBox, type Widget} from './Widget.js';
Simon Zünd48a1ec52022-03-31 09:51:0812
Jan Scheffler8ce0cbb2021-04-05 20:34:3713export interface View {
14 viewId(): string;
15
Simon Zünd48a1ec52022-03-31 09:51:0816 title(): Platform.UIString.LocalizedString;
Jan Scheffler8ce0cbb2021-04-05 20:34:3717
18 isCloseable(): boolean;
19
Alex Rudenkoec400262021-10-05 06:03:0820 isPreviewFeature(): boolean;
21
Jan Scheffler8ce0cbb2021-04-05 20:34:3722 isTransient(): boolean;
23
24 toolbarItems(): Promise<ToolbarItem[]>;
25
26 widget(): Promise<Widget>;
27
28 disposeView(): void|Promise<void>;
29}
30
31export class SimpleView extends VBox implements View {
Simon Zünd48a1ec52022-03-31 09:51:0832 readonly #title: Platform.UIString.LocalizedString;
Simon Zünd140d8122022-03-30 10:12:5633 readonly #viewId: string;
34
Simon Zünd48a1ec52022-03-31 09:51:0835 constructor(title: Platform.UIString.LocalizedString, isWebComponent?: boolean, viewId?: string) {
Jan Scheffler8ce0cbb2021-04-05 20:34:3736 super(isWebComponent);
Simon Zünd48a1ec52022-03-31 09:51:0837 this.#title = title;
Simon Zünd140d8122022-03-30 10:12:5638 this.#viewId = viewId ?? title;
Jan Scheffler8ce0cbb2021-04-05 20:34:3739 }
40
41 viewId(): string {
Simon Zünd140d8122022-03-30 10:12:5642 return this.#viewId;
Jan Scheffler8ce0cbb2021-04-05 20:34:3743 }
44
Simon Zünd48a1ec52022-03-31 09:51:0845 title(): Platform.UIString.LocalizedString {
46 return this.#title;
Jan Scheffler8ce0cbb2021-04-05 20:34:3747 }
48
49 isCloseable(): boolean {
50 return false;
51 }
52
53 isTransient(): boolean {
54 return false;
55 }
56
57 toolbarItems(): Promise<ToolbarItem[]> {
58 return Promise.resolve([]);
59 }
60
61 widget(): Promise<Widget> {
Simon Zünd48a1ec52022-03-31 09:51:0862 return Promise.resolve(this);
Jan Scheffler8ce0cbb2021-04-05 20:34:3763 }
64
65 revealView(): Promise<void> {
66 return ViewManager.instance().revealView(this);
67 }
68
69 disposeView(): void {
70 }
Alex Rudenkoec400262021-10-05 06:03:0871
72 isPreviewFeature(): boolean {
73 return false;
74 }
Jan Scheffler8ce0cbb2021-04-05 20:34:3775}
76
77export interface ViewLocation {
78 appendApplicableItems(locationName: string): void;
79 appendView(view: View, insertBefore?: View|null): void;
80 showView(view: View, insertBefore?: View|null, userGesture?: boolean): Promise<void>;
81 removeView(view: View): void;
82 widget(): Widget;
83}
84
85export interface TabbedViewLocation extends ViewLocation {
86 tabbedPane(): TabbedPane;
87 enableMoreTabsButton(): ToolbarMenuButton;
88}
89
90export interface ViewLocationResolver {
91 resolveLocation(location: string): ViewLocation|null;
92}