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