Skip to content

Commit

Permalink
Make control panel optional (#201)
Browse files Browse the repository at this point in the history
* Support no control panel

* Put things in new

* Fix second window fails to start

* Rename method names and signatures

---------

Co-authored-by: Wu Yu Wei <[email protected]>
  • Loading branch information
Legend-Master and wusyong authored Oct 16, 2024
1 parent 4e7edd0 commit 698eeb3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
5 changes: 3 additions & 2 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,9 +1240,10 @@ impl IOCompositor {
self.on_resize_webview_event(panel.webview_id, rect);
}

let rect = DeviceIntRect::from_size(size);
let content_size = window.get_content_size(rect);
if let Some(w) = &mut window.webview {
let rect = DeviceIntRect::from_size(size);
w.set_size(rect);
w.set_size(content_size);
self.on_resize_webview_event(w.webview_id, w.rect);
}

Expand Down
26 changes: 4 additions & 22 deletions 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::{PipelineNamespace, PipelineNamespaceId, WebViewId};
use base::id::{PipelineNamespace, PipelineNamespaceId};
use bluetooth::BluetoothThreadFactory;
use bluetooth_traits::BluetoothRequest;
use canvas::canvas_paint_thread::CanvasPaintThread;
Expand All @@ -26,9 +26,7 @@ use profile;
use script::{self, JSEngineSetup};
use script_traits::WindowSizeData;
use servo_config::{opts, pref};
use servo_url::ServoUrl;
use style;
use units::DeviceIntRect;
use webgpu;
use webrender::{create_webrender_instance, ShaderPrecacheFlags, WebRenderOptions};
use webrender_api::*;
Expand All @@ -43,7 +41,6 @@ use winit::{
use crate::{
compositor::{IOCompositor, InitialCompositorState, ShutdownState},
config::Config,
webview::WebView,
window::Window,
};

Expand Down Expand Up @@ -84,7 +81,7 @@ impl Verso {
config.init();
// Reserving a namespace to create TopLevelBrowsingContextId.
PipelineNamespace::install(PipelineNamespaceId(0));
let (window, rendering_context) = Window::new(evl);
let (mut window, rendering_context) = Window::new(evl);
let event_loop_waker = Box::new(Waker(proxy));
let opts = opts::get();

Expand Down Expand Up @@ -362,14 +359,7 @@ impl Verso {
opts.debug.convert_mouse_to_touch,
);

// Send the constellation message to start Panel UI
// TODO: Should become a window method
let panel_id = window.panel.as_ref().unwrap().webview_id;
let url = ServoUrl::parse("verso://panel.html").unwrap();
send_to_constellation(
&constellation_sender,
ConstellationMsg::NewWebView(url, panel_id),
);
window.create_panel(&constellation_sender);

let mut windows = HashMap::new();
windows.insert(window.id(), (window, webrender_document));
Expand Down Expand Up @@ -438,15 +428,7 @@ impl Verso {
) {
let mut window =
Window::new_with_compositor(evl, compositor);
let panel_id = WebViewId::new();
let url =
ServoUrl::parse("verso://panel.html").unwrap();
send_to_constellation(
&self.constellation_sender,
ConstellationMsg::NewWebView(url, panel_id),
);
let rect = DeviceIntRect::from_size(window.size());
window.panel = Some(WebView::new(panel_id, rect));
window.create_panel(&self.constellation_sender);
let webrender_document = document.clone();
self.windows
.insert(window.id(), (window, webrender_document));
Expand Down
10 changes: 3 additions & 7 deletions src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ impl WebView {
Self { webview_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);
rect.min.x += 10;
rect.max.y -= 10;
rect.max.x -= 10;
/// Set the webview size.
pub fn set_size(&mut self, rect: DeviceIntRect) {
self.rect = rect;
}
}
Expand Down Expand Up @@ -164,7 +160,7 @@ impl Window {
let size = self.size();
let rect = DeviceIntRect::from_size(size);
let mut webview = WebView::new(demo_id, rect);
webview.set_size(rect);
webview.set_size(self.get_content_size(rect));
self.webview = Some(webview);
send_to_constellation(sender, ConstellationMsg::NewWebView(demo_url, demo_id));
log::debug!("Verso Window {:?} adds webview {}", self.id(), demo_id);
Expand Down
34 changes: 28 additions & 6 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use glutin::{
};
use glutin_winit::DisplayBuilder;
use script_traits::{TouchEventType, WheelDelta, WheelMode};
use servo_url::ServoUrl;
use webrender_api::{
units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePoint, LayoutVector2D},
ScrollLocation,
Expand Down Expand Up @@ -93,16 +94,11 @@ impl Window {
.expect("Failed to create rendering context");
log::trace!("Created rendering context for window {:?}", window);

let size = window.inner_size();
let size = Size2D::new(size.width as i32, size.height as i32);
(
Self {
window,
surface,
panel: Some(WebView::new(
WebViewId::new(),
DeviceIntRect::from_size(size),
)),
panel: None,
webview: None,
mouse_position: Cell::new(PhysicalPosition::default()),
modifiers_state: Cell::new(ModifiersState::default()),
Expand Down Expand Up @@ -133,6 +129,7 @@ impl Window {
.rendering_context
.create_surface(&window)
.unwrap();

let mut window = Self {
window,
surface,
Expand All @@ -145,6 +142,31 @@ impl Window {
window
}

/// Get the content area size for the webview to draw on
pub fn get_content_size(&self, mut size: DeviceIntRect) -> DeviceIntRect {
if self.panel.is_some() {
size.min.y = size.max.y.min(100);
size.min.x += 10;
size.max.y -= 10;
size.max.x -= 10;
}
size
}

/// Send the constellation message to start Panel UI
pub fn create_panel(&mut self, constellation_sender: &Sender<ConstellationMsg>) {
let size = self.window.inner_size();
let size = Size2D::new(size.width as i32, size.height as i32);
let panel_id = WebViewId::new();
self.panel = Some(WebView::new(panel_id, DeviceIntRect::from_size(size)));

let url = ServoUrl::parse("verso://panel.html").unwrap();
send_to_constellation(
constellation_sender,
ConstellationMsg::NewWebView(url, panel_id),
);
}

/// Handle Winit window event and return a boolean to indicate if the compositor should repaint immediately.
pub fn handle_winit_window_event(
&mut self,
Expand Down

0 comments on commit 698eeb3

Please sign in to comment.