diff --git a/Cargo.lock b/Cargo.lock index 30aee29523f..5b3b39c9981 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -921,11 +921,9 @@ dependencies = [ name = "geckoservo" version = "0.0.1" dependencies = [ - "app_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/layout/block.rs b/components/layout/block.rs index e2818e1a7fd..4bfef78cb3d 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -713,7 +713,7 @@ impl BlockFlow { // infrastructure to make it scrollable. let viewport_size = LogicalSize::from_physical(self.fragment.style.writing_mode, - shared_context.viewport_size); + shared_context.viewport_size()); let block_size = max(viewport_size.block, self.fragment.border_box.size.block + block_start_margin_value + block_end_margin_value); @@ -990,7 +990,7 @@ impl BlockFlow { if is_root { let viewport_size = LogicalSize::from_physical(self.fragment.style.writing_mode, - layout_context.shared_context().viewport_size); + layout_context.shared_context().viewport_size()); block_size = max(viewport_size.block, block_size) } @@ -1154,7 +1154,7 @@ impl BlockFlow { pub fn explicit_block_containing_size(&self, shared_context: &SharedStyleContext) -> Option { if self.is_root() || self.is_fixed() { let viewport_size = LogicalSize::from_physical(self.fragment.style.writing_mode, - shared_context.viewport_size); + shared_context.viewport_size()); Some(viewport_size.block) } else if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) && self.base.block_container_explicit_block_size.is_none() { @@ -1220,7 +1220,7 @@ impl BlockFlow { fn calculate_absolute_block_size_and_margins(&mut self, shared_context: &SharedStyleContext) { let opaque_self = OpaqueFlow::from_flow(self); let containing_block_block_size = - self.containing_block_size(&shared_context.viewport_size, opaque_self).block; + self.containing_block_size(&shared_context.viewport_size(), opaque_self).block; // This is the stored content block-size value from assign-block-size let content_block_size = self.fragment.border_box.size.block; @@ -1354,7 +1354,7 @@ impl BlockFlow { if self.is_root() { explicit_content_size = max(parent_container_size, explicit_content_size); } // Calculate containing block inline size. let containing_block_size = if flags.contains(IS_ABSOLUTELY_POSITIONED) { - self.containing_block_size(&shared_context.viewport_size, opaque_self).inline + self.containing_block_size(&shared_context.viewport_size(), opaque_self).inline } else { content_inline_size }; @@ -1718,7 +1718,7 @@ impl BlockFlow { debug!("Setting root position"); self.base.position.start = LogicalPoint::zero(self.base.writing_mode); self.base.block_container_inline_size = LogicalSize::from_physical( - self.base.writing_mode, shared_context.viewport_size).inline; + self.base.writing_mode, shared_context.viewport_size()).inline; self.base.block_container_writing_mode = self.base.writing_mode; } } @@ -2820,7 +2820,7 @@ impl ISizeAndMarginsComputer for AbsoluteNonReplaced { shared_context: &SharedStyleContext) -> Au { let opaque_block = OpaqueFlow::from_flow(block); - block.containing_block_size(&shared_context.viewport_size, opaque_block).inline + block.containing_block_size(&shared_context.viewport_size(), opaque_block).inline } fn set_inline_position_of_flow_if_necessary(&self, @@ -2932,7 +2932,7 @@ impl ISizeAndMarginsComputer for AbsoluteReplaced { -> MaybeAuto { let opaque_block = OpaqueFlow::from_flow(block); let containing_block_inline_size = - block.containing_block_size(&shared_context.viewport_size, opaque_block).inline; + block.containing_block_size(&shared_context.viewport_size(), opaque_block).inline; let container_block_size = block.explicit_block_containing_size(shared_context); let fragment = block.fragment(); fragment.assign_replaced_inline_size_if_necessary(containing_block_inline_size, container_block_size); @@ -2947,7 +2947,7 @@ impl ISizeAndMarginsComputer for AbsoluteReplaced { shared_context: &SharedStyleContext) -> Au { let opaque_block = OpaqueFlow::from_flow(block); - block.containing_block_size(&shared_context.viewport_size, opaque_block).inline + block.containing_block_size(&shared_context.viewport_size(), opaque_block).inline } fn set_inline_position_of_flow_if_necessary(&self, diff --git a/components/layout/multicol.rs b/components/layout/multicol.rs index 6d228e75f5e..9e341d96d01 100644 --- a/components/layout/multicol.rs +++ b/components/layout/multicol.rs @@ -140,7 +140,7 @@ impl Flow for MulticolFlow { // FIXME: (until column balancing) substract margins/borders/padding LogicalSize::from_physical( self.block_flow.base.writing_mode, - ctx.shared_context().viewport_size, + ctx.shared_context().viewport_size(), ).block } } diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 7e8c4e1e3bf..529100c06d8 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -503,7 +503,6 @@ impl LayoutThread { LayoutContext { style_context: SharedStyleContext { - viewport_size: self.viewport_size.clone(), stylist: rw_data.stylist.clone(), running_animations: self.running_animations.clone(), expired_animations: self.expired_animations.clone(), diff --git a/components/style/animation.rs b/components/style/animation.rs index bebda0e6339..048c1bfa521 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -426,7 +426,7 @@ fn compute_style_for_animation_step(context: &SharedStyleContext, }; let computed = - properties::apply_declarations(context.viewport_size, + properties::apply_declarations(context.viewport_size(), /* is_root = */ false, iter, previous_style, diff --git a/components/style/context.rs b/components/style/context.rs index 75e71bd844b..fa3e6182c0f 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -63,9 +63,6 @@ pub enum QuirksMode { /// There's exactly one of these during a given restyle traversal, and it's /// shared among the worker threads. pub struct SharedStyleContext { - /// The current viewport size. - pub viewport_size: Size2D, - /// The CSS selector stylist. pub stylist: Arc, @@ -93,6 +90,13 @@ pub struct SharedStyleContext { pub default_computed_values: Arc, } +impl SharedStyleContext { + /// Return a suitable viewport size in order to be used for viewport units. + pub fn viewport_size(&self) -> Size2D { + self.stylist.device.au_viewport_size() + } +} + /// Information about the current element being processed. We group this together /// into a single struct within ThreadLocalStyleContext so that we can instantiate /// and destroy it easily at the beginning and end of element processing. diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 260a2fbb28e..0a14c3447dc 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -94,10 +94,10 @@ impl Device { self.viewport_override.as_ref().map(|v| { Size2D::new(Au::from_f32_px(v.size.width), Au::from_f32_px(v.size.height)) - }).unwrap_or_else(|| { - // TODO(emilio): Grab from pres context. - Size2D::new(Au::from_f32_px(1024.0), - Au::from_f32_px(768.0)) + }).unwrap_or_else(|| unsafe { + // TODO(emilio): Need to take into account scrollbars. + Size2D::new(Au((*self.pres_context).mVisibleArea.width), + Au((*self.pres_context).mVisibleArea.height)) }) } } diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index f468ec94ab8..8a38318de01 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1373,8 +1373,7 @@ extern "C" { style: ServoComputedValuesBorrowed, parent_style: ServoComputedValuesBorrowedOrNull, - pres_context: - RawGeckoPresContextBorrowed, + set: RawServoStyleSetBorrowed, result: RawGeckoComputedKeyframeValuesListBorrowedMut); } diff --git a/components/style/matching.rs b/components/style/matching.rs index aae30ce1948..2fbf2760ce8 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -539,7 +539,7 @@ trait PrivateMatchMethods: TElement { // Invoke the cascade algorithm. let values = - Arc::new(cascade(shared_context.viewport_size, + Arc::new(cascade(shared_context.viewport_size(), rule_node, inherited_values, layout_parent_style, diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml index 829aa98a270..a787ce685b3 100644 --- a/ports/geckolib/Cargo.toml +++ b/ports/geckolib/Cargo.toml @@ -13,11 +13,9 @@ crate-type = ["staticlib", "rlib"] bindgen = ["style/use_bindgen"] [dependencies] -app_units = "0.4" atomic_refcell = "0.1" cssparser = "0.12" env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size -euclid = "0.11" lazy_static = "0.2" libc = "0.2" log = {version = "0.3.5", features = ["release_max_level_info"]} diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index d50a4c74371..0c85b8a45a7 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -2,12 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use app_units::Au; use atomic_refcell::AtomicRefMut; use cssparser::Parser; use cssparser::ToCss as ParserToCss; use env_logger::LogBuilder; -use euclid::Size2D; use num_cpus; use parking_lot::RwLock; use rayon; @@ -43,7 +41,6 @@ use style::gecko_bindings::bindings::{nsACString, nsAString}; use style::gecko_bindings::bindings::Gecko_AnimationAppendKeyframe; use style::gecko_bindings::bindings::RawGeckoComputedKeyframeValuesListBorrowedMut; use style::gecko_bindings::bindings::RawGeckoElementBorrowed; -use style::gecko_bindings::bindings::RawGeckoPresContextBorrowed; use style::gecko_bindings::bindings::RawServoAnimationValueBorrowed; use style::gecko_bindings::bindings::RawServoAnimationValueStrong; use style::gecko_bindings::bindings::RawServoImportRuleBorrowed; @@ -162,8 +159,6 @@ fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyle ThreadLocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone()); SharedStyleContext { - // FIXME (bug 1303229): Use the actual viewport size here - viewport_size: Size2D::new(Au(0), Au(0)), stylist: per_doc_data.stylist.clone(), running_animations: per_doc_data.running_animations.clone(), expired_animations: per_doc_data.expired_animations.clone(), @@ -1335,23 +1330,24 @@ pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed, pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeListBorrowed, style: ServoComputedValuesBorrowed, parent_style: ServoComputedValuesBorrowedOrNull, - pres_context: RawGeckoPresContextBorrowed, + raw_data: RawServoStyleSetBorrowed, computed_keyframes: RawGeckoComputedKeyframeValuesListBorrowedMut) { use style::properties::LonghandIdSet; use style::properties::declaration_block::Importance; use style::values::computed::Context; + let data = PerDocumentStyleData::from_ffi(raw_data).borrow(); let style = ComputedValues::as_arc(&style); let parent_style = parent_style.as_ref().map(|r| &**ComputedValues::as_arc(&r)); - let init = ComputedValues::default_values(pres_context); + + let default_values = data.stylist.device.default_values(); let context = Context { is_root_element: false, - // FIXME (bug 1303229): Use the actual viewport size here - viewport_size: Size2D::new(Au(0), Au(0)), - inherited_style: parent_style.unwrap_or(&init), - layout_parent_style: parent_style.unwrap_or(&init), + viewport_size: data.stylist.device.au_viewport_size(), + inherited_style: parent_style.unwrap_or(default_values), + layout_parent_style: parent_style.unwrap_or(default_values), style: (**style).clone(), font_metrics_provider: None, }; @@ -1374,7 +1370,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis .filter_map(|&(ref decl, imp)| { if imp == Importance::Normal { let property = TransitionProperty::from_declaration(decl); - let animation = AnimationValue::from_declaration(decl, &context, &init); + let animation = AnimationValue::from_declaration(decl, &context, default_values); debug_assert!(property.is_none() == animation.is_none(), "The failure condition of TransitionProperty::from_declaration \ and AnimationValue::from_declaration should be the same"); diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index 8754021afa5..ac04fb58757 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -4,11 +4,9 @@ #![deny(warnings)] -extern crate app_units; extern crate atomic_refcell; extern crate cssparser; extern crate env_logger; -extern crate euclid; #[macro_use] extern crate lazy_static; extern crate libc; #[macro_use] extern crate log;