diff --git a/src/components/main/layout/incremental.rs b/src/components/main/layout/incremental.rs index da45839188c..165548e9517 100644 --- a/src/components/main/layout/incremental.rs +++ b/src/components/main/layout/incremental.rs @@ -47,11 +47,6 @@ impl RestyleDamage { 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. /// We would rather not allow this, but some types in script /// need to store RestyleDamage without depending on this crate. diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs index 899d998293b..af14f96a9c6 100644 --- a/src/components/main/layout/layout_task.rs +++ b/src/components/main/layout/layout_task.rs @@ -33,7 +33,7 @@ use script::dom::element::{HTMLBodyElementTypeId, HTMLHtmlElementTypeId}; use script::layout_interface::{AddStylesheetMsg, ContentBoxQuery}; use script::layout_interface::{ContentBoxesQuery, ContentBoxesResponse, ExitNowMsg, LayoutQuery}; 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::{ReflowForDisplay, ReflowMsg}; 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. struct PropagateDamageTraversal { - resized: bool, + all_style_damage: bool, } impl PreorderFlowTraversal for PropagateDamageTraversal { #[inline] fn process(&mut self, flow: &mut Flow) -> bool { - // Also set any damage implied by resize. - if self.resized { - flow::mut_base(flow).restyle_damage.union_in_place(RestyleDamage::for_resize()) + if self.all_style_damage { + flow::mut_base(flow).restyle_damage.union_in_place(RestyleDamage::all()) } 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())); } + // 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), Au::from_px(data.window_size.height as int)); - let resized = self.screen_size != Some(screen_size); - debug!("resized: {}", resized); + if self.screen_size != Some(screen_size) { + all_style_damage = true; + } self.screen_size = Some(screen_size); // Create a layout context for use throughout the following passes. @@ -423,7 +430,7 @@ impl LayoutTask { // Perform CSS selector matching if necessary. match data.damage.level { ReflowDocumentDamage => {} - MatchSelectorsDocumentDamage => { + _ => { do profile(time::LayoutSelectorMatchCategory, self.profiler_chan.clone()) { node.match_subtree(self.stylist.clone()); node.cascade_subtree(None); @@ -438,7 +445,7 @@ impl LayoutTask { // Propagate damage. layout_root.traverse_preorder(&mut PropagateDamageTraversal { - resized: resized, + all_style_damage: all_style_damage }); layout_root.traverse_postorder(&mut ComputeDamageTraversal.clone()); diff --git a/src/components/script/layout_interface.rs b/src/components/script/layout_interface.rs index efc47a38635..8de94f8a04e 100644 --- a/src/components/script/layout_interface.rs +++ b/src/components/script/layout_interface.rs @@ -69,6 +69,8 @@ pub enum DocumentDamageLevel { ReflowDocumentDamage, /// Perform CSS selector matching and reflow. MatchSelectorsDocumentDamage, + /// Content changed; set full style damage and do the above. + ContentChangedDocumentDamage, } impl DocumentDamageLevel { @@ -135,6 +137,11 @@ fn test_add_damage() { } 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); } diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index dc49ca493b8..63d1fdec2df 100755 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -23,6 +23,7 @@ use layout_interface::{ContentBoxQuery, ContentBoxResponse}; use layout_interface::{DocumentDamageLevel, HitTestQuery, HitTestResponse, LayoutQuery}; use layout_interface::{LayoutChan, MatchSelectorsDocumentDamage, QueryMsg, ReapLayoutDataMsg}; use layout_interface::{Reflow, ReflowDocumentDamage, ReflowForDisplay, ReflowGoal, ReflowMsg}; +use layout_interface::ContentChangedDocumentDamage; use layout_interface; use dom::node::ScriptView; @@ -329,7 +330,7 @@ impl Page { /// FIXME: This should basically never be used. pub fn reflow_all(&mut self, goal: ReflowGoal, script_chan: ScriptChan, compositor: @ScriptListener) { if self.frame.is_some() { - self.damage(MatchSelectorsDocumentDamage); + self.damage(ContentChangedDocumentDamage); } //FIXME: In the case where an initial reflow is required, we should always