mirror of
https://github.com/servo/servo.git
synced 2025-06-21 23:59:00 +01:00
commit
f7cc49c30f
4 changed files with 43 additions and 24 deletions
|
@ -47,11 +47,6 @@ impl RestyleDamage {
|
||||||
restyle_damage!(Repaint, BubbleWidths, Reflow)
|
restyle_damage!(Repaint, BubbleWidths, Reflow)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Effects of resizing the window.
|
|
||||||
pub fn for_resize() -> RestyleDamage {
|
|
||||||
RestyleDamage::all()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a RestyleDamage from the underlying bit field.
|
/// Create a RestyleDamage from the underlying bit field.
|
||||||
/// We would rather not allow this, but some types in script
|
/// We would rather not allow this, but some types in script
|
||||||
/// need to store RestyleDamage without depending on this crate.
|
/// need to store RestyleDamage without depending on this crate.
|
||||||
|
|
|
@ -33,7 +33,7 @@ use script::dom::element::{HTMLBodyElementTypeId, HTMLHtmlElementTypeId};
|
||||||
use script::layout_interface::{AddStylesheetMsg, ContentBoxQuery};
|
use script::layout_interface::{AddStylesheetMsg, ContentBoxQuery};
|
||||||
use script::layout_interface::{ContentBoxesQuery, ContentBoxesResponse, ExitNowMsg, LayoutQuery};
|
use script::layout_interface::{ContentBoxesQuery, ContentBoxesResponse, ExitNowMsg, LayoutQuery};
|
||||||
use script::layout_interface::{HitTestQuery, ContentBoxResponse, HitTestResponse};
|
use script::layout_interface::{HitTestQuery, ContentBoxResponse, HitTestResponse};
|
||||||
use script::layout_interface::{MatchSelectorsDocumentDamage, Msg, PrepareToExitMsg};
|
use script::layout_interface::{ContentChangedDocumentDamage, Msg, PrepareToExitMsg};
|
||||||
use script::layout_interface::{QueryMsg, ReapLayoutDataMsg, Reflow, ReflowDocumentDamage};
|
use script::layout_interface::{QueryMsg, ReapLayoutDataMsg, Reflow, ReflowDocumentDamage};
|
||||||
use script::layout_interface::{ReflowForDisplay, ReflowMsg};
|
use script::layout_interface::{ReflowForDisplay, ReflowMsg};
|
||||||
use script::script_task::{ReflowCompleteMsg, ScriptChan, SendEventMsg};
|
use script::script_task::{ReflowCompleteMsg, ScriptChan, SendEventMsg};
|
||||||
|
@ -112,15 +112,14 @@ impl PostorderFlowTraversal for ComputeDamageTraversal {
|
||||||
///
|
///
|
||||||
/// FIXME(pcwalton): Merge this with flow tree building and/or other traversals.
|
/// FIXME(pcwalton): Merge this with flow tree building and/or other traversals.
|
||||||
struct PropagateDamageTraversal {
|
struct PropagateDamageTraversal {
|
||||||
resized: bool,
|
all_style_damage: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PreorderFlowTraversal for PropagateDamageTraversal {
|
impl PreorderFlowTraversal for PropagateDamageTraversal {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn process(&mut self, flow: &mut Flow) -> bool {
|
fn process(&mut self, flow: &mut Flow) -> bool {
|
||||||
// Also set any damage implied by resize.
|
if self.all_style_damage {
|
||||||
if self.resized {
|
flow::mut_base(flow).restyle_damage.union_in_place(RestyleDamage::all())
|
||||||
flow::mut_base(flow).restyle_damage.union_in_place(RestyleDamage::for_resize())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let prop = flow::base(flow).restyle_damage.propagate_down();
|
let prop = flow::base(flow).restyle_damage.propagate_down();
|
||||||
|
@ -404,10 +403,18 @@ impl LayoutTask {
|
||||||
|cache| cache.next_round(self.make_on_image_available_cb()));
|
|cache| cache.next_round(self.make_on_image_available_cb()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// true => Do the reflow with full style damage, because content
|
||||||
|
// changed or the window was resized.
|
||||||
|
let mut all_style_damage = match data.damage.level {
|
||||||
|
ContentChangedDocumentDamage => true,
|
||||||
|
_ => false
|
||||||
|
};
|
||||||
|
|
||||||
let screen_size = Size2D(Au::from_px(data.window_size.width as int),
|
let screen_size = Size2D(Au::from_px(data.window_size.width as int),
|
||||||
Au::from_px(data.window_size.height as int));
|
Au::from_px(data.window_size.height as int));
|
||||||
let resized = self.screen_size != Some(screen_size);
|
if self.screen_size != Some(screen_size) {
|
||||||
debug!("resized: {}", resized);
|
all_style_damage = true;
|
||||||
|
}
|
||||||
self.screen_size = Some(screen_size);
|
self.screen_size = Some(screen_size);
|
||||||
|
|
||||||
// Create a layout context for use throughout the following passes.
|
// Create a layout context for use throughout the following passes.
|
||||||
|
@ -423,7 +430,7 @@ impl LayoutTask {
|
||||||
// Perform CSS selector matching if necessary.
|
// Perform CSS selector matching if necessary.
|
||||||
match data.damage.level {
|
match data.damage.level {
|
||||||
ReflowDocumentDamage => {}
|
ReflowDocumentDamage => {}
|
||||||
MatchSelectorsDocumentDamage => {
|
_ => {
|
||||||
do profile(time::LayoutSelectorMatchCategory, self.profiler_chan.clone()) {
|
do profile(time::LayoutSelectorMatchCategory, self.profiler_chan.clone()) {
|
||||||
node.match_subtree(self.stylist.clone());
|
node.match_subtree(self.stylist.clone());
|
||||||
node.cascade_subtree(None);
|
node.cascade_subtree(None);
|
||||||
|
@ -438,7 +445,7 @@ impl LayoutTask {
|
||||||
|
|
||||||
// Propagate damage.
|
// Propagate damage.
|
||||||
layout_root.traverse_preorder(&mut PropagateDamageTraversal {
|
layout_root.traverse_preorder(&mut PropagateDamageTraversal {
|
||||||
resized: resized,
|
all_style_damage: all_style_damage
|
||||||
});
|
});
|
||||||
layout_root.traverse_postorder(&mut ComputeDamageTraversal.clone());
|
layout_root.traverse_postorder(&mut ComputeDamageTraversal.clone());
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ use geom::size::Size2D;
|
||||||
use script_task::{ScriptChan};
|
use script_task::{ScriptChan};
|
||||||
use servo_util::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use std::comm::{Chan, SharedChan};
|
use std::comm::{Chan, SharedChan};
|
||||||
|
use std::cmp;
|
||||||
use style::Stylesheet;
|
use style::Stylesheet;
|
||||||
|
|
||||||
/// Asynchronous messages that script can send to layout.
|
/// Asynchronous messages that script can send to layout.
|
||||||
|
@ -62,23 +63,20 @@ pub struct ContentBoxesResponse(~[Rect<Au>]);
|
||||||
pub struct HitTestResponse(AbstractNode<LayoutView>);
|
pub struct HitTestResponse(AbstractNode<LayoutView>);
|
||||||
|
|
||||||
/// Determines which part of the
|
/// Determines which part of the
|
||||||
|
#[deriving(Eq, Ord)]
|
||||||
pub enum DocumentDamageLevel {
|
pub enum DocumentDamageLevel {
|
||||||
/// Perform CSS selector matching and reflow.
|
|
||||||
MatchSelectorsDocumentDamage,
|
|
||||||
/// Reflow, but do not perform CSS selector matching.
|
/// Reflow, but do not perform CSS selector matching.
|
||||||
ReflowDocumentDamage,
|
ReflowDocumentDamage,
|
||||||
|
/// Perform CSS selector matching and reflow.
|
||||||
|
MatchSelectorsDocumentDamage,
|
||||||
|
/// Content changed; set full style damage and do the above.
|
||||||
|
ContentChangedDocumentDamage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DocumentDamageLevel {
|
impl DocumentDamageLevel {
|
||||||
/// Sets this damage to the maximum of this damage and the given damage.
|
/// Sets this damage to the maximum of this damage and the given damage.
|
||||||
///
|
|
||||||
/// FIXME(pcwalton): This could be refactored to use `max` and the `Ord` trait, and this
|
|
||||||
/// function removed.
|
|
||||||
pub fn add(&mut self, new_damage: DocumentDamageLevel) {
|
pub fn add(&mut self, new_damage: DocumentDamageLevel) {
|
||||||
match (*self, new_damage) {
|
*self = cmp::max(*self, new_damage);
|
||||||
(ReflowDocumentDamage, new_damage) => *self = new_damage,
|
|
||||||
(MatchSelectorsDocumentDamage, _) => *self = MatchSelectorsDocumentDamage,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,3 +127,21 @@ impl LayoutChan {
|
||||||
LayoutChan(SharedChan::new(chan))
|
LayoutChan(SharedChan::new(chan))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_add_damage() {
|
||||||
|
fn assert_add(mut a: DocumentDamageLevel, b: DocumentDamageLevel,
|
||||||
|
result: DocumentDamageLevel) {
|
||||||
|
a.add(b);
|
||||||
|
assert!(a == result);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_add(ReflowDocumentDamage, ReflowDocumentDamage, ReflowDocumentDamage);
|
||||||
|
assert_add(ContentChangedDocumentDamage, ContentChangedDocumentDamage, ContentChangedDocumentDamage);
|
||||||
|
assert_add(ReflowDocumentDamage, MatchSelectorsDocumentDamage, MatchSelectorsDocumentDamage);
|
||||||
|
assert_add(MatchSelectorsDocumentDamage, ReflowDocumentDamage, MatchSelectorsDocumentDamage);
|
||||||
|
assert_add(ReflowDocumentDamage, ContentChangedDocumentDamage, ContentChangedDocumentDamage);
|
||||||
|
assert_add(ContentChangedDocumentDamage, ReflowDocumentDamage, ContentChangedDocumentDamage);
|
||||||
|
assert_add(MatchSelectorsDocumentDamage, ContentChangedDocumentDamage, ContentChangedDocumentDamage);
|
||||||
|
assert_add(ContentChangedDocumentDamage, MatchSelectorsDocumentDamage, ContentChangedDocumentDamage);
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ use layout_interface::{ContentBoxQuery, ContentBoxResponse};
|
||||||
use layout_interface::{DocumentDamageLevel, HitTestQuery, HitTestResponse, LayoutQuery};
|
use layout_interface::{DocumentDamageLevel, HitTestQuery, HitTestResponse, LayoutQuery};
|
||||||
use layout_interface::{LayoutChan, MatchSelectorsDocumentDamage, QueryMsg, ReapLayoutDataMsg};
|
use layout_interface::{LayoutChan, MatchSelectorsDocumentDamage, QueryMsg, ReapLayoutDataMsg};
|
||||||
use layout_interface::{Reflow, ReflowDocumentDamage, ReflowForDisplay, ReflowGoal, ReflowMsg};
|
use layout_interface::{Reflow, ReflowDocumentDamage, ReflowForDisplay, ReflowGoal, ReflowMsg};
|
||||||
|
use layout_interface::ContentChangedDocumentDamage;
|
||||||
use layout_interface;
|
use layout_interface;
|
||||||
|
|
||||||
use dom::node::ScriptView;
|
use dom::node::ScriptView;
|
||||||
|
@ -329,7 +330,7 @@ impl Page {
|
||||||
/// FIXME: This should basically never be used.
|
/// FIXME: This should basically never be used.
|
||||||
pub fn reflow_all(&mut self, goal: ReflowGoal, script_chan: ScriptChan, compositor: @ScriptListener) {
|
pub fn reflow_all(&mut self, goal: ReflowGoal, script_chan: ScriptChan, compositor: @ScriptListener) {
|
||||||
if self.frame.is_some() {
|
if self.frame.is_some() {
|
||||||
self.damage(MatchSelectorsDocumentDamage);
|
self.damage(ContentChangedDocumentDamage);
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME: In the case where an initial reflow is required, we should always
|
//FIXME: In the case where an initial reflow is required, we should always
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue