mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Bug 1303229: Get the proper viewport size for stylo. r=heycam
At least until we support scrollbars properly, this size is going to be the correct one. I've left a TODO to grab the proper one once we support it. This allows to trivially test viewport units for now. MozReview-Commit-ID: JdaZ6WlZ2C6 Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
parent
2f8cf6afc3
commit
95ccfa748e
8 changed files with 24 additions and 23 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -62,9 +62,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>,
|
||||
|
||||
|
@ -92,6 +89,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.
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -540,7 +540,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,
|
||||
|
|
|
@ -162,8 +162,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(),
|
||||
|
@ -1348,7 +1346,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
|
|||
|
||||
let context = Context {
|
||||
is_root_element: false,
|
||||
// FIXME (bug 1303229): Use the actual viewport size here
|
||||
// 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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue