From 9fdb791e93d6ec182680207fd055fa0a7c81cde5 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 3 May 2016 11:01:50 -0700 Subject: [PATCH 1/3] Geckolib: Implement font-weight. --- components/style/properties/longhand/font.mako.rs | 1 + ports/geckolib/properties.mako.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 59523c5a2a0..f83a536166e 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -173,6 +173,7 @@ ${helpers.single_keyword("font-variant", "normal small-caps")} pub mod computed_value { use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Hash, Deserialize, Serialize, HeapSizeOf, Debug)] + #[repr(u16)] pub enum T { % for weight in range(100, 901, 100): Weight${weight} = ${weight}, diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 47d4b5c7d72..ff7ddd9a40c 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -424,7 +424,7 @@ fn static_assert() { } -<%self:impl_trait style_struct_name="Font" skip_longhands="font-size" skip_additionals="*"> +<%self:impl_trait style_struct_name="Font" skip_longhands="font-size font-weight" skip_additionals="*"> // FIXME(bholley): Gecko has two different sizes, one of which (mSize) is the // actual computed size, and the other of which (mFont.size) is the 'display @@ -441,6 +441,18 @@ fn static_assert() { Au(self.gecko.mSize) } + fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) { + self.gecko.mFont.weight = v as u16; + } + <%call expr="impl_simple_copy('font_weight', 'mFont.weight')"> + + fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T { + debug_assert!(self.gecko.mFont.weight >= 100); + debug_assert!(self.gecko.mFont.weight <= 900); + debug_assert!(self.gecko.mFont.weight % 10 == 0); + unsafe { transmute(self.gecko.mFont.weight) } + } + // This is used for PartialEq, which we don't implement for gecko style structs. fn compute_font_hash(&mut self) {} From aa0e3e25e2fc6f998a2717c6fef9e785ca6fcaa4 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 3 May 2016 11:48:44 -0700 Subject: [PATCH 2/3] Add a runtime-wide initialization hook for Geckolib. --- ports/geckolib/bindings.rs | 1 + ports/geckolib/glue.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ports/geckolib/bindings.rs b/ports/geckolib/bindings.rs index 16724678a80..56785694d77 100644 --- a/ports/geckolib/bindings.rs +++ b/ports/geckolib/bindings.rs @@ -104,6 +104,7 @@ extern "C" { -> *const u16; pub fn Gecko_Namespace(element: *mut RawGeckoElement, length: *mut u32) -> *const u16; + pub fn Servo_Initialize(); pub fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, set: *mut RawServoStyleSet); pub fn Gecko_Construct_nsStyleFont(ptr: *mut nsStyleFont); diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 27edf4ed357..eb456937f6f 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -61,6 +61,10 @@ pub fn pseudo_element_from_atom(pseudo: *mut nsIAtom, * depend on but good enough for our purposes. */ +#[no_mangle] +pub extern "C" fn Servo_Initialize() -> () { +} + #[no_mangle] pub extern "C" fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, raw_data: *mut RawServoStyleSet) -> () { let document = unsafe { GeckoDocument::from_raw(doc) }; @@ -71,8 +75,12 @@ pub extern "C" fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, raw_data: *m let data = unsafe { &mut *(raw_data as *mut PerDocumentStyleData) }; // Force the creation of our lazily-constructed initial computed values on - // the main thread, since it's not safe to call elsewhere. This should move - // into a runtime-wide init hook at some point. + // the main thread, since it's not safe to call elsewhere. + // + // FIXME(bholley): this should move into Servo_Initialize as soon as we get + // rid of the HackilyFindSomeDeviceContext stuff that happens during + // initial_values computation, since that stuff needs to be called further + // along in startup than the sensible place to call Servo_Initialize. GeckoComputedValues::initial_values(); let _needs_dirtying = Arc::get_mut(&mut data.stylist).unwrap() From d4aa0288d61eee0f76d9442f2a1c5cdabecece89 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 3 May 2016 12:12:17 -0700 Subject: [PATCH 3/3] Enable standard logging for geckolib. --- ports/geckolib/Cargo.lock | 65 +++++++++++++++++++++++++++++++++++++++ ports/geckolib/Cargo.toml | 1 + ports/geckolib/glue.rs | 5 +++ ports/geckolib/lib.rs | 1 + 4 files changed, 72 insertions(+) diff --git a/ports/geckolib/Cargo.lock b/ports/geckolib/Cargo.lock index 680e0dd1f47..1289598dd57 100644 --- a/ports/geckolib/Cargo.lock +++ b/ports/geckolib/Cargo.lock @@ -4,6 +4,7 @@ version = "0.0.1" dependencies = [ "app_units 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -20,6 +21,14 @@ dependencies = [ "util 0.0.1", ] +[[package]] +name = "aho-corasick" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "app_units" version = "0.2.3" @@ -180,6 +189,15 @@ name = "encoding_index_tests" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "env_logger" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "euclid" version = "0.6.6" @@ -276,6 +294,14 @@ name = "matches" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "memchr" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num" version = "0.1.32" @@ -411,6 +437,23 @@ dependencies = [ "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "regex" +version = "0.1.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rustc-serialize" version = "0.3.19" @@ -523,6 +566,23 @@ name = "tenacious" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "thread-id" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "thread_local" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "time" version = "0.1.34" @@ -567,6 +627,11 @@ dependencies = [ "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "utf8-ranges" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "util" version = "0.0.1" diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml index b672f8cc298..2778792afcd 100644 --- a/ports/geckolib/Cargo.toml +++ b/ports/geckolib/Cargo.toml @@ -27,3 +27,4 @@ log = {version = "0.3.5", features = ["release_max_level_info"]} plugins = {path = "../../components/plugins"} util = {path = "../../components/util"} style = {path = "../../components/style", features = ["gecko"]} +env_logger = "0.3" diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index eb456937f6f..591b560e9b9 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -9,6 +9,7 @@ use bindings::{RawGeckoDocument, RawGeckoNode}; use bindings::{RawServoStyleSet, RawServoStyleSheet, ServoComputedValues, ServoNodeData}; use bindings::{nsIAtom}; use data::PerDocumentStyleData; +use env_logger; use euclid::Size2D; use gecko_style_structs::SheetParsingMode; use properties::GeckoComputedValues; @@ -63,6 +64,10 @@ pub fn pseudo_element_from_atom(pseudo: *mut nsIAtom, #[no_mangle] pub extern "C" fn Servo_Initialize() -> () { + // Enable standard Rust logging. + // + // See https://doc.rust-lang.org/log/env_logger/index.html for instructions. + env_logger::init().unwrap(); } #[no_mangle] diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index 63163583774..7d31b0c3fb3 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -15,6 +15,7 @@ extern crate app_units; #[macro_use] extern crate cssparser; +extern crate env_logger; extern crate euclid; extern crate heapsize; #[macro_use]