about summary refs log tree commit diff
path: root/sys/src/windows.rs
blob: c2094f336b8714a884dc18b9a78f3468db20cfbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/// Use the <code>browser.windows</code> API to interact with browser windows. You can use this API to create, modify, and rearrange windows in the browser.
use crate::tabs;

/// The type of browser window this is. Under some circumstances a Window may not be assigned type property, for example when querying closed windows from the $(ref:sessions) API.
pub enum WindowType {
    Normal,
    Popup,
    Panel,
    App,
    Devtools,
}

/// The state of this browser window. Under some circumstances a Window may not be assigned state property, for example when querying closed windows from the $(ref:sessions) API.
pub enum WindowState {
    Normal,
    Minimized,
    Maximized,
    Fullscreen,
    Docked,
}

pub struct Window {
    /// The ID of the window. Window IDs are unique within a browser session. Under some circumstances a Window may not be assigned an ID, for example when querying windows using the $(ref:sessions) API, in which case a session ID may be present
    pub id: Option<i64>, // minimum: 0
    /// Whether the window is currently the focused window.
    pub focused: bool,
    /// The offset of the window from the top edge of the screen in pixels. Under some circumstances a Window may not be assigned top property, for example when querying closed windows from the $(ref:sessions) API.
    pub top: Option<i64>,
    /// The offset of the window from the left edge of the screen in pixels. Under some circumstances a Window may not be assigned left property, for example when querying closed windows from the $(ref:sessions) API.
    pub left: Option<i64>,
    /// The width of the window, including the frame, in pixels. Under some circumstances a Window may not be assigned width property, for example when querying closed windows from the $(ref:sessions) API.
    pub width: Option<i64>,
    /// The height of the window, including the frame, in pixels. Under some circumstances a Window may not be assigned height property, for example when querying closed windows from the $(ref:sessions) API.
    pub height: Option<i64>,
    /// Array of $(ref:tabs.Tab) objects representing the current tabs in the window.
    pub tabs: Option<Vec<tabs::Tab>>,
    /// Whether the window is incognito.
    pub incognito: bool,
    /// The type of browser window this is.
    pub r#type: Option<WindowType>,
    /// The state of this browser window.
    pub state: Option<WindowState>,
    /// Whether the window is set to be always on top.
    pub always_on_top: bool,
    /// The session ID used to uniquely identify a Window obtained from the $(ref:sessions) API.
    pub session_id: Option<String>,
    /// The title of the window. Read-only.
    pub title: Option<String>,
}

/// Specifies what type of browser window to create. The 'panel' and 'detached_panel' types create a popup unless the '--enable-panels' flag is set.
pub enum CreateType {
    Normal,
    Popup,
    Panel,
    DetachedPanel,
}

/// Specifies whether the $(ref:windows.Window) returned should contain a list of the $(ref:tabs.Tab) objects.
pub struct GetInfo {
    /// If true, the $(ref:windows.Window) returned will have a <var>tabs</var> property that contains a list of the $(ref:tabs.Tab) objects. The <code>Tab</code> objects only contain the <code>url</code>, <code>title</code> and <code>favIconUrl</code> properties if the extension's manifest file includes the <code>\"tabs\"</code> permission.
    pub populate: Option<bool>,
    /// <code>windowTypes</code> is deprecated and ignored on Firefox.
    pub window_types: Option<Vec<WindowType>>, // DEPRECATED
}

// ------ Constants ------

/// The windowId value that represents the absence of a browser window.
pub const WINDOW_ID_NONE: i64 = -1;

/// The windowId value that represents the $(topic:current-window)[current window].
pub const WINDOW_ID_CURRENT: i64 = -2;

// ------ Functions ------

/// Gets details about a window.
// #[async(callback)]
pub fn get(
    window_id: i64, // minimum: -2
    get_info: Option<GetInfo>,
    callback: impl Fn(Window),
) {
    todo!()
}

/// Gets the $(topic:current-window)[current window].
// #[async(callback)]
pub fn get_current(get_info: Option<GetInfo>, callback: impl Fn(Window)) {
    todo!()
}

/// Gets the window that was most recently focused &mdash; typically the window 'on top'.
// #[async(callback)]
pub fn get_last_focused(get_info: Option<GetInfo>, callback: impl Fn(Window)) {
    todo!()
}

/// Gets all windows.
// #[async(callback)]
pub fn get_all(get_info: Option<GetInfo>, callback: impl Fn(Vec<Window>)) {
    todo!()
}

pub enum OneOrMany<T> {
    One(T),
    Many(Vec<T>),
}

