Skip to content

Commit

Permalink
Make webivew generic
Browse files Browse the repository at this point in the history
  • Loading branch information
wusyong committed Oct 15, 2024
1 parent 5b17b5d commit 62beed9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/verso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use arboard::Clipboard;
use base::id::WebViewId;
use base::id::{PipelineNamespace, PipelineNamespaceId, WebViewId};
use bluetooth::BluetoothThreadFactory;
use bluetooth_traits::BluetoothRequest;
use canvas::canvas_paint_thread::CanvasPaintThread;
Expand Down Expand Up @@ -82,6 +82,8 @@ impl Verso {
// Initialize configurations and Verso window
let protocols = config.create_protocols();
config.init();
// Reserving a namespace to create TopLevelBrowsingContextId.
PipelineNamespace::install(PipelineNamespaceId(0));
let (window, rendering_context) = Window::new(evl);
let event_loop_waker = Box::new(Waker(proxy));
let opts = opts::get();
Expand Down
23 changes: 1 addition & 22 deletions src/webview.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use arboard::Clipboard;
use base::id::{BrowsingContextId, PipelineNamespace, PipelineNamespaceId, WebViewId};
use base::id::{BrowsingContextId, WebViewId};
use compositing_traits::ConstellationMsg;
use crossbeam_channel::Sender;
use embedder_traits::{CompositorEventVariant, EmbedderMsg, PromptDefinition};
Expand Down Expand Up @@ -29,27 +29,6 @@ impl WebView {
Self { webview_id, rect }
}

/// Create a panel view from Winit window. A panel is a special web view that focus on controlling states around window.
/// It could be treated as the control panel or navigation bar of the window depending on usages.
///
/// At the moment, following Web API is supported:
/// - Close window: `window.close()`
/// - Navigate to previous page: `window.prompt('PREV')`
/// - Navigate to next page: `window.prompt('FORWARD')`
/// - Refresh the page: `window.prompt('REFRESH')`
/// - Minimize the window: `window.prompt('MINIMIZE')`
/// - Maximize the window: `window.prompt('MAXIMIZE')`
/// - Navigate to a specific URL: `window.prompt('NAVIGATE_TO:${url}')`
pub fn new_panel(rect: DeviceIntRect) -> Self {
// Reserving a namespace to create TopLevelBrowsingContextId.
PipelineNamespace::install(PipelineNamespaceId(0));
let id = WebViewId::new();
Self {
webview_id: id,
rect,
}
}

/// Set the webview size corresponding to the window size.
pub fn set_size(&mut self, mut rect: DeviceIntRect) {
rect.min.y = rect.max.y.min(100);
Expand Down
17 changes: 15 additions & 2 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ pub struct Window {
pub(crate) window: WinitWindow,
/// GL surface of the window
pub(crate) surface: Surface<WindowSurface>,
/// The main control panel of this window.
/// The main panel of this window. A panel is a special web view that focus on controlling states around window.
/// It could be treated as the control panel or navigation bar of the window depending on usages.
///
/// At the moment, following Web API is supported:
/// - Close window: `window.close()`
/// - Navigate to previous page: `window.prompt('PREV')`
/// - Navigate to next page: `window.prompt('FORWARD')`
/// - Refresh the page: `window.prompt('REFRESH')`
/// - Minimize the window: `window.prompt('MINIMIZE')`
/// - Maximize the window: `window.prompt('MAXIMIZE')`
/// - Navigate to a specific URL: `window.prompt('NAVIGATE_TO:${url}')`
pub(crate) panel: Option<WebView>,
/// The WebView of this window.
pub(crate) webview: Option<WebView>,
Expand Down Expand Up @@ -89,7 +99,10 @@ impl Window {
Self {
window,
surface,
panel: Some(WebView::new_panel(DeviceIntRect::from_size(size))),
panel: Some(WebView::new(
WebViewId::new(),
DeviceIntRect::from_size(size),
)),
webview: None,
mouse_position: Cell::new(PhysicalPosition::default()),
modifiers_state: Cell::new(ModifiersState::default()),
Expand Down

0 comments on commit 62beed9

Please sign in to comment.