clippy: Fix warnings in components/layout (#31612)

* clippy: fix warnings in components/layout

* fix: formatting
This commit is contained in:
eri 2024-03-11 11:24:36 +01:00 committed by GitHub
parent 7f1ef4c7fe
commit a6e25d555b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 129 additions and 150 deletions

View file

@ -1761,7 +1761,7 @@ impl BlockFlow {
// If you remove the might_have_floats_in conditional, this will go off. // If you remove the might_have_floats_in conditional, this will go off.
// TODO(servo#30572) revert to debug_assert!() once underlying bug is fixed // TODO(servo#30572) revert to debug_assert!() once underlying bug is fixed
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
if !(!self.is_inline_flex_item()) { if self.is_inline_flex_item() {
log::warn!("debug assertion failed! !self.is_inline_flex_item()"); log::warn!("debug assertion failed! !self.is_inline_flex_item()");
} }

View file

@ -199,7 +199,7 @@ impl InlineBlockSplit {
fragment_accumulator, fragment_accumulator,
InlineFragmentsAccumulator::from_inline_node(node, style_context), InlineFragmentsAccumulator::from_inline_node(node, style_context),
) )
.to_intermediate_inline_fragments::<ConcreteThreadSafeLayoutNode>(style_context), .get_intermediate_inline_fragments::<ConcreteThreadSafeLayoutNode>(style_context),
flow, flow,
}; };
@ -305,7 +305,7 @@ impl InlineFragmentsAccumulator {
.push_descendants(fragments.absolute_descendants); .push_descendants(fragments.absolute_descendants);
} }
fn to_intermediate_inline_fragments<'dom, N>( fn get_intermediate_inline_fragments<'dom, N>(
self, self,
context: &SharedStyleContext, context: &SharedStyleContext,
) -> IntermediateInlineFragments ) -> IntermediateInlineFragments
@ -482,7 +482,9 @@ where
node: &ConcreteThreadSafeLayoutNode, node: &ConcreteThreadSafeLayoutNode,
) { ) {
let mut fragments = fragment_accumulator let mut fragments = fragment_accumulator
.to_intermediate_inline_fragments::<ConcreteThreadSafeLayoutNode>(self.style_context()); .get_intermediate_inline_fragments::<ConcreteThreadSafeLayoutNode>(
self.style_context(),
);
if fragments.is_empty() { if fragments.is_empty() {
return; return;
}; };
@ -1079,7 +1081,7 @@ where
ConstructionItem::InlineFragments(InlineFragmentsConstructionResult { ConstructionItem::InlineFragments(InlineFragmentsConstructionResult {
splits: opt_inline_block_splits, splits: opt_inline_block_splits,
fragments: fragment_accumulator fragments: fragment_accumulator
.to_intermediate_inline_fragments::<ConcreteThreadSafeLayoutNode>( .get_intermediate_inline_fragments::<ConcreteThreadSafeLayoutNode>(
self.style_context(), self.style_context(),
), ),
}); });
@ -1196,7 +1198,7 @@ where
ConstructionItem::InlineFragments(InlineFragmentsConstructionResult { ConstructionItem::InlineFragments(InlineFragmentsConstructionResult {
splits: LinkedList::new(), splits: LinkedList::new(),
fragments: fragment_accumulator fragments: fragment_accumulator
.to_intermediate_inline_fragments::<ConcreteThreadSafeLayoutNode>(context), .get_intermediate_inline_fragments::<ConcreteThreadSafeLayoutNode>(context),
}); });
ConstructionResult::ConstructionItem(construction_item) ConstructionResult::ConstructionItem(construction_item)
} }
@ -1246,7 +1248,7 @@ where
ConstructionItem::InlineFragments(InlineFragmentsConstructionResult { ConstructionItem::InlineFragments(InlineFragmentsConstructionResult {
splits: LinkedList::new(), splits: LinkedList::new(),
fragments: fragment_accumulator fragments: fragment_accumulator
.to_intermediate_inline_fragments::<ConcreteThreadSafeLayoutNode>( .get_intermediate_inline_fragments::<ConcreteThreadSafeLayoutNode>(
style_context, style_context,
), ),
}); });

View file

