Auto merge of #15913 - emilio:viewport-size, r=heycam,hiro

Use the proper viewport size for stylo

Reviewed upstream at [bug 1303229](https://bugzil.la/1303229).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15913)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-03-11 04:40:31 -08:00 committed by GitHub
commit 06f99c13f2
12 changed files with 32 additions and 40 deletions

2
Cargo.lock generated
View file

@ -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)",

View file

@ -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<Au> {
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,

View file

@ -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
}
}

View file

@ -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(),

View file

@ -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,

View file

@ -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<Au>,
/// The CSS selector stylist.
pub stylist: Arc<Stylist>,
@ -93,6 +90,13 @@ pub struct SharedStyleContext {
pub default_computed_values: Arc<ComputedValues>,
}
impl SharedStyleContext {
/// Return a suitable viewport size in order to be used for viewport units.
pub fn viewport_size(&self) -> Size2D<Au> {
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.

View file

@ -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))
})
}
}

View file

@ -1373,8 +1373,7 @@ extern "C" {
style: ServoComputedValuesBorrowed,
parent_style:
ServoComputedValuesBorrowedOrNull,
pres_context:
RawGeckoPresContextBorrowed,
set: RawServoStyleSetBorrowed,
result:
RawGeckoComputedKeyframeValuesListBorrowedMut);
}

View file

@ -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,

View file

@ -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"]}

View file

@ -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");

View file

@ -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;