mirror of
https://github.com/servo/servo.git
synced 2025-06-17 04:44:28 +00:00
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:
commit
06f99c13f2
12 changed files with 32 additions and 40 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -921,11 +921,9 @@ dependencies = [
|
||||||
name = "geckoservo"
|
name = "geckoservo"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -713,7 +713,7 @@ impl BlockFlow {
|
||||||
// infrastructure to make it scrollable.
|
// infrastructure to make it scrollable.
|
||||||
let viewport_size =
|
let viewport_size =
|
||||||
LogicalSize::from_physical(self.fragment.style.writing_mode,
|
LogicalSize::from_physical(self.fragment.style.writing_mode,
|
||||||
shared_context.viewport_size);
|
shared_context.viewport_size());
|
||||||
let block_size = max(viewport_size.block,
|
let block_size = max(viewport_size.block,
|
||||||
self.fragment.border_box.size.block + block_start_margin_value +
|
self.fragment.border_box.size.block + block_start_margin_value +
|
||||||
block_end_margin_value);
|
block_end_margin_value);
|
||||||
|
@ -990,7 +990,7 @@ impl BlockFlow {
|
||||||
if is_root {
|
if is_root {
|
||||||
let viewport_size =
|
let viewport_size =
|
||||||
LogicalSize::from_physical(self.fragment.style.writing_mode,
|
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)
|
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> {
|
pub fn explicit_block_containing_size(&self, shared_context: &SharedStyleContext) -> Option<Au> {
|
||||||
if self.is_root() || self.is_fixed() {
|
if self.is_root() || self.is_fixed() {
|
||||||
let viewport_size = LogicalSize::from_physical(self.fragment.style.writing_mode,
|
let viewport_size = LogicalSize::from_physical(self.fragment.style.writing_mode,
|
||||||
shared_context.viewport_size);
|
shared_context.viewport_size());
|
||||||
Some(viewport_size.block)
|
Some(viewport_size.block)
|
||||||
} else if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) &&
|
} else if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) &&
|
||||||
self.base.block_container_explicit_block_size.is_none() {
|
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) {
|
fn calculate_absolute_block_size_and_margins(&mut self, shared_context: &SharedStyleContext) {
|
||||||
let opaque_self = OpaqueFlow::from_flow(self);
|
let opaque_self = OpaqueFlow::from_flow(self);
|
||||||
let containing_block_block_size =
|
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
|
// This is the stored content block-size value from assign-block-size
|
||||||
let content_block_size = self.fragment.border_box.size.block;
|
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); }
|
if self.is_root() { explicit_content_size = max(parent_container_size, explicit_content_size); }
|
||||||
// Calculate containing block inline size.
|
// Calculate containing block inline size.
|
||||||
let containing_block_size = if flags.contains(IS_ABSOLUTELY_POSITIONED) {
|
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 {
|
} else {
|
||||||
content_inline_size
|
content_inline_size
|
||||||
};
|
};
|
||||||
|
@ -1718,7 +1718,7 @@ impl BlockFlow {
|
||||||
debug!("Setting root position");
|
debug!("Setting root position");
|
||||||
self.base.position.start = LogicalPoint::zero(self.base.writing_mode);
|
self.base.position.start = LogicalPoint::zero(self.base.writing_mode);
|
||||||
self.base.block_container_inline_size = LogicalSize::from_physical(
|
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;
|
self.base.block_container_writing_mode = self.base.writing_mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2820,7 +2820,7 @@ impl ISizeAndMarginsComputer for AbsoluteNonReplaced {
|
||||||
shared_context: &SharedStyleContext)
|
shared_context: &SharedStyleContext)
|
||||||
-> Au {
|
-> Au {
|
||||||
let opaque_block = OpaqueFlow::from_flow(block);
|
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,
|
fn set_inline_position_of_flow_if_necessary(&self,
|
||||||
|
@ -2932,7 +2932,7 @@ impl ISizeAndMarginsComputer for AbsoluteReplaced {
|
||||||
-> MaybeAuto {
|
-> MaybeAuto {
|
||||||
let opaque_block = OpaqueFlow::from_flow(block);
|
let opaque_block = OpaqueFlow::from_flow(block);
|
||||||
let containing_block_inline_size =
|
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 container_block_size = block.explicit_block_containing_size(shared_context);
|
||||||
let fragment = block.fragment();
|
let fragment = block.fragment();
|
||||||
fragment.assign_replaced_inline_size_if_necessary(containing_block_inline_size, container_block_size);
|
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)
|
shared_context: &SharedStyleContext)
|
||||||
-> Au {
|
-> Au {
|
||||||
let opaque_block = OpaqueFlow::from_flow(block);
|
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,
|
fn set_inline_position_of_flow_if_necessary(&self,
|
||||||
|
|
|
@ -140,7 +140,7 @@ impl Flow for MulticolFlow {
|
||||||
// FIXME: (until column balancing) substract margins/borders/padding
|
// FIXME: (until column balancing) substract margins/borders/padding
|
||||||
LogicalSize::from_physical(
|
LogicalSize::from_physical(
|
||||||
self.block_flow.base.writing_mode,
|
self.block_flow.base.writing_mode,
|
||||||
ctx.shared_context().viewport_size,
|
ctx.shared_context().viewport_size(),
|
||||||
).block
|
).block
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -503,7 +503,6 @@ impl LayoutThread {
|
||||||
|
|
||||||
LayoutContext {
|
LayoutContext {
|
||||||
style_context: SharedStyleContext {
|
style_context: SharedStyleContext {
|
||||||
viewport_size: self.viewport_size.clone(),
|
|
||||||
stylist: rw_data.stylist.clone(),
|
stylist: rw_data.stylist.clone(),
|
||||||
running_animations: self.running_animations.clone(),
|
running_animations: self.running_animations.clone(),
|
||||||
expired_animations: self.expired_animations.clone(),
|
expired_animations: self.expired_animations.clone(),
|
||||||
|
|
|
@ -426,7 +426,7 @@ fn compute_style_for_animation_step(context: &SharedStyleContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
let computed =
|
let computed =
|
||||||
properties::apply_declarations(context.viewport_size,
|
properties::apply_declarations(context.viewport_size(),
|
||||||
/* is_root = */ false,
|
/* is_root = */ false,
|
||||||
iter,
|
iter,
|
||||||
previous_style,
|
previous_style,
|
||||||
|
|
|
@ -63,9 +63,6 @@ pub enum QuirksMode {
|
||||||
/// There's exactly one of these during a given restyle traversal, and it's
|
/// There's exactly one of these during a given restyle traversal, and it's
|
||||||
/// shared among the worker threads.
|
/// shared among the worker threads.
|
||||||
pub struct SharedStyleContext {
|
pub struct SharedStyleContext {
|
||||||
/// The current viewport size.
|
|
||||||
pub viewport_size: Size2D<Au>,
|
|
||||||
|
|
||||||
/// The CSS selector stylist.
|
/// The CSS selector stylist.
|
||||||
pub stylist: Arc<Stylist>,
|
pub stylist: Arc<Stylist>,
|
||||||
|
|
||||||
|
@ -93,6 +90,13 @@ pub struct SharedStyleContext {
|
||||||
pub default_computed_values: Arc<ComputedValues>,
|
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
|
/// Information about the current element being processed. We group this together
|
||||||
/// into a single struct within ThreadLocalStyleContext so that we can instantiate
|
/// into a single struct within ThreadLocalStyleContext so that we can instantiate
|
||||||
/// and destroy it easily at the beginning and end of element processing.
|
/// and destroy it easily at the beginning and end of element processing.
|
||||||
|
|
|
@ -94,10 +94,10 @@ impl Device {
|
||||||
self.viewport_override.as_ref().map(|v| {
|
self.viewport_override.as_ref().map(|v| {
|
||||||
Size2D::new(Au::from_f32_px(v.size.width),
|
Size2D::new(Au::from_f32_px(v.size.width),
|
||||||
Au::from_f32_px(v.size.height))
|
Au::from_f32_px(v.size.height))
|
||||||
}).unwrap_or_else(|| {
|
}).unwrap_or_else(|| unsafe {
|
||||||
// TODO(emilio): Grab from pres context.
|
// TODO(emilio): Need to take into account scrollbars.
|
||||||
Size2D::new(Au::from_f32_px(1024.0),
|
Size2D::new(Au((*self.pres_context).mVisibleArea.width),
|
||||||
Au::from_f32_px(768.0))
|
Au((*self.pres_context).mVisibleArea.height))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1373,8 +1373,7 @@ extern "C" {
|
||||||
style: ServoComputedValuesBorrowed,
|
style: ServoComputedValuesBorrowed,
|
||||||
parent_style:
|
parent_style:
|
||||||
ServoComputedValuesBorrowedOrNull,
|
ServoComputedValuesBorrowedOrNull,
|
||||||
pres_context:
|
set: RawServoStyleSetBorrowed,
|
||||||
RawGeckoPresContextBorrowed,
|
|
||||||
result:
|
result:
|
||||||
RawGeckoComputedKeyframeValuesListBorrowedMut);
|
RawGeckoComputedKeyframeValuesListBorrowedMut);
|
||||||
}
|
}
|
||||||
|
|
|
@ -539,7 +539,7 @@ trait PrivateMatchMethods: TElement {
|
||||||
|
|
||||||
// Invoke the cascade algorithm.
|
// Invoke the cascade algorithm.
|
||||||
let values =
|
let values =
|
||||||
Arc::new(cascade(shared_context.viewport_size,
|
Arc::new(cascade(shared_context.viewport_size(),
|
||||||
rule_node,
|
rule_node,
|
||||||
inherited_values,
|
inherited_values,
|
||||||
layout_parent_style,
|
layout_parent_style,
|
||||||
|
|
|
@ -13,11 +13,9 @@ crate-type = ["staticlib", "rlib"]
|
||||||
bindgen = ["style/use_bindgen"]
|
bindgen = ["style/use_bindgen"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
app_units = "0.4"
|
|
||||||
atomic_refcell = "0.1"
|
atomic_refcell = "0.1"
|
||||||
cssparser = "0.12"
|
cssparser = "0.12"
|
||||||
env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size
|
env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size
|
||||||
euclid = "0.11"
|
|
||||||
lazy_static = "0.2"
|
lazy_static = "0.2"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
log = {version = "0.3.5", features = ["release_max_level_info"]}
|
log = {version = "0.3.5", features = ["release_max_level_info"]}
|
||||||
|
|
|
@ -2,12 +2,10 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use app_units::Au;
|
|
||||||
use atomic_refcell::AtomicRefMut;
|
use atomic_refcell::AtomicRefMut;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use cssparser::ToCss as ParserToCss;
|
use cssparser::ToCss as ParserToCss;
|
||||||
use env_logger::LogBuilder;
|
use env_logger::LogBuilder;
|
||||||
use euclid::Size2D;
|
|
||||||
use num_cpus;
|
use num_cpus;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use rayon;
|
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::Gecko_AnimationAppendKeyframe;
|
||||||
use style::gecko_bindings::bindings::RawGeckoComputedKeyframeValuesListBorrowedMut;
|
use style::gecko_bindings::bindings::RawGeckoComputedKeyframeValuesListBorrowedMut;
|
||||||
use style::gecko_bindings::bindings::RawGeckoElementBorrowed;
|
use style::gecko_bindings::bindings::RawGeckoElementBorrowed;
|
||||||
use style::gecko_bindings::bindings::RawGeckoPresContextBorrowed;
|
|
||||||
use style::gecko_bindings::bindings::RawServoAnimationValueBorrowed;
|
use style::gecko_bindings::bindings::RawServoAnimationValueBorrowed;
|
||||||
use style::gecko_bindings::bindings::RawServoAnimationValueStrong;
|
use style::gecko_bindings::bindings::RawServoAnimationValueStrong;
|
||||||
use style::gecko_bindings::bindings::RawServoImportRuleBorrowed;
|
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());
|
ThreadLocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone());
|
||||||
|
|
||||||
SharedStyleContext {
|
SharedStyleContext {
|
||||||
// FIXME (bug 1303229): Use the actual viewport size here
|
|
||||||
viewport_size: Size2D::new(Au(0), Au(0)),
|
|
||||||
stylist: per_doc_data.stylist.clone(),
|
stylist: per_doc_data.stylist.clone(),
|
||||||
running_animations: per_doc_data.running_animations.clone(),
|
running_animations: per_doc_data.running_animations.clone(),
|
||||||
expired_animations: per_doc_data.expired_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,
|
pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeListBorrowed,
|
||||||
style: ServoComputedValuesBorrowed,
|
style: ServoComputedValuesBorrowed,
|
||||||
parent_style: ServoComputedValuesBorrowedOrNull,
|
parent_style: ServoComputedValuesBorrowedOrNull,
|
||||||
pres_context: RawGeckoPresContextBorrowed,
|
raw_data: RawServoStyleSetBorrowed,
|
||||||
computed_keyframes: RawGeckoComputedKeyframeValuesListBorrowedMut)
|
computed_keyframes: RawGeckoComputedKeyframeValuesListBorrowedMut)
|
||||||
{
|
{
|
||||||
use style::properties::LonghandIdSet;
|
use style::properties::LonghandIdSet;
|
||||||
use style::properties::declaration_block::Importance;
|
use style::properties::declaration_block::Importance;
|
||||||
use style::values::computed::Context;
|
use style::values::computed::Context;
|
||||||
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||||
|
|
||||||
let style = ComputedValues::as_arc(&style);
|
let style = ComputedValues::as_arc(&style);
|
||||||
let parent_style = parent_style.as_ref().map(|r| &**ComputedValues::as_arc(&r));
|
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 {
|
let context = Context {
|
||||||
is_root_element: false,
|
is_root_element: false,
|
||||||
// FIXME (bug 1303229): Use the actual viewport size here
|
viewport_size: data.stylist.device.au_viewport_size(),
|
||||||
viewport_size: Size2D::new(Au(0), Au(0)),
|
inherited_style: parent_style.unwrap_or(default_values),
|
||||||
inherited_style: parent_style.unwrap_or(&init),
|
layout_parent_style: parent_style.unwrap_or(default_values),
|
||||||
layout_parent_style: parent_style.unwrap_or(&init),
|
|
||||||
style: (**style).clone(),
|
style: (**style).clone(),
|
||||||
font_metrics_provider: None,
|
font_metrics_provider: None,
|
||||||
};
|
};
|
||||||
|
@ -1374,7 +1370,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
|
||||||
.filter_map(|&(ref decl, imp)| {
|
.filter_map(|&(ref decl, imp)| {
|
||||||
if imp == Importance::Normal {
|
if imp == Importance::Normal {
|
||||||
let property = TransitionProperty::from_declaration(decl);
|
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(),
|
debug_assert!(property.is_none() == animation.is_none(),
|
||||||
"The failure condition of TransitionProperty::from_declaration \
|
"The failure condition of TransitionProperty::from_declaration \
|
||||||
and AnimationValue::from_declaration should be the same");
|
and AnimationValue::from_declaration should be the same");
|
||||||
|
|
|
@ -4,11 +4,9 @@
|
||||||
|
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
extern crate app_units;
|
|
||||||
extern crate atomic_refcell;
|
extern crate atomic_refcell;
|
||||||
extern crate cssparser;
|
extern crate cssparser;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
extern crate euclid;
|
|
||||||
#[macro_use] extern crate lazy_static;
|
#[macro_use] extern crate lazy_static;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue