Jan Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 1 | // 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 Somsikov | 96f4b2f | 2024-01-19 12:52:08 | [diff] [blame^] | 5 | import * as Platform from '../../core/platform/platform.js'; |
Simon Zünd | 48a1ec5 | 2022-03-31 09:51:08 | [diff] [blame] | 6 | |
Jack Franklin | 3a80260 | 2022-07-13 08:39:42 | [diff] [blame] | 7 | import {type TabbedPane} from './TabbedPane.js'; |
| 8 | import {type ToolbarItem, type ToolbarMenuButton} from './Toolbar.js'; |
Jan Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 9 | import {ViewManager} from './ViewManager.js'; |
Jack Franklin | 3a80260 | 2022-07-13 08:39:42 | [diff] [blame] | 10 | import {VBox, type Widget} from './Widget.js'; |
Simon Zünd | 48a1ec5 | 2022-03-31 09:51:08 | [diff] [blame] | 11 | |
Jan Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 12 | export interface View { |
| 13 | viewId(): string; |
| 14 | |
Simon Zünd | 48a1ec5 | 2022-03-31 09:51:08 | [diff] [blame] | 15 | title(): Platform.UIString.LocalizedString; |
Jan Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 16 | |
| 17 | isCloseable(): boolean; |
| 18 | |
Alex Rudenko | ec40026 | 2021-10-05 06:03:08 | [diff] [blame] | 19 | isPreviewFeature(): boolean; |
| 20 | |
Jan Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 21 | isTransient(): boolean; |
| 22 | |
| 23 | toolbarItems(): Promise<ToolbarItem[]>; |
| 24 | |
| 25 | widget(): Promise<Widget>; |
| 26 | |
| 27 | disposeView(): void|Promise<void>; |
| 28 | } |
| 29 | |
| 30 | export class SimpleView extends VBox implements View { |
Simon Zünd | 48a1ec5 | 2022-03-31 09:51:08 | [diff] [blame] | 31 | readonly #title: Platform.UIString.LocalizedString; |
Danil Somsikov | 96f4b2f | 2024-01-19 12:52:08 | [diff] [blame^] | 32 | readonly #viewId: Lowercase<string>; |
Simon Zünd | 140d812 | 2022-03-30 10:12:56 | [diff] [blame] | 33 | |
Danil Somsikov | 96f4b2f | 2024-01-19 12:52:08 | [diff] [blame^] | 34 | constructor(title: Platform.UIString.LocalizedString, isWebComponent?: boolean, viewId?: Lowercase<string>) { |
Jan Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 35 | super(isWebComponent); |
Simon Zünd | 48a1ec5 | 2022-03-31 09:51:08 | [diff] [blame] | 36 | this.#title = title; |
Danil Somsikov | 96f4b2f | 2024-01-19 12:52:08 | [diff] [blame^] | 37 | 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 Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | viewId(): string { |
Simon Zünd | 140d812 | 2022-03-30 10:12:56 | [diff] [blame] | 46 | return this.#viewId; |
Jan Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 47 | } |
| 48 | |
Simon Zünd | 48a1ec5 | 2022-03-31 09:51:08 | [diff] [blame] | 49 | title(): Platform.UIString.LocalizedString { |
| 50 | return this.#title; |
Jan Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 51 | } |
| 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ünd | 48a1ec5 | 2022-03-31 09:51:08 | [diff] [blame] | 66 | return Promise.resolve(this); |
Jan Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | revealView(): Promise<void> { |
| 70 | return ViewManager.instance().revealView(this); |
| 71 | } |
| 72 | |
| 73 | disposeView(): void { |
| 74 | } |
Alex Rudenko | ec40026 | 2021-10-05 06:03:08 | [diff] [blame] | 75 | |
| 76 | isPreviewFeature(): boolean { |
| 77 | return false; |
| 78 | } |
Jan Scheffler | 8ce0cbb | 2021-04-05 20:34:37 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | export 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 | |
| 89 | export interface TabbedViewLocation extends ViewLocation { |
| 90 | tabbedPane(): TabbedPane; |
| 91 | enableMoreTabsButton(): ToolbarMenuButton; |
| 92 | } |
| 93 | |
| 94 | export interface ViewLocationResolver { |
| 95 | resolveLocation(location: string): ViewLocation|null; |
| 96 | } |