diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2014-10-10 22:55:53 -0700 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2014-10-13 16:33:19 -0700 |
commit | d560d5145400f81fcb816b08406f58171c605d6e (patch) | |
tree | 445e27118439784549425a9e9bc466d238a681df /components/util/range.rs | |
parent | a92e55597e03d6a7b71e8178cf4a7a6d760f94be (diff) | |
download | servo-d560d5145400f81fcb816b08406f58171c605d6e.tar.gz servo-d560d5145400f81fcb816b08406f58171c605d6e.zip |
layout: Refactor inline layout to remove the code that tried to avoid
splitting fragments.
I don't think it will be possible to avoid splitting fragments in the
presence of `vertical-align`, because one `ScannedTextFragment` could
potentially be split into arbitrary many fragments, each having its own
vertical position that can influence layout of other fragments.
This code also removes parts of `Range` that were no longer used.
Diffstat (limited to 'components/util/range.rs')
-rw-r--r-- | components/util/range.rs | 87 |
1 files changed, 23 insertions, 64 deletions
diff --git a/components/util/range.rs b/components/util/range.rs index 123bd42a280..9b2363b9967 100644 --- a/components/util/range.rs +++ b/components/util/range.rs @@ -79,24 +79,36 @@ macro_rules! int_range_index { } } + impl Mul<$Self, $Self> for $Self { + #[inline] + fn mul(&self, other: &$Self) -> $Self { + $Self(self.get() * other.get()) + } + } + impl Neg<$Self> for $Self { #[inline] fn neg(&self) -> $Self { $Self(-self.get()) } } - ) -} -#[deriving(Show)] -pub enum RangeRelation<I> { - OverlapsBegin(/* overlap */ I), - OverlapsEnd(/* overlap */ I), - ContainedBy, - Contains, - Coincides, - EntirelyBefore, - EntirelyAfter + impl ::std::num::One for $Self { + fn one() -> $Self { + $Self(1) + } + } + + impl ToPrimitive for $Self { + fn to_i64(&self) -> Option<i64> { + Some(self.get() as i64) + } + + fn to_u64(&self) -> Option<u64> { + Some(self.get() as u64) + } + } + ) } /// A range of indices @@ -267,38 +279,6 @@ impl<I: RangeIndex> Range<I> { Range::new(begin, end - begin) } } - - /// Computes the relationship between two ranges (`self` and `other`), - /// from the point of view of `self`. So, 'EntirelyBefore' means - /// that the `self` range is entirely before `other` range. - #[inline] - pub fn relation_to_range(&self, other: &Range<I>) -> RangeRelation<I> { - if other.begin() > self.end() { - return EntirelyBefore; - } - if self.begin() > other.end() { - return EntirelyAfter; - } - if self.begin() == other.begin() && self.end() == other.end() { - return Coincides; - } - if self.begin() <= other.begin() && self.end() >= other.end() { - return Contains; - } - if self.begin() >= other.begin() && self.end() <= other.end() { - return ContainedBy; - } - if self.begin() < other.begin() && self.end() < other.end() { - let overlap = self.end() - other.begin(); - return OverlapsBegin(overlap); - } - if self.begin() > other.begin() && self.end() > other.end() { - let overlap = other.end() - self.begin(); - return OverlapsEnd(overlap); - } - fail!("relation_to_range(): didn't classify self={}, other={}", - self, other); - } } /// Methods for `Range`s with indices based on integer values @@ -331,25 +311,4 @@ impl<T: Int, I: IntRangeIndex<T>> Range<I> { }, } } - - #[inline] - pub fn repair_after_coalesced_range(&mut self, other: &Range<I>) { - let relation = self.relation_to_range(other); - debug!("repair_after_coalesced_range: possibly repairing range {}", *self); - debug!("repair_after_coalesced_range: relation of original range and coalesced range {}: {}", - *other, relation); - let _1: I = IntRangeIndex::new(num::one::<T>()); - match relation { - EntirelyBefore => {}, - EntirelyAfter => { self.shift_by(-other.length()); }, - Coincides | ContainedBy => { self.reset(other.begin(), _1); }, - Contains => { self.extend_by(-other.length()); }, - OverlapsBegin(overlap) => { self.extend_by(_1 - overlap); }, - OverlapsEnd(overlap) => { - let len = self.length() - overlap + _1; - self.reset(other.begin(), len); - } - }; - debug!("repair_after_coalesced_range: new range: ---- {}", *self); - } } |