mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
Refactor DocumentDamageLevel::add and add test
This commit is contained in:
parent
c3a9583000
commit
b61160490a
1 changed files with 18 additions and 9 deletions
|
@ -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,18 @@ 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,
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +125,16 @@ 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(ReflowDocumentDamage, MatchSelectorsDocumentDamage, MatchSelectorsDocumentDamage);
|
||||||
|
assert_add(MatchSelectorsDocumentDamage, ReflowDocumentDamage, MatchSelectorsDocumentDamage);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue