libservo: Create a WebViewBuilder class to construct WebViews (#36483)

This exposes a new method of creating `WebView`s using the Rust builder
pattern. This will be more important as we add more kinds of
configuration options for `WebView` such as size and HiDPI scaling.

Testing: The API currently doesn't have tests, but functionality is
ensured by the fact that servoshell is the test harness.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-04-12 20:59:16 +02:00 committed by GitHub
parent 2454e00a68
commit 084fe007a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 100 additions and 51 deletions

View file

@ -19,7 +19,7 @@ use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize};
use servo::{
AllowOrDenyRequest, AuthenticationRequest, FilterPattern, FormControl, GamepadHapticEffectType,
LoadStatus, PermissionRequest, Servo, ServoDelegate, ServoError, SimpleDialog, TouchEventType,
WebView, WebViewDelegate,
WebView, WebViewBuilder, WebViewDelegate,
};
use url::Url;
@ -107,8 +107,10 @@ impl RunningAppState {
}
pub(crate) fn new_toplevel_webview(self: &Rc<Self>, url: Url) {
let webview = self.servo().new_webview(url);
webview.set_delegate(self.clone());
let webview = WebViewBuilder::new(self.servo())
.url(url)
.delegate(self.clone())
.build();
webview.focus();
webview.raise_to_top(true);
@ -459,8 +461,9 @@ impl WebViewDelegate for RunningAppState {
&self,
parent_webview: servo::WebView,
) -> Option<servo::WebView> {
let webview = self.servo.new_auxiliary_webview();
webview.set_delegate(parent_webview.delegate());
let webview = WebViewBuilder::new_auxiliary(&self.servo)
.delegate(parent_webview.delegate())
.build();
webview.focus();
webview.raise_to_top(true);