aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/layout/construct.rs
diff options
context:
space:
mode:
authorGlenn Watson <gw@intuitionlibrary.com>2014-08-22 21:21:09 +1000
committerGlenn Watson <gw@intuitionlibrary.com>2014-08-27 13:03:08 +1000
commitfa6b59901a4281b591d612480b5db22574363139 (patch)
treefd5a7bfd8bc9cb49860394e8389a57435a4da2da /src/components/layout/construct.rs
parent15ae8d1eeaacec8942c674a74c0c49d177ebaae8 (diff)
downloadservo-fa6b59901a4281b591d612480b5db22574363139.tar.gz
servo-fa6b59901a4281b591d612480b5db22574363139.zip
Add support for backgrounds on inline elements. Fix fixup() by removing it.
The code that managed ranges was buggy - failing on edge cases such as a span within a span. I have refactored the code so that the context information for inline formatting can optionally be stored within a fragment. This seems cleaner to me, and fixes the bugs encountered when making these changes by removing the need for the fixup() functionality (and ranges).
Diffstat (limited to 'src/components/layout/construct.rs')
-rw-r--r--src/components/layout/construct.rs38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/components/layout/construct.rs b/src/components/layout/construct.rs
index db6084a1c02..0f832bacfb8 100644
--- a/src/components/layout/construct.rs
+++ b/src/components/layout/construct.rs
@@ -32,7 +32,7 @@ use fragment::{ImageFragment, ImageFragmentInfo, SpecificFragmentInfo, TableFrag
use fragment::{TableCellFragment, TableColumnFragment, TableColumnFragmentInfo};
use fragment::{TableRowFragment, TableWrapperFragment, UnscannedTextFragment};
use fragment::{UnscannedTextFragmentInfo};
-use inline::{FragmentIndex, InlineFragments, InlineFlow};
+use inline::{InlineFragments, InlineFlow};
use parallel;
use table_wrapper::TableWrapperFlow;
use table::TableFlow;
@@ -57,7 +57,6 @@ use script::dom::node::{DocumentNodeTypeId, ElementNodeTypeId, ProcessingInstruc
use script::dom::node::{TextNodeTypeId};
use script::dom::htmlobjectelement::is_image_data;
use servo_util::namespace;
-use servo_util::range::Range;
use std::mem;
use std::sync::atomics::Relaxed;
use style::ComputedValues;
@@ -140,37 +139,40 @@ struct InlineFragmentsAccumulator {
/// The list of fragments.
fragments: InlineFragments,
- /// Whether we've created a range to enclose all the fragments. This will be true if the outer node
- /// is an inline and false otherwise.
- has_enclosing_range: bool,
+ /// Whether we've created a range to enclose all the fragments. This will be Some() if the outer node
+ /// is an inline and None otherwise.
+ enclosing_style: Option<Arc<ComputedValues>>,
}
impl InlineFragmentsAccumulator {
fn new() -> InlineFragmentsAccumulator {
InlineFragmentsAccumulator {
fragments: InlineFragments::new(),
- has_enclosing_range: false,
+ enclosing_style: None,
}
}
fn from_inline_node(node: &ThreadSafeLayoutNode) -> InlineFragmentsAccumulator {
- let mut fragments = InlineFragments::new();
- fragments.push_range(node.style().clone(), Range::empty());
+ let fragments = InlineFragments::new();
InlineFragmentsAccumulator {
fragments: fragments,
- has_enclosing_range: true,
+ enclosing_style: Some(node.style().clone()),
}
}
fn finish(self) -> InlineFragments {
let InlineFragmentsAccumulator {
fragments: mut fragments,
- has_enclosing_range
+ enclosing_style
} = self;
- if has_enclosing_range {
- let len = FragmentIndex(fragments.len() as int);
- fragments.get_mut_range(FragmentIndex(0)).range.extend_to(len);
+ match enclosing_style {
+ Some(enclosing_style) => {
+ for frag in fragments.fragments.mut_iter() {
+ frag.add_inline_context_style(enclosing_style.clone());
+ }
+ }
+ None => {}
}
fragments
}
@@ -374,10 +376,10 @@ impl<'a, 'b> FlowConstructor<'a, 'b> {
// Add whitespace results. They will be stripped out later on when
// between block elements, and retained when between inline elements.
let fragment_info = UnscannedTextFragment(UnscannedTextFragmentInfo::from_text(" ".to_string()));
- let fragment = Fragment::from_opaque_node_and_style(whitespace_node,
+ let mut fragment = Fragment::from_opaque_node_and_style(whitespace_node,
whitespace_style.clone(),
fragment_info);
- inline_fragment_accumulator.fragments.push(fragment, whitespace_style);
+ inline_fragment_accumulator.fragments.push(&mut fragment, whitespace_style);
}
ConstructionItemConstructionResult(TableColumnFragmentConstructionItem(_)) => {
// TODO: Implement anonymous table objects for missing parents
@@ -525,10 +527,10 @@ impl<'a, 'b> FlowConstructor<'a, 'b> {
=> {
// Instantiate the whitespace fragment.
let fragment_info = UnscannedTextFragment(UnscannedTextFragmentInfo::from_text(" ".to_string()));
- let fragment = Fragment::from_opaque_node_and_style(whitespace_node,
+ let mut fragment = Fragment::from_opaque_node_and_style(whitespace_node,
whitespace_style.clone(),
fragment_info);
- fragment_accumulator.fragments.push(fragment, whitespace_style)
+ fragment_accumulator.fragments.push(&mut fragment, whitespace_style)
}
ConstructionItemConstructionResult(TableColumnFragmentConstructionItem(_)) => {
// TODO: Implement anonymous table objects for missing parents
@@ -570,7 +572,7 @@ impl<'a, 'b> FlowConstructor<'a, 'b> {
}
let mut fragments = InlineFragments::new();
- fragments.push(Fragment::new(self, node), node.style().clone());
+ fragments.push(&mut Fragment::new(self, node), node.style().clone());
let construction_item = InlineFragmentsConstructionItem(InlineFragmentsConstructionResult {
splits: Vec::new(),