mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
This is a simple code organization change with no behavior change with the idea of making Layout 2020 easier to understand by new folks to the project. The idea is that we will have a cleaner separation between the different parts of layout ie one directory for the fragment tree and one (currently multiple) directory for the box tree.
68 lines
2.1 KiB
Rust
68 lines
2.1 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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/. */
|
|
|
|
use super::Fragment;
|
|
use crate::{cell::ArcRefCell, geom::flow_relative::Vec2};
|
|
use style::values::computed::{Length, LengthPercentage};
|
|
|
|
/// A reference to a Fragment which is shared between `HoistedAbsolutelyPositionedBox`
|
|
/// and its placeholder `AbsoluteOrFixedPositionedFragment` in the original tree position.
|
|
/// This will be used later in order to paint this hoisted box in tree order.
|
|
#[derive(Serialize)]
|
|
pub(crate) struct HoistedSharedFragment {
|
|
pub fragment: Option<ArcRefCell<Fragment>>,
|
|
pub box_offsets: Vec2<AbsoluteBoxOffsets>,
|
|
}
|
|
|
|
impl HoistedSharedFragment {
|
|
pub(crate) fn new(box_offsets: Vec2<AbsoluteBoxOffsets>) -> Self {
|
|
HoistedSharedFragment {
|
|
fragment: None,
|
|
box_offsets,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl HoistedSharedFragment {
|
|
/// In some cases `inset: auto`-positioned elements do not know their precise
|
|
/// position until after they're hoisted. This lets us adjust auto values
|
|
/// after the fact.
|
|
pub(crate) fn adjust_offsets(&mut self, offsets: Vec2<Length>) {
|
|
self.box_offsets.inline.adjust_offset(offsets.inline);
|
|
self.box_offsets.block.adjust_offset(offsets.block);
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize)]
|
|
pub(crate) enum AbsoluteBoxOffsets {
|
|
StaticStart {
|
|
start: Length,
|
|
},
|
|
Start {
|
|
start: LengthPercentage,
|
|
},
|
|
End {
|
|
end: LengthPercentage,
|
|
},
|
|
Both {
|
|
start: LengthPercentage,
|
|
end: LengthPercentage,
|
|
},
|
|
}
|
|
|
|
impl AbsoluteBoxOffsets {
|
|
pub(crate) fn both_specified(&self) -> bool {
|
|
match self {
|
|
AbsoluteBoxOffsets::Both { .. } => return true,
|
|
_ => return false,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn adjust_offset(&mut self, new_offset: Length) {
|
|
match *self {
|
|
AbsoluteBoxOffsets::StaticStart { ref mut start } => *start = new_offset,
|
|
_ => (),
|
|
}
|
|
}
|
|
}
|