mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
layout: Make IndependentFormattingContext::contents
private (again) (#38350)
This was done in #24871, but after some refactorings it became public.
This makes it private again. As said in
b2b3ea992c
:
> Privacy forces the rest of the code to go through methods
> rather than matching on the enum,
> reducing accidental layout-mode-specific behavior.
It also avoids the risk of accidentally calling `layout()` on the inner
layout-mode-specific struct, bypassing caching.
Testing: Not needed (no behavior change)
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
8c737a6a79
commit
c7c33f5f47
5 changed files with 34 additions and 32 deletions
|
@ -34,7 +34,9 @@ use crate::{
|
|||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) struct IndependentFormattingContext {
|
||||
pub base: LayoutBoxBase,
|
||||
pub contents: IndependentFormattingContextContents,
|
||||
// Private so that code outside of this module cannot match variants.
|
||||
// It should go through methods instead.
|
||||
contents: IndependentFormattingContextContents,
|
||||
}
|
||||
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
|
@ -65,6 +67,10 @@ impl Baselines {
|
|||
}
|
||||
|
||||
impl IndependentFormattingContext {
|
||||
pub(crate) fn new(base: LayoutBoxBase, contents: IndependentFormattingContextContents) -> Self {
|
||||
Self { base, contents }
|
||||
}
|
||||
|
||||
pub fn construct(
|
||||
context: &LayoutContext,
|
||||
node_and_style_info: &NodeAndStyleInfo,
|
||||
|
@ -139,13 +145,6 @@ impl IndependentFormattingContext {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_replaced(&self) -> bool {
|
||||
matches!(
|
||||
self.contents,
|
||||
IndependentFormattingContextContents::Replaced(_)
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn style(&self) -> &Arc<ComputedValues> {
|
||||
&self.base.style
|
||||
|
@ -238,6 +237,19 @@ impl IndependentFormattingContext {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn is_block_container(&self) -> bool {
|
||||
matches!(self.contents, IndependentFormattingContextContents::Flow(_))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn is_replaced(&self) -> bool {
|
||||
matches!(
|
||||
self.contents,
|
||||
IndependentFormattingContextContents::Replaced(_)
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn is_table(&self) -> bool {
|
||||
matches!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue