aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <nox@nox.paris>2020-06-10 14:23:55 +0200
committerAnthony Ramine <nox@nox.paris>2020-06-15 18:09:15 +0200
commitb53959d23d54e3a30a4c9d01ab2eb5b605d2579c (patch)
tree1dd366929820626062c9e577692da9f7f299b7d7
parentb66dd66403f990db1a287ea70841194aa388a519 (diff)
downloadservo-b53959d23d54e3a30a4c9d01ab2eb5b605d2579c.tar.gz
servo-b53959d23d54e3a30a4c9d01ab2eb5b605d2579c.zip
Move IndependentFormattingContext::as_replaced to IndependentFormattingContextContents
-rw-r--r--components/layout_2020/flow/inline.rs2
-rw-r--r--components/layout_2020/flow/mod.rs14
-rw-r--r--components/layout_2020/formatting_contexts.rs31
-rw-r--r--components/layout_2020/positioned.rs4
4 files changed, 32 insertions, 19 deletions
diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs
index ccb7d3caf39..4736cb27203 100644
--- a/components/layout_2020/flow/inline.rs
+++ b/components/layout_2020/flow/inline.rs
@@ -556,7 +556,7 @@ fn layout_atomic(
start_corner += &relative_adjustement(&atomic.style, ifc.containing_block)
}
- let fragment = match atomic.as_replaced() {
+ let fragment = match atomic.contents.as_replaced() {
Ok(replaced) => {
let size =
replaced.used_size_as_if_inline_element(ifc.containing_block, &atomic.style, &pbm);
diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs
index f3dbbc19e9c..2056a1bab15 100644
--- a/components/layout_2020/flow/mod.rs
+++ b/components/layout_2020/flow/mod.rs
@@ -288,24 +288,24 @@ impl BlockLevelBox {
)
},
)),
- BlockLevelBox::Independent(contents) => {
+ BlockLevelBox::Independent(independent) => {
Fragment::Box(positioning_context.layout_maybe_position_relative_fragment(
layout_context,
containing_block,
- &contents.style,
- |positioning_context| match contents.as_replaced() {
+ &independent.style,
+ |positioning_context| match independent.contents.as_replaced() {
Ok(replaced) => layout_in_flow_replaced_block_level(
containing_block,
- contents.tag,
- &contents.style,
+ independent.tag,
+ &independent.style,
replaced,
),
Err(non_replaced) => layout_in_flow_non_replaced_block_level(
layout_context,
positioning_context,
containing_block,
- contents.tag,
- &contents.style,
+ independent.tag,
+ &independent.style,
NonReplacedContents::EstablishesAnIndependentFormattingContext(
non_replaced,
),
diff --git a/components/layout_2020/formatting_contexts.rs b/components/layout_2020/formatting_contexts.rs
index 189ec36cb9a..d4c32e896cb 100644
--- a/components/layout_2020/formatting_contexts.rs
+++ b/components/layout_2020/formatting_contexts.rs
@@ -28,7 +28,7 @@ pub(crate) struct IndependentFormattingContext {
/// If it was requested during construction
pub content_sizes: BoxContentSizes,
- contents: IndependentFormattingContextContents,
+ pub contents: IndependentFormattingContextContents,
}
pub(crate) struct IndependentLayout {
@@ -38,10 +38,13 @@ pub(crate) struct IndependentLayout {
pub content_block_size: Length,
}
+#[derive(Debug, Serialize)]
+pub(crate) struct IndependentFormattingContextContents(IndependentFormattingContextContentsKind);
+
// Private so that code outside of this module cannot match variants.
// It should got through methods instead.
#[derive(Debug, Serialize)]
-enum IndependentFormattingContextContents {
+enum IndependentFormattingContextContentsKind {
Flow(BlockFormattingContext),
Flex(FlexContainer),
@@ -80,7 +83,9 @@ impl IndependentFormattingContext {
tag: Tag::from_node_and_style_info(info),
style: Arc::clone(&info.style),
content_sizes,
- contents: IndependentFormattingContextContents::Flow(bfc),
+ contents: IndependentFormattingContextContents(
+ IndependentFormattingContextContentsKind::Flow(bfc),
+ ),
}
},
DisplayInside::Flex => {
@@ -95,7 +100,9 @@ impl IndependentFormattingContext {
tag: Tag::from_node_and_style_info(info),
style: Arc::clone(&info.style),
content_sizes,
- contents: IndependentFormattingContextContents::Flex(fc),
+ contents: IndependentFormattingContextContents(
+ IndependentFormattingContextContentsKind::Flex(fc),
+ ),
}
},
},
@@ -106,7 +113,9 @@ impl IndependentFormattingContext {
tag: Tag::from_node_and_style_info(info),
style: Arc::clone(&info.style),
content_sizes,
- contents: IndependentFormattingContextContents::Replaced(replaced),
+ contents: IndependentFormattingContextContents(
+ IndependentFormattingContextContentsKind::Replaced(replaced),
+ ),
}
},
}
@@ -129,15 +138,19 @@ impl IndependentFormattingContext {
tag: Tag::from_node_and_style_info(info),
style: Arc::clone(&info.style),
content_sizes,
- contents: IndependentFormattingContextContents::Flow(bfc),
+ contents: IndependentFormattingContextContents(
+ IndependentFormattingContextContentsKind::Flow(bfc),
+ ),
}
}
+}
- pub fn as_replaced(&self) -> Result<&ReplacedContent, NonReplacedIFC> {
- use self::IndependentFormattingContextContents as Contents;
+impl IndependentFormattingContextContents {
+ pub fn as_replaced(&self) -> Result<&ReplacedContent, NonReplacedIFC<'_>> {
+ use self::IndependentFormattingContextContentsKind as Contents;
use self::NonReplacedIFC as NR;
use self::NonReplacedIFCKind as Kind;
- match &self.contents {
+ match &self.0 {
Contents::Replaced(r) => Ok(r),
Contents::Flow(f) => Err(NR(Kind::Flow(f))),
Contents::Flex(f) => Err(NR(Kind::Flex(f))),
diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs
index 838a36febe9..ca46f65cc2f 100644
--- a/components/layout_2020/positioned.rs
+++ b/components/layout_2020/positioned.rs
@@ -422,7 +422,7 @@ impl HoistedAbsolutelyPositionedBox {
let size;
let replaced_used_size;
- match absolutely_positioned_box.context.as_replaced() {
+ match absolutely_positioned_box.context.contents.as_replaced() {
Ok(replaced) => {
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-width
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-height
@@ -474,7 +474,7 @@ impl HoistedAbsolutelyPositionedBox {
|positioning_context| {
let size;
let fragments;
- match absolutely_positioned_box.context.as_replaced() {
+ match absolutely_positioned_box.context.contents.as_replaced() {
Ok(replaced) => {
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-width
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-height