Embed details stylesheet

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
This commit is contained in:
stevennovaryo 2025-05-13 21:37:39 +08:00
parent d7ec3635e6
commit 3da5ef2cd4
4 changed files with 7 additions and 15 deletions

View file

@ -5,10 +5,9 @@
use std::cell::{Cell, Ref}; use std::cell::{Cell, Ref};
use dom_struct::dom_struct; use dom_struct::dom_struct;
use embedder_traits::resources::Resource;
use html5ever::{LocalName, Prefix, local_name}; use html5ever::{LocalName, Prefix, local_name};
use js::rust::HandleObject; use js::rust::HandleObject;
use script_layout_interface::parse_resource_stylesheet; use script_layout_interface::parse_details_stylesheet;
use style::attr::AttrValue; use style::attr::AttrValue;
use super::element::ElementCreator; use super::element::ElementCreator;
@ -138,12 +137,11 @@ impl HTMLDetailsElement {
.AppendChild(link_element.upcast::<Node>(), can_gc) .AppendChild(link_element.upcast::<Node>(), can_gc)
.unwrap(); .unwrap();
let details_stylesheet = parse_resource_stylesheet( let details_stylesheet = parse_details_stylesheet(
link_element link_element
.upcast::<Node>() .upcast::<Node>()
.owner_doc() .owner_doc()
.style_shared_lock(), .style_shared_lock(),
Resource::DetailsCSS,
); );
link_element.set_stylesheet(details_stylesheet.unwrap()); link_element.set_stylesheet(details_stylesheet.unwrap());

View file

@ -66,7 +66,6 @@ pub fn sandbox_access_files_dirs() -> Vec<PathBuf> {
.unwrap_or_default() .unwrap_or_default()
} }
#[derive(Clone)]
pub enum Resource { pub enum Resource {
/// A list of GATT services that are blocked from being used by web bluetooth. /// A list of GATT services that are blocked from being used by web bluetooth.
/// The format of the file is a list of UUIDs, one per line, with an optional second word to specify the /// The format of the file is a list of UUIDs, one per line, with an optional second word to specify the
@ -110,9 +109,6 @@ pub enum Resource {
DirectoryListingHTML, DirectoryListingHTML,
/// A HTML page that is used for the about:memory url. /// A HTML page that is used for the about:memory url.
AboutMemoryHTML, AboutMemoryHTML,
/// A CSS file to style the elements inside <details> element UA Shadow Tree.
/// It can be empty but then <details> element simply wouldn't work.
DetailsCSS,
} }
impl Resource { impl Resource {
@ -127,7 +123,6 @@ impl Resource {
Resource::CrashHTML => "crash.html", Resource::CrashHTML => "crash.html",
Resource::DirectoryListingHTML => "directory-listing.html", Resource::DirectoryListingHTML => "directory-listing.html",
Resource::AboutMemoryHTML => "about-memory.html", Resource::AboutMemoryHTML => "about-memory.html",
Resource::DetailsCSS => "details.css",
} }
} }
} }
@ -172,7 +167,6 @@ fn resources_for_tests() -> Box<dyn ResourceReaderMethods + Sync + Send> {
Resource::AboutMemoryHTML => { Resource::AboutMemoryHTML => {
&include_bytes!("../../../resources/about-memory.html")[..] &include_bytes!("../../../resources/about-memory.html")[..]
}, },
Resource::DetailsCSS => &include_bytes!("../../../resources/details.css")[..],
} }
.to_owned() .to_owned()
} }

View file

@ -20,7 +20,6 @@ use base::Epoch;
use base::id::{BrowsingContextId, PipelineId, WebViewId}; use base::id::{BrowsingContextId, PipelineId, WebViewId};
use compositing_traits::CrossProcessCompositorApi; use compositing_traits::CrossProcessCompositorApi;
use constellation_traits::{LoadData, ScrollState}; use constellation_traits::{LoadData, ScrollState};
use embedder_traits::resources::{self, Resource};
use embedder_traits::{Theme, UntrustedNodeAddress, ViewportDetails}; use embedder_traits::{Theme, UntrustedNodeAddress, ViewportDetails};
use euclid::default::{Point2D, Rect}; use euclid::default::{Point2D, Rect};
use fnv::FnvHashMap; use fnv::FnvHashMap;
@ -54,6 +53,9 @@ use url::Url;
use webrender_api::ImageKey; use webrender_api::ImageKey;
use webrender_api::units::DeviceIntSize; use webrender_api::units::DeviceIntSize;
/// A CSS file to style <details> element.
static DETAILS_CSS: &[u8] = include_bytes!("../../layout/stylesheets/details.css");
pub trait GenericLayoutDataTrait: Any + MallocSizeOfTrait { pub trait GenericLayoutDataTrait: Any + MallocSizeOfTrait {
fn as_any(&self) -> &dyn Any; fn as_any(&self) -> &dyn Any;
} }
@ -671,10 +673,8 @@ pub fn parse_ua_stylesheet(
.map(DocumentStyleSheet) .map(DocumentStyleSheet)
} }
pub fn parse_resource_stylesheet( pub fn parse_details_stylesheet(
shared_lock: &SharedRwLock, shared_lock: &SharedRwLock,
resources: Resource,
) -> Result<ServoArc<Stylesheet>, &'static str> { ) -> Result<ServoArc<Stylesheet>, &'static str> {
let content = &resources::read_bytes(resources.clone()); parse_stylesheet_as_origin(shared_lock, "details.css", DETAILS_CSS, Origin::Author)
parse_stylesheet_as_origin(shared_lock, resources.filename(), content, Origin::Author)
} }