Skip to content
Permalink
Browse files

Remove some unused methods

Simply use `Fragment::is_replaced()` in block, and remove
`content_inline_size()` method from Fragment.
  • Loading branch information
stshine committed Dec 12, 2016
1 parent 07250a7 commit b1b17f186946c2a4bc65645d6cac697e7a87eed7
Showing with 10 additions and 81 deletions.
  1. +10 −27 components/layout/block.rs
  2. +0 −54 components/layout/fragment.rs
@@ -42,7 +42,6 @@ use flow::IS_ABSOLUTELY_POSITIONED;
use flow_list::FlowList;
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow};
use fragment::{IS_INLINE_FLEX_ITEM, IS_BLOCK_FLEX_ITEM};
use fragment::SpecificFragmentInfo;
use gfx::display_list::{ClippingRegion, StackingContext};
use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree;
@@ -555,27 +554,27 @@ impl BlockFlow {
/// relevant margins for this Block.
pub fn block_type(&self) -> BlockType {
if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) {
if self.is_replaced_content() {
if self.fragment.is_replaced() {
BlockType::AbsoluteReplaced
} else {
BlockType::AbsoluteNonReplaced
}
} else if self.is_inline_flex_item() {
BlockType::InlineFlexItem
} else if self.base.flags.is_float() {
if self.is_replaced_content() {
if self.fragment.is_replaced() {
BlockType::FloatReplaced
} else {
BlockType::FloatNonReplaced
}
} else if self.is_inline_block() {
if self.is_replaced_content() {
if self.fragment.is_replaced() {
BlockType::InlineBlockReplaced
} else {
BlockType::InlineBlockNonReplaced
}
} else {
if self.is_replaced_content() {
if self.fragment.is_replaced() {
BlockType::Replaced
} else {
BlockType::NonReplaced
@@ -668,22 +667,6 @@ impl BlockFlow {
}
}

/// Return true if this has a replaced fragment.
///
/// Text, Images, Inline Block and Canvas
/// (https://html.spec.whatwg.org/multipage/#replaced-elements) fragments are considered as
/// replaced fragments.
fn is_replaced_content(&self) -> bool {
match self.fragment.specific {
SpecificFragmentInfo::ScannedText(_) |
SpecificFragmentInfo::Svg(_) |
SpecificFragmentInfo::Image(_) |
SpecificFragmentInfo::Canvas(_) |
SpecificFragmentInfo::InlineBlock(_) => true,
_ => false,
}
}

/// Return shrink-to-fit inline-size.
///
/// This is where we use the preferred inline-sizes and minimum inline-sizes
@@ -1267,7 +1250,7 @@ impl BlockFlow {

let available_block_size = containing_block_block_size -
self.fragment.border_padding.block_start_end();
if self.is_replaced_content() {
if self.fragment.is_replaced() {
// Calculate used value of block-size just like we do for inline replaced elements.
// TODO: Pass in the containing block block-size when Fragment's
// assign-block-size can handle it correctly.
@@ -1896,7 +1879,7 @@ impl Flow for BlockFlow {
fn fragment(&mut self, layout_context: &LayoutContext,
fragmentation_context: Option<FragmentationContext>)
-> Option<Arc<Flow>> {
if self.is_replaced_content() {
if self.fragment.is_replaced() {
let _scope = layout_debug_scope!("assign_replaced_block_size_if_necessary {:x}",
self.base.debug_id());

@@ -2868,7 +2851,7 @@ impl ISizeAndMarginsComputer for AbsoluteReplaced {
fragment.assign_replaced_inline_size_if_necessary(containing_block_inline_size, container_block_size);
// For replaced absolute flow, the rest of the constraint solving will
// take inline-size to be specified as the value computed here.
MaybeAuto::Specified(fragment.content_inline_size())
MaybeAuto::Specified(fragment.content_box().size.inline)
}

fn containing_block_inline_size(&self,
@@ -2927,7 +2910,7 @@ impl ISizeAndMarginsComputer for BlockReplaced {
fragment.assign_replaced_inline_size_if_necessary(parent_flow_inline_size, container_block_size);
// For replaced block flow, the rest of the constraint solving will
// take inline-size to be specified as the value computed here.
MaybeAuto::Specified(fragment.content_inline_size())
MaybeAuto::Specified(fragment.content_box().size.inline)
}

}
@@ -2985,7 +2968,7 @@ impl ISizeAndMarginsComputer for FloatReplaced {
fragment.assign_replaced_inline_size_if_necessary(parent_flow_inline_size, container_block_size);
// For replaced block flow, the rest of the constraint solving will
// take inline-size to be specified as the value computed here.
MaybeAuto::Specified(fragment.content_inline_size())
MaybeAuto::Specified(fragment.content_box().size.inline)
}
}

@@ -3073,7 +3056,7 @@ impl ISizeAndMarginsComputer for InlineBlockReplaced {
fragment.assign_replaced_inline_size_if_necessary(parent_flow_inline_size, container_block_size);
// For replaced block flow, the rest of the constraint solving will
// take inline-size to be specified as the value computed here.
MaybeAuto::Specified(fragment.content_inline_size())
MaybeAuto::Specified(fragment.content_box().size.inline)
}
}

@@ -250,21 +250,6 @@ impl fmt::Debug for SpecificFragmentInfo {
}
}

/// Clamp a value obtained from style_length, based on min / max lengths.
fn clamp_size(size: Au,
min_size: LengthOrPercentage,
max_size: LengthOrPercentageOrNone,
container_size: Au)
-> Au {
let min_size = model::specified(min_size, container_size);
let max_size = model::specified_or_none(max_size, container_size);

max(min_size, match max_size {
None => size,
Some(max_size) => min(size, max_size),
})
}

/// Information for generated content.
#[derive(Clone)]
pub enum GeneratedContentInfo {
@@ -1580,45 +1565,6 @@ impl Fragment {
}
}

/// TODO: What exactly does this function return? Why is it Au(0) for
/// `SpecificFragmentInfo::Generic`?
pub fn content_inline_size(&self) -> Au {
match self.specific {
SpecificFragmentInfo::Generic |
SpecificFragmentInfo::GeneratedContent(_) |
SpecificFragmentInfo::Iframe(_) |
SpecificFragmentInfo::Table |
SpecificFragmentInfo::TableCell |
SpecificFragmentInfo::TableRow |
SpecificFragmentInfo::TableWrapper |
SpecificFragmentInfo::Multicol |
SpecificFragmentInfo::MulticolColumn |
SpecificFragmentInfo::InlineBlock(_) |
SpecificFragmentInfo::InlineAbsoluteHypothetical(_) |
SpecificFragmentInfo::InlineAbsolute(_) => Au(0),
SpecificFragmentInfo::Canvas(ref canvas_fragment_info) => {
canvas_fragment_info.replaced_image_fragment_info.computed_inline_size()
}
SpecificFragmentInfo::Svg(ref svg_fragment_info) => {
svg_fragment_info.replaced_image_fragment_info.computed_inline_size()
}
SpecificFragmentInfo::Image(ref image_fragment_info) => {
image_fragment_info.replaced_image_fragment_info.computed_inline_size()
}
SpecificFragmentInfo::ScannedText(ref text_fragment_info) => {
let (range, run) = (&text_fragment_info.range, &text_fragment_info.run);
let text_bounds = run.metrics_for_range(range).bounding_box;
text_bounds.size.width
}
SpecificFragmentInfo::TableColumn(_) => {
panic!("Table column fragments do not have inline_size")
}
SpecificFragmentInfo::UnscannedText(_) => {
panic!("Unscanned text fragments should have been scanned by now!")
}
}
}

/// Returns the dimensions of the content box.
///
/// This is marked `#[inline]` because it is frequently called when only one or two of the

0 comments on commit b1b17f1

Please sign in to comment.
You can’t perform that action at this time.