@ -55,6 +55,9 @@ pub fn malloc_size_of_persistent_local_context(ops: &mut MallocSizeOfOps) -> usi
}) })
} }
type WebrenderImageCache =
HashMap<(ServoUrl, UsePlaceholder), WebRenderImageInfo, BuildHasherDefault<FnvHasher>>;
/// Layout information shared among all workers. This must be thread-safe. /// Layout information shared among all workers. This must be thread-safe.
pub struct LayoutContext<'a> { pub struct LayoutContext<'a> {
/// The pipeline id of this LayoutContext. /// The pipeline id of this LayoutContext.
@ -73,11 +76,7 @@ pub struct LayoutContext<'a> {
pub font_cache_thread: Mutex<FontCacheThread>, pub font_cache_thread: Mutex<FontCacheThread>,
/// A cache of WebRender image info. /// A cache of WebRender image info.
pub webrender_image_cache: Arc< pub webrender_image_cache: Arc<RwLock<WebrenderImageCache>>,
RwLock<
HashMap<(ServoUrl, UsePlaceholder), WebRenderImageInfo, BuildHasherDefault<FnvHasher>>,
>,
>,
/// Paint worklets /// Paint worklets
pub registered_painters: &'a dyn RegisteredPainters, pub registered_painters: &'a dyn RegisteredPainters,

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#![allow(clippy::too_many_arguments)]
use app_units::Au; use app_units::Au;
use euclid::default::{Point2D, Rect, SideOffsets2D, Size2D}; use euclid::default::{Point2D, Rect, SideOffsets2D, Size2D};
use style::computed_values::background_attachment::single_value::T as BackgroundAttachment; use style::computed_values::background_attachment::single_value::T as BackgroundAttachment;

View file

@ -8,6 +8,8 @@
//! list building, as the actual painting does not happen here—only deciding *what* we're going to //! list building, as the actual painting does not happen here—only deciding *what* we're going to
//! paint. //! paint.
#![allow(clippy::too_many_arguments)]
use std::default::Default; use std::default::Default;
use std::sync::Arc; use std::sync::Arc;
use std::{f32, mem}; use std::{f32, mem};
@ -443,7 +445,7 @@ impl<'a> DisplayListBuildState<'a> {
let mut list = Vec::new(); let mut list = Vec::new();
let root_context = mem::replace(&mut self.root_stacking_context, StackingContext::root()); let root_context = mem::replace(&mut self.root_stacking_context, StackingContext::root());
self.to_display_list_for_stacking_context(&mut list, root_context); self.move_to_display_list_for_stacking_context(&mut list, root_context);
DisplayList { DisplayList {
list, list,
@ -451,7 +453,7 @@ impl<'a> DisplayListBuildState<'a> {
} }
} }
fn to_display_list_for_stacking_context( fn move_to_display_list_for_stacking_context(
&mut self, &mut self,
list: &mut Vec<DisplayItem>, list: &mut Vec<DisplayItem>,
stacking_context: StackingContext, stacking_context: StackingContext,
@ -473,7 +475,7 @@ impl<'a> DisplayListBuildState<'a> {
.into_iter() .into_iter()
.map(|index| index.to_define_item()), .map(|index| index.to_define_item()),
); );
self.to_display_list_for_items(list, child_items, info.children); self.move_to_display_list_for_items(list, child_items, info.children);
} else { } else {
let (push_item, pop_item) = stacking_context.to_display_list_items(); let (push_item, pop_item) = stacking_context.to_display_list_items();
list.push(push_item); list.push(push_item);
@ -482,12 +484,12 @@ impl<'a> DisplayListBuildState<'a> {
.into_iter() .into_iter()
.map(|index| index.to_define_item()), .map(|index| index.to_define_item()),
); );
self.to_display_list_for_items(list, child_items, info.children); self.move_to_display_list_for_items(list, child_items, info.children);
list.push(pop_item); list.push(pop_item);
} }
} }
fn to_display_list_for_items( fn move_to_display_list_for_items(
&mut self, &mut self,
list: &mut Vec<DisplayItem>, list: &mut Vec<DisplayItem>,
mut child_items: Vec<DisplayItem>, mut child_items: Vec<DisplayItem>,
@ -509,7 +511,7 @@ impl<'a> DisplayListBuildState<'a> {
.map_or(false, |child| child.z_index < 0) .map_or(false, |child| child.z_index < 0)
{ {
let context = child_stacking_contexts.next().unwrap(); let context = child_stacking_contexts.next().unwrap();
self.to_display_list_for_stacking_context(list, context); self.move_to_display_list_for_stacking_context(list, context);
} }
// Step 4: Block backgrounds and borders. // Step 4: Block backgrounds and borders.
@ -524,7 +526,7 @@ impl<'a> DisplayListBuildState<'a> {
child.context_type == StackingContextType::PseudoFloat child.context_type == StackingContextType::PseudoFloat
}) { }) {
let context = child_stacking_contexts.next().unwrap(); let context = child_stacking_contexts.next().unwrap();
self.to_display_list_for_stacking_context(list, context); self.move_to_display_list_for_stacking_context(list, context);
} }
// Step 6 & 7: Content and inlines that generate stacking contexts. // Step 6 & 7: Content and inlines that generate stacking contexts.
@ -536,7 +538,7 @@ impl<'a> DisplayListBuildState<'a> {
// Step 8 & 9: Positioned descendants with nonnegative, numeric z-indices. // Step 8 & 9: Positioned descendants with nonnegative, numeric z-indices.
for child in child_stacking_contexts { for child in child_stacking_contexts {
self.to_display_list_for_stacking_context(list, child); self.move_to_display_list_for_stacking_context(list, child);
} }
// Step 10: Outlines. // Step 10: Outlines.
@ -2642,10 +2644,10 @@ impl BlockFlow {
// The margins control which edges have sticky behavior. // The margins control which edges have sticky behavior.
let sticky_frame_data = StickyFrameData { let sticky_frame_data = StickyFrameData {
margins: SideOffsets2D::new( margins: SideOffsets2D::new(
sticky_position.top.to_option().map(|v| v.to_f32_px()), sticky_position.top.as_option().map(|v| v.to_f32_px()),
sticky_position.right.to_option().map(|v| v.to_f32_px()), sticky_position.right.as_option().map(|v| v.to_f32_px()),
sticky_position.bottom.to_option().map(|v| v.to_f32_px()), sticky_position.bottom.as_option().map(|v| v.to_f32_px()),
sticky_position.left.to_option().map(|v| v.to_f32_px()), sticky_position.left.as_option().map(|v| v.to_f32_px()),
), ),
vertical_offset_bounds, vertical_offset_bounds,
horizontal_offset_bounds, horizontal_offset_bounds,

View file

@ -12,6 +12,8 @@
//! They are therefore not exactly analogous to constructs like Skia pictures, which consist of //! They are therefore not exactly analogous to constructs like Skia pictures, which consist of
//! low-level drawing primitives. //! low-level drawing primitives.
#![allow(clippy::too_many_arguments)]
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::HashMap; use std::collections::HashMap;
use std::{f32, fmt}; use std::{f32, fmt};

View file

@ -250,7 +250,7 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static {
fn collect_stacking_contexts(&mut self, state: &mut StackingContextCollectionState); fn collect_stacking_contexts(&mut self, state: &mut StackingContextCollectionState);
/// If this is a float, places it. The default implementation does nothing. /// If this is a float, places it. The default implementation does nothing.
fn place_float_if_applicable<'a>(&mut self) {} fn place_float_if_applicable(&mut self) {}
/// Assigns block-sizes in-order; or, if this is a float, places the float. The default /// Assigns block-sizes in-order; or, if this is a float, places the float. The default
/// implementation simply assigns block-sizes if this flow might have floats in. Returns true /// implementation simply assigns block-sizes if this flow might have floats in. Returns true
@ -505,6 +505,7 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static {
} }
} }
#[allow(clippy::wrong_self_convention)]
pub trait ImmutableFlowUtils { pub trait ImmutableFlowUtils {
// Convenience functions // Convenience functions
@ -603,18 +604,18 @@ pub enum FlowClass {
impl FlowClass { impl FlowClass {
fn is_block_like(self) -> bool { fn is_block_like(self) -> bool {
match self { matches!(
self,
FlowClass::Block | FlowClass::Block |
FlowClass::ListItem | FlowClass::ListItem |
FlowClass::Table | FlowClass::Table |
FlowClass::TableRowGroup | FlowClass::TableRowGroup |
FlowClass::TableRow | FlowClass::TableRow |
FlowClass::TableCaption | FlowClass::TableCaption |
FlowClass::TableCell | FlowClass::TableCell |
FlowClass::TableWrapper | FlowClass::TableWrapper |
FlowClass::Flex => true, FlowClass::Flex
_ => false, )
}
} }
} }
@ -1232,50 +1233,32 @@ impl<'a> ImmutableFlowUtils for &'a dyn Flow {
/// Returns true if this flow is a table row flow. /// Returns true if this flow is a table row flow.
fn is_table_row(self) -> bool { fn is_table_row(self) -> bool {
match self.class() { matches!(self.class(), FlowClass::TableRow)
FlowClass::TableRow => true,
_ => false,
}
} }
/// Returns true if this flow is a table cell flow. /// Returns true if this flow is a table cell flow.
fn is_table_cell(self) -> bool { fn is_table_cell(self) -> bool {
match self.class() { matches!(self.class(), FlowClass::TableCell)
FlowClass::TableCell => true,
_ => false,
}
} }
/// Returns true if this flow is a table colgroup flow. /// Returns true if this flow is a table colgroup flow.
fn is_table_colgroup(self) -> bool { fn is_table_colgroup(self) -> bool {
match self.class() { matches!(self.class(), FlowClass::TableColGroup)
FlowClass::TableColGroup => true,
_ => false,
}
} }
/// Returns true if this flow is a table flow. /// Returns true if this flow is a table flow.
fn is_table(self) -> bool { fn is_table(self) -> bool {
match self.class() { matches!(self.class(), FlowClass::Table)
FlowClass::Table => true,
_ => false,
}
} }
/// Returns true if this flow is a table caption flow. /// Returns true if this flow is a table caption flow.
fn is_table_caption(self) -> bool { fn is_table_caption(self) -> bool {
match self.class() { matches!(self.class(), FlowClass::TableCaption)
FlowClass::TableCaption => true,
_ => false,
}
} }
/// Returns true if this flow is a table rowgroup flow. /// Returns true if this flow is a table rowgroup flow.
fn is_table_rowgroup(self) -> bool { fn is_table_rowgroup(self) -> bool {
match self.class() { matches!(self.class(), FlowClass::TableRowGroup)
FlowClass::TableRowGroup => true,
_ => false,
}
} }
/// Returns the number of children that this flow possesses. /// Returns the number of children that this flow possesses.
@ -1285,18 +1268,12 @@ impl<'a> ImmutableFlowUtils for &'a dyn Flow {
/// Returns true if this flow is a block flow. /// Returns true if this flow is a block flow.
fn is_block_flow(self) -> bool { fn is_block_flow(self) -> bool {
match self.class() { matches!(self.class(), FlowClass::Block)
FlowClass::Block => true,
_ => false,
}
} }
/// Returns true if this flow is an inline flow. /// Returns true if this flow is an inline flow.
fn is_inline_flow(self) -> bool { fn is_inline_flow(self) -> bool {
match self.class() { matches!(self.class(), FlowClass::Inline)
FlowClass::Inline => true,
_ => false,
}
} }
/// Dumps the flow tree for debugging. /// Dumps the flow tree for debugging.
@ -1392,7 +1369,7 @@ impl MutableOwnedFlowUtils for FlowRef {
for descendant_link in abs_descendants.descendant_links.iter_mut() { for descendant_link in abs_descendants.descendant_links.iter_mut() {
// TODO(servo#30573) revert to debug_assert!() once underlying bug is fixed // TODO(servo#30573) revert to debug_assert!() once underlying bug is fixed
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
if !(!descendant_link.has_reached_containing_block) { if descendant_link.has_reached_containing_block {
log::warn!("debug assertion failed! !descendant_link.has_reached_containing_block"); log::warn!("debug assertion failed! !descendant_link.has_reached_containing_block");
} }
let descendant_base = FlowRef::deref_mut(&mut descendant_link.flow).mut_base(); let descendant_base = FlowRef::deref_mut(&mut descendant_link.flow).mut_base();

View file

@ -49,6 +49,7 @@ impl FlowRef {
/// See <https://github.com/servo/servo/issues/6503>. /// See <https://github.com/servo/servo/issues/6503>.
/// Use Arc::get_mut instead when possible (e.g. on an Arc that was just created). /// Use Arc::get_mut instead when possible (e.g. on an Arc that was just created).
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[allow(clippy::should_implement_trait)]
pub fn deref_mut(this: &mut FlowRef) -> &mut dyn Flow { pub fn deref_mut(this: &mut FlowRef) -> &mut dyn Flow {
let ptr: *const dyn Flow = &*this.0; let ptr: *const dyn Flow = &*this.0;
unsafe { &mut *(ptr as *mut dyn Flow) } unsafe { &mut *(ptr as *mut dyn Flow) }

View file

@ -1592,9 +1592,8 @@ impl Fragment {
/// Returns true if and only if this fragment is a generated content fragment. /// Returns true if and only if this fragment is a generated content fragment.
pub fn is_unscanned_generated_content(&self) -> bool { pub fn is_unscanned_generated_content(&self) -> bool {
match self.specific { match self.specific {
SpecificFragmentInfo::GeneratedContent(ref content) => match **content { SpecificFragmentInfo::GeneratedContent(ref content) => {
GeneratedContentInfo::Empty => false, !matches!(**content, GeneratedContentInfo::Empty)
_ => true,
}, },
_ => false, _ => false,
} }
@ -1602,10 +1601,7 @@ impl Fragment {
/// Returns true if and only if this is a scanned text fragment. /// Returns true if and only if this is a scanned text fragment.
pub fn is_scanned_text_fragment(&self) -> bool { pub fn is_scanned_text_fragment(&self) -> bool {
match self.specific { matches!(self.specific, SpecificFragmentInfo::ScannedText(..))
SpecificFragmentInfo::ScannedText(..) => true,
_ => false,
}
} }
pub fn suppress_line_break_before(&self) -> bool { pub fn suppress_line_break_before(&self) -> bool {
@ -1972,8 +1968,8 @@ impl Fragment {
// see if we're going to overflow the line. If so, perform a best-effort split. // see if we're going to overflow the line. If so, perform a best-effort split.
let mut remaining_range = slice.text_run_range(); let mut remaining_range = slice.text_run_range();
let split_is_empty = inline_start_range.is_empty() && let split_is_empty = inline_start_range.is_empty() &&
!(self.requires_line_break_afterward_if_wrapping_on_newlines() && (self.white_space().allow_wrap() ||
!self.white_space().allow_wrap()); !self.requires_line_break_afterward_if_wrapping_on_newlines());
if split_is_empty { if split_is_empty {
// We're going to overflow the line. // We're going to overflow the line.
overflowing = true; overflowing = true;
@ -2259,14 +2255,14 @@ impl Fragment {
/// Returns true if this fragment is replaced content. /// Returns true if this fragment is replaced content.
pub fn is_replaced(&self) -> bool { pub fn is_replaced(&self) -> bool {
match self.specific { matches!(
self.specific,
SpecificFragmentInfo::Iframe(_) | SpecificFragmentInfo::Iframe(_) |
SpecificFragmentInfo::Canvas(_) | SpecificFragmentInfo::Canvas(_) |
SpecificFragmentInfo::Image(_) | SpecificFragmentInfo::Image(_) |
SpecificFragmentInfo::Media(_) | SpecificFragmentInfo::Media(_) |
SpecificFragmentInfo::Svg(_) => true, SpecificFragmentInfo::Svg(_)
_ => false, )
}
} }
/// Returns true if this fragment is replaced content or an inline-block or false otherwise. /// Returns true if this fragment is replaced content or an inline-block or false otherwise.
@ -2507,10 +2503,10 @@ impl Fragment {
/// Returns true if this fragment is a hypothetical box. See CSS 2.1 § 10.3.7. /// Returns true if this fragment is a hypothetical box. See CSS 2.1 § 10.3.7.
pub fn is_hypothetical(&self) -> bool { pub fn is_hypothetical(&self) -> bool {
match self.specific { matches!(
SpecificFragmentInfo::InlineAbsoluteHypothetical(_) => true, self.specific,
_ => false, SpecificFragmentInfo::InlineAbsoluteHypothetical(_)
} )
} }
/// Returns true if this fragment can merge with another immediately-following fragment or /// Returns true if this fragment can merge with another immediately-following fragment or
@ -3069,10 +3065,7 @@ impl Fragment {
} }
pub fn is_inline_absolute(&self) -> bool { pub fn is_inline_absolute(&self) -> bool {
match self.specific { matches!(self.specific, SpecificFragmentInfo::InlineAbsolute(..))
SpecificFragmentInfo::InlineAbsolute(..) => true,
_ => false,
}
} }
pub fn meld_with_next_inline_fragment(&mut self, next_fragment: &Fragment) { pub fn meld_with_next_inline_fragment(&mut self, next_fragment: &Fragment) {
@ -3141,11 +3134,11 @@ impl Fragment {
/// `vertical-align` set to `top` or `bottom`. /// `vertical-align` set to `top` or `bottom`.
pub fn is_vertically_aligned_to_top_or_bottom(&self) -> bool { pub fn is_vertically_aligned_to_top_or_bottom(&self) -> bool {
fn is_top_or_bottom(v: &VerticalAlign) -> bool { fn is_top_or_bottom(v: &VerticalAlign) -> bool {
match *v { matches!(
*v,
VerticalAlign::Keyword(VerticalAlignKeyword::Top) | VerticalAlign::Keyword(VerticalAlignKeyword::Top) |
VerticalAlign::Keyword(VerticalAlignKeyword::Bottom) => true, VerticalAlign::Keyword(VerticalAlignKeyword::Bottom)
_ => false, )
}
} }
if is_top_or_bottom(&self.style.get_box().vertical_align) { if is_top_or_bottom(&self.style.get_box().vertical_align) {

View file

@ -307,7 +307,7 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> {
} }
// Truncate down counters. // Truncate down counters.
for (_, counter) in &mut self.traversal.counters { for counter in self.traversal.counters.values_mut() {
counter.truncate_to_level(self.level); counter.truncate_to_level(self.level);
} }
self.traversal.list_item.truncate_to_level(self.level); self.traversal.list_item.truncate_to_level(self.level);

View file

@ -478,7 +478,7 @@ impl MaybeAuto {
} }
#[inline] #[inline]
pub fn to_option(&self) -> Option<Au> { pub fn as_option(&self) -> Option<Au> {
match *self { match *self {
MaybeAuto::Specified(value) => Some(value), MaybeAuto::Specified(value) => Some(value),
MaybeAuto::Auto => None, MaybeAuto::Auto => None,

View file

@ -35,8 +35,9 @@ pub struct UnsafeFlow(*const dyn Flow);
unsafe impl Sync for UnsafeFlow {} unsafe impl Sync for UnsafeFlow {}
unsafe impl Send for UnsafeFlow {} unsafe impl Send for UnsafeFlow {}
impl PartialEq for UnsafeFlow { impl PartialEq for UnsafeFlow {
#[allow(clippy::ptr_eq)]
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
// Compare the pointers explicitly to avoid clippy lint // Compare the pointers explicitly to avoid a clippy error
self.0 as *const u8 == other.0 as *const u8 self.0 as *const u8 == other.0 as *const u8
} }
} }

View file

@ -988,10 +988,10 @@ fn process_resolved_style_request_internal<'dom>(
}, },
}; };
let positioned = match style.get_box().position { let positioned = matches!(
Position::Relative | Position::Sticky | Position::Fixed | Position::Absolute => true, style.get_box().position,
_ => false, Position::Relative | Position::Sticky | Position::Fixed | Position::Absolute
}; );
//TODO: determine whether requested property applies to the element. //TODO: determine whether requested property applies to the element.
// eg. width does not apply to non-replaced inline elements. // eg. width does not apply to non-replaced inline elements.

View file

@ -37,7 +37,7 @@ use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use crate::model::{IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto}; use crate::model::{IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto};
use crate::table_cell::TableCellFlow; use crate::table_cell::TableCellFlow;
use crate::table_row::{ use crate::table_row::{
self, CellIntrinsicInlineSize, CollapsedBorder, CollapsedBorderProvenance, TableRowFlow, self, CellIntrinsicInlineSize, CollapsedBorder, CollapsedBorderFrom, TableRowFlow,
TableRowSizeData, TableRowSizeData,
}; };
use crate::table_wrapper::TableLayout; use crate::table_wrapper::TableLayout;
@ -339,11 +339,11 @@ impl Flow for TableFlow {
Some(TableInlineCollapsedBorders { Some(TableInlineCollapsedBorders {
start: CollapsedBorder::inline_start( start: CollapsedBorder::inline_start(
&self.block_flow.fragment.style, &self.block_flow.fragment.style,
CollapsedBorderProvenance::FromTable, CollapsedBorderFrom::Table,
), ),
end: CollapsedBorder::inline_end( end: CollapsedBorder::inline_end(
&self.block_flow.fragment.style, &self.block_flow.fragment.style,
CollapsedBorderProvenance::FromTable, CollapsedBorderFrom::Table,
), ),
}) })
} else { } else {
@ -354,7 +354,7 @@ impl Flow for TableFlow {
let mut previous_collapsed_block_end_borders = let mut previous_collapsed_block_end_borders =
PreviousBlockCollapsedBorders::FromTable(CollapsedBorder::block_start( PreviousBlockCollapsedBorders::FromTable(CollapsedBorder::block_start(
&self.block_flow.fragment.style, &self.block_flow.fragment.style,
CollapsedBorderProvenance::FromTable, CollapsedBorderFrom::Table,
)); ));
let mut first_row = true; let mut first_row = true;
let (border_padding, _) = self.block_flow.fragment.surrounding_intrinsic_inline_size(); let (border_padding, _) = self.block_flow.fragment.surrounding_intrinsic_inline_size();
@ -381,7 +381,7 @@ impl Flow for TableFlow {
), ),
None => NextBlockCollapsedBorders::FromTable(CollapsedBorder::block_end( None => NextBlockCollapsedBorders::FromTable(CollapsedBorder::block_end(
&self.block_flow.fragment.style, &self.block_flow.fragment.style,
CollapsedBorderProvenance::FromTable, CollapsedBorderFrom::Table,
)), )),
}; };
perform_border_collapse_for_row( perform_border_collapse_for_row(

View file

@ -27,7 +27,7 @@ use crate::display_list::{
use crate::flow::{Flow, FlowClass, FlowFlags, GetBaseFlow, OpaqueFlow}; use crate::flow::{Flow, FlowClass, FlowFlags, GetBaseFlow, OpaqueFlow};
use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use crate::table::InternalTable; use crate::table::InternalTable;
use crate::table_row::{CollapsedBorder, CollapsedBorderProvenance}; use crate::table_row::{CollapsedBorder, CollapsedBorderFrom};
use crate::{layout_debug, layout_debug_scope}; use crate::{layout_debug, layout_debug_scope};
#[allow(unsafe_code)] #[allow(unsafe_code)]
@ -406,19 +406,19 @@ impl CollapsedBordersForCell {
} }
fn should_paint_inline_start_border(&self) -> bool { fn should_paint_inline_start_border(&self) -> bool {
self.inline_start_border.provenance != CollapsedBorderProvenance::FromPreviousTableCell self.inline_start_border.provenance != CollapsedBorderFrom::PreviousTableCell
} }
fn should_paint_inline_end_border(&self) -> bool { fn should_paint_inline_end_border(&self) -> bool {
self.inline_end_border.provenance != CollapsedBorderProvenance::FromNextTableCell self.inline_end_border.provenance != CollapsedBorderFrom::NextTableCell
} }
fn should_paint_block_start_border(&self) -> bool { fn should_paint_block_start_border(&self) -> bool {
self.block_start_border.provenance != CollapsedBorderProvenance::FromPreviousTableCell self.block_start_border.provenance != CollapsedBorderFrom::PreviousTableCell
} }
fn should_paint_block_end_border(&self) -> bool { fn should_paint_block_end_border(&self) -> bool {
self.block_end_border.provenance != CollapsedBorderProvenance::FromNextTableCell self.block_end_border.provenance != CollapsedBorderFrom::NextTableCell
} }
pub fn adjust_border_widths_for_painting(&self, border_widths: &mut LogicalMargin<Au>) { pub fn adjust_border_widths_for_painting(&self, border_widths: &mut LogicalMargin<Au>) {

View file

@ -4,6 +4,8 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
#![allow(clippy::too_many_arguments)]
use std::cmp::max; use std::cmp::max;
use std::fmt; use std::fmt;
use std::iter::{Enumerate, Peekable}; use std::iter::{Enumerate, Peekable};
@ -123,7 +125,7 @@ impl TableRowFlow {
fn include_sizes_from_previous_rows( fn include_sizes_from_previous_rows(
col: &mut usize, col: &mut usize,
incoming_rowspan: &[u32], incoming_rowspan: &[u32],
incoming_rowspan_data: &mut Vec<Au>, incoming_rowspan_data: &mut [Au],
max_block_size: &mut Au, max_block_size: &mut Au,
) { ) {
while let Some(span) = incoming_rowspan.get(*col) { while let Some(span) = incoming_rowspan.get(*col) {
@ -390,7 +392,7 @@ impl Flow for TableRowFlow {
self.preliminary_collapsed_borders self.preliminary_collapsed_borders
.reset(CollapsedBorder::inline_start( .reset(CollapsedBorder::inline_start(
row_style, row_style,
CollapsedBorderProvenance::FromTableRow, CollapsedBorderFrom::TableRow,
)); ));
{ {
@ -736,7 +738,7 @@ pub struct CollapsedBorder {
/// The color of the border. /// The color of the border.
pub color: Color, pub color: Color,
/// The type of item that this border comes from. /// The type of item that this border comes from.
pub provenance: CollapsedBorderProvenance, pub provenance: CollapsedBorderFrom,
} }
impl Serialize for CollapsedBorder { impl Serialize for CollapsedBorder {
@ -753,14 +755,14 @@ impl Serialize for CollapsedBorder {
// FromTableColumnGroup are unused // FromTableColumnGroup are unused
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Clone, Copy, Debug, PartialEq, Serialize)] #[derive(Clone, Copy, Debug, PartialEq, Serialize)]
pub enum CollapsedBorderProvenance { pub enum CollapsedBorderFrom {
FromPreviousTableCell = 6, PreviousTableCell = 6,
FromNextTableCell = 5, NextTableCell = 5,
FromTableRow = 4, TableRow = 4,
FromTableRowGroup = 3, TableRowGroup = 3,
FromTableColumn = 2, TableColumn = 2,
FromTableColumnGroup = 1, TableColumnGroup = 1,
FromTable = 0, Table = 0,
} }
impl CollapsedBorder { impl CollapsedBorder {
@ -770,13 +772,13 @@ impl CollapsedBorder {
style: BorderStyle::None, style: BorderStyle::None,
width: Au(0), width: Au(0),
color: Color::transparent(), color: Color::transparent(),
provenance: CollapsedBorderProvenance::FromTable, provenance: CollapsedBorderFrom::Table,
} }
} }
/// Creates a collapsed border from the block-start border described in the given CSS style /// Creates a collapsed border from the block-start border described in the given CSS style
/// object. /// object.
fn top(css_style: &ComputedValues, provenance: CollapsedBorderProvenance) -> CollapsedBorder { fn top(css_style: &ComputedValues, provenance: CollapsedBorderFrom) -> CollapsedBorder {
CollapsedBorder { CollapsedBorder {
style: css_style.get_border().border_top_style, style: css_style.get_border().border_top_style,
width: css_style.get_border().border_top_width, width: css_style.get_border().border_top_width,
@ -787,7 +789,7 @@ impl CollapsedBorder {
/// Creates a collapsed border style from the right border described in the given CSS style /// Creates a collapsed border style from the right border described in the given CSS style
/// object. /// object.
fn right(css_style: &ComputedValues, provenance: CollapsedBorderProvenance) -> CollapsedBorder { fn right(css_style: &ComputedValues, provenance: CollapsedBorderFrom) -> CollapsedBorder {
CollapsedBorder { CollapsedBorder {
style: css_style.get_border().border_right_style, style: css_style.get_border().border_right_style,
width: css_style.get_border().border_right_width, width: css_style.get_border().border_right_width,
@ -798,10 +800,7 @@ impl CollapsedBorder {
/// Creates a collapsed border style from the bottom border described in the given CSS style /// Creates a collapsed border style from the bottom border described in the given CSS style
/// object. /// object.
fn bottom( fn bottom(css_style: &ComputedValues, provenance: CollapsedBorderFrom) -> CollapsedBorder {
css_style: &ComputedValues,
provenance: CollapsedBorderProvenance,
) -> CollapsedBorder {
CollapsedBorder { CollapsedBorder {
style: css_style.get_border().border_bottom_style, style: css_style.get_border().border_bottom_style,
width: css_style.get_border().border_bottom_width, width: css_style.get_border().border_bottom_width,
@ -812,7 +811,7 @@ impl CollapsedBorder {
/// Creates a collapsed border style from the left border described in the given CSS style /// Creates a collapsed border style from the left border described in the given CSS style
/// object. /// object.
fn left(css_style: &ComputedValues, provenance: CollapsedBorderProvenance) -> CollapsedBorder { fn left(css_style: &ComputedValues, provenance: CollapsedBorderFrom) -> CollapsedBorder {
CollapsedBorder { CollapsedBorder {
style: css_style.get_border().border_left_style, style: css_style.get_border().border_left_style,
width: css_style.get_border().border_left_width, width: css_style.get_border().border_left_width,
@ -825,7 +824,7 @@ impl CollapsedBorder {
fn from_side( fn from_side(
side: PhysicalSide, side: PhysicalSide,
css_style: &ComputedValues, css_style: &ComputedValues,
provenance: CollapsedBorderProvenance, provenance: CollapsedBorderFrom,
) -> CollapsedBorder { ) -> CollapsedBorder {
match side { match side {
PhysicalSide::Top => CollapsedBorder::top(css_style, provenance), PhysicalSide::Top => CollapsedBorder::top(css_style, provenance),
@ -839,7 +838,7 @@ impl CollapsedBorder {
/// style object. /// style object.
pub fn inline_start( pub fn inline_start(
css_style: &ComputedValues, css_style: &ComputedValues,
provenance: CollapsedBorderProvenance, provenance: CollapsedBorderFrom,
) -> CollapsedBorder { ) -> CollapsedBorder {
CollapsedBorder::from_side( CollapsedBorder::from_side(
css_style.writing_mode.inline_start_physical_side(), css_style.writing_mode.inline_start_physical_side(),
@ -852,7 +851,7 @@ impl CollapsedBorder {
/// style object. /// style object.
pub fn inline_end( pub fn inline_end(
css_style: &ComputedValues, css_style: &ComputedValues,
provenance: CollapsedBorderProvenance, provenance: CollapsedBorderFrom,
) -> CollapsedBorder { ) -> CollapsedBorder {
CollapsedBorder::from_side( CollapsedBorder::from_side(
css_style.writing_mode.inline_end_physical_side(), css_style.writing_mode.inline_end_physical_side(),
@ -865,7 +864,7 @@ impl CollapsedBorder {
/// style object. /// style object.
pub fn block_start( pub fn block_start(
css_style: &ComputedValues, css_style: &ComputedValues,
provenance: CollapsedBorderProvenance, provenance: CollapsedBorderFrom,
) -> CollapsedBorder { ) -> CollapsedBorder {
CollapsedBorder::from_side( CollapsedBorder::from_side(
css_style.writing_mode.block_start_physical_side(), css_style.writing_mode.block_start_physical_side(),
@ -878,7 +877,7 @@ impl CollapsedBorder {
/// object. /// object.
pub fn block_end( pub fn block_end(
css_style: &ComputedValues, css_style: &ComputedValues,
provenance: CollapsedBorderProvenance, provenance: CollapsedBorderFrom,
) -> CollapsedBorder { ) -> CollapsedBorder {
CollapsedBorder::from_side( CollapsedBorder::from_side(
css_style.writing_mode.block_end_physical_side(), css_style.writing_mode.block_end_physical_side(),
@ -1120,7 +1119,7 @@ fn perform_inline_direction_border_collapse_for_row(
let first_inline_border = &mut preliminary_collapsed_borders.inline[0]; let first_inline_border = &mut preliminary_collapsed_borders.inline[0];
first_inline_border.combine(&CollapsedBorder::inline_start( first_inline_border.combine(&CollapsedBorder::inline_start(
&child_table_cell.block_flow.fragment.style, &child_table_cell.block_flow.fragment.style,
CollapsedBorderProvenance::FromNextTableCell, CollapsedBorderFrom::NextTableCell,
)); ));
} }
@ -1128,7 +1127,7 @@ fn perform_inline_direction_border_collapse_for_row(
child_index + 1, child_index + 1,
CollapsedBorder::inline_end( CollapsedBorder::inline_end(
&child_table_cell.block_flow.fragment.style, &child_table_cell.block_flow.fragment.style,
CollapsedBorderProvenance::FromPreviousTableCell, CollapsedBorderFrom::PreviousTableCell,
), ),
); );
@ -1136,7 +1135,7 @@ fn perform_inline_direction_border_collapse_for_row(
let next_child_flow = next_child_flow.as_block(); let next_child_flow = next_child_flow.as_block();
inline_collapsed_border.combine(&CollapsedBorder::inline_start( inline_collapsed_border.combine(&CollapsedBorder::inline_start(
&next_child_flow.fragment.style, &next_child_flow.fragment.style,
CollapsedBorderProvenance::FromNextTableCell, CollapsedBorderFrom::NextTableCell,
)) ))
}; };
@ -1145,28 +1144,28 @@ fn perform_inline_direction_border_collapse_for_row(
if child_index + 1 == children_count { if child_index + 1 == children_count {
inline_collapsed_border.combine(&CollapsedBorder::inline_end( inline_collapsed_border.combine(&CollapsedBorder::inline_end(
row_style, row_style,
CollapsedBorderProvenance::FromTableRow, CollapsedBorderFrom::TableRow,
)); ));
} }
let mut block_start_border = CollapsedBorder::block_start( let mut block_start_border = CollapsedBorder::block_start(
&child_table_cell.block_flow.fragment.style, &child_table_cell.block_flow.fragment.style,
CollapsedBorderProvenance::FromNextTableCell, CollapsedBorderFrom::NextTableCell,
); );
block_start_border.combine(&CollapsedBorder::block_start( block_start_border.combine(&CollapsedBorder::block_start(
row_style, row_style,
CollapsedBorderProvenance::FromTableRow, CollapsedBorderFrom::TableRow,
)); ));
preliminary_collapsed_borders preliminary_collapsed_borders
.block_start .block_start
.push_or_set(child_index, block_start_border); .push_or_set(child_index, block_start_border);
let mut block_end_border = CollapsedBorder::block_end( let mut block_end_border = CollapsedBorder::block_end(
&child_table_cell.block_flow.fragment.style, &child_table_cell.block_flow.fragment.style,
CollapsedBorderProvenance::FromPreviousTableCell, CollapsedBorderFrom::PreviousTableCell,
); );
block_end_border.combine(&CollapsedBorder::block_end( block_end_border.combine(&CollapsedBorder::block_end(
row_style, row_style,
CollapsedBorderProvenance::FromTableRow, CollapsedBorderFrom::TableRow,
)); ));
preliminary_collapsed_borders preliminary_collapsed_borders

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Text layout. //! Text layout.
#![allow(clippy::too_many_arguments)]
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::collections::LinkedList; use std::collections::LinkedList;
@ -483,10 +484,10 @@ impl TextRunScanner {
SpecificFragmentInfo::ScannedText(new_text_fragment_info), SpecificFragmentInfo::ScannedText(new_text_fragment_info),
); );
let is_last_mapping_of_this_old_fragment = match mappings.peek() { let is_last_mapping_of_this_old_fragment = !matches!(
Some(mapping) if mapping.old_fragment_index == logical_offset => false, mappings.peek(),
_ => true, Some(mapping) if mapping.old_fragment_index == logical_offset
}; );
if let Some(ref mut context) = new_fragment.inline_context { if let Some(ref mut context) = new_fragment.inline_context {
for node in &mut context.nodes { for node in &mut context.nodes {