Skip to content

Commit

Permalink
Auto merge of #15913 - emilio:viewport-size, r=heycam,hiro
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo committed Mar 11, 2017
2 parents e102577 + 75fa30c commit 06f99c1
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 40 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions components/layout/block.rs
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/layout/multicol.rs
Expand Up @@ -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
}
}
Expand Down
1 change: 0 additions & 1 deletion components/layout_thread/lib.rs
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion components/style/animation.rs
Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions components/style/context.rs
Expand Up @@ -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>,

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions components/style/gecko/media_queries.rs
Expand Up @@ -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))
})
}
}
Expand Down
3 changes: 1 addition & 2 deletions components/style/gecko_bindings/bindings.rs
Expand Up @@ -1373,8 +1373,7 @@ extern "C" {
style: ServoComputedValuesBorrowed,
parent_style:
ServoComputedValuesBorrowedOrNull,
pres_context:
RawGeckoPresContextBorrowed,
set: RawServoStyleSetBorrowed,
result:
RawGeckoComputedKeyframeValuesListBorrowedMut);
}
Expand Down
2 changes: 1 addition & 1 deletion components/style/matching.rs
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions ports/geckolib/Cargo.toml
Expand Up @@ -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"]}
Expand Down
20 changes: 8 additions & 12 deletions ports/geckolib/glue.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
};
Expand All @@ -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");
Expand Down
2 changes: 0 additions & 2 deletions ports/geckolib/lib.rs
Expand Up @@ -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;
Expand Down

0 comments on commit 06f99c1

Please sign in to comment.