// TODO(V): { "type": "string", "format": "relativeUrl" }
pub type RelativeURL = String;

pub struct CreateData {
    /// A URL or array of URLs to open as tabs in the window. Fully-qualified URLs must include a scheme (i.e. 'http://www.google.com', not 'www.google.com'). Relative URLs will be relative to the current page within the extension. Defaults to the New Tab Page.
    pub url: Option<OneOrMany<RelativeURL>>,
    /// The id of the tab for which you want to adopt to the new window.
    pub tab_id: Option<i64>, // minimum: 0
    /// The number of pixels to position the new window from the left edge of the screen. If not specified, the new window is offset naturally from the last focused window. This value is ignored for panels.
    pub left: Option<i64>,
    /// The number of pixels to position the new window from the top edge of the screen. If not specified, the new window is offset naturally from the last focused window. This value is ignored for panels.
    pub top: Option<i64>,
    /// The width in pixels of the new window, including the frame. If not specified defaults to a natural width.
    pub width: Option<i64>, // minimum: 0
    /// The height in pixels of the new window, including the frame. If not specified defaults to a natural height.
    pub height: Option<i64>, // minimum: 0
    /// If true, opens an active window. If false, opens an inactive window.
    // pub focused: Option<bool>,  // disabled, as true is the only valid choice (deprecated with the message "Opening inactive windows is not supported.")
    /// Whether the new window should be an incognito window.
    pub incognito: Option<bool>,
    /// Specifies what type of browser window to create. The 'panel' and 'detached_panel' types create a popup unless the '--enable-panels' flag is set.
    pub r#type: Option<CreateType>,
    /// The initial state of the window. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'.
    pub state: Option<WindowState>,
    /// Allow scripts to close the window.
    pub allow_scripts_to_close: Option<bool>,
    /// The CookieStoreId to use for all tabs that were created when the window is opened.
    pub cookie_store_id: Option<String>,
    /// A string to add to the beginning of the window title.
    pub title_preface: Option<String>,
}

/// Creates (opens) a new browser with any optional sizing, position or default URL provided.
// #[async(callback)]
pub fn create(create_data: Option<CreateData>, callback: Option<impl Fn(Option<Window>)>) {
    todo!()
}

pub struct UpdateInfo {
    /// The offset from the left edge of the screen to move the window to in pixels. This value is ignored for panels.
    pub left: Option<i64>,
    /// The offset from the top edge of the screen to move the window to in pixels. This value is ignored for panels.
    pub top: Option<i64>,
    /// The width to resize the window to in pixels. This value is ignored for panels.
    pub width: Option<i64>, // minimum: 0
    /// The height to resize the window to in pixels. This value is ignored for panels.
    pub height: Option<i64>, // minimum: 0
    /// If true, brings the window to the front. If false, brings the next window in the z-order to the front.
    pub focused: Option<bool>,
    /// If true, causes the window to be displayed in a manner that draws the user's attention to the window, without changing the focused window. The effect lasts until the user changes focus to the window. This option has no effect if the window already has focus. Set to false to cancel a previous draw attention request.
    pub draw_attention: Option<bool>,
    /// The new state of the window. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'.
    pub state: Option<WindowState>,
    /// A string to add to the beginning of the window title.
    pub title_preface: Option<String>,
}

/// Updates the properties of a window. Specify only the properties that you want to change; unspecified properties will be left unchanged.
// #[async(callback)]
pub fn update(
    window_id: i64, // minimum: -2
    update_info: UpdateInfo,
    callback: Option<impl Fn(Window)>,
) {
    todo!()
}

/// Removes (closes) a window, and all the tabs inside it.
// #[async(callback)]
pub fn remove(
    window_id: i64, // minimum: -2
    callback: Option<impl Fn()>,
) {
    todo!()
}

// ------ Events ------

// Note: we skip the filters property of all events, since we want all events at all times.

/// Fired when a window is created.
///
/// * `window`: Details of the window that was created.
pub fn on_created(window: Window) {
    todo!()
}

/// Fired when a window is removed (closed).
///
/// * `window_id`: ID of the removed window.
pub fn on_removed(window_id: i64, // minimum: 0
) {
    todo!()
}

/// Fired when the currently focused window changes. Will be $(ref:windows.WINDOW_ID_NONE) if all browser windows have lost focus. Note: On some Linux window managers, WINDOW_ID_NONE will always be sent immediately preceding a switch from one browser window to another.
///
/// * `window_id`: ID of the newly focused window.
pub fn on_focus_changed(window_id: i64, // minimum: -1
) {
    todo!()
}