diff --git a/ports/geckolib/bindings.rs b/ports/geckolib/bindings.rs index 96a5cb40705..0fb3787e923 100644 --- a/ports/geckolib/bindings.rs +++ b/ports/geckolib/bindings.rs @@ -49,6 +49,8 @@ pub enum Struct_RawGeckoDocument { } pub type RawGeckoDocument = Struct_RawGeckoDocument; pub enum Struct_ServoNodeData { } pub type ServoNodeData = Struct_ServoNodeData; +pub enum Struct_ServoArcStyleSheet { } +pub type ServoArcStyleSheet = Struct_ServoArcStyleSheet; extern "C" { pub fn Gecko_ElementState(element: *mut RawGeckoElement) -> uint8_t; pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement, ns: *const uint8_t, @@ -78,4 +80,8 @@ extern "C" { data: *mut ServoNodeData) -> (); pub fn Servo_RestyleDocument(aDoc: *mut RawGeckoDocument) -> (); pub fn Servo_DropNodeData(data: *mut ServoNodeData) -> (); + pub fn Servo_StylesheetFromUTF8Bytes(bytes: *const uint8_t, + length: uint32_t) + -> *mut ServoArcStyleSheet; + pub fn Servo_DropStylesheet(sheet: *mut ServoArcStyleSheet) -> (); } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index bb1d6bcae3e..0c5b76bec61 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -6,12 +6,15 @@ use app_units::Au; use bindings::RawGeckoDocument; -use bindings::ServoNodeData; +use bindings::{ServoNodeData, ServoArcStyleSheet, uint8_t, uint32_t}; use euclid::Size2D; use euclid::size::TypedSize2D; use num_cpus; use std::cmp; use std::collections::HashMap; +use std::mem::transmute; +use std::slice; +use std::str::from_utf8_unchecked; use std::sync::mpsc::{channel, Sender}; use std::sync::{Arc, Mutex, RwLock}; use style::animation::Animation; @@ -21,8 +24,9 @@ use style::error_reporting::StdoutErrorReporter; use style::media_queries::{Device, MediaType}; use style::parallel::{self, WorkQueueData}; use style::selector_matching::Stylist; -use style::stylesheets::Stylesheet; +use style::stylesheets::{Origin, Stylesheet}; use style::traversal::RecalcStyleOnly; +use url::Url; use util::geometry::ViewportPx; use util::resource_files::set_resources_path; use util::thread_state; @@ -90,3 +94,24 @@ pub extern "C" fn Servo_DropNodeData(data: *mut ServoNodeData) -> () { let _ = Box::::from_raw(data as *mut NonOpaqueStyleData); } } + +#[no_mangle] +pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const uint8_t, + length: uint32_t) -> *mut ServoArcStyleSheet { + + let input = unsafe { from_utf8_unchecked(slice::from_raw_parts(bytes, length as usize)) }; + + // FIXME(heycam): Pass in the real base URL and sheet origin to use. + let url = Url::parse("about:none").unwrap(); + let sheet = Arc::new(Stylesheet::from_str(input, url, Origin::Author, Box::new(StdoutErrorReporter))); + unsafe { + transmute(sheet) + } +} + +#[no_mangle] +pub extern "C" fn Servo_DropStylesheet(sheet: *mut ServoArcStyleSheet) -> () { + unsafe { + let _ : Arc = transmute(sheet); + } +}