aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/layout_interface.rs
diff options
context:
space:
mode:
authorKeegan McAllister <kmcallister@mozilla.com>2013-12-09 12:31:34 -0800
committerKeegan McAllister <kmcallister@mozilla.com>2013-12-09 12:31:34 -0800
commitb61160490a631292293cde78e3f286b558bdc998 (patch)
treeee0549efaf897475d9e66738c989f461e89d015b /src/components/script/layout_interface.rs
parentc3a958300068744f7772e19cceb4f127e76d0579 (diff)
downloadservo-b61160490a631292293cde78e3f286b558bdc998.tar.gz
servo-b61160490a631292293cde78e3f286b558bdc998.zip
Refactor DocumentDamageLevel::add and add test
Diffstat (limited to 'src/components/script/layout_interface.rs')
-rw-r--r--src/components/script/layout_interface.rs27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/components/script/layout_interface.rs b/src/components/script/layout_interface.rs
index 3d9cc5e96e2..efc47a38635 100644
--- a/src/components/script/layout_interface.rs
+++ b/src/components/script/layout_interface.rs
@@ -15,6 +15,7 @@ use geom::size::Size2D;
use script_task::{ScriptChan};
use servo_util::geometry::Au;
use std::comm::{Chan, SharedChan};
+use std::cmp;
use style::Stylesheet;
/// Asynchronous messages that script can send to layout.
@@ -62,23 +63,18 @@ pub struct ContentBoxesResponse(~[Rect<Au>]);
pub struct HitTestResponse(AbstractNode<LayoutView>);
/// Determines which part of the
+#[deriving(Eq, Ord)]
pub enum DocumentDamageLevel {
- /// Perform CSS selector matching and reflow.
- MatchSelectorsDocumentDamage,
/// Reflow, but do not perform CSS selector matching.
ReflowDocumentDamage,
+ /// Perform CSS selector matching and reflow.
+ MatchSelectorsDocumentDamage,
}
impl DocumentDamageLevel {
/// 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) {
- match (*self, new_damage) {
- (ReflowDocumentDamage, new_damage) => *self = new_damage,
- (MatchSelectorsDocumentDamage, _) => *self = MatchSelectorsDocumentDamage,
- }
+ *self = cmp::max(*self, new_damage);
}
}
@@ -129,3 +125,16 @@ impl LayoutChan {
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(ReflowDocumentDamage, MatchSelectorsDocumentDamage, MatchSelectorsDocumentDamage);
+ assert_add(MatchSelectorsDocumentDamage, ReflowDocumentDamage, MatchSelectorsDocumentDamage);
+}